function checkForm(){
	
	var emails = "gt2,landlord4,landlord15";
	
	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);
	
	var RebuiltCost = parseInt(document.getElementById("Rebuild_Cost").value);
	
	// 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;
		}

/* Paused 26th July
// Quote Me Today
	if (startsWith != "BT")
		{
			emails += ",landlord3";	
		}

*/
	// 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(BGtime && RebuiltCost >= 200000)
		{
			emails += ",landlord6";	
		}

		
		
	// Cheers Insurance
	
	if(startsWith == "TW" || postcode3 == "KT1" || postcode3 == "KT2" || postcode3 == "KT7" || postcode3 == "KT8")
		{
			emails += ",landlord12";	
		}
		
	/*	
	//Bedfords (5pm - 9am)
	
	var bedfordTime = true;
	
	if(timeHours > 9 && timeHours < 17)
		{
			bedfordTime = false;
		}
	
	if(bedfordTime)
		{
			emails += ",landlord14";	
		}
	*/
	
	
	//Wheels Insurance
	/* Paused 27 August
	if(timeHours >= 9 && timeHours < 17 && notWeekend)
	{
		emails += ",landlord17";
	}
	*/

	document.getElementById("recipient_bcc").value = emails;
	document.getElementById("reference").value = emails;
}
	

function checkWholeForm(form) {
	
	//var em = form.Email.value;
	
    var why = "";
    why += isEmpty(document.getElementById('FullName').value, " Name");
	why += isEmpty(document.getElementById('Clients_Address').value, " Home Address");
	why += isEmpty(document.getElementById('Postcode').value, " Home Postcode");	
	why += isEmpty(document.getElementById('DaytimeNumber').value, " Contact Telephone");
	why += isEmpty(document.getElementById('email').value, " Email");
	
	why += checkStartDate();
	why += checkDropdown(document.getElementById('Type_Of_Flats').value, " Type Of Flats");
	why += checkDropdown(document.getElementById('Being_Insured').value, " Are you insuring the whole block or an individual flat?");
	why += checkAmount(document.getElementById('Rebuild_Cost').value, " Rebuild Cost Of The Property", " Please enter a valid Rebuild Cost Of The Property as a whole number e.g. 1000");
	why += checkDropdown(document.getElementById('ContentCover').value, " Contents Cover Required?");
	why += checkDropdown(document.getElementById('LossOfRentCover').value, " Loss Of Rent Cover Required?");
	why += checkDropdown(document.getElementById('InsuranceClaims5Years').value, " Have you made any claims in the past 5 years?");
	
	why += isEmpty(document.getElementById('AddressApp').value, " Address Of The Property To Be Insured");
	why += isEmpty(document.getElementById('PropertyPostCode').value, " Postcode Of The Property To Be Insured");
	why += checkDropdown(document.getElementById('NumberOfStories').value, " Number Of Stories");
	why += checkDropdown(document.getElementById('Wall_Type').value, " Wall Type");
	why += checkDropdown(document.getElementById('Roof_Type').value, " Roof Type");
	why += checkDropdown(document.getElementById('Floor_Type').value, " Floor Type");
	why += checkDropdown(document.getElementById('ListedBuilding').value, " Is The Property Listed?");
	why += isEmpty(document.getElementById('ConstructionYear').value, " Year Built");
	why += checkDropdown(document.getElementById('TenantType').value, " Type Of Tenants");
	

	 
if (why != "") {
       alert("Please fill in the following fields: \n"+why);
       return false;
    }
	else if(why == ""){
	return true;
	}
}

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 checkAmount(strng, errorMsg, noNumberMsg){
	var error = "";
	if (strng.length == 0){
		 error = "-"+errorMsg+"\n";
	  }
	
	else if (isNaN(strng)){
		 error = "-"+noNumberMsg+"\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;
}