/*****************************************************************************************
	Script	:	admin.js
	Date	:	01/08/2005
	Author	:	koh
	Usage	:	javascript basic function
*****************************************************************************************/
var IsNS4 = (navigator.appName.indexOf('Netscape') != -1)?1:0;
var IsIE = (navigator.appName.indexOf('Microsoft Internet Explorer') != -1)?1:0;

function changeCursor(the_obj) {
	the_obj.style.cursor = (IsIE)?'hand':'pointer';		
}
 
function toUpper(field) {
	field.value = field.value.toUpperCase().replace(/[^A-Z]/g, '');
}

function toNumeric(field) {
	field.value = field.value.replace(/[^0-9]/g, '');
}

function toDouble(field) {
	field.value = field.value.replace(/[^0-9.]/g, '');
}

function setDefaultText(the_obj, text) {
	if(the_obj.value.length == 0) {
		the_obj.value = text;
	}
}

function fadeDefaultText(the_obj, text) {
	if(the_obj.value == text) {
		the_obj.value = '';
	}
}

function chechIntEntry(e){
	if(!IsNS4 && (event.keyCode < 48 || event.keyCode > 57)) {
		event.keyCode = 0;
	}else if (IsNS4 && (e.which < 48 || e.which > 57)) {
		e.returnValue = false;
	}
}

function checkRegisterField(){
	var control;
	var proceed = true;
	var selectPackkage = false;
	with(document.frmForm){
		s1 = new String(txtPassword.value);
		s2 = new String(txtPassword2.value);
		alpha = new Array();
		numeric = new Array();
		alphanumeric = new Array();

		for(var icount = 0; icount < 2; icount++)
			alpha[icount] = new RegExp(/\d/g);

		for(var jcount = 0; jcount < 6; jcount++)
			numeric[jcount] = new RegExp(/^\d+$/g);

		for(var kcount = 0; kcount < 0; kcount++)
			alphanumeric[kcount] = new RegExp(/[a-zA-Z0-9]+/g);

selectPackkage = true;

/*

for(i=0; i<elements.length; i++) {
			if(elements[i].type=='checkbox' && elements[i].name.indexOf('chkPackage[')!=-1 && elements[i].checked){
				selectPackkage = true;
				break;
			}
		}
		
*/
		

		if(txtLoginid.value==''){ proceed = false; control = 1; }
		else if(txtPassword.value=='' || s1.length < 6){ proceed = false; control = 2; }
		else if(txtPassword2.value=='' || s2.length < 6){ proceed = false; control = 3; }
		else if(txtPassword.value!=txtPassword2.value){ proceed = false; control = 12; }
		else if(txtFullname.value=='' || alpha[0].test(txtFullname.value)){ proceed = false; control = 4; }
		else if(txtInitial.value.length!=2 || alpha[1].test(txtInitial.value)){ proceed = false; control = 17; }
		else if(selIdentitytype.value==''){ proceed = false; control = 5; }
		else if(txtDesignation.value==''){ proceed = false; control = 100; }
		else if(txtCompanyname.value==''){ proceed = false; control = 7; }
		else if(txtRegNo.value==''){ proceed = false; control = 15; }
		else if(txtEmail.value==''){ proceed = false; control = 8; }
		else if(validateForm(txtEmail) == false){ return false; }
		else if(!numeric[0].test(txtTel1.value)){ proceed = false; control = 9; }
		else if(!numeric[1].test(txtTel2.value)){ proceed = false; control = 10; }
		else if(!numeric[2].test(txtTel3.value)){ proceed = false; control = 11; }
		else if(txtAdd.value==''){ proceed = false; control = 16; }
		else if(txtPostcode.value==''){ proceed = false; control = 18; }
		else if(txtCity.value==''){ proceed = false; control = 19; }
		else if(chkOtherState.checked && txtState.value==''){
			proceed = false; 
			control = 20;
		}
		else if(!chkOtherState.checked && selState.value=='') {
			proceed = false; 
			control = 20;
		}
		else if(selCountry.value==''){ proceed = false; control = 21; }
		//else if(selectPackkage == false){ proceed = false; control = 22; }
		else if(selIdentitytype.value=='0'){
			if(!numeric[3].test(txtIdentity1.value) || !numeric[4].test(txtIdentity2.value) || !numeric[5].test(txtIdentity3.value)){
				proceed = false; 
				control = 6;
			}else{
				proceed = validateDOB(txtIdentity1.value);
				control = (!proceed) ? 14 : '';
			}
		}
		else if(selIdentitytype.value=='1' || selIdentitytype.value=='2'){
			if(!alphanumeric[0].test(txtIdentity.value)){
				proceed = false; 
				control = 6; 
			}
		}

		if(!proceed){
			switch(control){
			case 1:
				alert('Please enter Login ID');
				txtLoginid.focus();
				break;
			case 2:
				alert('Password must be at least 6 characters. Please enter again.');
				txtPassword.focus();
				break;
			case 3:
				alert('Please enter Confirmed Password');
				txtPassword2.focus();
				break;
			case 4:
				alert('Please enter a valid Full Name');
				txtFullname.focus();
				break;
			case 5:
				alert('Please select Identification');
				selIdentitytype.focus();
				break;
			case 6:
				alert('Please enter Identity No.');
				txtIdentity.focus();
				break;
			case 100:
				alert('Please enter Designation.');
				txtDesignation.focus();
				break;
			case 7:
				alert('Please enter Company Name');
				txtCompanyname.focus();
				break;
			case 15:
				alert('Plese enter Business Registration No.');
				txtRegNo.focus();
				break;
			case 8:
				alert('Please enter Email');
				txtEmail.focus();
				break;
			case 9:
				alert('Please enter Telephone No.');
				txtTel1.focus();
				break;
			case 10:
				alert('Please enter Telephone No.');
				txtTel2.focus();
				break;
			case 11:
				alert('Please enter Telephone No.');
				txtTel3.focus();
				break;
			case 12:
				alert('Password and Confirmed Password are not match');
				txtPassword.focus();
				break;
			case 14:
				alert('Invalid New IC No.');
				txtIdentity1.value='';
				txtIdentity2.value='';
				txtIdentity3.value='';
				txtIdentity1.select();
				break;
			case 16:
				alert('Please enter Correspondence Address');
				txtAdd.focus();
				break;
			case 17:
				alert('Initial must be of 2 alphabet characters');
				txtInitial.focus();
				break;
			case 18:
				alert('Please enter a Postcode');
				txtPostcode.focus();
				break;
			case 19:
				alert('Please enter a City');
				txtCity.focus();
				break;
			case 20:
				alert('Please enter a State');
				break;
			case 21:
				alert('Please select a Country');
				selCountry.focus();
				break;
			case 22:
				alert('Please choose the package that you are interested in');
				break;
		
			}
			
			



			return false;
		}else {
			return true;
		}
	}
}

function setCheckboxes(the_form, do_check, element_name)
{

	var elts      = document.forms[the_form].elements[element_name];
	var elts_cnt  = (typeof(elts.length) != 'undefined')
				  ? elts.length
				  : 0;

	if (elts_cnt) {
		for (var i = 0; i < elts_cnt; i++) {
			elts[i].checked = do_check;
		} // end for
	} else {
		elts.checked        = do_check;
	} // end if... else

} // end of the 'setCheckboxes()' function

function disableSpecifyMCert(the_obj){
	if(the_obj.options[the_obj.selectedIndex].value=="999"){
		document.frmForm.txtjob_m_cert.readOnly = false;
		document.frmForm.txtjob_m_cert.focus();
	}else{
		document.frmForm.txtjob_m_cert.readOnly = true;
	}
	return true;
}

function disableSpecifyOCert(the_obj){
	if(the_obj.options[the_obj.selectedIndex].value=="999"){
		document.frmForm.txtjob_o_cert.readOnly = false;
		document.frmForm.txtjob_o_cert.focus();
	}else{
		document.frmForm.txtjob_o_cert.readOnly = true;
	}
	return true;
}

function previewForm(frm, source){
	if(validPostJobField(frm)) {
		e = window.open('preview-ads.php?s='+source, 'popwin', 'height=500px,width=500px,left=30px,top=30px,status=no,location=no,menubar=no,scrollbars=yes,resizable=0,toolbar=no');
		if(IsIE) e.focus();
	}
	return false;
}

function postForm(frm){
	if(validPostJobField(frm)) {
		frm.btnSave.value = 'save';
		frm.submit();
	}
	return 0;
}

function validPostJobField(frm){
	var job_employment_type_checked = 0;
	var job_qualification_checked = 0;
	var job_work_country_checked = 0;
	var job_work_location_checked = 0;
	var job_field_of_study_checked = 0;

	for (i=0; i<frm.elements.length; i++) {
		if(frm.elements[i].name=="chkjob_employment_type[]"){
			if (frm.elements[i].checked){
				job_employment_type_checked = 1;
			}
		}
		if(frm.elements[i].name == "chkjob_qualification[]"){
			if (frm.elements[i].checked){
				job_qualification_checked = 1;
			}
		}
		if(frm.elements[i].name=="radjob_work_country"){
			if(frm.elements[i].checked){
				job_work_country_checked = 1;
			}
		}
	}

	if (frm.txtjob_company_name.value.length == 0)
	{
		alert("Please enter the Company Name");
		frm.txtjob_company_name.focus();
		return (false);
	}
	if (frm.txtjob_position_title.value.length == 0)
	{
		alert("Please enter the Job Title");
		frm.txtjob_position_title.focus();
		return (false);
	}
	if (frm.seljob_position_level.value.length == 0)
	{
		alert("Please select the Job Level");
		frm.seljob_position_level.focus();
		return (false);
	}
	
	if (frm.seljob_specialization.value.length == 0)
	{
		alert("Please select the Job Specialization");
		frm.seljob_specialization.focus();
		return (false);
	}
	
	if (job_employment_type_checked == 0)
	{
		alert("Please select Employment Type");
		return (false);
	}

	if (frm.txtjob_years_of_exp.value.length == 0)
	{
		alert("Please enter the Years of Experience");
		frm.txtjob_years_of_exp.focus();
		return (false);
	}

	if (frm.txtjob_min_month_salary.value.length == 0)
	{
		alert("Please enter the Monthly Minimum Salary");
		frm.txtjob_min_month_salary.focus();
		return (false);
	}

	if (frm.txtjob_max_month_salary.value != "" && parseInt(frm.txtjob_min_month_salary.value) > parseInt(frm.txtjob_max_month_salary.value)){
		alert("The Monthly Minimum Salary is more than Monthly Maximum Salary");
		frm.txtjob_min_month_salary.focus();
		return (false);
	} 
	
	if (frm.seljob_salary_currency.value.length == 0)
	{
		alert("Please select a Salary Currency");
		frm.seljob_salary_currency.focus();
		return (false);
	}

	if (job_work_country_checked == 0)
	{
		alert("Please state the base of the job to within or outside Malaysia");
		frm.radjob_work_country[0].focus();
		return (false);
	}
	else
	{
		if (frm.radjob_work_country[0].checked == true) {
			if (document.getElementById('work_location_state').selectedIndex == -1) {
				alert("Please select the state where the position is based");
				document.getElementById('work_location_state').focus();
				return (false);
			}
		}
		else {
			if (document.getElementById('work_location_country').selectedIndex <= 0) {
				alert("Please select the country where the position is based");
				frm.seljob_work_location.focus();
				return (false);
			}
		}
	}
	

	/* Set value for txtjob_work_location_specify - 2006/01/04 */
	var lenLocation = document.getElementById('sellocation_specify').length;
	var e = document.getElementById('sellocation_specify');
	/* Initialize */
	frm.txtjob_work_location_specify.value = '';
	for(j=0; j< lenLocation; j++) {
		frm.txtjob_work_location_specify.value += e.options[j].value + ',';
	}
	frm.txtjob_work_location_specify.value = frm.txtjob_work_location_specify.value.replace(/[,]$/, '');

	if (frm.txtjob_work_location_specify.value.length == 0){
		alert("Please specify work location");
		frm.txtlocation_specify.focus();
		return (false);
	}

	if (job_qualification_checked == 0)
	{
		alert("Please select required Education Levels");
		return (false);
	}

	if (document.getElementById('seljob_field_of_study').selectedIndex == -1)
	{
		alert("Please select at least one Field of Study");
		document.getElementById('seljob_field_of_study').focus();
		return (false);
	}

	if (frm.txtjob_summary_responsibilities.value == "")
	{
		alert("Please enter Job Responsibilities");
		frm.txtjob_summary_responsibilities.focus();
		return (false);
	}

	return true;
}

/* Prompt upon modify job citeria (for dropdown list) */
function alertUpdate(the_obj) {
	var objName = the_obj.name.substr(3);
	objName = 'hid'+objName;
	if(eval("document.frmForm."+objName+".value != the_obj.options[the_obj.selectedIndex].value")) {
		alert('Please proceed to change the requirement accordingly.');
	}
	return true;
}

/* Prompt upon modify job citeria (for textbox) */
function alertUpdate2(the_obj) {
	var objName = the_obj.name.substr(3);
	objName = 'hid'+objName;
	if(eval("document.frmForm."+objName+".value != the_obj.value")) {
		alert('Please proceed to change the requirement accordingly.');
	}
	return true;
}

/* Prompt upon modify job citeria (for checkbox) */
function alertUpdate3() {
	alert('Please proceed to change the requirement accordingly.');
	return true;
}

function checkRecoverPasswordField() {
	//alert(document.frmForm.selIdentityType.options[document.frmForm.selIdentityType.selectedIndex.value].value);
	var control;
	var proceed = true;

	with(document.frmForm) {
		if(txtFullName.value==''){ proceed = false; control = 1; }
		else if(selIdentityType.selectedIndex==0){ proceed = false; control = 2; }
		else if(txtEmail.value==''){ proceed = false; control = 4; }
		else if(selIdentityType.value=='0'){
			if(txtIdentity1.value=='' || txtIdentity2.value=='' || txtIdentity3.value==''){
				proceed = false; 
				control = 3;
			}else{
				proceed = validateDOB(txtIdentity1.value);
				control = (!proceed) ? 5 : '';
			}
		}
		else if(selIdentitytype.value=='1' || selIdentitytype.value=='2'){
			if(txtIdentity.value==''){
				proceed = false; 
				control = 3; 
			}
		}

		if(!proceed){
			switch(control){
			case 1:
				alert('Invalid Fullname');
				txtFullName.focus();
				break;
			case 2:
				alert('Invalid Identity Type');
				selIdentityType.focus();
				break;
			case 3:
				alert('Invalid Identity No.');
				txtIdentity.focus();
				break;
			case 4:
				alert('Invalid Email');
				txtEmail.focus();
				break;
			case 5:
				alert('Invalid New IC No.');
				txtIdentity1.value='';
				txtIdentity2.value='';
				txtIdentity3.value='';
				txtIdentity1.focus();
				break;
			}
			return false;
		}
	}
	return true;
}

function selectCheckbox(thisForm, childCheckbox) {
	var len = document.forms[thisForm.name].elements.length;
	for(i=0; i<len; i++) {
		var elts = document.forms[thisForm.name].elements[i]
		if(elts.type == 'checkbox' && elts.name.indexOf(childCheckbox) != -1 && elts.checked == 1){
			thisForm.submit();
			return true;
		}
	}
	alert('Please select at least one candidate.');
	document.forms[thisForm.name].selAppStatus.selectedIndex = 0;
	return false;
}

function selectCheckbox2(thisForm, childCheckbox) {
	var len = document.forms[thisForm.name].elements.length;
	for(i=0; i<len; i++) {
		var elts = document.forms[thisForm.name].elements[i]
		if(elts.type == 'checkbox' && elts.name.indexOf(childCheckbox) != -1 && elts.checked == 1){
			return true;
		}
	}
	alert('Please select at least one candidate.');
	return false;
}

function seekData(formName, vSelect) {
	var obj = document.forms[formName];
	obj.action.value = 'seek';
	obj.submit();
}

function checkRequest(thisForm) {
	var obj = document.forms[thisForm.name];
	if(obj.selJobList.value.length == 0) {
		alert('Please select a job!');
		obj.selJobList.focus();
		return false;
	}else {
		obj.action.value = 'save';
		obj.submit();
		return true;
	}
}

function checkBlacklist(thisForm, fieldName) {
	var elts = document.forms[thisForm.name].elements;
	var len = document.forms[thisForm.name].elements.length;
	
	for(i=0; i<len; i++) {
		if(elts[i].type == 'textarea' && elts[i].name.indexOf(fieldName) != -1 && elts[i].value.length < 1) {
			alert('Please state your reason for blacklisting the following candidate(s).');
			return false;
		}
	}
	return true;
}

function checkInterviewField(thisForm) {
	if(selectCheckbox2(thisForm, 'chkapplication[') == false) {
		return false;
	}

	var elts = document.forms[thisForm.name].elements;
	var len = elts.length;
	var description = new String();

	for(i=0; i<len; i++) {
			if(elts[i].type == 'text' && elts[i].name.indexOf('txtAppIntDateTime[') != -1 && elts[i].value.length < 1) {
				alert('Please enter interview date and time.');
				return false;
			}
			else if(elts[i].type == 'text' && elts[i].name.indexOf('txtAppIntDateTime[') != -1 && elts[i].value.length > 0) {
				var strDateTime = new String(elts[i].alt);
				var strInterviewDateSet = elts[i].value.substr(0, 10);
				var regMatch = new RegExp(strInterviewDateSet);
				result = strDateTime.substr(0, 10).match(regMatch);

				// isInterviewRequest is global variable
				if(result != null && isInterviewRequest && result.length > 0) {

					var intAppIdx = elts[i].name.toString().substr(18,(elts[i].name.length-1)-18);
					for(k=0; k<len; k++) {
						if(elts[k].type == 'hidden' && elts[k].name.indexOf('txtUserFullName['+intAppIdx+']') != -1) {
							description += elts[k].value+' has an interview on '+strDateTime+' for other position.\n';
						}// endif
					}// end for
				}// end if
			}

			if(elts[i].type == 'text' && elts[i].name.indexOf('txtIntTel[') != -1 && elts[i].value.length < 1) {
				alert('Please enter interviewer phone no.');
				return false;
			}

			if(elts[i].type == 'text' && elts[i].name.indexOf('txtIntVenue[') != -1 && elts[i].value.length < 1) {
				alert('Please enter interview venue.');
				return false;
			}
	}

	if(description.length) {
		description += '\nAre you sure want to proceed?';
		if(confirm(description)) {
			return true;
		}else {
			return false;
		}
	}
}

function setInterviewFlag(val) {
	if(val == '1' || val == '2') {
		isInterviewRequest = true;
	}else {
		isInterviewRequest = false;
	}
}

function delBlacklist(frmName, uid) {
	if(confirm('Are you sure want to remove the blacklisted user?')) {
		document.forms[frmName].usrid.value = uid;
		document.forms[frmName].action.value = 'delete';
		document.forms[frmName].submit();
	}else {
		return false;
	}
}

function checkLoginField() {
	var control;
	var proceed = true;

	with(document.frmForm) {
		if(txtLogin.value == '') {
			proceed = false;
			control = 1;
		}else if(txtPassword.value == '') {
			proceed = false;
			control = 2;
		}

		if(!proceed) {
			switch(control) {
			case 1:
				alert('Please enter Login ID.');
				txtLogin.focus();
				break;
			case 2:
				alert('Please enter Password.');
				txtPassword.focus();
				break;
			default:
				break;
			}

			return false;
		}
	}
	return true;
}

function checkProfileField() {
	var control;
	var proceed = true;

	with(document.frmForm) {
		if(chkSimilarAddress.checked == false) {
			if(txtAdd2.value == '') { proceed = false; control = 11; }
			else if(txtPostcode2.value == '') { proceed = false; control = 12; }
			else if(txtCity2.value == '') { proceed = false; control = 13; }
			else if(selState2.value == '') { proceed = false; control = 14; }
			else if(selCountry2.value == '') { proceed = false; control = 15; }
		}


		if(txtCompanyName.value == '') { proceed = false; control = 1; }
		else if(txtRegNo.value == '') { proceed = false; control = 2; }
		else if(txtTel_1_Country.value == '') { proceed = false; control = 3; }
		else if(txtTel_1_Area.value == '') { proceed = false; control = 4; }
		else if(txtTel_1_No.value == '') { proceed = false; control = 5; }
		else if(txtAdd1.value == '') { proceed = false; control = 6; }
		else if(txtPostcode1.value == '') { proceed = false; control = 7; }
		else if(txtCity1.value == '') { proceed = false; control = 8; }
		else if(selCountry1.value == '') { proceed = false; control = 10; }
		else if(chkOtherState.checked == false && selState1.value == '') { proceed = false; control = 9; }
		else if(chkOtherState.checked == true && txtState1.value == '') { proceed = false; control = 16; }

		if(!proceed) {
			switch(control) {
			case 1:
				alert('Please enter Company Name');
				txtCompanyName.focus();
				break;
			case 2:
				alert('Please enter Business Registration No.');
				txtRegNo.focus();
				break;
			case 3:
				alert('Please enter Telephone No(O)');
				txtTel_1_Country.focus();
				break;
			case 4:
				alert('Please enter Telephone No(O)');
				txtTel_1_Area.focus();
				break;
			case 5:
				alert('Please enter Telephone No(O)');
				txtTel_1_No.focus();
				break;
			case 6:
				alert('Please enter Correspondence Address');
				txtAdd1.focus();
				break;
			case 7:
				alert('Please enter Postcode');
				txtPostcode1.focus();
				break;
			case 8:
				alert('Please enter City');
				txtCity1.focus();
				break;
			case 9:
				alert('Please select a State');
				selState1.focus();
				break;
			case 10:
				alert('Please select a Country');
				selCountry1.focus();
				break;
			case 11:
				alert('Please enter Correspondence Address');
				txtAdd2.focus();
				break;
			case 12:
				alert('Please enter Postcode');
				txtPostcode2.focus();
				break;
			case 13:
				alert('Please enter City');
				txtCity2.focus();
				break;
			case 14:
				alert('Please select a State');
				selState2.focus();
				break;
			case 15:
				alert('Please select a Country');
				selCountry2.focus();
				break;
			case 16:
				alert('Please enter a State');
				txtState1.focus();
				break;

			}

			return false;
		}else{
			return true;
		}
	}
}

function checkAddUserField() {
	var control;
	var proceed = true;

	with(document.frmForm) {
		if(txtLoginid.value=='') { proceed = false; control = 1; }
		else if(txtPassword.value=='' || txtPassword.value.length < 6){ proceed = false; control = 2; }
		else if(txtPassword2.value=='' || txtPassword2.value.length <6){ proceed = false; control = 3; }
		else if(txtPassword.value!=txtPassword2.value){ proceed = false; control = 4; }
		else if(txtFullname.value==''){ proceed = false; control = 5; }
		else if(txtInitial.value==''){ proceed = false; control = 6; }
		else if(selIdentitytype.value==''){ proceed = false; control = 7; }
		else if(txtTelephone.value==''){ proceed = false; control = 11; }
		else if(validateForm(txtEmail) == false){ return false; }
		else if(uniqid.value=='no'){ proceed = false; control = 12; }
		else if(selIdentitytype.value=='0'){
			if(txtIdentity1.value=='' || txtIdentity2.value=='' || txtIdentity3.value==''){
				proceed = false; 
				control = 8;
			}else{
				proceed = validateDOB(txtIdentity1.value);
				control = (!proceed) ? 9 : '';
			}
		}
		else if(selIdentitytype.value=='1' || selIdentitytype.value=='2'){
			if(txtIdentity.value==''){
				proceed = false; 
				control = 10; 
			}
		}

		if(!proceed) {
			switch(control) {
			case 1:
				alert('Please enter Login ID');
				txtLoginid.focus();
				break;
			case 2:
				alert('Please enter Password with at least 6 characters');
				txtPassword.focus();
				break;
			case 3:
				alert('Please enter Confirmed Password at least 6 characters');
				txtPassword2.focus();
				break;
			case 4:
				alert('Password and Confirmed Password are not match');
				txtPassword.focus();
				break;
			case 5:
				alert('Please enter Full Name');
				txtFullname.focus();
				break;
			case 6:
				alert('Please enter Initial');
				txtInitial.focus();
				break;
			case 7:
				alert('Please select Identification');
				selIdentitytype.focus();
				break;
			case 8:
				alert('Please enter Identity No.');
				txtIdentity1.focus();
				break;
			case 9:
				alert('Invalid New IC No.');
				txtIdentity1.value='';
				txtIdentity2.value='';
				txtIdentity3.value='';
				txtIdentity1.focus();
				break;
			case 10:
				alert('Please enter Identity No.');
				txtIdentity.focus();
				break;
			case 11:
				alert('Please enter Contact No.');
				txtTelephone.focus();
				break;
			case 12:
				alert('Login ID has been taken. Please enter other ID');
				txtLoginid.focus();
				break;
			}

			return false;
		}else {
			return true;
		}
	}
}

function checkEditUserField() {
	var control;
	var proceed = true;

	with(document.frmForm) {
		if(txtFullname.value==''){ proceed = false; control = 1; }
		else if(txtInitial.value==''){ proceed = false; control = 2; }
		else if(selIdentitytype.value==''){ proceed = false; control = 3; }
		else if(txtTelephone.value==''){ proceed = false; control = 4; }
		else if(validateForm(txtEmail) == false){ return false; }
		else if(selIdentitytype.value=='0'){
			if(txtIdentity1.value=='' || txtIdentity2.value=='' || txtIdentity3.value==''){
				proceed = false; 
				control = 5;
			}else{
				proceed = validateDOB(txtIdentity1.value);
				control = (!proceed) ? 6 : '';
			}
		}
		else if(selIdentitytype.value=='1' || selIdentitytype.value=='2'){
			if(txtIdentity.value==''){
				proceed = false; 
				control = 7; 
			}
		}

		if(!proceed) {
			switch(control) {
			case 1:
				alert('Please enter Full Name');
				txtFullname.focus();
				break;
			case 2:
				alert('Please enter Initial');
				txtInitial.focus();
				break;
			case 3:
				alert('Please select Identification');
				selIdentitytype.focus();
				break;
			case 4:
				alert('Please enter Contact No.');
				txtTelephone.focus();
				break;
			case 5:
				alert('Please enter Identity No.');
				txtIdentity1.focus();
				break;
			case 6:
				alert('Invalid New IC No.');
				txtIdentity1.value='';
				txtIdentity2.value='';
				txtIdentity3.value='';
				txtIdentity1.focus();
				break;
			case 7:
				alert('Please enter Identity No.');
				txtIdentity.focus();
				break;
			}

			return false;
		}else {
			return true;
		}
	}

}

function checkAddUniField(thisForm) {
	var control;
	var proceed = true;
	var obj = document.forms[thisForm.name];

	if(thisForm.name == 'frmForm') {
		if(obj.txtUniName.value.length == 0) { proceed = false; control = 1; }
		else if(obj.txtAdd1.value.length == 0){ proceed = false; control = 2; }
		else if (obj.txtPostcode.value.length == 0){ proceed = false; control = 3; }
		else if (obj.txtCity.value.length == 0){ proceed = false; control = 4; }
		else if (obj.selState.value.length == 0){ proceed = false; control = 5; }
		else if (obj.selCountry.value.length == 0){ proceed = false; control = 6; }

		if(!proceed) {
			switch(control) {
			case 1:
				alert('Please enter University Name');
				obj.txtUniName.select();
				break;
			case 2:
				alert('Please enter Correspondence Address');
				obj.txtAdd1.select();
				break;
			case 3:
				alert('Please enter Postcode');
				obj.txtPostcode.select();
				break;
			case 4:
				alert('Please enter City');
				obj.txtCity.select();
				break;
			case 5:
				alert('Please select State');
				obj.selState.focus();
				break;
			case 6:
				alert('Please select Country');
				obj.selCountry.focus();
				break;
			}
			return false;

		}else {
			return true;
		}

	}else if(thisForm.name == 'frmForm2') {
		if(obj.selUni.value.length == 0) { proceed = false; control = 1; }
		else if(obj.txtFaculty.value.length == 0){ proceed = false; control = 2; }

		if(!proceed) {
			switch(control) {
			case 1:
				alert('Please select University');
				obj.selUni.focus();
				break;
			case 2:
				alert('Please enter Faculty Name');
				obj.txtFaculty.select();
				break;
			}
			return false;

		}else {
			return true;
		}

	}
}

function checkAddUadminField() {
	var control;
	var proceed = true;

	with(document.frmForm) {
		if(selUniversity.value.length == 0) { proceed = false; control = 1; }
		else if(selFaculty.value.length == 0) { proceed = false; control = 2; }
		else if(txtLoginid.value.length == 0 || uniqid.value.toLowerCase() == 'no') { proceed = false; control = 3; }
		else if(validateForm(txtLoginid) == false) { return false; }
		else if(txtPassword.value.length < 6) { proceed = false; control = 4; }
		else if(txtPassword2.value.length < 6) { proceed = false; control = 5; }
		else if(txtPassword.value != txtPassword2.value) { proceed = false; control = 6; }
		else if(txtFullname.value.length == 0) { proceed = false; control = 7; }
		else if(validateForm(txtEmail) == false) { return false; }
		else if(txtPhoneCode.value.length == 0 || txtPhoneNo.value.length == 0) { proceed = false; control = 8; }

		if(!proceed) {
			switch(control) {
			case 1: 
				alert('Please select a University');
				selUniversity.focus();
				break;
			case 2:
				alert('Please select a Faculty');
				selFaculty.focus();
				break;
			case 3:
				alert('Please enter a valid Login ID');
				txtLoginid.select();
				break;
			case 4:
				alert('Password must be at least 6 characters');
				txtPassword.select();
				break;
			case 5:
				alert('Confirmed Password must be at least 6 characters');
				txtPassword2.select();
				break;
			case 6:
				alert('Password and Confirmed Password are not matched. Please Enter Again.');
				txtPassword.select();
				break;
			case 7:
				alert('Please enter a valid Full Name');
				txtFullname.select();
				break;
			case 8:
				alert('Please enter a valid Contact No.');
				txtPhoneCode.value = '';
				txtPhoneNo.value = '';
				txtPhoneCode.select();
				break;
			}

			return false;
		}else {
			return true
		}
	}
}

function checkEditUadminField() {
	var control;
	var proceed = true;

	with(document.frmForm) {
		if(txtPassword.value != '' && txtPassword.value.length < 6) { proceed = false; control = 1; }
		else if(txtFullname.value.length == 0) { proceed = false; control = 2; }
		else if(validateForm(txtEmail) == false) { return false; }
		else if(txtPhoneCode.value.length == 0 || txtPhoneNo.value.length == 0) { proceed = false; control = 3; }

		if(!proceed) {
			switch(control) {
			case 1:
				alert('Password must be at least 6 characters');
				txtPassword.select();
				break;
			case 2:
				alert('Please enter a valid Full Name');
				txtFullname.select();
				break;
			case 3:
				alert('Please enter a valid Contact No.');
				txtPhoneCode.value = '';
				txtPhoneNo.value = '';
				txtPhoneCode.select();
				break;
			}

			return false;
		}else {
			return true
		}
	}
}

function promptMsg(field, type) {
	if(type == 'basic') {
		if(field.checked == false) {
			var message = 'Note: Unsubscribe Basic or AMCS package will DEACTIVATE all login access for this company.\n';
			message += 'Please double check all login accesses and its access rights.';
		}else {
			return 0;
		}

	}else if(type == 'intern') {
		if(field.checked == true) {
			var message = 'Note: Subscribe Internship package will DEACTIVATE all login access for this company.\n';
		}else {
			var message = 'Note: Unsubscribe Internship package will DEACTIVATE all login access for this company.\n';
		}
	}
	
	//testing for part-time //
	else if(type == 'parttime') {
		if(field.checked == true) {
			var message = 'Note: Subscribe Part Time package will DEACTIVATE all login access for this company.\n';
		}else {
			var message = 'Note: Unsubscribe Part Time package will DEACTIVATE all login access for this company.\n';
		}
	}
	//testing for part-time //
	
	alert(message);
}

function checkTraineePlacemt(frm) {
	var e = document.forms[frm.name];

	if(e.txtCommenceDT.value.length == 0) {
		alert('Please enter Start Date/Time');
		e.txtCommenceDT.select();
		return false;

	}else if(e.txtEndDT.value.length == 0) {
		alert('Please enter End Date/Time');
		e.txtEndDT.select();
		return false;

	}else if(e.txtPostition.value.length == 0) {
		alert('Please enter Position title.');
		e.txtPostition.select();
		return false;

	}else {
		var tempDate = e.txtCommenceDT.value.substr(0, 10);
		var tempTime = e.txtCommenceDT.value.substr(11, 8);
		var dtStart = new Date(tempDate.substr(6, 4), tempDate.substr(3, 2), tempDate.substr(0, 2), tempTime.substr(0, 2), tempTime.substr(3, 2), tempTime.substr(6, 2));

		tempDate = e.txtEndDT.value.substr(0, 10);
		tempTime = e.txtEndDT.value.substr(11, 8);
		var dtEnd = new Date(tempDate.substr(6, 4), tempDate.substr(3, 2), tempDate.substr(0, 2), tempTime.substr(0, 2), tempTime.substr(3, 2), tempTime.substr(6, 2));

		if(dtStart >= dtEnd) {
			alert('Start Date/Time cannot exceed or equals to End Date/Time');
			e.txtEndDT.select();
			return false;
		}
		
		return true;

	}
}

function addElement(thisForm, sourceField, targetField) {
	var source = document.forms[thisForm.name].elements[sourceField];
	var target = document.forms[thisForm.name].elements[targetField];

	if(source.value.length == 0) {
		alert('Enter at least a city.');
		source.focus();
		return false;
	}else if(!isNaN(source.value)) {
		alert('Enter a valid city.');
		source.focus();
		return false;
	}else {
		var city = source.value.replace(/[^A-Za-z\s]/g, '');

		for(i=0; i<target.length; i++) {
			//alert('text : '+target.options[i].text+' value : '+target.options[i].value);
			if(target.options[i].value.toLowerCase() == city.toLowerCase()) {
				alert('The value entered is already in the list.');
				return false;
			}
		}
		target.options[i] = new Option(city, city);
		source.value = '';
	}
}

function remElement(thisForm, targetField) {
	var target = document.forms[thisForm.name].elements[targetField];
	var targetLen = target.options.length;

	for(i=0; i<targetLen; i++) {
		if(i == target.options.selectedIndex) {
			target.options[i] = null;
		}
	}

	if(parseInt(target.options.length) == parseInt(targetLen)) {
		alert('Select a city to remove.');
		return false;
	}else {
		return true;
	}
}

function fadeWorkLocation(obj_to_fade, obj1, obj2) {
	var e1 = document.getElementById(obj1);
	var e2 = document.getElementById(obj2);

	if(obj_to_fade == 'state') {
		e1.disabled = true;
		e2.disabled = false;
		e1.selectedIndex = -1;
		e2.selectedIndex = 0;
	}else if(obj_to_fade == 'country') {
		e1.disabled = false;
		e2.disabled = true;
		e1.selectedIndex = -1;
		e2.selectedIndex = 0;
	}
}

function postSearch(the_form) {
	var lenSF = document.getElementById('f_sf2').length;
	var e = document.getElementById('f_sf2');
	for(j=0; j< lenSF; j++) {
		document.forms[the_form].f_sf.value += e.options[j].value + ',';
	}
	document.forms[the_form].f_sf.value = document.forms[the_form].f_sf.value.replace(/[,]$/, '');
}

function disableComName(the_obj, the_target) {
	var objTarget = document.frmForm.elements[the_target];
	var regMatch = new RegExp('recruiter', 'i');
	
	if(the_obj.checked == true) {
		objTarget.value = (objTarget.value != '') ? objTarget.value : 'Recruiter';
		objTarget.readOnly = true;
	}else {
		objTarget.value = (regMatch.exec(objTarget.value)) ? '' : objTarget.value;
		objTarget.readOnly = false;
	}
}

function checkEmail2ClientField() {
	var control;
	var proceed = true;

	with(document.frmForm) {
		// trim called from trimString.js
		if(trim(txtClientName.value).length == 0) { proceed = false; control = 1; }
		else if(validateForm(txtEmail) == false) { return false; }
		else if(trim(txtSubject.value).length == 0) { proceed = false; control = 2; }
		else if(trim(txtContent.value).length == 0) { proceed = false; control = 3; }

		if(!proceed) {
			switch(control) {
			case 1:
				alert('Please enter Client Name');
				txtClientName.select();
				break;
			case 2:
				alert('Please enter Subject');
				txtSubject.select();
				break;
			case 3:
				alert('Please enter Content');
				txtContent.select();
				break;
			}

			return false;
		}else {
			return true;
		}
	}
}

function checkEvaField() {
	var control = new Array();
	var elts = document.frmForm.elements;
	var lenObj = document.frmForm.elements.length;

	for(i=1; i<=23; i++) {
		for(j=0; j<lenObj; j++) {
			if(elts[j].type == 'radio' && elts[j].name == 'radQ'+i && elts[j].checked) {
				control.push(1);
				break;
			}
		}
	}

	for(i=1; i<=3; i++) {
		for(j=0; j<lenObj; j++) {
			if(elts[j].type == 'checkbox' && elts[j].name.indexOf('chkQ'+i+'[') != -1 && elts[j].checked) {
				control.push(1);
				break;
			}
		}
	}

	if(control.length != 26) {
		alert('Please fill up all mandatory fields');
		return false;

	}else {
		return true;
	}

}