function ValidateForm(theForm) {
  var fname = theForm.fname.value;
  var lname = theForm.lname.value;
  var uname = theForm.username.value;
  var passwd = theForm.password.value;
  var vpasswd = theForm.verifypassword.value;
	var sex = theForm.sex.value;
	var bdate_dd = theForm.birthdate_dd.value;
	var bdate_mm = theForm.birthdate_mm.value;
	var bdate_yy = theForm.birthdate_yy.value;
  var idcardno = theForm.idcardno.value;
  var passportno = theForm.passportno.value;
  var militaryregno = theForm.militaryregno.value;
  var address = theForm.address.value;
  var city = theForm.city.value;
  var postalcode = theForm.postalcode.value;
  var phone = theForm.phone.value;
  var mobilephone = theForm.mobilephone.value;
  var email = theForm.email.value;
  var schoolname = theForm.schoolname.value;
  var schoolclass = theForm.schoolclass.value;
  var fax = theForm.fax.value;
  var progrlanguage = theForm.progrlanguage.value;

	var bdate = new Date(bdate_yy,(bdate_mm-1),bdate_dd)
	var currdate = new Date()

  if (!fname) {
    alert("You must enter first name.");
    return false;
	} else if (!fname.match(/^[a-zA-Z ]+$/)) {
		alert("First name should be alphabetic and in English.");
		return false;
	} else if (!lname) {
		alert("You must enter last name.");
		return false;
	} else if (!lname.match(/^[a-zA-Z ]+$/)) {
		alert("Last name should be alphabetic and in English.");
		return false;
	} else if (!uname) {
		alert("You must enter username.");
		return false;
	} else if ((uname.length < 6) || (uname.length > 8)) {
		alert("Username should be 6-8 characters.");
		return false;
	} else if (!uname.match(/^[a-zA-Z0-9]+$/)) {
		alert("Username should be alphanumeric.");
		return false;
	} else if (!passwd) {
		alert("You must enter password.");
		return false;
	} else if ((passwd.length < 6) || (passwd.length > 8)) {
		alert("Password should be 6-8 characters.");
		return false;
	} else if (!passwd.match(/^[a-zA-Z0-9]+$/)) {
		alert("Password should be alphanumeric.");
		return false;
	} else if (passwd != vpasswd) {
		alert("Confirm password does not match.");
		return false;
	} else if ((!bdate_dd) || (!bdate_mm) || (!bdate_yy)) {
		alert("You must enter birth date.");
		return false;
	} else if ((bdate_dd != bdate.getDate()) || (bdate_mm != bdate.getMonth()+1) || (bdate_yy != bdate.getFullYear())) {
		alert("Invalid date.");
		return false;
	} else if ( ((currdate.getFullYear() - bdate_yy) > 20) || (((currdate.getFullYear() - bdate_yy) == 20) && (bdate_mm < currdate.getMonth()+1)) || (((currdate.getFullYear() - bdate_yy) == 20) && (bdate_mm == currdate.getMonth()+1) && (bdate_dd < currdate.getDate())) ) {
		alert("Your should be 12-20 years old.");
		return false;
	} else if ( ((currdate.getFullYear() - bdate_yy) < 12) || (((currdate.getFullYear() - bdate_yy) == 12) && (bdate_mm > currdate.getMonth()+1)) || (((currdate.getFullYear() - bdate_yy) == 12) && (bdate_mm == currdate.getMonth()+1) && (bdate_dd > currdate.getDate())) ) {
		alert("Your should be 12-20 years old.");
		return false;
	} else if (!idcardno) {
		alert("You must enter Id Card No.");
		return false;
	} else if (idcardno.length > 8) {
		alert("Id Card No should be maximum 8 digits.");
		return false;
	} else if (!idcardno.match(/^[0-9]+$/)) {
		alert("Id Card No should be numeric.");
		return false;
	} else if (passportno.length > 12) {
		alert("Passport No should be maximum 12 characters.");
		return false;
	} else if ((passportno) && (!passportno.match(/^[a-zA-Z0-9]+$/))) {
		alert("Passport No should be alphanumeric.");
		return false;
	} else if ((sex == "M") && (!militaryregno)) {
		alert("You must enter Military Reg No.");
		return false;
	} else if (militaryregno.length > 8) {
		alert("Military Reg No should be maximum 8 digits.");
		return false;
	} else if ((militaryregno) && (!militaryregno.match(/^[0-9]+$/))) {
		alert("Military Reg No should be numeric.");
		return false;
	} else if (!address) {
		alert("You must enter address.");
		return false;
	} else if (!city) {
		alert("You must enter city.");
		return false;
	} else if (!postalcode) {
		alert("You must enter Postal Code.");
		return false;
	} else if (postalcode.length > 6) {
		alert("Postal Code should be maximum 6 digits.");
		return false;
	} else if (!postalcode.match(/^[0-9]+$/)) {
		alert("Postal Code should be numeric.");
		return false;
	} else if (!phone) {
		alert("You must enter phone number.");
		return false;
	} else if (phone.length != 8) {
		alert("Phone number should be 8 digits.");
		return false;
	} else if (!phone.match(/^[2]+[2-6]+[0-9]+$/)) {
		alert("Incorrect phone number.");
		return false;
	} else if (!mobilephone) {
		alert("You must enter mobile phone number.");
		return false;
	} else if (mobilephone.length != 8) {
		alert("Mobile phone number should be 8 digits.");
		return false;
	} else if (!mobilephone.match(/^[9]+[9]+[0-9]+$/)) {
		alert("Incorrect mobile phone number.");
		return false;
	} else if (!email) {
		alert("You must enter email.");
		return false;
	} else if ((email.indexOf('@') == -1) || (email.indexOf('.') == -1)) {
		alert("Wrong email format.");
		return false;
	} else if (!schoolname) {
		alert("You must enter school name.");
		return false;
	} else if (!schoolclass) {
		alert("You must enter school class.");
		return false;
	} else if (schoolclass.length > 6) {
		alert("School Class should be maximum 6 characters.");
		return false;
	} else if (!schoolclass.match(/^[a-zA-Z0-9]+$/)) {
		alert("School Class should be alphanumeric.");
		return false;
	} else if ((fax) && (fax.length != 8)) {
		alert("Fax number should be 8 digits.");
		return false;
	} else if ((fax) && (!fax.match(/^[2]+[2-6]+[0-9]+$/))) {
		alert("Incorrect fax number.");
		return false;
	} else if ((!progrlanguage) || (progrlanguage == '0')) {
		alert("You must select programming language.");
		return false;
	} else {
		return true;
	}
}
function ValidateProfileForm(theForm) {
  var fname = theForm.fname.value;
  var lname = theForm.lname.value;
  var passwd = theForm.password.value;
  var vpasswd = theForm.verifypassword.value;
	var bdate_dd = theForm.birthdate_dd.value;
	var bdate_mm = theForm.birthdate_mm.value;
	var bdate_yy = theForm.birthdate_yy.value;
  var idcardno = theForm.idcardno.value;
  var passportno = theForm.passportno.value;
  var militaryregno = theForm.militaryregno.value;
  var address = theForm.address.value;
  var city = theForm.city.value;
  var postalcode = theForm.postalcode.value;
  var phone = theForm.phone.value;
  var mobilephone = theForm.mobilephone.value;
//  var email = theForm.email.value;
  var schoolname = theForm.schoolname.value;
  var schoolclass = theForm.schoolclass.value;
  var fax = theForm.fax.value;
  var progrlanguage = theForm.progrlanguage.value;

	var bdate = new Date(bdate_yy,(bdate_mm-1),bdate_dd)
	var currdate = new Date()
	
  if (!fname) {
    alert("You must enter first name.");
    return false;
	} else if (!fname.match(/^[a-zA-Z ]+$/)) {
		alert("First name should be alphabetic and in English.");
		return false;
	} else if (!lname) {
		alert("You must enter last name.");
		return false;
	} else if (!lname.match(/^[a-zA-Z ]+$/)) {
		alert("Last name should be alphabetic and in English.");
		return false;
	} else if (!passwd) {
		alert("You must enter password.");
		return false;
	} else if (((passwd.length < 6) || (passwd.length > 8)) && (passwd != ' ')) {
		alert("Password should be 6-8 characters.");
		return false;
	} else if ((!passwd.match(/^[a-zA-Z0-9]+$/)) && (passwd != ' ')) {
		alert("Password should be alphanumeric.");
		return false;
	} else if (passwd != vpasswd) {
		alert("Confirm password does not match.");
		return false;
	} else if ((!bdate_dd) || (!bdate_mm) || (!bdate_yy)) {
		alert("You must enter birth date.");
		return false;
	} else if ((bdate_dd != bdate.getDate()) || (bdate_mm != bdate.getMonth()+1) || (bdate_yy != bdate.getFullYear())) {
		alert("Invalid date.");
		return false;
	} else if (((currdate.getFullYear() - bdate_yy) > 20) || (((currdate.getFullYear() - bdate_yy) == 20) && (bdate_mm < currdate.getMonth()+1))) {
		alert("Your should be 20 years old or younger.");
		return false;
	} else if (!idcardno) {
		alert("You must enter Id Card No.");
		return false;
	} else if (idcardno.length > 8) {
		alert("Id Card No should be maximum 8 digits.");
		return false;
	} else if (!idcardno.match(/^[0-9]+$/)) {
		alert("Id Card No should be numeric.");
		return false;
	} else if (passportno.length > 12) {
		alert("Passport No should be maximum 12 characters.");
		return false;
	} else if ((passportno) && (!passportno.match(/^[a-zA-Z0-9]+$/))) {
		alert("Passport No should be alphanumeric.");
		return false;
	} else if (militaryregno.length > 8) {
		alert("Military Reg No should be maximum 8 digits.");
		return false;
	} else if ((militaryregno) && (!militaryregno.match(/^[0-9]+$/))) {
		alert("Military Reg No should be numeric.");
		return false;
	} else if (!address) {
		alert("You must enter address.");
		return false;
	} else if (!city) {
		alert("You must enter city.");
		return false;
	} else if (postalcode.length > 6) {
		alert("Postal Code should be maximum 6 digits.");
		return false;
	} else if ((postalcode) && (!postalcode.match(/^[0-9]+$/))) {
		alert("Postal Code should be numeric.");
		return false;
	} else if (!phone) {
		alert("You must enter phone number.");
		return false;
	} else if (phone.length != 8) {
		alert("Phone number should be 8 digits.");
		return false;
	} else if (!phone.match(/^[2]+[2-6]+[0-9]+$/)) {
		alert("Incorrect phone number.");
		return false;
	} else if ((mobilephone) && (mobilephone.length != 8)) {
		alert("Mobile phone number should be 8 digits.");
		return false;
	} else if ((mobilephone) && (!mobilephone.match(/^[9]+[9]+[0-9]+$/))) {
		alert("Incorrect mobile phone number.");
		return false;
//	} else if (!email) {
//		alert("You must enter email.");
//		return false;
//	} else if ((email.indexOf('@') == -1) || (email.indexOf('.') == -1)) {
//		alert("Wrong email format.");
//		return false;
	} else if (!schoolname) {
		alert("You must enter school name.");
		return false;
	} else if (!schoolclass) {
		alert("You must enter school class.");
		return false;
	} else if (schoolclass.length > 6) {
		alert("School Class should be maximum 6 characters.");
		return false;
	} else if (!schoolclass.match(/^[a-zA-Z0-9]+$/)) {
		alert("School Class should be alphanumeric.");
		return false;
	} else if ((fax) && (fax.length != 8)) {
		alert("Fax number should be 8 digits.");
		return false;
	} else if ((fax) && (!fax.match(/^[2]+[2-6]+[0-9]+$/))) {
		alert("Incorrect fax number.");
		return false;
	} else if ((!progrlanguage) || (progrlanguage == '0')) {
		alert("You must select programming language.");
		return false;
	} else {
		return true;
	}
}

