//
//
//
var productName = "MAVERICK";
var xmlMaverick = "partlists/products.xml";
var xmlMaverick115V = "MAVERICK_115V";
var xmlMaverickSS = "MAVERICK_SS";
var xmlMaverick230V = "MAVERICK_230V";
var xmlMaverick50Hz = "MAVERICK_50HZ";
var xmlMaverickProd = "MAVERICK";
var xmlMaverickExtras = "MAVERICK_EXTRAS";
var xmlXFile="partlists/exploded.xml";
var strName;


function getMaverickSuffix(formID)
{
    var rButton = null;
    var x = "";
    rButton = formID.rbMaverick;
    for ( var i=0; i<rButton.length; i++ ) {
        if ( rButton[i].checked ) {
            strName = formID.ID.value;
            x = strName.match(/-50HZ/g);
            switch ( i ) {
            case 0 : 
                formID.ID_NUM.value = strName;
                formID.PART_NAME.value = formID.ID_NUM.value;
                formID.NAME.value = formID.DESC.value + " ** Discharge Up";
                formID.IMAGE.src = "images/maverick-nd.jpg";
                if ( formID.BASE_PRICE.value.match(/N\/A/) )
                    formID.PRICE.value = 'N/A'
                else
                    formID.PRICE.value = '$' + Number( formID.BASE_PRICE.value ).toFixed(2);
                break;
            case 1 :
                if ( x )
                    formID.ID_NUM.value = strName.substring( 0, x.index ) + "-" + rButton[i].value.toString() + x;
                else
                    formID.ID_NUM.value = strName + "-" + rButton[i].value;
                formID.PART_NAME.value = formID.ID_NUM.value;
                formID.NAME.value = formID.DESC.value + " ** Discharge Right";
                formID.IMAGE.src = "images/maverick-3.jpg";
                if ( formID.BASE_PRICE.value.match(/N\/A/) )
                    formID.PRICE.value = 'N/A'
                else
                    formID.PRICE.value = '$' + Number( Number( formID.BASE_PRICE.value ) + Number( formID.DISCHARGE.value )).toFixed(2);
                break;
            case 2 : 
                if ( x )
                    formID.ID_NUM.value = strName.substring( 0, x.index ) + "-" + rButton[i].value.toString() + x;
                else
                    formID.ID_NUM.value = strName + "-" + rButton[i].value;
                formID.PART_NAME.value = formID.ID_NUM.value;
                formID.NAME.value = formID.DESC.value + " ** Discharge Left";
                formID.IMAGE.src = "images/maverick-4.jpg";
                if ( formID.BASE_PRICE.value.match(/N\/A/) )
                    formID.PRICE.value = 'N/A'
                else
                    formID.PRICE.value = '$' + Number( Number( formID.BASE_PRICE.value ) + Number( formID.DISCHARGE.value )).toFixed(2);
                break;
            }
        }
    }
}


function getExtraParts(formID)
{
    AddToCart(formID);
    if ( document.maverick_extras0.rbExtra[1].checked )
        AddToCart(document.maverick_extras0);
    if ( document.maverick_extras1.rbExtra[1].checked )
        AddToCart(document.maverick_extras1);
}


function select_maverick(self_drain, v115, hz50)
{
    var x = null;
    var y = null;
    var z = null;

    loadXMLDoc(xmlMaverick);
    document.write( "<table class='ptablef' align='center' border='1'>" );
    if ( self_drain ) {
        document.write( "<caption style='font-size:18px'>Pumps below are 115V, 60Hz</caption>" );
    } else if ( hz50 ) {
        document.write( "<caption style='font-size:18px'>Pumps below are 230V, 50Hz</caption>" );
    } else if ( v115 ) {
        document.write( "<caption style='font-size:18px'>Pumps below are 115V, 60Hz</caption>" );
    } else {
        document.write( "<caption style='font-size:18px'>Pumps below are 230V, 60Hz</caption>" );
    }
    document.write( "<thead>" );
    document.write( "<tr>" );
    document.write( "<th align='center' width='34' ><input type='button' value='Copy' class='btn-sml' onClick='Copy2Clipboard(false)' ></th>" );
    document.write( "<th align='center' width='110' >Model Number</th>" );
    document.write( "<th align='center' width='118'>Select Discharge Position</th>" );
    document.write( "<th align='center' width='36' >Amps High</th>" );
    document.write( "<th align='center' width='36' >Amps Low</th>" );
    document.write( "<th align='center' width='31' >HP (cd)</th>" );
    document.write( "<th align='center' width='31' >HP (spl)</th>" );
    document.write( "<th align='center' width='44' >Weight (lb)</th>" );
    document.write( "<th align='center' width='42' >Motor</th>" );
    document.write( "<th align='center' width='52' >Impeller</th>" );
    document.write( "<th align='center' width='54' ><span style='color:red'>Limited Offer</span></th>" );
    document.write( "<th align='center' width='90' >Quantity:</th>" );
    document.write( "</tr>" );
    document.write( "</thead>" );
    document.write( "<tbody>" );

    if ( self_drain ) {
        x = xmlhttp.responseXML.documentElement.getElementsByTagName( xmlMaverickSS );
    } else if ( hz50 ) {
        x = xmlhttp.responseXML.documentElement.getElementsByTagName( xmlMaverick50Hz );
    } else if ( v115 ) {
        x = xmlhttp.responseXML.documentElement.getElementsByTagName( xmlMaverick115V );
    } else {
        x = xmlhttp.responseXML.documentElement.getElementsByTagName( xmlMaverick230V );
    }
    for ( var i=0; i<x.length; i++ )
    {
        document.write( "<tr>" );
        if ( self_drain ) {
            document.write( "<form name='maverick_ss_115_" + i + "' >" );
        } else if ( v115 ) {
            document.write( "<form name='maverick_115_" + i + "' >" );
        } else if ( hz50 ) {
            document.write( "<form name='maverick_50hz_230_" + i + "' >" );
        } else {
            document.write( "<form name='maverick_230_" + i + "' >" );
        }
        document.write( "<td align='center' valign='middle'><input type='checkbox' name='clipcopy'></td>" );
        document.write( "<td align='left' valign='middle'>" );
        y = x[i].getElementsByTagName( "PART_NUM" ) [0].childNodes[0].nodeValue;
        document.write( "<input type='text' name='PART_NAME' class='inp-field' readonly value='" + y + "' />" );
        document.write( "<input type='hidden' name='ID' value='" + y + "' />"); 
        document.write( "</td>" );
        document.write( "<td align='left' valign='middle'>" );
        if ( self_drain ) {
            document.write( "<div onClick='getMaverickSuffix(document.maverick_ss_115_" + i + ")' />" );
        } else if ( v115 ) {
            document.write( "<div onClick='getMaverickSuffix(document.maverick_115_" + i + ")' />" );
        } else if ( hz50 ) {
            document.write( "<div onClick='getMaverickSuffix(document.maverick_50hz_230_" + i + ")' />" );
        } else {
            document.write( "<div onClick='getMaverickSuffix(document.maverick_230_" + i + ")' />" );
        }
        document.write( "<table border='0'><tr><td align='left' valign='middle'>" );
        document.write( "<img name='IMAGE' src='images/maverick-nd.jpg' width='50px' border='0'>" );
        document.write( "</td><td align='left'>" );
        document.write( "<input type='radio' name='rbMaverick' value=' ' checked >&nbsp;(Up)<br />" );
        document.write( "<input type='radio' name='rbMaverick' value='3'>-3 (Right)<br />" );
        document.write( "<input type='radio' name='rbMaverick' value='4'>-4 (Left)<br />" );
        document.write( "</td></tr></table>" );
        document.write( "</div>" );
        document.write( "<input type='hidden' name='ID_NUM' value='" + y + "' />"); 
        document.write( "</td>" );
        y = x[i].getElementsByTagName( "PART_VOLTS" ) [0].childNodes[0].nodeValue;
        z = productName + ": " + y + "V, ";
        document.write( "<td align='center' valign='middle'>" );
        y = x[i].getElementsByTagName( "PART_AMPS_HI" ) [0].childNodes[0].nodeValue;
        document.write( y );
        z += y + "/";
        document.write( "</td>" );
        document.write( "<td align='center' valign='middle'>" );
        y = x[i].getElementsByTagName( "PART_AMPS_LO" ) [0].childNodes[0].nodeValue;
        document.write( y );
        z += y + "A, ";
        document.write( "</td>" );
        document.write( "<td align='center' valign='middle'>" );
        y = x[i].getElementsByTagName( "PART_HP_CC" ) [0].childNodes[0].nodeValue;
        document.write( y );
        z += y + "cd/";
        document.write( "</td>" );
        document.write( "<td align='center' valign='middle'>" );
        y = x[i].getElementsByTagName( "PART_HP" ) [0].childNodes[0].nodeValue;
        document.write( y );
        z += y + "spl";
        document.write( "<input type='hidden' name='DESC' value='" + z + "' />");
        document.write( "<input type='hidden' name='NAME' value='" + z + "' />");
        document.write( "</td>" );
        document.write( "<td align='center' valign='middle'>" );
        document.write( x[i].getElementsByTagName( "PART_WEIGHT" ) [0].childNodes[0].nodeValue );
        document.write( "</td>" );
        document.write( "<td align='center' valign='middle'>" );
        document.write( x[i].getElementsByTagName( "MOTOR" ) [0].childNodes[0].nodeValue );
        document.write( "</td>" );
        document.write( "<td align='center' valign='middle'>" );
        document.write( x[i].getElementsByTagName( "IMPELLER" ) [0].childNodes[0].nodeValue );
        document.write( "</td>" );
        document.write( "<td width='12%' valign='middle' align='center'><span style='color:red'>" );
        y = x[i].getElementsByTagName( "PART_DSCNT" ) [0].childNodes[0].nodeValue;
        if ( y.match(/N\/A/) )
            y = 0;
        else
            y.length == 1 ? y = 0 : y = y.slice( 1, y.length );
        if ( y == 0 ) {
            document.write( "<input type='hidden' name='BASE_PRICE' value='N/A' />");
            document.write( "<input type='text' name='PRICE' size=8 class='inp-field-red' value='N/A' readonly />");
        }	else {
                document.write( "<input type='hidden' name='BASE_PRICE' value='" + y + "' />");
                document.write( "<input type='text' name='PRICE' size=8 class='inp-field-red' value='$" + y + "' readonly />");
        }
        z = x[i].getElementsByTagName( "PART_DISCHARGE" ) [0].childNodes[0].nodeValue;
        z.length == 1 ? z = 0 : z = z.slice( 1, z.length );
        document.write( "<input type='hidden' name='DISCHARGE' value='" + z + "' />");
        document.write( "</span></td>" );
        document.write( "<td align='center' valign='middle'>" );
        if ( y == 0 ) {
            document.write( "&nbsp;" );
        } else {
            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(this.form)' /><br />" );
            document.write( "<input type='button' value='View Order' class='btn-sml' onclick='DisplayCartAsWindow()' />" );
        }
        document.write( "</td>" );
        document.write( "</form>" );
        document.write( "</tr>" );
    }
    
    document.write( "</tbody>" );
    document.write( "</table>" );

    if ( hz50 || self_drain ) {
        document.write( "<table class='ptable' align='center' width='95%' border='2'>" );
        document.write( "<caption style='font-size:18px'>Select your pump unions, if needed, from the table below.<br /></caption" );
        document.write( "<caption style='font-size:18px'>Prices are valid with pump purchase.</caption" );
        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</th>" );
        document.write( "<th align='center'>Quantity</th>" );
        document.write( "<th align='center' style='color:red'>Limited Offer</th>" );
        document.write( "</tr>" );
        document.write( "</thead>" );
        document.write( "<tbody>" );
    
        x = xmlhttp.responseXML.documentElement.getElementsByTagName(xmlMaverickExtras);
        for (i = 0; i < x.length; i++)
        {
            document.write( "<tr>" );
            document.write( "<form name='maverick_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 align='left' valign='middle'>" );
            y = x[i].getElementsByTagName( "NUM" ) [0].childNodes[0].nodeValue;
            document.write( y );
            document.write( "<input type='hidden' name='ID_NUM' value='" + y + "' />");
            document.write( "</td>" );
            document.write( "<td align='left' valign='middle'>" );
            y = x[i].getElementsByTagName( "DESC" ) [0].childNodes[0].nodeValue;
            document.write( y );
            document.write( "<input type='hidden' name='NAME' value='" + y + "' />");
            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' style='color:red'>" );
            y = x[i].getElementsByTagName( "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( "<form name='clip'><textarea name='clip_copy' style='display:none'></textarea></form>" );
    }
}


function select_maverick_exploded(self_drain)
{
    var x = null;
    var y = null;

    loadXMLDoc(xmlXFile);
       document.write( "<table class='ptable' align='center' width='80%' border='2'>" );
       if (self_drain)
           document.write( "<caption style='font-size:18px;'>Maverick Self-Drain Spa and Hot Tub Pump Part List</caption>");
       else
           document.write( "<caption style='font-size:18px;'>Maverick Spa and Hot Tub Pump Part List</caption>");
       document.write( "<thead>" );
       document.write( "<tr>" );
       document.write( "<th align='center'><input type='button' value='Copy' class='btn-sml' onClick='CopyExp2Clipboard(false)' ></th>" );
       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( "<th align='center'>Quantity:</th>" );
       document.write( "</tr>" );
       document.write( "</thead>");
       document.write( "<tbody>" );
       self_drain ? x = xmlhttp.responseXML.documentElement.getElementsByTagName( xmlMaverickSS ) : x = xmlhttp.responseXML.documentElement.getElementsByTagName( xmlMaverickProd );

       for (i = 0; i < x.length; i++)
       {
          document.write( "<tr>" );
          document.write( "<form name='exploded" + i + "'>" );
          document.write( "<td width='5%' align='center' valign='middle'><input type='checkbox' name='clipcopy'></td>" );
          document.write( "<td width='15%' align='center' valign='middle'>" );
          document.write( x[i].getElementsByTagName( "INDEX" ) [0].childNodes[0].nodeValue );
          document.write( "</td>" );
          document.write( "<td width='15%' align='center' 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 align='left' valign='middle'>" );
          document.write( x[i].getElementsByTagName( "DESCRIPTION" ) [0].childNodes[0].nodeValue );
          document.write( "<input type='hidden' name='NAME' value='" + 
                          x[i].getElementsByTagName( "DESCRIPTION" ) [0].childNodes[0].nodeValue + "' />");
          document.write( "</td>" );
          document.write( "<td width='15%' align='center' valign='middle'>" );
          y = x[i].getElementsByTagName( "PRICE" ) [0].childNodes[0].nodeValue;
          document.write( y );
          if ( y.match(/N\/A/) )
              y = 0;
          else
              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( "<td width='10%' align='center' valign='middle'>" );
          if ( y == 0 ) {
              document.write( "&nbsp;" );
          } else {
              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='AddToCart(this.form)' /><br />" );
              document.write( "<input type='button' value='View Order' class='btn-sml' onclick='DisplayCartAsWindow()' />" );
          }
          document.write( "</td>" );
          document.write( "</form>" );
          document.write( "</tr>" );
       }
       document.write( "</tbody>" );
       document.write( "</table>" );
}

