arrRegions = [{"intRegionId":"57","strRegionName":"West Yorkshire","arrLocations":[{"intLocationId":"994","strLocationName":"Batley","strLocationNameWithPrefix":"Batley","strRegionName":"West Yorkshire"},{"intLocationId":"1010","strLocationName":"Bingley","strLocationNameWithPrefix":"Bingley","strRegionName":"West Yorkshire"},{"intLocationId":"85","strLocationName":"Bradford","strLocationNameWithPrefix":"Bradford","strRegionName":"West Yorkshire"},{"intLocationId":"1038","strLocationName":"Brighouse","strLocationNameWithPrefix":"Brighouse","strRegionName":"West Yorkshire"},{"intLocationId":"86","strLocationName":"Castleford","strLocationNameWithPrefix":"Castleford","strRegionName":"West Yorkshire"},{"intLocationId":"1085","strLocationName":"Cleckheaton","strLocationNameWithPrefix":"Cleckheaton","strRegionName":"West Yorkshire"},{"intLocationId":"87","strLocationName":"Dewsbury","strLocationNameWithPrefix":"Dewsbury","strRegionName":"West Yorkshire"},{"intLocationId":"1150","strLocationName":"Elland","strLocationNameWithPrefix":"Elland","strRegionName":"West Yorkshire"},{"intLocationId":"88","strLocationName":"Halifax","strLocationNameWithPrefix":"Halifax","strRegionName":"West Yorkshire"},{"intLocationId":"96","strLocationName":"Harrogate","strLocationNameWithPrefix":"Harrogate","strRegionName":"West Yorkshire"},{"intLocationId":"1212","strLocationName":"Hebden Bridge","strLocationNameWithPrefix":"Hebden Bridge","strRegionName":"West Yorkshire"},{"intLocationId":"1213","strLocationName":"Heckmondwike","strLocationNameWithPrefix":"Heckmondwike","strRegionName":"West Yorkshire"},{"intLocationId":"1223","strLocationName":"Holmfirth","strLocationNameWithPrefix":"Holmfirth","strRegionName":"West Yorkshire"},{"intLocationId":"89","strLocationName":"Huddersfield","strLocationNameWithPrefix":"Huddersfield","strRegionName":"West Yorkshire"},{"intLocationId":"90","strLocationName":"Ilkley","strLocationNameWithPrefix":"Ilkley","strRegionName":"West Yorkshire"},{"intLocationId":"91","strLocationName":"Keighley","strLocationNameWithPrefix":"Keighley","strRegionName":"West Yorkshire"},{"intLocationId":"1288","strLocationName":"Knottingley","strLocationNameWithPrefix":"Knottingley","strRegionName":"West Yorkshire"},{"intLocationId":"84","strLocationName":"Leeds","strLocationNameWithPrefix":"Leeds","strRegionName":"West Yorkshire"},{"intLocationId":"1307","strLocationName":"Liversedge","strLocationNameWithPrefix":"Liversedge","strRegionName":"West Yorkshire"},{"intLocationId":"1378","strLocationName":"Mirfield","strLocationNameWithPrefix":"Mirfield","strRegionName":"West Yorkshire"},{"intLocationId":"1406","strLocationName":"Normanton","strLocationNameWithPrefix":"Normanton","strRegionName":"West Yorkshire"},{"intLocationId":"1415","strLocationName":"Ossett","strLocationNameWithPrefix":"Ossett","strRegionName":"West Yorkshire"},{"intLocationId":"97","strLocationName":"Other","strLocationNameWithPrefix":"Other","strRegionName":"West Yorkshire"},{"intLocationId":"1416","strLocationName":"Otley","strLocationNameWithPrefix":"Otley","strRegionName":"West Yorkshire"},{"intLocationId":"92","strLocationName":"Pontefract","strLocationNameWithPrefix":"Pontefract","strRegionName":"West Yorkshire"},{"intLocationId":"1459","strLocationName":"Pudsey","strLocationNameWithPrefix":"Pudsey","strRegionName":"West Yorkshire"},{"intLocationId":"93","strLocationName":"Shipley","strLocationNameWithPrefix":"Shipley","strRegionName":"West Yorkshire"},{"intLocationId":"949","strLocationName":"Skipton","strLocationNameWithPrefix":"Skipton","strRegionName":"West Yorkshire"},{"intLocationId":"1509","strLocationName":"Sowerby Bridge","strLocationNameWithPrefix":"Sowerby Bridge","strRegionName":"West Yorkshire"},{"intLocationId":"1787","strLocationName":"Todmorden","strLocationNameWithPrefix":"Todmorden","strRegionName":"West Yorkshire"},{"intLocationId":"94","strLocationName":"Wakefield","strLocationNameWithPrefix":"Wakefield","strRegionName":"West Yorkshire"},{"intLocationId":"95","strLocationName":"Wetherby","strLocationNameWithPrefix":"Wetherby","strRegionName":"West Yorkshire"}]}]

AddPageLoadFunction(
	function(){
		var objVarElement = document.getElementById("QuickSearchRegion");
		
		if(objVarElement != null && objVarElement.options){			
			var objOption, objTextNode;

			var intCurrentRegionId = objVarElement.options[objVarElement.selectedIndex].value;		
			objVarElement.innerHTML="";
			
			var intNumRegions = arrRegions.length;
			var bolRegionFound = false;
			
			for(var i=0; i<intNumRegions;i++){
				objOption = document.createElement("option");
				objOption.value = arrRegions[i]["intRegionId"];
				if(intCurrentRegionId == arrRegions[i]["intRegionId"]){
					objOption.selected = "selected";
					bolRegionFound = true;
				}
				objTextNode = document.createTextNode(arrRegions[i]["strRegionName"]);
				objOption.appendChild(objTextNode);
				objVarElement.appendChild(objOption);
			}
			
			if(!bolRegionFound){
				intCurrentRegionId = objVarElement.options[objVarElement.selectedIndex].value;				
				QuickChangeRegionById(intCurrentRegionId);
			}					
			
			var objMyRules = { 
				"#QuickSearchRegion" : function(objElement){
					addEvent(objElement,"change",QuickChangeRegion);
				}
			};
			Behaviour.register(objMyRules);
			Behaviour.apply(objMyRules);
		}
	}
)

function QuickChangeRegion(objEvent){
	objEvent = PrepareEvent(objEvent);
	var intCurrentRegionId = objEvent.objTarget.options[objEvent.objTarget.selectedIndex].value;
	QuickChangeRegionById(intCurrentRegionId);
}

function QuickChangeRegionById(intRegionId){
	var objOption, objTextNode;
	
	var objVarElement = document.getElementById("QuickSearchLocation");
	objVarElement.innerHTML="";

	objOption = document.createElement("option");
	objOption.value = 0;
	objTextNode = document.createTextNode("All Locations");
	objOption.appendChild(objTextNode);
	objVarElement.appendChild(objOption);

	var intNumRegions = arrRegions.length;
	for(var i=0; i<intNumRegions;i++){
		if(intRegionId == arrRegions[i]["intRegionId"]){
			intCurrentRegion = i;
		}
	}
	
	var intNumLocations = arrRegions[intCurrentRegion]["arrLocations"].length;

	for(var i=0; i<intNumLocations;i++){
		objOption = document.createElement("option");
		objOption.value = arrRegions[intCurrentRegion]["arrLocations"][i]["intLocationId"];		
		objTextNode = document.createTextNode(arrRegions[intCurrentRegion]["arrLocations"][i]["strLocationName"]);
		objOption.appendChild(objTextNode);
		objVarElement.appendChild(objOption);
	}
}

