//this file is a javascript validation collection.
//please feel free to use this script.
//this is my own & my collegue javascript collection.
//can be free to use for doing project under Vintedge.Pte. Ltd.
function hand(){

}
 
function openWindow(url) {
	parameter = "width=610,height=440,toolbar=no,scrollbars=no,resizable=no";
	var v = window.open(url,'_blank',parameter);
}

function reset() {
	document.form1orms[0].reset();
}

function check_email(address) {
	//var emailPat = /^((\w|\.|\_)+)@(\[\d{1,3}(\.\d{1,3}){3}]|[A-Za-z]\w*(\.[A-Za-z]\w*)+)$/;
	var emailPat = /^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/;
	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 check(){
	
	if (trim(document.form1.name.value) == ""){
		alert("Please key in your name.");
		document.form1.name.focus();
		return;
	}

	if (document.form1.email.value == "" || !check_email(document.form1.email.value)){
		alert("Please key in a valid email.");
		document.form1.email.focus();
		return;
	}

	if (!document.form1.gender[0].checked && !document.form1.gender[1].checked){
			alert("Please select your gender.");
			document.form1.gender[0].focus();
		return;
	}

	if (document.form1.contact.value == ""){
		alert("Please key in your contact number.");
		document.form1.contact.focus();
		return;
	}
	//if (document.form1.contact.value.length > 0)
	//{
	//	if (((document.form1.contact.value.indexOf ('6') != 0) && (document.form1.contact.value.indexOf ('9') != 0) && (document.form1.contact.value.indexOf ('8') != 0)) || (document.form1.contact.value.length < 8)){
	//		alert("Your contact number format does not seem to be correct.");
	//		document.form1.contact.focus();
	//		return;
	//		}
	//}

	if (trim(document.form1.weekday.value) == ""){
		alert("Please select your preferred contact time at weekday.");
		document.form1.weekday.focus();
		return;
	}
	
	if (trim(document.form1.weekend.value) == ""){
		alert("Please select your preferred contact time at weekend.");
		document.form1.weekend.focus();
		return;
	}

	if (trim(document.form1.centre.value) == ""){
		alert("Please select your preferred centre.");
		document.form1.centre.focus();
		return;
	}

	if (trim(document.form1.enquiry.value) == ""){
		alert("Please key in your enquiry.");
		document.form1.enquiry.focus();
		return;
	}

	if ((document.form1.enquiry.value.length) >= 2045){
		alert("Your enquiry is too long. Please shorten your enquiry.");
		document.form1.enquiry.focus();
		return;
	}
	
	document.form1.submit();
}
