arrRegions = [{"intRegionId":"65","strRegionName":"Berkshire","arrLocations":[{"intLocationId":"657","strLocationName":"Abingdon","strLocationNameWithPrefix":"Abingdon","strRegionName":"Berkshire"},{"intLocationId":"666","strLocationName":"Ascot","strLocationNameWithPrefix":"Ascot","strRegionName":"Berkshire"},{"intLocationId":"659","strLocationName":"Bracknell","strLocationNameWithPrefix":"Bracknell","strRegionName":"Berkshire"},{"intLocationId":"188","strLocationName":"Camberley","strLocationNameWithPrefix":"Camberley","strRegionName":"Berkshire"},{"intLocationId":"663","strLocationName":"Crowthorne","strLocationNameWithPrefix":"Crowthorne","strRegionName":"Berkshire"},{"intLocationId":"655","strLocationName":"Didcot","strLocationNameWithPrefix":"Didcot","strRegionName":"Berkshire"},{"intLocationId":"669","strLocationName":"Fairford","strLocationNameWithPrefix":"Fairford","strRegionName":"Berkshire"},{"intLocationId":"605","strLocationName":"Faringdon","strLocationNameWithPrefix":"Faringdon","strRegionName":"Berkshire"},{"intLocationId":"671","strLocationName":"Henley-On-Thames","strLocationNameWithPrefix":"Henley-On-Thames","strRegionName":"Berkshire"},{"intLocationId":"598","strLocationName":"Hungerford","strLocationNameWithPrefix":"Hungerford","strRegionName":"Berkshire"},{"intLocationId":"670","strLocationName":"Lechlade","strLocationNameWithPrefix":"Lechlade","strRegionName":"Berkshire"},{"intLocationId":"667","strLocationName":"Maidenhead","strLocationNameWithPrefix":"Maidenhead","strRegionName":"Berkshire"},{"intLocationId":"668","strLocationName":"Marlow","strLocationNameWithPrefix":"Marlow","strRegionName":"Berkshire"},{"intLocationId":"660","strLocationName":"Newbury","strLocationNameWithPrefix":"Newbury","strRegionName":"Berkshire"},{"intLocationId":"653","strLocationName":"Oxford","strLocationNameWithPrefix":"Oxford","strRegionName":"Berkshire"},{"intLocationId":"658","strLocationName":"Reading","strLocationNameWithPrefix":"Reading","strRegionName":"Berkshire"},{"intLocationId":"673","strLocationName":"Sandhurst","strLocationNameWithPrefix":"Sandhurst","strRegionName":"Berkshire"},{"intLocationId":"664","strLocationName":"Slough","strLocationNameWithPrefix":"Slough","strRegionName":"Berkshire"},{"intLocationId":"587","strLocationName":"Swindon","strLocationNameWithPrefix":"Swindon","strRegionName":"Berkshire"},{"intLocationId":"661","strLocationName":"Thatcham","strLocationNameWithPrefix":"Thatcham","strRegionName":"Berkshire"},{"intLocationId":"654","strLocationName":"Wallingford","strLocationNameWithPrefix":"Wallingford","strRegionName":"Berkshire"},{"intLocationId":"656","strLocationName":"Wantage","strLocationNameWithPrefix":"Wantage","strRegionName":"Berkshire"},{"intLocationId":"665","strLocationName":"Windsor","strLocationNameWithPrefix":"Windsor","strRegionName":"Berkshire"},{"intLocationId":"672","strLocationName":"Witney","strLocationNameWithPrefix":"Witney","strRegionName":"Berkshire"},{"intLocationId":"662","strLocationName":"Wokingham","strLocationNameWithPrefix":"Wokingham","strRegionName":"Berkshire"}]}]

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

