function updFrequence(oCtrl, iId, iSsid, msgUpdating, msgFail, msgUnsub, msgDaily, msgWeekly, msgConnect)
{
	sDiv = 'ajaxmsg' + iId;
	var oFreCon = document.getElementById(sDiv);
	//if(oFreCon != null) oFreCon.innerHTML = "Updating...";
	if(oFreCon != null) oFreCon.innerHTML = msgUpdating;

	var iRandom = Math.random();
	var sUrl = dPath + "/my-job/upd-frequence.php?fid="+oCtrl.value+"&sid="+iId+"&rnd="+iRandom+"&ssid="+iSsid;
	var callbackFb = {};
	callbackFb.success = updFre;
	callbackFb.timeout = 8000; 
	callbackFb.argument = new Array(iId, oCtrl.value, msgUnsub, msgDaily, msgWeekly, msgConnect);
	//Do request
	if(typeof(YAHOO) != 'undefined')
	{
		var request = YAHOO.util.Connect.asyncRequest('GET', sUrl, callbackFb, null);   
	}
	else
	{
		//oFreCon.innerHTML = "Update fail. Please refresh this page and try again.";
		oFreCon.innerHTML = msgFail;
	}
}

function updFre(arg)
{
	iId = arg.argument[0];
	iFid = arg.argument[1];
	mix = arg.responseText;
	iSuccess = false;
	if(mix != undefined) 
	{
		iSuccess = mix.search('success'); 
		if(iSuccess > 0) iSuccess = true;
		else iSuccess = false;
	}
	sDiv = 'ajaxmsg' + iId;
	var oFreCon = document.getElementById(sDiv);
	if(iSuccess)
	{
		//if(iFid == 0){sHtml = "You have unsubscribed email alert.";}
		//else if(iFid == 1){sHtml = "You will receive an email alert daily.";}
		//else if (iFid == 2){sHtml = "You will receive an email alert weekly.";}
        if(iFid == 0){sHtml = arg.argument[2];}
        else if(iFid == 1){sHtml = arg.argument[3];}
        else if (iFid == 2){sHtml = arg.argument[4];}		
		else {sHtml = "Saved";}
	}
	//else sHtml = "Connection fail. Please try again.";
	else sHtml = arg.argument[5];
	if(oFreCon != null) oFreCon.innerHTML = sHtml;		
}

function delBookmarkJob(id, x, msg)
{
	//if(confirm('Are you sure deleting this bookmarked job?'))
	if(confirm(msg))
	{
		document.location.href= "?del=" + id + "&x=" + x;
	}
	return false;
}

function delSavedSearchJob(id, x, p, msg)
{
	//if(confirm('Are you sure to delete this job alert?'))
	if(confirm(msg))
	{
		document.location.href= "?did=" + id + p + "&x=" + x;
	}
	return false;
}

function checkLoginExist(x, lid, sType, msgRegisterB4, msgNotAvail)
{
	if(sType == 'E')
	{
		oDivLi = document.getElementById('login_id');
		if(oDivLi != null && trim(oDivLi.value) != "") return;
	}

	if(trim(lid) == "") 
	{
		return;
	}

	var iRandom = Math.random();
	var sUrl = dPath + '/registration/login-exist.php?x=' + x + '&ac=2&li=' + encodeURIComponent(lid) + "&rnd="+iRandom;

	var callbackFb = {};
	callbackFb.success = updLoginExist;
	callbackFb.timeout = 8000; 
	callbackFb.argument = new Array(sType, msgRegisterB4, msgNotAvail);
	//Do request
	if(typeof(YAHOO) != 'undefined')
	{
		var request = YAHOO.util.Connect.asyncRequest('GET', sUrl, callbackFb, null);   
	}
}

function updLoginExist(arg)
{
	sType = arg.argument[0];
	mix = arg.responseText;	
	if(mix != undefined) 
	{
		var result = mix.split("|");

		sDiv = 'div_register';
		var obj = elId(sDiv);
		if(obj != null) 
		{
			setDivMsg(sDiv, '');
			setObjVisibility(sDiv,'false'); 
		}

		sDiv = 'div_reg_login_id';
        if (result[0] == 0) {
			//Login Exist
			if(sType == 'E')
			{
				//sMsg = "Sorry, this email address has been registered as a Login ID by another user. You can still register with this Email address, but please enter a new login ID below.";
				sMsg = arg.argument[1];
			}
			else
			{
				//sMsg = "This Login ID not available. Please use another one.";
				sMsg = arg.argument[2];
			}			
			
			var oDiv = document.getElementById(sDiv);
			if(oDiv != null) 
			{
				setObjVisibility(sDiv, 'true'); 
				setDivMsg(sDiv, sMsg);	
				setDivClass(sDiv, 'errorReg');
			}				
			oDivLi = document.getElementById('dvLoginId');
			if(oDivLi != null)
			{
				oDivLi.style.display = '';
				document.getElementById('login_id').disabled = false;
				document.getElementById('login_id').focus();				
				document.getElementById('tipEmailDesc').style.display = 'none';
			}
        } 	
		else
		{
			var obj = elId(sDiv);
			if(obj != null) 
			{
				if(obj.className == 'errorReg')
				{
					setDivMsg(sDiv, '');
					setObjVisibility(sDiv,'false'); 
				}
			}

			//if Login ID field is empty, hide it
			if(sType == 'E')
			{
				oDivLi = document.getElementById('login_id');
				if(oDivLi != null && trim(oDivLi.value) == "")
				{
					oDivLi = document.getElementById('dvLoginId');
					if(oDivLi != null)
					{
						document.getElementById('tipEmailDesc').style.display = '';
						document.getElementById('cemail').focus();	
						document.getElementById('login_id').disabled = true;						
						oDivLi.style.display = 'none';
					}					
				}
			}
		}
	}
	
}

function showMoreOpt()
{
	setObjVisibility('optHide', 'true');
	setObjVisibility('optHideCtrl', 'false');
}

function saveSearch(oCtrl, bConfirm, bMode, msgSpec, msgMax, msgOths, msgLoc)
{
	bResult = true;
	//bResult = core_validator.onCheckSubmit(oCtrl);
	if(trim(document.master.subject.value) == "")
	{
		vConfig.form = 'master';
		vConfig.addError('subject', 'ERR_REQUIRED', "");
		core_validator.onHandleErrorByKey('master','subject');
		bResult = false;
	}	

	if(bResult == false)
	{
		saveSearchValidate(oCtrl, 1, msgSpec, msgMax, msgOths, msgLoc);
		document.location.href="#e1";
		return false;
	}
	else
	{ 
		bResult = saveSearchValidate(oCtrl, 1, msgSpec, msgMax, msgOths, msgLoc);
		if(bResult == false) return false;
		
//		if(bConfirm) 
//		{
//			bResult = confirm('Do you wish to preview jobs before create this job alert?\nClick \'Cancel\' to continue create job alert.');		
//			if(bResult)
//			{
//				document.master.mode.value = "preview";
//				document.master.submit();
//				return false;
//			}
//		}
		document.master.submit();
		return true;
	}
}

function saveSearchValidate(oCtrl, bFocus, msgSpec, msgMax, msgOths, msgLoc)
{
	bErr = false;
	oSpe = elName('specialization[]');
	bSpe = false;
	iSpe = 0;
	bOtherSpe = false;
	if(oSpe.length == 0) return true;	
	for(var i=0; i < oSpe.length ; i++) {if(oSpe[i].checked == true) {bSpe = true;iSpe++; if(oSpe[i].value == '116') bOtherSpe=true; }}

	oKey = elId('key');
	bKey = false;
	if(oKey != null) if(trim(oKey.value) != "") bKey = true;
		
	oLoc = elName('location[]');
	bLoc = false;
	for(var i=0; i < oLoc.length ; i++) {if(oLoc[i].checked == true) {bLoc = true;break;}}

	sDiv = 'div_mandatory';
	if(bSpe == false &&  bKey == false )
	{
		//Error Found
		//sMsg = "Please provide your specialization or keyword!";
		sMsg = msgSpec;
		var oDiv = document.getElementById(sDiv);
		if(oDiv != null) 
		{
			setObjVisibility(sDiv, 'true'); 
			setDivMsg(sDiv, sMsg);	
			setDivClass(sDiv, 'errorReg');
		}
		if(bFocus == 1) document.location.href="#e1";
		bErr = true;
	}
	else if(iSpe>5 && bErr == false) 
	{
		setObjVisibility(sDiv, 'true'); 
		//setDivMsg(sDiv, 'Please select maximum 5 specializations only.');	
		setDivMsg(sDiv, msgMax);
		setDivClass(sDiv, 'errorReg');
		if(bFocus == 1) document.location.href="#e1";
		bErr = true;
	}
	else
	{
		var obj = elId(sDiv);
		if(obj != null) 
		{
			if(obj.className == 'errorReg')
			{
				setDivMsg(sDiv, '');
				setObjVisibility(sDiv,'false'); 
			}
		}
	}	
	
	if(bOtherSpe && bKey == false)
	{
		setObjVisibility('div_key', 'true'); 
		//setDivMsg('div_key', "You have select 'Others' as your specialization. Please tell us more by providing keyword.");	
		setDivMsg('div_key', msgOths);
		setDivClass('div_key', 'errorReg');
		if(bFocus == 1) document.location.href="#e1";
		bErr = true;
	}
	else
	{
		var obj = elId('div_key');
		if(obj != null) 
		{
			if(obj.className == 'errorReg')
			{
				setDivMsg('div_key', '');
				setObjVisibility('div_key','false'); 
			}
		}
	}

	if(bLoc == false)
	{
		setObjVisibility('div_loc', 'true'); 
		//setDivMsg('div_loc', "Please provide your location!");	
		setDivMsg('div_loc', msgLoc);
		setDivClass('div_loc', 'errorReg');
		if(bFocus == 1) document.location.href="#e1";
		bErr = true;
	}
	else
	{
		var obj = elId('div_loc');
		if(obj != null) 
		{
			if(obj.className == 'errorReg')
			{
				setDivMsg('div_loc', '');
				setObjVisibility('div_loc','false'); 
			}
		}
	}

	if(bErr == true) return false;
	return true;
}

function showTips(sId, sMsg)
{
	var obj = elId(sId);
	if(obj != null) 
	{
		if(obj.className == 'errorReg') return;
		setObjVisibility(sId,'true'); 
		setDivClass(sId, 'overlay');	
		obj.innerHTML = sMsg;
	}
}


function hideTips(sId)
{
	var obj = elId(sId);
	if(obj != null) 
	{
		if(obj.className == 'errorReg') return;
		setObjVisibility(sId,'false');
		setDivClass(sId, '');
		obj.innerHTML = "";
	}
}

function toggleAllOverseas(oCtrl, sLoc)
{
	if (oCtrl.checked == true) checkAllLoc(0,1, sLoc);
	else uncheckAllLoc(0,1, sLoc);
}

function clearLocation()
{
	uncheckAllLoc(1,1);
	oCtrl = elId('cbAllOverseas');
	if(oCtrl != null) oCtrl.checked = false;
}

function updateThisExternal(oCtrl)
{
	sName = oCtrl.name;
	sName = sName.replace("[]","");
	if(sName == 'specialization')
	{
		if(typeof(bSpeCheckMax) == 'undefined') bSpeCheckMax = false;
		if(bSpeCheckMax)
		{
			if(typeof(sSpeErrDiv) == 'undefined') sSpeErrDiv = 'div_mandatory';
			if(typeof(sSpeLabel) == 'undefined') sSpeLabel = 'Specialization';
			ctrlMaxSel(oCtrl, sSpeErrDiv, sSpeLabel, bSpeCheckMax);
		}
	}
	
	if(sName == 'location')
	{
		isAllCountryCheck();
	}
}

//This is customize function
function updateThisDetail(oCtrl)
{	
	if(typeof(updateThisExternal) == 'function') updateThisExternal(oCtrl);
}

function isAllCountryCheck()
{	
	//check All overseas location flag, hard code
	oAllOvsCtrl = getEl('cbAllOverseas');
	if(oAllOvsCtrl != null)
	{
		bAllOvsCheck = true;
		if(typeof(sCountryLocation) == 'undefined') sCountryLocation = "";
		if(bAllOvsCheck && getEl('location10000').checked == false && sCountryLocation != '10000') bAllOvsCheck = false;
		if(bAllOvsCheck && getEl('location20000').checked == false && sCountryLocation != '20000') bAllOvsCheck = false;
		if(bAllOvsCheck && getEl('location30000').checked == false && sCountryLocation != '30000') bAllOvsCheck = false;
		if(bAllOvsCheck && getEl('location40000').checked == false && sCountryLocation != '40000') bAllOvsCheck = false;
		if(bAllOvsCheck && getEl('location50000').checked == false && sCountryLocation != '50000') bAllOvsCheck = false;
		if(bAllOvsCheck && getEl('location60000').checked == false && sCountryLocation != '60000') bAllOvsCheck = false;
		if(bAllOvsCheck && getEl('location70000').checked == false && sCountryLocation != '70000') bAllOvsCheck = false;
		if(bAllOvsCheck && getEl('location80000').checked == false && sCountryLocation != '80000') bAllOvsCheck = false;
		if(bAllOvsCheck && getEl('location100000').checked == false && sCountryLocation != '100000') bAllOvsCheck = false;
		if(bAllOvsCheck && getEl('location110000').checked == false && sCountryLocation != '110000') bAllOvsCheck = false;
		if(bAllOvsCheck && getEl('location120000').checked == false && sCountryLocation != '120000') bAllOvsCheck = false;
		if(bAllOvsCheck && getEl('location150000').checked == false && sCountryLocation != '150000') bAllOvsCheck = false;
		if(bAllOvsCheck && getEl('location90100').checked == false && sCountryLocation != '90100') bAllOvsCheck = false;
		oAllOvsCtrl.checked = bAllOvsCheck;
	}
}