function checkForm(){
	
	var emails = "gt2,landlord4,landlord15"; // landlord3, paused 26th July
	
	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 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;
		}
		
	
	// Partner Filters  landlord11 = bridle insurance
	
	if (startsWith != "BT")
		{
			emails += ",landlord8";	// landlord11 paused 15 July 2010
		}


	// 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)
		{
			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";
	}
	*/
	//Coversure Kidderminster Branch
	if(timeHours >= 9 && timeHours < 17 && notWeekend)
	{
		emails += ",landlord18";
	}

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

function checkWholeForm(form) {

    var why = "";

    why += isEmpty(form.FullName.value, " Name");
	why += isEmpty(form.DaytimeNumber.value, " Contact Telephone");	
	why += isEmpty(form.email.value, " Email");
	
	why += checkStartDate();
	why += isEmpty(form.Trade_Of_Building.value, " Trade/Occupation Of The Building");	
	why += isEmpty(document.getElementById('ContentCover').value, " Rebuild Cost Of The Property");
	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(form.AddressApp.value, " Address Of The Property To Be Insured");
	why += isEmpty(form.Postcode.value, " Postcode");
	why += checkDropdown(form.Number_Of_Stories.value, " Number Of Stories");
	why += checkDropdown(form.Wall_Type.value, " Wall Type");
	why += checkDropdown(form.Roof_Type.value, " Roof Type");
	why += checkDropdown(form.Floor_Type.value, " Floor Type");
	why += checkDropdown(form.FlatRoof.value, " Is There Any Flat Area Of Roof?");
	why += checkDropdown(form.ListedBuilding.value, " Is The Property Listed?");
	why += isEmpty(form.ConstructionYear.value, "Year Built");
	

 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 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;
}

