function validEmail(email){
    invalidChars = "/:,;"
    
    if((email=="") || (email=="Email Address")){
        return false
    }
    
    for(i=0;i<invalidChars.length;i++){
        badChar = invalidChars.charAt(i)
        if(email.indexOf(badChar,0)>-1){
            return false;
        }
    }
    
    atPos =  email.indexOf("@",1)
    if(atPos == -1){
        return false
    }
    if(email.indexOf("@",atPos+1)>-1){
        return false
    }
    
   periodPos = email.indexOf(".",atPos)
    if(periodPos == -1){
        return false
    } 
    
    if(periodPos+3 > email.length){
        return false
    }
    return true
}


function validateForm() {
	var errors='';
    var emailFilter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    var zipFilter = /^\d{5}$/;
    var phoneFilter = /^\d{3}-\d{3}-\d{4}$/;


	var phoneNumber = document.forms[0].phone1.value+'-'+document.forms[0].phone2.value+'-'+document.forms[0].phone3.value;

	if ((document.forms[0].fName.value == "") || (document.forms[0].fName.value == "First Name")) {
        	errors += '- First name is required\n';
    	} 
    
    	if ((document.forms[0].lName.value == "") || (document.forms[0].lName.value == "Last Name")){
        	errors += '- Last name is required\n';
    	}       
    	
    	if ((document.forms[0].address1.value == "") || (document.forms[0].address1.value == "Address 1")){
        	errors += '- Address1 is required\n';
    	}
    	
    	if ((document.forms[0].city.value == "") || (document.forms[0].city.value == "City")) {
        	errors += '- City is required\n';
    	} 
    	
    	if ((document.forms[0].state.value == "") || (document.forms[0].state.value == "Select State")) {
        	errors += '- State is required\n';
    	} 
    	 
    	if ((!zipFilter.test(document.forms[0].zip.value)) || (document.forms[0].zip.value =="Zip")){
        	errors += '- Zip code should be 5 digits (e.g 12345)\n';
    	} 
    	
    	if (!phoneFilter.test(phoneNumber)) {
        	errors += '- Phone number should be 10 digits (e.g 1112223333)\n';
    	}
  
    	if (!emailFilter.test(document.forms[0].email.value)) {
        	errors += '- A valid email address is required (e.g abc@xyz.com)\n';
    	}
    	 
    	//if (document.forms[0].insurance.value == "") {
        //	errors += '- Insurance Provider is required\n';
   	//}       
    
    
    	if (errors) 
        	alert('The following error(s) occurred:\n'+errors);
    
    	document.MM_returnValue = (errors == '');
}

function submitIt(contactForm){
    if(!validEmail(contactForm.email.value)){
        alert("Invalid email address")
        contactForm.email.focus()
        contactForm.email.select()
        return false  
    }
    
    if((contactForm.fName.value=="") || (contactForm.fName.value=="First Name")){
        alert("First name cannot be blank")
        return false
    }
    
    if((contactForm.lName.value=="") || (contactForm.lName.value=="Last Name")){
        alert("Last name cannot be blank")
        return false
    }
    
     if((contactForm.address1.value=="") ||(contactForm.address1.value=="Address 1")){
        alert("Address cannot be blank")
        return false
    }
    
     if((contactForm.city.value=="") ||(contactForm.city.value=="City")){
        alert("City cannot be blank")
        return false
    }
    
     if(contactForm.state.value==""){
        alert("State cannot be blank")
        return false
    }
    
     if((contactForm.zip.value=="")||(contactForm.zip.value=="Zip")){
        alert("Zip cannot be blank")
        return false
    }
	
	if(contactForm.phone1.value==""){
        alert("Phone must have total of 10 digits")
        return false
    }
    
        if(contactForm.phone2.value==""){
        alert("Phone must have total of 10 digits")
        return false
    }
    
        if(contactForm.phone3.value==""){
        alert("Phone must have total of 10 digits")
        return false
    }
    
     if(contactForm.btt.value==""){
        alert("Best Time To Call cannot be blank")
        return false
    }
    
	alert(contactForm.chg01.value);
	alert(contactForm.chg02.value);
	alert(contactForm.chg03.value);
    /*if(contactForm.chg01.value==""){
        alert("Have you been in pain for 6 months or more? Must be populated")
        return false
    }
    
     if(contactForm.chg02.value==""){
        alert("Orthopedic or Neurosurgeon question must be answered")
        return false
    }
    
     if(contactForm.chg03.value==""){
        alert("Have you had an MRI or CT Scan in the last 5 years? This question must be answered")
        return false
    }*/
    
     if(contactForm.insurance.value==""){
        alert("Must select Insurance provider")
        return false
    }
    
}

function numbersOnly(evt) {
    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : 
        ((evt.which) ? evt.which : 0));
    if (charCode > 31 && (charCode < 48 || charCode > 57)) {       
        return false;
	  
    }
    return true;
}


function lettersOnly(evt) {
    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : 
        ((evt.which) ? evt.which : 0));
    if (charCode > 31 && (charCode!= 45) && (charCode!= 32) &&(charCode < 65 || charCode > 90) && 
        (charCode < 97 || (charCode > 122))) {       
        return false;
    }
    return true;
}
