<!--
//Unviversal functions
var error_message = "";
function toggleDiv(divid){
	if(document.getElementById(divid).style.display == 'none'){
		document.getElementById(divid).style.display = 'block';
	}else{
		document.getElementById(divid).style.display = 'none';
	}
}
function IsNumeric(sText) { 
var ValidChars = "0123456789/"; 
var IsNumber=true; 
var Char; for (i = 0; i < sText.length && IsNumber == true; i++) 
	{ Char = sText.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) 
		{ IsNumber = false; } 
	} 
	return IsNumber; 
}
//
function avaliddate(field) {
		var thisdate = field.value;
		if(thisdate.charAt(2)!= "/" || thisdate.charAt(5)!= "/") {
			alert("* Date is in the incorrect format.");
			return false;
			} else {
				hasnumbs = IsNumeric(thisdate);
				if(hasnumbs == false) {
				alert("* Date is in the incorrect format.");return false;
				} else {
					date_array = thisdate.split("/");
					var day = date_array[0];
					var month = date_array[1];
					var year = date_array[2];
					if((day.length<2) || (month.length<2) || (year.length<4)) {
						alert("* Date is in the incorrect format.");return false;
					} else {
						if((day>31) || (month>12)) {
						alert("* Invalid Date.");
						return false;
					} else {
					return true;
					} 
				}
		   	}

		}

	}

//

function gettoday() {
var today = new Date()
ONE_DAY = 1000 * 60 * 60 * 24
Ctoday = today.getTime();
rday = Ctoday/ONE_DAY;
return rday+30;
}
function splitdate(thisdate) {
ONE_DAY = 1000 * 60 * 60 * 24
var Edate = new Date()
thisdate_array = thisdate.split("/");
var day = thisdate_array[0];
var month = thisdate_array[1];
var year = thisdate_array[2];
Edate = new Date(year, month, day);
Cdate = Edate.getTime();
Rdate = Cdate/ONE_DAY;
return Rdate;
}

//**********************************************************************************************************
//CHECKS DATE OF BIRTH, CLIENT IS OVER 16
function checkdob (form) {
if(avaliddate(form.dr_dob)) {
	Edob = splitdate(form.dr_dob.value);
	today = gettoday();
		if (Edob>today) { 
		alert("You Can't be born in the future!!"); 
		form.dr_dob.focus();
		form.dr_dob.value="";
		return false;
		} else { 
		 	if((today - Edob)< 6205) {
			alert("You have to be 17 to start a quote"); 
			form.dr_dob.value="";
			form.dr_dob.focus();
			return false;
			} else {
		 return;}
	} 
  } else {
	form.dr_dob.value="";
	form.dr_dob.focus();
	return false;
  }
}
//CHECKS DATE OF BIRTH, CLIENT IS OVER 16
function checkdobdriver (form) {
if(avaliddate(form.dr_dob)) {
	Edob = splitdate(form.dr_dob.value);
	today = gettoday();
		if (Edob>today) { 
		alert("Driver can't be born in the future!!"); 
		form.dr_dob.focus();
		form.dr_dob.value="";
		return false;
		} else { 
		 	if((today - Edob)< 5840) {
			alert("Driver has to be over 16."); 
			form.dr_dob.value="";
			form.dr_dob.focus();
			return false;
			} else {
		 return;}
	} 
} else {
form.dr_dob.value="";
form.dr_dob.focus();
return false;
}
}

//**********************************************************************************************************
//CHECKS Licence date, CLIENT IS OVER 16
function checklicdate (form) {
if(avaliddate(form.dr_lic_date)) {
	Edol = splitdate(form.dr_lic_date.value);
	Edob = splitdate(form.dr_dob.value);
	today = gettoday();
		if (Edol>today) { 
		alert("Your Licence acquired date cannot be in the future"); 
		form.dr_lic_date.focus();
		form.dr_lic_date.value="";
		return false;
		} else { 
		 	if((Edol - Edob)< 5840) {
			alert("Your licence could not have been acquired before your 17th Birthday"); 
			form.dr_lic_date.value="";
			form.dr_lic_date.focus();
			return false;
			} else {
		 return;}
	}
  } else {
	form.dr_lic_date.value="";
	form.dr_lic_date.focus();
	return false;

  }
}
//*************CHECKS the Conviction Date*******************************************************************
function checkdateofconv(field) {
if(avaliddate(field)) {
	Edoc = splitdate(field.value);
	today = gettoday();
		if (Edoc>today) { 
		alert("Your Conviction date cannot be in the future"); 
		field.focus();
		field.value="";
		return false;
		}



	}
}
//**********************************************************************************************************
function checklictype (form) {
	Edol = splitdate(form.dr_lic_date.value);
	today = gettoday();
	lictype = form.dr_licence.value;
		if(lictype=="EEC Licence") {
			if((today-Edol)>365) {
			alert("Your EEC licence cannot be held for more than a year"); 
			form.dr_lic_date.value="";
			form.dr_licence.value="none";
			form.dr_lic_date.focus();
			return false;
			}			
		} 
		insdate = splitdate(form.insdate.value);
			if(Edol>insdate) {
			alert("The Licence date cannot be after the Insurance Start date"); 
			form.dr_lic_date.value="";
			form.dr_licence.value="none";
			form.dr_lic_date.focus();
			return false;

		} else {
		return;
	}

}
//**********************************************************************************************************
function checkinsdate (form) {
if(avaliddate(form.mquote_insdate)) {

Edop2 = splitdate(form.dop2.value);
Einsdate = splitdate(form.mquote_insdate.value);
today = gettoday();
	if(Einsdate<today) {
	alert("Insurance cannot start in the past");
	form.mquote_insdate.focus();
	form.mquote_insdate.value="";
	return false;
	} 
	if(Einsdate<Edop2) {
	alert("Insurance cannot start before purchase date");
	form.mquote_insdate.focus();
	form.mquote_insdate.value="";
	return false;
	} 
	if((Einsdate - today)>62) {
	alert("Insurance cannot start more than 60 days ahead");
	form.mquote_insdate.focus();
	form.mquote_insdate.value="";
	return false;
	} 
	return; 
} else {
	form.mquote_insdate.focus();
	form.mquote_insdate.value="";
	return false;
}

}
//**********************************************************************************************************
//Check date of Claims
function checkdateofclaim (field) {
if(avaliddate(field)) {

	Edoc = splitdate(field.value);
	Edol = splitdate(document.thisform.dr_lic_date.value);
	today = gettoday();
		if(Edoc>today) {
		alert("Claim date cannot be in the future");
		field.focus();
		field.value="";
		return false;
		} else {
			if(Edoc<Edol) {
			alert("Claim date cannot before Date of Licence");
			field.focus();
			field.value="";
			return false;
			} else {
				if((today-Edoc)>1825) {
				alert("You don't need to tell us about claims older the 5 years ago");
				field.focus();
				field.value="";
				return false;
				} else {
				return;
			}
		}
	}
} else {
field.focus();
field.value="";
return false;
}
}
//**********************************************************************************************************

//Checks Year of Manufacture starts with 19 or 20
function checkyom(form) {
Edate = form.yom.value;
Edate = Edate.substring(0,2);
if((Edate != "19") && (Edate != "20")) {
	alert("Vehicle Year of Manufacture must be This or Last Century");
	form.yom.focus();
	form.yom.value="";
	return false;
	}
}
//**********************************************************************************************************
function checkyom(form) {
if(!form.yom.value) {
alert("You must enter a year of manufacture");
return;
	} else {
	var yom = form.yom.value;
	if(yom.length<4) {
	alert("Year of Manufacture must be 4 digits.");
	form.yom.focus();
	form.yom.value = "";
	return false;
	} else {	
		if((yom.substring(0,2)!= '19') && (yom.substring(0,2)!= '20')) {
		alert("Year of Manufacture must start with 19 or 20.");
		form.yom.focus();
		form.yom.value = "";
		return false;

		}
	    }
      }
}
//**********************************************************************************************************
//CHecks the Date of purchase id after Year of Manufacture
function checkdop(form) {
if(avaliddate(form.dop)) {

today = Math.round(gettoday());
if(!form.yom.value) {
alert("You must enter a year of manufacture");
form.yom.focus();
form.dop.value="";
return false;
} else {
Edop = Math.round(splitdate(form.dop.value));
EdopY = Math.round((Edop/365)+1969);
Eyom = form.yom.value;
if((Edop - today)>30) {
		alert("We cannot quote on purchase dates more than 30 days ahead");
		form.dop.value="";
		form.dop.focus();
		return false;
}
if(Eyom>EdopY) {
	alert("Vehicle Year of Manufacture must be before Date of Purchase");
	form.dop.value="";
	form.dop.focus();
	return false;
	} else {
	if((today - Edop)<365) {
		form.vehold.value="TRUE";
		document.getElementById('veh').style.display = 'block';	
		form.veh_omanu.focus();
		return;	
		} else {
		form.vehold.value="";
		form.veh_omanu.value="";
		form.veh_omodel.value="";
		form.veh_ospec.value="";
		form.veh_otime.value="";
		document.getElementById('veh').style.display = 'None';
		form.veh_reg.focus();
		return;		
		}
	   }
   }
} else {
form.dop.value="";
form.dop.focus();
return false;

}
}
//**********************************************************************************************************
//CHecks whether to display the Mods Textarea
function checkmods(form) {
	if(form.veh_mod.value == "Yes") {
	form.vehmod.value="TRUE";
	document.getElementById('veh3').style.display = 'block';
	return;
	} else {
	form.vehmod.value="";
	form.veh_mod_det.value='';
	document.getElementById('veh3').style.display = 'None';
	}
	
}
function checkgarage(form) {
	if(form.mquote_hear.value == "Garage / Dealer") {
	form.vehmod.value="TRUE";
	document.getElementById('veh3').style.display = 'block';
	return;
	} else {
	form.vehmod.value="";
	form.mquote_garage.value='';
	document.getElementById('veh3').style.display = 'None';
	}
	
}

function checkmanu(form) {
	if(form.Manu.value == "Other") {
	document.getElementById('veh88').style.display = 'block';
	document.getElementById('spacer1').style.display = 'none';
	return;
	} else {
	document.getElementById('veh88').style.display = 'none';
	document.getElementById('spacer1').style.display = 'block';
	form.Othermanu.value='';
	}
	
}
function checktitle(form) {
	if(form.Title.value == "Other") {
	document.getElementById('veh88').style.display = 'block';
	//document.getElementById('spacer1').style.display = 'none';
	return;
	} else {
	document.getElementById('veh88').style.display = 'none';
	//document.getElementById('spacer1').style.display = 'block';
	form.Othertitle.value='';
	return;
	}
	
}

function checkpro(form) {
	if((form.mquote_nocl.value >3) || (form.mquote_nocl.value =="9+")) {
	document.getElementById('veh88').style.display = 'block';
	//document.getElementById('spacer1').style.display = 'none';
	return;
	} else {
	document.getElementById('veh88').style.display = 'none';
	//document.getElementById('spacer1').style.display = 'block';
	form.mquote_pro.value=0;
	return;
	}
	
}


function checklenban(form) {
	var num_cons = form.dr_numcons.value;
	for(i=1; i<=num_cons; i++) {
		if(i==1) {
			if(form.dr_con1_dis.value == "Yes") {
				document.getElementById('veh891').style.display = 'block';
			} else {
				document.getElementById('veh891').style.display = 'none';
			}
		}
		if(i==2) {
			if(form.dr_con2_dis.value == "Yes") {
				document.getElementById('veh892').style.display = 'block';
			} else {
				document.getElementById('veh892').style.display = 'none';
			}
		}
		if(i==3) {
			if(form.dr_con3_dis.value == "Yes") {
				document.getElementById('veh893').style.display = 'block';
			} else {
				document.getElementById('veh893').style.display = 'none';
			}
		}
		if(i==4) {
			if(form.dr_con4_dis.value == "Yes") {
				document.getElementById('veh894').style.display = 'block';
			} else {
				document.getElementById('veh894').style.display = 'none';
			}
		}
		if(i==5) {
			if(form.dr_con5_dis.value == "Yes") {
				document.getElementById('veh895').style.display = 'block';
			} else {
				document.getElementById('veh895').style.display = 'none';
			}
		}
	
	}
}
//**********************************************************************************************************
//**********************************************************************************************************
//CHecks whether to display the Mods Textarea
function checknclaims(form) {
	var dr_dob = form.dr_dob.value;
	var dr_occ = form.dr_occ.value;
      var dr_bus = form.dr_bus.value;
	var dr_lic_date = form.dr_lic_date.value;
	var dr_licence = form.dr_licence.value;
	var dr_an_veh = form.dr_an_veh.value;
	var dr_numclaims = form.dr_numclaims.value;
	var dr_numcons = form.dr_numcons.value;
	var dr_disable = form.dr_disable.value;
	var formback = form.formback.value;

	
	if((dr_numclaims>0) || (dr_numcons>0) || (dr_disable =="Yes")) {
	strAddress = "mquote.php?type=2&forms=" + formback + "&dr_numclaims=" + dr_numclaims + "&dr_dob=" + dr_dob + "&dr_occ=" + dr_occ + "&dr_bus=" + dr_bus + "&dr_lic_date=" + dr_lic_date + "&dr_licence=" + dr_licence + "&dr_an_veh=" + dr_an_veh + "&dr_numcons=" + dr_numcons + "&dr_disable=" + dr_disable + "";
	location.href = strAddress;
		document.getElementById('veh3').style.display = 'block';
			if(dr_numcons>0) {
			document.getElementById('veh5').style.display = 'block';
			}
			if(dr_disable =="Yes") {
			document.getElementById('veh6').style.display = 'block';
			}

	return;
	} 
	if(dr_numclaims==0) {document.getElementById('veh3').style.display = 'None';}
	if(dr_numcons==0) {document.getElementById('veh5').style.display = 'None';}
	if(dr_disable=="No") {document.getElementById('veh6').style.display = 'None';}
	
	
}
//**********************************************************************************************************
//CHecks Disabled Entry
function checkdis(form) {
		checknclaims(form);
		return;
}
//CHecks Convitions Entry
function checkconvict(form) {
		checknclaims(form);
		return;
}
//**********************************************************************************************************
//CHecks whether to display the Mods Textarea
function checknclaims2(form) {
	var dr_title = form.dr_title.value;
	var dr_firstname = form.dr_firstname.value;
	var dr_othertitle = form.dr_othertitle.value;
	var dr_surname = form.dr_surname.value;
	var dr_dob = form.dr_dob.value;
	var dr_occ = form.dr_occ.value;
      var dr_bus = form.dr_bus.value;
	var dr_lic_date = form.dr_lic_date.value;
	var dr_licence = form.dr_licence.value;
	var dr_an_veh = form.dr_an_veh.value;
	var dr_numclaims = form.dr_numclaims.value;
	var dr_numcons = form.dr_numcons.value;
	var dr_disable = form.dr_disable.value;
	var formback = form.formback.value;


	
	if((dr_numclaims>0) || (dr_numcons>0) || (dr_disable =="Yes")) {
	strAddress = "mquote.php?type=2&forms=" + formback + "&dr_title=" + dr_title + "&dr_othertitle=" + dr_othertitle + "&dr_firstname=" + dr_firstname + "&dr_surname=" + dr_surname + "&dr_numclaims=" + dr_numclaims + "&dr_dob=" + dr_dob + "&dr_occ=" + dr_occ + "&dr_bus=" + dr_bus + "&dr_lic_date=" + dr_lic_date + "&dr_licence=" + dr_licence + "&dr_an_veh=" + dr_an_veh + "&dr_numcons=" + dr_numcons + "&dr_disable=" + dr_disable + "";
	location.href = strAddress;
		document.getElementById('veh3').style.display = 'block';
			if(dr_numcons>0) {
			document.getElementById('veh5').style.display = 'block';
			}
			if(dr_disable =="Yes") {
			document.getElementById('veh6').style.display = 'block';
			}

	return;
	} 
	if(dr_numclaims==0) {document.getElementById('veh3').style.display = 'None';}
	if(dr_numcons==0) {document.getElementById('veh5').style.display = 'None';}
	if(dr_disable=="No") {document.getElementById('veh6').style.display = 'None';}
	
	
}
//**********************************************************************************************************
//CHecks Disabled Entry
function checkdis2(form) {
		checknclaims2(form);
		return;
}
//CHecks Convitions Entry
function checkconvict2(form) {
		checknclaims2(form);
		return;
}
//**********************************************************************************************************

//Check Convict Code
function checkconvictcode (field) {
	var thisstring = field.value;
		if((thisstring.length<4) || (thisstring.length>4))  {
		alert("The Conviction code must be four characters long");   
		field.value = ""; 
  		field.focus();
  		return false;
		}			
		theletters = thisstring.substring(0,1);
		if(!(theletters.search(/[A-Z]+/)> -1) && !(theletters.search(/[a-z]+/)> -1)){
		alert("The Conviction code 1st character must be a Letter");   
		field.value = ""; 
  		field.focus();
  		return false;
		}
		theletters = thisstring.substring(1,2);
		if(!(theletters.search(/[A-Z]+/)> -1) && !(theletters.search(/[a-z]+/)> -1)){
		alert("The Conviction code 2nd character must be a Letter");   
		field.value = ""; 
  		field.focus();
  		return false;
		}

		theletters = thisstring.substring(2,3);
		if(!(theletters.search(/[0-9]+/)> -1)){
		alert("The Conviction code 3rd character must be a number");   
		field.value = ""; 
  		field.focus();
  		return false;
		}
		theletters = thisstring.substring(3,4);
		if(!(theletters.search(/[0-9]+/)> -1)){
		alert("The Conviction code 4th character must be a number");   
		field.value = ""; 
  		field.focus();
  		return false;
		}



}
//**********************************************************************************************************
function checkconvictfine (field) {
var thisstring = field.value;
if(thisstring.length<1)  {
		alert("The Conviction Fine must be a value or 0");   
		field.value = ""; 
  		field.focus();
  		return false;
		}	
		if((thisstring.search(/[A-Z]+/)> -1) || (thisstring.search(/[a-z]+/)> -1)){
		alert("The Conviction Fine cannot contain letters");   
		field.value = ""; 
  		field.focus();
  		return false;
		}


}
//**********************************************************************************************************

//Checks Insurance start date against TODAY, DATE OF BIRTH, DATE IN FUTURE
function checkins (form) {
Edob = splitdate(form.dob.value);
Eins = splitdate(form.insdate.value);
today = gettoday();
Edop = splitdate(form.dop.value);
if (Eins < today) { 
  alert("Policy start date must be in the future " + Eins + " < " + today);
  form.insdate.value = ""; 
  form.insdate.focus();
  return false;
	} else { 
		if((Eins - Edob)<6205) { 
			alert("You Can't Start Policy before you are 17!!");
			form.insdate.focus();
			form.insdate.value = "";
			return false;
			} else { 
				if((Eins - today)>90) {
				alert("We can't quote for policies starting more than 90 days in the future");
				form.insdate.focus();
				form.insdate.value = "";
				return false;
				} else {
					if(Eins < Edop)  {
					alert("Insurance can't start before date of purchase");
					form.insdate.focus();
					form.insdate.value = "";
					return false;
					} else {
				return; }
				}
			}
	}
}

//**********************************************************************************************************
function checkmarital(form) {
var mquote_cover = form.mquote_cover.value;
var mquote_insdate = form.mquote_insdate.value;
var mquote_nocl = form.mquote_nocl.value;
var mquote_cuins = form.mquote_cuins.value;
var mquote_mileage = form.mquote_mileage.value;
var mquote_use = form.mquote_use.value;
var mquote_drivers = form.mquote_drivers.value;
var mquote_pro = form.mquote_pro.value;


if(mquote_drivers=="Insured Only") {
	form.mquote_adddrivers.value = 0;
	}
if(mquote_drivers=="Insured & Spouse") {
	form.mquote_adddrivers.value = 1;
	}
if(mquote_drivers=="Insured & Common Law Partner") {
	form.mquote_adddrivers.value = 1;
	}
strAddress = "mquote.php?type=2&forms=3&mquote_cover=" + mquote_cover + "&mquote_insdate=" + mquote_insdate + "&mquote_nocl=" + mquote_nocl + "&mquote_cuins=" + mquote_cuins + "&mquote_pro=" + mquote_pro + "&mquote_mileage=" + mquote_mileage + "&mquote_use=" + mquote_use + "&mquote_drivers=" + mquote_drivers + "";
	location.href = strAddress;
	return;
}
//--->
