arrRegions = [{"intRegionId":"60","strRegionName":"Cheshire","arrLocations":[{"intLocationId":"958","strLocationName":"Alderley Edge","strLocationNameWithPrefix":"Alderley Edge","strRegionName":"Cheshire"},{"intLocationId":"225","strLocationName":"Appleton","strLocationNameWithPrefix":"Appleton","strRegionName":"North Cheshire"},{"intLocationId":"216","strLocationName":"Ashton-in-Makerfield","strLocationNameWithPrefix":"Ashton-in-Makerfield","strRegionName":"North Cheshire"},{"intLocationId":"221","strLocationName":"Birchwood","strLocationNameWithPrefix":"Birchwood","strRegionName":"North Cheshire"},{"intLocationId":"215","strLocationName":"Burtonwood","strLocationNameWithPrefix":"Burtonwood","strRegionName":"North Cheshire"},{"intLocationId":"1072","strLocationName":"Cheadle","strLocationNameWithPrefix":"Cheadle","strRegionName":"Cheshire"},{"intLocationId":"414","strLocationName":"Chester","strLocationNameWithPrefix":"Chester","strRegionName":"West Cheshire"},{"intLocationId":"944","strLocationName":"Congleton","strLocationNameWithPrefix":"Congleton","strRegionName":"Cheshire"},{"intLocationId":"945","strLocationName":"Crewe","strLocationNameWithPrefix":"Crewe","strRegionName":"Cheshire"},{"intLocationId":"415","strLocationName":"Deeside","strLocationNameWithPrefix":"Deeside","strRegionName":"West Cheshire"},{"intLocationId":"1131","strLocationName":"Dukinfield","strLocationNameWithPrefix":"Dukinfield","strRegionName":"Cheshire"},{"intLocationId":"416","strLocationName":"Ellesmere Port","strLocationNameWithPrefix":"Ellesmere Port","strRegionName":"West Cheshire"},{"intLocationId":"417","strLocationName":"Flint","strLocationNameWithPrefix":"Flint","strRegionName":"West Cheshire"},{"intLocationId":"1176","strLocationName":"Frodsham","strLocationNameWithPrefix":"Frodsham","strRegionName":"Cheshire"},{"intLocationId":"217","strLocationName":"Golborne","strLocationNameWithPrefix":"Golborne","strRegionName":"North Cheshire"},{"intLocationId":"1707","strLocationName":"High Peak","strLocationNameWithPrefix":"High Peak","strRegionName":"Cheshire"},{"intLocationId":"1234","strLocationName":"Hyde","strLocationNameWithPrefix":"Hyde","strRegionName":"Cheshire"},{"intLocationId":"946","strLocationName":"Knutsford","strLocationNameWithPrefix":"Knutsford","strRegionName":"Cheshire"},{"intLocationId":"219","strLocationName":"Leigh","strLocationNameWithPrefix":"Leigh","strRegionName":"North Cheshire"},{"intLocationId":"1352","strLocationName":"Lymm","strLocationNameWithPrefix":"Lymm","strRegionName":"Cheshire"},{"intLocationId":"130","strLocationName":"Macclesfield","strLocationNameWithPrefix":"Macclesfield","strRegionName":"Cheshire"},{"intLocationId":"1741","strLocationName":"Malpas","strLocationNameWithPrefix":"Malpas","strRegionName":"Cheshire"},{"intLocationId":"422","strLocationName":"Middlewich","strLocationNameWithPrefix":"Middlewich","strRegionName":"West Cheshire"},{"intLocationId":"421","strLocationName":"Nantwich","strLocationNameWithPrefix":"Nantwich","strRegionName":"West Cheshire"},{"intLocationId":"1391","strLocationName":"Neston","strLocationNameWithPrefix":"Neston","strRegionName":"Cheshire"},{"intLocationId":"218","strLocationName":"Newton-le-Willows","strLocationNameWithPrefix":"Newton-le-Willows","strRegionName":"North Cheshire"},{"intLocationId":"420","strLocationName":"Northwich","strLocationNameWithPrefix":"Northwich","strRegionName":"West Cheshire"},{"intLocationId":"227","strLocationName":"Other","strLocationNameWithPrefix":"Other","strRegionName":"North Cheshire"},{"intLocationId":"423","strLocationName":"Other","strLocationNameWithPrefix":"Other","strRegionName":"West Cheshire"},{"intLocationId":"1453","strLocationName":"Prenton","strLocationNameWithPrefix":"Prenton","strRegionName":"Cheshire"},{"intLocationId":"222","strLocationName":"Runcorn","strLocationNameWithPrefix":"Runcorn","strRegionName":"North Cheshire"},{"intLocationId":"1480","strLocationName":"Sale","strLocationNameWithPrefix":"Sale","strRegionName":"Cheshire"},{"intLocationId":"947","strLocationName":"Sandbach","strLocationNameWithPrefix":"Sandbach","strRegionName":"Cheshire"},{"intLocationId":"223","strLocationName":"St. Helens","strLocationNameWithPrefix":"St. Helens","strRegionName":"North Cheshire"},{"intLocationId":"1779","strLocationName":"Stalybridge","strLocationNameWithPrefix":"Stalybridge","strRegionName":"Cheshire"},{"intLocationId":"1546","strLocationName":"Tarporley","strLocationNameWithPrefix":"Tarporley","strRegionName":"Cheshire"},{"intLocationId":"214","strLocationName":"Warrington","strLocationNameWithPrefix":"Warrington","strRegionName":"North Cheshire"},{"intLocationId":"224","strLocationName":"Widnes","strLocationNameWithPrefix":"Widnes","strRegionName":"North Cheshire"},{"intLocationId":"948","strLocationName":"Wilmslow","strLocationNameWithPrefix":"Wilmslow","strRegionName":"Cheshire"},{"intLocationId":"419","strLocationName":"Winsford","strLocationNameWithPrefix":"Winsford","strRegionName":"West Cheshire"},{"intLocationId":"220","strLocationName":"Winwick","strLocationNameWithPrefix":"Winwick","strRegionName":"North Cheshire"},{"intLocationId":"226","strLocationName":"Woolston","strLocationNameWithPrefix":"Woolston","strRegionName":"North Cheshire"},{"intLocationId":"300","strLocationName":"Wrexham","strLocationNameWithPrefix":"Wrexham","strRegionName":"West Cheshire"}]}]

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);
	}
}
