//
//	Magnaflow Pump XML Data Reader and RadioButton Handler
//
var xmlFile = "partlists/products.xml";
var xmlMagnaflow48 = "MAGNAFLOW_48FRAME";
var xmlMagnaflow56 = "MAGNAFLOW_56FRAME";
var xmlMagnaflow50 = "MAGNAFLOW_50HZ";
var xmlMagnaflowExtras = "MAGNAFLOW_EXTRAS";
var xmlXMagnaflow = "partlists/exploded.xml";
var strName;

function getMagnaSuffix(formID)
{
    var rButton;
    var strTemp = "";
    rButton = formID.rbMagna;
    for ( var i=0; i<formID.rbMagna.length; i++ )
    {
        if ( rButton[i].checked )
        {
            strName = formID.ID.value;
            strTemp = 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/magnaflow-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 ( strTemp )
                        formID.ID_NUM.value = strName.substring( 0, strTemp.index ) + "-" + rButton[i].value.toString() + strTemp;
                    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/magnaflow-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 ( strTemp )
                        formID.ID_NUM.value = strName.substring( 0, strTemp.index ) + "-" + rButton[i].value.toString() + strTemp;
                    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/magnaflow-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.magnaflow_extras0.rbExtra[1].checked )
        AddToCart(document.magnaflow_extras0);
    if ( document.magnaflow_extras1.rbExtra[1].checked )
        AddToCart(document.magnaflow_extras1);
}


function select_magnaflow(frame56, hz50)
{
    var x;
    var y = null;
    var z = null;

    loadXMLDoc(xmlFile);
    document.write( "<table class='ptablef' align='center' border='1'>" );
    hz50 ? document.write( "<caption style='font-size:18px'>Pumps below are 230V, 50Hz, Class B</caption" ) : document.write( "<caption style='font-size:18px'>Pumps below are 230V, 60Hz, Class B</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>" );
    hz50 ? x = xmlhttp.responseXML.documentElement.getElementsByTagName( xmlMagnaflow50 ) : frame56 ? x = xmlhttp.responseXML.documentElement.getElementsByTagName( xmlMagnaflow56 ) : x = xmlhttp.responseXML.documentElement.getElementsByTagName( xmlMagnaflow48 );

    for (i = 0; i < x.length; i++)
    {
        document.write( "<tr>" );
        hz50 ? document.write( "<form name='magnaflow_50hz" + i + "' >" ) : frame56 ? document.write( "<form name='magnaflow_56_60hz" + i + "' >" ) : document.write( "<form name='magnaflow_48_60hz" + i + "' >" );
        document.write( "<td align='center' valign='middle'><input type='checkbox' name='clipcopy'></td>" );
        document.write( "<td 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'>" );
        hz50 ? document.write( "<div onClick='getMagnaSuffix(document.magnaflow_50hz" + i + ")' />" ) : frame56 ? document.write( "<div onClick='getMagnaSuffix(document.magnaflow_56_60hz" + i + ")' />" ) : document.write( "<div onClick='getMagnaSuffix(document.magnaflow_48_60hz" + i + ")' />" );
        document.write( "<table class='discharge' border='0'><tr><td align='left'>" );
        document.write( "<img name='IMAGE' src='images/magnaflow-nd.jpg' width='44px' border='0'>" );
        document.write( "</td><td align='left'>" );
        document.write( "<input type='radio' name='rbMagna' value=' ' checked=true>&nbsp;(Up)<br />" );
        document.write( "<input type='radio' name='rbMagna' value='3'>-3 (Right)<br />" );
        document.write( "<input type='radio' name='rbMagna' 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;
        frame56 ?   z = xmlMagnaflow56 + ": " + y + "V, " : z = xmlMagnaflow48 + ": " + 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( "PART_MOTOR" ) [0].childNodes[0].nodeValue );
        document.write( "</td>" );
        document.write( "<td align='center' valign='middle'>" );
        document.write( x[i].getElementsByTagName( "PART_IMP" ) [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=6 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=6 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-smlr' 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 ( frame56 || ( !frame56 && hz50 ) )
    {
        document.write( "<table class='ptable' align='center' width='95%' border='1'>" );
        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(xmlMagnaflowExtras);
        for (i = 0; i < x.length; i++)
        {
            document.write( "<tr>" );
            document.write( "<form name='magnaflow_extras" + i + "'>" );
            document.write( "<td align='left' 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_magnaflow_exploded(frame56)
{
    var x;
    var y = null;

    loadXMLDoc(xmlXMagnaflow);
    document.write( "<table class='ptable' align='center' width='80%' border='2'>" );
	if (frame56)
		document.write( "<caption style='font-size:18px;'>Magnaflow-56 Spa and Hot Tub Pump Part List</caption>");
	else
		document.write( "<caption style='font-size:18px;'>Magnaflow 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>" );
    frame56 ? x = xmlhttp.responseXML.documentElement.getElementsByTagName( xmlMagnaflow56 ) : x = xmlhttp.responseXML.documentElement.getElementsByTagName( xmlMagnaflow48 );
    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>" );
}


