function stateChange_ad(ad_url) 
{ 
	if (xmlHttp.readyState==4)
	{ 
		//alert(xmlHttp.responseText);
		//alert('הנתון עודכן בהצלחה.');
		//if (document.getElementById('small_font'))	{document.getElementById('small_font').focus();}
	}
window.location=ad_url;
}

function ads_stats_update(id,ad_url)
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="ads_stats.php";
var params = "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 = stateChange_ad(ad_url);
xmlHttp.send(params);
}

/* 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" : "" );
}

// redirectPsymulator Function
function redirectPsymulator()
 {
  window.open('http://www.psymulator.co.il');
 }

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

   return false;
  }

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

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

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

   // Beginning of Password Checking
   temp=trim(passForm.password.value);
   passForm.password.value=temp;
   if (temp=="")
      {
	alert("אנא רשמו את הסיסמה המבוקשת באותיות לועזיות ובספרות בלבד.");
	passForm.password.focus();
	return false;
      }
   // End of Password Checking
   return true;
  }

function doSmartLoading(div_id, category_type, question_id, answer_location)
{
 exp1="document.getElementById('"+div_id+"').innerHTML='<div align=\"center\" style=\"margin-top: 100px\"><img src=\"images/other/ajax-loader-bar.gif\" alt=\"\" width=\"128px\" height=\"15px\" /></div>';";
 eval(exp1);

 str ="intval=window.setInterval(\"updateTimer('"+div_id+"', '"+category_type+"', '"+question_id+"', '"+answer_location+"')\", 1500);";
 eval(str);
}

/* change_radio_button Function */
function change_radio_button(q_number, q_bg, selected_answer)
  {
   for (j=1; j<=4; j++)
	{
	 if (j==selected_answer)
	    { exp="temp=document.getElementById('"+q_number+j+"').style.background='url(images/numbers/"+q_bg+"-black.png) no-repeat center';"; }
	 else
	    { exp="temp=document.getElementById('"+q_number+j+"').style.background='url(images/numbers/"+q_bg+j+".png) no-repeat center';"; }

	 eval(exp);
	}
  }

function popitup(win_url, win_height, win_width)
  {
   temp="window.open('"+win_url+"', 'פורטל פסיכומטרי', 'height="+win_height+"px, width="+win_width+"px, toolbar=0, status=0, scrollbars=0, resizable=0, menubar=0, left=50px, top=50px');";
   eval(temp);
  }

/* clear_search_field Function */
function clear_search_field(sel_option, sel_id, sel_text)
 {
  temp="obj=document.getElementById('"+sel_id+"');";
  eval(temp);
  if (sel_option=="1")
     {
      if (obj.value=="")
         { obj.value=sel_text; }
     }
     
  if (sel_option=="0")
     {
      if (obj.value==sel_text)
         { obj.value=""; }
     }
 }
 
/* clear_form_field Function */
function clear_form_field(form_id, field_id, sel_option, field_value)
 {
  tmp="passForm=document.forms['"+form_id+"'];";
  eval(tmp);
 
  temp="obj=passForm."+field_id+";";
  eval(temp);
  
  if (sel_option=="1")
     {
      if (obj.value=="")
         { obj.value=field_value }
     }
     
  if (sel_option=="0")
     {
      if (obj.value==field_value)
         { obj.value=""; }
     }
 }
 
/* goto_forum Function */
function goto_forum(chosen_top_id, chosen_msg_id)
 {
  temp="redirect='http://www.psychometry.co.il/psychometry/forum.php?chosen_top_id="+chosen_top_id+"&chosen_msg_id="+chosen_msg_id+"#msg"+chosen_msg_id+"';";
  eval(temp);
  window.location=redirect;
 }
 
/* validContactForm Function */
function validContactForm(form_id, div_id)
 {
  tmp="passForm=document.forms['"+form_id+"'];";
  eval(tmp);

  // Beginning of Regular Expressions Creating
  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;
     }
  // End of Full Name Checking
  
   // Beginning of Phone Number Checking
   temp=trim(passForm.phone_number.value);
   passForm.phone_number.value=temp;

   if (temp.charAt(0)!="0")
	{
	 alert("הספרה הראשונה של מספר הטלפון מוכרחה להיות 0.");
	 passForm.phone_number.focus();
	 return false;
	}

   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;
	}
   // End of Phone Number Checking

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

  // Beginning of Message Content Checking
  temp=trim(passForm.remarks.value);
  passForm.remarks.value=temp;
  if (temp=="")
     {
      alert("אנא רשמו את תוכן ההודעה.");
      passForm.remarks.focus();
      return false;
     }
  // End of Message Content 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;
 }
 
/* validForumReplyForm Function */
function validForumReplyForm(form_id)
  {
   tmp="passForm=document.forms['"+form_id+"'];";
   eval(tmp);
   
   // Beginning of Regular Expressions Creating
  regular_email_address=/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
  // End of Regular Expressions Creating

   // 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

   // Beginning of License Agreement Checking
   if (passForm.license_agreement.checked==false)
      {
	alert("עליך להסכים לתנאי השימוש בפורום.");
	return false;
      }
   // End of License Agreement Checking
   return true;
  }
  
function show_dd(id, stat)
  {
   if (stat=="0")
      { eval("document.getElementById('"+id+"').style.display='none';"); }
   else
      { eval("document.getElementById('"+id+"').style.display='';"); }
  }
  
/* validSubscriptionWithTermsForm Function */
function validSubscriptionWithTermsForm(form_id)
  {
   tmp="passForm=document.forms['"+form_id+"'];";
   eval(tmp);

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

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

   // Beginning of First Name Checking
   temp=trim(passForm.first_name.value);
   passForm.first_name.value=temp;
   if (temp=="")
      {
	alert("אנא רשמו את השם הפרטי.");
	passForm.first_name.focus();
	return false;
      }

   exp ="Set_Cookie('subscription_form[first_name]', '"+escape(temp)+"', 30, '/');";
   eval(exp);
   // End of First Name Checking

   // Beginning of Last Name Checking
   temp=trim(passForm.last_name.value);
   passForm.last_name.value=temp;
   if (temp=="")
      {
	alert("אנא רשמו את שם המשפחה.");
	passForm.last_name.focus();
	return false;
      }

   exp ="Set_Cookie('subscription_form[last_name]', '"+escape(temp)+"', 30, '/');";
   eval(exp);
   // End of Last Name Checking

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

   exp ="Set_Cookie('subscription_form[nickname]', '"+escape(temp)+"', 30, '/');";
   eval(exp);
   // End of Nickname Checking
   
   // Beginning of Phone Prefix Checking
   temp=trim(passForm.phone_prefix.value);
   passForm.phone_prefix.value=temp;
   if (temp=="")
      {
	alert("אנא בחרו את הקידומת למספר הטלפון שלכם.");
	passForm.phone_prefix.focus();
	return false;
      }
      
   exp ="Set_Cookie('subscription_form[phone_prefix]', '"+escape(temp)+"', 30, '/');";
   eval(exp);
   // End of Phone Prefix Checking

   // Beginning of Phone Number Checking
   temp=trim(passForm.phone_number.value);
   passForm.phone_number.value=temp;
   if (!(regular_phones.test(temp)))
      {
	alert("אנא מלאו את מספר הטלפון שלכם בספרות בלבד.");
	passForm.phone_number.focus();
	return false;
      }
      
   exp ="Set_Cookie('subscription_form[phone_number]', '"+escape(temp)+"', 30, '/');";
   eval(exp);
   // End of Phone Number Checking

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

   exp ="Set_Cookie('subscription_form[email_address]', '"+temp+"', 30, '/');";
   eval(exp);
   // End of E-mail Address Checking
   
   // Beginning of Exam Date Checking
   temp=trim(passForm.exam_date.value);
   passForm.exam_date.value=temp;
   if (temp=="")
      {
	alert("אנא בחרו במועד שבו אתם ניגשים לבחינה.");
	passForm.exam_date.focus();
	return false;
      }

   exp ="Set_Cookie('subscription_form[exam_date]', '"+temp+"', 30, '/');";
   eval(exp);
   // End of Exam Date Checking

   // Beginning of Studying Place Checking
   temp=trim(passForm.studying_place.value);
   passForm.studying_place.value=temp;
   if (temp=="")
      {
	alert("אנא בחרו איפה אתם לומדים לבחינה הפסיכומטרית.");
	passForm.studying_place.focus();
	return false;
      }

   exp ="Set_Cookie('subscription_form[studying_place]', '"+temp+"', 30, '/');";
   eval(exp);
   // End of Studying Place Checking
   
   // Beginning of City Checking
   temp=trim(passForm.city.value);
   passForm.city.value=temp;
   if (temp=="")
      {
	alert("אנא רשמו אזור מגורים.");
	passForm.city.focus();
	return false;
      }
      
   exp ="Set_Cookie('subscription_form[city]', '"+escape(temp)+"', 30, '/');";
   eval(exp);
   // End of City 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

   // Beginning of Terms of Use Checking
   temp=document.getElementById('terms').checked;
   if (!temp)
      {
	alert("אנא אשרו את תנאי השימוש.");
	return false;
      }
   // End of Terms of Use Checking
   return true;
  }
