/* Trim Function */
function trim(value)
 {
  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" : "" );
}

/* Input Emphasis Function */
function input_emphasis(cell)
 {
  emphasis="document.all."+cell+".style.backgroundColor='#ffffff'";
  eval(emphasis);
  return true;
 }

/* Input Emphasis Function */
function input_emphasis(cell)
 {
  emphasis="document.all."+cell+".style.backgroundColor='#ffffff'";
  eval(emphasis);
  return true;
 }

/* Cell Emphasis Function */
function cell_emphasis(question, field, number_of_fields)
  {
   for (i=1; i<=number_of_fields; i++)
	{
	 if (field==i)
	  {
	   emphasis="document.getElementById('"+question+"_"+i+"').style.backgroundColor='#ff0000'";
	   eval(emphasis);
	  }
	 else
	  {
	   emphasis="document.getElementById('"+question+"_"+i+"').style.backgroundColor='#ffffcc'";
	   eval(emphasis);
	  }
	}
  }

/* Checkbox Emphasis Function */
function checkbox_emphasis(cell)
 {
  cell_="document.getElementById("+cell+").checked";
  if (eval(cell_))
     {
      emphasis="document.getElementById('"+cell+"').style.backgroundColor='#ff0000'";
      eval(emphasis);
     }
  else
    {
     emphasis="document.getElementById('"+cell+"').style.backgroundColor='#ffffcc'";
     eval(emphasis);
    }
 }

/* 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})+$/;
  // 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 (!(regular_phones.test(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!="")
     {
      if (!(regular_email_address.test(temp)))
	  {
          alert("אנא מלאו כתובת דואר אלקטרוני תקינה.");
          passForm.email_address.focus();
          return false;
	  }
     }
  // End of E-mail Address Checking

  // Beginning of Home Address Checking
  temp=trim(passForm.home_address.value);
  passForm.home_address.value=temp;
  if (temp=="")
     {
      alert("אנא מלאו את עיר המגורים שלכם.");
      passForm.home_address.focus();
      return false;
     }
  // End of Home 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;
 }

/* validEntranceForm Function */
function validEntranceForm(passForm)
  {
   // Beginning of Regular Expressions Creating
   regular_english=/^([a-zA-Z0-9]{2,})$/;
   // End of Regular Expressions Creating


   // Beginning of Username Checking
   temp=trim(passForm.username.value);
   passForm.username.value=temp;
   if (!(regular_english.test(temp)))
      {
	alert("אנא רשמו את שם המשתמש באותיות באנגלית ובספרות בלבד.\nרב תודות.");
	passForm.username.focus();
	return false;
      }
   // End of Username Checking

   // Beginning of Password Checking
   temp=trim(passForm.password.value);
   passForm.password.value=temp;
   if (!(regular_english.test(temp)))
      {
	alert("אנא רשמו את הסיסמה באותיות באנגלית ובספרות בלבד.\nרב תודות.");
	passForm.password.focus();
	return false;
      }
   // End of Password Checking
   return true;
  }

/* validUsersForm Function */
function validUsersForm(passForm)
  {
   // Beginning of Regular Expressions Creating
   regular_english=/^([a-zA-Z0-9_]{1,})$/;
   regular_hebrew=/^([^a-zA-Z0-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 Username Checking
   temp=trim(passForm.username.value);
   passForm.username.value=temp;
   if (!(regular_english.test(temp)))
      {
	alert("אנא רשמו את שם המשתמש באותיות באנגלית ובספרות בלבד.\nרב תודות.");
	passForm.username.focus();
	return false;
      }
   // End of Username Checking

   // Beginning of Password Checking
   temp=trim(passForm.password.value);
   passForm.password.value=temp;
   if (!(regular_english.test(temp)))
      {
	alert("אנא רשמו את הסיסמה באותיות באנגלית ובספרות בלבד.\nרב תודות.");
	passForm.password.focus();
	return false;
      }
   // End of Password Checking

   // Beginning of Full Name Checking
   temp=trim(passForm.full_name.value);
   passForm.full_name.value=temp;
   if (!(regular_hebrew.test(temp)))
      {
	alert("אנא רשמו את השם המלא בעברית בלבד.\nרב תודות.");
	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("אנא רשמו את כתובת הדואר האלקטרוני האדמיניסטרטיבית בתבנית נאותה.\nרב תודות.");
	    passForm.email_address.focus();
	    return false;
          }
      }
   // End of E-mail Address Checking

   // Beginning of User Status Checking
   o1=passForm.user_status_0.checked;
   o2=passForm.user_status_1.checked;
   if ((!(o1)) && (!(o2)))
      {
	alert("אנא בחרו במצב המשתמש.\nרב תודות.");
	return false;
      }
   // End of User Status Checking
   return true;
  }

/* validUploadFilesForm Function */
function validUploadFilesForm(passForm)
  {
   // Beginning of File Name Checking
   temp=trim(passForm.file_name.value);
   passForm.file_name.value=temp;
   if (temp=="")
      {
	alert("אנא רשמו את שם הקובץ.\nרב תודות.");
	passForm.file_name.focus();
	return false;
      }
   // End of File Name Checking

   // Beginning of File Selection Checking
   temp=trim(passForm.file_selection.value);
   passForm.file_selection.value=temp;
   if ((passForm.page_type.value=="insertion") && (temp==""))
      {
	alert("אנא בחרו בקובץ להעלאה.\nרב תודות.");
	passForm.file_selection.focus();
	return false;
      }

   /*
   if (temp!="")
      {
	temp=temp.substring((temp.length-3),(temp.length));
	temp=temp.toLowerCase();
	if ((temp!="doc") && (temp!="dot") && (temp!="xls") && (temp!="pdf") && (temp!="rtf") && (temp!="zip") && (temp!="rar") && (temp!="htm") && (temp!="tml"))
	   {
	    alert("תבנית הקובץ שבחרתם להעלות אינה נתמכת.\nאנא השתמשו בתבניות MS-Word, MS-Excel, RTF, PDF, ZIP, RAR, HTM או HTML בלבד.\nרב תודות.");
	    passForm.file_selection.focus();
	    return false;
	   }
      }
   */
   // End of File Selection Checking
   return true;
  }

/* validUpdatesBoardForm Function */
function validUpdatesBoardForm(passForm)
  {
   // Beginning of Regular Expressions Creating
   regular_date=/^((\d){1,2})(\.){1}((\d){1,2})(\.){1}((\d){4})$/;
   // End of Regular Expressions Creating

   // Beginning of Update Header Checking
   temp=trim(passForm.update_header.value);
   passForm.update_header.value=temp;
   if (temp=="")
      {
	alert("נא רשמו את כותרת העדכון.\nרב תודות.");
	passForm.update_header.focus();
	return false;
      }
   // End of Update Header Checking

   /*
   // Beginning of Update Content Checking
   temp=trim(passForm.update_content.value);
   passForm.update_content.value=temp;
   if (temp=="")
      {
	alert("נא רשמו את תוכן העדכון.\nרב תודות.");
	passForm.update_content.focus();
	return false;
      }
   // End of Update Content Checking
   */

   // Beginning of Update Area Checking
   if ((!(passForm.update_area_1.checked)) && (!(passForm.update_area_2.checked)))
      {
	alert("נא בחרו באזור העדכון.\nרב תודות.");
	return false;
      }
   // End of Update Area Checking

   // Beginning of Update Status Checking
   if ((!(passForm.update_status_1.checked)) && (!(passForm.update_status_2.checked)))
      {
	alert("נא בחרו במצב העדכון.\nרב תודות.");
	return false;
      }
   // End of Update Status Checking

   // Beginning of Update Expires Checking
   temp=trim(passForm.update_expires.value);
   passForm.update_expires.value=temp;
   if (!(regular_date.test(temp)))
      {
	alert("נא רשמו את תאריך התפוגה בתבנית DD.MM.YYYY.\nרב תודות.");
	passForm.update_expires.focus();
	return false;
      }
   // End of Update Expires Checking
   return true;
  }

function validGalleryForm(passForm)
  {
   // Beginning of Regular Expressions Creating
   regular_hebrew=/^([^a-zA-Z0-9_]{1,})$/;
   regular_digits=/^([0-9]{1,})$/;
   // End of Regular Expressions Creating

   // Beginning of PR Image Name Checking
   temp=trim(passForm.pr_image_name.value);
   passForm.pr_image_name.value=temp;
   if (passForm.page_type.value=="insertion")
      {
	temp=temp.substring((temp.length-3),(temp.length));
	temp=temp.toLowerCase();
	if ((temp!="jpg") && (temp!="jpeg") && (temp!="gif") && (temp!="png"))
	   {
	    alert("קובץ התמונה לתצוגה מקדימה שבחרתם להעלות חייב להיות באחת מן התבניות הבאות: JPG, JPEG, GIF או PNG.");
	    passForm.pr_image_name.focus();
	    return false;
	   }
      }
   // End of PR Image Name Checking

   // Beginning of OR Image Name Checking
   temp=trim(passForm.or_image_name.value);
   passForm.or_image_name.value=temp;
   if (passForm.page_type.value=="insertion")
      {
	temp=temp.substring((temp.length-3),(temp.length));
	temp=temp.toLowerCase();
	if ((temp!="jpg") && (temp!="jpeg") && (temp!="gif") && (temp!="png"))
	   {
	    alert("קובץ התמונה לתצוגה מלאה שבחרתם להעלות חייב להיות באחת מן התבניות הבאות: JPG, JPEG, GIF או PNG.");
	    passForm.or_image_name.focus();
	    return false;
	   }
      }
   // End of OR Image Name Checking

   // Beginning of Image Status Checking
   if ((!(passForm.image_status_1.checked)) && (!(passForm.image_status_2.checked)))
      {
	alert("נא לבחור במצב התמונה.");
	return false;
      }
   // End of Image Status Checking

   // Beginning of Hebrew Description Checking
   temp=trim(passForm.image_he_description.value);
   passForm.image_he_description.value=temp;
   // End of Hebrew Description Checking
   return true;
  }

/* validPagesCategoriesForm Function */
function validPagesCategoriesForm(passForm)
  {
   // Beginning of Regular Expressions Creating
   regular_hebrew=/^([^a-zA-Z0-9_]{1,})$/;
   // End of Regular Expressions Creating

   // Beginning of Category Name Checking
   temp=trim(passForm.category_name.value);
   passForm.category_name.value=temp;
   if (!(regular_hebrew.test(temp)))
      {
	alert("אנא רשמו את שם הקטגוריה באותיות בעברית בלבד.\nרב תודות.");
	passForm.category_name.focus();
	return false;
      }
   // End of Category Name Checking
   return true;
  }

/* validPagesContentsForm Function */
function validPagesContentsForm(passForm)
  {
   // Beginning of Regular Expressions Creating
   regular_english=/^([a-zA-Z0-9_]{1,})$/;
   regular_hebrew=/^([^a-zA-Z0-9_]{1,})$/;
   regular_digits=/^([0-9_]{1,})$/;
   // End of Regular Expressions Creating

   // Beginning of Page Name Checking
   temp=trim(passForm.page_name.value);
   passForm.page_name.value=temp;
   if (temp=="")
      {
	alert("אנא רשמו את שם העמוד.\nרב תודות.");
	passForm.page_name.focus();
	return false;
      }
   // End of Page Name Checking

   // Beginning of Page Title Checking
   temp=trim(passForm.page_title.value);
   passForm.page_title.value=temp;
   if (temp=="")
      {
	alert("אנא רשמו את כותרת העמוד.\nרב תודות.");
	passForm.page_title.focus();
	return false;
      }
   // End of Page Title Checking

   // Beginning of Page Description Checking
   temp=trim(passForm.page_description.value);
   passForm.page_description.value=temp;
   if (temp=="")
      {
	alert("אנא רשמו את תיאור העמוד.\nרב תודות.");
	passForm.page_description.focus();
	return false;
      }
   // End of Page Description Checking

   // Beginning of Page Keywords Checking
   temp=trim(passForm.page_keywords.value);
   passForm.page_keywords.value=temp;
   if (temp=="")
      {
	alert("אנא רשמו את מילות המפתח של העמוד.\nרב תודות.");
	passForm.page_keywords.focus();
	return false;
      }
   // End of Page Keywords Checking
   return true;
  }

/* validNavigationAppearanceOrderForm Function */
function validNavigationAppearanceOrderForm(passForm)
  {
   // Beginning of Regular Expressions Creating
   regular_digits=/^([0-9]{1,})$/;
   // End of Regular Expressions Creating

   pages_amount=passForm.pages_amount.value;

   for (i=1; i<=pages_amount; i++)
	{
	 exp ="temp=passForm.page_location_"+i+";";
	 eval(exp);

	 if (!(regular_digits.test(temp.value)))
	    {
	     alert("עליך לבחור בערך למספור עבור פריט "+i+" בשורה העליונה של התפריט העליון.\nהערך מוכרח להיות בספרות בלבד.");
	     temp.focus();
	     return false;
	    }
	}
   return true;
  }

/* validPagesNavigationForm Function */
function validPagesNavigationForm(passForm)
  {
   // Beginning of Regular Expressions Creating
   regular_hebrew=/^([^a-zA-Z0-9_]{1,})$/;
   regular_english=/^([a-zA-Z0-9_]{1,})$/;
   // End of Regular Expressions Creating

   // Beginning of Page Name Checking
   temp=trim(passForm.page_name.value);
   passForm.page_name.value=temp;
   if (temp=="")
      {
	alert("אנא רשמו את שם הפריט.\nרב תודות.");
	passForm.page_name.focus();
	return false;
      }
   // End of Page Name Checking

   // Beginning of Page URL Checking
   temp=trim(passForm.page_url.value);
   passForm.page_url.value=temp;
   if (temp=="")
      {
	alert("אנא רשמו את URL הפריט.\nרב תודות.");
	passForm.page_url.focus();
	return false;
      }
   // End of Page URL Checking
   return true;
  }

function doSmartLoading(div_id)
  {
   if (BrowserDetect.browser=="Firefox")
      {
	exp1="document.getElementById('"+div_id+"').innerHTML='<div align=\"center\" style=\"margin-top: 13px\"><img src=\"images/other/ajax-loader-bar.gif\" alt=\"\" width=\"128px\" height=\"15px\" /></div>';";
      }
   else if (BrowserDetect.browser=="Explorer")
      {
	exp1="document.getElementById('"+div_id+"').innerHTML='<div align=\"center\" style=\"margin-top: 14px\"><img src=\"images/other/ajax-loader-bar.gif\" alt=\"\" width=\"128px\" height=\"15px\" /></div>';";
      }
   else
      {
	exp1="document.getElementById('"+div_id+"').innerHTML='<div align=\"center\" style=\"margin-top: 13px\"><img src=\"images/other/ajax-loader-bar.gif\" alt=\"\" width=\"128px\" height=\"15px\" /></div>';";
      }

   eval(exp1);

   str ="intval=window.setInterval(\"updateTimer('"+div_id+"')\", 2000);";
   eval(str);
  }

function changeSmartForm(div_id)
  {
   if (BrowserDetect.browser=="Firefox")
      {
	html_code="<div align=\"center\" style=\"font-size: 12px; margin-top: 3px\">פרטיך נשלחו בהצלחה!<br />נציגנו יצרו איתך קשר בהקדם.</div>";
      }
   else if (BrowserDetect.browser=="Explorer")
      {
       html_code="<div align=\"center\" style=\"font-size: 12px; margin-top: 4px\">פרטיך נשלחו בהצלחה!<br />נציגנו יצרו איתך קשר בהקדם.</div>";
      }
   else
      {
       html_code="<div align=\"center\" style=\"font-size: 12px; margin-top: 3px\">פרטיך נשלחו בהצלחה!<br />נציגנו יצרו איתך קשר בהקדם.</div>";
      }

   exp="document.getElementById('"+div_id+"').innerHTML='"+html_code+"';";
   eval(exp);
  }

sec=0;
function updateTimer(div_id)
  {
   sec++;

   if (sec==2)
      {
	sec=0;
	window.clearInterval(intval);
	changeSmartForm(div_id);
      }
  }

/* validSmartContactForm Function */
function validSmartContactForm(form_id, button_id, div_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})$/;
   // 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('taamal_form[full_name]', '"+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;

   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;
	}

   exp ="Set_Cookie('taamal_form[phone_number]', '"+temp+"', 30, '/');";
   eval(exp);
   // End of Phone Number Checking

   ajaxFunction(form_id);
   doSmartLoading(div_id);
   return false;
  }