arrRegions = [{"intRegionId":"85","strRegionName":"Shropshire","arrLocations":[{"intLocationId":"1646","strLocationName":"Bewdley","strLocationNameWithPrefix":"Bewdley","strRegionName":"Shropshire"},{"intLocationId":"1648","strLocationName":"Bishops Castle","strLocationNameWithPrefix":"Bishops Castle","strRegionName":"Shropshire"},{"intLocationId":"1034","strLocationName":"Bridgnorth","strLocationNameWithPrefix":"Bridgnorth","strRegionName":"Shropshire"},{"intLocationId":"1042","strLocationName":"Broseley","strLocationNameWithPrefix":"Broseley","strRegionName":"Shropshire"},{"intLocationId":"1659","strLocationName":"Bucknell","strLocationNameWithPrefix":"Bucknell","strRegionName":"Shropshire"},{"intLocationId":"1078","strLocationName":"Church Stretton","strLocationNameWithPrefix":"Church Stretton","strRegionName":"Shropshire"},{"intLocationId":"1679","strLocationName":"Craven Arms","strLocationNameWithPrefix":"Craven Arms","strRegionName":"Shropshire"},{"intLocationId":"1151","strLocationName":"Ellesmere","strLocationNameWithPrefix":"Ellesmere","strRegionName":"Shropshire"},{"intLocationId":"1722","strLocationName":"Knighton","strLocationNameWithPrefix":"Knighton","strRegionName":"Shropshire"},{"intLocationId":"1735","strLocationName":"Llanymynech","strLocationNameWithPrefix":"Llanymynech","strRegionName":"Shropshire"},{"intLocationId":"1737","strLocationName":"Ludlow","strLocationNameWithPrefix":"Ludlow","strRegionName":"Shropshire"},{"intLocationId":"1350","strLocationName":"Lydbury North","strLocationNameWithPrefix":"Lydbury North","strRegionName":"Shropshire"},{"intLocationId":"1743","strLocationName":"Market Drayton","strLocationNameWithPrefix":"Market Drayton","strRegionName":"Shropshire"},{"intLocationId":"1748","strLocationName":"Montgomery","strLocationNameWithPrefix":"Montgomery","strRegionName":"Shropshire"},{"intLocationId":"1387","strLocationName":"Much Wenlock","strLocationNameWithPrefix":"Much Wenlock","strRegionName":"Shropshire"},{"intLocationId":"1756","strLocationName":"Oswestry","strLocationNameWithPrefix":"Oswestry","strRegionName":"Shropshire"},{"intLocationId":"1771","strLocationName":"Shifnal","strLocationNameWithPrefix":"Shifnal","strRegionName":"Shropshire"},{"intLocationId":"1773","strLocationName":"Shrewsbury","strLocationNameWithPrefix":"Shrewsbury","strRegionName":"Shropshire"},{"intLocationId":"536","strLocationName":"Telford","strLocationNameWithPrefix":"Telford","strRegionName":"Shropshire"},{"intLocationId":"1784","strLocationName":"Tenbury Wells","strLocationNameWithPrefix":"Tenbury Wells","strRegionName":"Shropshire"},{"intLocationId":"1794","strLocationName":"Welshpool","strLocationNameWithPrefix":"Welshpool","strRegionName":"Shropshire"},{"intLocationId":"1621","strLocationName":"Whitchurch","strLocationNameWithPrefix":"Whitchurch","strRegionName":"Shropshire"}]}]

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

