function checkForm(){
	
	var emails = "shop3,shop6,shop16"; // ,shop8,,shop19 
	
	var postcodeStr = document.getElementById("Postcode").value;
	var startsWith = postcodeStr.substring(0,2);
	var postcode3 = postcodeStr.substring(0,3);
	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 notWeekend = true;
	
	if(currentDay == 0 || currentDay == 6)
		{
			notWeekend = false;
		}
	
	var shopTrade = document.getElementById("Shop_Trade").value;
	
	//Number Of Claims
	
	var numberOfClaims = document.getElementById("InsuranceClaims5Years").value ;
	var max2Claims = false;
	
	if (numberOfClaims == "None" || numberOfClaims == "1" || numberOfClaims == "2")
		{
			max2Claims = true;
		}
		
	// Standard Construction
	
	var	standardConstruction = false;
	
	if (document.getElementById("Standard_Construction").value == "Yes")
		{
			standardConstruction = true;
		}
		
	//Doors Fitted With Proper Locks
	
	var locksFitted = false;
	
	if(document.getElementById("Doors_Fitted_Deadlock").value == "Yes")
		{
			locksFitted = true;
		}
		
	// 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;	
			}
			
		// SME Insurance
		
		if(startsWith != "BT" )
					{
						emails += ",shop2";
					}
		
					
		//Barry Grainger
		
			// Time Filter
			
			var BGtime = false;
			if(currentDay == 1 || currentDay == 2 || currentDay == 3 || currentDay == 4)
			{
			if(timeHours >= 9 && timeHours < 17)
				{
					BGtime = true;
				}
			}
			// Friday time - no leads after 5pm until 9am Monday
			if(currentDay == 5)
			{
				if(timeHours >= 9 && timeHours < 17)
				{
					BGtime = true;
				}
				
			}
		
				
		
		if(shopTrade != "Launderette (unattended)" || shopTrade != "D.I.Y. &/Or Hardware retail" || shopTrade != "Adult Bookstore" || shopTrade != "DIY - Including Timber" || shopTrade != "DIY Store" || shopTrade != "Petrol Station" || shopTrade != "Golf Professionals Shop")
			  {
				if(startsWith != "BT" && BGtime)
					{
						emails += ",shop5";
					}
			  }
			  
			  
		//Norwich & Peterborough Insurance
						
			
			if(startsWith == "CO" || startsWith =="CM" || startsWith =="SG" || startsWith == "CB" || startsWith == "IP" || startsWith == "NR" || startsWith == "PE" || startsWith == "NN" || startsWith == "LN")
			{
				emails += ",shop7";
			}


		// Coversure Insurance (Dudley) 
		var tradeCoversure = document.getElementById("Shop_Trade").value;
		if(notWeekend && timeHours >= 9 && timeHours < 16 && tradeCoversure != "Antiques Retailing" && tradeCoversure != "Second-hand Dealing")
	{
		emails += ",shop9";
	}


/*
		//First4 && PS Roberts && Yours Insurance && Hensure Insurance
	
	if(startsWith != "BT")
		{
			emails += ",shop10"; // paused 5th July, please place back in here once live again.
		}
*/

	// Cheers Insurance
	
	if(startsWith == "TW" || postcode3 == "KT1" || postcode3 == "KT2" || postcode3 == "KT7" || postcode3 == "KT8")
		{
			emails += ",shop14";	
		}
		


	//First4 && PS Roberts && Yours Insurance && Hensure Insurance
	var fridayTimes = true;
	if(currentDay == 5 && timeHours > 16)// if day is friday(5) and time is over 4pm then set value to false
	{
		fridayTimes = false;
	}
	
	
	if(startsWith != "BT" && notWeekend && timeHours >=7 && timeHours <17 && fridayTimes)
		{
			emails += ",shop15"; // shop10, paused 5th July, please place back in here once live again.
		}


/*	
	//Oncover Insurance
	
	var oncoverPostcode = true
	
	if(londonPostcode || startsWith == "GL")
		{
			oncoverPostcode = false;
		}
	
	if(oncoverPostcode)
		{
			emails += ",shop17";	
		}
*/
	
	//Wheels Insurance
	 
	if(timeHours >= 9 && timeHours < 17 && notWeekend)
	{
		emails += ",shop18";
	}
	
	
		
	document.getElementById("recipient_bcc").value = emails;
	document.getElementById("reference").value = emails;
}

function checkWholeForm(form) {
	
    var why = "";
	why += checkDropdown(document.getElementById('Title').value, " Title");
    why += isEmpty(document.getElementById('FullName').value, " Full Name");
	why += isEmpty(document.getElementById('DaytimeNumber').value, " Contact Telephone Number");	
	why += isEmpty(document.getElementById('email').value, " Email");
	why += isEmpty(document.getElementById('AddressApp').value, " Shop Address");
	why += isEmpty(document.getElementById('Postcode').value, " Shop Postcode");
	why += isEmpty(document.getElementById('BusinessName').value, " Business/Trading Name");
	why += checkStartDate();
	why += checkDropdown(document.getElementById('InsuranceClaims5Years').value, " Number of claims made in the past 5 years?");
	why += isEmpty(document.getElementById('FixturesAndFittings').value, " Tenants Improvements/Fixtures and Fittings");
	why += isEmpty(document.getElementById('General_Contents').value, " General Contents");
	why += isEmpty(document.getElementById('GeneralStock').value, " General Stock");
	why += isEmpty(document.getElementById('Tobacco').value, " Stock Of Tobacco");
	why += isEmpty(document.getElementById('WinesAndSpirits').value, " Wines & Spirits");
	why += checkDropdown(document.getElementById('Shop_Trade').value, " Trade");
	why += checkDropdown(document.getElementById('Standard_Construction').value, " Is the property of standard construction eg. Brick/Stone/Slate/Tile");
	why += checkDropdown(document.getElementById('Doors_Fitted_Deadlock').value, " Are all final exit doors fitted with minimum of 5 lever mortice deadlock");
	why += checkDropdown(document.getElementById('Premises_Occupied').value, " Are the premises occupied overnight? e.g. manager living above");
	why += checkDropdown(document.getElementById('ATM_Terminal').value, " Do you have a lottery terminal/ATM on site");
	why += checkDropdown(document.getElementById('Alarm').value, " Is There An Alarm System Fitted?");
	why += checkDropdown(document.getElementById('YearsEstablished').value, " How long have you been trading for?");
	 
    if (why != "") {
       alert("Please fill in the following fields: \n"+why);
       return false;
    }
}

function checkStartDate(){
var error = "";
if ( (document.getElementById("PolicyDate").value == "") || (document.getElementById("PolicyMonth").value == "0") || (document.getElementById('PolicyYear').value == "") )
		{
			error = "- Please Enter A Valid Policy Start Date"+"\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;
}
