/*
return element object by Id
@param string, object Id
@return element object
*/
function elId(id){return document.getElementById(id);}

/*
return element object by name
@param string, object name
@return element object
*/
function elName(name){return document.getElementByName(name);}

/**
 * trim value
 * @param string strToTrim. value to be trim.
 * @return string
 */
function trim(strToTrim)
{
	return strToTrim.replace(/^\s+|\s+$/g,"");
}

/**
 * set object visibility
 * @param string strObjName. object name.
 * @param boolean blnShow. true=visible | false=collapse
 */
function setObjVisibility(strObjName, blnShow)
{	
	var obj = elId(strObjName);
	if(obj == null) return;

	var strVisibleValue ;
//	if(blnShow == 'true') strVisibleValue = 'visible';
//	else strVisibleValue = 'collapse';
//	obj.style.visibility = strVisibleValue;
	
	if(blnShow == 'true')
	{
		obj.style.display = '';
		obj.style.visibility = 'visible';		
	}
	else obj.style.display = 'none';
}

/**
 * set object Div msg
 * @param string strObjName. regex.
 * @param string strMsg. msg
 * @param string strClassName. css class name
 */
function setDivMsg(strObjName, strMsg, strClassName)
{
	var obj = elId(strObjName);
	if(obj == null) return;
	if(typeof(strClassName) != 'undefined' && strClassName.length > 0) 
	{
		strMsg = "<span class='" + strClassName +"'>" + strMsg + "</span>";
	}
	obj.innerHTML  = strMsg;
}

/*
* Do submit
*/
function doSubmit(objCtrl)
{
	objCtrl.form.submit();
}

/*
* Do Client site language translation
*/
function lang(strKey)
{
	var translation = eval(strKey);
	if(translation == '') return strKey;
	return translation;
}

function escapeHTML (str)
{
   var div = document.createElement('div');
   var text = document.createTextNode(str);
   div.appendChild(text);
   return div.innerHTML;
}


/*
* Include a js file in a js file. same as includeJs2 
*/
function includeJs(strUrl)
{
	var str = '<script type="text/javascript" src="' + strUrl + '"></script>';
	document.write(str); 
}

/*
* Include a js file in a js file. same as includeJs 
*/
function includeJs2(strUrl)
{
	var body = document.getElementsByTagName('body').item(0);
	script = document.createElement('script');
	script.src = strUrl;
	script.type = 'text/javascript';
	body.appendChild(script);
}

function popWin(url, h, w) 
{
	var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;

	if(typeof(h) == 'undefined') h = 600;
	if(typeof(w) == 'undefined') w = 700;
	
	if (is_chrome)
	{
		w=window.open('about:blank', "W958b6e9ea6bed1f9c5288b15959dad77", "left=150,top=120,menubar=no,height="+h+",width="+w+",scrollbars=yes,resizable=yes");
		w.opener = null;
		w.document.location = url;
	}
	else
	{
		w=window.open(url, "W958b6e9ea6bed1f9c5288b15959dad77", "left=150,top=120,menubar=no,height="+h+",width="+w+",scrollbars=yes,resizable=yes");
	}
	w.focus();
} 

<!--
/*
 * cookie.js - mainly manipulate cookie handling which similar to backend php
 * Secondly manipulate serialize, url, security
 */
//serialize object
//Source from : http://www.coolcode.cn/andot/javascript-php-serialize-unserialize/171
//Source from : http://www.onicos.com/staff/iz/amuse/javascript/expert/utf.txt
var core_serialize = {
	serialize:function(o){
		var p = 0, sb = [], ht = [], hv = 1;
		var classname = function(o) {
			if (typeof(o) == 'undefined' || typeof(o.constructor) == 'undefined') return '';
			var c = o.constructor.toString();
			c = core_serialize.utf16to8(c.substr(0, c.indexOf('(')).replace(/(^\s*function\s*)|(\s*$)/ig, ''));
			return ((c == '') ? 'Object' : c);
		};
		var is_int = function(n) {
			var s = n.toString(), l = s.length;
			if (l > 11) return false;
			for (var i = (s.charAt(0) == '-') ? 1 : 0; i < l; i++) {
				switch (s.charAt(i)) {
					case '0':
					case '1':
					case '2':
					case '3':
					case '4':
					case '5':
					case '6':
					case '7':
					case '8':
					case '9': break;
					default : return false;
				}
			}
			return !(n < -2147483648 || n > 2147483647);
		};
		var in_ht = function(o) {
			for (var k in ht) if (ht[k] === o) return k;
			return false;
		};
		var ser_null = function() {
			sb[p++] = 'N;';
		};
		var ser_boolean = function(b) {
			sb[p++] = (b ? 'b:1;' : 'b:0;');
		};
		var ser_integer = function(i) {
			sb[p++] = 'i:' + i + ';';
		};
		var ser_double = function(d) {
			if (isNaN(d)) d = 'NAN';
			else if (d == Number.POSITIVE_INFINITY) d = 'INF';
			else if (d == Number.NEGATIVE_INFINITY) d = '-INF';
			sb[p++] = 'd:' + d + ';';
		};
		var ser_string = function(s) {
			var utf8 = core_serialize.utf16to8(s);
			sb[p++] = 's:' + utf8.length + ':"';
			sb[p++] = utf8;
			sb[p++] = '";';
		};
		var ser_date = function(dt) {
			sb[p++] = 'O:4:"Date":7:{';
			sb[p++] = 's:4:"year";';
			ser_integer(dt.getFullYear());
			sb[p++] = 's:5:"month";';
			ser_integer(dt.getMonth() + 1);
			sb[p++] = 's:3:"day";';
			ser_integer(dt.getDate());
			sb[p++] = 's:4:"hour";';
			ser_integer(dt.getHours());
			sb[p++] = 's:6:"minute";';
			ser_integer(dt.getMinutes());
			sb[p++] = 's:6:"second";';
			ser_integer(dt.getSeconds());
			sb[p++] = 's:11:"millisecond";';
			ser_integer(dt.getMilliseconds());
			sb[p++] = '}';
		}
		var ser_array = function(a) {
			sb[p++] = 'a:';
			var lp = p;
			sb[p++] = 0;
			sb[p++] = ':{';
			for (var k in a) {
				if (typeof(a[k]) != 'function') {
					is_int(k) ? ser_integer(k) : ser_string(k);
					__serialize(a[k]);
					sb[lp]++;
				}
			}
			sb[p++] = '}';
		};
		var ser_object = function(o) {
			var cn = classname(o);
			if (cn == '') ser_null();
			else if (typeof(o.serialize) != 'function') {
				sb[p++] = 'O:' + cn.length + ':"' + cn + '":';
				var lp = p;
				sb[p++] = 0;
				sb[p++] = ':{';
				if (typeof(o.__sleep) == 'function') {
					var a = o.__sleep();
					for (var kk in a) {
						ser_string(a[kk]);
						__serialize(o[a[kk]]);
						sb[lp]++;
					}
				}
				else {
					for (var k in o) {
						if (typeof(o[k]) != 'function') {
							ser_string(k);
							__serialize(o[k]);
							sb[lp]++;
						}
					}
				}
				sb[p++] = '}';
			}
			else {
				var cs = o.serialize();
				sb[p++] = 'C:' + cn.length + ':"' + cn + '":' + cs.length + ':{' +cs + '}';
			}
		};
		var ser_pointref = function(R) {
			sb[p++] = 'R:' + R + ';';
		};
		var ser_ref = function(r) {
			sb[p++] = 'r:' + r + ';';
		};
		var __serialize = function(o) {
			if (o == null || o.constructor == Function) {
				hv++;
				ser_null();
			}
			else switch (o.constructor) {
				case Boolean: {
					hv++;
					ser_boolean(o);
					break;
				}
				case Number: {
					hv++;
					is_int(o) ? ser_integer(o) : ser_double(o);
					break;
				}
				case String: {
					hv++;
					ser_string(o);
					break;
				}
				case Date: {
					hv++;
					ser_date(o);
				}
				case Object:
				case Array: {
					var r = in_ht(o);
					if (r) {
						ser_pointref(r);
					}
					else {
						ht[hv++] = o;
						ser_array(o);
					}
					break;
				}
				default: {
					var r = in_ht(o);
					if (r) {
						hv++;
						ser_ref(r);
					}
					else {
						ht[hv++] = o;
						ser_object(o);
					}
					break;
				}
			}
		};
		__serialize(o);
		return sb.join('');
	},
	
	unserialize:function(ss) {
		var p = 0, ht = [], hv = 1;
		var unser_null = function() {
			p++;
			return null;
		};
		var unser_boolean = function() {
			p++;
			var b = (ss.charAt(p++) == '1');
			p++;
			return b;
		};
		var unser_integer = function() {
			p++;
			var i = parseInt(ss.substring(p, p = ss.indexOf(';', p)));
			p++;
			return i;
		};
		var unser_double = function() {
			p++;
			var d = ss.substring(p, p = ss.indexOf(';', p));
			switch (d) {
				case 'NAN': d = NaN; break;
				case 'INF': d = Number.POSITIVE_INFINITY; break;
				case '-INF': d = Number.NEGATIVE_INFINITY; break;
				default: d = parseFloat(d);
			}
			p++;
			return d;
		};
		var unser_string = function() {
			p++;
			var l = parseInt(ss.substring(p, p = ss.indexOf(':', p)));
			p += 2;
			var s = core_serialize.utf8to16(ss.substring(p, p += l));
			p += 2;
			return s;
		};
		var unser_array = function() {
			p++;
			var n = parseInt(ss.substring(p, p = ss.indexOf(':', p)));
			p += 2;
			var a = [];
			ht[hv++] = a;
			for (var i = 0; i < n; i++) {
				var k;
				switch (ss.charAt(p++)) {
					case 'i': k = unser_integer(); break;
					case 's': k = unser_string(); break;
					case 'U': k = unser_unicode_string(); break;
					default: return false;
				}
				a[k] = __unserialize();
			}
			p++;
			return a;
		};
		var unser_date = function() {
			var k, a = [];
			for (var i = 0; i < 7; i++) {
				p++;
				k = unser_string();
				p++;
				a[k] = unser_integer();
			}
			var dt = new Date(
				a['year'],
				a['month'] - 1,
				a['day'],
				a['hour'],
				a['minute'],
				a['second'],
				a['millisecond']
			);
			ht[hv++] = dt;
			return dt;
		}
		var unser_object = function() {
			p++;
			var l = parseInt(ss.substring(p, p = ss.indexOf(':', p)));
			p += 2;
			var cn = core_serialize.utf8to16(ss.substring(p, p += l));
			p += 2;
			var n = parseInt(ss.substring(p, p = ss.indexOf(':', p)));
			p += 2;
			if (cn == "Date" && n == 7) {
				return unser_date();
			}
			if (eval(['typeof(', cn, ') == "undefined"'].join(''))) {
				eval(['function ', cn, '(){}'].join(''));
			}
			var o = eval(['new ', cn, '()'].join(''));
			ht[hv++] = o;
			for (var i = 0; i < n; i++) {
				var k;
				switch (ss.charAt(p++)) {
					case 's': k = unser_string(); break;
					case 'U': k = unser_unicode_string(); break;
					default: return false;
				}
				if (k.charAt(0) == '\0') {
					k = k.substring(k.indexOf('\0', 1) + 1, k.length);
				}
				o[k] = __unserialize();
			}
			p++;
			if (typeof(o.__wakeup) == 'function') o.__wakeup();
			return o;
		};
		var unser_custom_object = function() {
			p++;
			var l = parseInt(ss.substring(p, p = ss.indexOf(':', p)));
			p += 2;
			var cn = core_serialize.utf8to16(ss.substring(p, p += l));
			p += 2;
			var n = parseInt(ss.substring(p, p = ss.indexOf(':', p)));
			p += 2;
			if (eval(['typeof(', cn, ') == "undefined"'].join(''))) {
				eval(['function ', cn, '(){}'].join(''));
			}
			var o = eval(['new ', cn, '()'].join(''));
			ht[hv++] = o;
			if (typeof(o.unserialize) != 'function') p += n;
			else o.unserialize(ss.substring(p, p += n));
			p++;
			return o;
		};
		var unser_unicode_string = function() {
			p++;
			var l = parseInt(ss.substring(p, p = ss.indexOf(':', p)));
			p += 2;
			var sb = [];
			for (var i = 0; i < l; i++) {
				if ((sb[i] = ss.charAt(p++)) == '\\') {
					sb[i] = String.fromCharCode(parseInt(ss.substring(p, p += 4), 16));
				}
			}
			p += 2;
			return sb.join('');
		};
		var unser_ref = function() {
			p++;
			var r = parseInt(ss.substring(p, p = ss.indexOf(';', p)));
			p++;
			return ht[r];
		};
		var __unserialize = function() {
			switch (ss.charAt(p++)) {
				case 'N': return ht[hv++] = unser_null();
				case 'b': return ht[hv++] = unser_boolean();
				case 'i': return ht[hv++] = unser_integer();
				case 'd': return ht[hv++] = unser_double();
				case 's': return ht[hv++] = unser_string();
				case 'U': return ht[hv++] = unser_unicode_string();
				case 'r': return ht[hv++] = unser_ref();
				case 'a': return unser_array();
				case 'O': return unser_object();
				case 'C': return unser_custom_object();
				case 'R': return unser_ref();
				default: return false;
			}
		};
		return __unserialize();
	},
	
	utf16to8:function(str){
		var out, i, len, c;
		out = "";
		len = str.length;
		for(i = 0; i < len; i++) {
			c = str.charCodeAt(i);
			if ((c >= 0x0001) && (c <= 0x007F)) {
				out += str.charAt(i);
			} else if (c > 0x07FF) {
				out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F));
				out += String.fromCharCode(0x80 | ((c >>  6) & 0x3F));
				out += String.fromCharCode(0x80 | ((c >>  0) & 0x3F));
			} else {
				out += String.fromCharCode(0xC0 | ((c >>  6) & 0x1F));
				out += String.fromCharCode(0x80 | ((c >>  0) & 0x3F));
			}
		}
		return out;
	},

	utf8to16:function(str){
		var out, i, len, c;
		var char2, char3;

		out = "";
		len = str.length;
		i = 0;
		while(i < len) {
			c = str.charCodeAt(i++);
			switch(c >> 4)
			{ 
			  case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
				// 0xxxxxxx
				out += str.charAt(i-1);
				break;
			  case 12: case 13:
				// 110x xxxx   10xx xxxx
				char2 = str.charCodeAt(i++);
				out += String.fromCharCode(((c & 0x1F) << 6) | (char2 & 0x3F));
				break;
			  case 14:
				// 1110 xxxx  10xx xxxx  10xx xxxx
				char2 = str.charCodeAt(i++);
				char3 = str.charCodeAt(i++);
				out += String.fromCharCode(((c & 0x0F) << 12) |
							   ((char2 & 0x3F) << 6) |
							   ((char3 & 0x3F) << 0));
				break;
			}
		}
		return out;
	}
};//end serialize object

// Url Object
var core_url = {
	getBaseDomain:function(){
		e = document.domain.split(/\./);
		if(e.length > 1) return (e[e.length-2] + "." +  e[e.length-1]) ;
		else return "";	  
	}
};//end url object

// Cookie Object
var core_cookie = {
	iExpiry : 0,
	sPath : '/',
	sDomain : '',
	bSecure : false,
	bHttpOnly : true,

	getTime:function(){
		var dTime = new Date();
		dTime.getTime();
		return Math.round(dTime/1000);
	},
	
	setExpiry:function(){
		this.iExpiry = this.getTime()- 3600;
	},

	addExpiryTime:function(iTime){
		this.iExpiry = this.getTime() + iTime;
	},

	setBaseDomain:function(){
		if(this.isLocalHost()) return;		
		this.sDomain = "." + core_url.getBaseDomain();
	},

	setFullDomain:function(){
		if(this.isLocalHost()) return;
		this.sDomain = "." + document.location.hostname ;
	},

	setOtherDomain:function(sDomain){
		this.sDomain = sDomain;
	},
	
	isLocalHost:function(){
		var sHost = document.location.hostname;
		if(sHost.search(/localhost/i)<0) return false;
		this.sDomain = 'core.cookie.dev';
		return true;
	},
	
	setSecure:function(){
		this.bSecure = true;
	},

	setPath:function(sPath){
		this.sPath = sPath;
	},

	getValue:function(sType, sSubKey){
		var sCookie = this.getCookie(sType);
		var aPart = new Array();
		if(sCookie != "")
		{
			sCookie = core_security.decodeValue(sCookie);
			aPart = core_serialize.unserialize(sCookie);
			if(typeof(sSubKey) == 'undefined') return aPart;	

			if(typeof(aPart[sSubKey]) != 'undefined') return aPart[sSubKey];
		}
		return "";
	},

	setValue:function(sType, mValue, sSubKey){
		var sCookie = this.getCookie(sType);
		var aPart = new Array(); 	
		var sValue;
		if(sCookie != "")
		{
			sCookie = core_security.decodeValue(sCookie);
			aPart = core_serialize.unserialize(sCookie);			
		}
		if(typeof(sSubKey) != 'undefined')
		{
			aPart[sSubKey] = mValue ; 
			sValue = core_serialize.serialize(aPart);
		}
		else
		{			
			sValue = core_serialize.serialize(mValue);			
		}
		sValue = core_security.encodeValue(sValue);
		return this.setCookie(sType, sValue);
	},

	setCookie:function(sName, sValue){
		var iExpiry = this.iExpiry ;
		var oDate = new Date();
		oDate.setTime(iExpiry * 1000);
		iExpiry = oDate.toGMTString();
		var sPath = this.sPath ;
		var sDomain = this.sDomain ;
		var bSecure = this.bSecure ;

		var sCookie = sName + "=" + escape ( sValue ) ;
		if ( iExpiry )	sCookie += "; expires=" + iExpiry;
		if ( sPath )	sCookie += "; path=" + escape ( sPath );
		if ( sDomain )	sCookie += "; domain=" + escape ( sDomain );	  
		if ( bSecure )	sCookie += "; secure";	  
		document.cookie = sCookie;
	},

	getCookie:function(sName){
		if (document.cookie.length>0){
			sStart=document.cookie.indexOf(sName + "=");
			if (sStart!=-1){ 
				sStart=sStart + sName.length+1; 
				sEnd=document.cookie.indexOf(";",sStart);
				if (sEnd==-1) sEnd=document.cookie.length;
				return unescape(document.cookie.substring(sStart,sEnd));
			} 
		}	
		return "";
	}
};//end cookie object

core_cookie.addExpiryTime(3600);
core_cookie.setBaseDomain();

// Security Object
var core_security = {	
	s:"",
	t:"",

	encodeValue:function(mValue){
		return this.doSwitch(mValue, true);
	},
	
	decodeValue:function(sValue){
		return this.doSwitch(sValue, false);		
	},
	
	doSwitch:function(sValue, bEncode)
	{
		if(sValue == "") return sValue;
		
		var aCode = this.getEncodeSource(bEncode);
		aStr = sValue.split("");
		var sNew = "";
		var sChar = "";
		for (var i=0; i< aStr.length; i++ )
		{
			sChar = aStr[i];
			if(typeof(aCode[sChar]) != 'undefined') sNew += aCode[sChar];
			else sNew += sChar;
		}
		return sNew;
	},
	
	getEncodeSource:function(bEncode)
	{
		var aCode = new Array();
		var sSource = this.s;
		var sTarget = this.t;

		var aSource = sSource.split("");
		var aTarget = sTarget.split("");

		if(bEncode)
		{
			for(var i=0; i<aSource.length; i++)
			{
				aCode[aSource[i]] = aTarget[i];
			}			
		}
		else
		{
			for(var i=0; i<aTarget.length; i++)
			{
				aCode[aTarget[i]] = aSource[i];
			}
		}
		return aCode;		
	}


};//end object security

//encode from http://iframe.in/
//core_security.s = "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ";
eval(unescape('%63%6F%72%65%5F%73%65%63%75%72%69%74%79%2E%73%20%3D%20%22%61%62%63%64%65%66%67%68%69%6A%6B%6C%6D%6E%6F%70%71%72%73%74%75%76%77%78%79%7A%31%32%33%34%35%36%37%38%39%30%41%42%43%44%45%46%47%48%49%4A%4B%4C%4D%4E%4F%50%51%52%53%54%55%56%57%58%59%5A%22%3B'));
//core_security.t = "hijklVWXYZvwxyz123mnopqr4stu560ABCDEFG789HIJKQRSTLMNOPUabcdefg";
eval(unescape('%63%6F%72%65%5F%73%65%63%75%72%69%74%79%2E%74%20%3D%20%22%68%69%6A%6B%6C%56%57%58%59%5A%76%77%78%79%7A%31%32%33%6D%6E%6F%70%71%72%34%73%74%75%35%36%30%41%42%43%44%45%46%47%37%38%39%48%49%4A%4B%51%52%53%54%4C%4D%4E%4F%50%55%61%62%63%64%65%66%67%22%3B'));

//-->

function correctPNG() {// correctly handle PNG transparency in Win IE 5.5 & 6.
   var arVersion = navigator.appVersion.split("MSIE"); var version = parseFloat(arVersion[1]);
   if ((version >= 5.5) && (document.body.filters)) {
      for(var i=0; i<document.images.length; i++) {
         var img = document.images[i]; var imgName = img.src.toUpperCase();
         if (imgName.substring(imgName.length-3, imgName.length) == "PNG") {
            var imgID = (img.id) ? "id='" + img.id + "' " : ""; var imgClass = (img.className) ? "class='" + img.className + "' " : "";
            var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "; var imgStyle = "display:inline-block;" + img.style.cssText 
            if (img.align == "left") imgStyle = "float:left;" + imgStyle
            if (img.align == "right") imgStyle = "float:right;" + imgStyle
            if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
            var strNewHTML = "<span " + imgID + imgClass + imgTitle
            + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
            + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
            + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>";
            img.outerHTML = strNewHTML
            i = i-1;
         }
      }
   }    
}
if (window.addEventListener)
	window.addEventListener("onload", correctPNG, false);
else
	window.attachEvent("onload", correctPNG);
/*-------------------------------------------------------------------------------------------------
	Feature Part
-------------------------------------------------------------------------------------------------*/

function doSearchLog(iRandom, sCountry, iCnt, sParam)
{
	var callbackLog = {};
	if(typeof(sParam) == 'undefined') sParam = '';
	var sUrl = dPath + "/"+sCountry+"/job-search-log.php?rnd="+iRandom+"&cnt="+iCnt+"&"+sParam;
	var callbackLog = {};
	//Optional to assign timeout in ms.
	callbackLog.timeout = 8000; 
	//Do request
	var request = YAHOO.util.Connect.asyncRequest('GET', sUrl, callbackLog, null);  
}

function sendFeedBack(sCountry)
{
	var aCountry = new Array();
	//associative array
	aCountry['id'] = 'indonesia';
	aCountry['my'] = 'malaysia';
	
	var aObj = document.getElementsByName('fb[]');
	var bResult = false;
	var iId = "";
	
	for (var i =0; i<aObj.length; i++)
	{
		if(aObj[i].checked == true) iId = aObj[i].value;		
	}
	if(iId == "") 
	{
		alert("Please select one option.");
		return false;
	}	
	//truncate at 1k
	var sMsg = document.feedback.fbmsg.value;
	if (sMsg.length > 1000)
	{
		sMsg = sMsg.substring(0,1000) + '...';
	}
	var iRandom = Math.random();
	var sUrl = dPath + "/"+aCountry[sCountry]+"/feedback.php?fbid="+iId+"&fbmsg="+sMsg+"&country="+sCountry+"&rnd="+iRandom;
	var callbackFb = {};
	callbackFb.success = updFb;
	callbackFb.timeout = 8000; 
	//Do request
	var request = YAHOO.util.Connect.asyncRequest('GET', sUrl, callbackFb, null);   
}

function updFb()
{
	var oFbCon = document.getElementById('fbCon');
	sHtml = "<div class='enter'></div><div>Thank you for your feedback.</div><div class='enter'></div>";
	if(oFbCon != null) oFbCon.innerHTML = sHtml;	
}

/*-------------------------------------------------------------------------------------------------
	Logic Validate Part
-------------------------------------------------------------------------------------------------*/

function ctrlYoe(bMin)
{
	oMin = getEl('experience-min');
	oMax = getEl('experience-max');
	iMin = Number(oMin.value);
	iMax = Number(oMax.value);
	if((iMax< iMin) && iMax != '-1')
	{
		if(bMin == true) oMax.value = '-1';
		else  oMin.value = '-1';
	}	
}

function ctrlMaxSel(oCtrl, sDiv, sLabel, iMax)
{
	bCheck = checkRequiredCb(oCtrl, '0,' + iMax , false);
	if(bCheck == false)
	{
		setObjVisibility(sDiv, 'true'); 
		setDivMsg(sDiv, 'Please select maximum 5 ' + sLabel + ' only.');	
		setDivClass(sDiv, 'errorReg');
		oCtrl.checked = false;
		updateThis(oCtrl, false, true);
	}
	else
	{
		setDivMsg(sDiv, '');
		setObjVisibility(sDiv,'false'); 
	}
}

/*-------------------------------------------------------------------------------------------------
	Common Part
-------------------------------------------------------------------------------------------------*/
//Get Element
function getEl(sId) 
{ 
	return document.getElementById(sId); 
}

function hideEl(sId) 
{ 
	getEl(sId).style.visibility = 'hidden';
	getEl(sId).style.position = 'absolute';
}

function showEl(sId) 
{ 
	getEl(sId).style.visibility = 'visible';
	getEl(sId).style.position = 'static';
}

function hidediv(sName) {
    if (document.getElementById) { // DOM3 = IE5, NS6
	document.getElementById(sName).style.visibility = 'hidden';
	document.getElementById(sName).style.display = 'none';
    } else {
		if (document.layers) { // Netscape 4
			document.layers[sName].visibility = 'hidden';
			document.layers[sName].display = 'none';
		} else { // IE 4
			document.all[sName].style.visibility = 'hidden';
			document.all[sName].style.display = 'none';
		}
    }
}

function showdiv(sName) {
    if (document.getElementById) { // DOM3 = IE5, NS6
	document.getElementById(sName).style.visibility = 'visible';
	document.getElementById(sName).style.display = 'block';
    } else {
	if (document.layers) { // Netscape 4
	    document.layers[sName].visibility = 'visible';
	    document.layers[sName].display = 'block';
	} else { // IE 4
	    document.all[sName].style.visibility = 'visible';
	    document.all[sName].style.display = 'block';
	}
    }
} 

function disableThis(oCtrl)
{
	oCtrl.disabled=true;
}

function enableThis(oCtrl)
{
	oCtrl.disabled=false;
}

function updateInnerHtml(sCtrl, sHtml)
{
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(sCtrl).innerHTML = sHtml;
	} else {
		if (document.layers) { // Netscape 4
			document.layers[sCtrl].innerHTML = sHtml;
		} else { // IE 4
			document.all[sCtrl].innerHTML = sHtml;
		}
	}
}

/*-------------------------------------------------------------------------------------------------
	Criteria
-------------------------------------------------------------------------------------------------*/
function disableAll(field)
{
	field = document.getElementsByName(field);
    for (i = 0; i < field.length; i++) {
		field[i].disabled = true ;	
    }
}

function checkAll(field) {
	field = document.getElementsByName(field);
    for (i = 0; i < field.length; i++) {
	field[i].checked = true ;
	updateThis(field[i], false, true);
    }
}

function uncheckAll(field) {
	field = document.getElementsByName(field);
    for (i = 0; i < field.length; i++) {
	field[i].checked = false ;
	updateThis(field[i], false, true);
	enableThis(field[i]);
    }
}

//Create this function because we mix name for location and oversea but diff handle on UI
//Added a container for determinating rows inside
function checkAllLoc(bLoc, bOvs, sCurLoc, sContainer)
{
	var contained = 0;
	if(typeof(sCurLoc) == 'undefined') sCurLoc = "";
	if (typeof(sContainer) != 'undefined')
	{
		field = YAHOO.util.Dom.getElementsByClassName('', 'input', YAHOO.util.Dom.getElementsByClassName(sContainer)[0]);
		contained = 1;
	} else {
		field = document.getElementsByName('location[]');
	}
    for (i = 0; i < field.length; i++) {
		if (field[i].checked && field[i].disabled) continue;
		iId = field[i].id;
		iId = iId.substring(8);
		sKey = iId.substring(iId.length-4, iId.length); 
		sKey2 = iId.substring(0,3);
		if ( bOvs == 0 && bLoc == 1 && (iId == '90100' || sKey == '0000' || sKey2 == '901') && contained == 0) continue;
		if ( bOvs == 1 && bLoc == 0 && (iId != '90100' && sKey != '0000')) continue;
		if( sCurLoc == iId && bOvs == 1 && bLoc == 0) continue;		
		field[i].checked = true ;		
		updateThis(field[i], false, true);
		toggleCb(field[i]);	
    }	
}

//Create this function because we mix name for location and oversea but diff handle on UI
//Added a container for determinating rows inside
function uncheckAllLoc(bLoc, bOvs, sCurLoc, sContainer)
{
	var contained = 0;
	if(typeof(sCurLoc) == 'undefined') sCurLoc = "";
	if (typeof(sContainer) != 'undefined')
	{
		field = YAHOO.util.Dom.getElementsByClassName('', 'input', YAHOO.util.Dom.getElementsByClassName(sContainer)[0]);
		contained = 1;
	} else {
		field = document.getElementsByName('location[]');
	}
    for (i = 0; i < field.length; i++) {
		if (field[i].checked == false && field[i].disabled == false) continue;
		iId = field[i].id;
		iId = iId.substring(8);
		sKey = iId.substring(iId.length-4, iId.length);
		sKey2 = iId.substring(0,3);
		if ( bOvs == 0 && bLoc == 1 && (iId == '90100' || sKey == '0000' || sKey2 == '901') && contained == 0) continue;
		if ( bOvs == 1 && bLoc == 0 && (iId != '90100' && sKey != '0000' && sKey2 != '901')) continue;
		if( sCurLoc == iId && bOvs == 1 && bLoc == 0) continue;		
		field[i].checked = false ;
		updateThis(field[i], false, true);
		enableThis(field[i]);
		toggleCb(field[i]);
		
		//check short list
		sSL = 'Sl' + field[i].id;
		oSl = getEl(sSL);
		if(oSl != null) enableThis(oSl);
    }	
}

function updateThisScan(sName)
{
	var aCtrl = document.getElementsByName(sName);
	for (var x = 0; x < aCtrl.length; x++) updateThis(aCtrl[x], false, true);		
}

function updateRadioSet(what) {	
	var field = what.name;
	field = document.getElementsByName(field);
	for (i = 0; i < field.length; i++) {
	updateThis(field[i], false, true);
    }
}

function updateThisById(sId, sIdMirror)
{
	oCtrl = getEl(sId);
	if(oCtrl == null) return;
	oCtrl2 = getEl(sIdMirror);
	if(oCtrl2 == null) return;
	oCtrl.checked = oCtrl2.checked;
	updateThis(oCtrl);
}

function updateThis(what, bAvoid, bScan) {
    var selectedClassName = "labelSelected";
    var normalClassName = "labelNormal";

    if( what.checked == true ){what.parentNode.className = selectedClassName;}
	else{what.parentNode.className = normalClassName;}
	
	if(typeof(bAvoid) == 'undefined') bAvoid = false;
	updateThisDesc(what, bAvoid);	

	if(typeof(bScan) == 'undefined') bScan = false;
	if(bScan == false) updateThisDetail(what);	

	//check short list
	sSL = 'Sl' + what.id;
	oSl = getEl(sSL);
	if(oSl != null) oSl.checked = what.checked;
}

function updateThisDesc(what, bAvoid)
{
	if(typeof(bAvoid) == 'undefined') bAvoid = false;
	sName = what.name;
	sName = sName.replace("[]","") + 'Sel';
	//hardcode
	if(sName == 'roleSel') sName = 'specializationSel';
	sDesc = trim(what.alt);
	if(sDesc == '') return;
	
	var oDiv = document.getElementById(sName);
	if(oDiv == null) return;

	sLegend = '<b>Your Selection: </b><br/>';
	
	sHtml = oDiv.innerHTML;
	if(typeof(sHtml) == 'undefined' || sHtml == '') {sHtml = ', ';} 
	else{ sHtml = sHtml.substring(27) ; sHtml = ', ' + sHtml + ', ';}	
	sSearch = ', ' + escapeHTML(sDesc) + ', ';
	if( what.checked == true && bAvoid == false && what.disabled == false)
	{		
		bFound = sHtml.search(sSearch);
		if(bFound == -1) sHtml = sHtml + sDesc + ', ';
	}
	else sHtml = sHtml.replace(sSearch, ', ') ;	 
	if(sHtml.length > 4){ sHtml = sHtml.substring(2, (sHtml.length - 2) ); sHtml = sLegend + sHtml;}
	else {sHtml = '';}
	oDiv.innerHTML = sHtml;
}

//This is customize function
function updateThisDetail(oCtrl)
{	
	if(typeof(updateThisExternal) == 'function') updateThisExternal(oCtrl);
}

/*-------------------------------------------------------------------------------------------------
	Toogle Specialization Role
-------------------------------------------------------------------------------------------------*/
function toggleSpeRole(iSpe, bShow)
{
	sKey = 'optSpeRole' + iSpe;
	sLblKey = 'lblTogSpeRole' + iSpe;
	if(typeof(bShow) == 'undefined')
	{
		var oCtrl = getEl(sKey);
		if(oCtrl.style.display == '' || oCtrl.style.display =='none') bShow = true;
		else  bShow = false;
	}	
	if(bShow)  
	{
		getEl(sLblKey).innerHTML = 'Hide Options';
		showdiv(sKey);		
	}
	else
	{
		getEl(sLblKey).innerHTML = 'More Options';
		hidediv(sKey);		
	}
}



/*-------------------------------------------------------------------------------------------------
	Toogle Check Box Tree - location
-------------------------------------------------------------------------------------------------*/
function toggleCbById(sId)
{
	oCtrl = getEl(sId);
	if(oCtrl == null) return;
	toggleCb(oCtrl);
}

/*Old logic: Using class name. For all same elements (same name)*/
function toggleCb(oCtrl)
{
	sName = oCtrl.name;
	bCheck = oCtrl.checked;
	sStart = oCtrl.parentNode.parentNode.className;	
	bStart = false; 
	var oEl = document.getElementsByName(sName);	
	for (x = 0; x < oEl.length; x++) 
	{		
		if(oEl[x].id == oCtrl.id && bStart == false) { bStart = true; continue; }					
		
		if(bStart == false) continue;

		sParantCls = oEl[x].parentNode.parentNode.className;

		if(sParantCls == "") continue;
		if(sParantCls == sStart && bStart == true) break;		
		if(sParantCls < sStart && bStart == true) break;

		oEl[x].checked = bCheck;
		updateThis(oEl[x], true, true);
		if(bCheck) disableThis(oEl[x]);
		else enableThis(oEl[x]);

		//check short list
		sSL = 'Sl' + oEl[x].id;
		oSl = getEl(sSL);
		if(oSl != null) 
		{
			if(bCheck) disableThis(oSl);
			else enableThis(oSl);	
		}
	}			
}

/*New logic: Store parent id in parent element's id*/
function toggleCbSpe(oCtrl)
{
	sName = 'role[]';
	bCheck = oCtrl.checked;
	iSpe = oCtrl.value;
	var oEl = document.getElementsByName(sName);	
	for (x = 0; x < oEl.length; x++) 
	{		
		sParentSpe = oEl[x].parentNode.parentNode.id;
		sParentSpe = sParentSpe.substring(6);
		if(sParentSpe != iSpe) continue;

		oEl[x].checked = bCheck;
		updateThis(oEl[x], true, true);
		if(bCheck) disableThis(oEl[x]);
		else enableThis(oEl[x]);		
	}			
}

function toggleAllSpe(sId)
{
	oCtrl = document.getElementById(sId);
	if(oCtrl != null) toggleCbSpe(oCtrl);
}

function toggleAllLoc(sId)
{
	oCtrl = document.getElementById(sId);
	if(oCtrl != null) toggleCb(oCtrl);
}

/*-------------------------------------------------------------------------------------------------
	Toogle Quick Search
-------------------------------------------------------------------------------------------------*/
function toggleQs(sName)
{
	var sCtrl = sName + "Con";
	var oCon = document.getElementById(sCtrl);
	if(oCon.style.display == '' || oCon.style.display =='none') showdiv(sCtrl);
	else hidediv(sCtrl);
	updateOptSel(sName);
}

function updateOptSel(sName) 
{	
	var sCtrl = sName + "Sel";
	var sHtml = getCheckBoxSet(sName) ;
	updateInnerHtml(sCtrl, sHtml);
}

function getCheckBoxSet(sName)
{
	var aRes = Array();
	if(sName == 'qsSpe') aRes = getCheckBoxLabel(sName, document.getElementsByName('specialization[]'));
	if(sName == 'qsInd') aRes = getCheckBoxLabel(sName, document.getElementsByName('industry[]'));
	if(sName == 'qsLoc') 
	{ 
		var aRes = getCheckBoxLabel(sName, document.getElementsByName('location[]'));
		aRes = getCheckBoxLabel(sName, document.getElementsByName('country[]'), aRes[0], aRes[1], aRes[2]);		
	}	
	if(typeof(aRes[0]) != 'undefined') return aRes[0];
	return "";
}

function getCheckBoxLabel(sName, elN, sHtml, iCount, iAdd)
{
	var limit = 1;
    var additional = 0;
    var count = 0;
	var STR_FILLER = "";
	var STR_NONE = getDefLabelDesc(sName);
    var STR_ALL = "All";  
	if(typeof(sHtml) == 'undefined' || sHtml == STR_NONE) var sHtml = "";
	if(typeof(iCount) != 'undefined') count = count + iCount;
	if(typeof(iAdd) != 'undefined' && iAdd!=0)
	{
		additional = additional + iAdd;
		sHtml = sHtml.replace(" ... " + additional + " more" , "" );
	}
	limit = limit - count;
	if(limit <= 0) limit = 0;
	
	for(i = 0; i < elN.length; i++){
		if ( elN[i].checked == true && limit > 0) 
		{	    			
			var labels = document.getElementsByTagName('label');
			var mylabel = "";
			for (x = 0; x < labels.length; x++) {
				if(labels[x].htmlFor == elN[i].id) {
					mylabel = labels[x].innerHTML;
				}
			}			
			sHtml += STR_FILLER +"" + mylabel + "";
			limit--;
			count++;
			STR_FILLER = ", ";
		} else if (elN[i].checked == true && limit == 0) {
			additional++;
			count++;
		}
    }

	if (count == 0) sHtml = STR_NONE; 
//	else if (count == elN.length && count != 1) { sHtml = STR_ALL; } 
	else if (limit == 0 && additional > 0) {var ENDSTR = " ... " + additional + " more"; sHtml += ENDSTR ; }
	
	var aRes = Array();
	aRes[0] = sHtml;
	aRes[1] = count;
	aRes[2] = additional;
	return aRes;
}

function getDefLabelDesc(sName)
{
	if(sName == 'qsSpe') return "Select specialization";
	if(sName == 'qsLoc') return "Select location";
	if(sName == 'qsInd') return "Select industry";
	return false;
}





/*-------------------------------------------------------------------------------------------------
	Do advance search
-------------------------------------------------------------------------------------------------*/
function doAdvanceSearch(sUrl)
{
	//Advance search possible param
	var sParam = "";
	sParam = sParam + asGetText('key');
	sParam = sParam + asGetCBList('area');
	sParam = sParam + asGetText('option');
	sParam = sParam + asGetCBList('location', 1);
	sParam = sParam + asGetCBList('industry', 1);
	sParam = sParam + asGetCBList('specialization', 1);
	sParam = sParam + asGetCBList('role', 1);
	sParam = sParam + asGetCBList('position', 1);
	sParam = sParam + asGetCBList('job-type', 1);
	sParam = sParam + asGetCBList('qualification', 1);
	sParam = sParam + asGetCBList('field-of-study', 1);
	sParam = sParam + asGetText('nationality');
	sParam = sParam + asGetText('experience-min');
	sParam = sParam + asGetText('experience-max');
	sParam = sParam + asGetText('salary');	
	sParam = sParam + asGetCBList('classified');
	sParam = sParam + asGetCBList('salary-option');
	sParam = sParam + asGetText('salary-currency');
	sParam = sParam + asGetCBList('job-posted', 1);
	sParam = sParam + asGetHidden('campus');
	sParam = sParam + asGetHidden('src');
	
	if(sParam != "") 
	{
		sParam = sParam.substring(1, sParam.length);		
		sUrl = sUrl + '?' + sParam;
	}
	
	document.location.href = sUrl;	
}

function asGetText(sKey)
{
	oCtrl = getEl(sKey);
	if(oCtrl != null) 
	{
		sVal = trim(oCtrl.value);
		if(sVal != "") return '&' + sKey + '=' + asUrlEncode(sVal);
	}
	return '';
}

function asGetCBList(sKey, bArray)
{
	sCtrl = sKey;
	if(typeof(bArray) !='undefined' && bArray == 1) sCtrl = sCtrl + '[]';
	oCtrl = document.getElementsByName(sCtrl);
	var sParam = '';
    for (i = 0; i < oCtrl.length; i++) {
		if(oCtrl[i].checked  && oCtrl[i].disabled == false)
		{
			sParam = sParam + oCtrl[i].value + ',';
		}	
    }
	if(sParam != '')
	{
		sParam = sParam.substring(0, sParam.length-1);	
		sParam = '&' + sKey + '=' + asUrlEncode(sParam);
	}
	return sParam;
}

function asGetHidden(sKey)
{
	oCtrl = document.getElementsByName(sKey);
	var sParam = '';
    for (i = 0; i < oCtrl.length; i++) {		
		sParam = sParam + oCtrl[i].value;			
    }	
	if(sParam != '')
	{		
		sParam = '&' + sKey + '=' + sParam;
	}
	return sParam;
}

function asUrlEncode(str)
{
	var ret = str;     
	ret = ret.toString();    
	ret = encodeURIComponent(ret);    
	ret = ret.replace(/%20/g, '+');     
	return ret;
	//return escape(str).replace(/\+/g,'%2B').replace(/%20/g, '+').replace(/\*/g, '%2A').replace(/\//g, '%2F').replace(/@/g, '%40');
}

/*-------------------------------------------------------------------------------------------------
	Banner Part - external
-------------------------------------------------------------------------------------------------*/
// The id/name for flash banner
leaderboard_id = "homepage_leaderboard";

// Setup expandable leaderboard
function jobstreet_setup_expleaderboard(file, width, height, expwidth, expheight) {
      if(!expwidth) {
            expwidth = width;
      }
      if(!expheight) {
            expheight = height;
      }
      jobstreet_writeFlash(leaderboard_id, file, expwidth, expheight, "transparent", "");
      jobstreet_shrink_leaderboard();
} 

// Call this from flash banner to expand your ad
function jobstreet_expand_leaderboard() {
      jobstreet_getFlash(leaderboard_id).height = 120;
}

// Call this from flash banner to shrink your ad
function jobstreet_shrink_leaderboard() {
      jobstreet_getFlash(leaderboard_id).height = 60;
}

// Function to get flash id/name
function jobstreet_getFlash(id) {
      if(navigator.appName.indexOf("Microsoft") != -1) {
            return window[id];
      }else {
            return document[id];
      }
}

// Function to write the flash
function jobstreet_writeFlash(id, file, width, height, wmode, params) {
      var flashTag = '';
      flashTag += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ';
      flashTag += 'id="' + id + '" ';
      flashTag += 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#" ';
      flashTag += 'width="' + width + '" ';
      flashTag += 'height="' + height + '">';
      flashTag += '<param name="movie" value="' + file + '"/>';
      flashTag += '<param name="wmode" value="' + wmode + '"/>';
      flashTag += '<param name="quality" value="high"/>';
      flashTag += '<param name="flashvars" value="' + params + '"/>';
      flashTag += '<param name="allowscriptaccess" value="always"/>';
      flashTag += '<embed src="' + file + '"';
      flashTag += ' width="' + width + '"';
      flashTag += ' height="' + height + '"';
      flashTag += ' type="application/x-shockwave-flash"';
      flashTag += ' name="' + id + '"';
      flashTag += ' allowscriptaccess="always"';
      flashTag += ' quality="high"';
      flashTag += ' wmode="' + wmode + '" ';
      flashTag += ' flashvars="' + params + '" ';
      flashTag += ' swliveconnect="true" ';
      flashTag += ' pluginspage="http://www.macromedia.com/go/getflashplayer">';
      flashTag += '</embed>';
      flashTag += '</object>';
      document.write(flashTag);
}
