arrRegions = [{"intRegionId":"87","strRegionName":"Worcestershire","arrLocations":[{"intLocationId":"1629","strLocationName":"Alcester","strLocationNameWithPrefix":"Alcester","strRegionName":"Worcestershire"},{"intLocationId":"1646","strLocationName":"Bewdley","strLocationNameWithPrefix":"Bewdley","strRegionName":"Worcestershire"},{"intLocationId":"1656","strLocationName":"Broadway","strLocationNameWithPrefix":"Broadway","strRegionName":"Worcestershire"},{"intLocationId":"1657","strLocationName":"Bromyard","strLocationNameWithPrefix":"Bromyard","strRegionName":"Worcestershire"},{"intLocationId":"1669","strLocationName":"Cheltenham","strLocationNameWithPrefix":"Cheltenham","strRegionName":"Worcestershire"},{"intLocationId":"1670","strLocationName":"Chipping Campden","strLocationNameWithPrefix":"Chipping Campden","strRegionName":"Worcestershire"},{"intLocationId":"103","strLocationName":"Droitwich","strLocationNameWithPrefix":"Droitwich","strRegionName":"Worcestershire"},{"intLocationId":"1690","strLocationName":"Evesham","strLocationNameWithPrefix":"Evesham","strRegionName":"Worcestershire"},{"intLocationId":"1699","strLocationName":"Gloucester","strLocationNameWithPrefix":"Gloucester","strRegionName":"Worcestershire"},{"intLocationId":"105","strLocationName":"Halesowen","strLocationNameWithPrefix":"Halesowen","strRegionName":"Worcestershire"},{"intLocationId":"107","strLocationName":"Kidderminster","strLocationNameWithPrefix":"Kidderminster","strRegionName":"Worcestershire"},{"intLocationId":"1727","strLocationName":"Ledbury","strLocationNameWithPrefix":"Ledbury","strRegionName":"Worcestershire"},{"intLocationId":"1742","strLocationName":"Malvern","strLocationNameWithPrefix":"Malvern","strRegionName":"Worcestershire"},{"intLocationId":"1755","strLocationName":"Oldbury","strLocationNameWithPrefix":"Oldbury","strRegionName":"Worcestershire"},{"intLocationId":"1435","strLocationName":"Pershore","strLocationNameWithPrefix":"Pershore","strRegionName":"Worcestershire"},{"intLocationId":"110","strLocationName":"Redditch","strLocationNameWithPrefix":"Redditch","strRegionName":"Worcestershire"},{"intLocationId":"1772","strLocationName":"Shipston-On-Stour","strLocationNameWithPrefix":"Shipston-On-Stour","strRegionName":"Worcestershire"},{"intLocationId":"1775","strLocationName":"Smethwick","strLocationNameWithPrefix":"Smethwick","strRegionName":"Worcestershire"},{"intLocationId":"1528","strLocationName":"Stourport-On-Severn","strLocationNameWithPrefix":"Stourport-On-Severn","strRegionName":"Worcestershire"},{"intLocationId":"1784","strLocationName":"Tenbury Wells","strLocationNameWithPrefix":"Tenbury Wells","strRegionName":"Worcestershire"},{"intLocationId":"1785","strLocationName":"Tewkesbury","strLocationNameWithPrefix":"Tewkesbury","strRegionName":"Worcestershire"},{"intLocationId":"121","strLocationName":"Worcester","strLocationNameWithPrefix":"Worcester","strRegionName":"Worcestershire"}]}]

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

