function toggleLayer( whichLayer )
{
  var elem, vis;
  if( document.getElementById ) // this is the way the standards work
    elem = document.getElementById( whichLayer );
  else if( document.all ) // this is the way old msie versions work
      elem = document.all[whichLayer];
  else if( document.layers ) // this is the way nn4 works
    elem = document.layers[whichLayer];
  vis = elem.style;
  // if the style.display value is blank we try to figure it out here
  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
  vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}

function showProcess()
{
	toggleLayer('submitButton');
	toggleLayer('processWhirl');
}

function loadXMLDoc(url)
{
// code for Mozilla, etc.
if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest()
  xmlhttp.open("GET",url,true)
  xmlhttp.send(null)
  xmlhttp.onreadystatechange=state_Change
  }
// code for IE
else if (window.ActiveXObject)
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
    if (xmlhttp)
    {
    xmlhttp.open("GET",url,true)
    xmlhttp.send()
    xmlhttp.onreadystatechange=state_Change
    }
  }
}

function state_Change()
{
// if xmlhttp shows "loaded"
if (xmlhttp.readyState==4)
  {
  // if "OK"
      if (xmlhttp.status==200)
      {
      document.getElementById('signsCount').innerHTML=xmlhttp.responseText + "<br/><span style=\"letter-spacing:0.5px;\">חתימות באתר</span>";
      t=setTimeout("loadXMLDoc( \"http://www.atzuma.co.il/signatures_count.php\" );",5000);
      }
  }
}

function init()
{
	loadXMLDoc("http://www.atzuma.co.il/signatures_count.php");
	Nifty("ul#split h3","top");
 	Nifty("ul#split2 h3","top");
	Nifty("ul#split3 h3","top");
}

function PrintComments()
{
	var ver = navigator.appVersion;
	var dom = document.getElementById ? 1: 0;
	var nIE6 = ( ver.indexOf('MSIE 6') > -1 && dom ) ? 1 : 0;
	var nIE5 = ( ver.indexOf('MSIE 5') > -1 && dom ) ? 1 : 0;
	var nIE4 = ( document.all && !dom ) ? 1 : 0;
	var nNS5 = ( dom && parseInt(ver) >= 5 ) ? 1 : 0;
	var nNS4 = ( document.layers && !dom ) ? 1 : 0;	
	if ( nIE6 || nIE5 || nNS5 || nNS4 )
		window.print();
	else if ( nIE4 )
		IEPrint();
      	return;
}

function comments(sid) {
	window.open('', 'thecomments', 'toolbar=no, directories=no,'+'status=no, resizable=yes, scrollbars=yes, location=no'+', dependent, width=650, height=450');
}
var mapWindow
function newWindow(s)
{
	mapWindow=window.open(s, 'mapWin','width=550,height=350,scrollbars=yes,resizable=1')
	mapWindow.focus()
}

function submitonce (theform) {
	if (document.all||document.getElementById)
	{
		for (i=0;i<theform.length;i++)
		{
			var tempobj=theform.elements[i]
			if(tempobj.type.toLowerCase()=="submit"||tempobj.type.toLowerCase()=="reset")
				tempobj.disabled=true
		}
	}
}

function textCounter(field,cntfield,maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else
cntfield.value = maxlimit - field.value.length;
}

//<![CDATA[
function emoticon(code) {
	x = document.postform.text;
	x.value = x.value + ' [' + code + ']';
	document.postform.text.focus();
}
function emoticonp(code) {
	if (window.event && window.event.keyCode == 13) {
		return emoticon(code);
         	}
}
//]]>

//<![CDATA[
function qpost(code) {
	x = document.postform.text;
	x.value = x.value + '[' + code + ']';
	document.postform.text.focus();
}
function qpostp(code) {
	if (window.event && window.event.keyCode == 13) {
		return emoticon(code);
	}
}
//]]>

function checkUncheckAll(theElement) {
	var theForm = theElement.form, z = 0;
	while (theForm[z].type == 'checkbox' && theForm[z].name != 'checkall') {
		theForm[z].checked = theElement.checked;
		z++;
	}
}

function avail_Check()
{
// if xmlhttp shows "loaded"
if (xmlhttp.readyState==4)
  {
  // if "OK"
      if (xmlhttp.status==200)
      {
          var avail = ''
          if (xmlhttp.responseText == '0')
          {
            avail = '<font color="green">פנוי!&nbsp;&nbsp;<img src="http://cdn.atzuma.co.il/images/available.gif" alt="פנוי"/></font>';
          }
          else
          {
            avail = '<font color="red">תפוס, עליך לבחור כתובת אחרת&nbsp;&nbsp;<img src="http://cdn.atzuma.co.il/images/taken.gif" alt="תפוס"/></font>';
          }
          document.getElementById("url_chosen_avail").innerHTML = '<b>זמינות:</b>&nbsp;&nbsp;&nbsp;' + avail;
      }
  }
}

function updateSub() {
  theurl = document.getElementById("url").value;
  if (theurl.length >= 3)
  {
    var url = 'http://www.atzuma.co.il/url-check.php?name=' + theurl;
    // code for Mozilla, etc.
    if (window.XMLHttpRequest)
      {
      xmlhttp=new XMLHttpRequest()
      xmlhttp.open("GET",url,true)
      xmlhttp.send(null)
      xmlhttp.onreadystatechange=avail_Check
      }
    // code for IE
    else if (window.ActiveXObject)
      {
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
        if (xmlhttp)
        {
        xmlhttp.open("GET",url,true)
        xmlhttp.send()
        xmlhttp.onreadystatechange=avail_Check
        }
      }
    document.getElementById("url_chosen").innerHTML = '<b>הכתובת שנבחרה:</b>&nbsp;&nbsp;&nbsp;<span dir="ltr">http://www.atzuma.co.il/' + theurl + '/</span>';
  }
  else
  {
    document.getElementById("url_chosen").innerHTML = '';
    document.getElementById("url_chosen_avail").innerHTML = '';
  }
}

function searchboxClicked() {
	if (document.getElementById("petitionSearchBox").value == 'חיפוש עצומה...')
	{
		document.getElementById("petitionSearchBox").value = '';
	}
}

function searchboxBlurred() {
	if (document.getElementById("petitionSearchBox").value == '')
	{
		document.getElementById("petitionSearchBox").value = 'חיפוש עצומה...';
	}
}

function addLink()
{
	document.getElementById("freetext").value += '|קישור|http://www.example.com|סוף|';
}

function showPress(url,width,height,name) {
	open('http://cdn.atzuma.co.il/images/press/press.htm?pic='+url, name, 'width= ' + width + ', height=' + height);	
	}

// Signature Count START
var c;
var t;
var floorTime = 1500;
var roofTime = 4000;

function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

function getRandomInt(min,max) 
{ 
 return Math.round(min + Math.random()*(max-min)) 
} 

function popUp(page)
{
	mapWindow=window.open(page, 'Contact','width=700,height=500,scrollbars=yes,resizable=1')
	mapWindow.focus()
}

function timedCount()
{
str = document.getElementById('signsCount').innerHTML;
str.replace("<font>","");
str.replace("</font>","");
var strNoCommas= "" 
len= str.length 
for(x=0;x<len;++x){ 
  if(str.charAt(x)!=",")
  if(str.charAt(x)!=" ")
  if(str.charAt(x)!="ח")
  if(str.charAt(x)!="ת")
  if(str.charAt(x)!="י")
  if(str.charAt(x)!="מ")
  if(str.charAt(x)!="ו")
  if(str.charAt(x)!="ת")
  if(str.charAt(x)!="ב")
  if(str.charAt(x)!="א")
  if(str.charAt(x)!="ר")
	{strNoCommas=strNoCommas +str.charAt(x)} 
}

c = strNoCommas | 0;
c=c+1;
document.getElementById('signsCount').innerHTML = addCommas(c) + " חתימות באתר";
roofTime += 500;
floorTime += 300;
t=setTimeout("timedCount()",getRandomInt(getRandomInt(300,floorTime),roofTime));
}
// Signature Count END


function Petition_id_selected()
{
if (document.par.m_idc.checked == true) { 
$.jGrowl('<div dir=\'rtl\'>טיפ: אנו ממליצים שלא לחייב את הגולשים להקליד את מספר תעודת הזהות שלהם באם זה לא הכרחי. אתם עלולים לאבד חתימות בעקבות צעד זה.</div>',{life:6000,closer:'false'});
}
}

function Petition_notes_selected()
{
if (document.par.m_notes.checked == true) { 
$.jGrowl('<div dir=\'rtl\'>טיפ: אנו ממליצים שלא לחייב את הגולשים להקליד הערה באם זה לא הכרחי. אתם עלולים לאבד חתימות בעקבות צעד זה.</div>',{life:6000,closer:'false'});
}
}

function Petition_telephone_selected()
{
if (document.par.m_telephone.checked == true) { 
$.jGrowl('<div dir=\'rtl\'>טיפ: אנו ממליצים שלא לחייב את הגולשים להקליד את מספר הטלפון שלהם באם זה לא הכרחי. אתם עלולים לאבד חתימות בעקבות צעד זה.</div>',{life:6000,closer:'false'});
}
}

function Petition_mobile_selected()
{
if (document.par.m_mobile.checked == true) { 
$.jGrowl('<div dir=\'rtl\'>טיפ: אנו ממליצים שלא לחייב את הגולשים להקליד את מספר הטלפון הנייד שלהם באם זה לא הכרחי. אתם עלולים לאבד חתימות בעקבות צעד זה.</div>',{life:6000,closer:'false',position:'top-left'});
}
}