arrRegions = [{"intRegionId":"62","strRegionName":"Hertfordshire","arrLocations":[{"intLocationId":"578","strLocationName":"Abbots Langley","strLocationNameWithPrefix":"Abbots Langley","strRegionName":"Hertfordshire"},{"intLocationId":"570","strLocationName":"Baldock","strLocationNameWithPrefix":"Baldock","strRegionName":"Hertfordshire"},{"intLocationId":"558","strLocationName":"Barnet","strLocationNameWithPrefix":"Barnet","strRegionName":"Hertfordshire"},{"intLocationId":"564","strLocationName":"Berkhamsted","strLocationNameWithPrefix":"Berkhamsted","strRegionName":"Hertfordshire"},{"intLocationId":"446","strLocationName":"Bishop's Stortford","strLocationNameWithPrefix":"Bishop's Stortford","strRegionName":"Hertfordshire"},{"intLocationId":"579","strLocationName":"Borehamwood","strLocationNameWithPrefix":"Borehamwood","strRegionName":"Hertfordshire"},{"intLocationId":"561","strLocationName":"Broxbourne","strLocationNameWithPrefix":"Broxbourne","strRegionName":"Hertfordshire"},{"intLocationId":"572","strLocationName":"Buntingford","strLocationNameWithPrefix":"Buntingford","strRegionName":"Hertfordshire"},{"intLocationId":"585","strLocationName":"Bushey","strLocationNameWithPrefix":"Bushey","strRegionName":"Hertfordshire"},{"intLocationId":"582","strLocationName":"Dunstable","strLocationNameWithPrefix":"Dunstable","strRegionName":"Hertfordshire"},{"intLocationId":"513","strLocationName":"Harlow","strLocationNameWithPrefix":"Harlow","strRegionName":"Hertfordshire"},{"intLocationId":"552","strLocationName":"Harpenden","strLocationNameWithPrefix":"Harpenden","strRegionName":"Hertfordshire"},{"intLocationId":"555","strLocationName":"Hatfield","strLocationNameWithPrefix":"Hatfield","strRegionName":"Hertfordshire"},{"intLocationId":"563","strLocationName":"Hemel Hempstead","strLocationNameWithPrefix":"Hemel Hempstead","strRegionName":"Hertfordshire"},{"intLocationId":"575","strLocationName":"Hertford","strLocationNameWithPrefix":"Hertford","strRegionName":"Hertfordshire"},{"intLocationId":"568","strLocationName":"Hitchin","strLocationNameWithPrefix":"Hitchin","strRegionName":"Hertfordshire"},{"intLocationId":"562","strLocationName":"Hoddesdon","strLocationNameWithPrefix":"Hoddesdon","strRegionName":"Hertfordshire"},{"intLocationId":"577","strLocationName":"Kings Langley","strLocationNameWithPrefix":"Kings Langley","strRegionName":"Hertfordshire"},{"intLocationId":"567","strLocationName":"Knebworth","strLocationNameWithPrefix":"Knebworth","strRegionName":"Hertfordshire"},{"intLocationId":"569","strLocationName":"Letchworth Garden City","strLocationNameWithPrefix":"Letchworth Garden City","strRegionName":"Hertfordshire"},{"intLocationId":"583","strLocationName":"Luton","strLocationNameWithPrefix":"Luton","strRegionName":"Hertfordshire"},{"intLocationId":"573","strLocationName":"Much Hadham","strLocationNameWithPrefix":"Much Hadham","strRegionName":"Hertfordshire"},{"intLocationId":"559","strLocationName":"Potters Bar","strLocationNameWithPrefix":"Potters Bar","strRegionName":"Hertfordshire"},{"intLocationId":"580","strLocationName":"Radlett","strLocationNameWithPrefix":"Radlett","strRegionName":"Hertfordshire"},{"intLocationId":"576","strLocationName":"Rickmansworth","strLocationNameWithPrefix":"Rickmansworth","strRegionName":"Hertfordshire"},{"intLocationId":"571","strLocationName":"Royston","strLocationNameWithPrefix":"Royston","strRegionName":"Hertfordshire"},{"intLocationId":"556","strLocationName":"Sawbridgeworth","strLocationNameWithPrefix":"Sawbridgeworth","strRegionName":"Hertfordshire"},{"intLocationId":"551","strLocationName":"St. Albans","strLocationNameWithPrefix":"St. Albans","strRegionName":"Hertfordshire"},{"intLocationId":"566","strLocationName":"Stevenage","strLocationNameWithPrefix":"Stevenage","strRegionName":"Hertfordshire"},{"intLocationId":"565","strLocationName":"Tring","strLocationNameWithPrefix":"Tring","strRegionName":"Hertfordshire"},{"intLocationId":"560","strLocationName":"Waltham Cross","strLocationNameWithPrefix":"Waltham Cross","strRegionName":"Hertfordshire"},{"intLocationId":"574","strLocationName":"Ware","strLocationNameWithPrefix":"Ware","strRegionName":"Hertfordshire"},{"intLocationId":"581","strLocationName":"Watford","strLocationNameWithPrefix":"Watford","strRegionName":"Hertfordshire"},{"intLocationId":"553","strLocationName":"Welwyn","strLocationNameWithPrefix":"Welwyn","strRegionName":"Hertfordshire"},{"intLocationId":"554","strLocationName":"Welwyn Garden City","strLocationNameWithPrefix":"Welwyn Garden City","strRegionName":"Hertfordshire"}]}]

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

