function validate_form() {
  var currentForm = document.registration;
  if (currentForm.full_name.value == "")
  {	
    alert("Please enter your full name");
  	currentForm.full_name.focus();
  	return false;
  }
  if (!validName(currentForm.full_name.value)) {
     alert("You've enter an invalid name");
     currentForm.full_name.focus();
     return false;
  } 
  if (currentForm.nric.value == "")
  {	
    alert("Please enter your NRIC number");
  	currentForm.nric.focus();
  	return false;
  }
  if (currentForm.nationality.value == "")
  {	
    alert("Please enter your nationality");
  	currentForm.nationality.focus();
  	return false;
  }
    if (currentForm.email_address.value == "")
  {	
    alert("Please enter your email address");
  	currentForm.email_address.focus();
  	return false;
  }
    if (!validEmail(currentForm.email_address)) {
     alert("You've enter an invalid email address");
     currentForm.email_address.focus();
     return false;
  } 
    if (currentForm.address.value == "")
  {	
    alert("Please enter your contact address");
  	currentForm.address.focus();
  	return false;
  }
    if (currentForm.postal_code.value == "")
  {	
    alert("Please enter your postal code");
  	currentForm.postal_code.focus();
  	return false;
  }

	var hasContact = 0;
    if (currentForm.home_no.value !== "")
  {	
  	hasContact = 1;
	if(!validPhone(currentForm.home_no)) { return false; }
  }

   if (currentForm.mobile_no.value !== "")
  {	
  	hasContact = 1;
	if(!validPhone(currentForm.mobile_no)) { return false; }
  }
   
   //optional
  if (currentForm.office_no.value !== "")
  {	
  	if(!validPhone(currentForm.office_no)) { return false; }
  }

   if (currentForm.fax_no.value !== "")
  {	
  	if(!validPhone(currentForm.fax_no)) { return false; }
  }



 if (hasContact == "0")
  {	
    alert("Please enter either your Home Contact or Mobile Number");
    currentForm.home_no.focus();
  	return false;
  }

    if (currentForm.file.value == "")
  {	
	alert("Please attach your reseume");
  	currentForm.file.focus();
  	return false;
  }    

	var filelen = currentForm.file.value.length;
	var filelen2 = currentForm.file.value.length - 3;
   if (currentForm.file.value.substr(filelen2,filelen) !== "doc" ) {
	alert("Please attach only MS Word document file");
  	currentForm.file.focus();
  	return false;

  }

   if (currentForm.position_1.value !== "")
	{
	if (currentForm.position_1.value.length < 5)
	{
	alert("Please enter the full position name");
  	currentForm.position_1.focus();
  	return false;
	}
  }

   if (currentForm.position_2.value !== "")
	{
	if (currentForm.position_2.value.length < 5)
	{
	alert("Please enter the full position name");
  	currentForm.position_2.focus();
  	return false;
	}
  }
     if (currentForm.position_3.value !== "")
	{
	if (currentForm.position_3.value.length < 5)
	{
	alert("Please enter the full position name");
  	currentForm.position_3.focus();
  	return false;
	}
  }

  
  if (currentForm.accept.checked == false)
  {	
    alert("You've to accept the Privacy Policy Statement");
  	currentForm.accept.focus();
  	return false;
  }

}



function validEmail(email) {
	if (email.value.length > 0) {
		var filter = /^[a-zA-Z0-9]([a-zA-Z0-9_\.\-\+])*\@([a-zA-Z0-9]([a-zA-Z0-9\-])*\.)+([a-zA-Z0-9])+$/;
		var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;

		if (!filter.test(email.value)) {			
		        return false;
		}
		else if (email.value.match(illegalChars)) {
				return false;
		} 

	}
	return true;
}

function validName(alphane)
{
	var numaric = alphane;
	for(var j=0; j<numaric.length; j++)
		{
		  var alphaa = numaric.charAt(j);
		  var hh = alphaa.charCodeAt(0);
		  if( (hh > 31 && hh<33)  || (hh > 64 && hh<91) || (hh > 96 && hh<123))
		  {
		  }
			else	{
				return false;
			}
		}
 return true;
}

function validPhone(fld) {
    var error = "";
    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');    

    if (isNaN(parseInt(stripped))) {
        alert("Please enter a valid phone number.");
		fld.focus(); 
	    return false;
    } else if (!(stripped.length >= 8)) {
        alert("Please enter a valid phone number.");
		fld.focus(); 
	    return false;
    }
	else { return true; }
}