arrRegions = [{"intRegionId":"118","strRegionName":"North Yorkshire","arrLocations":[{"intLocationId":"1801","strLocationName":"Barnoldswick","strLocationNameWithPrefix":"Barnoldswick","strRegionName":"North Yorkshire"},{"intLocationId":"999","strLocationName":"Bedale","strLocationNameWithPrefix":"Bedale","strRegionName":"North Yorkshire"},{"intLocationId":"1069","strLocationName":"Catterick Garrison","strLocationNameWithPrefix":"Catterick Garrison","strRegionName":"North Yorkshire"},{"intLocationId":"68","strLocationName":"Darlington","strLocationNameWithPrefix":"Darlington","strRegionName":"North Yorkshire"},{"intLocationId":"1165","strLocationName":"Filey","strLocationNameWithPrefix":"Filey","strRegionName":"North Yorkshire"},{"intLocationId":"1197","strLocationName":"Guisborough","strLocationNameWithPrefix":"Guisborough","strRegionName":"North Yorkshire"},{"intLocationId":"1208","strLocationName":"Hawes","strLocationNameWithPrefix":"Hawes","strRegionName":"North Yorkshire"},{"intLocationId":"1287","strLocationName":"Knaresborough","strLocationNameWithPrefix":"Knaresborough","strRegionName":"North Yorkshire"},{"intLocationId":"1303","strLocationName":"Leyburn","strLocationNameWithPrefix":"Leyburn","strRegionName":"North Yorkshire"},{"intLocationId":"1359","strLocationName":"Malton","strLocationNameWithPrefix":"Malton","strRegionName":"North Yorkshire"},{"intLocationId":"65","strLocationName":"Middlesbrough","strLocationNameWithPrefix":"Middlesbrough","strRegionName":"North Yorkshire"},{"intLocationId":"1411","strLocationName":"Northallerton","strLocationNameWithPrefix":"Northallerton","strRegionName":"North Yorkshire"},{"intLocationId":"1438","strLocationName":"Pickering","strLocationNameWithPrefix":"Pickering","strRegionName":"North Yorkshire"},{"intLocationId":"66","strLocationName":"Redcar","strLocationNameWithPrefix":"Redcar","strRegionName":"North Yorkshire"},{"intLocationId":"1467","strLocationName":"Richmond","strLocationNameWithPrefix":"Richmond","strRegionName":"North Yorkshire"},{"intLocationId":"1469","strLocationName":"Ripon","strLocationNameWithPrefix":"Ripon","strRegionName":"North Yorkshire"},{"intLocationId":"264","strLocationName":"Saltburn-by-The-Sea","strLocationNameWithPrefix":"Saltburn-by-The-Sea","strRegionName":"North Yorkshire"},{"intLocationId":"1488","strLocationName":"Scarborough","strLocationNameWithPrefix":"Scarborough","strRegionName":"North Yorkshire"},{"intLocationId":"1493","strLocationName":"Selby","strLocationNameWithPrefix":"Selby","strRegionName":"North Yorkshire"},{"intLocationId":"1494","strLocationName":"Settle","strLocationNameWithPrefix":"Settle","strRegionName":"North Yorkshire"},{"intLocationId":"949","strLocationName":"Skipton","strLocationNameWithPrefix":"Skipton","strRegionName":"North Yorkshire"},{"intLocationId":"67","strLocationName":"Stockton-on-Tees","strLocationNameWithPrefix":"Stockton-on-Tees","strRegionName":"North Yorkshire"},{"intLocationId":"1543","strLocationName":"Tadcaster","strLocationNameWithPrefix":"Tadcaster","strRegionName":"North Yorkshire"},{"intLocationId":"1555","strLocationName":"Thirsk","strLocationNameWithPrefix":"Thirsk","strRegionName":"North Yorkshire"},{"intLocationId":"1598","strLocationName":"Whitby","strLocationNameWithPrefix":"Whitby","strRegionName":"North Yorkshire"},{"intLocationId":"1615","strLocationName":"Yarm","strLocationNameWithPrefix":"Yarm","strRegionName":"North Yorkshire"},{"intLocationId":"1617","strLocationName":"York","strLocationNameWithPrefix":"York","strRegionName":"North 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);
	}
}
