arrRegions = [{"intRegionId":"135","strRegionName":"Bangalore","arrLocations":[{"intLocationId":"2108","strLocationName":"Adugodi","strLocationNameWithPrefix":"Adugodi","strRegionName":"Bangalore"},{"intLocationId":"2109","strLocationName":"Banashankari","strLocationNameWithPrefix":"Banashankari","strRegionName":"Bangalore"},{"intLocationId":"2110","strLocationName":"Banaswadi","strLocationNameWithPrefix":"Banaswadi","strRegionName":"Bangalore"},{"intLocationId":"2121","strLocationName":"Bangalore City","strLocationNameWithPrefix":"Bangalore City","strRegionName":"Bangalore"},{"intLocationId":"2111","strLocationName":"Basavanagudi","strLocationNameWithPrefix":"Basavanagudi","strRegionName":"Bangalore"},{"intLocationId":"2112","strLocationName":"Basaveshwaranagar","strLocationNameWithPrefix":"Basaveshwaranagar","strRegionName":"Bangalore"},{"intLocationId":"2113","strLocationName":"BTM layout","strLocationNameWithPrefix":"BTM layout","strRegionName":"Bangalore"},{"intLocationId":"2114","strLocationName":"Channapatna","strLocationNameWithPrefix":"Channapatna","strRegionName":"Bangalore"},{"intLocationId":"2115","strLocationName":"Chickpet","strLocationNameWithPrefix":"Chickpet","strRegionName":"Bangalore"},{"intLocationId":"2116","strLocationName":"Doddaballapur","strLocationNameWithPrefix":"Doddaballapur","strRegionName":"Bangalore"},{"intLocationId":"2117","strLocationName":"Doorvaninagar","strLocationNameWithPrefix":"Doorvaninagar","strRegionName":"Bangalore"},{"intLocationId":"2118","strLocationName":"HBR layout","strLocationNameWithPrefix":"HBR layout","strRegionName":"Bangalore"},{"intLocationId":"2119","strLocationName":"Hebbal","strLocationNameWithPrefix":"Hebbal","strRegionName":"Bangalore"},{"intLocationId":"2120","strLocationName":"Hennur","strLocationNameWithPrefix":"Hennur","strRegionName":"Bangalore"},{"intLocationId":"2122","strLocationName":"Indira Nagar","strLocationNameWithPrefix":"Indira Nagar","strRegionName":"Bangalore"},{"intLocationId":"2123","strLocationName":"J. P. Nagar","strLocationNameWithPrefix":"J. P. Nagar","strRegionName":"Bangalore"},{"intLocationId":"2124","strLocationName":"Jakkur","strLocationNameWithPrefix":"Jakkur","strRegionName":"Bangalore"},{"intLocationId":"2125","strLocationName":"Jalahalli","strLocationNameWithPrefix":"Jalahalli","strRegionName":"Bangalore"},{"intLocationId":"2126","strLocationName":"Jayanagar","strLocationNameWithPrefix":"Jayanagar","strRegionName":"Bangalore"},{"intLocationId":"2127","strLocationName":"Jnana Bharathi","strLocationNameWithPrefix":"Jnana Bharathi","strRegionName":"Bangalore"},{"intLocationId":"2128","strLocationName":"Kadugodi Colony","strLocationNameWithPrefix":"Kadugodi Colony","strRegionName":"Bangalore"},{"intLocationId":"2129","strLocationName":"Kamakshipalya","strLocationNameWithPrefix":"Kamakshipalya","strRegionName":"Bangalore"},{"intLocationId":"2130","strLocationName":"Kanakapura","strLocationNameWithPrefix":"Kanakapura","strRegionName":"Bangalore"},{"intLocationId":"2131","strLocationName":"Koramangala","strLocationNameWithPrefix":"Koramangala","strRegionName":"Bangalore"},{"intLocationId":"2132","strLocationName":"Kumaraswamy Layout","strLocationNameWithPrefix":"Kumaraswamy Layout","strRegionName":"Bangalore"},{"intLocationId":"2133","strLocationName":"Laggere","strLocationNameWithPrefix":"Laggere","strRegionName":"Bangalore"},{"intLocationId":"2134","strLocationName":"Mahadevapura Industrial Area","strLocationNameWithPrefix":"Mahadevapura Industrial Area","strRegionName":"Bangalore"},{"intLocationId":"2135","strLocationName":"Nelamangala","strLocationNameWithPrefix":"Nelamangala","strRegionName":"Bangalore"},{"intLocationId":"2148","strLocationName":"Other Locations in Bangalore","strLocationNameWithPrefix":"Other Locations in Bangalore","strRegionName":"Bangalore"},{"intLocationId":"2136","strLocationName":"Peenya Industrial Area","strLocationNameWithPrefix":"Peenya Industrial Area","strRegionName":"Bangalore"},{"intLocationId":"2137","strLocationName":"Puttenahalli","strLocationNameWithPrefix":"Puttenahalli","strRegionName":"Bangalore"},{"intLocationId":"2138","strLocationName":"R.T. Nagar","strLocationNameWithPrefix":"R.T. Nagar","strRegionName":"Bangalore"},{"intLocationId":"2139","strLocationName":"Rajaji Nagar","strLocationNameWithPrefix":"Rajaji Nagar","strRegionName":"Bangalore"},{"intLocationId":"2140","strLocationName":"RajaRajeshwari Nagar","strLocationNameWithPrefix":"RajaRajeshwari Nagar","strRegionName":"Bangalore"},{"intLocationId":"2141","strLocationName":"Ramanagaram","strLocationNameWithPrefix":"Ramanagaram","strRegionName":"Bangalore"},{"intLocationId":"2142","strLocationName":"Sadaramanga Industrial Area","strLocationNameWithPrefix":"Sadaramanga Industrial Area","strRegionName":"Bangalore"},{"intLocationId":"2143","strLocationName":"Sanjeevini Nagar","strLocationNameWithPrefix":"Sanjeevini Nagar","strRegionName":"Bangalore"},{"intLocationId":"2107","strLocationName":"Shanti Nagar","strLocationNameWithPrefix":"Shanti Nagar","strRegionName":"Bangalore"},{"intLocationId":"2144","strLocationName":"Shivaji Nagar","strLocationNameWithPrefix":"Shivaji Nagar","strRegionName":"Bangalore"},{"intLocationId":"2145","strLocationName":"Vimanapura","strLocationNameWithPrefix":"Vimanapura","strRegionName":"Bangalore"},{"intLocationId":"2146","strLocationName":"Whitefield","strLocationNameWithPrefix":"Whitefield","strRegionName":"Bangalore"},{"intLocationId":"2147","strLocationName":"Yeshwantpur","strLocationNameWithPrefix":"Yeshwantpur","strRegionName":"Bangalore"}]}]

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