arrRegions = [{"intRegionId":"67","strRegionName":"Oxfordshire","arrLocations":[{"intLocationId":"657","strLocationName":"Abingdon","strLocationNameWithPrefix":"Abingdon","strRegionName":"Oxfordshire"},{"intLocationId":"698","strLocationName":"Bampton","strLocationNameWithPrefix":"Bampton","strRegionName":"Oxfordshire"},{"intLocationId":"697","strLocationName":"Banbury","strLocationNameWithPrefix":"Banbury","strRegionName":"Oxfordshire"},{"intLocationId":"692","strLocationName":"Bicester","strLocationNameWithPrefix":"Bicester","strRegionName":"Oxfordshire"},{"intLocationId":"691","strLocationName":"Brackley","strLocationNameWithPrefix":"Brackley","strRegionName":"Oxfordshire"},{"intLocationId":"685","strLocationName":"Buckingham","strLocationNameWithPrefix":"Buckingham","strRegionName":"Oxfordshire"},{"intLocationId":"699","strLocationName":"Burford","strLocationNameWithPrefix":"Burford","strRegionName":"Oxfordshire"},{"intLocationId":"700","strLocationName":"Carterton","strLocationNameWithPrefix":"Carterton","strRegionName":"Oxfordshire"},{"intLocationId":"702","strLocationName":"Chinnor","strLocationNameWithPrefix":"Chinnor","strRegionName":"Oxfordshire"},{"intLocationId":"696","strLocationName":"Chipping Norton","strLocationNameWithPrefix":"Chipping Norton","strRegionName":"Oxfordshire"},{"intLocationId":"671","strLocationName":"Henley-On-Thames","strLocationNameWithPrefix":"Henley-On-Thames","strRegionName":"Oxfordshire"},{"intLocationId":"678","strLocationName":"High Wycombe","strLocationNameWithPrefix":"High Wycombe","strRegionName":"Oxfordshire"},{"intLocationId":"695","strLocationName":"Kidlington","strLocationNameWithPrefix":"Kidlington","strRegionName":"Oxfordshire"},{"intLocationId":"670","strLocationName":"Lechlade","strLocationNameWithPrefix":"Lechlade","strRegionName":"Oxfordshire"},{"intLocationId":"704","strLocationName":"Moreton-In-Marsh","strLocationNameWithPrefix":"Moreton-In-Marsh","strRegionName":"Oxfordshire"},{"intLocationId":"653","strLocationName":"Oxford","strLocationNameWithPrefix":"Oxford","strRegionName":"Oxfordshire"},{"intLocationId":"658","strLocationName":"Reading","strLocationNameWithPrefix":"Reading","strRegionName":"Oxfordshire"},{"intLocationId":"693","strLocationName":"Thame","strLocationNameWithPrefix":"Thame","strRegionName":"Oxfordshire"},{"intLocationId":"654","strLocationName":"Wallingford","strLocationNameWithPrefix":"Wallingford","strRegionName":"Oxfordshire"},{"intLocationId":"703","strLocationName":"Watlington","strLocationNameWithPrefix":"Watlington","strRegionName":"Oxfordshire"},{"intLocationId":"672","strLocationName":"Witney","strLocationNameWithPrefix":"Witney","strRegionName":"Oxfordshire"},{"intLocationId":"701","strLocationName":"Woodstock","strLocationNameWithPrefix":"Woodstock","strRegionName":"Oxfordshire"}]}]

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

