
window.onerror=function(msg){
$("body").attr("JSError",msg);
}

/*
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.getElementsByName(name);}

/**
 * trim value
 * @param string strToTrim. value to be trim.
 * @return string
 */
function trim(strToTrim)
{
	return strToTrim.replace(/^\s+|\s+$/g,"");
}

function selectAll(obj, ctrl){
	for(i=0;i<ctrl.length;i++)
    {
		if (obj != ctrl[i]) {	//dont disable own control
			if (obj.checked) {
				ctrl[i].checked = true;
				ctrl[i].disabled = true;
			}
			else {
				ctrl[i].checked = false;
				ctrl[i].disabled = false;
			}
		}
    }
}

/**
 * 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')
	{
		obj.style.display = '';
		obj.style.visibility = 'visible';		
	}
	else
	{
		obj.style.display = 'none';
	}
}

function setDivClass(sObj, sCssClass)
{
	var obj = elId(sObj);
	if(obj == null) return;
	obj.className=sCssClass;
}

/**
 * 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, height, width, winId)
{
        sWidth = screen.width || 1024;
        sHeight = screen.height || 600;

        if(typeof(height) == 'undefined') height = sHeight - sHeight * 0.15;
        if(typeof(width) == 'undefined') width = 767;
        if(typeof(winId) == 'undefined') winId = "W958b6e9ea6bed1f9c5288b15959dad77";

        //Detecting user resolution, if above use this.
        if ( sWidth > 1024 )
        {
                width = 967;
        }

        //Center the display
        displayRight = sWidth/2 - width/2;
        displayTop = 30;

        w=window.open(url, winId, "left="+displayRight+",top="+displayTop+",menubar=no,height="+height+",width="+width+",scrollbars=yes,resizable=yes");
        w.focus();
}

function companyPopWin(url, h, w) 
{
	var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
	
	if(typeof(h) == 'undefined') h = 500;
	if(typeof(w) == 'undefined') w = 700;
	
	if (is_chrome)
	{
		w=window.open('about:blank', "", "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, "", "left=150,top=120,menubar=no,height="+h+",width="+w+",scrollbars=yes,resizable=yes");
	}
	w.focus();
}

function setFixedPosition(id,x,y){
    var sty=elId(id).style;
    sty.left=x + 'px';
    sty.top=y + 'px';
} 

function centerDiv(E){
  var A = document.getElementById(E);
  if (IE) {
    C = document.body.clientWidth;
    D = document.body.clientHeight;
  } else {
    C = window.innerWidth;
    D = window.innerHeight;
  }
  //must display block first to have clientWidth and clientHeight
  A.style.display = "block";
  var elementWidth = A.clientWidth;
  var elementHeight = A.clientHeight;
  
  if(D - elementHeight < 0)
	A.style.top = "0px";
  else
	A.style.top = String(Math.round((D-elementHeight)/2))+"px";
  
  if(C - elementWidth < 0)
	A.style.left = "0px";
  else
	A.style.left = String(Math.round((C-elementWidth)/2))+"px";
}

function centerDivQuickSignUp(E){
  var A = document.getElementById(E);
  if (IE) {
    C = document.documentElement.clientWidth;
    D = document.documentElement.clientHeight;
  } else {
    C = window.innerWidth;
    D = window.innerHeight;
  }
  //must display block first to have clientWidth and clientHeight
  A.style.display = "block";
  var elementWidth = A.clientWidth;
  var elementHeight = A.clientHeight;
  A.style.top = String(Math.round(((D-elementHeight)/2)-65))+"px";  
  A.style.left = String(Math.round((C-elementWidth)/2))+"px";
}

//to display a popup that does not pop off the edge of the screen if the link is toward the edge, make sure cross-browser compatible
function setPosition(id,x,y){
    var sty=elId(id).style;
    
    //to get browser's page view screen size
    getScreenAvailHeight = screen.availHeight;
    getScreenAvailWidth = screen.availWidth;
   
    //to get Pop-up window size
    getPopupHeight = elId(id).offsetHeight;
    getPopupWidth = elId(id).offsetWidth;
	
	//Microsoft's DOM (IE, Opera and Konqeuror)
 	if (IE) {
        getScrollTop = document.documentElement.scrollTop;
 		if ((tempAvailY + y + getPopupHeight) > getScreenAvailHeight) {
            topY = tempY - getPopupHeight;
		  	if (topY < getScrollTop) { 
		  	   topY = topY - getScrollTop - 30;
            } 	
	  	} 	else {
	  		topY = tempY + y;
	  	}
        	  	
	} 
	//W3C DOM  (Mozilla, Netscape and Epiphany)
  	else {
        getScrollTop = window.pageYOffset;
  		if 	(tempAvailY + 110 + y + getPopupHeight > getScreenAvailHeight)	{
	  		topY = tempY - getPopupHeight;
	  		if (topY < getScrollTop) {	
	  			topY = topY - getScrollTop - 30; 
            }
	  	}   else {
	  		topY = tempY + y;
	  		
	  	}
	}
	//alert("tempAvailY (mouse) + y + getPopupHeight > getScreenAvailHeight"+"<br/>" + tempAvailY + "+" + y + "+" + getPopupHeight + ">" + getScreenAvailHeight);
  	
  	if (topY < 0) {
		topY = 0 + getScrollTop; 
  	}
  	
  	sty.top = topY + 'px';
  	sty.left = tempX + x + 'px';
}

function getMouseXY(e) 
{	
	if (window.event) 
	{		
		//mouse position within the web page you would simply add the scroll position of the page within the browser window
		if(navigator.platform == "iPad"){ //iPad's Safari compability
			tempX = window.event.clientX + document.documentElement.scrollLeft;
			tempY = window.event.clientY + document.documentElement.scrollTop;
		}
		else{
			tempX = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
			tempY = window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop;
		}
		
		tempAvailX = window.event.screenX;
		tempAvailY = window.event.screenY;
		
    	getScrollTop = document.documentElement.scrollTop;
	} 
	else 
	{
		//event.pageX and event.pageY, using these fields you do not have to add the scroll position of the page
		tempX = e.pageX;
		tempY = e.pageY;
		
		tempAvailX = e.clientX;
		tempAvailY = e.clientY;
		
		getScrollTop = window.pageYOffset;		
	}
	
	if (tempX < 0) { tempX = 0;	}
	if (tempAvailX < 0) { tempAvailX = 0;	}
	if (tempY < 0) { tempY = 0;	}
	if (tempAvailY < 0) { tempAvailY = 0;	}
		
	return true;
}

function closeWin() {
	window.open('','_parent','');
	window.close();
}

function Trim(str) {
	var res = /^\s+/ig;
	var ree = /\s+$/ig;
	var out = str.replace(res,"").replace(ree,"");
    return out;
}

function isIE6OrAbove() 
{ 
	var bver = navigator.appVersion.indexOf("MSIE") 
	if(bver!=-1) { 
		bver=bver+5 
		var vernum = navigator.appVersion.substr(bver,3) 
		if(vernum>6) {
			return true;
		} else {
			return false;
		} 
	} else {
		return true;
	}
 } 

function isBrowser(b,v) {
  /*
  ** Check if the current browser is compatible
  **  b  browser name
  **  v  version number (if 0 don't check version)
  ** returns true if browser equals and version equals or greater
  */
  browserOk = false;
  versionOk = false;

  browserOk = (navigator.appName.indexOf(b) != -1);
  if (v == 0) versionOk = true;
  else  versionOk = (v <= parseInt(navigator.appVersion));
  return browserOk && versionOk;
  }


/**
*
*  UTF-8 data encode / decode
*  http://www.webtoolkit.info/
*
**/
var Url = {

    // public method for url encoding
    encode : function (string) {
		string = escape(this._utf8_encode(string));
		return string.replace(/\+/g, "%2B");        
    },

    // public method for url decoding
    decode : function (string) {
        return this._utf8_decode(unescape(string));
    },

    // private method for UTF-8 encoding
    _utf8_encode : function (string) {
        string = string.replace(/\r\n/g,"\n");
        var utftext = "";

        for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }

        return utftext;
    },

    // private method for UTF-8 decoding
    _utf8_decode : function (utftext) {
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;

        while ( i < utftext.length ) {

            c = utftext.charCodeAt(i);

            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else if((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i+1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
                c2 = utftext.charCodeAt(i+1);
                c3 = utftext.charCodeAt(i+2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }

        }

        return string;
    }

}


/**************************************/
// Description: Expandable ad setup script 
// Version: 1.0
// Last update: Oct 10, 2008
// Sample usage:
//    <script type="text/javascript">
//          jobstreet_setup_expleaderboard("MyLeaderboard.swf", 728, 90, 728, 180);
//    </script>
/**************************************/

// 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);
}

function focus_form_field(id)
{
	var obj;
	if (elId(id)) {obj =elId(id); } else { obj = elName(id);obj=obj[0];}	
	if(obj != null && obj.type != 'hidden' && obj.disabled == false) { obj.focus(); return true; }
	return false;
}


if (self.parent.frames.length != 0) {
	if(document.getElementById('eb').value != '1502')
		self.parent.location = window.document.URL;
}
var IE = document.all?true:false;
if (!IE) {
	if (window.event) document.captureEvents(Event.MOUSEMOVE);
}
//mouse cursor position relative to the top left corner of the web page
var tempX=0;
var tempY=0;
//mouse distance from the left and top of the browser window respectively
var tempAvailX=0;
var tempAvailY=0;

var getScrollTop=0;

