function ValidateForm_MrkExs_General(theForm) {
	return true;
}

function ValidateForgotPasswordForm(theForm) {
  var email = theForm.email.value;
	
	if (!email) {
		alert("Please enter your email.");
		return false;
	} else {
		if ((email.indexOf('@') == -1) || (email.indexOf('.') == -1)) {
			alert("Wrong email format.");
			return false;
		} else {
			return true;
		}
	}
}
function ValidateCanLoginForm(theForm) {
  var username = theForm.can_log_username.value;
  var password = theForm.can_log_password.value;
	
	if (!username) {
		alert("Please enter your username.");
		return false;
	} else if (!password) {
			alert("Please enter your password.");
			return false;
	} else {
		return true;
	}
}
function ValidateInsLoginForm(theForm) {
  var username = theForm.ins_log_username.value;
  var password = theForm.ins_log_password.value;
	
	if (!username) {
		alert("Please enter your username.");
		return false;
	} else if (!password) {
			alert("Please enter your password.");
			return false;
	} else {
		return true;
	}
}
function ValidateTstMrkLoginForm(theForm) {
  var username = theForm.tstmrk_log_username.value;
  var password = theForm.tstmrk_log_password.value;
	
	if (!username) {
		alert("Please enter your username.");
		return false;
	} else if (!password) {
			alert("Please enter your password.");
			return false;
	} else {
		return true;
	}
}
function ValidateMrkLoginForm(theForm) {
  var username = theForm.mrk_log_username.value;
  var password = theForm.mrk_log_password.value;
	
	if (!username) {
		alert("Please enter your username.");
		return false;
	} else if (!password) {
			alert("Please enter your password.");
			return false;
	} else {
		return true;
	}
}
function ValidatePinLoginForm(theForm) {
  var username = theForm.pin_log_username.value;
  var password = theForm.pin_log_password.value;
	
	if (!username) {
		alert("Please enter your username.");
		return false;
	} else if (!password) {
			alert("Please enter your password.");
			return false;
	} else {
		return true;
	}
}
function ValidateCenLoginForm(theForm) {
  var username = theForm.cen_log_username.value;
  var password = theForm.cen_log_password.value;
	
	if (!username) {
		alert("Please enter your username.");
		return false;
	} else if (!password) {
			alert("Please enter your password.");
			return false;
	} else {
		return true;
	}
}
function notifyApproveOrReject(theType,theArray,theStatus) {
	w_width = 530;
	w_height = 400;
	if (screen) {
		w_left = (screen.availWidth - w_width)/2;
		w_top = ((screen.availHeight - w_height)/2)-20;
	}
	theWindowParam = 'width='+w_width+',height='+w_height+',left='+w_left+',top='+w_top+',status=no,resizable=no,scrollbars=yes';
	
	fparam = 'notify.php?style=pub&type='+theType+'&list='+theArray+'&status='+theStatus;
  window.notifyApproveOrReject = open(fparam, 'notifyApproveOrReject', theWindowParam);
	setTimeout('if(notifyApproveOrReject&&!notifyApproveOrReject.closed)notifyApproveOrReject.focus()',100);
}
function ModulePrintPage() {
  lochref = '' + this.location;
	if (lochref.indexOf('?') > 0) {
		lochref = '?' + lochref.substring((lochref.indexOf('?')) + 1);
	} else {
		lochref = '';
	}

	w_width = 790;
	w_height = 500;
	if (screen) {
		w_left = (screen.availWidth - w_width)/2;
		w_top = ((screen.availHeight - w_height)/2)-20;
	}
	theWindowParam = 'width='+w_width+',height='+w_height+',left='+w_left+',top='+w_top+',status=no,resizable=no,scrollbars=yes';

	fparam = 'print_mod.php'+lochref;
  window.showPrintWindow = open(fparam, 'showPrintWindow', theWindowParam);
	setTimeout('if(showPrintWindow&&!showPrintWindow.closed)showPrintWindow.focus()',100);
}


function ValidateForm_Can_Filter(theForm) {
  var can_ecdl_id = theForm.can_ecdl_id.value;
  var can_idn = theForm.can_idn.value;
  var can_ssn = theForm.can_ssn.value;
  var can_personal_record = theForm.can_personal_record.value;
  var can_lname = theForm.can_lname.value;
  var exp_id = theForm.exp_id.value;

	if ((!can_ecdl_id)&&(!can_idn)&&(!can_ssn)&&(!can_personal_record)&&(!can_lname)&&(!exp_id)) {
		alert("You must enter at least one filter.");
		return false;
	} else {
		return true;
	}
}

function ValidateForm_Cit_General(theForm) {
	return true;
}

function ValidateForm_Mod_General(theForm) {
	return true;
}

function ValidateForm_Cen_General(theForm) {
  var cen_code = theForm.cen_code.value;
  var cen_name = theForm.cen_name.value;
  var cen_company_name = theForm.cen_company_name.value;
  var cit_id = theForm.cit_id.value;
  var cen_mng_name = theForm.cen_mng_name.value;
  var cen_mng_home_phone = theForm.cen_mng_home_phone.value;
  var cen_mng_work_phone = theForm.cen_mng_work_phone.value;
  var cen_mng_mobile_phone = theForm.cen_mng_mobile_phone.value;
  var cen_mng_email = theForm.cen_mng_email.value;
  var cen_address1 = theForm.cen_address1.value;
  var cen_zip_code = theForm.cen_zip_code.value;
  var cen_adr_cit_id = theForm.cen_adr_cit_id.value;
  var cen_phone1 = theForm.cen_phone1.value;
  var cen_email = theForm.cen_email.value;
  var cen_directions = theForm.cen_directions.value;

  var username = theForm.cen_log_username.value;
  var passwd = theForm.cen_log_password.value;
  var vpasswd = theForm.verifycen_log_password.value;
	
	if ((!cen_code) || (!cen_name) || (!cen_company_name) || (!cit_id) || (!cen_mng_name) || (!cen_mng_home_phone) || (!cen_mng_work_phone) || (!cen_mng_mobile_phone) || (!cen_mng_email) || (!cen_address1) || (!cen_zip_code) || (!cen_adr_cit_id) || (!cen_phone1) || (!cen_email) || (!cen_directions)) {
		alert("You must enter all fields marked with (*).");
		return false;
	} else if ((cen_mng_email.indexOf('@') == -1) || (cen_mng_email.indexOf('.') == -1)) {
		alert("Wrong email format.");
		return false;
	} else if ((cen_email.indexOf('@') == -1) || (cen_email.indexOf('.') == -1)) {
		alert("Wrong email format.");
		return false;
	} else if (!username) {
		alert("You must enter username.");
		return false;
	} else if ((username.length < 4) && (username != ' ')) {
		alert("Username must be more than 4 characters length.");
		return false;
	} else if (!passwd) {
		alert("You must enter password.");
		return false;
	} else if ((passwd.length < 4) && (passwd != ' ')) {
		alert("Password must be more than 4 characters length.");
		return false;
	} else if ((passwd.indexOf(' ') != -1) && (passwd != ' ')) {
		alert("Wrong password format.");
		return false;
	} else if (passwd != vpasswd) {
		alert("Verify password does not match.");
		return false;
	} else {
		return true;
	}
}

function ValidateForm_Lab_General(theForm) {
	return true;
}

function ValidateForm_Exg_General(theForm) {
	return true;
}

function ValidateForm_Ins_General(theForm) {
  var ins_fname = theForm.ins_fname.value;
  var ins_lname = theForm.ins_lname.value;
  var ins_idn = theForm.ins_idn.value;
  var ins_address1 = theForm.ins_address1.value;
  var ins_address2 = theForm.ins_address2.value;
  var ins_adr_cit_id = theForm.ins_adr_cit_id.value;
  var ins_home_phone = theForm.ins_home_phone.value;
  var ins_mobile_phone = theForm.ins_mobile_phone.value;
  var ins_email = theForm.ins_email.value;

  var username = theForm.ins_log_username.value;
  var passwd = theForm.ins_log_password.value;
  var vpasswd = theForm.verifyins_log_password.value;
	
	if ((!ins_fname) || (!ins_lname) || (!ins_idn) || (!ins_address1) || (!ins_address2) || (!ins_adr_cit_id) || (!ins_home_phone) || (!ins_mobile_phone) || (!ins_email)) {
		alert("You must enter all fields marked with (*).");
		return false;
	} else if ((ins_email.indexOf('@') == -1) || (ins_email.indexOf('.') == -1)) {
		alert("Wrong email format.");
		return false;
	} else if (!username) {
		alert("You must enter username.");
		return false;
	} else if ((username.length < 4) && (username != ' ')) {
		alert("Username must be more than 4 characters length.");
		return false;
	} else if (!passwd) {
		alert("You must enter password.");
		return false;
	} else if ((passwd.length < 4) && (passwd != ' ')) {
		alert("Password must be more than 4 characters length.");
		return false;
	} else if ((passwd.indexOf(' ') != -1) && (passwd != ' ')) {
		alert("Wrong password format.");
		return false;
	} else if (passwd != vpasswd) {
		alert("Verify password does not match.");
		return false;
	} else {
		return true;
	}
}
function ValidateForm_TstMrk_General(theForm) {
  var tstmrk_fname = theForm.tstmrk_fname.value;
  var tstmrk_lname = theForm.tstmrk_lname.value;
  var tstmrk_idn = theForm.tstmrk_idn.value;
  var tstmrk_address1 = theForm.tstmrk_address1.value;
  var tstmrk_address2 = theForm.tstmrk_address2.value;
  var tstmrk_adr_cit_id = theForm.tstmrk_adr_cit_id.value;
  var tstmrk_home_phone = theForm.tstmrk_home_phone.value;
  var tstmrk_mobile_phone = theForm.tstmrk_mobile_phone.value;
  var tstmrk_email = theForm.tstmrk_email.value;

  var username = theForm.tstmrk_log_username.value;
  var passwd = theForm.tstmrk_log_password.value;
  var vpasswd = theForm.verifytstmrk_log_password.value;
	
	if ((!tstmrk_fname) || (!tstmrk_lname) || (!tstmrk_idn) || (!tstmrk_address1) || (!tstmrk_address2) || (!tstmrk_adr_cit_id) || (!tstmrk_home_phone) || (!tstmrk_mobile_phone) || (!tstmrk_email)) {
		alert("You must enter all fields marked with (*).");
		return false;
	} else if ((tstmrk_email.indexOf('@') == -1) || (tstmrk_email.indexOf('.') == -1)) {
		alert("Wrong email format.");
		return false;
	} else if (!username) {
		alert("You must enter username.");
		return false;
	} else if ((username.length < 4) && (username != ' ')) {
		alert("Username must be more than 4 characters length.");
		return false;
	} else if (!passwd) {
		alert("You must enter password.");
		return false;
	} else if ((passwd.length < 4) && (passwd != ' ')) {
		alert("Password must be more than 4 characters length.");
		return false;
	} else if ((passwd.indexOf(' ') != -1) && (passwd != ' ')) {
		alert("Wrong password format.");
		return false;
	} else if (passwd != vpasswd) {
		alert("Verify password does not match.");
		return false;
	} else {
		return true;
	}
}

function ValidateForm_Pin_General(theForm) {
  var pin_fname = theForm.pin_fname.value;
  var pin_lname = theForm.pin_lname.value;
  var pin_address1 = theForm.pin_address1.value;
  var pin_email = theForm.pin_email.value;
	
  var username = theForm.pin_log_username.value;
  var passwd = theForm.pin_log_password.value;
  var vpasswd = theForm.verifypin_log_password.value;
	
	if ((!pin_fname) || (!pin_lname) || (!pin_address1) || (!pin_email)) {
		alert("You must enter all fields marked with (*).");
		return false;
	} else if ((pin_email.indexOf('@') == -1) || (pin_email.indexOf('.') == -1)) {
		alert("Wrong email format.");
		return false;
	} else if (!username) {
		alert("You must enter username.");
		return false;
	} else if ((username.length < 4) && (username != ' ')) {
		alert("Username must be more than 4 characters length.");
		return false;
	} else if (!passwd) {
		alert("You must enter password.");
		return false;
	} else if ((passwd.length < 4) && (passwd != ' ')) {
		alert("Password must be more than 4 characters length.");
		return false;
	} else if ((passwd.indexOf(' ') != -1) && (passwd != ' ')) {
		alert("Wrong password format.");
		return false;
	} else if (passwd != vpasswd) {
		alert("Verify password does not match.");
		return false;
	} else {
		return true;
	}
}

function ValidateForm_Exp_General(theForm) {
	return true;
}

function ValidateForm_Trg_General(theForm) {
	return true;
}

function ValidateForm_Exs_General(theForm) {

  var exs_date_dd = theForm.exs_date_dd.value;
  var exs_date_mm = theForm.exs_date_mm.value;
  var exs_date_yy = theForm.exs_date_yy.value;
	
	var exp_start_date_dd = theForm.exp_start_date_dd.value;
	var exp_start_date_mm = theForm.exp_start_date_mm.value;
	var exp_start_date_yy = theForm.exp_start_date_yy.value;
	
	var exp_end_date_dd = theForm.exp_end_date_dd.value;
	var exp_end_date_mm = theForm.exp_end_date_mm.value;
	var exp_end_date_yy =	theForm.exp_end_date_yy.value;
	
  var exs_date = new Date(exs_date_yy,(exs_date_mm-1),exs_date_dd);
	exs_date2=exs_date_dd+exs_date_mm+exs_date_yy;
	
	var exp_start_date = new Date(exp_start_date_yy,(exp_start_date_mm-1),exp_start_date_dd);
	var exp_end_date = new Date(exp_end_date_yy,(exp_end_date_mm-1),exp_end_date_dd);

	if ( ((exs_date_dd != exs_date.getDate()) || (exs_date_mm != exs_date.getMonth()+1) || (exs_date_yy != exs_date.getFullYear())) && (exs_date2 != '') ) {
		alert("Invalid Exam Session Date.");
		return false;
	} else if ((exs_date<exp_start_date)||(exs_date>exp_end_date)) {
		alert("Exam session date is outside exam period");
		return false;
	} else { 
		return true;
	}
}

function ValidateForm_Can_General(theForm) {
  var can_fname = theForm.can_fname.value;
  var can_lname = theForm.can_lname.value;
  var can_idn = theForm.can_idn.value;
  var can_personal_record = theForm.can_personal_record.value;
  var spe_id = theForm.spe_id.value;
  var cit_id = theForm.cit_id.value;
  var exg_id = theForm.exg_id.value;
  var can_address1 = theForm.can_address1.value;
  var can_address2 = theForm.can_address2.value;
  var can_adr_cit_id = theForm.can_adr_cit_id.value;
  var can_home_phone = theForm.can_home_phone.value;
  var can_email = theForm.can_email.value;

  var username = theForm.can_log_username.value;
  var passwd = theForm.can_log_password.value;
  var vpasswd = theForm.verifycan_log_password.value;
	
	if ((!can_fname) || (!can_lname) || (!can_idn) || (!can_personal_record) || (!spe_id) || (!cit_id) || (!exg_id) || (!can_address1) || (!can_address2) || (!can_adr_cit_id) || (!can_home_phone) || (!can_email)) {
		alert("You must enter all fields marked with (*).");
		return false;
	} else if ((can_email.indexOf('@') == -1) || (can_email.indexOf('.') == -1)) {
		alert("Wrong email format.");
		return false;
	} else if (!username) {
		alert("You must enter username.");
		return false;
	} else if ((username.length < 4) && (username != ' ')) {
		alert("Username must be more than 4 characters length.");
		return false;
	} else if (!passwd) {
		alert("You must enter password.");
		return false;
	} else if ((passwd.length < 4) && (passwd != ' ')) {
		alert("Password must be more than 4 characters length.");
		return false;
	} else if ((passwd.indexOf(' ') != -1) && (passwd != ' ')) {
		alert("Wrong password format.");
		return false;
	} else if (passwd != vpasswd) {
		alert("Verify password does not match.");
		return false;
	} else {
		return true;
	}
}

function ValidateForm_Exr_General(theForm) {
	return true;
}

function ValidateForm_CanTransferForm_General(theForm) {
	var can_idn = theForm.can_idn.value;
	
	if (!can_idn) {
		alert("Please enter candidate id card no.");
		return false;
	} else {
		return true;
	}
}

function ValidateForm_CanSearchForm_General(theForm) {
	var can_idn = theForm.ins_idn.value;
	
	if (!can_idn) {
		alert("Please enter candidate id card no.");
		return false;
	} else {
		return true;
	}
}
function ValidateForm_PinCanSearchForm_General(theForm) {
	var can_idn = theForm.can_idn.value;
	
	if (!can_idn) {
		alert("Please enter candidate id card no.");
		return false;
	} else {
		return true;
	}
}
function ValidateForm_CanSelectTrg(theForm){
	var trg=theForm.trg_id.value;
	
	if(!trg){
		alert("You must select one of the listed Training Groups.");
		return false;
	} else {
		return true;
	}
}

function ValidateFormLabelMessage(theForm) {
  var lang = theForm.lbl_lang.value;
  var label = theForm.lbl_label.value;
	
	if (!lang) {
		alert("Language is undefined.");
		return false;
	} else if (!label) {
		alert("You must enter Label.");
		return false;
	} else {
		return true;
	}
}
function OnCheckAll( theForm, theName, theChecked ) {
// used to mark all check boxes in a list as "checked"
    for( var i=0; i<theForm.length; i++ ) {
        var input = theForm[i];
        if( input.nodeName == 'INPUT' )
            if( input.type == 'checkbox' && input.name == theName && ! input.disabled )
                if( input.checked != theChecked )
                    input.checked = theChecked;
    }
}
function ChangeGroupActionAndSubmit( theForm, theValue ) {
	theForm.MM_GroupAction.value=theValue;
	theForm.submit();
}

function ValidateConfirmForm(theForm) {
  var confirmcheckbox = theForm.confirmcheckbox.value;
	
	if (confirmcheckbox != 'Y') {
		alert("You must confirm the action first by clicking on the checkbox above.");
		return false;
	} else {
		return true;
	}
}
function changeConfirmCheckbox(theValue) {
	if (theValue == 'Y') {
		document.ConfirmForm.confirmcheckbox.value = 'N';
	} else {
		document.ConfirmForm.confirmcheckbox.value = 'Y';
	}
}
function changeFieldValue(theField,theValue){
	theValue = String (theValue);

	document.getElementById(theField).value = theValue;
}
function CheckResult(theField){
	var	theValue = document.getElementById(theField).value;
	if (!theValue.match(/^[0-9]+$/)) {
		document.getElementById(theField).value = 0;
		alert("Result should be numeric.");
	} else if ((theValue > 100)||(theValue < 0)) {
		document.getElementById(theField).value = 0;
		alert("Result can take values from 0 - 100");
	}
}

function CheckCanNumberVerification(theCanNumber, theCanVerNumber) {
		var	theCanNum = document.getElementById(theCanNumber).value;
		var theCanVerNum = document.getElementById(theCanVerNumber).value;
		if ((theCanVerNum != '')&&(theCanNum == '')) {
			alert("Enter the Candidate number first");
			document.getElementById(theCanVerNumber).value = "";
		} else {
			if (theCanNum != theCanVerNum) {
				alert("Candidate Number "+theCanNum+" does mot match with the Verify Candidate Number");
				document.getElementById(theCanVerNumber).value = "";
			}
		}
}

function CheckCandidatesNumbers(totalResults) {
	for (var i=1; i<=totalResults; i++) {
		var	theCanNum = document.getElementById("can_ecdl_no_"+i).value;
		var theCanVerNum = document.getElementById("can_verify_ecdl_no_"+i).value;
		if (theCanNum != theCanVerNum) {
			alert("Candidate Number "+theCanNum+" does mot match with the Verify Candidate Number");
			return false;
			break;
		}
	}
}
