function AddressSearch()
{
	var Postcode = document.getElementById("Textbox_SearchPostcode").value;
	
	if (Postcode == "")
	{
		alert("You must enter a FULL postcode for the address search to be successful.");
		document.getElementById("Textbox_SearchPostcode").focus();
	}
	else
	{
		window.open("/Contact/AddressSearch.aspx?Postcode=" + Postcode, null, "height=400,width=800,resizeable=no,scrollbars=yes");
	}
}

function ChangeCallMeState(_Enabled)
{
	document.getElementById("RingMy").disabled = !_Enabled;
	document.getElementById("RingOn").disabled = !_Enabled;
	document.getElementById("RingFrom").disabled = !_Enabled;
	document.getElementById("RingTo").disabled = !_Enabled;
}

function SubmitForm()
{
	var ValidationMessage = ""
		
	if (document.getElementById("Textbox_FirstName").value == "")
	{
		if (ValidationMessage != "") { ValidationMessage += "\n"; }
		ValidationMessage += "You must enter a first name.";
	}
	
	if (document.getElementById("Textbox_LastName").value == "")
	{
		if (ValidationMessage != "") { ValidationMessage += "\n"; }
		ValidationMessage += "You must enter a last name.";
    }

    if (document.getElementById("Textbox_Email").value == "") 
    {
        if (ValidationMessage != "") { ValidationMessage += "\n"; }
            ValidationMessage += "You must enter Email.";
    }


    if (document.getElementById("Textbox_TelephoneHome").value == "") 
    {
        if (ValidationMessage != "") { ValidationMessage += "\n"; }
            ValidationMessage += "You must enter Home Telephone Number.";
    }
    
	if (document.getElementById("Textbox_Postcode").value == "")
	{
		if (ValidationMessage != "") { ValidationMessage += "\n"; }
		ValidationMessage += "You must enter your postcode.";
	}

	if (window.location.search.indexOf("aftersalesser") != -1 || window.location.search.indexOf("aftersalesparts") != -1)
	{
		if (document.getElementById("DlServiceManu").value == "0")
		{
			if (ValidationMessage != "") { ValidationMessage += "\n"; }
			ValidationMessage += "You must select an manufacturer";
		}
		
		if (window.location.search.indexOf("aftersalesser") != -1)
		{
			var today = new Date();
			var prefServiceDate = new Date();
			var altServiceDate = new Date();
			
			prefServiceDate.setFullYear(parseInt(document.getElementById("DlPrefdServDateYear").value), parseInt(document.getElementById("DlPrefdServDateMonth").value) -1 , parseInt(document.getElementById("DlPrefdServDateDay").value));
			
			altServiceDate.setFullYear(parseInt(document.getElementById("DlAltdServDateYear").value), parseInt(document.getElementById("DlAltdServDateMonth").value) -1 , parseInt(document.getElementById("DlAltdServDateDay").value));
						
			if (prefServiceDate <= today)
			{
				if (ValidationMessage != "") { ValidationMessage += "\n"; }
				ValidationMessage += "You must select a preferred service date in advance";
			}

			if (altServiceDate <= today)
			{
				if (ValidationMessage != "") { ValidationMessage += "\n"; }
				ValidationMessage += "You must select an alternative service date in advance";
			}

			if (document.getElementById("DlServiceFuelMenu").value == "0")
			{
				if (ValidationMessage != "") { ValidationMessage += "\n"; }
				ValidationMessage += "You must select a fuel type";
			}
		
			if (document.getElementById("Textbox_ServiceModel").value == "")
			{
				if (ValidationMessage != "") { ValidationMessage += "\n"; }
				ValidationMessage += "You must select an model";
			}
			
			if (document.getElementById("TextBox_Mileage").value == "")
			{
				if (ValidationMessage != "") { ValidationMessage += "\n"; }
				ValidationMessage += "You must enter mileage for the vehicle";
			}
			
			if (document.getElementById("Textbox_Year").value == "")
			{
				if (ValidationMessage != "") { ValidationMessage += "\n"; }
				ValidationMessage += "You must enter the year for the vehicle";
			}

			if (document.getElementById("TextBox_RegNo").value == "")
			{
				if (ValidationMessage != "") { ValidationMessage += "\n"; }
				ValidationMessage += "You must enter the registration number for the vehicle";
			}
		}	
	}
	
	
	if (document.getElementById("Textbox_Email").value != "" && document.getElementById("Textbox_TelephoneHome").value != "")
	{
		if (document.getElementById("RadioButton_Email").checked && document.getElementById("Textbox_Email").value == "")
		{
			if (ValidationMessage != "") { ValidationMessage += "\n"; }
			ValidationMessage += "To be contacted by email you must enter an email address.";
		}
		
		if (document.getElementById("RadioButton_Phone").checked)
		{
			switch (document.getElementById("RingMy").value)
			{
				case "0":
					if (document.getElementById("Textbox_TelephoneHome").value == "")
					{
						if (ValidationMessage != "") { ValidationMessage += "\n"; }
						ValidationMessage += "To be contacted on your home telephone then you must enter that telephone number.";
					}
					break;
				case "1":
					if (document.getElementById("Textbox_TelephoneWork").value == "")
					{
						if (ValidationMessage != "") { ValidationMessage += "\n"; }
						ValidationMessage += "To be contacted on your work telephone then you must enter that telephone number.";
					}
					break;
				case "2":
					if (document.getElementById("Textbox_TelephoneMobile").value == "")
					{
						if (ValidationMessage != "") { ValidationMessage += "\n"; }
						ValidationMessage += "To be contacted on your mobile telephone then you must enter that telephone number.";
					}
					break;
			}
		}
	}
	
	if (ValidationMessage != "")
	{
		alert(ValidationMessage);
		return false;
	}
	
	return true;
}

function UpdatePrefDaysForMonth()
{
	var daysInMonthsValue = document.MainForm.DaysInMonths.value;
	var daysInMonthsArr = daysInMonthsValue.split("|");

	var preServiceDateDay = document.getElementById("DlPrefdServDateDay");
	var preServiceDateYear = document.getElementById("DlPrefdServDateYear");
	
	//Leap year check - if required, add extra day for February
	if (preServiceDateYear % 4 == 0)
		daysInMonthsArr[1] = "29";
	
	var preServiceDateMonthInt = parseInt(document.getElementById("DlPrefdServDateMonth").value) - 1;
	
	preServiceDateDay.options.length = 0;
	
	var daysInCurrentMonth = parseInt(daysInMonthsArr[preServiceDateMonthInt]);
	
	for (i = 1; i <= daysInCurrentMonth; i++)
		preServiceDateDay.options[preServiceDateDay.options.length] = new Option(i, i); 
}

function UpdateAltDaysForMonth()
{	
	var daysInMonthsValue = document.MainForm.DaysInMonths.value;
	var daysInMonthsArr = daysInMonthsValue.split("|");

	var altServiceDateDay = document.getElementById("DlAltdServDateDay");
	var altServiceDateYear = document.getElementById("DlAltfdServDateYear");
	
	//Leap year check - if required, add extra day for February
	if (altServiceDateYear % 4 == 0)
		daysInMonthsArr[1] = "29";
	
	var altServiceDateMonthInt = parseInt(document.getElementById("DlAltdServDateMonth").value) - 1;
	
	altServiceDateDay.options.length = 0;
	
	var daysInCurrentMonth = parseInt(daysInMonthsArr[altServiceDateMonthInt]);
	
	for (i = 1; i <= daysInCurrentMonth; i++)
		altServiceDateDay.options[altServiceDateDay.options.length] = new Option(i, i); 

}




