// MessengerofHealth


//========================================================================
//========================================================================
//========================================================================

//function init(){}

 var browserName=navigator.appName; // Get the Browser Name 

if(browserName=="Microsoft Internet Explorer") // For IE 
	{ 

//		window.onload=init; // Call init function in IE 
	} 
	else 
	{ 
		if (document.addEventListener) // For Firefox 
		{ 
//			document.addEventListener("load", init, false); // Call init function in Firefox 
//			document.addEventListener("DOMContentLoaded", init, false); // Call init function in Firefox 
		} 
	} 

//window.onload = function(){};  
//========================================================================
//========================================================================
//========================================================================

var XMLHttpRequestObject = null; 
var BROWSER = "unknown";

function InitAJAX()
{
	var XMLHttpRequestObject = null; 

//	if ( XMLHttpRequestObject != null) return;

	try{ 
		XMLHttpRequestObject =new ActiveXObject("Msxml2.XMLHTTP"); 
	}catch(e){ 
		try{ 
			XMLHttpRequestObject =new ActiveXObject("Microsoft.XMLHTTP"); 
		}catch(e){ 
			try {
 
	                                           XMLHttpRequestObject =new XMLHttpRequest(); 
	                                    }catch(e){ 
				XMLHttpRequestObject =false; 

			}
		} 
	}

	if ( XMLHttpRequestObject == null) alert("object is not initialized");	

	return(XMLHttpRequestObject);

}
		
//========================================================================
//========================================================================
//========================================================================
		
				
var loginIn = 0;
function Login()
{
	var url;
	url = document.location.href;
	//========================================================================
	if (url.indexOf("localhost", 0) != (-1) ) 
	{
		txtLogin.value = "pokallus";
	}


	if (txtLogin.value == "pokallus")
	{ 
		loggedIn = 1;
		hide("divLogin");
		LoadPage('MenuDetail.txt','intro.txt');
		show("wrapper");
		show("bottom");

	}	
	txtLogin.value = "";
}
//========================================================================
//========================================================================
//========================================================================

function Startup()
{
	var url;
	var parm;
	url = document.location.href;

var browser = "unknown";

if ( navigator.userAgent.indexOf("MSIE", 0)   != (-1) ) BROWSER = "MSIE";
if ( navigator.userAgent.indexOf("Firefox", 0) != (-1) ) BROWSER = "Firefox";
if ( navigator.userAgent.indexOf("Safari", 0)   != (-1) ) BROWSER = "Safari";
 

	if (url.indexOf("localhost", 0) == (-1) ) 
	{
		if (url.indexOf("https://messengerofhealth.ipower.com", 0) == (-1)   ) 
		{
			window.location = "https://messengerofhealth.ipower.com" ;		
		}
	}

	parm = "site=MessengerOfHealth&browser=" + navigator.userAgent ;
	parm = encodeURI(parm);


	if (url.indexOf("https://messengerofhealth.ipower.com", 0) != (-1)   ) 
	{
		GetServerData("monitor.php", parm,  noop,  "TEXT");
	}

	if (url.indexOf("OK", 0) != (-1) ) 
	{
//		hide("divLogin");
		LoadPage('MenuDetail.txt','Page15.txt');
		show("wrapper");
		show("bottom");
	}

	else if (url.indexOf("CANCEL", 0) != (-1) ) 
	{
//		hide("divLogin");
		LoadPage('MenuDetail.txt','CustomerInfo.txt');
		show("wrapper");
		show("bottom");
	}
	else if (url.indexOf("ConsultingServices", 0) != (-1) ) 
	{
//		hide("divLogin");
		LoadPage('MenuDetail.txt','ConsultingServices.txt');
		show("wrapper");
		show("bottom");
	}
	else 
	{
var obj2 = document.getElementById("acontent");
obj2.clientheight = 4048; 
//		LoadPage("MenuDetail.txt","intro.txt");
		LoadPage("MenuDetail.txt","introKenTest.txt");
	}



//msgWindow=window.open('http://localhost/messengerofhealth/dev.html','windowName','toolbar=no'); 
//window.close();
//oncontextmenu="return false;"

}


//========================================================================

function noop(data)
{
	//does nothing
}

//========================================================================
//========================================================================
//========================================================================

var BFirstName;
var BLastName;
var BAddress1;
var BAddress2;
var BCity;
var BState;
var BZIP;
var BEmail;
var BPhone;

var SFirstName;
var SLastName;
var SAddress1;
var SAddress2;
var SCity;
var SState;
var SZIP;
var SEmail;
var SPhone;

var CheckingOut  = false;


var PLCO = new Array (
 	  0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                    0, 0, 0, 0, 0, 0, 1, 1, 0, 0,
                    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                    0, 0, 0, 1, 0, 1, 0, 0, 0, 0,
                    0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
                    1, 1, 1, 0, 0, 0, 0, 0, 0, 0,
                    1, 1, 1, 0, 0, 0, 0, 0, 0, 0,
                    1, 1, 1, 1, 0, 0, 0, 0, 0, 0,
                    1, 1, 1, 1, 0, 0, 0, 0, 0, 0);

var PLQTY = new Array (
	  0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                    0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                    0, 0, 0, 0, 0, 0, 0, 0, 0, 0);

var PL = new Array(
	40.00,  40.00,  40.00,  40.00,  40.00,  40.00,  40.00,  30.00,  30.00,   0.00,
          	40.00,  42.00,  48.00,  25.00,  37.00,  35.00,  55.00,  40.00,   40.00,   0.00,
          	30.00,  40.00,  30.00,  40.00,  35.00,   0.00,   0.00,   0.00,   0.00,   0.00,
          	18.00,  18.00,  18.00,  55.00,  20.00,  70.00,   0.00,   0.00,   0.00,   0.00,
          	28.00,  15.00,  15.00,  25.00,  45.00,   0.00,   0.00,   0.00,   0.00,   0.00,
                   300.00, 300.00, 375.00,   0.00,   0.00,   0.00,   0.00,   0.00,   0.00,   0.00,
                   38.50,  38.50,  38.50,   0.00,   0.00,   0.00,   0.00,   0.00,   0.00,   0.00,
                   38.50,  38.50,  38.50,  38.50,   0.00,   0.00,   0.00,   0.00,   0.00,   0.00,
                   34.00,  38.50,  52.00,  35.00,  12.00,   0.00,   0.00,   0.00,   0.00,   0.00);


var PLname = new Array(
                       "MuscleProvider (Vanilla)", "MuscleProvider (Chocolate)", "Ultra Size (Vanilla)", "Ultra Size (Chocolate)", "Ultimate Muscle Protein (Vanilla)", "Ultimate Muscle Protein (Chocolate)", "Ultimate Muscle Protein (Cookies Creme)", "Mass Maker (Vanilla)", "Mass Maker (Chocolate)", "", 
                       "Ultra 40", "Mass", "Muscle Synergy", "Creatine Select Plus Phosphates", "Glutamine Select Plus BCAAs", "Muscle Mass BCAA", "Amino Stat", "NeuroBalance", "Density", "", 
                       "Lean Out", "7 Keto MuscLEAN", "Energy Reserve", "GH Factor", "Muscularity BCAA", "", "", "", "", "", 
                       "Advance Antioxidant Compound", "Joint Care", "Bev ZMA", "Statlyte", "EFA Gold", "IsoBlast", "", "", "", "", 
                       "Super Pak", "Ultra 4", "Ultra C", "Vitamin B-5 4 oz. jar", "Vitamin B-5 8 oz. jar", "", "", "", "", "", 
                       "Female Comprehensive Test", "Male Comprehensive Test", "Endoscreen Female 28 day Panel Saliva Hormone Test", "", "", "", "", "", "", "", 
                       "Bio-Est", "Bio-Plex", "Bio Femme IC", "", "", "", "", "", "", "", 
                       "ENDOSIS IC", "Triplex", "Biosis IC", "Libidex", "", "", "", "", "", "", 
                       "DigestAll", "Detoxinal", "Ultra D", "HLC Intensive Capsules", "Multiple Enzymes", "", "", "", "", "");          
//========================================================================

function NumericCheck(e)
{
	var keynum;
	var keychar;
	keynum = (window.event) ? event.keyCode : e.keyCode;
//alert(keynum + "  " + e.which);
	if (keynum  == 0) keynum = e.which;
if (keynum == 8 || keynum == 46 ) return(keynum);
	keychar = String.fromCharCode(keynum);
//alert(keychar);
	numcheck = /\d/;

	return numcheck.test(keychar);
}

//========================================================================

function PriceQTYGet(theObj, index)
{
	if (PLQTY[index-1] == 0)
	{
		theObj.value = "";
	}
	else
	{
		theObj.value = PLQTY[index-1];
	}
}

//========================================================================

function PriceQTYStore(theObj, index)
{
	
	PLQTY[index-1] = theObj.value;

}

//========================================================================

function PriceQTYShow()
{
	for (i=1; i<PLQTY.length; i++)
	{
		PLQ = document.getElementById("PLQ" + i);

		if (PLQ == null) continue;

		if (PLQTY[i-1] == 0)
			PLQ.value = "";
		else
		{
			PLQ.value = PLQTY[i-1];
	
		}
	}
}

//========================================================================

var OrderSubtotal   = 0;
var OrderShipMethod = "";
var OrderShipAmount = 0.0;
var OrderTotal      = 0.0;

function PriceUpdate1()
{  //PLSn  PLAn 1-28

	var PSL;
	var PLA;
	var subtotal = 0;
	

	for (i=1; i<PLQTY.length; i++)
	{
		PSL = document.getElementById("PLQ" + i);
		PLA = document.getElementById("PLA" + i);

		if (PSL == null) continue;

		if (PSL.value == 0)
			PLA.value = "";
		else
		{
	
//			PLA.value = "$" + (PSL.value * PL[i-1]) + ".00"; 
			PLA.value = num2money(PSL.value * PL[i-1]);
			subtotal += (PSL.value * PL[i-1]);
		}
	}

//	Subtotal.value = "$" + subtotal + ".00";
	OrderSubtotal  = subtotal;
	Subtotal.value = num2money(subtotal);
	

}          
//========================================================================

function PriceUpdate2()
{  

	var PSL;
	var PLA;
	var subtotal = 0.0;
	var total = 0.0	

	OrderTotal = OrderSubtotal + OrderShipAmount;

	var Subtotal2     = document.getElementById("Subtotal2");
	var ShipAmount2   = document.getElementById("ShipAmount");
	var Total2        = document.getElementById("Total");


	Subtotal2.value = num2money(OrderSubtotal);
	ShipAmount2.value = num2money(OrderShipAmount);

	Total2.value = num2money(OrderTotal);
	

}  

//========================================================================

function GetSabreShippingCost(MethodIndex)
{
	var i;
	var items = (0);
	var ShipAmount  = (0.0);
	var BaseShipment = (0.0);

	var Pickup           = document.getElementById("Pickup");
	var ShipMethod = document.getElementById("ShipMethod");
	

	if ( MethodIndex == 2 ) BaseShipment = (10.0);   // $10.00
	if ( MethodIndex == 3 ) BaseShipment = (16.0);   // $16.00



	for (i=1; i<PLQTY.length; i++)
	{
		if ( (PLQTY[i-1] != 0) && (PLCO[i-1] == 1) )
		{
			items += (PLQTY[i-1] * 1);
		}
     	}

	if (items == 0)  return(0.0);

	if (BaseShipment == 0.0)
	{
		alert("The Sabre products in your shopping cart require a \"Method of Shipment\" to be selected.");
		return (-1);	
	}

	if (items > 4)
	{
		ShipAmount = (items - 4) * 1.0 + BaseShipment;
	}
	else
	{
		ShipAmount = BaseShipment;
	}


	return(ShipAmount);
}

//========================================================================

function GetShippingCost( MedthodIndex )
{
	var i;
	var items = (0);
	var ShipAmount  = (0.0);
	var BaseShipment = (0.0);

	var Pickup           = document.getElementById("Pickup");
	var ShipMethod = document.getElementById("ShipMethod");

	for (i=1; i<PLQTY.length; i++)
	{
		if ( (PLQTY[i-1] != 0) && (PLCO[i-1] == 0) )
		{
			items += (PLQTY[i-1] * 1);
		}
     	}

	if ( !Pickup.checked)   // if not pickup
	{
		BaseShipment = ShippingChart[MedthodIndex].base;   // base shipping cost;
		if (BaseShipment == (0.0) )
		{
			alert("You must choose a \"Method of Shipment\" or Pickup for Beverly products.");
			return (-1);
		}

		if (items > 0)
			ShipAmount = BaseShipment  + (items * ShippingChart[MedthodIndex].item);
		if (ShipAmount > ShippingChart[MedthodIndex].max )   
			ShipAmount = ShippingChart[MedthodIndex].max;
	}

	if ( GetSabreShippingCost(MedthodIndex) == (-1) ) return (-1);
	ShipAmount = ShipAmount + GetSabreShippingCost(MedthodIndex);
	return(ShipAmount);
}

//========================================================================

function CalculateShipping()
{  
	var ShipAmount = 0.0;

	var Pickup           = document.getElementById("Pickup");
	var ShipMethod = document.getElementById("ShipMethod");
	
	ShipAmount = GetShippingCost(ShipMethod.value);

		switch(ShipMethod.value)
		{
		case "0":
			OrderShipMethod = "";
			break;

		case "2":
			OrderShipMethod = "Standard Shipping";
			break;

		case "3":
			OrderShipMethod = "USPS Priority Mail";
			break;

		}

	OrderShipAmount = ShipAmount;

	if ( ShipAmount > (-1) ) PriceUpdate2();
	

}          
        
//========================================================================

function StorePriceQTY()
{
	var PLQ;
	for (i=1; i<PLQTY.length; i++)
	{
		PLQ = document.getElementById("PLQ" + i);

		if (PLQ == null) continue;

		if (PLQ.value == 0)
			PLQTY[i-1] = 0;
		else
		{
	
			PLQTY[i-1] = PLQ.value; 
		}
	}


}          
//========================================================================
function AnyItemsInCart()
{
	var PLQ;
	var items = (0);

	StorePriceQTY(); 

	for (i=1; i<PLQTY.length; i++)
	{
		PLQ = document.getElementById("PLQ" + i);

		if (PLQ == null) continue;

		if (PLQ.value > 0) items++; 
	}

	if (items == 0) 
	{
		alert("You have no items in you shopping cart.");
		return (false);
	}

	LoadPage('MenuDetail.txt','CustomerInfo.txt');

	return (true);
}          

//========================================================================

function num2money(n_value) 
{

	// validate input
	if (isNaN(Number(n_value)))
		return 'ERROR';

	// save the sign
	var b_negative = Boolean(n_value < 0);
	n_value = Math.abs(n_value);

	// round to 1/100 precision, add ending zeroes if needed
	var s_result = String(Math.round(n_value*1e2)%1e2 + '00').substring(0,2);

	// separate all orders
	var b_first = true;
	var s_subresult;
	while (n_value > 1) {
		s_subresult = (n_value >= 1e3 ? '00' : '') + Math.floor(n_value%1e3);
		s_result = s_subresult.slice(-3) + (b_first ? '.' : ',') + s_result;
		b_first = false;
		n_value = n_value/1e3;
	}
	// add at least one integer digit
	if (b_first)
		s_result = '0.' + s_result;
	
	// apply formatting and return
	return  b_negative
		? '($' + s_result + ')'
		: '$' + s_result;
}

//========================================================================


function FormatPriceData()
{
	var ParamString;

 	var PSL;
	var PLA;
	var total = 0;

	var qtylst = "";
	var pricelst = "";

	var sep = "";
		
	ParamString = "";

	ParamString += "InvoiceID=" + encodeURI(InvoiceID);
	
	ParamString += "&BFirstName=" + encodeURI(BFirstName);
	ParamString += "&BLastName=" + encodeURI(BLastName);
	ParamString += "&BAddress1=" + encodeURI(BAddress1);
	ParamString += "&BAddress2=" + encodeURI(BAddress2);
	ParamString += "&BCity=" + encodeURI(BCity);
	ParamString += "&BState=" + encodeURI(BState);
	ParamString += "&BZIP="   + encodeURI(BZIP);
	ParamString += "&BEmail=" + encodeURI(BEmail);
	ParamString += "&BPhone=" + encodeURI(BPhone);

	ParamString += "&SFirstName=" + encodeURI(SFirstName);
	ParamString += "&SLastName=" + encodeURI(SLastName);
	ParamString += "&SAddress1=" + encodeURI(SAddress1);
	ParamString += "&SAddress2=" + encodeURI(SAddress2);
	ParamString += "&SCity=" + encodeURI(SCity);
	ParamString += "&SState=" + encodeURI(SState);
	ParamString += "&SZIP="   + encodeURI(SZIP);
	ParamString += "&SEmail=" + encodeURI(SEmail);
	ParamString += "&SPhone=" + encodeURI(SPhone);

/*
	for (i=1; i<PLQTY.length; i++)
	{
		PSL = document.getElementById("PLQ" + i);
		PLA = document.getElementById("PLA" + i);

		if (PSL == null) continue;

		if (PSL.value == 0)
		{
			qtylst   += sep;
			pricelst += sep;
		}
		else
		{
			qtylst   += sep + PSL.value ;
			pricelst += sep + num2money(PSL.value * PL[i-1]);

			total += (PSL.value * PL[i-1]);
		}
		sep = "|";
	}
*/
	for (i=1; i<PLQTY.length; i++)
	{
		if (PLQTY[i-1] == 0)
		{
			qtylst   += sep;
			pricelst += sep;
		}
		else
		{
			qtylst   += sep + PLQTY[i-1] ;
			pricelst += sep + num2money(PLQTY[i-1] * PL[i-1]);

			total += (PLQTY[i-1] * PL[i-1]);
		}
		sep = "|";
	}


	ParamString += "&QTYLST="   + encodeURI(qtylst);
	ParamString += "&PRICELST=" + encodeURI(pricelst);
	ParamString += "&SUBTOTAL=" + encodeURI(num2money(total));

	ParamString += "&SHIPPING="       + encodeURI(num2money(OrderShipAmount));
	ParamString += "&SHIPPINGmethod=" + OrderShipMethod;
	ParamString += "&TOTAL="          + encodeURI(num2money(OrderTotal));

	return (ParamString);
}

//========================================================================
        function SubmitEmail()
        {
	       XMLHttpRequestObject  = InitAJAX();


	       if(XMLHttpRequestObject) 
	       {
//		      XMLHttpRequestObject.open("POST", "Email.php", true); 
		      XMLHttpRequestObject.open("POST", "https://messengerofhealth.ipower.com/Email.php", true); 
             	      XMLHttpRequestObject.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 

              	      XMLHttpRequestObject.onreadystatechange = function() 
		        { 
			    if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200) 
				{ 
	                                      //alert("Data Received from Email.PHP");
						
	                                      //alert(XMLHttpRequestObject.responseText);
	                                      //alert("An email has been sent to Messenger Of Health");
		        		}
 
		       } 
          
 		var ParamString = FormatPriceData();
		XMLHttpRequestObject.send(ParamString);   

//		 XMLHttpRequestObject.send("x=12");   
 	         }


        }



//========================================================================


function BuildPostData()
{

	var string = "";
	var FieldData;
	var sep = "";
	
	
	for (var i=0; i< field.length; i++)
	{

			string += sep + field[i].FieldName + "=" +encodeURI(TrimString(document.getElementById(field[i].FieldName).value));
		sep = "&";
	}

	return string;

}

//========================================================================

function StoreDataResults(results)
{

//	alert ("Your Heath and Wellness form has been submitted to the Messenger Of Health");

/*
	if (results == " success") results = "Your Heath and Wellness form has been submitted to the Messenger Of Health";
	var newWin = open("","Mydoc","width=400,height=400,resizable=yes,alwaysRaised=yes");
	newWin.document.writeln(results);
	newWin.document.close();
	newWin.focus();
*/

}

//=======================================================
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}

// example of using trim, ltrim, and rtrim
//var myString = " hello my name is ";
//alert("*"+myString.trim()+"*");
//alert("*"+myString.ltrim()+"*");
//alert("*"+myString.rtrim()+"*");

//========================================================================

var CIBname = new Array(
		"BFirstName",
		"BLastName",
		"BAddress1",
		"BCity",
		"BState",
		"BZIP",
		"BEmail",
		"BPhone1",
		"BPhone2",
		"BPhone3"
		);


var CISname = new Array(
		"SFirstName",
		"SLastName",
		"SAddress1",
		"SCity",
		"SState",
		"SZIP",
		"SEmail",
		"SPhone1",
		"SPhone2",
		"SPhone3"
		);

//========================================================================

function MissingShippingInfo()
{
	var results   = false;
	var results2 = false;
	var obj;
	var objcb;
	var error = "";


	for (i=0; i< CIBname.length; i++)
	{

 		obj = document.getElementById( CIBname[i] );
		if ( obj.value.trim().length == 0 )
		{
			results = true;
		} 
				
	}

	if (results == true) error += "You have missing item(s) in the Billing Information Section\n\n";

	objcb     = document.getElementById("SFcb");

  	if (objcb.checked)
	{
		for (i=0; i< CISname.length; i++)
		{

	 		obj = document.getElementById( CISname[i] );
			if ( obj.value.trim().length == 0 )
			{
				results2 = true;
			} 
				
			}
		if (results2 == true) 
		{
			error += "You have missing item(s) in the Shipping Information Section\n\n";
			results = true;
		}
	}

	if (results == true) alert(error);

	return (results);
}

//========================================================================

function ProcessShippingForm()
{
  	var obj     = document.getElementById("SFcb");

  	if (obj.checked)
	{
		show("TBShipInfo");
	}
	else
	{
		hide("TBShipInfo");
	}
}

//========================================================================
var InvoiceID = "";


function PayPalLoad()
{
  	var el = document.getElementById('formPayPal');
  	var item;
  	var index = 1;

	if ( MissingShippingInfo() ) return(false);

	CalculateShipping();

	if (OrderShipAmount == (-1) ) return(false);

	InvoiceID =  GetNextInvoiceID();

	if ( InvoiceID.indexOf("MOH", 0) == (-1) ) 
	{
		alert("Having problems connecting to the server.\nPlease try later");
		return (false);
	}


	CheckingOut = true;

	BFirstName = document.getElementById('BFirstName').value;
	BLastName  = document.getElementById('BLastName').value;
	BAddress1  = document.getElementById('BAddress1').value;
	BAddress2  = document.getElementById('BAddress2').value;
	BCity      = document.getElementById('BCity').value;
	BState     = document.getElementById('BState').value;
	BZIP       = document.getElementById('BZIP').value;
	BEmail     = document.getElementById('BEmail').value;
	BPhone     = "(" +document.getElementById('BPhone1').value + ") " + document.getElementById('BPhone2').value + "-" + document.getElementById('BPhone3').value;
	
	SFirstName = document.getElementById('SFirstName').value;
	SLastName  = document.getElementById('SLastName').value;
	SAddress1  = document.getElementById('SAddress1').value;
	SAddress2  = document.getElementById('SAddress2').value;
	SCity      = document.getElementById('SCity').value;
	SState     = document.getElementById('SState').value;
	SZIP       = document.getElementById('SZIP').value;
	SEmail     = document.getElementById('SEmail').value;
	SPhone     = "(" + document.getElementById('SPhone1').value + ") " + document.getElementById('SPhone2').value + "-" +document.getElementById('SPhone3').value;

	SubmitEmail();


                  item = document.createElement("input"); 
                  item.type  = "hidden";
                  item.name  = "invoice";
                  item.value = InvoiceID;
                  el.appendChild(item);


	for (i=1; i<PLQTY.length; i++)
	{
		if (PLQTY[i-1] != 0)
		{
		     item = document.createElement("input"); 
		     item.type  = "hidden";
		     item.name  = "item_name_" + index;
		     item.value = PLname[i-1];
		     el.appendChild(item);

		     item = document.createElement("input");
		     item.type  = "hidden";
		     item.name  = "amount_" + index;
		     item.value = PL[i-1];
		     el.appendChild(item);

		     item = document.createElement("input");
		     item.type  = "hidden";
		     item.name  = "quantity_" + index++;
		     item.value = PLQTY[i-1];
		     el.appendChild(item);

		}
     	}

		     item = document.createElement("input"); 
		     item.type  = "hidden";
		     item.name  = "handling_cart";
		     item.value = OrderShipAmount;
		     el.appendChild(item);


	return (true);
}

//========================================================================
//========================================================================

function GetNextInvoiceID()
{

	var params = "";
	var url;


	XMLHttpRequestObject  = InitAJAX();

	url = document.location.href;
	if (url.indexOf("localhost", 0) != (-1) ) 
	{
		//localhost 
//		url = "http://localhost/messengerofhealth/";
		url = "https://messengerofhealth.ipower.com/";
	}
	else
	{
		//server messensger.ipower.com
		url = "https://messengerofhealth.ipower.com/";
	}

try{
	XMLHttpRequestObject.open("POST",  url + "GetNextInvoiceID.php", false); 
	XMLHttpRequestObject.send(params); 
}catch(e){
alert(e.message);
	alert("Having problems connecting to the server.\n Please try later.");
	return ("Problems");
}

	return (XMLHttpRequestObject.responseText);

}
//========================================================================
//========================================================================

var months = ["January", "Febuary", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];

var days = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];

function getInvoiceDate()
{
	var value;

	var cdate       = new Date();
	var cyear       = cdate.getFullYear();
	var cmonth    = months[cdate.getMonth()];
	var cday        = cdate.getDate();
	var cdname   = days[cdate.getDay()];

	var chour      = cdate.getHours();
	var cmin       = cdate.getMinutes();
 
	var ampm = "am";


	if (chour > 11) ampm="pm";
	if (chour ==  0) chour = 12; 
	if (chour > 12) chour -= 12;

	value = cdname + ":  " + cmonth + "  " + cday + ", " + cyear + "  [" + chour + ":" + cmin + " " + ampm  + "]"; 

	return value;
}

//========================================================================
//========================================================================
function SendByMail()
{
	var url;
	url = document.location.href;

  	var item;
  	var index = 1;
	var item;
	var uamt;
	var qnty;
	var amt;
	var Subtotal = 0;
	var PrintWind;



	if ( MissingShippingInfo() ) return(false);

	CalculateShipping();
	if (OrderShipAmount == (-1) ) return(false);

	InvoiceID = GetNextInvoiceID();

	if ( InvoiceID.indexOf("MOH", 0) == (-1) ) 
	{
		alert(InvoiceID);
		return false;
	}

	if (url.indexOf("localhost", 0) == (-1) ) 
	{
		PrintWind = open ('https://messengerofhealth.ipower.com/dummy.html', 'Invoice','toolbar=yes,scrollbars=yes,resizable=yes');
	}
	else
	{
		PrintWind = window.open('dummy.html','Invoice','toolbar=yes,scrollbars=yes,resizable=yes');

		PrintWind = open ('dummy.html', 'Invoice','scrollbars=yes');
	}

	if (PrintWind == null)
	{
		alert("You must enable popups to show and print this order form.");
		return false;
	}



	BFirstName = document.getElementById('BFirstName').value;
	BLastName  = document.getElementById('BLastName').value;
	BAddress1  = document.getElementById('BAddress1').value;
	BAddress2  = document.getElementById('BAddress2').value;
	BCity      = document.getElementById('BCity').value;
	BState     = document.getElementById('BState').value;
	BZIP       = document.getElementById('BZIP').value;
	BEmail     = document.getElementById('BEmail').value;
	BPhone     = "(" + document.getElementById('BPhone1').value  + ") " + document.getElementById('BPhone2').value + "-" + document.getElementById('BPhone3').value;


	PrintWind.document.writeln("<html><head></head><body onload='window.print();' >");


	PrintWind.document.writeln("<table style='border: ridge gold 6px' width='800'>");

	PrintWind.document.writeln("<tr><td><font size='+1' style='background-color: #eeeeee'> Invoice Number: <b>" + InvoiceID +" </b></font></td>");
	PrintWind.document.writeln("<td align=right><font size='+1' style='background-color: #eeeeee'><b> " + getInvoiceDate() + " </b></font></td></tr>");

	PrintWind.document.writeln("<tr><td align=right valign=top><font color=blue size='+2'>Make Check Payable To:</font></td><td align=left><font size='+2'>Connie Allen-Pridgen, CNC </font><br><br></td></tr>");

	PrintWind.document.writeln("<tr><td align=right valign=top><font color=blue size='+2'>Send Check and this order form to:</font></td><td align=Left><font size='+2'>Connie Allen-Pridgen, CNC<br> 2337 SE Marius St.<br> Port St Lucie, FL 34952</font> </td></tr>");



	PrintWind.document.writeln("<tr><td width='50%'>");


	PrintWind.document.writeln("<table style='border: ridge gold 6px' width='100%'>");
	PrintWind.document.writeln("<tr style='background-color: #eeeeee'><th colspan=2 align=center>Billing Address</th></tr>");
	PrintWind.document.writeln("<tr><td>            To: </td><td>" + BFirstName + " " +  BLastName + "</td></tr>");
	PrintWind.document.writeln("<tr><td>Address:  </td><td>" + BAddress1 + "</td></tr>");
	PrintWind.document.writeln("<tr><td>                   </td><td>" + BAddress2 + "</td></tr>");
	PrintWind.document.writeln("<tr><td>	             </td><td>" + BCity + ", " + BState + " " +   BZIP  + "</td></tr>");
	PrintWind.document.writeln("<tr><td colspan=2><hr></td></tr>");
	PrintWind.document.writeln("<tr><td>Email:      </td><td>" + BEmail + "</td></tr>");
	PrintWind.document.writeln("<tr><td>Phone:    </td><td>" +  BPhone + "</td></tr>");
	PrintWind.document.writeln("</table>");

	SFirstName = document.getElementById('SFirstName').value;
	SLastName  = document.getElementById('SLastName').value;
	SAddress1  = document.getElementById('SAddress1').value;
	SAddress2  = document.getElementById('SAddress2').value;
	SCity      = document.getElementById('SCity').value;
	SState     = document.getElementById('SState').value;
	SZIP       = document.getElementById('SZIP').value;
	SEmail     = document.getElementById('SEmail').value;
	SPhone     = "(" + document.getElementById('SPhone1').value + ") " + document.getElementById('SPhone2').value + "-" +document.getElementById('SPhone3').value;

	PrintWind.document.writeln("</td><td width='50%'>");


	PrintWind.document.writeln("<table style='border: ridge gold 6px' width='100%'>");
	PrintWind.document.writeln("<tr style='background-color: #eeeeee'><th colspan=2 align=center>Shipping Address</th></tr>");
	PrintWind.document.writeln("<tr><td>            To: </td><td>" + SFirstName + " " +   SLastName + "</td></tr>");
	PrintWind.document.writeln("<tr><td>Address:  </td><td>" + SAddress1 + "</td></tr>");
	PrintWind.document.writeln("<tr><td>                   </td><td>" + SAddress2 + "</td></tr>");
	PrintWind.document.writeln("<tr><td>	             </td><td>" + SCity + ", " + SState + " " +  SZIP  + "</td></tr>");
	PrintWind.document.writeln("<tr><td colspan=2><hr></td></tr>");
	PrintWind.document.writeln("<tr><td>Email:      </td><td>" + SEmail + "</td></tr>");
	PrintWind.document.writeln("<tr><td>Phone:    </td><td>" +  SPhone + "</td></tr>");
	PrintWind.document.writeln("</table>");

	PrintWind.document.writeln("</td></tr>");
	PrintWind.document.writeln("<tr><td colspan=2 >");

	PrintWind.document.writeln("<table border=1 width='100%'>");
	PrintWind.document.writeln("<tr style='background-color: #eeeeee'><th>Item</th><th>unit cost</th><th>quantity</th><th>Amount</th></th>");

	for (i=1; i<PLQTY.length; i++)
	{
		if (PLQTY[i-1] != 0)
		{
			item  = PLname[i-1];
			uamt = PL[i-1];
			qnty  = PLQTY[i-1];
			amt    = uamt * qnty;
			Subtotal += amt;

			PrintWind.document.writeln("<tr><td>" + item + "</td>");
			PrintWind.document.writeln("<td align=right>" + num2money(uamt) + "</td>");
			PrintWind.document.writeln("<td align=right>" + qnty + "</td>");
			PrintWind.document.writeln("<td align=right>" + num2money(amt) + "</td></tr>");
		}
     	}

	PrintWind.document.writeln("<tr><td align=right colspan=3>Subtotal</td><td align=right>" + num2money(Subtotal) + "</td></tr>");
	PrintWind.document.writeln("<tr><td align=right colspan=3>Shipping and Handling [" + OrderShipMethod + "]</td><td align=right>" + num2money(OrderShipAmount) + "</td></tr>");
	PrintWind.document.writeln("<tr><td align=right colspan=3>Total Amount of Order</td><td align=right>" + num2money(Subtotal + OrderShipAmount) + "</td></tr>");


	PrintWind.document.writeln("</table></td></tr></table></body></html>");

	PrintWind.document.close();
	
                  PrintWind.focus();

	return (false);
}

//========================================================================
//========================================================================
//========================================================================


function DisplayMenu(data)
{
	var obj = document.getElementById("content-left"); 
//	obj.innerHTML = XMLHttpRequestObject.responseText; 
	obj.innerHTML = ""; 
	obj.innerHTML = data; 
//	obj.innerHTML = "left side"; 
	location.href = "#MOHtop";

}

//========================================================================

function DisplayPage(data)
{
	var obj = document.getElementById("contain-main"); 


//	obj.innerHTML = XMLHttpRequestObject.responseText; 
	obj.innerHTML = ""; 
	obj.innerHTML = data; 
	location.href = "#MOHtop";

//

//if (data.indexOf("File: Product1.txt", 0) != (-1) )
//{
		//setTimeout(ktime, 5000);
//
//}


}


//function ktime()
//{
//	alert("File: Product1.txt");

//Quantity1L=document.getElementById("Quantity1L");
//Quantity2L=document.getElementById("Quantity2L");

//PriceQTYGet(Quantity1L, 1);
//PriceQTYGet(Quantity2L, 2);
//}

//========================================================================

var HWpage = false;

function LoadPage(menu, page)
{
	var message = "";
   

	message += "You are about to leave the HW questionnaire.\n";
	message += "If you do so, you will loose all your enter data.\n\n";
	message += "Click \"OK\" to leave and loose all you entered on the questionnaire\n\n";
	message += "Click \"Cancel\" to stay and finish the questionnaire\n";
	message += "";

	if (HWpage)
	{
		if ( confirm(message)  )
		{
			HWpage = false;
		}
		else
		{
			return;
		}
	}


	GetServerData("", menu, DisplayMenu, "TEXT");
	GetServerData("", page, DisplayPage, "TEXT");


//	DisplayMenu(GetServerDataNow(menu, "", "TEXT") );
//	DisplayPage(GetServerDataNow(page, "", "TEXT") );
}

//========================================================================
function GetServerData(routine, params, func, format)
{

	var url;
	url = document.location.href;
	URLstr = "";

	var XMLHttpRequestObject = null; 	


	XMLHttpRequestObject  = InitAJAX();

	document.body.style.cursor = "Wait";
	if(XMLHttpRequestObject) 
	{
		try{

			if (routine == "")
			{
				XMLHttpRequestObject.open("GET", URLstr + params, true); 
				params = null;
			}
			else
			{
				XMLHttpRequestObject.open("POST", URLstr + routine, true); 
			}


/*
Possible XMLHttpRequestObject.readyState codes are: 

0 - uninitialized 
1 - loading 
2 - loaded 
3 - interactive 
4 - complete 
*/		

			XMLHttpRequestObject.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); 

			XMLHttpRequestObject.onreadystatechange = function() 
				{ 
					if (XMLHttpRequestObject.readyState == 4) 
					{
						if (XMLHttpRequestObject.status == 200) 
						{ 			
							if (format == "TEXT")
							{       
								var results = XMLHttpRequestObject.responseText;
								(func)(results);  


								//alert(results);					
							}
	
							if (format == "XML")
							{
								var xmlDocument = XMLHttpRequestObject.responseXML;
								(func)(xmlDocument);
							}
						}
						else
						{
			//alert(XMLHttpRequestObject.status);

//							alert(URLstr + routine);
//							alert(XMLHttpRequestObject.status);
//							GetServerData(routine, params, func, format);
						}
						document.body.style.cursor = "default";
					} 
				} 
			XMLHttpRequestObject.send(params); 
		}
		catch(e) {alert(e.message);}
	}
}
//========================================================================
//========================================================================
//========================================================================
//========================================================================

function GetServerDataNow(routine, paramss, format)
{
	var params = null;
	var url;

	url = document.location.href;

	XMLHttpRequestObject  = InitAJAX();

	url = document.location.href;  
	if (url.indexOf("localhost", 0) != (-1) ) 
	{
//		url = "http://localhost/MessengerOfHealth/";
//		url = "http://MessengerOfHealth.com/";
	}
	else
	{
//		url = "http://localhost/MessengerOfHealth/";
	}

try{


	XMLHttpRequestObject.open("GET",  url + routine , false); 


	XMLHttpRequestObject.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); 

	XMLHttpRequestObject.send(params); 

}catch(e){
	alert("Having problems connecting to the server.\n Please try later.");
	return ("Problems");
}

	if (XMLHttpRequestObject.readyState != 4) { alert(XMLHttpRequestObject.readyState) }; 

	if (XMLHttpRequestObject.status != 200) { alert(XMLHttpRequestObject.status) };


	if (format == "TEXT")  return (XMLHttpRequestObject.responseText);

	return (XMLHttpRequestObject.responseXML);

}
//========================================================================
//========================================================================
//========================================================================
function show(control)
{
	if (control != "")
	{
		document.getElementById(control).style.visibility="visible";
		document.getElementById(control).style.display="block";
	}
}

function hide(control)
{
	if (control != "")
	{
		document.getElementById(control).style.visibility="hidden";
		document.getElementById(control).style.display="none";
	}
}

//========================================================================
function LoadProducts(page)
{
	GetServerData("", page, DisplayPage, "TEXT");
//	GetServerData("", page, LoadProductsDiv, "TEXT");
}

function LoadProductsDiv(data)
{
	control = document.getElementById("divProducts");
	
	if (control != "")
	{
		control.innerHTML = data;
	}
	location.href = "#MOHtop";

}

//========================================================================
var PageLocation;
function LoadPageLocation(page,loc)
{
	PageLocation = loc;
	GetServerData("", page, DisplayPageLocation, "TEXT");
}

function DisplayPageLocation(data)
{
	var obj = document.getElementById("contain-main"); 
	obj.innerHTML = data; 

//	location.href = "#MOHtop";
	location.href = PageLocation;
}

//========================================================================
window.onbeforeunload = LeavingSite;


function LeavingSite()
{	
	//add check for if in middle of data entry for products or HWQ.

	var Pstatus    = false;
	var HWstatus = false;
	var message = "";

	message += "You are about to leave the Messenger Of Health website.\n";
	message += "If you do so, you will loose all your enter data.\n\n";

	if ( CheckingOut ) return;
		
	if ( OrderSubtotal > 0 )
	{	
		Pstatus = true;
		message += "  - You will loose the items in your shopping cart. \n\n";
	}

	if (HWpage) 
	{	
		Pstatus = true;
		message += "  - You will loose all your HW questionnaire entered data to this point\n\n";
	}

	message += "Click \"OK\" to continue EXITING the Messenger of Health website.\n\n";
	message += "Click \"Cancel\" to STAY in the Messenger Of Health website.\n";
	message += "";


	if ( Pstatus || HWstatus ) return message;


}

//http://www.webreference.com/dhtml/diner/beforeunload/bunload2.html
// to cancel event:     window.onbeforeunload = null;


//................or us this....................
//<S CRIPT LANGUAGE="JScript" TYPE="text/javascript" FOR=window EVENT=onbeforeunload>
//  mess = "You will lose all information provided\nduring navigation of this site"
//  return mess;
//</ SCRIPT>



//========================================================================
//========================================================================

var ShippingChart = new Array();

function ShippingMethod(method, base, item, max) 
{

	this.method = method;
	this.base   = base;
	this.item   = item;
	this.max    = max;


}

function InitShippingData()
{
	var fi = 0;
	
	ShippingChart[fi++] = new ShippingMethod("not used",              0.00, 0.00,    0.00); 
	ShippingChart[fi++] = new ShippingMethod("Pickup",                0.00, 0.00,    0.00); 
	ShippingChart[fi++] = new ShippingMethod("Standard Shipping",     5.95, 1.00,   11.95); 
	ShippingChart[fi++] = new ShippingMethod("USPS Priority Mail",    5.50, 2.00,   14.95); 

//	ShippingChart[fi++] = new ShippingMethod("UPS Ground",            6.60, 0.70, 9999.00); 
//	ShippingChart[fi++] = new ShippingMethod("UPS 2nd Day Air",      13.30, 1.50, 9999.00); 
//	ShippingChart[fi++] = new ShippingMethod("UPS Next Day Air",     29.80, 3.60, 9999.00); 

}

InitShippingData();


//========================================================================
//========================================================================
