var productName = new Array();
var prodIdValue = new Array();
var x;
var y;
var xmlhttp;
var response;

function loadXMLDoc(url){
	xmlhttp=null;
	
	// code for Mozilla, etc.
	if (window.XMLHttpRequest)
	{
	xmlhttp=new XMLHttpRequest()
	}
	// code for IE
	else if (window.ActiveXObject)
	{
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
	
	if (xmlhttp!=null)
	{
	xmlhttp.onreadystatechange=state_Change
	xmlhttp.open("GET",url,true)
	xmlhttp.send(null)
	}		
	else
	{
	alert("Your browser does not support XMLHTTP.")
	}
}
function state_Change() {
	if (xmlhttp.readyState==4) {
		// if "OK"
		if (xmlhttp.status==200) {
		response = (xmlhttp.responseText);
		importXML();
		} 
	}
}
function importXML(){
//import xml
	
	if (document.implementation && document.implementation.createDocument) {
		xmlDoc = document.implementation.createDocument("", "", null);
		xmlDoc.onload = CreateArrayValues;
	} else if (window.ActiveXObject){
		xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		
		xmlDoc.onreadystatechange = function () {
			if (xmlDoc.readyState == 4) CreateArrayValues()			
		};
	} else {
		alert('Your browser can\'t handle this script');
		return;
	}
	
	// code for IE
	if (window.ActiveXObject){
	xmlDoc.loadXML(response);
	}else{// code for Mozilla, Firefox, Opera, etc.
	var parser=new DOMParser();
	xmlDoc=parser.parseFromString(response,"text/xml");
	CreateArrayValues();
	}
}

function CreateArrayValues()
{
	x = null;
	x = xmlDoc.getElementsByTagName('Product');
	if (x.length>0){
		for (i=0;i<x.length;i++){
			productName[i] = (x[i].childNodes[0].firstChild.nodeValue);
			prodIdValue[i] = (x[i].childNodes[1].firstChild.nodeValue);
		} //end for loop
		WriteOptions();
	}else {
	document.getElementById('productSelect').options.length = 0;
	document.getElementById('productSelect').options[0] = new Option('Problem Loading Products  ','');
	}
}
function WriteOptions() {
		//erase all current options
		document.getElementById('productSelect').options.length = 0;
		
		var j=1;
		document.getElementById('productSelect').options[0] = new Option('Select Product From List','');

	//iterate through array and add options for each
	for (var i=0;i<x.length;i++){
		if (productName[i] == null){
		//do nothing and don't increment j
		} else {
			document.getElementById('productSelect').options[j] = new Option(productName[i],prodIdValue[i]);
			j++;
			productName[i] = null;
			prodIdValue[i] = null;
		}//end if else
	}//end for loop
	
	if (j==0){
	document.getElementById('productSelect').options[0] = new Option('No Products Available  ','');
	document.getElementById('productSelect').disabled = true;
	}else {
	//enable text box and submit button, hide Disabled button
	document.getElementById('productSelect').disabled = false;
	}
}
function EnableGetParts(){
	if (document.getElementById('productSelect').value == ""){
	document.getElementById('submitParts').style.display = "none";
	document.getElementById('submitPartsDisabled').style.display = "block";
	}else{
	document.getElementById('submitPartsDisabled').style.display = "none";
	document.getElementById('submitParts').style.display = "block";
	}
}
