
function checkEmail(strEmail) {
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (!filter.test(strEmail)) {
		return false;
	}
	return true;
}

function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}


function validateContactForm() {
		
	if (trim($F('frmName')) == '')
	{
		$('frmName').focus();
		alert('Please fill in your Name');
		return false;
	}

	if (trim($F('frmEmail')) == '')
	{
		$('frmEmail').focus();
		alert('Please fill in your Email address');
		return false;
	}

	if (!checkEmail(trim($F('frmEmail'))))
	{
		$('frmEmail').focus();
		alert('Please enter a valid email address ');
		return false;
	}

	if ($F('frmEmail') != $F('frmEmailConfirm'))
	{
		$('frmEmailConfirm').focus();
		alert('Your email addresses do not match');
		return false;
	}
	
	if (trim($F('frmMessage')) == '')
	{
		$('frmMessage').focus();
		alert('Please fill in your Message');
		return false;
	}
	
	if (trim($F('frmContact')) == 'x')
	{
		$('frmContact').focus();
		alert('Please select a Recipient');
		return false;
	}

	
	if (trim($F('frmCaptcha')) == '')
	{
		$('frmCaptcha').focus();
		alert('Please fill in the Security Code');
		return false;
	}

	$('frmObjContact').submit();
	return true;
}

function validateBrochureForm() {
		
	if (trim($F('frmName-bro')) == '')
	{
		$('frmName-bro').focus();
		alert('Please fill in your Name');
		return false;
	}

	if (trim($F('frmAddress1-bro')) == '')
	{
		$('frmAddress1-bro').focus();
		alert('Please fill in your Address');
		return false;
	}
	
	if (trim($F('frmTownCity-bro')) == '')
	{
		$('frmTownCity-bro').focus();
		alert('Please fill in your Town/City');
		return false;
	}

	if (trim($F('frmCounty-bro')) == '')
	{
		$('frmCounty-bro').focus();
		alert('Please fill in your County');
		return false;
	}

	if (trim($F('frmPostCode-bro')) == '')
	{
		$('frmPostCode-bro').focus();
		alert('Please fill in your Post Code');
		return false;
	}

	if (trim($F('frmEmail-bro')) == '')
	{
		$('frmEmail-bro').focus();
		alert('Please fill in your Email address');
		return false;
	}

	if (!checkEmail(trim($F('frmEmail-bro'))))
	{
		$('frmEmail-bro').focus();
		alert('Please enter a valid email address ');
		return false;
	}

	if ($F('frmEmail-bro') != $F('frmEmailConfirm-bro'))
	{
		$('frmEmailConfirm-bro').focus();
		alert('Your email addresses do not match');
		return false;
	}
	
	if (trim($F('frmCaptcha-bro')) == '')
	{
		$('frmCaptcha-bro').focus();
		alert('Please fill in the Security Code');
		return false;
	}

	$('frmObjBrochure').submit();
	return true;
}

function validateEnquiryForm() {
		
	if (trim($F('frmName')) == '')
	{
		$('frmName').focus();
		alert('Please fill in your Name');
		return false;
	}

	if (trim($F('frmEmail')) == '')
	{
		$('frmEmail').focus();
		alert('Please fill in your Email address');
		return false;
	}

	if (!checkEmail(trim($F('frmEmail'))))
	{
		$('frmEmail').focus();
		alert('Please enter a valid email address ');
		return false;
	}

	if ($F('frmEmail') != $F('frmEmailConfirm'))
	{
		$('frmEmailConfirm').focus();
		alert('Your email addresses do not match');
		return false;
	}
		
	if (trim($F('frmTelephone')) == '')
	{
		$('frmTelephone').focus();
		alert('Please fill in your Telephone number');
		return false;
	}

	if ($F('frmAreaInterest') == "")
	{
		$('frmAreaInterest').focus();
		alert('Please select an Area of Interest');
		return false;
	}

	if ($F('frmAreaInterest') == "z" && $F('frmAreaInterestOther') == "Please indicate interest") 
	{
		$('frmAreaInterestOther').focus();
		alert('Please fill in your interest');
		return false;
	}		
	
	if (trim($F('frmCaptcha')) == '')
	{
		$('frmCaptcha').focus();
		alert('Please fill in the Security Code');
		return false;
	}

	$('frmObjEnquiry').submit();
	return true;
}