function check_email(address) {
	var emailPat = /^((\w|\.|\_)+)@(\[\d{1,3}(\.\d{1,3}){3}]|[A-Za-z]\w*(\.[A-Za-z]\w*)+)$/;
	var matchArray = address.match(emailPat);
	if (matchArray == null)
		return false;
	else
		return true;
}

function isDigit() {
if ((event.keyCode < 48)||(event.keyCode > 57 )) {
  if (event.keyCode != 46)
	{event.returnValue=false;}
}
}

function trim(inputString)
{
	var retValue = inputString;
	var ch = retValue.substring(0, 1);

	while (ch == " ")
	{ // Check for space at the start of the string
		retValue = retValue.substring(1, retValue.length);
		ch = retValue.substring(0, 1);
	}

	ch = retValue.substring(retValue.length-1, retValue.length);

	while (ch == " ")
	{ // Check for spaces at the end of the string
		retValue = retValue.substring(0, retValue.length-1);
		ch = retValue.substring(retValue.length-1, retValue.length);
	}
	
	return retValue;
}


function doit(){
if (trim(document.f.name.value) == ""){
	alert("Please key in your name.");
	document.f.name.focus();
	return;
	}
if (trim(document.f.company.value) == ""){
	alert("Please key in your company name.");
	document.f.company.focus();
	return;
	}

if (trim(document.f.email.value) == ""){
	alert("Please key in your email address.");
	document.f.email.focus();
	return;
	}
if(!check_email(trim(document.f.email.value)))
 {
   validity = false;
   alert("Your email format does not seem to be correct.");
   document.f.email.focus();
   return;
 }

if (trim(document.f.contact.value) == ""){
	alert("Please key in your contact number.");
	document.f.contact.focus();
	return;
}

if (document.f.contact.value.length > 0)
{
	if (document.f.contact.value.length < 8){
		alert("Your contact number format does not seem to be correct.");
		document.f.contact.focus();
		return;
	}
}

if (isNaN(document.f.contact.value) == true)
{
	alert("Your contact number format does not seem to be correct.");
	document.f.contact.focus();
	return;
}

if (trim(document.f.fax.value) == ""){
	alert("Please key in your fax number.");
	document.f.fax.focus();
	return;
}

if (document.f.fax.value.length > 0)
{
	if (document.f.mobile.value.length < 8){
		alert("Your fax number format does not seem to be correct.");
		document.f.fax.focus();
		return;
	}
}

if (isNaN(document.f.fax.value) == true)
{
	alert("Your fax number format does not seem to be correct.");
	document.f.fax.focus();
	return;
}

if (trim(document.f.msg.value) == ""){
	alert("Please key in your message.");
	document.f.msg.focus();
	return;
	}

document.f.submit();
}