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

/* Trim Function */
function trim(value)
 {
  var temp = value;
  return temp.replace(/^\s*(\b.*\b|)\s*$/, "$1");
 }

/* validContactForm Function */
function validContactForm(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})+$/;
  regular_url=/(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
  // 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("אנא מלאו כתובת דואר אלקטרוני תקינה.");
      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
  */

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

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

  // Beginning of Regular Expressions Creating
  regular_phones=/^([0-9\-\+]{9,})$/;
  // 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;
     }
  // 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;
     }
  // End of Last Name 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;
     }
  // End of Phone Number Checking

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

  // Beginning of Favoured Perfume Checking
  temp=trim(passForm.favoured_perfume.value);
  passForm.favoured_perfume.value=temp;
  /*
  if (temp=="")
     {
      alert("אנא מלאו את הבושם האהוב עליכם.");
      passForm.favoured_perfume.focus();
      return false;
     }
  */
  // End of Favoured Perfume 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;
 }

/* validSubscriptionForm Function */
function validSubscriptionForm(form_id)
  {
  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_postal_code=/^([0-9]{5})$/;
   regular_credit_card_cvv=/^([0-9]{3,4})$/;
   regular_credit_card_number=/^([0-9]{8,16})$/;
   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('registration_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('registration_form[last_name]', '"+escape(temp)+"', 30, '/');";
   eval(exp);
   // End of Last Name 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('registration_form[city]', '"+escape(temp)+"', 30, '/');";
   eval(exp);
   // End of City Checking

   // Beginning of Street Address Checking
   temp=trim(passForm.street_address.value);
   passForm.street_address.value=temp;
   if (temp=="")
      {
	 alert("אנא רשמי את הכתובת.");
	 passForm.street_address.focus();
	 return false;
      }

   exp ="Set_Cookie('registration_form[street_address]', '"+escape(temp)+"', 30, '/');";
   eval(exp);
   // End of Street Address Checking

   // Beginning of Postal Code Checking
   temp=trim(passForm.postal_code.value);
   passForm.postal_code.value=temp;
   if (temp!="")
      {
	if (!(regular_postal_code.test(temp)))
	   {
	    alert("אנא רשמי את המיקוד שלך ב-5 ספרות.");
	    passForm.postal_code.focus();
	    return false;
	   }

	exp ="Set_Cookie('registration_form[postal_code]', '"+escape(temp)+"', 30, '/');";
	eval(exp);
      }
   // End of Postal Code 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('registration_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('registration_form[email_address]', '"+escape(temp)+"', 30, '/');";
   eval(exp);
   // End of E-mail Address Checking

   // Beginning of Payment Method Checking
   temp=trim(passForm.payment_method.value);
   passForm.payment_method.value=temp;
   exp ="Set_Cookie('registration_form[payment_method]', '"+escape(temp)+"', 30, '/');";
   eval(exp);
   // End of Payment Method Checking
   
// Beginning of CC Type Checking
  temp=trim(passForm.credit_card_type.value);
  passForm.credit_card_type.value=temp;
  if (temp=="")
     {
      alert("אנא בחרו סוג כרטיס אשראי.");
      passForm.credit_card_type.focus();
      return false;
     }
  // End of CC Type Checking
  
  // Beginning of CC Number Checking
  temp=trim(passForm.credit_card_number.value);
  passForm.credit_card_number.value=temp;
  if (!(regular_credit_card_number.test(temp)))
     {
      alert("אנא רשום מספר כרטיס אשראי בספרות בלבד.");
      passForm.credit_card_number.focus();
      return false;
     }
  // End of CC Number Checking

  // Beginning of CC Expires Month Checking
  temp=trim(passForm.credit_card_expires_month.value);
  passForm.credit_card_expires_month.value=temp;
  if (temp=="")
     {
      alert("אנא בחרו חודש תוקף הכרטיס.");
      passForm.credit_card_expires_month.focus();
      return false;
     }
  // End of CC Expires Month Checking
  
  // Beginning of CC Expires Year Checking
  temp=trim(passForm.credit_card_expires_year.value);
  passForm.credit_card_expires_year.value=temp;
  if (temp=="")
     {
      alert("אנא בחרו שנת תוקף הכרטיס.");
      passForm.credit_card_expires_year.focus();
      return false;
     }
  // End of CC Expires Year Checking
  
  // Beginning of CVV Checking
  temp=trim(passForm.credit_card_cvv.value);
  passForm.credit_card_cvv.value=temp;
  if (!(regular_credit_card_cvv.test(temp)))
     {
      alert("אנא רשום 3 ספרות 3-4 גב הכרטיס.");
      passForm.credit_card_cvv.focus();
      return false;
     }
  // End of CVV Checking

   // Beginning of License Agreement Checking
   if (passForm.license_agreement.checked==false)
      {
	alert("עלייך להסכים לתנאי השימוש.");
	return false;
      }
   // End of License Agreement Checking
   return true;
  }

function add_product_to_cart(product_id, form_id)
  {
   tmp="passForm=document.forms['"+form_id+"'];";
   eval(tmp);

   product_quantity=passForm.product_quantity.value;

   // Beginning of Regular Expressions
   regular_digits=/^([0-9]{1,5})$/;
   // End of Regular Expressions

   // Beginning of Product Quantity Checking
   temp=trim(product_quantity);
   if (!(regular_digits.test(temp)))
      {
	alert("אנא ציינו את כמות המוצר המבוקשת בספרות בלבד.");
	passForm.product_quantity.focus();
	return false;
      }
   // End of Product Quantity Checking
   
   xmlHttp=GetXmlHttpObject();
   if (xmlHttp==null)
      {
       alert("Your browser does not support AJAX!");
       return;
      }

   var url="../add_product_to_cart.php";
   var params="product_id="+product_id+"&product_quantity="+product_quantity;
  
   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=function(){
	  if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	     {
	      window.location='../shopping_cart.php';
	     }
	    };
   xmlHttp.send(params);
  }

function change_product_quantity_in_cart(product_id, field_id, form_id)
  {
   tmp="product_quantity=document.getElementById('"+field_id+"');";
   eval(tmp);

   // Beginning of Regular Expressions
   regular_digits=/^([0-9]{1,5})$/;
   // End of Regular Expressions

   // Beginning of Product Quantity Checking
   temp=trim(product_quantity.value);
   if (!(regular_digits.test(temp)))
      {
	alert("אנא ציינו את כמות המוצר המבוקשת בספרות בלבד.");
	product_quantity.focus();
	return false;
      }
   // End of Product Quantity Checking

   xmlHttp=GetXmlHttpObject();
   if (xmlHttp==null)
      {
       alert("Your browser does not support AJAX!");
       return;
      }

   var url="add_product_to_cart.php";
   var params="product_id="+product_id+"&product_quantity="+product_quantity.value;
  
   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=function(){
	  if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	     {
	      window.location='../shopping_cart.php';
	     }
	    };
   xmlHttp.send(params);
  }

function erase_product_from_cart(record_id)
  {
   msg=confirm("האם את בטוחה שברצונך להסיר את המוצר מסל הקניות שלך?");

   if (msg==true)
      {
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	   {
	    alert("Your browser does not support AJAX!");
	    return;
	   }

	var url="erase_product_from_cart.php";
	var params="record_id="+record_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=function(){
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	   {
	    window.location='shopping_cart.php';
	   }
	  };
	xmlHttp.send(params);
      }
   else
      { alert("לא בוצעו שינויים."); }
  }

function add_product_to_cart_from_manufactures(product_id)
  {
   xmlHttp=GetXmlHttpObject();
   if (xmlHttp==null)
      {
       alert("Your browser does not support AJAX!");
       return;
      }

   var url="../add_product_to_cart.php";
   var params="product_id="+product_id+"&product_quantity=1";
  
   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=function(){
	  if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	     {
	      window.location='../shopping_cart.php';
	     }
	    };
   xmlHttp.send(params);
  }

function products_sorting(sort_by, sort_order, page_number, sort_series)
  {
   passForm=document.forms['search_form'];
   document.getElementById('sort_by').value=sort_by;
   document.getElementById('sort_order').value=sort_order;
   document.getElementById('page_number').value=page_number;
   document.getElementById('sort_series').value=sort_series;
   passForm.submit();
  }
  
function products_sorting_category(sort_by, sort_order, char_name, sort_series)
  {
   passForm=document.forms['search_form'];
   document.getElementById('sort_by').value=sort_by;
   document.getElementById('sort_order').value=sort_order;
   document.getElementById('char_name').value=char_name;
   document.getElementById('sort_series').value=sort_series;
   passForm.submit();
  }
  
function sub_products_sorting(char_name)
  {
   passForm=document.forms['search_form'];
   document.getElementById('char_name').value=char_name;
   passForm.submit();
  }

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

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