/* Trim Function */
function trim(value)
 {
  temp=value;
  return temp.replace(/^\s*(\b.*\b|)\s*$/, "$1");
 }

/* 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=0; i<number_of_fields; i++)
	{
	 if (field==i)
	  {
	   emphasis="document.all."+question+"_"+i+".style.backgroundColor='#ff0000'";
	   eval(emphasis);
	  }
	 else
	  {
	   emphasis="document.all."+question+"_"+i+".style.backgroundColor='#ffffcc'";
	   eval(emphasis);
	  }
	}
  }

/* Checkbox Emphasis Function */
function checkbox_emphasis(cell)
 {
  cell_="document.all."+cell+".checked";
  if (eval(cell_ ))
     {
      emphasis="document.all."+cell+".style.backgroundColor='#ff0000'";
      eval(emphasis);
     }
  else
    {
     emphasis="document.all."+cell+".style.backgroundColor='#ffffcc'";
     eval(emphasis);
    }
 }

/* validSearchForm Function */
function validSearchForm(form_id)
  {
  tmp="passForm=document.forms['"+form_id+"'];";
  eval(tmp);

   // Beginning of Search Query Checking
   temp=trim(passForm.as_q.value);
   passForm.as_q.value=temp;

   if (passForm.language.value=="en")
      { message="Please enter a query in the search field."; }

   if (passForm.language.value=="he")
      { message="אנא הקלד ערך בתיבת החיפוש.\nרב תודות."; }

   if (temp=="")
      {
	alert(message);
	passForm.as_q.focus();
	return false;
      }
   // End of Search Query Checking
   return true;
  }

/* Clear Text Click Function */
function clear_text_click()
  {
   temp=trim(document.getElementById("search_query").value);
   document.getElementById("search_query").value=temp;

   if (temp=="הקלד ערך לחיפוש")
      { document.getElementById("search_query").value=""; }

   return true;
  }

/* Clear Text Blur Function */
function clear_text_blur()
  {
   temp=trim(document.getElementById("search_query").value);
   document.getElementById("search_query").value=temp;
   if (temp=="")
      { document.getElementById("search_query").value="הקלד ערך לחיפוש"; }
   return true;
  }

/* validFindEmployeeForm Function */
function validFindEmployeeForm(form_id)
  {
  tmp="passForm=document.forms['"+form_id+"'];";
  eval(tmp);

   // Beginning of Regular Expressions Creating
   regular_hebrew=/^([^a-zA-Z0-9_]{2,})$/;
   // End of Regular Expressions Creating

   // Beginning of Name2Find Checking
   temp=trim(passForm.name_to_find.value);
   passForm.name_to_find.value=temp;
   if (!(regular_hebrew.test(temp)))
      {
	alert("השם לחיפוש מוכרח לכלול 2 אותיות לפחות ולא יכול לכלול אותיות בלועזית, ספרות או סימנים אחרים.\nנא תקנו את הרישום.\nרב תודות.");
	passForm.name_to_find.focus();
	return false;
      }
   // End of Name2Find Checking
   return true;
  }

/* 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("אנא רשמו את שמכם המלא.\nרב תודות.");
      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("אנא רשמו את מספר הטלפון שלכם בספרות, קווים מפרידים וסימני + בלבד.\nרב תודות.");
      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("כתובת הדואר האלקטרוני נרשמה בתבנית שגויה.\nאנא תקנו את הרישום.\nרב תודות.");
          passForm.email_address.focus();
          return false;
	  }
     }
  // End of E-mail Address Checking

  // Beginning of Message Subject Checking
  temp=trim(passForm.message_subject.value);
  passForm.message_subject.value=temp;
  if (temp=="")
     {
      alert("אנא רשמו את נושא המסר.\nרב תודות.");
      passForm.message_subject.focus();
      return false;
     }
  // End of Message Subject Checking

  // Beginning of Message Content Checking
  temp=trim(passForm.message_content.value);
  passForm.message_content.value=temp;
  if (temp=="")
     {
      alert("אנא רשמו את תוכן המסר.\nרב תודות.");
      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 Type Checking
   o1=passForm.file_type_0.checked;
   o2=passForm.file_type_1.checked;
   if ((!(o1)) && (!(o2)))
      {
	alert("נא בחרו בסוג הרשומה.\nרב תודות.");
	return false;
      }
   // End of File Type Checking

   // Beginning of File Name Checking
   temp=trim(passForm.file_name.value);
   passForm.file_name.value=temp;
   if ((passForm.file_type_1.checked) && (((passForm.page_type.value=="insertion") && (temp=="")) || ((passForm.page_type.value=="modification") && (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.file_type_1.checked) && (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

   // Beginning of File URL Checking
   temp=trim(passForm.file_url.value);
   passForm.file_url.value=temp;
   if ((passForm.file_type_0.checked) && (temp==""))
      {
	alert("אנא רשמו את כתובת הקישור.\nרב תודות.");
	passForm.file_url.focus();
	return false;
      }
   // End of File URL Checking

   // Beginning of File Description Checking
   temp=trim(passForm.file_description.value);
   passForm.file_description.value=temp;
   if (temp=="")
      {
	alert("אנא רשמו תיאור קצר עבור הקובץ.\nרב תודות.");
	passForm.file_description.focus();
	return false;
      }
   // End of File Description Checking

   // Beginning of File Status Checking
   o1=passForm.file_status_0.checked;
   o2=passForm.file_status_1.checked;
   if ((!(o1)) && (!(o2)))
      {
	alert("נא בחרו במצב הרשומה.\nרב תודות.");
	return false;
      }
   // End of File Status Checking
   return true;
  }

/* validDecisionsForm Function */
function validDecisionsForm(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 Meeting Date Checking
   temp=trim(passForm.meeting_date.value);
   temp=passForm.meeting_date.value;
   if (!regular_date.test(temp))
      {
	alert("נא רשמו את תאריך הישיבה בתבנית DD.MM.YYYY.\nרב תודות.");
	passForm.meeting_date.focus();
	return false;
      }
   // End of Meeting Date Checking
   return true;
  }

/* validArticlesForm Function */
function validArticlesForm(passForm)
  {
   // Beginning of Article Title Checking
   temp=trim(passForm.article_title.value);
   temp=passForm.article_title.value;
   if (temp=="")
      {
	alert("נא רשמו את כותרת המאמר.\nרב תודות.");
	passForm.article_title.focus();
	return false;
      }
   // End of Article Title Checking

   // Beginning of File Name Checking
   temp=trim(passForm.file_name.value);
   passForm.file_name.value=temp;
   if ((passForm.file_selection.value!="") && (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.file_name.value!="") && (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;
  }

/* validNewCommentForm Function */
function validNewCommentForm(passForm)
 {
  // 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 Full Name Checking
  temp=trim(passForm.full_name.value);
  passForm.full_name.value=temp;
  if (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אנא תקנו את הרישום.\nרב תודות.");
          passForm.email_address.focus();
          return false;
	  }
     }
  // End of E-mail Address Checking

  // Beginning of Comment Subject Checking
  temp=trim(passForm.comment_subject.value);
  passForm.comment_subject.value=temp;
  if (temp=="")
     {
      alert("אנא רשמו את כותרת התגובה.\nרב תודות.");
      passForm.comment_subject.focus();
      return false;
     }
  // End of Comment Subject Checking

  // Beginning of Comment Content Checking
  temp=trim(passForm.comment_content.value);
  passForm.comment_content.value=temp;
  if (temp=="")
     {
      alert("אנא רשמו את תוכן התגובה.\nרב תודות.");
      passForm.comment_content.focus();
      return false;
     }
  // End of Comment Content Checking
  return true;
 }

/* Add New Comment Function */
function add_new_comment(aid)
  {
   if (document.myForm.article_id.value=="")
      {
	document.getElementById("new_comment_area").style.display="";
	document.myForm.article_id.value=aid;
      }
   else
      {
	document.getElementById("new_comment_area").style.display="none";
	document.myForm.article_id.value="";
      }
   return true;
  }

/* Show All Comments Function */
function show_all_comments(aid)
  {

   temp="var_name='open_comments_"+aid+"';";
   eval(temp);

   temp2="var_name2='comments_article_"+aid+"';";
   eval(temp2);

   if (document.getElementById(var_name).value=="1")
      {
	document.getElementById(var_name2).style.display="none";
	document.getElementById(var_name).value="";
      }
   else
      {
	document.getElementById(var_name2).style.display="";
	document.getElementById(var_name).value="1";
      }
   return true;
  }