//constant arrays

$(document).ready(function(){
	var selected1;
	var selected2;
	$('#productLine').change(function(){
		$('#productType').empty();
		$('#productName').empty();
		selected1 = this.options[this.selectedIndex].value;
		if(selected1 != 'none'){
			$.ajax({
				type:"GET",
				url:"/script/xml/products.xml",
				datatype:"xml",
				success: function(xml){
					var addBlank = document.createElement('option');
					with(addBlank){
						value = 'none';
					}
					var blankText = document.createTextNode('-- Please Select One --');
					addBlank.appendChild(blankText);
					$('#productType').append(addBlank);
					$(xml).find("line[value='"+selected1+"']").each(function(){
						$(this).find('type').each(function(){
							var addOption = document.createElement('option');
							var addText = document.createTextNode($(this).attr('value'));
							addOption.appendChild(addText);
							$('#productType').append(addOption);
						});
					});
				}
			});
			$('#productType').attr("disabled", "");
		}else{
			$('#productType').attr("disabled", "disabled");
		}
		$('#productName').attr("disabled", "disabled");		
	});
	$('#productType').change(function(){
		selected2 = this.options[this.selectedIndex].value;
		$('#productName').empty();
		if(selected2 != 'none'){
			$.ajax({
				type:"GET",
				url:"/script/xml/products.xml",
				datatype:"xml",
				success: function(xml){
					$(xml).find("line[value='"+selected1+"']").each(function(){
						$(this).find("type[value='"+selected2+"']").each(function(){
							$(this).find("name").each(function(){
								var addOption = document.createElement('option');
								var addText = document.createTextNode($(this).text());
								addOption.appendChild(addText);
								$('#productName').append(addOption);
							});
						});
					});
				}
			});
			$('#productName').attr("disabled", "");
		}else{
			$('#productName').attr("disabled", "disabled");
		}
	});

});