// JavaScript Document

function validation() {
// error text
missinginfo = "";

// validate name
var nameRe = /^[A-z-' '-'-'-''']*$/;
if (!nameRe.test(document.form.name.value) || (document.form.name.value =="")) {
missinginfo += "\n     -  Name";
}
//validate age
	var ageRe = /^[1-99]*$/;
if (!ageRe.test(document.form.age.value) || (document.form.age.value =="")) {
missinginfo += "\n     -  Age";
}


// validate nric
//var nricError = false;
//	var nricRe = /^[1-9]*$/;
//	var nricReFirst = /^[S-s]*$/;
//	var nricReLast = /^[A-j-''-Z-z]*$/;
//for (var i= 1; i<8 ; i++) {
//	if (!nricRe.test(document.form.nric.value.charAt(i)) || (!nricReFirst.test(document.form.nric.value.charAt(0))) || (!nricReLast.test(document.form.nric.value.charAt(8))) ||(document.form.nric.value.length != "9")) {
//		var nricError = true;
//		
//		}
//}										
//if(nricError == true) {
//		missinginfo += "\n     -  NRIC";	
//	}
// valiate address
if (document.form.nric.value == "") {

missinginfo += "\n     -  NRIC";
}

/* validate email
if ((document.form.email.value == "") || 
(document.form.email.value.indexOf('@') == -1) || 
(document.form.email.value.indexOf('.') == -1) ||
((document.form.email.value.indexOf('.')) < (document.form.email.value.indexOf('@')))
) {

missinginfo += "\n     -  Email address";
}
*/

// Email Validation Javascript
// copyright 23rd March 2003, by Stephen Chapman, Felgall Pty Ltd

// You have permission to copy and use this javascript provided that
// the content of the script is not changed in any way.

var  noEmailError = true;
if (document.form.email.value == '') {
   noEmailError = false;

} else {
var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
for (i=0; i<invalidChars.length; i++) {
   if (document.form.email.value.indexOf(invalidChars.charAt(i),0) > -1) {
   noEmailError = false;
 
   }
}

for (i=0; i<document.form.email.value.length; i++) {
   if (document.form.email.value.charCodeAt(i)>127) {
    noEmailError = false;

   }
}

var atPos = document.form.email.value.indexOf('@',0);
if (atPos == -1) {
 noEmailError = false;
}


if (atPos == 0) {
    noEmailError = false;
 
}

if (document.form.email.value.indexOf('@', atPos + 1) > - 1) {
 noEmailError = false;

}

if (document.form.email.value.indexOf('.', atPos) == -1) {
  noEmailError = false;
}

if (document.form.email.value.indexOf('@.',0) != -1) {
 noEmailError = false;
 
}
if (document.form.email.value.indexOf('.@',0) != -1){
   noEmailError = false;

}
if (document.form.email.value.indexOf('..',0) != -1) {
 noEmailError = false;
  
}

var suffix = document.form.email.value.substring(document.form.email.value.lastIndexOf('.')+1);

if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
 noEmailError = false;

}
}

if ( noEmailError == false) {
missinginfo += "\n     -  Email Address";
	
	}


// valiate address
if (document.form.contactno.value == "") {

missinginfo += "\n     -  Contact No.";
}


// check if mailing list checkbox is tick
var mailingList = false;
if(document.form.mailingList.checked == true) {
	mailingList = true;
	
	}

// display text is there is error
if (missinginfo != "") {
missinginfo ="_____________________________\n" +
"You failed to correctly fill in your:\n" +
missinginfo + "\n_____________________________" +
"\nPlease re-enter and submit again!";
alert(missinginfo);
return false;
}
else{
	
	document.forms["form"].action="processcontact.php";
  document.forms["form"].method="POST";
  document.forms["form"].submit();

	}
}

