//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 ismaxlength(obj){
	var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
	if (obj.getAttribute && obj.value.length>mlength)
	obj.value=obj.value.substring(0,mlength)
}





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 doit(){
		
var status1=true

if (!document.form1.salutation[0].checked && !document.form1.salutation[1].checked && !document.form1.salutation[2].checked && !document.form1.salutation[3].checked && !document.form1.salutation[4].checked && !document.form1.salutation[5].checked){
			alert("Please select your salutation.");
			document.form1.salutation[0].focus();
		return;
	}

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 address.");
	document.form1.email.focus();
	return;
}

if (trim(document.form1.officeno.value) == "" && trim(document.form1.mobileno.value) == "" && trim(document.form1.homeno.value) == "" ){
	alert("Please key in either your office no or/and mobile no or/and home no.");
	
	return;
}

if (trim(document.form1.nric.value) == ""){
	alert("Please key in your nric no.");
	document.form1.nric.focus();
	return;
}

if (trim(document.form1.homeblk.value) == ""){
	alert("Please key in your home address.");
	document.form1.homeblk.focus();
	return;
}
	if (trim(document.form1.unitno.value) == ""){
	alert("Please key in your unit no.");
	document.form1.unitno.focus();
	return;
}

if (trim(document.form1.street.value) == ""){
	alert("Please key in your street address.");
	document.form1.street.focus();
	return;
}
if (trim(document.form1.postal.value) == ""){
	alert("Please key in your postal code.");
	document.form1.postal.focus();
	return;
}


if (!document.form1.userType[0].checked && !document.form1.userType[1].checked){
			alert("Please select your preferred membership type.");
			document.form1.userType[0].focus();
		return;
	}

document.form1.submit();
}


