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 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" : "" );
}

// this fixes an issue with the old method, ambiguous values
// with this test document.cookie.indexOf( name + "=" );
function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );


		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}

// 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);
}

/* validDailyQuestion Function */
function validDailyQuestion(form_id)
  {
   tmp="passForm=document.forms['"+form_id+"'];";
   eval(tmp);

   valid_q=0;
   count_answers=0;
	 
   for (j=1; j<=4; j++)
       {
	 exp ="q_value=passForm.answer_"+j+".checked;";
	 eval(exp);
	      
	 if (q_value==true)
	    {
	     count_answers++;
	     selected_answer=j;
	    }
	}

   if (count_answers==0)
      {
       alert("אנא ענו על השאלה היומית.");
	return false;
      }
      
   doSmartLoading('daily_question_content', passForm.category_type.value, passForm.question_id.value, selected_answer);
   return false;
  }

/* 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)
 {
  obj=document.getElementById('search_query');
  if (sel_option=="1")
     {
      if (obj.value=="")
         { obj.value="חיפוש לימודים..."; }
     }
     
  if (sel_option=="0")
     {
      if (obj.value=="חיפוש לימודים...")
         { 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 (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.message_content.value);
  passForm.message_content.value=temp;
  // End of Message Content 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
   
   // Beginning of Followup Checking
   o1=document.getElementById('followup').checked;
   if (o1==true)
      {
	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 Followup Checking
   return true;
  }
  
function display_banner(div_id, object_id, div_width, div_height, banner_name, banner_bg)
{
		x ="<object style='z-index:1;' width='"+div_width+"' height='"+div_height+"' id='"+object_id+"'>";
		x+="<param name='movie' value='"+banner_name+"' />";
		x+="<param name='quality' value='high' />";
		//x+"<PARAM NAME='wmode' VALUE='transparent' />";
		x+="<param name='bgcolor' value='" + banner_bg+"' />";
		x+="<embed src='"+banner_name+"' quality='high' bgcolor='"+banner_bg+"' width='"+div_width+"' height='"+div_height+"' type='application/x-shockwave-flash'></embed>";
		x+="</object>";
		
		eval("document.getElementById('"+div_id+"').innerHTML=\""+x+"\";");
}