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

/* validContactForm Function */
function validContactForm(form_id, div_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=="") || (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 (!(regular_email_address.test(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;
  // End of Message Content Checking
  
  var full_name=$('#contact_full_name').val();
  var phone_number=$('#contact_phone_number').val();
  var email_address=$('#contact_email_address').val();
  var message_content=$('#contact_message_content').val();

   $.get('send_mail_procedure.php', { full_name: full_name, phone_number: phone_number, email_address: email_address, message_content: message_content }, function(data) {
	alert('פנייתך נשלחה בהצלחה.\nנציגנו יצרו איתך קשר בתוך 24 שעות.\nהמשך גלישה נעימה.');
	$('#contact_popup').css("display", "none");
	return false;
   });
  
  return false;
 }

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

/* website_redirect Function */
function website_redirect(link_url)
  {
   exp ="window.open('"+link_url+"');";
   eval(exp);
  }

/* clear_field Function */
function clear_field(sel_id, sel_option, sel_text)
 {
  eval("obj=document.getElementById('"+sel_id+"');");
  if ((sel_option=="1") && (obj.value==""))
     { obj.value=sel_text; }
     
  if ((sel_option=="0") && (obj.value==sel_text))
     { obj.value=""; }
 }
