

var optionList
var addOption
var addOptionText
var messageCount
var optionListOptions


function populateMesh(obj) {
	
	optionList = document.getElementById("meshType")
	optionListOptions = optionList.getElementsByTagName("option")

	messageCount = optionListOptions.length


		addOption = document.createElement("option")
		addOption.value = -1		
		addOptionText = document.createTextNode("Select Mesh Type")	
		addOption.appendChild(addOptionText)	
		optionList.appendChild(addOption)
		
		if(obj.value == -1){
			
		document.getElementById("meshType").disabled = true
		document.getElementById("unitMeasure").disabled = true
		document.getElementById("sieveSearch").disabled = true
		document.getElementById("sieveSearch").style.backgroundImage = "url(images/sievesearch_disabled.jpg)"
		document.getElementById("aperture").value = "Type Aperture Size"
		document.getElementById("aperture").disabled = true

		clearOutOptionList()
	
		return false
	
		}
		
		clearOutOptionList()
		document.getElementById("unitMeasure").disabled = true
		document.getElementById("sieveSearch").disabled = true
		document.getElementById("sieveSearch").style.backgroundImage = "url(images/sievesearch_disabled.jpg)"	
		document.getElementById("aperture").value = "Type Aperture Size"
		document.getElementById("aperture").disabled = true
		
	
	if((obj.value == 1) || (obj.value == 2) || (obj.value == 5) || (obj.value == 6)){
		
	
		addOption = document.createElement("option")
		addOption.value = 0		
		addOptionText = document.createTextNode("Woven Wire")		
		addOption.appendChild(addOptionText)	
		optionList.appendChild(addOption)	
		
	}
	
	
	else {
			

		addOption = document.createElement("option")
		addOption.value = 0		
		addOptionText = document.createTextNode("Woven Wire")		
		addOption.appendChild(addOptionText)	
		optionList.appendChild(addOption)
		
		addOption = document.createElement("option")
		addOption.value = 1		
		addOptionText = document.createTextNode("Perforated Plate")		
		addOption.appendChild(addOptionText)	
		optionList.appendChild(addOption)		
		
	}
	
		document.getElementById("meshType").disabled = false
	
	
}



function populateUom(obj){
		
	optionList = document.getElementById("unitMeasure")
	optionListOptions = optionList.getElementsByTagName("option")
	
	messageCount = optionListOptions.length
	
	
		addOption = document.createElement("option")
		addOption.value = -1
		addOptionText = document.createTextNode("Select Measurement")
		addOption.appendChild(addOptionText)
		optionList.appendChild(addOption)
		
			
		if(obj.value == -1){
			
		document.getElementById("unitMeasure").disabled = true
		document.getElementById("aperture").disabled = true
		document.getElementById("sieveSearch").disabled = true
		document.getElementById("sieveSearch").style.backgroundImage = "url(images/sievesearch_disabled.jpg)"
		document.getElementById("aperture").value = "Type Aperture Size"
		
		clearOutOptionList()
	
		return false

		}
	
		clearOutOptionList()
		document.getElementById("aperture").value = "Type Aperture Size"
		document.getElementById("aperture").disabled = true
		document.getElementById("sieveSearch").disabled = true
		document.getElementById("sieveSearch").style.backgroundImage = "url(images/sievesearch_disabled.jpg)"
	
		if(obj.value == 0){
		
		addOption = document.createElement("option")
		addOption.value = 0
		addOptionText = document.createTextNode("mm")
		addOption.appendChild(addOptionText)
		optionList.appendChild(addOption)
		
		addOption = document.createElement("option")
		addOption.value = 1
		addOptionText = document.createTextNode("microns")
		addOption.appendChild(addOptionText)
		optionList.appendChild(addOption)
		
		}		
	
	
		if(obj.value == 1){
		
		addOption = document.createElement("option")
		addOption.value = 0
		addOptionText = document.createTextNode("mm")
		addOption.appendChild(addOptionText)
		optionList.appendChild(addOption)
		
		}		
		
		document.getElementById("unitMeasure").disabled = false
}



function showAperture() {
	
		if((document.getElementById("unitMeasure").value == -1) || (document.getElementById("meshType").value == -1)){
			
			return false
			
		}
		
		document.getElementById("aperture").value = ""	
		document.getElementById("aperture").disabled = false
	
		
}

function showSubmit() {
	
		document.getElementById("sieveSearch").disabled = false
		document.getElementById("sieveSearch").style.backgroundImage = "url(images/sievesearch_off.jpg)"
	
}

function clearAperture(obj) {
	
		obj.value = ""	
}



function clearOutOptionList() {
	
//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 = optionListOptions[0]

		
				optionList.removeChild(thisOption)
	

			}

		}	
	
}


