window.onload = function() 
{
	if (document.getElementById)
	{
		/* Associate logo's onclick event with home page */
		var logo = document.getElementById("logo");
		if (logo != null)
		{
				logo.onclick = function() 
				{
					window.location = 'index.php';
					return false;
				}
		}
		
		var aContactFormFirst = document.getElementById('contactformfirst');
		if (aContactFormFirst != null) aContactFormFirst.onsubmit = JSFnValidateContactFormFirst;
		
		var aContactForm = document.getElementById('contactform');
		if (aContactForm != null) aContactForm.onsubmit = JSFnValidateContactForm;
		
		aLinks = document.getElementsByTagName("a");
		for (aIndex = 0; aIndex < aLinks.length; aIndex++)
		{
			if (aLinks[aIndex].href == 'http://www1.utdgroup.com/legal/cms/conveyancingwizard/default.asp?CDUserCode=0592C458-E401-4954-A82B-3812A051D60C') 
			{
				aLinks[aIndex].onclick = JsFnNewWindowLink;
			}
		}
		
		var aSpecificContact = document.getElementById("contactmessage");
		var aMenuSpecificContact = document.getElementById("menucontactmessage");
		if ((aSpecificContact != null) && (aMenuSpecificContact != null))
		{
				aMenuSpecificContact.innerHTML = aSpecificContact.innerHTML;
		}
	}	
}

function JsFnNewWindowLink()
{
	var aNewWindow = window.open(this.href, '', 'width=630px, height=720px, scrollbars');
	aNewWindow.focus();
	return false;
}

//Validate the contact form (first form)
var aContactRequiredFieldsFirst = new Array ("Forename","Please enter your forename to continue",
										"Surname","Please enter your surname to continue",
										"Day","Please enter your date of birth to continue",
										"Month","Please enter your date of birth to continue",
										"Year","Please enter your date of birth to continue",
										"Postcode","Please enter your postcode to continue",
										"Email","Please enter your email address to continue",
										"JointApplication","Please select whether this is a joint application to continue",
										"FoundProperty","Please select whether a property has been found to continue",
										"TelNo","Please enter your telephone number to continue");

//Validate the contact form
var aContactRequiredFields = new Array ("Nature","Please select Nature of Mortgage Enquiry to continue",
										"RepaymentOption","Please select a repayment option to continue",
										"CreditProblems","Please select if you have had any credit problems to continue",
										"LoanRequired","Please enter loan required to continue",
										"PropertyValue","Please enter property value to continue",
										"HouseholdIncome","Please enter house income to continue",
//										"disclosure","Please confirm that you have read and understood our inital disclosure document.",
										"custom","Please confirm that you have read and understood our Terms of Business and Privacy Policy.");
function JSFnValidateContactFormFirst()
{
	return JSFnValidateForm(aContactRequiredFieldsFirst);
}

function JSFnValidateContactForm()
{
	return JSFnValidateForm(aContactRequiredFields);
}

function JSFnValidateForm(aRequiredFields)
{
	for (aIndex = 0; aIndex < aRequiredFields.length; aIndex = aIndex + 2)
	{
		currElement = document.getElementById(aRequiredFields[aIndex]);
		if (currElement != null)
		{
			if  (   (   (currElement.type == 'text')
				     && (currElement.value == ''))
				 || (   (currElement.type == 'password')
				     && (currElement.value == ''))
				 || (   (currElement.type == 'checkbox')
				     && (currElement.checked == false))
				 || (   (currElement.type == 'file')
				     && (currElement.value == ''))
				 || (   (currElement.type == 'textarea')
				     && (currElement.value == ''))
				 || (   (currElement.type == 'select-one')
				     && (currElement.value == '')))
			{
				alert(aRequiredFields[aIndex + 1]);
				return false;
			}
			else if (currElement.type == 'radio')
			{
				aIndex = aIndex + 2;
				if (!currElement.checked)
				{
					currElement = document.getElementById(aRequiredFields[aIndex]);
					if ((currElement.type == 'radio') && (!currElement.checked))
					{
						alert(aRequiredFields[aIndex + 1]);
						return false;
					}
				}
			}
		}
	}
	return true;
}
