
function ValidateNo(NumStr, String){
    for(var Idx=0; Idx<NumStr.length; Idx++)
    {
        var Char = NumStr.charAt(Idx);
        var Match = false;

        for(var Idx1=0; Idx1<String.length; Idx1++)
        {
            if(Char == String.charAt (Idx1))
                Match = true;
        }

        if (!Match)
            return false;
    }
    return true;
} 

function validateNumber(number){
	var patt=/\+?(\(\d+\)|\d+)\s?\d+-?\d+/;
	if(number.replace(patt,"") == ""){
		return true;
	}
	return false;
}

function validEmail(email) {
    invalidChars = " /:,;אבגדהוזחטיכלמנסעפצקרשת";         
    if (email == "") {// cannot be empty
      return false
    }
    for (i=0; i<invalidChars.length; i++) { // does it contain any invalid characters?
      badChar = invalidChars.charAt(i)
      if (email.indexOf(badChar,0) > -1) {
        return false
      }
    }
    atPos = email.indexOf("@",1)            // there must be one "@" symbol
    if (atPos == -1) {
      return false
    }
    if (email.indexOf("@",atPos+1) != -1) { // and only one "@" symbol
      return false
    }
    periodPos = email.indexOf(".",atPos)
    if (periodPos == -1) {                  // and at least one "." after the "@"
      return false
    }
    if (periodPos+3 > email.length) {       // must be at least 2 characters after the "."
      return false
    }
    return true
}
    
function validate(){	  
    str="";
    strN="";
	strL="";
    flag=true;
    focos=0;
    
    if((document.formi.fname.value.length<2)){
      flag=false;
      str=str+err_arr['fname']+"<br>";
      if (focos==0) {document.formi.fname.focus();focos=1 }
      //return false;
    }
	
	if((document.formi.lname.value.length<2)){
      flag=false;
      str=str+err_arr['lname']+"<br>";
      if (focos==0) {document.formi.lname.focus();focos=1 }
      //return false;
    }

    if((document.formi.email.value.length==0)){
      flag=false;
      str=str + err_arr['email_empty']+"<br>";
      if (focos==0) {document.formi.email.focus();focos=1 }
      //return false; 
    }
    if (!validEmail(document.formi.email.value) && (document.formi.email.value!="")) {
      str=str + err_arr['email_invalid']+"<br>";
      flag=false;
      if (focos==0) {document.formi.email.focus();focos=1 }
      //return false
    }
    
	if(validateNumber(document.formi.phone.value)==false && document.formi.phone.value.length!=""){
		flag=false;
      	str=str+err_arr['phone_invalid']+"<br>";
      	if (focos==0) {document.formi.phone.focus();focos=1 }
		}
    if(flag==true){
			return true;
    } else {
    	str = str + '<br>';
      if (document.layers) {
        document.layers['contactalert'].document.close();
        document.layers['contactalert'].document.write(str);
        document.layers['contactalert'].document.close();       
      } else {
        if (document.all) {
          document.all.contactalert.innerHTML = str;
        } else {
          document.getElementById('contactalert').innerHTML = str;
        }
      } 
      
      document.location.href='#';  
      return false;
    }
}
