arrRegions = [{"intRegionId":"61","strRegionName":"Warwickshire","arrLocations":[{"intLocationId":"1629","strLocationName":"Alcester","strLocationNameWithPrefix":"Alcester","strRegionName":"Warwickshire"},{"intLocationId":"1636","strLocationName":"Atherstone","strLocationNameWithPrefix":"Atherstone","strRegionName":"Warwickshire"},{"intLocationId":"516","strLocationName":"Bedworth","strLocationNameWithPrefix":"Bedworth","strRegionName":"Warwickshire"},{"intLocationId":"541","strLocationName":"D.I.R.F.T","strLocationNameWithPrefix":"D.I.R.F.T","strRegionName":"Warwickshire"},{"intLocationId":"1690","strLocationName":"Evesham","strLocationNameWithPrefix":"Evesham","strRegionName":"Warwickshire"},{"intLocationId":"1216","strLocationName":"Henley-In-Arden","strLocationNameWithPrefix":"Henley-In-Arden","strRegionName":"Warwickshire"},{"intLocationId":"106","strLocationName":"Kenilworth","strLocationNameWithPrefix":"Kenilworth","strRegionName":"Warwickshire"},{"intLocationId":"108","strLocationName":"Leamington Spa","strLocationNameWithPrefix":"Leamington Spa","strRegionName":"Warwickshire"},{"intLocationId":"544","strLocationName":"Magna Park","strLocationNameWithPrefix":"Magna Park","strRegionName":"Warwickshire"},{"intLocationId":"545","strLocationName":"Meriden","strLocationNameWithPrefix":"Meriden","strRegionName":"Warwickshire"},{"intLocationId":"517","strLocationName":"Nuneaton","strLocationNameWithPrefix":"Nuneaton","strRegionName":"Warwickshire"},{"intLocationId":"111","strLocationName":"Rugby","strLocationNameWithPrefix":"Rugby","strRegionName":"Warwickshire"},{"intLocationId":"1772","strLocationName":"Shipston-On-Stour","strLocationNameWithPrefix":"Shipston-On-Stour","strRegionName":"Warwickshire"},{"intLocationId":"546","strLocationName":"Southam","strLocationNameWithPrefix":"Southam","strRegionName":"Warwickshire"},{"intLocationId":"547","strLocationName":"Stoneleigh","strLocationNameWithPrefix":"Stoneleigh","strRegionName":"Warwickshire"},{"intLocationId":"114","strLocationName":"Stratford-upon-Avon","strLocationNameWithPrefix":"Stratford-upon-Avon","strRegionName":"Warwickshire"},{"intLocationId":"1538","strLocationName":"Studley","strLocationNameWithPrefix":"Studley","strRegionName":"Warwickshire"},{"intLocationId":"118","strLocationName":"Warwick","strLocationNameWithPrefix":"Warwick","strRegionName":"Warwickshire"}]}]

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