if(typeof(lngAddToJobList) == 'undefined')	lngAddToJobList = "Jobs added to MyJobList!";
if(typeof(lngPlsSelOne) == 'undefined')		lngPlsSelOne = "Please select one or more jobs first! Tick the checkbox to select.";
if(typeof(lngDelJob) == 'undefined')		lngDelJob = "Delete this Job from MyJobList?";
if(typeof(lngDelAllJob) == 'undefined')		lngDelAllJob = "Delete all Jobs in MyJobList?";

function addAllMyJobList()
{
	var oField = document.getElementsByName('cb[]');	
	var bCheckCnt = 0;
	for(var i =0; i<oField.length ;i++)
	{
		sId = oField[i].id;
		sId = sId.substr(2);
		addMyJobList(oField[i], sId);	
		if(oField[i].checked) bCheckCnt++;		
	}
	if(bCheckCnt>0) alert(lngAddToJobList);
	else alert(lngPlsSelOne);
}

function addMyJobList(oCtrl, iGlobalJobId)
{
	var isAdd = oCtrl.checked;
	var sVal = getMyJobList();
	if(isAdd)
	{
		var arrVal = sVal.split(",");
		if (!arrVal.exists(iGlobalJobId))
			sVal = sVal + ',' + iGlobalJobId;
	}
	else 
	{
		sVal = sVal.replace(',' + iGlobalJobId,'');
	}
	setMyJobList(sVal);	
}

function getMyJobList()
{
	core_cookie.setFullDomain();
	return core_cookie.getValue('JAVASCRIPT', 'MYJOBLIST');
}

function setMyJobList(sVal)
{
	core_cookie.setFullDomain();
	core_cookie.setValue('JAVASCRIPT', sVal, 'MYJOBLIST');
}

function delAllMyJobList(sParam)
{
	if(typeof(sParam) == 'undefined') sParam = "";
	var bSure = confirm(lngDelAllJob);
	if(bSure == false) return;
	setMyJobList('');

	sUrl = dPath + '/' + sCountry + '/job-classified.php';
	if(sParam != "") sUrl = sUrl + '?' + sParam;
	location.href = sUrl;
}

function delMyJobList(oCtrl, iGlobalJobId)
{
	var bSure = confirm(lngDelJob);
	if(bSure == false) return;
	var sVal = getMyJobList();
	sVal = sVal.replace(',' + iGlobalJobId,'');
	setMyJobList(sVal);	
	
	var sDiv = 'rowMyJobList' + iGlobalJobId;
	var oDiv = document.getElementById(sDiv);	
	if(oDiv == null) return;
	oDiv.style.visibility = 'hidden';
	oDiv.style.display = 'none';

	if(sVal == "")
	{
		//redirect to classified jobs list
		location.href = dPath + '/' + sCountry + '/job-classified.php';
	}
}

function updMyJobList()
{
	var oField = document.getElementsByName('cb[]');	
	var iId, sVal, iMatch;
	sVal = getMyJobList();
	for(var i =0; i<oField.length ;i++)
	{
		iId = oField[i].id
		iId = iId.replace(/cb/, ",");
		iMatch = sVal.match(iId);
		if(iMatch != null) oField[i].checked = true;
	}
}

function clearMyJobList()
{
	setMyJobList('');
	var oField = document.getElementsByName('cb[]');	
	for(var i =0; i<oField.length ;i++) oField[i].checked = false;
}

function viewMyJobList(sParam)
{
	if(typeof(sParam) == 'undefined') sParam = "";
	var sVal = getMyJobList();	
	if(sVal == '')
	{
		//alert('MyJobList is empty. Please select Jobs by tick the checkbox below.');
		//return;
	}
	sUrl = dPath + '/' + sCountry + '/my-job-classified.php';
	if(sParam != "") sUrl = sUrl + '?' + sParam;
	location.href = sUrl;
}

function printMyJobList()
{
	window.print();
}

Array.prototype.exists = function(search){
  for (var i=0; i<this.length; i++)
    if (this[i] == search) return true;
		
  return false;
}