// jobsearch.js : client-side support for the jobsearch app.
//<![CDATA[
function WTLog(trackKeys) {
	//dcsMultiTrack - declared in http://media.monster.com/js/wt/"+gDcsId+"_main.js
	if (typeof dcsMultiTrack  != 'undefined') {	
		//var trackKeys = JsViewTracker[key];	
		if (trackKeys && trackKeys.length > 0) {		
			var wtparams = new Array();
			for (var i=0; i<trackKeys.length; i++) {
				var kvp = trackKeys[i];
				if (kvp[0] == 'gDcsId') {
					if (typeof gClickDcsId  != 'undefined') { kvp[1] = gClickDcsId; } //wt global var 
				} 			
				wtparams.push(kvp[0]);
				wtparams.push(kvp[1]);				
			}
			dcsMultiTrack.apply(this, wtparams);
		}	
	}
	else { 
		// alert('dcsMultiTrack function not found');
	}
}
//]]>

// JsConst is a collection of constants
var JsConst = {
QS_PAGENUMBER : "pg",
QS_KEYWORDS   : "q",
QS_JOBTITLE_TROVIX : "tjt",
QS_CITY       : "cnme",
QS_STATEID    : "sid",
QS_ZIP        : "zip",
QS_RADIUS     : "rad",
QS_RADIUS_UNITS     : "rad_units",
QS_SORT       : "sort",
QS_JTO        : "jto",
QS_TIMEPERIOD : "tm",
QS_JOBTYPE    : "jt",
QS_BRD		  : "brd",
QS_SRID		  : "SRID",
QS_LID		  : "lid",
QS_LID_OLD	  : "lid_values",
QS_LNHASH	  : "lnhash",
QS_YE		  : "ye",
QS_CAREERLEVEL : "lv",
QS_EDUCATIONLEVEL : "eid",
QS_SALMIN     : "salmin",
QS_SALMAX     : "salmax",
QS_VIEW       : "vw",
  VIEWBRIEF    : "b",
  VIEWDETAILED : "d",
  VIEWMAP	   : "m",  
QS_MLTDOCID   : "mlt.docid",
QS_MLTFIELD: "mlt.field",
QS_MLT_JOB_TITLE: "mltjt",
QS_COMPANY_NAME : "cn",
QS_CATEGORY_ID	: "fn",
QS_OCCUPATION_ID : "occ",
QS_OCCUPATION_ID_OLD : "fn_values",
QS_INDUSTRY_ID : "indid",
QS_INDUSTRY_ID_OLD : "indid_values",
QS_QUERYTYPE : "qt",
  QUERYTYPE_PHRASE : "phrase",
QS_EXCLUDE_KEYWORDS : "xq",
QS_GREYBOXVIEW : "greyboxview",
    GB_VIEWBRIEF    : "list",
    GB_VIEWDETAILED : "add",
    GB_VIEWMAP	   : "replace",  
QS_AGENTID     : "agentID",
QS_WT_GBVIEW:   "a.svs",
QS_CONTINENT   : "ct",
QS_COUNTRY     : "cy", 
QS_LOCGENRE     : "locgen",
QS_WHERE : "where",
INPUT_CNTNT    : "cntnt",
INPUT_CNTRY    : "cntry",
INPUT_KEYWORDS : "keywords",
INPUT_KEYWORDS_TROVIX : "trovixkeywords",
INPUT_JOBTITLE_TROVIX : "trovixjobtitle",
INPUT_CITY     : "city",
INPUT_STATE    : "state",
INPUT_EUROSTATE: "eurostate",
INPUT_ZIP      : "zip",
INPUT_RADIUS   : "radius",
INPUT_RADIUS_TROVIX : "trovixradius",
INPUT_JTO      : "jto",
INPUT_DEFAULT_RADIUS      : "defaultradius",
INPUT_DEFAULT_RADIUS_TROVIX      : "trovixdefaultradius",
INPUT_RADIUS_UNITS      : "radiusunits",
INPUT_RADIUS_UNITS_TROVIX      : "trovixradiusunits",
INPUT_COMPANY_NAME : "company",

INPUT_CATEGORIES : "categories",
INPUT_OCCUPATIONS : "occupations",
INPUT_LOCATIONS : "locations",
INPUT_LOCATION_CNTNT : "locationcontinent",
INPUT_LOCATION_INTNL : "locationintnl",
INPUT_INDUSTRIES : "industries",
INPUT_SELECTED_SEARCH_TAB : "selectedsearchtabforsearch",
INPUT_JOBTYPES : "jobtypes",
INPUT_EXACT_PHRASE : "exactphrase",
INPUT_EXCLUDE_KEYWORDS : "excludekeywords",
INPUT_UPDATE_AGENTID : "updateagentid",
INPUT_NATIONWIDELID      : "joblocations",
INPUT_NATIONWIDELID_TROVIX      : "trovixjoblocations",
INPUT_INTERNSHIPS: "internships",
INPUT_WIRED65MONSJOBS: "wiredmonsjobs",
INPUT_PATHWAYSMONSJOBS: "pathwaysmonsjobs",
INPUT_JOBCORPSMONSJOBS: "jobcorpsmonsjobs",
INPUT_JOBCATEGORIES_OCCUPATIONS: "categoriesoccupations",
INPUT_WHERE: "where",
INPUT_WHERE_TROVIX: "trovixwhere",

z:0};

//simple view obj to store view value & reId
function JsView (view, reId) {
	this.Value = view;
	this.ReId = reId;
}

//hashtable of existing views
var JsViewManager = new Array();
JsViewManager[JsConst.VIEWBRIEF] = new JsView(JsConst.VIEWBRIEF, 10);
JsViewManager[JsConst.VIEWDETAILED]  = new JsView(JsConst.VIEWDETAILED, 9);
JsViewManager[JsConst.VIEWMAP] = new JsView(JsConst.VIEWMAP, 144);

// JsUtil is a collection of helper functions.
var JsUtil = {

// helper function 
GetEl : function( id ) {
   return document.getElementById( id );
   // todo: add document.layers and document.all crap for old browsers...
},

// URI encoding.
EncodeQueryValue : function(s) {
	if(encodeURIComponent){	return encodeURIComponent(s); }
	if(escape){return escape(s);}
	return s;
},
// uri decoding
DecodeQueryValue : function(s) {
	// strange, but neither of these functions will decode '+' to ' ',
	// so we need to do this now...
	var s2 = s.replace(/\+/g,' ');
	if (decodeURIComponent) {	
		try {
			return decodeURIComponent(s2)
		}
		catch (e) {
			if (e instanceof URIError) {
				//assume iso-8859-1 url encoding. This can occur for EUR channels
				//which send querystrings w/non-standard ASCII chars (i.e. O-umlaut)
				//encoded via iso-8859-1 from www homepage. 
				//decodeURIComponent requires UTF-8 encoding. 
				//unescape (deprecated) can decode iso-8859-1 encoded chars.
				return decodeURIComponent(unescape(s2));
			}
			else { throw e; }
		}		
	}
	if(unescape){return unescape(s2);}
	return s2;
},


// Show and Hide.
ShowElem : function( e, displayStyle ) {
	var elem = e;
	var display = displayStyle || '';
	
	if ( typeof e === 'string' ) {
		elem = JsUtil.GetEl(e);
	}
	if ( elem ) {
		elem.style.display=display;
		elem.style.visibility='visible';
	}
},

HideElem : function( e, useVisibility ) {
	var elem = e;
	if ( typeof e === 'string' ) {
		elem = JsUtil.GetEl(e);
	}
	if ( elem ) {
		if ( useVisibility ) elem.style.visibility = 'hidden';
		else elem.style.display='none';
	}
},

//returns an array of elements that match className
GetElementsByClassName : function (className, tag, elm){
	var elm = elm || document;
	if ( typeof elm === 'string' ) {
		elm = JsUtil.GetEl(elm);
	}

	var testClass = new RegExp("(^|\\\\s)" + className + "(\\\\s|$)");
	var tag = tag || "*";
	var elements = (tag == "*" && elm.all)? elm.all : elm.getElementsByTagName(tag);
	var returnElements = [];
	var current;
	var length = elements.length;
	for(var i=0; i < length; i++){
		current = elements[i];
		if(testClass.test(current.className)){
			returnElements.push(current);
		}
	}
	return returnElements;
},

AddToList : function( commaList, s ) {
	if ( commaList.length===0 )
		return s;
	// split
	var arItems = commaList.split(',');
	var arNew = [];
	for ( var i in arItems ) {
		if ( arItems[i]===s ) {
			// found the item in the list
			return commaList; // return unchanged
		}
		arNew.push(arItems[i]); // copy items
	}
	arNew.push(s); // new item
	return arNew.join(',');
},

RemoveFromList : function( commaList, s ) {
	// split
	var arItems = commaList.split(',');
	var arNew = [];
	for ( var i in arItems ) {
		if ( arItems[i]===s ) {
			// found the item in the list
			continue; // skip
		}
		arNew.push(arItems[i]); // copy items
	}
	return arNew.join(',');
},

// Get the element's value.  Currently works for text boxes (easy) and dropdowns (not so easy).
GetElementValue : function( elem ) {
	// elem may be a SELECT element,
	if ( elem.nodeName=="SELECT" ) {
		for ( var i=0; i<elem.childNodes.length; i++ ) {
			var nOption = elem.childNodes[i]; 
			if ( nOption.nodeName != "OPTION" ) {continue;}
			// nOption.value is the 'value' attribute
			// nOption.childNodes[0].nodeValue is the inner text
			// nOption.selected is a boolean 
			if ( nOption.selected ) {
				return nOption.value;
			}
		}
		// nothing was selected
		return "";
	} else if (elem.type == "checkbox") {
	    return elem.checked;
	} else if ( elem.nodeName == "A" ) {
	    return elem.name;
	} else {
		// assume its a simple text box
		return elem.value; 
	}
},

// amarculescu: Get the object's value.  Currently works for DropDownCheckBoxList objects
GetObjectValue : function( obj ) {
	if (obj.constructor.toString().match(/function\sDropDownCheckBoxList/)) {
		// the selection the selection is cached in the embedded TwoTierCheckBoxList, so
		// just reset the cache before retrieving the current selection
		obj.checkBoxList.selection = null;
		
		var checkBoxListSelection = obj.checkBoxList.getSelection();
		var arrCategoryIds = new Array();

		// build an array containing the selected values
		if (checkBoxListSelection.itemCount > 0) {
			// first loop over the first level items
			for (var i = 0; i < checkBoxListSelection.items.length; i++) {
				arrCategoryIds.push(checkBoxListSelection.items[i].value);
			}
			
			// loop over the selected folders, if any
			for (var i = 0; i < checkBoxListSelection.folders.length; i++) {
				var folder = checkBoxListSelection.folders[i];
				for (var j = 0; j < folder.items.length; j++) {
					arrCategoryIds.push(folder.items[j].value);
				}
			}
		}

		return arrCategoryIds;
	}
},
IsControlLoaded : function() {

   var selectedTab = null;
   var SELECTED_CITY = '1';
   var SELECTED_ZIP = '2';
   var SELECTED_LOCATIONS = '3';
   var SELECTED_INTERNTNL = '5';

	//If selectedTab == null, assumes channel is not using client-side
	//toggling of location views
	if (JsMain.Inputs[JsConst.INPUT_SELECTED_SEARCH_TAB] != null) 
	{
		selectedTab = JsUtil.GetElementValue(JsMain.Inputs[JsConst.INPUT_SELECTED_SEARCH_TAB]);
	}
	
	if(selectedTab ==SELECTED_CITY)
	{
		if(JsMain.Inputs[JsConst.INPUT_CITY] == null)
		   return false;
	}
	else if(selectedTab==SELECTED_LOCATIONS)
   	{
		if(JsMain.Inputs[JsConst.INPUT_LOCATIONS] == null)
	      return false;
	}
	else if(selectedTab==SELECTED_ZIP)
   	{
		if(JsMain.Inputs[JsConst.INPUT_ZIP] == null )
		   return false;
	}
	else if(selectedTab==SELECTED_INTERNTNL)
	{
		if(JsMain.Inputs[JsConst.INPUT_LOCATION_INTNL] == null )
		  return false;
		  
	}
	if(JsMain.Inputs[JsConst.INPUT_KEYWORDS] !== "undefined" && selectedTab !=null) 
	{
	   return true;
	}
	if(selectedTab==null)
    {
	   return false;
	}
	
	return true;

},


// remove spaces from left and right
Trim : function( s ) {
	var s2 = s;
	while ( s2.charAt(0)==' ' )
		s2 = s2.substring(1);
	while ( s2.charAt(s2.length-1)==' ' )
		s2 = s2.substring(0,s2.length-1);
	return s2;
},

z:0
};

// MultiMap is a multi-valued map, used to hold query string values.
function MultiMap()
{
	this._map = {};
}

MultiMap.prototype.Clear = function( k ) {
	var key = k.toLowerCase();
	if ( key in this._map ) {
		this._map[key] = []; // empty array
	}
};

MultiMap.prototype.ClearAll = function () {
    this._map = [];
};

MultiMap.prototype.Set = function( k, v ) {
	var key = k.toLowerCase();
	this._map[key] = [ v ]; // array of length 1
};

MultiMap.prototype.SetMulti = function( k, vv ) {
	var key = k.toLowerCase();
	this._map[key] = vv; // vv is an array object
};


MultiMap.prototype.Add = function( k, v ) {
	var key = k.toLowerCase();
	if ( ! ( key in this._map ) ) {
		this._map[key] = []; // empty array
	}
	// Make sure value is not already in array, don't want dupe key value pairs
	for ( var i in this._map[key])
	{
		if ( this._map[key][i] === v )
		{ 
			//alert("found: " + v);
			return;
		}
	}
//	alert("not found: " + v);
	this._map[key].push(v); // might be empty string, but not null
};

// Convert a query string into a name value mapping.  
MultiMap.prototype.QueryStringUnserialize = function( queryString ) {
	// split on &
	var nvarr = queryString.split('&');
	for ( var i in nvarr ) {
		nv = nvarr[i]; // "a=b"
		nvsplit = nv.split('=');
		if ((nvsplit[0].toLowerCase()!='fedemp') && (nvsplit[0].toLowerCase()!='fedpub')){
		       	var k = nvsplit.length>0 ? nvsplit[0].toLowerCase() : null;
		}
		else{
		    var k = nvsplit.length>0 ? nvsplit[0] : null;
		}
		
		var v = nvsplit.length>1 ? nvsplit[1] : "";
		v = JsUtil.DecodeQueryValue( v );
		if ( k !== null ) {
			if ( ! ( k in this._map ) ) {
				this._map[k] = []; // empty array
			}
			this._map[k].push(v); // might be empty string, but not null
		}
	}
};

// Convert the name-value-mapping to a query string.
MultiMap.prototype.QueryStringSerialize = function () {
    var qs = "";
    var anchor = "";
    var foundAnchor = false;
    for (var n in this._map) {
        var valueArray = this._map[n];
        for (var i in valueArray) {
            if (qs.length > 0) {
                qs += "&";
            }
     
            if (foundAnchor !== true &&  valueArray[i] !=null && isNaN(valueArray[i]) ) {
                anchor = valueArray[i].split('#')[1];
                if (anchor !== undefined) {
                    foundAnchor = true;
                    anchor = "#" + anchor;
                }
            }

            /* don't remove #, user could try to find "C#" or so, the url is encoded later.
            if (anchor !== undefined) {
                if (isNaN(valueArray[i])) {
                    valueArray[i] = valueArray[i].replace(anchor, '');
                }
            }
            */

            value = JsUtil.EncodeQueryValue(valueArray[i]);
            qs += n;
            qs += "=";
            qs += value;
        }
    }
    if (anchor !== undefined) {
        qs = qs + anchor;
    }
    return qs;
};



// JsMain is the main logic for the page.
var JsMain = {


// finds the form tag, and adds a special onsubmit handler to it.
// NOTE: this could break if the page template is changed.
SearchOnSubmit : function() {
	var startNode = document.body;
	var formNode = null;
	for ( var i=0; i<startNode.childNodes.length; i++ ) {
		var cn = startNode.childNodes[i];
		if ( cn.nodeName && cn.nodeName=="FORM" ){
			formNode = cn;
			break;
		}
	}
	if ( formNode !== null ) {
		//alert('found form');
		formNode.onsubmit = function(){_jsevt(['search']);return false;};
	}
},

View : null, 

REValue : null,

IsSaveSearch : false,

// queryMap: the query string in MultiMap form
GotoPage : function( queryMap ) {
	
	//clear the Greybox view mode if not registered & always the wt tag
	queryMap.Clear(JsConst.QS_GREYBOXVIEW);
	queryMap.Clear(JsConst.QS_WT_GBVIEW);	

	if(JsMain.IsSaveSearch)   
	{	    
	    queryMap.Set( JsConst.QS_GREYBOXVIEW, 'Add' );
	    
	    if ( typeof JsMain.Inputs[JsConst.INPUT_UPDATE_AGENTID] !== "undefined" ) {
		    var agentID = JsUtil.Trim( JsUtil.GetElementValue( JsMain.Inputs[JsConst.INPUT_UPDATE_AGENTID] ) );
		    if(agentID && agentID.length>0) queryMap.Set( JsConst.QS_AGENTID, agentID ); 
	    }

	    WTLog( new Array(['DCS.dcsuri', 'Search_SaveSearch.lyr']) );
	}

	if (this.View == null && queryMap._map[JsConst.QS_VIEW] && queryMap._map[JsConst.QS_VIEW] != "") {
		//if view null, but exists in qs, set view to/existing qs value			
		JsMain.SetView(queryMap._map[JsConst.QS_VIEW]);
	}

	//set view to queryMap
	if (this.View != null) {
		if (queryMap._map[JsConst.QS_VIEW]) {
			queryMap.Set(JsConst.QS_VIEW, this.View.Value);	
		}
		else {
			queryMap.Add(JsConst.QS_VIEW, this.View.Value);	
		}		
	}
	else { queryMap.Clear(JsConst.QS_VIEW);	}

	// set re value here
	if ( this.REValue != null ) {
		queryMap.Set( "re", this.REValue );
	} else {
		queryMap.Clear( "re" );
	}
	var page = JsMain.CurrentPage()
	var url = page + "?" + queryMap.QueryStringSerialize();
	window.location.href = url;
},

// return the current url, without the query string
CurrentPage : function() {
	// get the current page url
	var currentPage;
	var currentUrl = window.location.href;
	// find the query string part and split there
	var currentSplit = currentUrl.split('?');
	// If we are in SEO mode, then force any refinements to the /Search.aspx page to allow the user to avoid
	// the SEO controller module.
	if (typeof SEO_JOB_SEARCH_PARAMS == "string")
	{
		// split out the path elements and rebuild the path with /Search.aspx as the target page
		var pathSplit = currentSplit[0].split('/');
		currentPage = pathSplit[0]+'//'+pathSplit[2]+'/Search.aspx';
	}
	else
	{
		// Otherwise we just use the current page definition
		currentPage = currentSplit[0];
	}
	return currentPage;
},

// Return the current query string as a MultiMap
CurrentQueryString : function() {
    var mm = new MultiMap();
	var queryParams = "";
	// get the current page url
	var currentUrl = window.location.href;
	// find the query string part
	var currentSplit = currentUrl.split('?');
	if ( currentSplit.length > 1 ){ queryParams = currentSplit[1]; }
    // Append SEO_JOB_SEARCH_PARAMS, if it is defined
    if (typeof SEO_JOB_SEARCH_PARAMS == "string") { queryParams += ((queryParams.length == 0 ? '' : '&') + SEO_JOB_SEARCH_PARAMS); }
	if ( queryParams.length != 0 )
	{
		mm.QueryStringUnserialize( queryParams );
	}
	return mm; // might be empty
},

DoSearch : function() {
	// get the current query ( a MultiMap )
	
	var curQuery = JsMain.CurrentQueryString();
   
	// start on page 1 always
	curQuery.Set( JsConst.QS_PAGENUMBER, 1 );	
	// we'll sort by rel if keywords or cityname is present
	//var bSortByRel = false;
	// get the keywords
	//var bKw = false;
	 
	if ( typeof JsMain.Inputs[JsConst.INPUT_KEYWORDS] !== "undefined" ) {
		var kw = JsUtil.Trim( JsUtil.GetElementValue( JsMain.Inputs[JsConst.INPUT_KEYWORDS] ) );
		var prompt = JsUtil.Trim(JsMain.GetPrompt(JsConst.INPUT_KEYWORDS));
		if ( kw.length > 0 && kw != prompt ) {
			curQuery.Set( JsConst.QS_KEYWORDS, kw ); 
			//bSortByRel = true;
			//bKw = true;
			 
			// check JTO if any
			if ( typeof JsMain.Inputs[JsConst.INPUT_JTO] !== "undefined" ) {
		        var jto = JsUtil.GetElementValue( JsMain.Inputs[JsConst.INPUT_JTO] );
		        if ( jto ) {
			        curQuery.Set( JsConst.QS_JTO, "1" );
		        }
		        else
			        curQuery.Clear(JsConst.QS_JTO);
			}
			 
			// check Exact Phrase if any
			if ( typeof JsMain.Inputs[JsConst.INPUT_EXACT_PHRASE] !== "undefined" ) {
		        var thisPhrase = JsUtil.GetElementValue( JsMain.Inputs[JsConst.INPUT_EXACT_PHRASE] );
		        if ( thisPhrase ) {
			        curQuery.Set( JsConst.QS_QUERYTYPE, JsConst.QUERYTYPE_PHRASE );
		        }
		        else
			        curQuery.Clear(JsConst.QS_QUERYTYPE);
	        }
		} else {
		      
			curQuery.Clear(JsConst.QS_KEYWORDS);
		}
			
	} else {
		//alert('no keywords control!');
	}
	
	// Handle Exclude keywords
	if ( typeof JsMain.Inputs[JsConst.INPUT_EXCLUDE_KEYWORDS] !== "undefined" ) {
		var xkw = JsUtil.Trim( JsUtil.GetElementValue( JsMain.Inputs[JsConst.INPUT_EXCLUDE_KEYWORDS] ) );
		var prompt = JsUtil.Trim(JsMain.GetPrompt(JsConst.INPUT_EXCLUDE_KEYWORDS));
		if ( xkw.length > 0 && xkw != prompt ) {
			curQuery.Set( JsConst.QS_EXCLUDE_KEYWORDS, xkw ); 
		} else {
			curQuery.Clear(JsConst.QS_EXCLUDE_KEYWORDS);
		}
    }

	// amarculescu: Get any category data
	if ( typeof JsMain.Inputs[JsConst.INPUT_CATEGORIES] !== "undefined") {
		var categoryIds = JsUtil.GetObjectValue(JsMain.Inputs[JsConst.INPUT_CATEGORIES]);
		
		if (categoryIds.length > 0) {
			// clear the occ values if the user refines by category
			curQuery.Clear(JsConst.QS_OCCUPATION_ID);
			// add a multi entry containing the array			
			curQuery.SetMulti(JsConst.QS_CATEGORY_ID, categoryIds);
		}
		else {
			curQuery.Clear(JsConst.QS_CATEGORY_ID);
		}
		// clear the "fn_values" parameter, we only support it for the initial loading of the page
		// the first time the user refines the search, it is converted into "fn"
		curQuery.Clear(JsConst.QS_OCCUPATION_ID_OLD);
	}
	
	// amarculescu: Get any occupation data
	if ( typeof JsMain.Inputs[JsConst.INPUT_OCCUPATIONS] !== "undefined") {
		var occupationIds = JsUtil.GetObjectValue(JsMain.Inputs[JsConst.INPUT_OCCUPATIONS]);
		
		if (occupationIds.length > 0) {
			// clear the fn values if the user refines by occupation
			curQuery.Clear(JsConst.QS_CATEGORY_ID);
			// add a multi entry containing the array			
			curQuery.SetMulti(JsConst.QS_OCCUPATION_ID, occupationIds);
		}
		else {
			curQuery.Clear(JsConst.QS_OCCUPATION_ID);
		}
		// clear the "fn_values" parameter, we only support it for the initial loading of the page
		// the first time the user refines the search, it is converted into "occ"
		curQuery.Clear(JsConst.QS_OCCUPATION_ID_OLD);
	}
	
	// amarculescu: Get any industry data
	if ( typeof JsMain.Inputs[JsConst.INPUT_INDUSTRIES] !== "undefined") {
		var industryIds = JsUtil.GetObjectValue(JsMain.Inputs[JsConst.INPUT_INDUSTRIES]);
		
		if (industryIds.length > 0) {
			// add a multi entry containing the array			
			curQuery.SetMulti(JsConst.QS_INDUSTRY_ID, industryIds);
		}
		else {
			curQuery.Clear(JsConst.QS_INDUSTRY_ID);
		}
		// clear the "indid_values" parameter, we only support it for the initial loading of the page
		// the first time the user refines the search, it is converted into "indid"
		curQuery.Clear(JsConst.QS_INDUSTRY_ID_OLD);
	}
				
	if ( typeof JsMain.Inputs[JsConst.INPUT_JOBTYPES] !== "undefined") {
		var jobTypes = JsUtil.GetObjectValue(JsMain.Inputs[JsConst.INPUT_JOBTYPES]);
		
		if (jobTypes.length > 0) {
			// add a multi entry containing the array			
			curQuery.SetMulti(JsConst.QS_JOBTYPE, jobTypes);
		}
		else {
			curQuery.Clear(JsConst.QS_JOBTYPE);
		}
		// may need to handle/clear the "job_status" parameter???
		//curQuery.Clear(JsConst.QS_INDUSTRY_ID_OLD);
	}
				
	var bZip = false;
	var bCity = false;
	var bState = false;
	var bCountry = false;
	var bContinent = false;
	var bLidSelected = false;
	
	var bLocationCriteriaSet = false;
	var selectedTab = null;
	var SELECTED_CITY = '1';
	var SELECTED_ZIP = '2';
	var SELECTED_LOCATIONS = '3';
	var SELECTED_CONTINENT = '4';
	var SELECTED_INTERNTNL = '5';

	//If selectedTab == null, assumes channel is not using client-side
	//toggling of location views
	if (JsMain.Inputs[JsConst.INPUT_SELECTED_SEARCH_TAB] != null) 
	{
		selectedTab = JsUtil.GetElementValue(JsMain.Inputs[JsConst.INPUT_SELECTED_SEARCH_TAB]);
	}
	
	//Order of precedence for setting location search criteria: location, zip, city/stateINPUT_LOCATION_CNTNT : "locationcontinent",
    var locationWidgetValues = null;
    if( (JsMain.Inputs[JsConst.INPUT_LOCATIONS] != null || JsMain.Inputs[JsConst.INPUT_LOCATION_CNTNT] != null || JsMain.Inputs[JsConst.INPUT_LOCATION_INTNL] != null) 
    && (selectedTab == SELECTED_LOCATIONS || selectedTab == SELECTED_CONTINENT || selectedTab == SELECTED_INTERNTNL || selectedTab == null))
	{
	    if(selectedTab == SELECTED_LOCATIONS || selectedTab == null)
	    {
	        if(JsMain.Inputs[JsConst.INPUT_LOCATIONS] != null )
	        {
		        locationWidgetValues = JsUtil.GetObjectValue(JsMain.Inputs[JsConst.INPUT_LOCATIONS]);
		        bCountry = true;
			    curQuery.Set(JsConst.QS_COUNTRY, JsUtil.GetElementValue(JsMain.Inputs[JsConst.INPUT_CNTRY]));
	        }
	    }
	    else if(selectedTab == SELECTED_CONTINENT )
	    {
	        if(JsMain.Inputs[JsConst.INPUT_LOCATION_CNTNT] != null)
	        {	        
		        locationWidgetValues = JsUtil.GetObjectValue(JsMain.Inputs[JsConst.INPUT_LOCATION_CNTNT]);
		        bContinent = true;
   			    curQuery.Set(JsConst.QS_CONTINENT, JsUtil.GetElementValue(JsMain.Inputs[JsConst.INPUT_CNTNT]));
            }
        }
	    else if(selectedTab == SELECTED_INTERNTNL )
	    {    
	        if(JsMain.Inputs[JsConst.INPUT_LOCATION_INTNL] != null )
	        {
  		        locationWidgetValues = JsUtil.GetObjectValue(JsMain.Inputs[JsConst.INPUT_LOCATION_INTNL]);
		        bContinent = true;
			    curQuery.Set(JsConst.QS_CONTINENT, "AF,AS,AU,CA,EU,ME,NA,SA");
	        }
	    }
		// cope with hardcoded locations for UK channels
		// hash that prevents us from duplicate IDs when a single location is mapped to multiple IDs
		var locationIDs = new Array();
		// array that enables us to tell to the Search page which hardcoded location have been selected
		// Note: this is necessary for refinements of locations mapped to multiple IDs, because these
		// locations cannot be infered from the lid query string parameter.
		var locationNameHashes = new Array();
		
		    for (var i = 0; i < locationWidgetValues.length; i++) {
			    var itemValue = locationWidgetValues[i];
    			
			    if (itemValue.indexOf(';') < 0) {
				    // this is a standard location id
				    // to make the array items unique, check for a previous entry
				    if(locationIDs[itemValue] == null)
				    {
				        locationIDs[itemValue] = itemValue;
				    }
			    }
			    else {
				    // this is a location mapped to several location IDs, we need to parse it
				    var hashLength = itemValue.indexOf('_');

				    var locationNameHash = itemValue.substring(0, hashLength);
				    // and the multiple coma separated IDs
				    var strLocationIDs = itemValue.substring(hashLength + 1);
    				
				    // first collect the multiple ids
				    var singleLocationIDs = strLocationIDs.split(';');
				    for (var j = 0; j < singleLocationIDs.length; j++) 
				    {
					    var singleLocationID = singleLocationIDs[j];
					    if(locationIDs[singleLocationID] == null)
					    {
					        locationIDs[singleLocationID] = singleLocationID;
					    }
				    }

				    // now record the originating location name
				    // also prevent duplicating
				    if(locationNameHashes[locationNameHash] == null)
				    {
				        locationNameHashes.push(locationNameHash);
				    }
			    }
			}
		
		
		// Convert the locationIDs hash to an index based array that can be used in curQuery.SetMulti
		var locationIDsValues = new Array();
		for (var key in locationIDs) {
			locationIDsValues.push(locationIDs[key]);
		}
		
		if (locationIDsValues.length > 0) {
			// add a multi entry containing the array	
			curQuery.SetMulti(JsConst.QS_LID, locationIDsValues);
			bLidSelected = true;
			bLocationCriteriaSet = true;
		}
		else {
			curQuery.Clear(JsConst.QS_LID);
		}
		// clear the "lid_values" parameter, we only support it for the initial loading of the page
		// the first time the user refines the search, it is converted into "lid"
		curQuery.Clear(JsConst.QS_LID_OLD);
		
		// HACK for the channels using hardcoded values with multiple IDs
		// pass the location name hashes to the QS, if any, so that the Search page can perform the refinement
		if (locationNameHashes.length > 0) {
			curQuery.SetMulti(JsConst.QS_LNHASH, locationNameHashes);
		}
		else {
			curQuery.Clear(JsConst.QS_LNHASH);
		}
	}
	//If location not found, get zip
	if(! bLocationCriteriaSet && JsMain.Inputs[JsConst.INPUT_ZIP] != null && (selectedTab == SELECTED_ZIP || selectedTab == null))
	{
	   	// get the zip
		//JPF March '07 Ticket  DEV001768778
		var z = "";
		// Make sure zip is visible before using its value
		if ( JsMain.IsVisible(JsMain.Inputs[JsConst.INPUT_ZIP]) ) {
			z = JsUtil.Trim( JsUtil.GetElementValue( JsMain.Inputs[JsConst.INPUT_ZIP] ) );
		}		
		if ( z.length > 0 && z != JsUtil.Trim(JsMain.GetPrompt(JsConst.INPUT_ZIP))  ) 
		{
			curQuery.Set( JsConst.QS_ZIP, z ); 
			bZip = true;
			bLocationCriteriaSet = true;
		}
		else
		{
		  	curQuery.Clear(JsConst.QS_ZIP);
		
		}
	}
			
	//If location or zip not found, get city/state	
	if (! bLocationCriteriaSet && (selectedTab == SELECTED_CITY || selectedTab == null))
	{
		// get the cityname
		if(JsMain.Inputs[JsConst.INPUT_CITY] != null )
		{
			var c = "";
			// Make sure cityname is visible before using its value
			if ( JsMain.IsVisible(JsMain.Inputs[JsConst.INPUT_CITY]) ) {
				c = JsUtil.Trim( JsUtil.GetElementValue( JsMain.Inputs[JsConst.INPUT_CITY] ) );
			}
			var prompt = JsUtil.Trim(JsMain.GetPrompt(JsConst.INPUT_CITY));
			if ( c.length > 0 && c != prompt ) {
				curQuery.Set( JsConst.QS_CITY, c );
				//bSortByRel = true;
				bCity = true;
				bLocationCriteriaSet = true;
			} else {
				curQuery.Clear(JsConst.QS_CITY);
				
			}
		}			
		
		// get the stateID
		if( typeof JsMain.Inputs[JsConst.INPUT_STATE] !== "undefined")
		{
		    var sid = 0;
			// Make sure stateID is visible before using its value
			if ( JsMain.IsVisible(JsMain.Inputs[JsConst.INPUT_STATE]) ) {
				sid = JsUtil.GetElementValue( JsMain.Inputs[JsConst.INPUT_STATE] );
			}
			if ( (sid-0) > 0 ) {
				curQuery.Set( JsConst.QS_STATEID, sid );
				bState = true;
				bLocationCriteriaSet = true;
			}
			else
			{
				curQuery.Clear(JsConst.QS_STATEID);
			}
		}
		if( typeof JsMain.Inputs[JsConst.INPUT_EUROSTATE] !== "undefined")
		{ 
		   	var sid = 0;
		
			
		
			if ( JsMain.Inputs[JsConst.INPUT_EUROSTATE]!== null ) {
			    sid = JsUtil.GetObjectValue( JsMain.Inputs[JsConst.INPUT_EUROSTATE] );
			
				 
			}
			if ( (sid-0) > 0 ) {
				curQuery.Set( JsConst.QS_STATEID, sid );
				bState = true;
				bLocationCriteriaSet = true;
			}
			else
			{
				curQuery.Clear(JsConst.QS_STATEID);
			
			}
	    }
		

	}	
	
	// here we clear current query, because it contains data from previous request
	if(!bZip)
	{
		curQuery.Clear(JsConst.QS_ZIP);
	}
	
	if(!bCity)
	{
		curQuery.Clear(JsConst.QS_CITY);
	}
	if(!bState)
	{
		curQuery.Clear(JsConst.QS_STATEID);
	}
	
	if(!bLidSelected)
	{
		curQuery.Clear(JsConst.QS_LID);
	}
	if(!bCountry)
	{
		curQuery.Clear(JsConst.QS_COUNTRY);
	}

	if(!bContinent)
	{
		curQuery.Clear(JsConst.QS_CONTINENT);
	}
	
	if(bState || bCity || bZip)
	{
	    curQuery.Clear(JsConst.QS_LOCGENRE);
	}
	
	
	//Find Radius Drop Down Control and make sure it is visible before using its value
	var bRadius=false;    
	if ( typeof JsMain.Inputs[JsConst.INPUT_RADIUS] !== "undefined" && 
		JsMain.Inputs[JsConst.INPUT_RADIUS].style.display !== "none" && (bCity||bZip) )
	{
		var r = JsUtil.GetElementValue( JsMain.Inputs[JsConst.INPUT_RADIUS] );
		// be sure radius was selected
		if ( r<1 ) r = JsUtil.GetElementValue( JsMain.Inputs[JsConst.INPUT_DEFAULT_RADIUS] );
		curQuery.Set( JsConst.QS_RADIUS, r );
		var ru = JsUtil.GetElementValue( JsMain.Inputs[JsConst.INPUT_RADIUS_UNITS] );
		if (ru != null & ru.length > 0) curQuery.Set(JsConst.QS_RADIUS_UNITS, ru);
		bRadius = true;
	}
	else 
	{
		//alert('No Radius Drop Down Found;\')
		curQuery.Clear(JsConst.QS_RADIUS);
	}

	// Get the company name
	if ( typeof JsMain.Inputs[JsConst.INPUT_COMPANY_NAME] !== "undefined" ) {
		var coName = JsUtil.Trim( JsUtil.GetElementValue( JsMain.Inputs[JsConst.INPUT_COMPANY_NAME] ) );
		var prompt = JsUtil.Trim(JsMain.GetPrompt(JsConst.INPUT_COMPANY_NAME));
		if ( coName.length > 0 && coName != prompt ) {
			curQuery.Set( JsConst.QS_COMPANY_NAME, coName ); 
		} else {
			curQuery.Clear(JsConst.QS_COMPANY_NAME);
		}
	}
	
		
	// if any of city,state,or zip was used, clear out lid=
	if ( bCity || bState || bZip )
	 {
		curQuery.Clear(JsConst.QS_LID);
	 }
	
   // Set NationWide Jobs lid=42886
   if ( typeof JsMain.Inputs[JsConst.INPUT_NATIONWIDELID] !== "undefined" )
   {
	    var jclid = JsUtil.Trim( JsUtil.GetElementValue( JsMain.Inputs[JsConst.INPUT_NATIONWIDELID] ) );
	    var bNationWideJobs = false;
        if ( jclid.indexOf("42886") > -1 ) 
	        {
			    curQuery.Set( JsConst.QS_LID, jclid); 
			    bNationWideJobs = true ;
		    }	 	
    }
    	
	// clear out the MLT fields
	curQuery.Clear(JsConst.QS_MLTDOCID);
	curQuery.Clear(JsConst.QS_MLTFIELD);
	curQuery.Clear(JsConst.QS_MLT_JOB_TITLE);
	
    // clear the sort value - let the app choose the default
	curQuery.Clear( JsConst.QS_SORT );
	
	//clear the Greybox view mode if not registered
	/*if(JsMain.IsSaveSearch)   
	{
	    curQuery.Set( JsConst.QS_GREYBOXVIEW, 'Add' );
	    
	    if ( typeof JsMain.Inputs[JsConst.INPUT_UPDATE_AGENTID] !== "undefined" ) {
		    var agentID = JsUtil.Trim( JsUtil.GetElementValue( JsMain.Inputs[JsConst.INPUT_UPDATE_AGENTID] ) );
		    if(agentID && agentID.length>0) curQuery.Set( JsConst.QS_AGENTID, agentID ); 
	    }

	    WTLog( new Array(['DCS.dcsuri', 'Search_SaveSearch.lyr']) );
	}
	else{
	    curQuery.Clear( JsConst.QS_GREYBOXVIEW );	
	}*/
	
	if (JsMain.REValue == null) {
	JsMain.REValue = 0; //0,Refine Search Form
	}
	// go to the new page
	JsMain.GotoPage( curQuery );
},

SetKeywords : function ( kw ) {
	// get the current query
	var curQuery = JsMain.CurrentQueryString();
	// start on page 1 
	curQuery.Set( JsConst.QS_PAGENUMBER, 1 );
	// update the keywords
	curQuery.Set( JsConst.QS_KEYWORDS , kw ); 
	// go to the new page
	JsMain.GotoPage( curQuery );
},

SetSort : function( sortval ) {
	// get the current query
	
	var curQuery = JsMain.CurrentQueryString();
	
	// start on page 1 
	curQuery.Set( JsConst.QS_PAGENUMBER, 1 );
	// update the sort param
	curQuery.Set( JsConst.QS_SORT, sortval ); 
	// go to the new page
	JsMain.GotoPage( curQuery );
},

SetView : function( vw ) {

	//set state of view
	var jsView = JsViewManager[vw];

	if (jsView) {
		this.View = jsView;	
	}	
},

SubmitView : function(vw) {
	var curQuery = JsMain.CurrentQueryString();
	// start on page 1 
	curQuery.Set( JsConst.QS_PAGENUMBER, 1 );
	JsMain.SetView(vw);
	// go to the new page
	JsMain.GotoPage( curQuery );	
},

SetPageNum : function( pagenum ) {
	// pagenum should be a number type
	
	/*
	if ( typeof pagenum !== "number" ) { 
		//alert("SetPageNum: number expected."); 
		return;
	}
	*/
	
	if (isNaN(pagenum))
	{
	    return;
	}
	
	// get the current query
	var curQuery = JsMain.CurrentQueryString();
	// set the JsConst.QS_PAGENUMBER value
	curQuery.Set( JsConst.QS_PAGENUMBER, pagenum );
	
	// go to the new page
	JsMain.GotoPage( curQuery );
},


SetJobAttr : function( qskey, jobattrid ) {
	// jobtypeid should be a number type
	if ( typeof jobattrid !== "number" ) { 
		//alert("SetJobAttr: number expected."); 
		return;
	}
	// get the current query
	var curQuery = JsMain.CurrentQueryString();
	// start on page 1 
	curQuery.Set( JsConst.QS_PAGENUMBER, 1 );
	if ( jobattrid<1 ) {
		// clear out any jt value
		curQuery.Clear( qskey ); 
	} else {
	    //this is a multilocation click - clear out all locations
	    if(qskey==JsConst.QS_LOCGENRE){
	        curQuery.Clear(JsConst.QS_LID); 
	        curQuery.Clear(JsConst.QS_CITY); 
	        curQuery.Clear(JsConst.QS_STATEID); 
			curQuery.Clear(JsConst.QS_ZIP); 
	        curQuery.Clear(JsConst.QS_RADIUS); 
	        curQuery.Clear(JsConst.QS_RADIUS_UNITS); 
	    }
	    	    
		// set the "jt" value
		curQuery.Set( qskey, jobattrid );
		// Temporary solution to ignore certain refinements until the search index is revamped
		//curQuery.Add( "allowrefs", qskey );
	}
	
	// go to the new page
	JsMain.GotoPage( curQuery );
},

SetTm : function( tmval ) {
	// get the current query
	var curQuery = JsMain.CurrentQueryString();
	// start on page 1 
	curQuery.Set( JsConst.QS_PAGENUMBER, 1 );
	// tmval could be number (3) or string ('3d')
	if ( typeof tmval==="number" && tmval<0 ) {
		curQuery.Clear( JsConst.QS_TIMEPERIOD ); // clear out any tm value
	} else if ( typeof tmval==="string" && tmval.length<1 ) {
		curQuery.Clear( JsConst.QS_TIMEPERIOD ); // clear out any tm value
	} else {
		curQuery.Set( JsConst.QS_TIMEPERIOD, tmval ); // set the "tm" value
	}
	// go to the new page
	JsMain.GotoPage( curQuery );
},

SetLid : function( lid ) {
	// should be a number type
	if ( typeof lid !== "number" ) { 
		//alert("SetLid: number expected."); 
		return;
	}
	// get the current query
	var curQuery = JsMain.CurrentQueryString();

	// start on page 1 
	curQuery.Set( JsConst.QS_PAGENUMBER, 1 );
	if ( lid<1 ) {
		// clear 
		curQuery.Clear( JsConst.QS_LID ); 
	} else {
		// set the "jt" value
		curQuery.Set( JsConst.QS_LID, lid ); 
		// clear out other location options
		curQuery.Clear(JsConst.QS_CITY);	//delete city query
		curQuery.Clear(JsConst.QS_STATEID);	//delete state query
		curQuery.Clear(JsConst.QS_ZIP);	//delete zipcode query
		curQuery.Clear(JsConst.QS_RADIUS);	//delete radius query
	}
	
	// go to the new page
	JsMain.GotoPage( curQuery );
},

NavJt : function( jtvals ) {
	// jtvals should be array of ints
	// get the current query
	var curQuery = JsMain.CurrentQueryString();
	// start on page 1 
	curQuery.Set( JsConst.QS_PAGENUMBER, 1 );
	// clear out "jt"
	curQuery.Clear("jt");
	// set
	if ( jtvals.length > 0 )
	{
		curQuery.SetMulti( "jt", jtvals );		
	}
	// go to the new page
	JsMain.GotoPage( curQuery );
},


SetSalary : function( SRID, salmin, salmax ) {
	// both args should be numbers
	if ( ( typeof SRID !== "number" ) || (typeof salmin !== "number" ) || ( typeof salmax !== "number" ) ) { 
		//alert("SetSalary: number expected."); 
		return;
	}

	// get the current query
	var curQuery = JsMain.CurrentQueryString();
	// start on page 1 
	curQuery.Set( JsConst.QS_PAGENUMBER, 1 );
	

	// SRID
	if ( SRID < 1 ) {
		// clear out all salary options
		curQuery.Clear( JsConst.QS_SRID ); 
		curQuery.Clear( JsConst.QS_SALMIN ); 
		curQuery.Clear( JsConst.QS_SALMAX ); 
	} else {
		curQuery.Set( JsConst.QS_SRID, SRID ); 
		// don't set salmin/salmax togeter with SRID (confusing)
	}
	// Temporary solution to ignore certain refinements until the search index is revamped
	//curQuery.Add( "allowrefs", "SRID" );
	
	// go to the new page
	JsMain.GotoPage( curQuery );
},

MoreLikeThis : function( docid/*number*/, field/*string*/, field2/*string*/ ) {
	// get the current query
	var curQuery = JsMain.CurrentQueryString();
	
	// setCookie("oq", curQuery.QueryStringSerialize());
	
	// start on page 1 
	curQuery.Set( JsConst.QS_PAGENUMBER, 1 );
	
	// clear out keywords - since they are not used for mlt
	curQuery.Clear( JsConst.QS_KEYWORDS );
	// set the mlt params
	curQuery.Set( JsConst.QS_MLTDOCID, docid );
	curQuery.Set(JsConst.QS_MLTFIELD, field);
	curQuery.Set(JsConst.QS_MLT_JOB_TITLE, field2);
		
	// sort by relevance for mlt
	curQuery.Set( JsConst.QS_SORT, "rv.dt" );

	// go to the new page
	JsMain.GotoPage( curQuery );
},

Inputs : {}, // map input name to a control object

Prompts : {}, // map input prompt to a control object

RegisterInput : function( name, controlOrObjectID ) {
	// find the element
	var ctl = JsUtil.GetEl( controlOrObjectID );
	
	// add to the inputs hash
	if ( ctl !== null ) {
		JsMain.Inputs[name] = ctl;
	}
	else {
		// amarculescu: extending this to javascript object
		try {
			// we assume this is a valid javascript object
			var object = eval(controlOrObjectID);
			if (object != null) {
				JsMain.Inputs[name] = object;
			}
		}
		catch(err) {
			// ignore this, we won't register illegal ids
		}
	}
},

RegisterPrompt : function( name, prompt ) {
	JsMain.Prompts[name] = prompt;
},

GetPrompt : function( name ) {
	var retVal = JsMain.Prompts[name];
	return retVal != null ? retVal : "";
},

IsVisible : function( elem ) {
	for ( var currElem = elem; currElem != null && currElem.tagName != 'FORM'; currElem = currElem.parentNode )
	{
		if (currElem.style.display == "none") { return false; }
	}
	return true;
},

Listeners : {}, // map event name to an array of listeners

AddListener : function( evtname, handler ) {
	if ( ! ( evtname in JsMain.Listeners ) ) {
		JsMain.Listeners[evtname]=[]; // empty array
	}
	JsMain.Listeners[evtname].push(handler); // add the new handler
},

HandleEvent : function( evtobj ) {
	var evtname = evtobj[0]; // first element is the evtname
	if ( evtname in JsMain.Listeners ) {
		var handlers = JsMain.Listeners[evtname]
		for ( var k in handlers ) {
			handlers[k](evtobj); // call it
		}
	}
},

z:0
};


// This is the entrypoint for this module.  Any click events, etc, will go here first.
// Accepts a variable argument list.
var _jsevt = function() {
	for ( var i=0; i<arguments.length; i++ )
	{
	var o = arguments[i];
	var key = o[0].toLowerCase();
	
	// o should be an array.  The first element is the command, any other elements will be parameters.
	if ( key === "search" ) { 
		// The main search button.
		if(JsUtil.IsControlLoaded())
			JsMain.DoSearch();
		
	} else if ( key === "searchonsubmit" ) {
		JsMain.SearchOnSubmit();
		
	} else if ( key === "setsavedsearch" ) {
	   JsMain.IsSaveSearch = true;	 
	      		
	} else if ( key === "page" ) {
		// The prev or next page links go here.
		// 1st param should be the page num
		JsMain.SetPageNum( o[1] );

	} else if ( /^input\.[a-z]+$/.test(key) ) {
		// something like input.keywords
		var s2 = key.split('.');
		if ( s2.length > 1 ) {
			JsMain.RegisterInput( s2[1], o[1] );
		}
	
	} else if ( /^prompt\.[a-z]+$/.test(key) ) {
		// something like prompt.city
		var s2 = key.split('.');
		if ( s2.length > 1 ) {		
			JsMain.RegisterPrompt( s2[1], o[1] );
		}
	
	} else if ( key === "sort" ) {
		// 1st param should be the sort param
		JsMain.SetSort( o[1] );
		
	} else if ( key === "view" ) {
		// 1st param should be the view param
		JsMain.SubmitView( o[1] );						

	} else if ( key === "tm" ) {
		// 1st param should be the number of days
		JsMain.SetTm( o[1] );

	} else if ( key === "showelem" ) {
		// 1st param should be the element id
		JsUtil.ShowElem( o[1] );

	} else if ( key === "hideelem" ) {
		// 1st param should be the element id
		JsUtil.HideElem( o[1] );
		
	} else if ( key === "jtyp" || key==="jsta" || key==="jshf" || key==="fn"  ||  key==="ye"  || key==="lv"  || key==="eid"  || key==="tm" || key==="jot" || key==="locgen") {
		// param should be the jobattributeid
		JsMain.SetJobAttr( key, o[1] );
		
	}
	else if ( key==="lid" ) {
		JsMain.SetLid( o[1] );
		
	} else if ( key === "navjt" ) {
		// param should be array of ints
		JsMain.NavJt( o[1] );

	} else if ( key === "jtt" ) {
		// param should be array of ints
		JsMain.NavJt( o[1] );

	} else if ( key === "jts" ) {
		// param should be array of ints
		JsMain.NavJt( o[1] );


	} else if ( key === "srid" ) {
		// 1st and 2nd params will be salmin and salmax
		JsMain.SetSalary( o[1], o[2], o[3] );

	} else if ( key === "mlt" ) {
		// this is the morelikethis command
		// 1st param will be the docid, 2nd param will be the field
		JsMain.MoreLikeThis( o[1], o[2], o[3]);

	} else if ( key === "kw" ) {
		JsMain.SetKeywords( o[1] );
		
	} else if ( key === "re" ) {
		JsMain.REValue = o[1];

	} else if ( key === "listen" ) {
		// register a listener for an event
		JsMain.AddListener( o[1], o[2] ); // evtname, handler

	} else {
		// it must be a registered evt handler
		JsMain.HandleEvent( o );
	}
	}
};


// This was copied from jobsearch.monster.com
function popMMLL(st,ci)
{
	var strMMLL="http://monster.monstermoving.monster.com/jumpPage.asp?"+"State="+st+"&location="+ci;
	var winMMLL=window.open(strMMLL,'location','width=760,height=600,top=10,left=10,screenx=10,screeny=10,toolbar,location,scrollbars,resizable,menubar');
	winMMLL.focus();
	return false;
}

function popMMLL2(st,ci)
{
	var MMStateMap = new Array("","","AL","AK","AZ","AR","CA","CO","CT","DE",
		"FL","GA","HI","ID","IL","IN","IA","KA","KY","LA",
		"ME","MD","MA","MI","MN","MS","MO","MT","NE","NV",
		"NH","NJ","NM","NY","NC","ND","OH","OK","OR","PA",
		"RI","SC","SD","TN","TX","UT","VT","VA","WA","WV",
		"WI","WY","DC");

	var stateID = 0;
	for (i = 2; i < MMStateMap.length; i++)
	{
		if (MMStateMap[i] == st) { stateID = i; break; }
	}
	if (stateID == 0) { return false; }
	
	var strMMLL="http://monster.moving.com/jumpZipSelector.asp?State="+stateID+"&City="+ci;
	var winMMLL=window.open(strMMLL,'location','width=760,height=600,top=10,left=10,screenx=10,screeny=10,toolbar,location,scrollbars,resizable,menubar');
	winMMLL.focus();
	return false;
}

function popMMLLzip(zip)
{
	var strMMLL="http://monster.moving.com/jumpresults.asp?Zip="+zip;
	var winMMLL=window.open(strMMLL,'location','width=760,height=600,top=10,left=10,screenx=10,screeny=10,toolbar,location,scrollbars,resizable,menubar');
	winMMLL.focus();
	return false;
}

function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

getHostName = function () {
    //return RootSecurityDomain in case it was defined on server side
    if (typeof (RootSecurityDomain) != "undefined")
        return RootSecurityDomain;

    var host = "";
    var monIdx = window.location.host.lastIndexOf(".monster");
    if (monIdx > -1) {
        return window.location.host.substr(monIdx);
    } else {
        monIdx = window.location.host.toLowerCase().lastIndexOf(".careerone");
        if (monIdx > -1) {
            return window.location.host.substr(monIdx);
        };
    };

    var hostArray = window.location.host.split(".");
    while (hostArray.length > 2) {
        hostArray.shift();
    }
    for (var i = 0; i < hostArray.length; i++) {
        host += "." + hostArray[i];
    }
    return host;
}

isPowerSearch = function() {
  if ($.cookie('scsjsv') == 1)
    return true;
  return false;
}
