function ageCalculation()
{
	var DOBday = document.getElementById("DOB_day").value;
	var DOBmonth = document.getElementById("DOB_month").value;
	var DOByear = document.getElementById("DOB_year").value;
	
	var d = new Date();
	var curr_date = d.getDate();
	var curr_month = d.getMonth() + 1;
	var curr_year = d.getFullYear();
	
	var age = curr_year - DOByear;
	
	if(curr_month < DOBmonth)
	{
		age = age - 1;
	}
	
	else if(curr_month == DOBmonth)
	{
		if(curr_date < DOBday)
		{
			age = age - 1;
		}	
	}
	
	return age;
}

function checkForm(){
	
	//String passed to email script
	var emails = "gravytrain"; 
	
	//Postcode filter variables
	var postcodeStr = document.getElementById("Base_Postcode").value;
	var startsWith = postcodeStr.substring(0,2);
	var postcode3 = postcodeStr.substring(0,3);
	var postcode4 = postcodeStr.substring(0,4);
	startsWith = startsWith.toUpperCase();
	var startsWithFirstLetter = postcodeStr.substring(0,1);
	startsWithFirstLetter = startsWithFirstLetter.toUpperCase();	
	var no = postcodeStr.substring(1,2);
	
	// Set Time
	
	var d = new Date();	
	var timeHours = parseInt(d.getHours());
	
	
	// Weekend Filter
	
	var currentDay = d.getDay();
	var curr_date = d.getDate();
	var curr_month = d.getMonth() + 1;
	var curr_year = d.getFullYear();
	
	var notWeekend = true;
	
	if(currentDay == 0 || currentDay == 6)
		{
			notWeekend = false;
		}
	
	var DOBday = document.getElementById("DOB_day").value;
	var DOBmonth = document.getElementById("DOB_month").value;
	var DOByear = document.getElementById("DOB_year").value;
	
	//Age Filters (The form will not submit data unless the user is aged between 25 - 90 by default)
		//Set user age as value
		var age = ageCalculation(age);
	
		//Min age limit
		var age25Min = true;
		var age28Min = true;
		var age30Min = true;
		
		var age35Min = true;
		
		//min age 25
		if(age < 25)
			{
				age25Min = false;
			}
		
		//min age 28
		if(age < 28)
			{
				age28Min = false;
			}
			
		//min age 30
		if(age < 30)
			{
				age30Min = false;
			}
		
		//min age 35
		if(age < 35)
			{
				age35Min = false;	
			}
			
		//Max age limit
		var maxAge70 = true;
		var maxAge69 = true;
		
		//max age 69
		if(age > 69)
			{
				maxAge69 = false;	
			}
		
			//max age 70
		if(age > 70)
			{
				maxAge70 = false;
			}
	
					
	//licence Held Since - min 3 years
	var licHeldSince = false;
		
	var licHeldFor = document.getElementById("licence_Held_For").value
	
	if (licHeldFor != "Under 1 Year" && licHeldFor != "1 Year" && licHeldFor != "2 Year")
		{
			licHeldSince = true;	
		}
		
	//licence Held Since - min 2 years
	
	var licHeldSince2 = false;
	
	if (licHeldFor != "Under 1 Year" && licHeldFor != "1 Year") 
		{
			licHeldSince2 = true;	
		}
		
	//licence Held Since - min 4 years
	
	var licHeldSince4 = false;
	
	if (licHeldFor != "Under 1 Year" && licHeldFor != "1 Year" && licHeldFor != "2 Year" && licHeldFor != "3 Year") 
		{
			licHeldSince4 = true;	
		}
		
	//licence Held Since - min 5 years
	
	var licHeldSince5 = false;
	
	if (licHeldFor != "Under 1 Year" && licHeldFor != "1 Year" && licHeldFor != "2 Year" && licHeldFor != "3 Year" && licHeldFor != "4 Year") 
		{
			licHeldSince5 = true;	
		}
	
		
		
		//Residence 5+ Years
		var residence6Years = false;
		var residence5Years = false;
		var residence4Years = false;
		var residence3Years = false;
		
		var livedFor = document.getElementById("Residence").value ;
		
		// Residence 6 years
		
		if (livedFor >= 6 || livedFor == "Since Birth" || livedFor == "10+")
		{
			residence6Years = true;	
		}
		
		// Residence 5 years
		
		if (livedFor >= 5 || livedFor == "Since Birth" || livedFor == "10+")
		{
			residence5Years = true;	
		}
		
		// Residence 3 Years
		
		if (livedFor >= 3 || livedFor == "Since Birth" || livedFor == "10+")
		{
			residence3Years = true;	
		}
		
		// Residence 4 Years
		
		if (livedFor >= 4 || livedFor == "Since Birth" || livedFor == "10+")
		{
			residence4Years = true;	
		}
		
		
		//Taxi Badge Held For 1 Year
		
		var TaxiBadge1Year = true;
		var TaxiBadgeLenth = document.getElementById("TaxiBadge_Held_For").value ;
		
		if (TaxiBadgeLenth == "Under 1 Year")
			{
				TaxiBadge1Year = false;	
			}
		
		//Taxi Badge For 2 Years
		
		var TaxiBadge2Year = true;
		
		if (TaxiBadgeLenth == "Under 1 Year" || TaxiBadgeLenth == "1 Year")
			{
				TaxiBadge2Year = false;	
			}
			
		//Taxi Badge For 3 Years
		
		var TaxiBadge3Year = true;
		
		if (TaxiBadgeLenth == "Under 1 Year" || TaxiBadgeLenth == "1 Year" || TaxiBadgeLenth == "2 Year")
			{
				TaxiBadge3Year = false;	
			}
			
				//Taxi Badge For 5 Years
		
		var TaxiBadge5Year = true;
		
		if (TaxiBadgeLenth == "Under 1 Year" || TaxiBadgeLenth == "1 Year" || TaxiBadgeLenth == "2 Year" || TaxiBadgeLenth == "3 Year" || TaxiBadgeLenth == "4 Year")
			{
				TaxiBadge5Year = false;	
			}
			
		// Taxi Min NCB 
		var TaxiNCB = document.getElementById('Taxi_No_Claims').value;
		
			//Min 1 Years NCB
			var min1YearsNCB = true;
			
			if(TaxiNCB == "None")
				{
					var min1YearsNCB = false;	
				}
		
			
			//Min 2 YEars
			var min2YearsNCB = true;
			
			if(TaxiNCB == "None" || TaxiNCB == "1 Year")
				{
					var min2YearsNCB = false;	
				}
			
			//Min 3 YEars
			var min3YearsNCB = true;
			
			if(TaxiNCB == "None" || TaxiNCB == "1 Year" || TaxiNCB == "2 Years")
				{
					var min3YearsNCB = false;	
				}
				
			
		
			//Taxi NCB max 2 years
			
			var max2YearsTaxiNCB = false;
			
			
			if(TaxiNCB == "None" || TaxiNCB == "1 Year" || TaxiNCB == "2 Years")
				{
					max2YearsTaxiNCB = true;
				}
				
			//Taxi min 5 Years
			
			var min5YearsTaxiNCB = false;
			
			if(TaxiNCB == "5 Years" || TaxiNCB == "6 Years" || TaxiNCB == "7 Years" || TaxiNCB == "8 Years" || TaxiNCB == "9 Years" || TaxiNCB == "10 Years" || TaxiNCB == "10+ Years")
				{
					min5YearsTaxiNCB = true;
				}
				
			
			//Taxi min 8 Years
			
			var min8YearsTaxiNCB = false;
			
			if(TaxiNCB == "8 Years" || TaxiNCB == "9 Years" || TaxiNCB == "10 Years" || TaxiNCB == "10+ Years")
				{
					min8YearsTaxiNCB = true;
				}
				
				
			// Number Of Passengers
			
			var numberOfPassengers = parseInt(document.getElementById("Number_Of_Passengers").value) ;
			
				// Min 5 Passengers
				
				var passengers5 = true;
				
				if(numberOfPassengers < 5)
					{
						passengers5 = false;	
					}
					
				// Max of 8 passengers
				
				var maxPassengers8 = true;
				
				if(numberOfPassengers > 8)
					{
						maxPassengers8 = false;	
					}
							
		
		// London Postcode
		var londonPostcode = false;
		
		if(startsWithFirstLetter == "E" || startsWithFirstLetter == "N" || startsWithFirstLetter == "W")
			{
				if((no == "1") || (no == "2") || (no == "3") || (no == "4") || (no == "5") || (no == "6") || (no == "7") || (no == "8") || (no == "9"))
					{
						londonPostcode = true;	
					}
			}			
		
		if(startsWith == "SE" || startsWith == "WC" || startsWith == "EC" || startsWith == "NW" || startsWith == "SW")
			{
				londonPostcode = true;	
			}
			
		
		// Northern Postcode
		var northernPostcode = false;
		
		if(startsWithFirstLetter == "B" || startsWithFirstLetter == "L" || startsWithFirstLetter == "M" || startsWithFirstLetter == "S")
			{
				if((no == "1") || (no == "2") || (no == "3") || (no == "4") || (no == "5") || (no == "6") || (no == "7") || (no == "8") || (no == "9"))
						{
							northernPostcode = true;	
						}
			}
			
		if(startsWith == "BB" || startsWith == "BD" || startsWith == "BL" || startsWith == "CH" || startsWith == "CV" || startsWith == "CW" || startsWith == "DE" || startsWith == "DL" || startsWith == "DN" || startsWith == "DY" || startsWith == "FY" || startsWith == "HD" || startsWith == "HG" || startsWith == "HU" || startsWith == "HX" || startsWith == "IP" || startsWith == "LA" || startsWith == "LE" || startsWith == "LL" || startsWith == "LN" || startsWith == "LS" || startsWith == "NG" || startsWith == "NR" || startsWith == "OL" || startsWith == "PE" || startsWith == "PR" || startsWith == "SK" || startsWith == "ST" || startsWith == "SY" || startsWith == "TF" || startsWith == "TS" || startsWith == "WA" || startsWith == "WF" || startsWith == "WN" || startsWith == "WS" || startsWith == "WV" || startsWith == "YO")
		  {
		  		northernPostcode = true;	
		  }
		  
		  
		  //Scottish Postcode
		  
		  var scottishPostcode = false;
		  
		  if( startsWith == "AB" || startsWith == "DD" || startsWith == "DG" || startsWith == "EH" || startsWith == "FK" || startsWith == "HS" || startsWith == "IV" || startsWith == "KA" || startsWith == "KW" || startsWith == "KY" || startsWith == "ML" || startsWith == "PA" || startsWith == "PH" || startsWith == "TD" || startsWith == "ZE" )
				{
					scottishPostcode = true;
				}
		
		if (startsWithFirstLetter == "G")
			{
					if ((no == "1") || (no == "2") || (no == "3") || (no == "4") || (no == "5") || (no == "6") || (no == "7") || (no == "8") || (no == "9"))
					{
						scottishPostcode = true;
					}	
			}
			
			var DriverCover = document.getElementById("Drivers").value;
			
			
			var noConvictions = false;
			
			if(document.getElementById("Convictions").value == "No")
			{
					noConvictions = true;
			}
		
	
		//Osborne & Sons
		
		var osbAuth = true;	
	var osbTA = new Array("City of Bradford", "Salford City Council", "Bridgend County Borough Council", "Public Carriage Office");
	
	//Check Local Authority
	for(var osbCount = 0; osbCount < osbTA.length; osbCount++)
		{
			var osbAuthValue = osbTA[osbCount];
			
			if(document.getElementById('Licensing_Authority').value == osbAuthValue)
			{
				osbAuth = false;
				break;
			}
		}
				
		var vehicleUse = document.getElementById("Vehicle_Use").value;
				
		if(londonPostcode || startsWith == "SM" || startsWith == "KT" || startsWith == "CR" || startsWith == "RH" || startsWith == "GU" || startsWith == "TW" || startsWith == "BR")
			{		
				if( (vehicleUse == "Private Hire") && notWeekend && age25Min && osbAuth)	
					{
						emails += ",taxi3";	
					}
			}
	

	//DNA
	
	var dnaAuth = true;	
	var dnaTA = new Array("City of Birmingham", "City of Bradford", "Blackburn With Darwen Borough Council", "Bolton Metropolitan Borough Council");
	
	//Check Local Authority
	for(var dnaCount = 0; dnaCount < dnaTA.length; dnaCount++)
		{
			var dnaAuthValue = dnaTA[dnaCount];
			
			if(document.getElementById('Licensing_Authority').value == dnaAuthValue)
			{
				dnaAuth = false;
				break;
			}
		}
	
	if(londonPostcode == false && dnaAuth && age25Min)
		{
			emails += ",taxi4";			
		}




	
	
	//Choice Quote
	var validChoiceQuotePostCode = false;
	
	if(startsWith == "AB" || startsWith == "BT" || startsWith == "CH" || startsWith == "CW" || startsWith == "DD" || startsWith == "DG" || startsWith == "EH" || startsWith == "FK" || startsWith == "FY" || startsWith == "IV" || startsWith == "KA" || startsWith == "KW" || startsWith == "KY" || startsWith == "LA" || startsWith == "ML" || startsWith == "PA" || startsWith == "PH" || startsWith == "PR" || startsWith == "TD" || startsWith == "WA")
		{
			validChoiceQuotePostCode = true;
		}
		
	if (startsWithFirstLetter == "G" || startsWithFirstLetter == "L")
			{
					if ((no == "1") || (no == "2") || (no == "3") || (no == "4") || (no == "5") || (no == "6") || (no == "7") || (no == "8") || (no == "9"))
					{
						validChoiceQuotePostCode = true;
					}	
			}

	if(document.getElementById('Taxi_No_Claims').value != "None" || document.getElementById('Private_No_Claims').value != "None")
		{
			if (validChoiceQuotePostCode) 
				{
					emails += ",taxi5";
				}
		}

		
		
		
		// JMI Insurance
		var jmiTime = false;
		if(timeHours >= 9 && timeHours < 17)
			{
				jmiTime = true;
			}
		
		// Post codes not accepted
		var validJMIPostCode = true;
	
	if(startsWith == "GY" || startsWith == "IM" || startsWith == "JE" || startsWith == "BT")
		{
			validJMIPostCode = false;
		}
		
			var jmiAuth = true;	
	var jmiTA = new Array("Blackburn with Darwen Borough Council", "City of Wakefield", "City of Bradford", "Oldham Metropolitan Borough Council", "Bolton Metropolitan Borough Council", "Derby City Council", "Walsall Metropolitan Borough Council", "Dudley Metropolitan Borough Council", "City of Birmingham", "Stoke-on-Trent City Council", "Peterborough City Council", "Luton Borough Council");
	
	//Check Local Authority
	for(var jmiCount = 0; jmiCount < jmiTA.length; jmiCount++)
		{
			var jmiAuthValue = jmiTA[jmiCount];
			
			if(document.getElementById('Licensing_Authority').value == jmiAuthValue)
			{
				jmiAuth = false;
				break;
			}
		}
		
		// Which Drivers are accepted
		
		
		var jmiDrivers = true;
		if(document.getElementById('Drivers').value == "AnyDriver")
		{
			jmiDrivers = false;
		}
		
		
		if(validJMIPostCode && age30Min && maxAge70 && licHeldSince5 && TaxiBadge3Year && jmiAuth && jmiDrivers)/*  && notWeekend && jmiTime */
			{
				emails += ",taxi6";	
			}


	
	
	//EGroup
	if ((startsWith == "AB") || (startsWith == "BA") || (startsWith == "BH") || (startsWith == "BN") || (startsWith == "BS") || (startsWith == "CA") || (startsWith == "CB") || (startsWith == "CF") || (startsWith == "CO") || (startsWith == "CT") || (startsWith == "CW") || (startsWith == "DD") || (startsWith == "DG") || (startsWith == "DH") || (startsWith == "DN") || (startsWith == "DT") || (startsWith == "EH") || (startsWith == "EX") || (startsWith == "FK") || (startsWith == "GL") || (startsWith == "GU") || (startsWith == "HG") || (startsWith == "HR") || (startsWith == "IV") || (startsWith == "KA") || (startsWith == "KT") || (startsWith == "KW") || (startsWith == "KY") || (startsWith == "HP") || (startsWith == "LA") || (startsWith == "LD") || (startsWith == "LL") || (startsWith == "LN") || (startsWith == "NP") || (startsWith == "NN") || (startsWith == "NR") || (startsWith == "OX") || (startsWith == "PH") || (startsWith == "PE") || (startsWith == "PL") || (startsWith == "PO") || (startsWith == "RG") || (startsWith == "SA") || (startsWith == "SG") || (startsWith == "SN") || (startsWith == "SO") || (startsWith == "SP") || (startsWith == "SY") || (startsWith == "TA") || (startsWith == "TF") || (startsWith == "TN") || (startsWith == "TQ") || (startsWith == "TR") || (startsWith == "WR") || (startsWith == "YO"))
	
		{
			emails += ",taxi14";
		}
	
	
				


	//Quoteline Direct
		
		var quotelinePostcode = true;
		
	if ( (startsWith == "SW") || (startsWith == "NW") || (startsWith == "WC") || (startsWith == "WF") || (startsWith == "EC") || (startsWith == "SE") || (startsWith == "AB") || (startsWith == "DD") || (startsWith == "DG") || (startsWith == "EH") || (startsWith == "FK") || (startsWith == "IV") || (startsWith == "KA") || (startsWith == "KW") || (startsWith == "KY") || (startsWith == "ML") || (startsWith == "PA") || (startsWith == "PH") || (startsWith == "TD") )
		{
			quotelinePostcode = false;
		}
	
   if ( (startsWithFirstLetter == "B") || (startsWithFirstLetter == "E") || (startsWithFirstLetter == "G") || (startsWithFirstLetter == "N") || (startsWithFirstLetter == "W") )
		{
			if ((no == "1") || (no == "2") || (no == "3") || (no == "4") || (no == "5") || (no == "6") || (no == "7") || (no == "8") || (no == "9")) 
			{
				quotelinePostcode = false;
			}
		}

	if (quotelinePostcode && max2YearsTaxiNCB && age25Min)
		{
			emails += ",taxi7";
		}

		
																			 																	  

		
		
	//Stavely Head
	
	
	var stavAuth = true;	
	var stavTA = new Array("City of Manchester", "Blackburn With Darwen Borough Council", "Rochdale Metropolitan Borough Council", "Oldham Metropolitan Borough Council", "Bury Metropolitan Borough Council");
	
	//Check Local Authority
	for(var stavCount = 0; stavCount < stavTA.length; stavCount++)
		{
			var stavAuthValue = stavTA[stavCount];
			
			if(document.getElementById('Licensing_Authority').value == stavAuthValue)
			{
				stavAuth = false;
				break;
			}
		}
	
		
	
	if (startsWith != "BT" && licHeldSince && document.getElementById("Drivers").value == "Insured Only" && residence6Years && age30Min && stavAuth)
		{
			emails += ",taxi8";	 
		}
		
		
		
	// Ashbourne Insurance
	
	var ashPostcode = false;
	
	if(startsWith == "CM" || startsWith == "SG" || startsWith == "EN")    
		{
			ashPostcode = true;	
		}
	
	
	if ( ashPostcode && DriverCover != "InsuredPlus2" && DriverCover != "AnyDriver" && document.getElementById('Licencing_Authority').value != "Public Carriage Office" )
		{
			emails += ",taxi10";
		}
		
		
	
	// Graysons Insurance
	
	var graysonPostcode = false;
	
	if(startsWith == "AL" || startsWith == "BA" || startsWith == "BH" || startsWith == "BN" || startsWith == "BS" || startsWith == "CB" || startsWith == "CO" || startsWith == "CM" || startsWith == "CT" || startsWith == "DT" || startsWith == "EX" || startsWith == "GL" || startsWith == "GU" || startsWith == "HP" || startsWith == "IP" || startsWith == "LU" || startsWith == "ME" || startsWith == "MK" || startsWith == "NN" || startsWith == "NR" || startsWith == "OX" || startsWith == "PE" || startsWith == "PL" || startsWith == "PO" || startsWith == "RG" || startsWith == "RH" || startsWith == "SG" || startsWith == "SL" || startsWith == "SN" || startsWith == "SO" || startsWith == "SP" || startsWith == "SS" || startsWith == "TA" || startsWith == "TN" || startsWith == "TQ" || startsWith == "TR")    
		{
			graysonPostcode = true;	
		}
		
	if(graysonPostcode && licHeldSince2 && residence3Years)
		{
			emails += ",taxi11";
		}
	
	
	// & Peterborough Insurance brokers
	
	var peterboroughPostcode = false;
	
	if(startsWith == "CO" || startsWith =="CB" || startsWith =="IP" || startsWith == "NR" || startsWith == "PE")
	{
		peterboroughPostcode = true;
	}
	
	if(peterboroughPostcode && age30Min)
	{
		emails += ",taxi12";
	}
	
	

	// Insurance Factory
	
	var insuranceFactory = false;
	
	if(startsWith == "BA" || startsWith == "BB" || startsWith == "BD" || startsWith == "BH" || startsWith == "BN" || startsWith == "BS" || startsWith == "CA" || startsWith == "CB" || startsWith == "CM" || startsWith == "CO" || startsWith == "CT" || startsWith == "CV" || startsWith == "DE" || startsWith == "DH" || startsWith == "DL" || startsWith == "DN" || startsWith == "DT" || startsWith == "DY" || startsWith == "EX" || startsWith == "FY" || startsWith == "GL" || startsWith == "GU" || startsWith == "HG" || startsWith == "HP" || startsWith == "HR" || startsWith == "HU" || startsWith == "IP" || startsWith == "LA" || startsWith == "LE" || startsWith == "LN" || startsWith == "ME" || startsWith == "MK" || startsWith == "NE" || startsWith == "NG" || startsWith == "NN" || startsWith == "NR" || startsWith == "OX" || startsWith == "PE" || startsWith == "PL" || startsWith == "PO" || startsWith == "RG" || startsWith == "RH" || startsWith == "SG" || startsWith == "SK" || startsWith == "SN" || startsWith == "SO" || startsWith == "SP" || startsWith == "SR" || startsWith == "ST" || startsWith == "SY" || startsWith == "TA" || startsWith == "TN" || startsWith == "TQ" || startsWith == "TS" || startsWith == "WD" || startsWith == "WR" || startsWith == "WS" || startsWith == "WV" || startsWith == "YO")
		{
			insuranceFactory = true;
		}
	
	if (startsWithFirstLetter == "C" || startsWithFirstLetter == "S")
		{
			if ((no == "1") || (no == "2") || (no == "3") || (no == "4") || (no == "5") || (no == "6") || (no == "7") || (no == "8") || (no == "9")) 
			{
				insuranceFactory = false;
			}
		}
	
	if (insuranceFactory)
		{
			emails += ",taxi13";
		}
		
		
	//Freeway Insurance
	
	var freewayPostcode = true;
	var freewayAuth = true;	
	var freewayTA = new Array("Aberdeen City","Aberdeenshire","Barrow-in-Furness Borough Council","Barnsley Metropolitan Borough","Blackburn With Darwen Borough Council","Bolton Metropolitan Borough Council","Bristol City Council","Burnley Borough Council","Bury Metropolitan Borough Council","Calderdale Metropolitan Borough Council","Cardiff County Council","Caerphilly County Borough Council","Chesterfield Borough Council","City of London","Dartford Borough Council","Derby City Council","Glasgow City","Gateshead Metropolitan Borough Council","Hartlepool Borough Council","Hyndburn Borough Council","Leicester City Council","Public Carriage Office","Luton Borough Council","North Lanarkshire","Nottingham City Council","Walsall Metropolitan Borough Council","Watford Borough Council");
	
	
	if(document.getElementById("Level_Of_Cover").value == "3rd Party Only")
	{
		freewayTA.push("City of Birmingham","City of Manchester","City of Liverpool");
	}
	
	//Check Local Authority
	for(var freewayCount = 0; freewayCount < freewayTA.length; freewayCount++)
		{
			var authValue = freewayTA[freewayCount];
			
			if(document.getElementById('Licensing_Authority').value == authValue)
			{
				freewayAuth = false;
				break;
			}
		}
	
	//Check Postcode
	if(startsWith == "AB" || startsWith == "BB" || startsWith == "BL" || startsWith == "BR" || startsWith == "BS" || startsWith == "CF" || startsWith == "CR" || startsWith == "DA" || startsWith == "DE" || startsWith == "EN" || startsWith == "HA" || startsWith == "HX" || startsWith == "IG" || startsWith == "KT" || startsWith == "LA" || startsWith == "LE" || startsWith == "LU" || startsWith == "NE" || startsWith == "NG" || startsWith == "RM" || startsWith == "S4" || startsWith == "S7" || startsWith == "SM" || startsWith == "TN" || startsWith == "TS" || startsWith == "TW" || startsWith == "UB" || startsWith == "WD" || startsWith == "WS" || londonPostcode)
		{
			freewayPostcode = false;
		}
		
	if (startsWithFirstLetter == "G")
		{
			if ((no == "1") || (no == "2") || (no == "3") || (no == "4") || (no == "5") || (no == "6") || (no == "7") || (no == "8")) 
			{
				freewayPostcode = false;
			}
		}
	
	if(licHeldSince5 && DriverCover == "Insured Only" && TaxiBadge1Year && residence5Years && freewayPostcode && freewayAuth)
		{
			emails += ",taxi15";
		}
		





	// D Miller Insurance
	
	var dMillerPostcode = false;
	
	if(startsWith == "BB" || startsWith == "BL" || startsWith == "CH" || startsWith == "CW" || startsWith == "FR" || startsWith == "HD" || startsWith == "HL" || startsWith == "HX" || startsWith == "LA" || startsWith == "LL" || startsWith == "OL" || startsWith == "PR" || startsWith == "SK" || startsWith == "SL" || startsWith == "WA" || startsWith == "WN")
		{
			dMillerPostcode = true;
		}
		
	if ( startsWithFirstLetter == "M" )
		{
			if ((no == "1") || (no == "2") || (no == "3") || (no == "4") || (no == "5") || (no == "6") || (no == "7") || (no == "8") || (no == "9")) 
			{
				dMillerPostcode = true;
			}
		}
	
	if(licHeldSince2 && dMillerPostcode && min5YearsTaxiNCB)
		{
			emails += ",taxi16";
		}


		

	// XYZ Insurance
	
	if(age25Min && licHeldSince2 && startsWith != "BT" && passengers5 && document.getElementById("Taxi_Type").value != "Saloon Up To 5 Passengers")

		{
			emails += ",taxi17";
		}

	
	
	// A Plan
	
	var aPlanPostcode = false;
	
	if (startsWith == "BH" || startsWith == "SO" || startsWith == "DT" || startsWith == "PO" || startsWith == "PE" || startsWith == "BS" || startsWith == "EX" || startsWith == "TQ" || startsWith == "TN" || startsWith == "PL" || startsWith == "AB" || startsWith == "DD" || startsWith == "IP" || startsWith == "BA" || startsWith == "GL" || startsWith == "WR" || startsWith == "OX" || startsWith == "NN" || startsWith == "LL" || startsWith == "DG" || startsWith == "EH" || startsWith == "RH" || startsWith == "YO")
		{
			aPlanPostcode = true;
		}
	
	if (age30Min && residence4Years && TaxiBadge1Year && licHeldSince4 && aPlanPostcode)
		{
			emails += ",taxi18";	
		}
		
		

	// Milestone Insurance
	
	var milestonePostcode = true;
	
	if(londonPostcode || startsWith == "BB" || startsWith == "BL" || startsWith == "BR" || startsWith == "BT" || startsWith == "CH" || startsWith == "CW" || startsWith == "CR" || startsWith == "DA" || startsWith == "EN" || startsWith == "FY" || startsWith == "HA" || startsWith == "IG" || startsWith == "KT" || startsWith == "ME" || startsWith == "NE" || startsWith == "OL" || startsWith == "PR" || startsWith == "RH" || startsWith == "SE" || startsWith == "SG" || startsWith == "SK" || startsWith == "SM" || startsWith == "TN" || startsWith == "TW" || startsWith == "WA" || startsWith == "WD" || startsWith == "WN" || startsWith == "WS" || startsWith == "UB")
		{
			milestonePostcode = false;
		}
		
	if (startsWithFirstLetter == "B" || startsWithFirstLetter == "L" || startsWithFirstLetter == "M")
		{
			if ((no == "1") || (no == "2") || (no == "3") || (no == "4") || (no == "5") || (no == "6") || (no == "7") || (no == "8") || (no == "9")) 
			{
				milestonePostcode = false;
			}
		}
	
	if(document.getElementById("Taxi_No_Claims").value != "None" && milestonePostcode && age25Min)
		{
			emails += ",taxi19";	
		}
		
	if(document.getElementById("Taxi_No_Claims").value == "None")
		{
			if(scottishPostcode)
				{
					emails += ",taxi19";	
				}
		}
		
	
	//Barry Granger
		// Time Filter
		
		var BGtime = false;
		
		if(timeHours >= 9 && timeHours < 22)
			{
				BGtime = true;
			}			
	
	var grangerPostcodes = false;
/*	 ****************** Postcodes paused until further notice   ***********
	if (startsWith == "BA" || startsWith == "BH" || startsWith == "BN" || startsWith == "BR" || startsWith == "BS" || startsWith == "CB" || startsWith == "CF" || startsWith == "CO" || startsWith == "CT" || startsWith == "DA" || startsWith == "DT" || startsWith == "EX" || startsWith == "GL" || startsWith == "GU" || startsWith == "HP" || startsWith == "HR" || startsWith == "IP" || startsWith == "LD" || startsWith == "LL" || startsWith == "LN" || startsWith == "ME" || startsWith == "NP" || startsWith == "NN" || startsWith == "NR" || startsWith == "OX" || startsWith == "PE" || startsWith == "PL" || startsWith == "PO" || startsWith == "RH" || startsWith == "SA" || startsWith == "SG" || startsWith == "SN" || startsWith == "SO" || startsWith == "SP" || startsWith == "SY" || startsWith == "TA" || startsWith == "TN" || startsWith == "TQ" || startsWith == "TR" || startsWith == "WR")
		{
			grangerPostcodes = true;
		}
	******************	*/
	
	

	if(startsWith =="TN" || startsWith =="ME" || startsWith =="DA" || startsWith =="CT" || startsWith =="RH")
		{
			grangerPostcodes = true
		}
	
	if( age25Min && licHeldSince2 && TaxiBadge2Year && residence3Years && document.getElementById("Taxi_No_Claims").value != "None" && grangerPostcodes && notWeekend && BGtime)
		{
			if(document.getElementById("Drivers").value == "Insured Only" || document.getElementById("Drivers").value == "InsuredPlus1")
			{
				emails += ",taxi20";
			}
		}

	
	
		
	//Laurie Ross Insurance
	
	var lauriePostcode = false;
	
	if(startsWith == "EH" || startsWith == "FK" || startsWith == "KA" || startsWith == "ML" || startsWith == "PA")
		{
			lauriePostcode = true;
		}
		
	if (startsWithFirstLetter == "G")
		{
			if ((no == "1") || (no == "2") || (no == "3") || (no == "4") || (no == "5") || (no == "6") || (no == "7") || (no == "8") || (no == "9")) 
			{
				lauriePostcode = true;
			}
		}
		
	if(lauriePostcode)
		{
			emails += ",taxi21";	
		}
		
	
	//11 Answer
	
	var answer11Postcode = false;
	
	if(startsWith == "BA" || startsWith == "BH" || startsWith == "BN" || startsWith == "DT" || startsWith == "EX" || startsWith == "GL" || startsWith == "IP" || startsWith == "PL" || startsWith == "NR" || startsWith == "RH" || startsWith == "SP" || startsWith == "TN" || startsWith == "TQ" || startsWith == "TR")
		{
			answer11Postcode = true;	
		}
		
	if(answer11Postcode && age30Min && licHeldSince5 && residence5Years && TaxiBadge3Year && document.getElementById("Level_Of_Cover").value != "3rd Party Only")
		{
			emails += ",taxi22";
		}

		
	//Coversure
	
		
	if(postcode4 == "MK40" || postcode4 == "MK41" || postcode4 == "MK42" || postcode4 == "MK44" || postcode4 == "NN10" || postcode4 == "NN14" || postcode4 == "NN15" || postcode4 == "NN16" || postcode4 == "NN18" || postcode3 == "NN9" || postcode4 == "PE17" || postcode4 == "PE18" || postcode4 == "PE19" || postcode4 == "PE26" || postcode4 == "PE27" || postcode4 == "PE28" || postcode4 == "SG17" || postcode4 == "SG18" || postcode4 == "SG19" || postcode3 == "SG8" || postcode3 == "SG9")
		{
			emails += ",taxi23";	
		}
	
	
	//Club Class Insurance  Services
	
	var clubClassAuth = false;
	var clubClassTA = new Array("Ashford Borough Council", "Hastings Borough Council", "Rother District Council", "Eastbourne Borough Council", "Lewes District Council",
"Tunbridge Wells Borough Council", "Brighton & Hove Council");
	
	//Check Local Authority
	for(var clubClassCount = 0; clubClassCount < clubClassTA.length; clubClassCount++)
		{
			var clubClassValue = clubClassTA[clubClassCount];
			
			if(document.getElementById('Licensing_Authority').value == clubClassValue)
			{
				clubClassAuth = true;
				break;
			}
		}
	
	if (age35Min && maxAge69 && document.getElementById("Other_Occupation").value != "Yes" && licHeldSince5 && TaxiBadge5Year && min3YearsNCB && noConvictions && maxPassengers8 && clubClassAuth)
	{
		emails += ",taxi24";
	}
	
	
		

	//Bell Insurance
	
	var bellPostcode = true;
	
	if(startsWith == "BB" || startsWith == "BD" || startsWith == "BL" || startsWith == "BT" || startsWith == "CH" || startsWith == "EN" || startsWith == "FY" || startsWith == "HD" || startsWith == "LS"  || startsWith == "WS" || londonPostcode)
		{
			bellPostcode = false;
		}
	
	if (startsWithFirstLetter == "B" || startsWithFirstLetter == "M" || startsWithFirstLetter == "L" || startsWithFirstLetter == "S")
		{
			if ((no == "1") || (no == "2") || (no == "3") || (no == "4") || (no == "5") || (no == "6") || (no == "7") || (no == "8") || (no == "9")) 
			{
				bellPostcode = false;
			}
		}
		
		var bellAuth = true;
	var bellTA = new Array("City of London", "City of Liverpool","City of Bradford","Calderdale Metropolitan Borough Council", "City of Manchester" , "Blackburn With Darwen Borough Council", "Public Carriage Office" ,"City of Leeds" , "Three Rivers District Council","Oldham Metropolitan Borough Council", "Solihull Metropolitan Borough Council","Trafford Borough Council", "Wigan Metropolitan Borough Council","St Helens Metropolitan Borough Council");
	
	//Check Local Authority
	for(var bellCount = 0; bellCount < bellTA.length; bellCount++)
		{
			var bellValue = bellTA[bellCount];
			
			if(document.getElementById('Licensing_Authority').value == bellValue)
			{
				bellAuth = false;
				break;
			}
		}
		
	if(age30Min && bellPostcode && min1YearsNCB && noConvictions && DriverCover != "AnyDriver" && bellAuth )
		{
			emails += ",taxi25";	
		}
		
		
		//Coversure – Redditch Branch
	var coversurePostcode = false;
	
	if(postcode3 == "B97" || postcode3 == "B98" || postcode3 == "B60" || postcode3 == "B61" || startsWith == "WR" || startsWith == "HR" )
		{
			coversurePostcode = true;
		}
	
	if(coversurePostcode)
		{
			emails += ",taxi26";	
		}
		
		
		
	
		document.getElementById("recipient_bcc").value = emails;
		document.getElementById("reference").value = emails;
		 
	


}

	
	
function checkWholeForm(form) {
	
	var age = ageCalculation(age);
    var why = "";
	
	var startsWith = document.getElementById("Base_Postcode").value.substring(0,2);
	startsWith = startsWith.toUpperCase();
	
	
	why += checkDropdown(form.Title.value, " Title");
	why += isEmpty(form.Name.value, " Name");
	why += checkDOB();	
	why += checkDropdown(form.Residence.value, " UK Resident For");
	why += isEmpty(form.Home_Address.value, " Home Address");
	why += isEmpty(form.Home_Postcode.value, " Home Postcode");
	why += isEmpty(form.email.value, " Email");
	why += isEmpty(form.Home_Number.value, " Home Telephone Number");
	why += isEmpty(form.Mobile_Number.value, " Mobile/Work Telephone Number");
	why += checkDropdown(form.Other_Occupation.value, " Other Occupation");
	why += isEmpty(form.Base_Postcode.value, " Base / Rank Postcode");
	why += checkDropdown(form.licence_Held_For.value, " Full UK licence Held For");
	why += checkDropdown(form.TaxiBadge_Held_For.value, " Taxi / PCV Badge Held For");
	why += checkDropdown(form.Licensing_Authority.value, " Name Of Licensing Authority");
	
	why += isEmpty(form.Start_Date_Of_Cover.value, " Required Start Date Of Cover");
	why += checkDropdown(form.Level_Of_Cover.value, " Level Of Cover");
	why += checkDropdown(form.Drivers.value, " Drivers");
	why += checkDropdown(form.Taxi_No_Claims.value, " Taxi No Claims Bonus");
	why += checkDropdown(form.Private_No_Claims.value, " Private No Claims Bonus");
	why += checkDropdown(form.Accidents_Losses.value, " Accidents/Losses in last 5 years");
	why += checkDropdown(form.Convictions.value, " Convictions in last 5 years");
	
	why += isEmpty(form.Vehicle_Registration.value, " Vehicle Registration");
	why += checkDropdown(form.Vehicle_Use.value, " Vehicle Use");
	why += checkDropdown(form.Number_Of_Passengers.value, " Number Of Passengers");
	why += isEmpty(form.Vehicle_Make.value, " Vehicle Make");
	why += isEmpty(form.Vehicle_Model.value, " Vehicle Model");
	why += isEmpty(form.EngineSize.value, " Engine Size");
	why += checkDropdown(form.Taxi_Type.value, " Taxi Type");
	why += isEmpty(form.Year_Of_Manufacture.value, " Year Of Manufacturer");
	why += isEmpty(form.Current_Value.value, " Current Value");
	
	
 	if (why != "") {
       alert("Please fill in the following fields: \n"+why);
       return false;
    }
	
	else if(age < 25 || age > 90){
		alert('Unfortunately we are unable to submit your details as none of our partners will offer you cover due \nto your age. Please check your Date of Birth to make sure it has been entered correctly.');
		return false;
	}
	else if(startsWith == "BT"){
		alert('Unfortunately we are unable to submit your details as none of our partners will offer you cover due \ndue to your Base/Rank Postcode.');
		return false;
	}

	else if(why == ""){
	return true;
	}
}

function checkDOB(){
var error = "";
var currentDate = new Date();
var currentYear = currentDate.getFullYear();

if ( (document.getElementById("DOB_day").value == "") || (document.getElementById("DOB_month").value == "0") || (document.getElementById('DOB_year').value == "") || isNaN(document.getElementById('DOB_day').value) || isNaN(document.getElementById('DOB_year').value) )
		{
			error = "- Enter A Valid DOB"+"\n";
		}
else if(document.getElementById('DOB_year').value.length != 4)
		{
				error = "- Enter A Valid DOB Year"+"\n";
		}
	return error;
}


function isEmpty(strng, str){
var error = "";
  if (strng.length == 0){
     error = "-"+str+"\n";
  }
return error;	  
}

function checkDropdown(choice, str){
    var error = "";
	if (choice == "0"){
       error = "-"+str+"\n";
    }    
return error;
}

function radioChecked(radiobutton, str){
var error = "";
  for(i=0; i<radiobutton.length; i++){
 	 if(radiobutton[i].checked == true){
		 error = "";
		 break;
	 }
  	 else{
		 error = "-"+str+"\n";
	}
  }
return error;	  
}

function checkBoxChecked(checkbox, str){
    var error = "";
	if (!checkbox.checked){
       error = "-"+str+"\n";
    }    
return error;
}

