// email

function checkEmail (strng) {
var error="";
if (strng == "") {
   error = "Please enter an email address.\n";
}

    var emailFilter=/^.+@.+\..{2,3}$/;
    if (!(emailFilter.test(strng))) { 
       error = "Please enter a valid email address.\n";
    }
    else {
//test email for illegal characters
       var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
         if (strng.match(illegalChars)) {
          error = "The email address contains illegal characters.\n";
       }
    }
return error;    
}

// non-empty textbox

function isEmpty(strng,fieldname) {
var error = "";
  if (strng.length == 0) {
     error = fieldname + " has not been filled in.\n"
  }
return error;	  
}

// valid selector from dropdown list

function checkDropdown(choice) {
var error = "";
    if (choice == 0) {
    error = "Please choose a state.\n";
    }    
return error;
}   

function checkQuoteForm(theForm) {
    var why = "";
    why += isEmpty(theForm._tbFirstName.value,"First Name");
    why += isEmpty(theForm._tbLastName.value,"Last Name");
 	why += isEmpty(theForm._tbpractice.value,"Hospital/Practice");    
 	why += isEmpty(theForm._tbAddress1.value,"Address 1");     
 	why += isEmpty(theForm._tbCity.value,"City");
 	why += checkDropdown(theForm._tbstate.value);      		 	
 	why += isEmpty(theForm._tbzip.value,"Zip");
 	why += checkEmail(theForm._tbEmail.value);		 	     
 	why += isEmpty(theForm._tbMessage.value,"Your message");		
    if (why != "") {
       alert(why);
       return false;
    }
return true;
}

function checkRequestForm(theForm) {
 var why = "";
    why += isEmpty(theForm._tbFirstName.value,"First Name");
    why += isEmpty(theForm._tbLastName.value,"Last Name");
 	why += checkEmail(theForm._tbEmail.value);		 	         
 	why += isEmpty(theForm._tbMessage.value,"Your message");
 	if (why != "") {
       alert(why);
       return false;
    }
return true;
}

function checkFormEmail(theForm) {
 var why = "";;
 	why += checkEmail(theForm._nlEmail.value);		 	         
 	if (why != "") {
       alert(why);
       return false;
    }
return true;
}

function toggleForms() {
	radios = document.getElementsByName('formtoggle');
	if (radios[0].checked) { 
		document.getElementById('quote').style.display = "block";
		document.getElementById('general').style.display = "none";
		 }
	if(radios[1].checked) { 
		document.getElementById('quote').style.display = "none";
		document.getElementById('general').style.display = "block";
		 }
	}