// JavaScript Document

function validate_registration () {
	//
	var slTitle        = trim(document.frmRegistration.slTitle.value);
	var txFirstName    = trim(document.frmRegistration.txFirstName.value);
	//var txMiddleName   = trim(document.frmRegistration.txMiddleName.value);
	var txLastName     = trim(document.frmRegistration.txLastName.value);
	var txPrimaryPhone = trim(document.frmRegistration.txPrimaryPhone.value);
	var txEmailAddress = trim(document.frmRegistration.txEmailAddress.value);
	var slCountry      = trim(document.frmRegistration.slCountry.value);
	var psPassword1    = trim(document.frmRegistration.psPassword1.value);
	var psPassword2    = trim(document.frmRegistration.psPassword2.value);
	var hdExec         = trim(document.frmRegistration.hdExec.value);
	
	var isEmailValid   = validateEmail(txEmailAddress);
	
	var errorMsg = "One or more of the following required fields are missing:";
	
	if (slTitle == "0")       errorMsg += "\r\n* Title";
	if (txFirstName == "")    errorMsg += "\r\n* First name";
	//if (txMiddleName == "")   errorMsg += "\r\n* Middle name";
	if (txLastName == "")     errorMsg += "\r\n* Last name";
	if (txPrimaryPhone == "") errorMsg += "\r\n* Primary phone No.";
	if (txEmailAddress == "") errorMsg += "\r\n* Email address";
	// call function to validate email address
	if (txEmailAddress != "" && isEmailValid == 0)    errorMsg += "\r\n* Please enter valid email address";
	if (slCountry == "0")     errorMsg += "\r\n* Country";
	if (psPassword1 == "")    errorMsg += "\r\n* Password";
	if (psPassword2 == "")    errorMsg += "\r\n* Re-enter password";

	// If required fields are entered, and not executive job-seeker
	if (hdExec != "yes") {
		if (errorMsg == "One or more of the following required fields are missing:") {
			if ((psPassword1 == psPassword2) && (psPassword1.length >= 6)) {
				//if (confirm("Do you want to submit information?"))			
					return true;
				//else 
					//return false;
			}
			else {
				//
				if (psPassword1 != psPassword2) 
					alert ("Sorry but your password fields do not match.");
				else 
					alert ("Sorry but your password should contain at least 6 characters.");
				return false;
			}
		}
		else {
			// 
			alert (errorMsg);
			return false;
		}
	}
}// validate_registration 
