// --------------------- vcenter check input --------------
function openBrWindow(theURL,winName,features)
{
   window.open(theURL,winName,features);
}

function check_input()
{
   language = document.visitForm.language.value;

   userName=document.visitForm.userName.value;
   if ((userName == "") || (userName == " ") || (userName == "  ") || (userName == "   ") || (userName.length < 3))
      {
       if (language == "hebrew")
          window.alert('נא למלא שם פונה\t');
       else
          window.alert('Please enter your name\t');
       document.visitForm.userName.focus();
       return false;
      }

   tz=document.visitForm.tz.value;
   if ((tz == "") || (!nCheck(tz)))
      {
       if (language == "hebrew")
          alert('מספר תעודת זהות/דרכון שגוי, יש להקיש ספרות בלבד');
       else
          window.alert('Wrong ID/passport no. Please enter digits only\t');
      document.visitForm.tz.focus();
      return false;
      }

   email_add=document.visitForm.email_add.value;
   if ((email_add == "") || (email_add == " ") || (!checkEmail(email_add)))
      {
       if (language == "hebrew")
          alert('כתובת דוא"ל לא תקינה');
       else
          window.alert('Wrong email address\t');
       document.visitForm.email_add.focus();
       return false;
      }

   studentsNumber=document.visitForm.studentsNumber.value;
   if ((studentsNumber == "") || (!nCheck(studentsNumber)) || (studentsNumber == 0) || (studentsNumber > 44))
      {
       if (language == "hebrew")
          alert('מספר המשתתפים שגוי, יש להקיש ספרות בלבד, עד 44 משתתפים');
       else
          window.alert('Please enter number of participants, digits only,\t\n maximum 44 per group');
      document.visitForm.studentsNumber.focus();
      return false;
      }

   txt_dtub=document.visitForm.txt_dtub.value;
   txt_dtub_dd = txt_dtub.substring(0,2);
   //if (txt_dtub_dd < 10) txt_dtub_dd= "0" + txt_dtub_dd; 
   txt_dtub_mm = txt_dtub.substring(3,5);
   //if (txt_dtub_mm < 10) txt_dtub_mm= "0" + txt_dtub_mm; 
   txt_dtub_yyyy = txt_dtub.substring(6,10);
   txt_dtub_date = txt_dtub_yyyy +txt_dtub_mm +txt_dtub_dd;

   full_today = new Date();
   dd = full_today.getDate();
   if (dd < 10) dd= "0" + dd;
   mm = full_today.getMonth() + 1;
   if (mm < 10) mm= "0" + mm; 
   yyyy = full_today.getFullYear();
   today_date = yyyy +"" +mm +"" +dd;

   if ((txt_dtub_date == today_date) || (txt_dtub_date < today_date))
      {
       if (language == "hebrew")
          alert('המועד המועדף לביקור שנבחר אינו תקין\t\nיש לבחור מועד ביקור מאוחר מהיום');
       else
          window.alert('Preferred date must be later than the current date\t');
       document.visitForm.txt_dtub.focus();
       return false;
      }

   phone=document.visitForm.phone.value;
   if ((phone == "") || (!nCheck(phone)))
      {
       if (language == "hebrew")
          alert('מספר טלפון שגוי, יש להקיש ספרות בלבד');
       else
          window.alert('Wrong phone number, Please enter digits only\t');
      document.visitForm.phone.focus();
      return false;
      }
   if (phone.length < 9)
      {
       if (language == "hebrew")
          alert('מספר טלפון שגוי, יש להקיש מספר כולל קידומת, בספרות בלבד');
       else
          window.alert('Wrong phone number, Please enter digits only\t');
      document.visitForm.phone.focus();
      return false;
      }

   fax=document.visitForm.fax.value;
   if ((fax != "") && (!nCheck(fax))) 
      {
       if (language == "hebrew")
          alert('מספר פקס שגוי, יש להקיש ספרות בלבד');
       else
          window.alert('Wrong fax number, Please enter digits only\t');
      document.visitForm.fax.focus();
      return false;
      }
   if ((fax != "") && (fax.length < 9)) 
      {
       if (language == "hebrew")
          alert('מספר פקס שגוי, יש להקיש מספר כולל קידומת, בספרות בלבד');
       else
          window.alert('Wrong fax number, Please enter digits only\t');
      document.visitForm.fax.focus();
      return false;
      }

 return true;
}  //end function

 function nCheck(full_tz) 
  {
    //this string stores all the characters which are valid, each entered character will be checked
    //against this list for validity
    var validInput = "0123456789"; 
       //cycle through 'full_tz' checking that the only digits there are valid
       for (i=0; i < full_tz.length; i++) 
           {
            var character = full_tz.charAt(i);           // check if evry char from input exsist in validInput
            if (validInput.indexOf(character) == -1)  // if exsist we get the position (who cares) if not, -1.
               {
                return false;  // invalid input
               }
           }
           return true;  // valid input
   }


function checkEmail(strEmail)
{
//return /^\w+@([\w\-]+\.)+\w{2,3}$/.test(strEmail);
return /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/.test(strEmail);

}




