<!--
// Filename: products.js
// Project : Iceshield.com
// Description: javascript file used on the product pages of the website

	//preload the product sub-navigation
	var icoPrdPropBoots = ROLLOVER_Preload( "./images/icoPrdPropBoots.gif" );
	var icoPrdPropBootsOn = ROLLOVER_Preload( "./images/icoPrdPropBootsOn.gif" );
	var icoPrdWingBoots = ROLLOVER_Preload( "./images/icoPrdWingBoots.gif" );
	var icoPrdWingBootsOn = ROLLOVER_Preload( "./images/icoPrdWingBootsOn.gif" );
	var icoPrdEngInlets = ROLLOVER_Preload( "./images/icoPrdEngInlets.gif" );
	var icoPrdEngInletsOn = ROLLOVER_Preload( "./images/icoPrdEngInletsOn.gif" );
	var icoPrdHarnesses = ROLLOVER_Preload( "./images/icoPrdHarnesses.gif" );
	var icoPrdHarnessesOn = ROLLOVER_Preload( "./images/icoPrdHarnessesOn.gif" );
	var icoPrdAccessories = ROLLOVER_Preload( "./images/icoPrdAccessories.gif" );
	var icoPrdAccessoriesOn = ROLLOVER_Preload( "./images/icoPrdAccessoriesOn.gif" );

	var arrTerms = new Array();
	arrTerms[1] = 'PartTypeID';
	arrTerms[2] = 'Manufacturer';
	arrTerms[3] = 'Model';
	arrTerms[4] = 'Series';
	
	function UpdateProductSearch( lngID )
	{
		var strKeyPN = document.getElementById( 'txtKeyPN' ).value;
		var strTerms = document.getElementById( 'sel' + arrTerms[ lngID ] ).value;
		var objSelMod = document.getElementById( 'sel' + arrTerms[ 3 ] );
		var objSelSer = document.getElementById( 'sel' + arrTerms[ 4 ] );
		if ( lngID == 1 )
		{
			if ( strTerms == '' || parseInt( strTerms ) == 2 || parseInt( strTerms ) == 3 || parseInt( strTerms ) == 5 )
			{
				//hide the plane search drop-downs
				document.getElementById( 'productPlaneSearch' ).style.display = 'none';
			}
			else
			{
				//make sure the plane search drop-downs are visible
				document.getElementById( 'productPlaneSearch' ).style.display = 'block';
			}
		}
		var xmlHttp = AJAX_GetXMLHttp();
		if ( xmlHttp == null )
		{
			alert( "Error: Could not instantiate XmlHttp object." );
			return;
		}
		if ( lngID == 4 && strTerms != '' && strKeyPN == '' )
		{
			//change the action of the form to directly go the product plane view page
			document.getElementById( 'frmProductSearch' ).action = 'productSearchExpress.asp';
			//submit the form
			document.frmProductSearch.submit();
		}
		else
		{
			//make sure the action of the form is set to the default
			document.getElementById( 'frmProductSearch' ).action = 'productSearchResults.asp';
		}
		//update the product search dropdowns
		xmlHttp.open( 'GET', 'xml/productSearchDataXml.asp?ID=' + lngID + '&terms=' + strTerms, true );
		xmlHttp.send( 'ID=' + lngID + '&terms=' + strTerms );
		xmlHttp.onreadystatechange = function()
		{
			if ( xmlHttp.readyState == 4 && xmlHttp.status == 200 )
			{
				//filter the dropdowns on the product search
				UpdateSearchForm( xmlHttp.responseText, lngID, strTerms );
			}
		}
	}
	
	var arrForm = new Array();
	arrForm[1] = 'Manufacturer';
	arrForm[2] = 'Model';
	arrForm[3] = 'Series';
	function UpdateSearchForm( xmlString, lngID, strTerms )
	{
		var xmlDoc;
		var dataset;
		var objSel;
		var strValue = '';
		var i;
		if ( strTerms == '' )
		{
			var objSelMfg = document.getElementById( 'sel' + arrTerms[ 2 ] );
			var objSelMod = document.getElementById( 'sel' + arrTerms[ 3 ] );
			var objSelSer = document.getElementById( 'sel' + arrTerms[ 4 ] );
			//what are you looking for...
			if ( lngID == 1 )
			{
				/*
				objSelMfg.options.length = 0;
				objSelMfg.options[ objSelMfg.options.length ] = new Option( 'Select what you\'re looking for...', '', false, false );
				objSelMfg.disabled = true;
				*/
				objSelMod.options.length = 0;
				objSelMod.options[ objSelMod.options.length ] = new Option( 'Select a Manufacturer...', '', false, false );
				objSelMod.disabled = true;
				objSelSer.options.length = 0;
				objSelSer.options[ objSelSer.options.length ] = new Option( 'Select a Model...', '', false, false );
				objSelSer.disabled = true;
			}
			//plane manufacturer
			if ( lngID == 2 )
			{
				objSelMod.options.length = 0;
				objSelMod.options[ objSelMod.options.length ] = new Option( 'Select a Manufacturer...', '', false, false );
				objSelMod.disabled = true;
				objSelSer.options.length = 0;
				objSelSer.options[ objSelSer.options.length ] = new Option( 'Select a Model...', '', false, false );
				objSelSer.disabled = true;
			}
			//model
			if ( lngID == 3 )
			{
				objSelSer.options.length = 0;
				objSelSer.options[ objSelSer.options.length ] = new Option( 'Select a Model...', '', false, false );
				objSelSer.disabled = true;
			}
		}
		else
		{
			//plane manufacturer or model
			if ( lngID == 2 || lngID == 3 )
			{
				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 = document.getElementById( 'sel' + arrForm[ lngID ] );
				objSel.disabled = false;
				objSel.options.length = 0;
				objSel.options[ objSel.options.length ] = new Option( 'Any ' + arrForm[ lngID ] + '...', '', false, false );
				//get the dataset
				dataset = xmlDoc.getElementsByTagName( 'IceShieldSearchData' );
				if ( dataset.length != 0 )
				{
					//loop through the xml data
					for ( var i=0; i < dataset.length; i++ )
					{
						strValue = dataset[i].childNodes[0].firstChild.nodeValue;
						//update the select box
						objSel.options[ objSel.options.length ] = new Option( strValue, strValue, false, false );
					}
					if ( lngID == 1 )
					{
						UpdateProductSearch( 2 );
					}
					if ( lngID == 2 )
					{
						UpdateProductSearch( 3 );
					}
					if ( lngID == 3 )
					{
						UpdateProductSearch( 4 );
					}
				}
			}
		}
	}
//-->

