//
//          Functions to handle the Megaflow pumps XML Data.
//
var xmlFileMF5 = "partlists/products.xml";
var xmlXFileMF5 = "partlists/exploded.xml";
var xmlMegaflow = "MEGAFLOW";
var xmlMegaflow56 = "MEGAFLOW_56FRAME";
var xmlMegaflow48 = "MEGAFLOW_48FRAME";
var xmlMegaflowExtras = "MEGAFLOW_EXTRAS";
var strName =  "";

function getMF5Suffix(formID)
{
    var rButton;
    var x = "";
    rButton = formID.rbMF5;
    for ( var i=0; i<formID.rbMF5.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/megaflow-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/megaflow-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/megaflow-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.megaflow_extras0.rbExtra[1].checked )
        AddToCart(document.magnaflow_extras0);
    if ( document.megaflow_extras1.rbExtra[1].checked )
        AddToCart(document.magnaflow_extras1);
	if ( document.megaflow_extras2.rbExtra[1].checked )
		AddToCart(document.magnaflow_extras1);
}


function select_megaflow(hz50)
{
    var x = null;
    var y = null;
    var z = null;
    var k = 0;

   loadXMLDoc(xmlFileMF5);
   for (var j=0; j<2; j++)
   {
	   if (!j)
	   {
		   x = xmlhttp.responseXML.documentElement.getElementsByTagName( xmlMegaflow56 );
		   document.write( "<table class='ptablef' align='center' border='1'>" );
		   document.write( "<caption style='font-size:18px'>Pumps below are 230V, 60Hz, Class B</caption" );
	   }
	   else
	   {
		   x = xmlhttp.responseXML.documentElement.getElementsByTagName( xmlMegaflow48 );
		   document.write( "<table class='ptable2f' align='center' border='1'>" );
		   document.write( "<caption style='font-size:18px'>Pumps below are 230V, 50Hz, 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='90' >Model Number</th>" );
	   document.write( "<th align='center' width='134'>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>" );

	   for (i = 0; i < x.length; i++)
	   {
		  document.write( "<tr>" );
		  hz50 ? document.write( "<form name='megaflow_50hz" + k + "'>" ) :	document.write( "<form name='megaflow_60hz" + k + "'>" );
		  document.write( "<td valign='middle' align='center'><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 valign='middle' align='left'>" );
		  hz50 ? document.write( "<div onClick='getMF5Suffix(document.megaflow_50hz" + k++ + ")' />" ) : document.write( "<div onClick='getMF5Suffix(document.megaflow_60hz" + k++ + ")' />" );
		  document.write( "<table class='discharge' border='0'><tr><td align='left'>" );
		  document.write( "<img name='IMAGE' src='images/megaflow-nd.jpg' width='50px' border='0'>" );
		  document.write( "</td><td valign='middle' align='left'>" );
		  document.write( "<input type='radio' name='rbMF5' value=' ' checked=true>&nbsp;(Up)<br />" );
		  document.write( "<input type='radio' name='rbMF5' value='3'>-3 (Right)<br />" );
		  document.write( "<input type='radio' name='rbMF5' 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;
		  j==0 ? z = xmlMegaflow56 + " : " + y + "V, " : z = xmlMegaflow48 + " : " + y + "V, ";
		  document.write( "<td valign='middle' align='center'>" );
		  y = x[i].getElementsByTagName( "PART_AMPS_HI" ) [0].childNodes[0].nodeValue;
		  document.write( y );
		  z += y + "/";
		  document.write( "</td>" );
		  document.write( "<td valign='middle' align='center'>" );
		  y = x[i].getElementsByTagName( "PART_AMPS_LO" ) [0].childNodes[0].nodeValue;
		  document.write( y );
		  z += y + "A, ";
		  document.write( "</td>" );
		  document.write( "<td valign='middle' align='center'>" );
		  y = x[i].getElementsByTagName( "PART_HP_CC" ) [0].childNodes[0].nodeValue;
		  document.write( y );
		  z += y + "cd/";
		  document.write( "</td>" );
		  document.write( "<td valign='middle' align='center'>" );
		  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 valign='middle' align='center'>" );
		  document.write( x[i].getElementsByTagName( "PART_WEIGHT" ) [0].childNodes[0].nodeValue );
		  document.write( "</td>" );
		  document.write( "<td valign='middle' align='center'>" );
		  document.write( x[i].getElementsByTagName( "PART_MOTOR" ) [0].childNodes[0].nodeValue );
		  document.write( "</td>" );
		  document.write( "<td valign='middle' align='center'>" );
		  document.write( x[i].getElementsByTagName( "PART_IMP" ) [0].childNodes[0].nodeValue );
		  document.write( "</td>" );
		  document.write( "<td valign='middle' align='center'><span style='color:red'>" );
		  y = x[i].getElementsByTagName( "PART_PRICE" ) [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 valign='middle' align='center'>" );
		  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>" );
   }


   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(xmlMegaflowExtras);
   for (i = 0; i < x.length; i++)
   {
	   document.write( "<tr>" );
	   document.write( "<form name='megaflow_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>" );
}


function select_megaflow_exploded()
{
   var x = null;
   var y = null;
   loadXMLDoc(xmlXFileMF5);
   document.write( "<table class='ptable' align='center' width='80%' border='2'>" );
   document.write( "<caption style='font-size:18px;'>Megaflow 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>" );
   x = xmlhttp.responseXML.documentElement.getElementsByTagName( xmlMegaflow );
   for (i = 0; i < x.length; i++)
   {
	  document.write( "<tr>" );
	  document.write( "<form name='exploded_" + i + "'>" );
	  document.write( "<td width='5%' valign='middle' align='center'><input type='checkbox' name='clipcopy'></td>" );
	  document.write( "<td width='15%' valign='middle' align='center'>" );
	  document.write( x[i].getElementsByTagName( "INDEX" ) [0].childNodes[0].nodeValue );
	  document.write( "</td>" );
	  document.write( "<td width='15%' valign='middle' align='center'>" );
	  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' align='left'>" );
	  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 valign='middle' width='15%' align='center'>" );
	  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%' valign='middle' align='center'>" );
	  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>" );
   document.write( "<form name='clip'><textarea name='clip_copy' style='display:none'></textarea></form>" );
}

