var homepage = {

	site : "", // CP UK COM

	homejobsearch : function(){

		ShowDebug("In homejobsearch");

		ShowDebug("this.site = " + this.site);

		switch (this.site)		
		{
			case "CP":17/02/2010
				this.removeareas("Gulf");
				break;
			case "UK":
				this.removeareas("Gulf");
				break;
			case "COM":
				this.removeareas("Canada,Gulf,India,Australasia");
				break;
			default:
				ShowDebug("invalid site specified = " + this.site);
		
		}

	},

	setuphomepage : function(){

		ShowDebug("IN setuphomepage");

		ShowDebug("this.site = " + this.site);

		switch (this.site)
		{
			case "CP":
				this.removeoptions("locallstRegion","India,Australasia,USA,Canada","VALUE");
				this.removeoptions("lstRegion","India,Australasia,USA,Canada","TEXT");
				break;
			case "UK":
				this.removeoptions("locallstRegion","India,Australasia,USA,Canada","VALUE");
				this.removeoptions("locallstSector","Digital Media and Creative,eCommerce/Web Technology,Games and 3D,PR and Marcomms","VALUE");// same for both networks
				this.removeoptions("lstSector","Digital Media and Creative,eCommerce/Web Technology,Games and 3D,PR and Marcomms","TEXT");// same for both network
				break;
			case "COM":
				this.removeoptions("locallstRegion","UK and Europe");
				this.removeoptions("locallstSector","Digital Media and Creative,eCommerce/Web Technology,Games and 3D,PR and Marcomms","VALUE");// same for both networks
				this.removeoptions("lstSector","Digital Media and Creative,eCommerce/Web Technology,Games and 3D,PR and Marcomms","TEXT");// same for both networks
				break;
			default:
				ShowDebug("invalid site specified = " + this.site);
		}
	},

	removeareas : function(rem){
		//Debugger.debug = true;
		ShowDebug("IN removeareas rem = " + rem);

		if(!rem||rem=="")return;
				
		var el = getEl('locallstArea');
		var r = getEl('locallstRegion');
		
		if(!el || !r) return;

		var a = rem.split(",");

		ShowDebug("loop through " + a.length + " items to remove");

		ShowDebug("region value is = " + r.value);
		ShowDebug("region selected index = " + r.options[r.options.selectedIndex]);

		ShowDebug("there are " + el.options.length + " items in the select box");
		for(var x=0;x<el.options.length;x++){
			ShowDebug("option " + x + " = " + el.options[x].value);
		}

		for(var x=0,l=a.length;x<l;x++){

			ShowDebug("check whether list item " + r.options[r.options.selectedIndex].value + " == " + a[x]);

			if(r.options[r.options.selectedIndex].value==a[x]){

				ShowDebug("this option is on list and selected " + a[x]);

				// remove all from area list apart from the any option
				//for(var i=0,al=el.length;i<al;i++){
				for (var i=(el.options.length-1); i>=0; i--){ 
					if(el.options[i].value!=""){
						ShowDebug("remove option " + el.options[i].value);
						el.options[i]=null;				
					}
				}	

			}
		}

		ShowDebug("all options removed");
	
	},

	removeoptions : function(lst,rem,m){

		ShowDebug("IN removeoptions lst = " + lst + ", rem = " + rem + " m = " + m);

		if(!rem||rem=="")return;
				
		var el = getObj(lst);

		if(!el) return;

		var f,a = rem.split(",");

		ShowDebug("loop through " + a.length + " items to remove");

		ShowDebug("there are " + el.options.length + " items in the select box");

		// loop through items in ascending order otherwise we run into problems with missing list items
		for(var x=0,l=a.length;x<l;x++){
	
			ShowDebug("remove " + a[x]);

			for (var i=(el.options.length-1); i>=0; i--){ 
				
				f = false;

				// do we match on ID or value?
				if(m=="VALUE" && a[x].toLowerCase()==el.options[i].value.toLowerCase()){
					f=true; //match on value
				}else if(m=="TEXT" && a[x].toLowerCase()==el.options[i].text.toLowerCase()){
					f=true; //match on description
				}

				if(f){
					
					ShowDebug("remove this option " + el.options[i].value);

					el.options[i]=null;
					break;
				}	

			}
		}
		
	}	

}

// once DOM has loaded setup page
DOM(function(){
	// set up the quick search to show correct values for network
	homepage.setuphomepage();		

	if(typeof(objLLpage11locallstArea)=="object"){

		// set function thats called when linked list is called to remove categories
		objLLpage11locallstArea.OnCategoriesLoaded = function(){				
			homepage.homejobsearch.call(homepage);
		};

	}

})



/*
// create emergency debugger div for IE and override showdebug

//sm("Body ready so add custom logger")
var log = document.createElement("div");
log.setAttribute("id","logWindow");			
var styles = {visibility:"visible",display:"block",zIndex:"2147483647",position:"relative",backgroundColor:"#fff",border:"1px solid",overflow:"auto",width:"98%",left:"0",bottom:"0",height:"200px",padding:"5px",textAlign:"left" };
setStyles(log,styles);
GetBody().appendChild(log);	
//sm("append to body")
var r = document.getElementById("logWindow");

ShowDebug = function(m){
	var s=document.createElement("span");
	s.innerHTML = XSSEncode(m) + "<br />";
	//sm("s.innerHTML = " + s.innerHTML);
	var el=document.getElementById("logWindow"); //use custom logger
	el.appendChild(s);

}

XSSEncode =  function(s,en){
	if(!iE(s)){
		
		// do we convert to numerical or html entity?
		
		s = s.replace(/\'/g,"&#39;"); //no HTML equivalent as &apos is not cross browser supported
		s = s.replace(/\"/g,"&quot;");
		s = s.replace(/</g,"&lt;");
		s = s.replace(/>/g,"&gt;");
	
		return s;
	}else{
		return "";
	}
}
*/
