window.onload = function()
{}



//begin validation checks
  function valButton(btn) {
    var cnt = -1;
    for (var i=btn.length-1; i > -1; i--) {
        if (btn[i].checked) {cnt = i; i = -1;}
    }
    if (cnt > -1) return btn[cnt].value;
    else return null;
}
  function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}

function ValidateEmail(){
	var emailID=document.getElementById("txtEmail")
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email ID")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	return true
 }
  

	
	
function checkForm(form) {
alert(form);
	  var af=new Array();
		//your info
      af[0]="Name is required";
	  af[1]="Phone number is required";
	  af[2]="Best time to call is required";
	  af[3]="Please enter details about your request.";
	  	  
//Loop through forms elements	 

for (var i = 0; i < form.elements.length; i++) {
	 
	 
	 
	//Checks if Name is only Letters or Numbers
	if(i==0 && form.elements[0].value!=""){
		if(isAlphanumeric(form.elements[0], "Only Letters or Numbers Please")==false){
		return false;
	}
	}
	
	//Checks if HomePhone is only Numbers

	if(i==1 && form.elements[1].value!=""){
		if(isAlphanumeric(form.elements[1], "Only Letters or Numbers Please")==false){
		return false;
	}
	}
	
}


// If the element's string matches the regular expression it is all numbers
function isNumeric(elem, helperMsg){
	var numericExpression = /^[0-9]+$/;
	if(elem.value.match(numericExpression)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}



// If the element's string matches the regular expression it is numbers and letters
function isAlphanumeric(elem, helperMsg){
	var alphaExp = /^[0-9a-zA-Z ]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}
function check_length(field,min,max,fieldname){
 	
	if(field.value.length>max || field.value.length<min){
		alert(fieldname+" Minimum "+min+" characters and Maximum "+max+" characters");
		field.focus();
		return false;
	}else{
		return true;
	}
}
