<!--
// Filename: products.js
// Project : nzmfg.com
// Description: javascript file used for product view pages

	
	function UpdateSKU( strSkuCode, strSkuListPrice, strSkuAccPrice, strSkuListPriceD, strSkuAccPriceD, lngSkuPpsID )
	{
		var objSKU;
		var objSkuListPrice;
		var objSkuListPriceD;
		var objSkuListPriceDBlock;
		var objSkuAccPrice;
		var objSkuAccPriceBlock;
		var objSkuAccPriceD;
		var objSkuAccPriceDBlock;
		var blnPriceReduction = false;
		
		//set up the price target objects
		objSKU = document.getElementById( 'DisplaySKU' );
		objSkuListPrice = document.getElementById( 'SkuListPrice' );
		objSkuListPriceD = document.getElementById( 'SkuListPriceD' );
		objSkuListPriceDBlock = document.getElementById( 'SkuListPriceDBlock' );
		objSkuAccPrice = document.getElementById( 'SkuAccPrice' );
		objSkuAccPriceBlock = document.getElementById( 'SkuAccPriceBlock' );
		objSkuAccPriceD = document.getElementById( 'SkuAccPriceD' );
		objSkuAccPriceDBlock = document.getElementById( 'SkuAccPriceDBlock' );
		
		//set the sku code label
		objSKU.innerHTML = strSkuCode;
		
		//always display the list price, unless it is zero
		if ( strSkuListPrice != '$0.00' )
		{
			objSkuListPrice.innerHTML = strSkuListPrice;
		}
		else
		{
			objSkuListPrice.innerHTML = '<span>Price Temporarily Unavailable</span>';
		}
		
		//check for an account price
		if ( strSkuAccPrice != '$0.00' )
		{
			//check account discount price
			if ( strSkuAccPriceD != '$0.00' )
			{
				//strike through the account price
				objSkuAccPrice.style.textDecoration = 'line-through';
				//set the discount account price and display
				//account normal price
				objSkuAccPrice.innerHTML = strSkuAccPrice;
				objSkuAccPriceBlock.style.display = 'block';
				//account discount price
				objSkuAccPriceD.innerHTML = strSkuAccPriceD;
				objSkuAccPriceDBlock.style.display = 'block';
				blnPriceReduction = true;
			}
			else
			{
				//remove any strike through
				objSkuAccPrice.style.textDecoration = 'none';
				//account normal price
				objSkuAccPrice.innerHTML = strSkuAccPrice;
				objSkuAccPriceBlock.style.display = 'block';
				//account discount price
				objSkuAccPriceD.innerHTML = '';
				objSkuAccPriceDBlock.style.display = 'none';
			}
		}
		else
		{
			objSkuAccPriceBlock.style.display = 'none';
			//check customer discount price
			if ( strSkuListPriceD != '$0.00' )
			{
				//strike through the list price
				objSkuListPrice.style.textDecoration = 'line-through';
				//set the discount list price and display
				objSkuListPriceD.innerHTML = strSkuListPriceD;
				objSkuListPriceDBlock.style.display = 'block';
				blnPriceReduction = true;
			}
			else
			{
				//remove any strike through
				objSkuListPrice.style.textDecoration = 'none';
				//clear any previous discount price and hide
				objSkuListPriceD.innerHTML = '';
				objSkuListPriceDBlock.style.display = 'none';
			}
		}
		
		//check the pricing status ID and display the image if necessary
		if ( lngSkuPpsID != 0 && blnPriceReduction == true )
		{
			if ( objImg = document.getElementById( 'prdSpecialImg' + lngSkuPpsID ) )
			{
				objImg.style.display = 'block';
				// make sure the other image is not displayed
				if ( lngSkuPpsID == 2 )
				{
					if ( objImg1 = document.getElementById( 'prdSpecialImg1' ) )
					{
						objImg1.style.display = 'none';
					}
				}
				if ( lngSkuPpsID == 1 )
				{
					if ( objImg2 = document.getElementById( 'prdSpecialImg2' ) )
					{
						objImg2.style.display = 'none';
					}
				}
			}
		}
		else
		{
			// make sure the images are not displayed
			if ( objImg1 = document.getElementById( 'prdSpecialImg1' ) )
			{
				objImg1.style.display = 'none';
			}
			if ( objImg2 = document.getElementById( 'prdSpecialImg2' ) )
			{
				objImg2.style.display = 'none';
			}
		}
	}

	function Validate()
	{
		if ( objSelLen = document.frmProduct.selLenID )
		{
			if ( objSelLen.value == '' )
			{
				alert( 'Please select length.' );
				return false;
			}
		}
		if( objSkuSet = document.getElementById( 'hidSkuSet' ) )
		{
			if ( objSkuSet.value == '1' )
			{
				if ( objProductSkuSet = document.frmProduct.radProductSkuSet )
				{
					if ( objProductSkuSet.length == undefined )
					{
						if ( objProductSkuSet.checked == false )
						{
							alert( 'Please select a product.' );
							return false;
						}
					}
					else
					{
						for ( var i = 0; i < objProductSkuSet.length; i++ )
						{
							if ( objProductSkuSet[i].checked == true )
							{
								if ( objOriQty = document.frmProduct.txtOriQty )
								{
									if ( ( objOriQty.value <= 0 ) || ( objOriQty.value == '' ) )
									{
										alert( 'Please enter a quantity greater than zero.' );
										return false;
									}
									else
									{
										return true;
									}
								}
							}
						}
					}
					alert( 'Please select a product.' );
					return false;
				}
			}
		}
		if ( objOriQty = document.frmProduct.txtOriQty )
		{
			if ( ( objOriQty.value <= 0 ) || ( objOriQty.value == '' ) )
			{
				alert( 'Please enter a quantity greater than zero.' );
				return false;
			}
			else
			{
				return true;
			}
		}
		return false;
	}
	
	function LoadSkusByLength( objSelect, objTarget )
	{
		var lngPrdID = document.getElementById( 'hidID' ).value;
		if ( objLen = document.getElementById( objSelect ) )
		{
			//get the length
			var strLength = objLen.value;
			var xmlHttp = AJAX_GetXMLHttp();
			if ( xmlHttp == null )
			{
				alert( "Error: Could not instantiate XmlHttp object." );
				return;
			}
			//get the skus for the provided length
			xmlHttp.open( 'GET', 'xml/productsXml.asp?prdID=' + lngPrdID + '&len=' + strLength, true );
			xmlHttp.send( 'prdID=' + lngPrdID + '&len=' + strLength );
			xmlHttp.onreadystatechange = function()
			{
				if ( xmlHttp.readyState == 4 && xmlHttp.status == 200 )
				{
					//load the radios based on the length
					LoadLengthOptions( xmlHttp.responseText, strLength, objTarget );
				}
			}
		}
		return;
	}
	
	function LoadLengthOptions( xmlString, strLength, objTarget )
	{
		var xmlDoc;
		var xmlDataset;
		var lngSkuID;
		var lngMultiSkuNoResist;
		var strSkuName;
		var strSkuDescription;
		var strSkuListPrice;
		var strSkuAccPrice;
		var strSkuListPriceD;
		var strSkuAccPriceD;
		var strSkuCode;
		var lngSkuPpsID;
		var strHtm;
		var i;
		
		if ( objTarg = document.getElementById( objTarget ) )
		{
			// 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 xml dataset
			xmlDataset = xmlDoc.getElementsByTagName( 'LengthOptions' );
			if ( xmlDataset.length != 0 )
			{
				//get the radio format indicator
				lngMultiSkuNoResist = parseInt( document.getElementById( 'hidMultiSkuNoResist' ).value );
				strHtm = '';
				strHtm += "<div class=\"resistanceBoxText\">Select Your Resistance:</div>";
				//loop through the xml data
				for ( i=0; i < xmlDataset.length; i++ )
				{
					lngSkuID = xmlDataset[i].childNodes[0].firstChild.nodeValue;
					strSkuName = xmlDataset[i].childNodes[1].firstChild.nodeValue;
					strSkuDescription = xmlDataset[i].childNodes[2].firstChild.nodeValue;
					strSkuListPrice = new String( xmlDataset[i].childNodes[3].firstChild.nodeValue );
					strSkuAccPrice = new String( xmlDataset[i].childNodes[4].firstChild.nodeValue );
					strSkuListPriceD = new String( xmlDataset[i].childNodes[5].firstChild.nodeValue );
					strSkuAccPriceD = new String( xmlDataset[i].childNodes[6].firstChild.nodeValue );
					strSkuCode = new String( xmlDataset[i].childNodes[7].firstChild.nodeValue );
					lngSkuPpsID = parseInt( xmlDataset[i].childNodes[8].firstChild.nodeValue );
					
					//check the radio format indicator
					if ( lngMultiSkuNoResist == 1 )
					{
						strHtm += "<input type=\"radio\" name=\"radProductSkuSet\" value=\"" + lngSkuID + "\" onclick=\"javascript:UpdateSKU('" + strSkuCode + "','" + strSkuListPrice + "','" + strSkuAccPrice + "','" + strSkuListPriceD + "','" + strSkuAccPriceD + "'," + lngSkuPpsID + ");\" style=\"vertical-align:middle;\">" + strSkuName + ": " + strSkuDescription + "<br>";
					}
					else
					{
						strHtm += "<input type=\"radio\" name=\"radProductSkuSet\" value=\"" + lngSkuID + "\" onclick=\"javascript:UpdateSKU('" + strSkuCode + "','" + strSkuListPrice + "','" + strSkuAccPrice + "','" + strSkuListPriceD + "','" + strSkuAccPriceD + "'," + lngSkuPpsID + ");\" style=\"vertical-align:middle;\"><img src=\"images/productColor" + strSkuName + ".jpg\" width=\"16\" height=\"16\" alt=\"\" class=\"productColor\">" + strSkuName + ": " + strSkuDescription + "<br>";
					}
				}
				// place the html into the target div
				objTarg.innerHTML = strHtm;
			}
			else
			{
				objTarg.innerHTML = '';
			}
		}
		return;
	}
//-->
