﻿<!--
var gs_imgUrlCollapsed = "http://media.monster.com/mm/usen/js/arrow_right.gif";
var gs_imgUrlExpanded = "http://media.monster.com/mm/usen/js/arrow_dn.gif";
var ls_hrUrl = "http://media.monster.com/id/js/mons/JSRD/ImpvSrc_HrzRl.gif";
var limitmsg = "Please limit your selection of locations. To search all locations, do not select a specific location.";
var limitmsg2 = "Please reduce your selection of search criteria.";

// Expand or collapse
function ExpandMenu(as_div, as_selectTagToHide)
{
	// If menu expanded, collapse it and return.
	if (document.getElementById(as_div).style.visibility == "")
	{
		CollapseMenu(as_div, as_selectTagToHide);
		return;
	}

    var l_image; 
    // hide all other menus
    eval('l_image = document.images["img_'+as_div+'"]');
    var lyr= new Array('TITLES','STATUSES','CATEGORIES','LOCATIONS','SALARIES');
    for(var l=0;l<lyr.length;l++)if(as_div!=lyr[l])CollapseMenu(lyr[l], as_selectTagToHide);

    var li_y
    li_y = docjslib_getImageYfromTop (l_image);

	// Position menu
	with(document.getElementById(as_div).style)
		{
		left = 10;
		top = li_y + 17;
		}
		
	// expand if collapsed
	document["img_" + as_div].src = "http://media.monster.com/mm/usen/js/arrow_dn.gif";
	with(document.getElementById(as_div).style)
		{
		display = "";
		visibility = "";
		zIndex = "1492";
		} //fix Opera issue

	// IE bug <select> tags and flash burning through; set underlying <select> to hidden.
	setVisibilityOfElements(as_selectTagToHide, false);
}

// Collapse menu
function CollapseMenu(as_div, as_selectTagToHide)
{
    // hide menu
    hideRefinementLayer(as_div);

	// set arrow images to collapsed state
	resetImage (as_div, gs_imgUrlCollapsed);

	// IE bug <select> tags - re-display <select> that was previously hidden.
	setVisibilityOfElements(as_selectTagToHide, true);
}

//sets visibility (true/false) to a set of html elements passed in as a CSV list
function setVisibilityOfElements(as_elements, ab_visible)
{
	if (as_elements.length > 0)
	{
		var l_arrTagsToHide = as_elements.split(",")
		for(l_i in l_arrTagsToHide)
		{
			l_tagToHide = l_arrTagsToHide[l_i]
			if (document.getElementById(l_tagToHide) != null)
			{
				document.getElementById(l_tagToHide).style.visibility = ab_visible ? "visible":"hidden";
			}
		}
	}
}
function hideRefinementLayer(e){
	if (e == null)
	{
		this.css.visibility="hidden"
		this.css.display="none"
	}
	else
	{
		(document.getElementById)? document.getElementById(e).style.visibility = "hidden" : (document.layers && !document.getElementById)? document.layers[e].visibility = "hide" : document.all[e].style.visibility = "hidden";
		(document.getElementById)? document.getElementById(e).style.display = "none" : (document.layers && !document.getElementById)? document.layers[e].display = "none" : document.all[e].style.display = "none";
	}
} 
// returns Y pos of an image
function docjslib_getImageYfromTop(imgID) {
  if(document.layers && !document.getElementById){
      return eval(imgID).y
  }
  else{
      return docjslib_getRealTop(imgID);
  }
}
function docjslib_getRealTop(imgElem) {
	yPos = eval(imgElem).offsetTop;
	tempEl = eval(imgElem).offsetParent;
	while (tempEl != null) {
  		yPos += tempEl.offsetTop;
  		tempEl = tempEl.offsetParent;
  	}
	return yPos;
}

function CheckRadiusZip()
{
 
  if(!document.form_rad_zip.location[1].checked)
	{return false;}
  
  var li_rad = document.form_rad_zip.rad.value;
  var ls_zip = document.form_rad_zip.zip.value;
  var blnNotValid = false;
  //validate
  
  
  ls_zip = LTrim(RTrim(ls_zip));
  var strCID = 160;
  switch (strCID)
  {
	case 160:
		if(ls_zip.length < 5 || ls_zip.length > 8 || !ls_zip.match(/\w{1,4}\s*\w{1,4}/))
		{blnNotValid = true;}
		break;
	case 109:
		if(ls_zip.length > 7)
		{blnNotValid = true;}
		break;
	default:
		if(isNaN(ls_zip) || ls_zip.length > 5)
		{blnNotValid = true;}
  }
  // 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");
	
}
  
  
  if(blnNotValid)
  {
	if(li_rad != "" || ls_zip != "")
	{
		errorMsg = "You've selected search by Postal Code. Please define Postal Code and Radius.";
		
		return false;
	}
  }
  
  return true;
}

var startURL;
var errorMsg='';

function getError(){return errorMsg;}

// returns false if 'strFieldName' field should not be added to url
function shouldNotSkip(as_param, as_fieldName, as_zip)
{
    if (as_param != 'q') return true;
    
    // q means that the q+cityname+sid+zip+radius was submitted
    // if sid or zip was entered, block the lid
    if ((as_zip.length > 0)&&(as_fieldName == 'lid'))
    {
        return false;//block lid
    }
    
    return true;

}

function refineSearchURL()
{
  return startURL;
}

function refineSearch(refineRef, as_value)
{
  var li_rad = "";
  if(document.form_rad_zip.rad)   {li_rad = document.form_rad_zip.rad.value;}
  var ls_zip = ""; 
  if(document.form_rad_zip.zip)   {ls_zip = document.form_rad_zip.zip.value;}
  
  var li_location = "";
  if(document.form_rad_zip.location)
  {
  if(document.form_rad_zip.location[0].checked)
  {li_location = "1";}
  else{if(document.form_rad_zip.location[1].checked)
	{li_location = "2";}}
  }
  var ls_cnme = "";
  if(document.form_rad_zip.cnme)  {ls_cnme = document.form_rad_zip.cnme.value;}
	
  var refineRef2 = (refineRef=='salmin' ? 'salmax':'' );
  var refineRef3 = (refineRef=='salmin' ? 'SRID':'' );

  startURL = 'http://jobsearch.monsterpublic.co.uk/jobsearch.asp?';

  for(var f=0;f<document.form_rad_zip.elements.length;f++)
	{
	var fname=document.form_rad_zip.elements[f].name;
  	var fvalue=document.form_rad_zip.elements[f].value;

  	if((document.form_rad_zip.elements[f].type=='hidden') && (fvalue != null))
      if( 
		fname!='refine' && 
		fname!='re' && 
		fname!='pg' &&
  		  fname!='jts' &&
  		  fname!='jtt' &&
  		  fname!='jt' &&
		fname!=refineRef && 
  		  fname!=refineRef2 &&
  		  fname!=refineRef3 &&
  		  (refineRef!='lid' || (fname!='zip' && fname!='cnme' && fname!='location')) && //when lid selected, forget zip, cnme and sid
  		  shouldNotSkip(refineRef, fname, ls_zip)
      )
      {
     		startURL += ( startURL!='http://jobsearch.monsterpublic.co.uk/jobsearch.asp?' ? '&' : '' ) + fname + '=' + escape(fvalue);
  		}
  		
  		if((fname=='jts')||(fname=='jtt'))
  		{
        //alert('field ' + fname + ' has value ' + fvalue);
  		  if(fvalue.length > 0)
    		{
          //alert('refineSearch adding ' + fname + ' with value ' + fvalue);
          startURL += ( startURL!='http://jobsearch.monsterpublic.co.uk/jobsearch.asp?' ? '&' : '' ) + 'jt=' + (fvalue);
        }
      }
	}

	if(document.form_rad_zip.q.value.length > 0)
	{
  startURL+='&q='+ encodeURIComponent(document.form_rad_zip.q.value);
	}

  if(refineRef != 'lid')//if lid then it does not make sense to keep zip, sid or city name
  {
    if(CheckRadiusZip())
  	{
  	if(ls_zip != "")
  		{
		startURL += '&zip=' + ls_zip;
  		startURL += '&rad=' + li_rad;
  		}
  	}
  	
  	else
  	{
  	if(document.form_rad_zip.location[1].checked)
  	{  	return false;}
  	}
  	
    
    if(ls_cnme.length > 0 && document.form_rad_zip.location[0].checked){startURL += '&cnme=' + ls_cnme;}
    if(li_location.length > 0){startURL += '&location=' + li_location;}
  }

  var ls_re='112';
  if(refineRef.match(/zip/))    { ls_re = "93"; }
  if(refineRef.match(/fn/))     { ls_re = "94"; }
  if(refineRef.match(/lid/))    { ls_re = "95"; }
  if(refineRef.match(/jt/))     { ls_re = "96"; }
  if(refineRef.match(/jts/))     { ls_re = "96"; }
  if(refineRef.match(/jtt/))     { ls_re = "96"; }
  if(refineRef.match(/salmin/)) { ls_re = "97"; }
  if(refineRef.match(/salmax/)) { ls_re = "97"; }
  if(refineRef.match(/jobtitle/)) { ls_re = "112"; }
  if(refineRef.match(/lv/)) { ls_re = "132"; }
  if(refineRef.match(/ye/)) { ls_re = "133"; }
  startURL = startURL+'&re='+ ls_re ;

  if(as_value != "skip")//skip refine when improving
  {
    if(refineRef == 'lid')
    {
      AddSearchParam('lid', 'LOCATIONS', '');
    }
    if(refineRef == 'fn')
    {
      AddSearchParam('fn', 'CATEGORIES', '');
    }
  }
  
  startURL = startURL.replace("?&", "?");   // DEV00542196 fix

  if( startURL.length>2080 ){
	alert(limitmsg2); 
	return false;
	}

  return true;	
  }
  
function rl(ai_paramValue)
	{ 
	if( refineSearch('lid') ) window.location.href=refineSearchURL();
	}

function rc(ai_paramValue)
	{
	if( refineSearch('fn') ) window.location.href=refineSearchURL();
	}

function rj(ai_paramValue)
{
	if( refineSearch('jt') )
		{
		AddSearchParam('jt', '', ai_paramValue);
		window.location.href=refineSearchURL();
		}
}
function lid(ai_paramValue)
{
  if(ai_paramValue == undefined){ai_paramValue = '';}

	if( refineSearch('lid', 'skip') )
	{
		AddSearchParam('lid', '', ai_paramValue);
		window.location.href=refineSearchURL();
	}
}	
function fn(ai_paramValue)
{
  if(ai_paramValue == undefined){ai_paramValue = '';}

	if( refineSearch('fn', 'skip') )
	{
		AddSearchParam('fn', '', ai_paramValue);
		window.location.href=refineSearchURL();
	}
}	
function rt(ai_paramValue)
{
	document.form_rad_zip.q.value='"'+unescape(document.formTITLES.ddTITLES.options[document.formTITLES.ddTITLES.selectedIndex].value)+'"';
	if( refineSearch('jobtitle') )
		{
		window.location.href=refineSearchURL();
		}
}
function rs(s1,s2,s3)
{
	if( refineSearch('salmin') )
	{
	  if(!isNaN(s1) && !isNaN(s2) && !isNaN(s3))
		{
		  AddSalaryParams(s1 + '', s2 + '', s3 + '');
		}
		window.location.href=refineSearchURL();
		}
}
function salmin(s1, s2, s3)
{
  rs(s1, s2, s3);
}
function AddSearchParam(as_paramName, ai_formID, ai_paramValue){

  var ls_url = startURL;
  //alert('as_paramName=' + as_paramName +'\nai_formID=' + ai_formID + '\nai_paramValue=' + ai_paramValue + '\nls_url=' + ls_url);

  if(ai_formID=='')
	{
     	if (ai_paramValue != "")
    		{
    	 	ls_url += '&' + as_paramName + "=" + ai_paramValue;
     		}
     	startURL=ls_url;
     	return true;
	}
  else
	{
	var multiParam='';
    
  if(!document.forms['form' + ai_formID])
  {
    return true;
  }

	var dropdown = document.forms['form' + ai_formID]['dd' + ai_formID];
	var intSelCount=0;
	var li_optionsLength;
	var blnIsCombo=false;

	if(dropdown.options)
	{
    li_optionsLength = dropdown.options.length;
    blnIsCombo = true;
  }
  else
  {
	  li_optionsLength = dropdown.length;
	  blnIsCombo = false;
  }
  
	for(var x=0; x < li_optionsLength; x++)
  {
     if(!blnIsCombo)//2tier widget
     {
        if(dropdown[x].checked)
        {
            multiParam+=(multiParam!=''?'&':'')+as_paramName + "=" + dropdown[x].value;
        }
	   }
	   else
	   {
	       multiParam+=(multiParam!=''?'&':'')+as_paramName + "=" + dropdown.options[x].value;
     }
  	 intSelCount++;
  }
	if ( multiParam.length>2083 || (intSelCount>200 && ai_formID=='LOCATIONS') )
		{
		alert( (ai_formID=='LOCATIONS' ? limitmsg : limitmsg2) );
		return false;
	  	}
	else
  		{
	  	if (multiParam != "")
	  		{
		  	ls_url += getQueryStringDelimiter(ls_url) + multiParam;
			}
		startURL=ls_url;
		return true;
	  	}
	}
}

function AddSalaryParams(as_paramValue1, as_paramValue2, as_paramValue3)
{
  var ls_url = startURL;

  var regular = new RegExp("salmin=\\d*");
  ls_url = ls_url.replace(regular, "");
  regular = new RegExp("salmax=\\d*");
  ls_url = ls_url.replace(regular, "");
  regular = new RegExp("SRID=\\d*");
  ls_url = ls_url.replace(regular, "");
  if(as_paramValue1.length > 0){
      ls_url += "&salmin=" + as_paramValue1;
  }
  if(as_paramValue2.length > 0 && as_paramValue2 != "-1"){
      ls_url += "&salmax=" + as_paramValue2;
  }
  if(as_paramValue3.length > 0){
      ls_url += "&SRID=" + as_paramValue3;
  }

  startURL=ls_url;
}

function getQueryStringDelimiter(as_url)
{
	return (as_url.indexOf("?") > 0) ? "&" : "?";
}

function resetImage(as_div, as_imgUrl)
{
	var imageId = "img_" + as_div;
	if (document[imageId])
	{
		document[imageId].src = as_imgUrl;
	}
}

function editOpts(intDirection, formName, ddName)
{
    	var heading = '';
    	var msg = '';
    	var flag;
    	var arrnew = new Array();
    	with ( document[formName] ){
		fDD = eval( 'document.'+formName+'.f'+ddName );
		tDD = eval( 'document.'+formName+'.'+ddName );
    		if (intDirection)
    		{
    			msg = '';
    			for(var x=0;x<fDD.length;x++)
    			{
    				var opt = fDD.options[x];
    				if (opt.selected)
    				{
    					flag = 1;
    					if (tDD.length > 200)
    					{
    						alert( (ddName=='ddLOCATIONS' ? limitmsg : limitmsg2) );
    						break;
    					}
    					for (var y=0;y<tDD.length;y++)
    					{
    						var myopt = tDD.options[y];
    						if (myopt.value == opt.value)
    						{
    							flag = 0;
    						}
    					}
    					if (flag)
    					{
    						tDD.options[tDD.options.length] = new Option(opt.text, opt.value, 0, 0);
    					}
    				}
    			}
    		}
    		else
    		{
    			for(var x=tDD.length-1;x>=0;x--){
    				var opt = tDD.options[x];
    				if (opt.selected){
    					//Remove it from the select box
    					tDD.options[x] = null;
    				}
    			}
    		}
    	}
}

//-->

