
/* SUBMIT CONTACT FORM VALIDATION */
function validEmail(email) {
	invalidChars = ' !#$%^&*(){}[]+=~`?/:;,"'

	
	if (email == "") {
		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 "@"
		return false;
	}
	periodPos = email.indexOf(".",atPos+1)  //and at least one "." after the "@"
		if (periodPos == -1) {
		return false;
	}
	if (email.charAt(atPos+1) == ".") {	//is there a "." right after the "@"
		return false;
	}
	if (periodPos+3 > email.length) {  	//must be at least 2 characters after the "."
		return false;
	}
	return true;
}

function validateEmailSignup(form) {
	
	if (form.fname.value == '') {
		alert("Please fill in your first name.");
		form.fname.focus();
		form.fname.select();
		return false;
	}
	if (form.lname.value == '') {
		alert("Please fill in your last name.");
		form.lname.focus();
		form.lname.select();
		return false;
	}
	if (!validEmail(form.femail.value)) {
		alert("A valid E-mail Address is required.");
		form.femail.focus();
		form.femail.select();
		return false;
	}
	
	var myindexvalue = form.faddresstype.value
	var myindex = form.faddresstype.selectedIndex
	if (myindexvalue == 0) {
		alert("Please select an Address Type.");
		form.faddresstype.focus();
		return false;
	}
	
	if (form.faddress.value == '') {
		alert("Please fill in your address.");
		form.faddress.focus();
		form.faddress.select();
		return false;
	}
	if (form.fcity.value == '') {
		alert("Please fill in your city.");
		form.fcity.focus();
		form.fcity.select();
		return false;
	}
	
	var myindexvalue = form.fstate.value
	var myindex = form.fstate.selectedIndex
	if (myindexvalue == 0) {
		alert("Please select a State.");
		form.fstate.focus();
		return false;
	}
	var myindexvalue = form.fcountry.value
	var myindex = form.fcountry.selectedIndex
	if (myindexvalue == 0) {
		alert("Please select a Country.");
		form.fcountry.focus();
		return false;
	}
	
	if (form.fzip.value == '') {
		alert("Please fill in your Zip Cpde.");
		form.fzip.focus();
		form.fzip.select();
		return false;
	}
	if (form.fphonework.value == '') {
		alert("Please fill in your phone number.");
		form.fphonework.focus();
		form.fphonework.select();
		return false;
	}
	return true;
}
	
function ValidateSubmit(form) {
	
	
	var myindexvalue = form.referrer.value
	var myindex = form.referrer.selectedIndex
	if (myindexvalue == 0) {
		alert("Please select a recipient.");
		return false;
	}
		
	if (form.name.value == '') {
		alert("Please fill in your first name.");
		form.name.focus();
		form.name.select();
		return false;
	}
	if (form.last_name.value == '') {
		alert("Please fill in your last name.");
		form.last_name.focus();
		form.last_name.select();
		return false;
	}
	if (!validEmail(form.email.value)) {
		alert("A valid E-mail Address is required.");
		form.email.focus();
		form.email.select();
		return false;
	}
	if (form.comments.value == '') {
		alert("Please fill in a comment.");
		form.comments.focus();
		form.comments.select();
		return false;
	}
	
	//if we made it to here, everything's valid, so return true
	return true
	
}


/* GET A QUOTE FORM VALIDATION*/
function GetQuoteValidation(form) {
	if (form.name.value == '') {
		alert("Please fill in your name.");
		form.name.focus();
		form.name.select();
		return false;
	}
	
	if (form.street.value == '') {
		alert("Please fill in your street address.");
		form.street.focus();
		form.street.select();
		return false;
	}
	if (form.city.value == '') {
		alert("Please fill in your city.");
		form.city.focus();
		form.city.select();
		return false;
	}
	if (form.postal.value == '') {
		alert("Please fill in your postal code.");
		form.postal.focus();
		form.postal.select();
		return false;
	}
	if (form.home_phone.value == '') {
		alert("Please fill in your phone number.");
		form.home_phone.focus();
		form.home_phone.select();
		return false;
	}
	
	if (!validEmail(form.email.value)) {
		alert("A valid E-mail Address is required.");
		form.email.focus();
		form.email.select();
		return false;
	}
	var check = 0;
   	//loop through radio buttons and check for values
   	for (var i = 0; i < 2; i++)
   	{
    	var checked = form.referred[i].checked;
     	if (checked)
      	{
       		check = 1;
      	}
    }
	//if checked post the form
	if (check != 1)
	{
     	alert ("Please select an option for were you referred by an existingi policyholder.");
     	return false;
    }
	
	var myindex = form.hear_about.selectedIndex
	if (myindex==0)  
	{
		alert ("Please select an option for where did you hear about us.");
		return false;	
	}
	
	if (form.contact_home.value == '') {
		alert("Please fill in your contact phone number.");
		form.contact_home.focus();
		form.contact_home.select();
		return false;
	}

	if (!validEmail(form.contact_email.value)) {
		alert("A valid contact e-mail address is required.");
		form.contact_email.focus();
		form.contact_email.select();
		return false;
	}
return true;	
}


/* AUTO BLOCK SELECTION */
function TypeOfLost(form)
{
	var myindex = form.insurance_lost.selectedIndex
	if (myindex==0) return false;
	if (myindex==2)
	{
		document.getElementById("auto_block").style.display = "inline";
		document.getElementById("auto_submitted").value = 1;
	}
	else
	{
		document.getElementById("auto_block").style.display = "none";
		document.getElementById("auto_submitted").value = 0;
	}
}
/* END  AUTO BLOCK SELECTION */


/* MAKE A CLAIM FORM VALIDATION*/
function MakeClaimValidation(form) {

	if (form.personal_name.value == '') {
		alert("Please fill in the name of the policy holder.");
		form.personal_name.focus();
		form.personal_name.select();
		return false;
	}
	
	if (form.personal_street.value == '') {
		alert("Please fill in your street number and name.");
		form.personal_street.focus();
		form.personal_street.select();
		return false;
	}
	if (form.personal_city.value == '') {
		alert("Please fill in your city.");
		form.personal_city.focus();
		form.personal_city.select();
		return false;
	}
	var myindex6 = form.personal_prov.selectedIndex
	if (myindex6==0)  
	{
		alert ("Please select a province");
		return false;	
	}
	
	var myindex5 = form.personal_country.selectedIndex
	if (myindex5==0)  
	{
		alert ("Please select a country");
		return false;	
	}
	
	if (form.personal_zip.value == '') {
		alert("Please fill in your postal code.");
		form.personal_zip.focus();
		form.personal_zip.select();
		return false;
	}
	if (form.personal_home_phone.value == '') {
		alert("Please fill in your home phone number.");
		form.personal_home_phone.focus();
		form.personal_home_phone.select();
		return false;
	}
	if (form.personal_cell_phone.value == '') {
		alert("Please fill in your cell phone number.");
		form.personal_cell_phone.focus();
		form.personal_cell_phone.select();
		return false;
	}
	var myindex = form.personal_best_number.selectedIndex
	if (myindex==0)  
	{
		alert ("Please select an option for the best number you can be reached at.");
		return false;	
	}
	
	
	if (!validEmail(form.personal_email.value)) {
		alert("A valid E-mail Address is required.");
		form.personal_email.focus();
		form.personal_email.select();
		return false;
	}
	
	
	
	var myindex3 = form.insurance_lost.selectedIndex
	if (myindex3==0)  
	{
		alert ("Please select a type of lost");
		return false;	
	}
	
	if (form.insurance_loss.value == '') {
		alert("Please fill in location of the loss.");
		form.insurance_loss.focus();
		form.insurance_loss.select();
		return false;
	}
	if (form.insurance_details_loss.value == '') {
		alert("Please fill in details regarding the loss.");
		form.insurance_details_loss.focus();
		form.insurance_details_loss.select();
		return false;
	}
	
	
	
	if (form.auto_submitted.value == 1) {
		/* auto form has been selected*/
		var check = 0;
	   	//loop through radio buttons and check for values
	   	for (var i = 0; i < 2; i++)
	   	{
	    	var checked = form.auto_policy_holder[i].checked;
	     	if (checked)
	      	{
	       		check = 1;
	      	}
	    }
		//if checked post the form
		if (check != 1)
		{
	     	alert ("Please select an option for is the driver the policy holder.");
	     	return false;
	    }
		
		var myindex4 = form.auto_driver_relation.selectedIndex
		if (myindex4==0)  
		{
			alert ("Please select the drivers relation to insured");
			return false;	
		}
		
		if (form.auto_driver_name.value == '') {
			alert("Please fill in the drivers name.");
			form.auto_driver_name.focus();
			form.auto_driver_name.select();
			return false;
		}
		if (form.auto_street.value == '') {
			alert("Please fill in the street number and name.");
			form.auto_street.focus();
			form.auto_street.select();
			return false;
		}
		if (form.auto_city.value == '') {
			alert("Please fill in the city.");
			form.auto_city.focus();
			form.auto_city.select();
			return false;
		}
		if (form.auto_country.value == '') {
			alert("Please fill in the country.");
			form.auto_country.focus();
			form.auto_country.select();
			return false;
		}
		if (form.auto_veh_make.value == '') {
			alert("Please fill in the Vehicle make.");
			form.auto_veh_make.focus();
			form.auto_veh_make.select();
			return false;
		}
		if (form.auto_veh_model.value == '') {
			alert("Please fill in the Vehicle model.");
			form.auto_veh_model.focus();
			form.auto_veh_model.select();
			return false;
		}
		if (form.auto_veh_yr.value == '') {
			alert("Please fill in the Vehicle year.");
			form.auto_veh_yr.focus();
			form.auto_veh_yr.select();
			return false;
		}
		
		/* auto form has been selected*/
		var check2 = 0;
	   	//loop through radio buttons and check for values
	   	for (var i = 0; i < 2; i++)
	   	{
	    	var checked = form.auto_veh_drivable[i].checked;
	     	if (checked)
	      	{
	       		check2 = 1;
	      	}
	    }
		//if checked post the form
		if (check2 != 1)
		{
	     	alert ("Please select an option for is the vehicle drivable.");
	     	return false;
	    }
		
		if (form.auto_veh_location.value == '') {
			alert("Please fill in the Location of the vehicle.");
			form.auto_veh_location.focus();
			form.auto_veh_location.select();
			return false;
		}
		
		if (form.auto_passengers.value == '') {
			alert("Please fill in how many passengers.");
			form.auto_passengers.focus();
			form.auto_passengers.select();
			return false;
		}
		
		/* auto form has been selected*/
		var check3 = 0;
	   	//loop through radio buttons and check for values
	   	for (var i = 0; i < 2; i++)
	   	{
	    	var checked = form.auto_injuries[i].checked;
	     	if (checked)
	      	{
	       		check3 = 1;
	      	}
	    }
		//if checked post the form
		if (check3 != 1)
		{
	     	alert ("Please select an option for were there any injuries.");
	     	return false;
	    }
		
		/* auto form has been selected*/
		var check4 = 0;
	   	//loop through radio buttons and check for values
	   	for (var i = 0; i < 2; i++)
	   	{
	    	var checked = form.auto_other_veh[i].checked;
	     	if (checked)
	      	{
	       		check4 = 1;
	      	}
	    }
		//if checked post the form
		if (check4 != 1)
		{
	     	alert ("Please select an option for were other vehicles involved in the accident.");
	     	return false;
	    }
	}
return true;	
}


/* CHECK TO SEE IF THE DRIVER IS THE POLICY HOLDER */
function CheckForPolicyHolder(radio_value) {
	if (radio_value == 1) {
		document.getElementById("auto_driver_name").value = document.getElementById("personal_name").value;
		document.getElementById("auto_street").value = document.getElementById("personal_street").value;
		document.getElementById("auto_apt").value = document.getElementById("personal_apt").value;
		document.getElementById("auto_city").value = document.getElementById("personal_city").value;
		document.getElementById("auto_country").value = document.getElementById("personal_country").value;
		document.getElementById("auto_prov").value = document.getElementById("personal_prov").value;
		document.getElementById("auto_zip").value = document.getElementById("personal_zip").value;
	}
	else {
		document.getElementById("auto_driver_name").value = '';
		document.getElementById("auto_street").value = '';
		document.getElementById("auto_apt").value = '';
		document.getElementById("auto_city").value = '';
		document.getElementById("auto_country").value = 0;
		document.getElementById("auto_prov").value = 0;
		document.getElementById("auto_zip").value = '';
	}
	
	
}