function openPopUp(pUrl,w,h) {	
	var l= getWindowPosition("width")-(w/2);
	var t= getWindowPosition("height")-(h/2);
	window.open(pUrl, 'popUp', 'width='+w+',height='+h+',left='+l+',top='+t+',resizable=yes');
}

function getWindowPosition(dim){
  var myWidth = 0, myHeight = 0;
// a little check cos IE doens't support window innerWidth

  if(typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
 
    theTop = document.documentElement.scrollTop;
    theHeight = window.innerHeight/2;
  
	theLeft = document.documentElement.scrollLeft;
    theWidth  = window.innerWidth/2;
    
    myWidth = theLeft+theWidth;
    myHeight = theTop+theHeight;

  }
  else if( document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight )) {
    //IE 6+ in 'standards compliant mode'
    theTop = document.documentElement.scrollTop;
    theHeight = document.documentElement.clientHeight/2;
  
	theLeft = document.documentElement.scrollLeft;
    theWidth  = document.documentElement.clientWidth/2;
       
    myWidth = theLeft+theWidth;
    myHeight = theHeight+theTop;

  } else if( document.body && (document.body.clientWidth || document.body.clientHeight )) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }

  if(dim == 'width'){
	return myWidth;
  }
  else{
	return myHeight;
  }

}

function changeJobSelection()
{
	//document.location.href =document.getElementById("selectBranch").options[document.getElementById("selectBranch").selectedIndex].value;
	var newid = document.getElementById("findJobCenter").options[document.getElementById("findJobCenter").selectedIndex].value;
	
	var oldlocation = new String(document.location);
	//alert(oldlocation);
	
	var arrayloc = oldlocation.split("?");
	//alert(arrayloc[0]);
	
	var newloc;
	if (newid != ''){
		newloc = arrayloc[0] + "?jobid=" + newid;
	}
	else{
		newloc = arrayloc[0];
	}
	//alert(newloc);
	document.location.href = newloc;
}


// Removes leading whitespaces
function LTrim( value ) {
	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
	
}

// Removes ending whitespaces
function RTrim( value ) {
	
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
	
}

// Removes leading and ending whitespaces
function trim( value ) {
	
	return LTrim(RTrim(value));
	
}


function doSearch()
{

	var query = location.href;
	var urlarray = query.split('?');
	var urlf = urlarray[0];
	
	var txtSearch = document.getElementById("txtPageSearch");
	if (txtSearch != null )
	{
		txtSearchValue = txtSearch.value;
	}
	var searchCategoryValue="";
	var searchSubCategoryValue="";
	if (trim(txtSearchValue)!='')
	{
		query = urlf + "?q=" +txtSearchValue+'&l=1';
		 
		var searchCategory = document.getElementById("searchCategory");
		if (searchCategory != null ) 
		{
			searchCategoryValue = searchCategory.value;
			query+='&categ='+searchCategoryValue;
			
			if (trim(searchCategoryValue) !='0')
			{
				query+='&mc=scCategory=:'+searchCategoryValue;
			}	
		}
		var searchSubCategory = document.getElementById("searchSubCategory");
		if ((searchSubCategory != null)  && (trim(searchSubCategoryValue) !='0'))
		{
			searchSubCategoryValue = searchSubCategory.value;
			query+='&subCateg='+searchSubCategoryValue;
			
			if (trim(searchSubCategoryValue) !='0')
			{
				query+='&mc=scSubCategory=:'+searchSubCategoryValue;
			}
			
		}
	}	
	
	location.href=query;
}

function checkEnter(e,caller) //e is event object passed from function invocation
{

	var characterCode //literal character code will be stored in this variable

	if(e && e.which ||e.which == 0)
	{ //if which property of event object is supported (NN4)
	
		e = e;
		characterCode = e.which; //character code is contained in NN4's which property
	}
	else
	{
		e = event;
		characterCode = e.keyCode //character code is contained in IE's keyCode property
	}

	if(characterCode == 13)//if generated character code is equal to ascii 13 (if enter key)
	{ 
	    if(document.all){
		    e.returnValue=false;
            e.cancel = true;
        }
        else{
         e.preventDefault();
        }
        var obj = document.getElementById(caller);
        if(obj){        
            
            if(obj.click){
		        obj.click();
		    }
		}
		return false;
	}
	else
	{
		return true;
	}
		
}
