arrRegions = [{"intRegionId":"117","strRegionName":"County Durham","arrLocations":[{"intLocationId":"1643","strLocationName":"Barnard Castle","strLocationNameWithPrefix":"Barnard Castle","strRegionName":"County Durham"},{"intLocationId":"265","strLocationName":"Billingham","strLocationNameWithPrefix":"Billingham","strRegionName":"County Durham"},{"intLocationId":"1011","strLocationName":"Bishop Auckland","strLocationNameWithPrefix":"Bishop Auckland","strRegionName":"County Durham"},{"intLocationId":"1021","strLocationName":"Boldon Colliery","strLocationNameWithPrefix":"Boldon Colliery","strRegionName":"County Durham"},{"intLocationId":"1676","strLocationName":"Consett","strLocationNameWithPrefix":"Consett","strRegionName":"County Durham"},{"intLocationId":"1105","strLocationName":"Crook","strLocationNameWithPrefix":"Crook","strRegionName":"County Durham"},{"intLocationId":"68","strLocationName":"Darlington","strLocationNameWithPrefix":"Darlington","strRegionName":"County Durham"},{"intLocationId":"58","strLocationName":"Durham","strLocationNameWithPrefix":"Durham","strRegionName":"County Durham"},{"intLocationId":"1145","strLocationName":"East Boldon","strLocationNameWithPrefix":"East Boldon","strRegionName":"County Durham"},{"intLocationId":"259","strLocationName":"Ferryhill","strLocationNameWithPrefix":"Ferryhill","strRegionName":"County Durham"},{"intLocationId":"69","strLocationName":"Hartlepool","strLocationNameWithPrefix":"Hartlepool","strRegionName":"County Durham"},{"intLocationId":"1703","strLocationName":"Hebburn","strLocationNameWithPrefix":"Hebburn","strRegionName":"County Durham"},{"intLocationId":"263","strLocationName":"Newton Aycliffe","strLocationNameWithPrefix":"Newton Aycliffe","strRegionName":"County Durham"},{"intLocationId":"1473","strLocationName":"Rowlands Gill","strLocationNameWithPrefix":"Rowlands Gill","strRegionName":"County Durham"},{"intLocationId":"270","strLocationName":"Shildon","strLocationNameWithPrefix":"Shildon","strRegionName":"County Durham"},{"intLocationId":"1512","strLocationName":"Spennymoor","strLocationNameWithPrefix":"Spennymoor","strRegionName":"County Durham"},{"intLocationId":"67","strLocationName":"Stockton-on-Tees","strLocationNameWithPrefix":"Stockton-on-Tees","strRegionName":"County Durham"},{"intLocationId":"1573","strLocationName":"Trimdon Station","strLocationNameWithPrefix":"Trimdon Station","strRegionName":"County Durham"},{"intLocationId":"1604","strLocationName":"Wingate","strLocationNameWithPrefix":"Wingate","strRegionName":"County Durham"}]}]

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

