//
//      Functions to handle the Hotline EXT pages.
//
var xmlFile="partlists/products.xml";
var xmlHotlineEXT = "HOTLINE_EXT";
var xmlHotlineEXTAP = "HOTLINE_EXTAP";
var xmlHotlineEXTExtras = "HOTLINE_EXT_EXTRAS";
var xmlXFile="partlists/exploded.xml";

var apTrue = false;

var apString = "-AP";
var modelString = "SPA";
var descrString = "";
var priceString = 0;
var priceBase = 0;
var cpriceString = 0;

var hlPumps = 0;
var arPumps = new Array(4);
for ( var i=0; i<arPumps.length; i++ )
    arPumps[i] = new Array(3);
var hlBlower = 0;
var arBlower = new Array(3);
for ( var i=0; i<arBlower.length; i++ )
    arBlower[i] = new Array(3);


function getRadios( formID )
{
    rb = formID.rbPumps;
    for ( var i = 0; i<rb.length; i++ )
        if ( rb[i].checked )
            hlPumps = i;

    rb = formID.rbBlower;
    for ( var i = 0; i<rb.length; i++ )
        if ( rb[i].checked )
            hlBlower = i;

    modelString  = "SPA";
    modelString += arPumps[0][hlPumps];
    if ( hlBlower > 0 ){
            var tmp = modelString.split("-");
            modelString = tmp[0] + arBlower[0][hlBlower] + "-" + tmp[1];
    }
    if (apTrue)
        modelString += apString;
    document.hotlineEXT1.ID_NUM.value = modelString;
    document.hotlineEXT2.ID_NUM.value = modelString;

    apTrue ? descrString = "Hotline EXTAP Pack; " : descrString  = "Hotline EXT Pack; ";
    descrString += arPumps[1][hlPumps] + " ";
    if ( hlBlower > 0 )
        descrString += ": " + arBlower[1][hlBlower] + " ";
    document.hotlineEXT1.NAME.value = descrString + ".";
    document.hotlineEXT2.NAME.value = descrString + ".";
    
    priceString  = Number( priceBase );
    priceString += Number( arPumps[2][hlPumps].slice( 1, arPumps[2][hlPumps].length ) );
    priceString += Number( arBlower[2][hlBlower].slice( 1, arBlower[2][hlBlower].length ) );
    document.hotlineEXT1.PRICE.value = '$' + Number( priceString ).toFixed(2);
    document.hotlineEXT2.PRICE.value = '$' + Number( priceString ).toFixed(2);
}


function getExtraParts()
{
    AddToCart(document.hotlineEXT1);
    for ( var i = 0; i < document.forms.length; i++ )
    {
        if ( document.forms[i].name.search(/hotlineEXT_extras/) > -1 &&
             document.forms[i].rbExtra[1].checked )
            AddToCart(document.forms[i]);
    };
}


function select_hotline_ext_options(ap)
{
    var x = null;
    var y = null;
    var z = null;

   apTrue = ap;
   loadXMLDoc(xmlFile);
   document.write( "<table class='ptable' align='center' width='90%' border='2'>" );
   document.write( "<thead>" );
   document.write( "<tr>" );
   document.write( "<th align='center'><input type='button' value='Copy' class='btn-sml' onClick='Copy2Clipboard(true)' ></th>" );
   document.write( "<th align='center'>Model Number</th>" );
   document.write( "<th align='center'>Model Description</th>" );
   document.write( "<th align='center'><span style='color:red'>Limited Offer</span></th>" );
   document.write( "<th align='center'>Quantity</th>" );
   document.write( "</tr>" );
   document.write( "</thead>" );
   document.write( "<tbody>" );
   apTrue ? x = xmlhttp.responseXML.documentElement.getElementsByTagName( xmlHotlineEXTAP ) : x = xmlhttp.responseXML.documentElement.getElementsByTagName( xmlHotlineEXT );
   for (i = 0; i < x.length; i++)
   {
      document.write( "<tr>" );
      document.write( "<form name='hotlineEXT1'>" );
      document.write( "<td align='center' valign='middle'><input type='checkbox' name='clipcopy1'></td>" );
      document.write( "<td align='left' valign='middle'>" );
      modelString = x[i].getElementsByTagName( "NUMBER" ) [0].childNodes[0].nodeValue;
      document.write( "<input type='text' name='ID_NUM' class='inp-field' size='35' onchange='this.value=modelString' value='" + modelString + "' readonly />");
      document.write( "</td>" );
      document.write( "<td align='left' valign='middle'>" );
      descrString = x[i].getElementsByTagName( "DESCRIPTION" ) [0].childNodes[0].nodeValue;
      document.write( "<textarea name='NAME' class='inp-field' cols='60' rows='9' wrap='hard' onchange='this.value=descrString' value='" + descrString + "' readonly ></textarea>");
      document.write( "</td>" );
      document.write( "<td align='center' valign='middle'><span style='color:red'>" );
      y = x[i].getElementsByTagName( "PRICE" ) [0].childNodes[0].nodeValue;
      priceBase = y.slice( 1, y.length );
      document.write( "<input type='text' name='PRICE' size=8 class='inp-field-red' onchange='this.value=priceString' value='$" + priceString + "' readonly />");
      document.write( "</td>" );
      document.write( "<td align='center' valign='middle'>" );
      document.write( "<input type='text' size=6 maxlength=4 name='QUANTITY' onchange='this.value=CKquantity(this.value)' value='1' /><br />" );
      document.write( "<input type='button' value='Add to Order' class='btn-sml' onClick='getExtraParts()' /><br />" );
      document.write( "<input type='button' value='View Order' class='btn-sml' onclick='DisplayCartAsWindow()' />" );
      document.write( "</span></td>" );
      document.write( "</form>" );
      document.write( "</tr>" );
   }
   document.write( "</td>" );
   document.write( "</tr>" );
   document.write( "</form>" );
   document.write( "</tbody>" );
   document.write( "</table>" );


   document.write( "<table class='ptable' align='center' width='99%' border='2'>" );
   document.write( "<thead>" );
   document.write( "<tr>" );
   document.write( "<th width='10%' align='center'>Option Code</th>" );
   document.write( "<th width='20%' align='center'>Option to Choose</th>" );
   document.write( "<th width='60%' align='center'>Option Description</th>" );
   document.write( "<th width='10%' align='center'>Option Price</th>" );
   document.write( "</tr>" );
   document.write( "</thead>" );
   document.write( "<form name='hotline_ext_options'>" );
   document.write( "<tbody>" );
   document.write( "<tr>" );
   document.write( "<td align='center'>Pump Options:</td>" );
   document.write( "<td align='left' valign='bottom' style='line-height:20px'>" );
   document.write( "<div onClick='getRadios(document.hotline_ext_options)' />" );
   apTrue ? x = xmlhttp.responseXML.documentElement.getElementsByTagName( "HOTLINE_EXTAP_PUMP_OPTIONS" ) : x = xmlhttp.responseXML.documentElement.getElementsByTagName( "HOTLINE_EXT_PUMP_OPTIONS" );
   for (i = 0; i < x.length; i++)
   {
       arPumps[0][i] = x[i].getElementsByTagName( "CODE" ) [0].childNodes[0].nodeValue; 
       document.write( "<input type='radio' name='rbPumps' value='" + arPumps[0][i] );
       i == 0 ? document.write("' checked='true'>" ) : document.write( "'>" );
       document.write( arPumps[0][i] + "<br />" );
   }
   document.write( "</div>" );
   document.write( "</td>" );
   document.write( "<td align='left' valign='bottom' style='line-height:20px'>" );
   for (i = 0; i < x.length; i++)
   {
       arPumps[1][i] = x[i].getElementsByTagName( "DESC" ) [0].childNodes[0].nodeValue; 
       document.write( arPumps[1][i] + "<br />" );
   }
   document.write( "</td>" );
   document.write( "<td align='right' valign='bottom' style='line-height:20px; padding-right:15px'>" );
   for (i = 0; i < x.length; i++)
   {
       arPumps[2][i] = x[i].getElementsByTagName( "PRICE" ) [0].childNodes[0].nodeValue;    
       document.write( arPumps[2][i] + "<br />" );
   }
   document.write( "</td>" );
   document.write( "</tr>" );
   document.write( "<tr>" );
   document.write( "<td align='center'>Blower Options:</td>" );
   document.write( "<td align='left' valign='bottom' style='line-height:20px'>" );
   document.write( "<div onClick='getRadios(document.hotline_ext_options)' />" );
   x = xmlhttp.responseXML.documentElement.getElementsByTagName( "HOTLINE_EXT_BLOWER_OPTIONS" );
   for (i = 0; i < x.length; i++)
   {
       arBlower[0][i] = x[i].getElementsByTagName( "CODE" ) [0].childNodes[0].nodeValue;    
       document.write( "<input type='radio' name='rbBlower' value='" + arBlower[0][i] );
       i == 0 ? document.write( "' checked='true'>" ) : document.write( "'>" );
       document.write( arBlower[0][i] + "<br />" );
   }
   document.write( "</div>" );
   document.write( "</td>" );
   document.write( "<td align='left' valign='bottom' style='line-height:20px'>" );
   for (i = 0; i < x.length; i++)
   {
       arBlower[1][i] = x[i].getElementsByTagName( "DESC" ) [0].childNodes[0].nodeValue;    
       document.write( arBlower[1][i] + "<br />" );
   }
   document.write( "</td>" );
   document.write( "<td align='right' valign='bottom' style='line-height:20px; padding-right:15px'>" );
   for (i = 0; i < x.length; i++)
   {
       arBlower[2][i] = x[i].getElementsByTagName( "PRICE" ) [0].childNodes[0].nodeValue;   
       document.write( arBlower[2][i] + "<br />" );
   }
   document.write( "</td>" );
   document.write( "</tr>" );
   document.write( "</form>" );
   document.write( "</tbody>" );
   document.write( "</table>" );


   document.write( "<table class='ptable' align='center' width='99%' border='2'>" );
   document.write( "<thead>" );
   document.write( "<tr>" );
   document.write( "<th align='center'>&nbsp;</th>" );
   document.write( "<th align='center'>Model Number</th>" );
   document.write( "<th align='center'>Model Description<br />These prices only valid with spa pack purchase.</th>" );
   document.write( "<th align='center'>Quantity</th>" );
   document.write( "<th align='center'>List Price</th>" );
   document.write( "</tr>" );
   document.write( "</thead>" );
   document.write( "<tbody>" );
   x = xmlhttp.responseXML.documentElement.getElementsByTagName( xmlHotlineEXTExtras );
   for (i = 0; i < x.length; i++)
   {
      document.write( "<tr>" );
      document.write( "<form name='hotlineEXT_extras" + i + "'>" );
      document.write( "<td valign='middle'>" );
      document.write( "<input type='radio' value='0' checked='true' name='rbExtra'>Not needed<br />" );
      document.write( "<input type='radio' value='1' name='rbExtra'>Add to Order" );
      document.write( "</td>" );
      document.write( "<td valign='middle'>" );
      document.write( x[i].getElementsByTagName( "PART_NUM" ) [0].childNodes[0].nodeValue );
      document.write( "<input type='hidden' name='ID_NUM' value='" + 
                      x[i].getElementsByTagName( "PART_NUM" ) [0].childNodes[0].nodeValue + "' />");
      document.write( "</td>" );
      document.write( "<td valign='middle'>" );
      document.write( x[i].getElementsByTagName( "PART_DESC" ) [0].childNodes[0].nodeValue );
      document.write( "<input type='hidden' name='NAME' value='" + 
                      x[i].getElementsByTagName( "PART_DESC" ) [0].childNodes[0].nodeValue + "' />");
      document.write( "</td>" );
      document.write( "<td width='10%' align='center' valign='middle'>" );
      document.write( "<input type='text' size=4 maxlength=4 name='QUANTITY' onchange='this.value=CKquantity(this.value)' value='1' /><br />" );
      document.write( "</td>" );
      document.write( "<td align='center' valign='middle'>" );
      y = x[i].getElementsByTagName( "PART_PRICE" ) [0].childNodes[0].nodeValue;
      document.write( y );
      y.length == 1 ? y = 0 : y = y.slice( 1, y.length );
      document.write( "<input type='hidden' name='PRICE' value='" + y + "' />");
      document.write( "</td>" );
      document.write( "</form>" );
      document.write( "</tr>" );
   }
   document.write( "</tbody>" );
   document.write( "</table>" );


   document.write( "<table class='ptable' align='center' width='90%' border='2'>" );
   document.write( "<thead>" );
   document.write( "<tr>" );
   document.write( "<th align='center'><input type='button' value='Copy' class='btn-sml' onClick='Copy2Clipboard(true)' ></th>" );
   document.write( "<th align='center'>Model Number</th>" );
   document.write( "<th align='center'>Model Description</th>" );
   document.write( "<th align='center'><span style='color:red'>Limited Offer</span></th>" );
   document.write( "<th align='center'>Quantity</th>" );
   document.write( "</tr>" );
   document.write( "</thead>" );
   document.write( "<tbody>" );
   apTrue ? x = xmlhttp.responseXML.documentElement.getElementsByTagName( xmlHotlineEXTAP ) : x = xmlhttp.responseXML.documentElement.getElementsByTagName( xmlHotlineEXT );
   for (i = 0; i < x.length; i++)
   {
      document.write( "<tr>" );
      document.write( "<form name='hotlineEXT2'>" );
      document.write( "<td align='center' valign='middle'><input type='checkbox' name='clipcopy2'></td>" );
      document.write( "<td align='left' valign='middle'>" );
      modelString = x[i].getElementsByTagName( "NUMBER" ) [0].childNodes[0].nodeValue;
      document.write( "<input type='text' name='ID_NUM' class='inp-field' size='35' onchange='this.value=modelString' value='" + modelString + "' readonly />");
      document.write( "</td>" );
      document.write( "<td align='left' valign='middle'>" );
      descrString = x[i].getElementsByTagName( "DESCRIPTION" ) [0].childNodes[0].nodeValue;
      document.write( "<textarea name='NAME' class='inp-field' cols='60' rows='9' wrap='hard' onchange='this.value=descrString' value='" + descrString + "' readonly ></textarea>");
      document.write( "</td>" );
      document.write( "<td align='center' valign='middle'><span style='color:red'>" );
      y = x[i].getElementsByTagName( "PRICE" ) [0].childNodes[0].nodeValue;
      priceBase = y.slice( 1, y.length );
      document.write( "<input type='text' name='PRICE' size=8 class='inp-field-red' onchange='this.value=priceString' value='$" + priceString + "' readonly />");
      document.write( "</td>" );
      document.write( "<td align='center' valign='middle'>" );
      document.write( "<input type='text' size=6 maxlength=4 name='QUANTITY' onchange='this.value=CKquantity(this.value)' value='1' /><br />" );
      document.write( "<input type='button' value='Add to Order' class='btn-sml' onClick='getExtraParts()' /><br />" );
      document.write( "<input type='button' value='View Order' class='btn-sml' onclick='DisplayCartAsWindow()' />" );
      document.write( "</span></td>" );
      document.write( "</form>" );
      document.write( "</tr>" );
   }
   document.write( "</td>" );
   document.write( "</tr>" );
   document.write( "</form>" );
   document.write( "</tbody>" );
   document.write( "</table>" );

   document.write( "<form name='clip'><textarea name='clip_copy' style='display:none'></textarea></form>" );
}


function select_hotline_ext_exploded()
{
    var x;

    loadXMLDoc( xmlXFile );
    document.write( "<table class='ptable' align='center' width='60%' border='2'>" );
    document.write( "<thead>" );
    document.write( "<tr>" );
    document.write( "<th align='center'>Index Number:</th>" );
    document.write( "<th align='center'>Part Number:</th>" );
    document.write( "<th align='center'>Description:</th>" );
    document.write( "<th align='center'>List Price:</th>" );
    document.write( "</tr>" );
    document.write( "</thead>");
    document.write( "<tbody>" );
    x = xmlhttp.responseXML.documentElement.getElementsByTagName( xmlHotlineEXT );

    for (i = 0; i < x.length; i++)
    {
        document.write( "<tr>" );
        document.write( "<td width='15%' align='center'>" );
        document.write( x[i].getElementsByTagName( "INDEX" ) [0].childNodes[0].nodeValue );
        document.write( "</td>" );
        document.write( "<td width='15%' align='center'>" );
        document.write( x[i].getElementsByTagName( "PART_NUM" ) [0].childNodes[0].nodeValue );
        document.write( "</td>" );
        document.write( "<td align='left'>" );
        document.write( x[i].getElementsByTagName( "DESCRIPTION" ) [0].childNodes[0].nodeValue );
        document.write( "</td>" );
        document.write( "<td width='20%' align='center'>" );
        document.write( x[i].getElementsByTagName( "PRICE" ) [0].childNodes[0].nodeValue );
        document.write( "</td>" );
        document.write( "</tr>" );
    }
    document.write( "</tbody>" );
    document.write( "</table>" );
}

