<!--
	//filename: productUpgrades.js
	//project: transtarindustries.com
	//description: dynamically updates the form elements and product upgrade data lists
	
	function UpdateUpgradeSearch()
	{
		//lose the focus on the select box
		document.getElementById( 'hidFocus' ).focus();
		var lngUmID = document.getElementById( 'selUmID' ).value;
		var xmlHttp = AJAX_GetXMLHttp();
		if ( xmlHttp == null )
		{
			alert( "Error: Could not instantiate XmlHttp object." );
			return;
		}
		//update the product search dropdowns
		xmlHttp.open( 'GET', 'productsUpgradesXml.asp?ID=1&umID=' + lngUmID, true );
		xmlHttp.send( 'ID=1&umID=' + lngUmID );
		xmlHttp.onreadystatechange = function()
		{
			if ( xmlHttp.readyState == 4 && xmlHttp.status == 200 )
			{
				//filter the dropdown
				UpdateUttDropdown( xmlHttp.responseText );
			}
		}
	}
	function UpdateUttDropdown( xmlString )
	{
		var xmlDoc;
		var objSel = document.getElementById( 'selUttID' );
		var dataset;
		var lngUttID = '';
		var strUttName = '';
		var i;
		if ( xmlString.length <= 0 )
		{
			return;
		}
		// Instantiate the xml parser
		xmlDoc = AJAX_GetXMLParser();
		if ( xmlDoc == null )
		{
			alert( "Error: Could not instantiate XML parser." );
			return;
		}
		// Load the XML string
		xmlDoc = AJAX_LoadXML( xmlDoc, xmlString );
		if ( xmlDoc == null )
		{
			alert( "Error: Could not parse XML data." );
			return;
		}
		//get the select box
		objSel.options.length = 0;
		objSel.options[ objSel.options.length ] = new Option( 'Select a Transmission Type...', '', false, false );
		//get the dataset
		dataset = xmlDoc.getElementsByTagName( 'UpgradeTransmissions' );
		if ( dataset.length != 0 )
		{
			//loop through the xml data
			for ( var i=0; i < dataset.length; i++ )
			{
				//assign the values
				lngUttID = dataset[i].childNodes[0].firstChild.nodeValue;
				strUttName = dataset[i].childNodes[1].firstChild.nodeValue;
				//update the select box
				objSel.options[ objSel.options.length ] = new Option( strUttName, lngUttID, false, false );
			}
		}
	}
	function UpdateUpgList()
	{
		//lose the focus on the select box
		document.getElementById( 'hidFocus' ).focus();
		//display the loading notification
		document.getElementById( 'upgLoading' ).style.display = 'block';
		var lngUttID = document.getElementById( 'selUttID' ).value;
		var xmlHttp = AJAX_GetXMLHttp();
		if ( xmlHttp == null )
		{
			alert( "Error: Could not instantiate XmlHttp object." );
			return;
		}
		if ( lngUttID != '' )
		{
			//update the product search dropdowns
			xmlHttp.open( 'GET', 'productsUpgradesXml.asp?ID=2&uttID=' + lngUttID, true );
			xmlHttp.send( 'ID=2&uttID=' + lngUttID );
			xmlHttp.onreadystatechange = function()
			{
				if ( xmlHttp.readyState == 4 && xmlHttp.status == 200 )
				{
					//update the list
					ProcessUpgList( xmlHttp.responseText );
				}
			}
		}
		else
		{
			//hide the loading notification
			document.getElementById( 'upgLoading' ).style.display = 'none';
			//reset the list
			document.getElementById( 'upgList' ).innerHTML = '';
		}
	}
	function ProcessUpgList( xmlString )
	{
		var xmlDoc;
		var dataset;
		var strUpgPartNumber = '';
		var strUpgName = '';
		var strUpgDescription = '';
		var strHtml = '';
		var i;
		if ( xmlString.length <= 0 )
		{
			return;
		}
		// Instantiate the xml parser
		xmlDoc = AJAX_GetXMLParser();
		if ( xmlDoc == null )
		{
			alert( "Error: Could not instantiate XML parser." );
			return;
		}
		// Load the XML string
		xmlDoc = AJAX_LoadXML( xmlDoc, xmlString );
		if ( xmlDoc == null )
		{
			alert( "Error: Could not parse XML data." );
			return;
		}
		//get the dataset
		dataset = xmlDoc.getElementsByTagName( 'UpgradeProducts' );
		if ( dataset.length != 0 )
		{
			//start the table
			strHtml += '<table width=\"450\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\" class=\"tblUpgList\">';
			//create the table header
			strHtml += '<tr class=\"tblUpgHeader\">';
			strHtml += '<td width=\"75\">Part #</td>';
			strHtml += '<td width=\"125\">Part Name</td>';
			strHtml += '<td width=\"250\">Description</td>';
			strHtml += '</tr>';
			//loop through the xml data
			for ( var i=0; i < dataset.length; i++ )
			{
				//assign the values
				strUpgPartNumber = dataset[i].childNodes[0].firstChild.nodeValue;
				strUpgName = dataset[i].childNodes[1].firstChild.nodeValue;
				strUpgDescription = dataset[i].childNodes[2].firstChild.nodeValue;
				strHtml += '<tr class=\"tblUpgData\">';
				strHtml += '<td>' + strUpgPartNumber + '</td>';
				strHtml += '<td>' + strUpgName + '</td>';
				strHtml += '<td>' + strUpgDescription + '</td>';
				strHtml += '</tr>';
			}
			//close up the table
			strHtml += '</table>';
			//hide the loading notification
			document.getElementById( 'upgLoading' ).style.display = 'none';
			//set the content of the Upgrade box
			document.getElementById( 'upgList' ).innerHTML = strHtml;
		}
		else
		{
			//hide the loading notification
			document.getElementById( 'upgLoading' ).style.display = 'none';
			//notify the user
			document.getElementById( 'upgList' ).innerHTML = '<p>There are currently no product upgrades for the selected manufacter and transmission type. Please check back soon for updates.</p>';
		}
	}
	function GetMfgTransmissions()
	{
		if ( document.getElementById( 'selUmID' ).value != '' )
		{
			document.getElementById( 'boxUtt' ).style.display = 'block';
			UpdateUpgradeSearch();
		}
		else
		{
			//hide the loading notification
			document.getElementById( 'upgLoading' ).style.display = 'none';
			//hide the transmission dropdown
			document.getElementById( 'boxUtt' ).style.display = 'none';
			//reset the list
			document.getElementById( 'upgList' ).innerHTML = '';
		}
	}
//-->