arrRegions = [{"intRegionId":"119","strRegionName":"East Yorkshire","arrLocations":[{"intLocationId":"1006","strLocationName":"Beverley","strLocationNameWithPrefix":"Beverley","strRegionName":"East Yorkshire"},{"intLocationId":"1035","strLocationName":"Bridlington","strLocationNameWithPrefix":"Bridlington","strRegionName":"East Yorkshire"},{"intLocationId":"1800","strLocationName":"Brough","strLocationNameWithPrefix":"Brough","strRegionName":"East Yorkshire"},{"intLocationId":"1095","strLocationName":"Cottingham","strLocationNameWithPrefix":"Cottingham","strRegionName":"East Yorkshire"},{"intLocationId":"1127","strLocationName":"Driffield","strLocationNameWithPrefix":"Driffield","strRegionName":"East Yorkshire"},{"intLocationId":"1189","strLocationName":"Goole","strLocationNameWithPrefix":"Goole","strRegionName":"East Yorkshire"},{"intLocationId":"1218","strLocationName":"Hessle","strLocationNameWithPrefix":"Hessle","strRegionName":"East Yorkshire"},{"intLocationId":"1230","strLocationName":"Hornsea","strLocationNameWithPrefix":"Hornsea","strRegionName":"East Yorkshire"},{"intLocationId":"1232","strLocationName":"Hull","strLocationNameWithPrefix":"Hull","strRegionName":"East Yorkshire"},{"intLocationId":"1408","strLocationName":"North Ferriby","strLocationNameWithPrefix":"North Ferriby","strRegionName":"East Yorkshire"},{"intLocationId":"1608","strLocationName":"Withernsea","strLocationNameWithPrefix":"Withernsea","strRegionName":"East 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);
	}
}

