var localAreaList = new Array()


//create our object constructor for the country / region list of the properties
function localArea(regionRef, localRef, regionName) {
	
	
	this[0] = regionRef
	this[1] = localRef
	this[2] = regionName
	
}


function populateLocalAreas(selectedRegion) {
	
	
	var addOption
	var addOptionText
	var regionList = document.getElementById("requestedLocal")
	var regionListOptions = regionList.getElementsByTagName("option")
	
	//we need to store the original length of the regionListOptions array, as this will change as we delete elements
	var messageCount = regionListOptions.length
	var thisOption
	
	

	//first remove any existing messages from the select option

		if(messageCount > 0){
		
			for(var j = 0; j < messageCount; j++) {
			
				//we always specify the exact array location, as we remove elements from the list so the array dynamically resizes.
				//location 2 becomes location 1 and location 1 becomes location 0 etc.
				//we leave location 0 intact as it has the 'please select' message
				thisOption = regionListOptions[0]

		
				regionList.removeChild(thisOption)
	

			}

		}
		
		
		
		addOption = document.createElement("option")
		addOption.value = "0"
		
		addOptionText = document.createTextNode("select sub-region")
		
		addOption.appendChild(addOptionText)
		
		regionList.appendChild(addOption)

		

	
	for( var i = 0; i < localAreaList.length; i++){	
	
	
		if(localAreaList[i][0] == selectedRegion) {
			
			//alert(localAreaList[i][1])
			
			
		addOption = document.createElement("option")
		addOption.value = localAreaList[i][1]
		
		addOptionText = document.createTextNode(localAreaList[i][2])
		
		addOption.appendChild(addOptionText)
		
		regionList.appendChild(addOption)

	

		}
		
	}
	
	
}
