function toggle_element(obj)
{
	var el = document.getElementById(obj);
	el.style.display = (el.style.display != 'none' ? 'none' : '' );


}

function set_hours(id,str)
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="ajax_oper.php";
var params = "action=set_hours&id="+id+"&value="+str;
xmlHttp.open("POST", url, true);
//Send the proper header information along with the request
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-length", params.length);
xmlHttp.setRequestHeader("Connection", "close");
xmlHttp.onreadystatechange = stateChange;
xmlHttp.send(params);
}

function remove_post(id)
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="include/admin_ajax_oper.php";
var params = "action=remove_post&id="+id;
xmlHttp.open("POST", url, true);
//Send the proper header information along with the request
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-length", params.length);
xmlHttp.setRequestHeader("Connection", "close");
xmlHttp.onreadystatechange = post_removed;
xmlHttp.send(params);
}

//-----------------------------------------------------------------------------------

function text_update(id,str,clm,tbl)
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="../../../include/admin_ajax_oper.php";
var params = "action=q_name&id="+id+"&name="+str+"&clm="+clm+"&tbl="+tbl;
xmlHttp.open("POST", url, true);
//Send the proper header information along with the request
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-length", params.length);
xmlHttp.setRequestHeader("Connection", "close");
xmlHttp.onreadystatechange = stateChange;
xmlHttp.send(params);
}

//----------------------------------------------------------------------------------

function open_mikbazt(category_id,mikbatz_id,open)
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
  if (open)
	open = "1";
  else
	open = "0";
var url="../../../include/admin_ajax_oper.php";
var params = "action=mikbatz_open&category_id="+category_id+"&mikbatz_id="+mikbatz_id+"&open="+open;

xmlHttp.open("POST", url, true);
//Send the proper header information along with the request
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-length", params.length);
xmlHttp.setRequestHeader("Connection", "close");
xmlHttp.onreadystatechange = stateChange;
xmlHttp.send(params);
}

//----------------------------------------------------------------------------------

function q_category_name(id,str)
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="ajax_oper.php";
var params = "action=q_name&id="+id+"&name="+str;
xmlHttp.open("POST", url, true);
//Send the proper header information along with the request
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-length", params.length);
xmlHttp.setRequestHeader("Connection", "close");
xmlHttp.onreadystatechange = stateChange;
xmlHttp.send(params);
}


function index_update(id,str)
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="ajax_oper.php";
var params = "action=index_update&id="+id+"&name="+str;
xmlHttp.open("POST", url, true);
//Send the proper header information along with the request
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-length", params.length);
xmlHttp.setRequestHeader("Connection", "close");
xmlHttp.onreadystatechange = stateChange_index;
xmlHttp.send(params);
}


function mikbatz_update(category,id,str)
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="ajax_operations.php";
var params = "action=mu&id="+id+"&st="+str+"&category_id="+category;
xmlHttp.open("POST", url, true);
//Send the proper header information along with the request
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-length", params.length);
xmlHttp.setRequestHeader("Connection", "close");
xmlHttp.onreadystatechange = stateChange;
xmlHttp.send(params);
}
//----------------------------------------------------------------------------------

function question_location(id,str)
{ 
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="ajax_operations.php";
var params = "action=ql&id="+id+"&st="+str;
xmlHttp.open("POST", url, true);
//Send the proper header information along with the request
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-length", params.length);
xmlHttp.setRequestHeader("Connection", "close");
xmlHttp.onreadystatechange = stateChange;
xmlHttp.send(params);
}
//----------------------------------------------------------------------------------
function stateChange() 
{ 
	if (xmlHttp.readyState==4)
	{ 
		//alert(xmlHttp.responseText);
		//alert('הנתון עודכן בהצלחה.');
		//if (document.getElementById('small_font'))	{document.getElementById('small_font').focus();}
	}
}

//----------------------------------------------------------------------------------
function post_removed() 
{ 
	if (xmlHttp.readyState==4)
	{ 
		window.location.reload();
	}
}

//----------------------------------------------------------------------------------

function stateChange_index() 
{ 
	if (xmlHttp.readyState==4)
	{ 
		alert(xmlHttp.responseText);
		//alert('הנתון עודכן בהצלחה.');
		window.location.reload();
	}
}
//----------------------------------------------------------------------------------
function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}

//-----------------------------------------------------------------------------------

function move_to_hebrew()
{
	exp ="Set_Cookie('language_id', 'HE', 30, '/');";
	eval(exp);
}
function choose_language(language_id)
{
	exp ="Set_Cookie('language_id', '"+language_id+"', 30, '/');";
	eval(exp);
	if (language_id=="EN")
	{	
		window.location="http://www.cybergmat.com";
	}
	else
	{
		temp = "window.location='http://www.cybergmat.com/index_"+language_id+"'";
		eval(temp);
	}
	return true;
}
/* Trim Function */
function trim(value)
 {
  var temp = value;
  return temp.replace(/^\s*(\b.*\b|)\s*$/, "$1");
 }

function Set_Cookie( name, value, expires, path, domain, secure ) 
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

/*
if the expires variable is set, make the correct 
expires time, the current script below will set 
it for x number of days, to make it for hours, 
delete * 24, for minutes, delete * 60 * 24
*/
if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
( ( path ) ? ";path=" + path : "" ) + 
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}

/* validContactForm Function */
function validContactForm(form_id, button_name)
  {
  tmp="passForm=document.forms['"+form_id+"'];";
  eval(tmp);

   // Beginning of Regular Expressions Creating
   regular_hebrew=/^([^a-zA-Z0-9_]{1,})$/;
   regular_digits=/^([0-9]{1})$/;
   regular_email_address=/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
   // End of Regular Expressions Creating

   // Beginning of Full Name Checking
   temp=trim(passForm.full_name.value);
   passForm.full_name.value=temp;
   if (temp=="")
      {
	 alert("אנא רשמו את שמכם.");
	 passForm.full_name.focus();
	 return false;
      }

   exp ="Set_Cookie('cybergmat_form[full_name]', '"+escape(temp)+"', 30, '/');";
   eval(exp);
   // End of Full Name Checking

   // Beginning of Phone Number Checking
   temp=trim(passForm.phone_number.value);
   passForm.phone_number.value=temp;

   count_digits=0;
   for (i=0; i<=temp.length; i++)
	 {
	  if (regular_digits.test(temp.charAt(i)))
	     { count_digits++; }
	 }

   if (count_digits<9)
	{
	 alert("אנא רשמו את מספר הטלפון שלכם כולל קידומת ב-9 ספרות לפחות.");
	 passForm.phone_number.focus();
	 return false;
	}

   exp ="Set_Cookie('cybergmat_form[phone_number]', '"+escape(temp)+"', 30, '/');";
   eval(exp);
   // End of Phone Number Checking

   // Beginning of Bulletin Address Checking
   if (passForm.v_bulletin_address.value!="")
	{
	 temp=trim(passForm.bulletin_address.value);
	 passForm.bulletin_address.value=temp;
	 if (passForm.v_must_bulletin_address.value!="")
	    {
	     if (temp=="")
		 {
		  alert("אנא רשמו כתובת למשלוח ידיעון.");
		  passForm.bulletin_address.focus();
		  return false;
		 }
          }

       exp ="Set_Cookie('cybergmat_form[bulletin_address]', '"+escape(temp)+"', 30, '/');";
       eval(exp);
      }
   // End of Bulletin Address Checking

   // Beginning of Living Area Checking
   if (passForm.v_living_area.value!="")
	{
	 temp=trim(passForm.living_area.value);
	 passForm.living_area.value=temp;
	 if (passForm.v_must_living_area.value!="")
	    {
	     if (temp=="")
		 {
		  alert("אנא רשמו את אזור המגורים שלכם.");
		  passForm.living_area.focus();
		  return false;
		 }
          }

       exp ="Set_Cookie('cybergmat_form[living_area]', '"+escape(temp)+"', 30, '/');";
       eval(exp);
      }
   // End of Living Area Checking

   // Beginning of E-mail Address Checking
   if (passForm.v_email_address.value!="")
	{
	 temp=trim(passForm.email_address.value);
	 passForm.email_address.value=temp;
	 if (passForm.v_must_email_address.value!="")
	    {
	     if (!(regular_email_address.test(temp)))
		 {
		  alert("אנא רשמו את כתובת הדואר האלקטרוני שלכם בתבנית חוקית.");
		  passForm.email_address.focus();
		  return false;
		 }
          }

       exp ="Set_Cookie('cybergmat_form[email_address]', '"+escape(temp)+"', 30, '/');";
       eval(exp);
      }
   // End of E-mail Address Checking

   // Beginning of Message Content Checking
   if (passForm.v_remarks.value!="")
	{
	 temp=trim(passForm.msg_content.value);
	 passForm.msg_content.value=temp;
	 if (passForm.v_must_remarks.value!="")
	    {
	     if (temp=="")
		 {
		  alert("אנא רשמו מלל חופשי.");
		  passForm.msg_content.focus();
		  return false;
		 }
          }
      }
   // End of Message Content Checking

   // Beginning of Course of Studies Checking
   if (passForm.v_cos.value!="")
	{
	 temp=trim(passForm.cos.value);
	 passForm.cos.value=temp;
	 if (passForm.v_must_cos.value!="")
	    {
	     if (temp=="")
		 {
		  alert("אנא מלאו את שדה מסלול הלימודים.");
		  passForm.cos.focus();
		  return false;
		 }
          }

       exp ="Set_Cookie('cybergmat_form[course_of_study]', '"+escape(temp)+"', 30, '/');";
       eval(exp);
      }
   // End of Course of Studies Checking

   // Beginning of Departments Checking
   if (passForm.v_deps.value!="")
	{
	 temp=trim(passForm.deps.value);
	 passForm.deps.value=temp;
	 if (passForm.v_must_deps.value!="")
	    {
	     if (temp=="")
		 {
		  alert("אנא מלאו את שדה החוג.");
		  passForm.deps.focus();
		  return false;
		 }
          }

       exp ="Set_Cookie('cybergmat_form[dep_code]', '"+escape(temp)+"', 30, '/');";
       eval(exp);   
      }
   // End of Departments Checking

   // doLoading(form_id, button_name);
   return true;
  }
  
function doLoading(form_id, button_id)
  {
   exp1="document.getElementById('"+button_id+"').style.background='url(../images/other/ajax-loader.gif) no-repeat center';";
   eval(exp1);
   exp2="document.getElementById('"+button_id+"').disabled=true;";
   eval(exp2);

   return false;
  }
  
function send_mail_procedure(form_id, div_id)
  {
   tmp="passForm=document.forms['"+form_id+"'];";
   eval(tmp);

   full_name=passForm.full_name.value;
   phone_number=passForm.phone_number.value;
   email_address=passForm.email_address.value;
   company_name=passForm.company_name.value;
   web_url=passForm.web_url.value;
   message_content=passForm.message_content.value;

   new Ajax.Request('send_mail_procedure.php',
    {
     method: 'post',
     parameters: {full_name: full_name, phone_number: phone_number, email_address: email_address, company_name: company_name, web_url: web_url, message_content: message_content, limit: 999}
    });

   str="document.getElementById('"+div_id+"').innerHTML='<br /><br /><br /><br /><br /><span style=\"font-size: 13px\">פנייתך נשלחה בהצלחה.<br />נציגנו יצרו איתך קשר בתוך 24 שעות.<br />המשך גלישה נעימה.</span>';";
   eval(str);
  }

/* validForumReplyForm Function */
function validForumReplyForm(form_id)
  {
   tmp="passForm=document.forms['"+form_id+"'];";
   eval(tmp);

   // Beginning of Nickname Checking
   temp=trim(passForm.nickname.value);
   passForm.nickname.value=temp;
   if (temp=="")
      {
	alert("אנא בחרו כינוי לזיהוי בפורום.");
	passForm.nickname.focus();
	return false;
      }
   // End of Nickname Checking

   // Beginning of Subject Checking
   temp=trim(passForm.subject.value);
   passForm.subject.value=temp;
   if (temp=="")
      {
	alert("אנא רשמו את כותרת ההודעה.");
	passForm.subject.focus();
	return false;
      }
   // End of Subject Checking

   // Beginning of Captcha Checking
   temp=trim(passForm.captcha_code.value);
   passForm.captcha_code.value=temp;
   if (temp=="")
      {
	alert("אנא רשמו את רצף התווים המופיע בתמונה.");
	passForm.captcha_code.focus();
	return false;
      }
   // End of Captcha Checking
   return true;
  }
  
/* check_poll_answer Function */
function check_poll_answer(poller_id)
 {
  o1=document.getElementById('option1').checked;
  o2=document.getElementById('option2').checked;
  o3=document.getElementById('option3').checked;
  o4=document.getElementById('option4').checked;
  o5=document.getElementById('option5').checked;

  if ((!o1) && (!o2) && (!o3) && (!o4) && (!o5))
     {
      alert("אנא סמן את תשובתך");
      return false;
     }
  
  return false;
 }
 
/* Alter Details Form Area Function */
function alter_details_form_area(stat)
  {
   if (stat=="0")
	{ document.getElementById('details_form_area').style.display="none"; }

   if (stat=="1")
	{ document.getElementById('details_form_area').style.display=""; }
  }
  
/* validContactSupportForm Function */
function validContactSupportForm(form_id)
 {
	tmp="passForm=document.forms['"+form_id+"'];";
  eval(tmp);

  // Beginning of Regular Expressions Creating
  regular_phones=/^([0-9\-\+]{9,})$/;
  regular_email_address=/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
  // End of Regular Expressions Creating

  // Beginning of Full Name Checking
  temp=trim(passForm.full_name.value);
  passForm.full_name.value=temp;
  if (temp=="")
     {
      alert("Please specify your name.");
      passForm.full_name.focus();
      return false;
     }
  // End of Full Name Checking
  
  // Beginning of E-mail Address Checking
  temp=trim(passForm.email_address.value);
   passForm.email_address.value=temp;
   if (temp!="")
    {
	if (!(regular_email_address.test(temp)))
	   {
	    alert("Please specify a valid email address.");
	    passForm.email_address.focus();
	    return false;
        }
    }
   else
	{
	    alert("Please specify a valid email address.");
	    passForm.email_address.focus();
	    return false;
    }
  // End of E-mail Address Checking

  // Beginning of Message Content Checking
  temp=trim(passForm.message_content.value);
  passForm.message_content.value=temp;
  if (temp=="")
     {
      alert("Please specify your comments or questions.");
      passForm.message_content.focus();
      return false;
     }
  // End of Message Content Checking
  return true;
 }
 
 /* validContactSupportForm Function */
function validContactSupportForm_he(form_id)
 {
  tmp="passForm=document.forms['"+form_id+"'];";
  eval(tmp);

  // Beginning of Regular Expressions Creating
  regular_phones=/^([0-9\-\+]{9,})$/;
  regular_email_address=/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
  // End of Regular Expressions Creating

  // Beginning of Full Name Checking
  temp=trim(passForm.full_name.value);
  passForm.full_name.value=temp;
  if (temp=="")
     {
      alert("אנא רשמו את שמכם המלא.");
      passForm.full_name.focus();
      return false;
     }
  // End of Full Name Checking

  // Beginning of Phone Number Checking
  /*temp=trim(passForm.phone_number.value);
  passForm.phone_number.value=temp;
  if (temp=="")
     {
      alert("אנא רשמו את מספר הטלפון שלכם בספרות, קווים מפרידים וסימני + בלבד.");
      passForm.phone_number.focus();
      return false;
     }
  // End of Phone Number Checking*/

  // Beginning of E-mail Address Checking
  temp=trim(passForm.email_address.value);
  passForm.email_address.value=temp;
  if (temp=="")
     {
      alert("כתובת הדואר האלקטרוני נרשמה בתבנית שגויה.\nאנא תקנו את הרישום.");
      passForm.email_address.focus();
      return false;
     }
  // End of E-mail Address Checking

  // Beginning of Message Content Checking
  temp=trim(passForm.message_content.value);
  passForm.message_content.value=temp;
  /*
  if (temp=="")
     {
      alert("אנא רשמו את תוכן הפנייה.");
      passForm.message_content.focus();
      return false;
     }
  */
  // End of Message Content Checking
  return true;
 }
 
 
 function verify_user()
 {
	var user = document.myForm.username.value;
	
	//creating an ajax object
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  } 
	var url="include/admin_ajax_oper.php";
	var params = "action=verify&username="+user;
	xmlHttp.open("POST", url, true);
	//Send the proper header information along with the request
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.onreadystatechange = verifying;
	xmlHttp.send(params);
 }
 
 var order_allowed = true;
 
 function verify_order()
 {
	if (order_allowed)
		return true;
	alert("The email address you've entered already exists in the system.\\nPlease login or enter a different email address.");
	return false;
 }
 
 function verifying()
 {
	if (xmlHttp.readyState==4)
	{
		eval(xmlHttp.responseText);
	}
 }
 
 var user_type = "existing_user";
 
 function new_user()
 {
	document.myForm.full_name.value = "";
	document.myForm.username.value = "";
	document.myForm.password.value = "";
	document.myForm.ccNumber.value = "";
	
	document.myForm.username.style.border = "2px solid red";
	document.getElementById('password_verify').innerHTML="";
	document.getElementById('main').style.visibility = "hidden";
	document.getElementById('verify_button').style.visibility = "visible";
	user_type = "new_user";
 }
 
 function existing_user()
 {
	if (document.myForm.password.value=="" || document.myForm.username.value=="")
	{
		document.myForm.full_name.value = "";
		document.myForm.username.value = "";
		document.myForm.password.value = "";
		document.myForm.ccNumber.value = "";
		document.getElementById('main').style.visibility = "hidden";
	}
	document.getElementById('verify_button').style.visibility = "visible";
	user_type = "existing_user";
	verify_user();
 }
