//---------------------------------------------------------------------||
// FUNCTION:    CKquantity                                             ||
// PARAMETERS:  Quantity to                                            ||
// RETURNS:     Quantity as a number, and possible alert               ||
// PURPOSE:     Make sure quantity is represented as a number          ||
//---------------------------------------------------------------------||
function CKquantity(checkString) {
   var strNewQuantity = "";

   for ( i = 0; i < checkString.length; i++ ) {
      ch = checkString.substring(i, i+1);
      if ( (ch >= "0" && ch <= "9") || (ch == '.') )
         strNewQuantity += ch;
   }

   if ( strNewQuantity.length < 1 )
      strNewQuantity = "0";

   return(strNewQuantity);
}
//LINE 21
//---------------------------------------------------------------------||
// FUNCTION: CKstring
//---------------------------------------------------------------------||
function CKstring(checkString) {
  return(":"+checkString)}
//---------------------------------------------------------------------||
// FUNCTION:    AddToCart                                              ||
// PARAMETERS:  Form Object                                            ||
// PURPOSE:     Adds a product to the user's shopping cart             ||
//---------------------------------------------------------------------||
function AddToCart(thisForm) {

//var yourCart = document.open("text/html", "replace");

var notice = "";
var orderDetails = "";
var iNumberOrdered = 0;
var strTotal = 0; 
var strShipping = 0; 
var i=0;
var strOutput = "";
var customer = "";

strOutput = "<HTML><HEAD><TITLE>Your Shopping Cart</TITLE></HEAD>";
//strOutput += "<BODY id='cart'><FORM action='https://www.paypal.com/cgi-bin/webscr' method='post'>";
strOutput += "<BODY>";
strOutput += "<TABLE border=1><TR>" +
"<TH align=\"left\"><B>"+"NAME AND SIZE"+"</B></TH>" +
"<TH align=\"right\"><B>"+"QUANTITY"+"</B></TH>" +
"<TH align=\"right\"><B>"+"UNIT PRICE" +"</B></TH></TR>";
for (i=0; i<parseFloat((thisForm.elements.length)-3); i++)
{
if (parseFloat(thisForm.elements[i].value) > 0)
{
strTotal = strTotal + parseFloat(thisForm.elements[i].value)*parseFloat(thisForm.elements[i].name);
iNumberOrdered = iNumberOrdered + parseFloat(thisForm.elements[i].value);
var StrItem = (thisForm.elements[i].id+"--------"+parseFloat(thisForm.elements[i].value) + "----------------$" + thisForm.elements[i].name + ".00 \n");
//strOutput += "<p><TD COLSPAN=3 CLASS=\"nopentry\">" + StrItem + "</TD>";
strOutput += "<TR><TD align=\"left\">" + thisForm.elements[i].id + "</TD><TD align=\"right\">" + parseFloat(thisForm.elements[i].value) + "</TD><TD align=\"right\">$" + thisForm.elements[i].name + ".00</TD></TR>";
orderDetails += StrItem + "\n";
}
}
for (i=parseFloat(thisForm.elements.length - 5); i<parseFloat(thisForm.elements.length - 2); i++)
{
  customer += " " + thisForm.elements[i].value + " ";
}


if ( iNumberOrdered == 0 ) 
{
strOutput += "<TR><TD COLSPAN=3 CLASS=\"nopentry\"><CENTER><BR><B>Your cart is empty</B><BR><BR></CENTER></TD></TR>";
}

strOutput += "<TR><TD COLSPAN=3 align=\"right\">&nbsp;</TD></TR>";
strOutput += "<TR><TD COLSPAN=3 align=\"right\">";
strOutput += " Total: $" + strTotal + ".00";
strOutput += "</TD></TR>";
orderDetails += " Total: $" + strTotal + ".00";
if (strTotal >= 50 && strTotal <= 100)
{strShipping = 9.25;}
else if (strTotal >= 101 && strTotal <= 200)
{strShipping = 11.00;}
else if (strTotal > 200 && strTotal <= 350)
{strShipping = 14.00;}
else if (strTotal > 350 && strTotal <500)
{strShipping = 16.95;}
else if (strTotal >= 500)
{strShipping = 0.00;}
else {alert("$50.00 is the minimum order. Please press BACK on your browser and add more items to your cart.");}
strOutput += "<TR><TD COLSPAN=3 align=\"right\">";
strOutput += " Shipping: $" + strShipping;
strOutput += "</TD></TR>";
strTotal = strTotal + strShipping;
strOutput += "<TR><TD COLSPAN=3 align=\"right\">";
strOutput += " Grand Total: $" + strTotal; 
strOutput += "</TD></TR>";
strOutput += "</TABLE>";
strOutput += "<BR /><BR />";

orderDetails += " Shipping: $" + strShipping;
orderDetails += " Grand Total: $" + strTotal; 
strOutput += "";
strOutput += " Customer Info: " + customer;
orderDetails += " \n\n Customer Info: " + customer;
strOutput += "<BR /><BR />Please print this page for your records.<BR /> We now accept orders via email. Click the Submit Order button below to send your order to us for processing, at which time we will call for billing or credit card information.<br>If you are not sure, please print and fax this page to (405) 702-6689.<br>  Once we receive your order, we will call you to confirm payment. Thank you!";

document.write(strOutput);

//var linkPhone = "<P><A HREF='mailto:info@cassilone.com?subject=Your Latham and Company Order&body="+orderDetails+"'>Submit order and pay over the Phone</A>";
var linkPhone = "<BR /><FORM action='submit_order.php' method='post'><INPUT type='hidden' name='OrderData' value='"+orderDetails+"'><INPUT type='submit' name='SubmitOrder' value='Submit Order'></FORM>";

//var linkPay = "<P><A HREF='https://www.paypal.com/cgi-bin/webscr'>Submit Order and pay via PayPal<input type='hidden' //name='cmd' value='_xclick'><input type='hidden' name='LathamandCompany' value='beloncik@hotmail.com'><input type='hidden' //name='item_name' value='Aggregated items'><input type='hidden' name='amount' value=strTotal></A>";

var linkCancel = "<BR /><A HREF='http://allformypet.com/index.html'>Cancel and return to Homepage</A>";
//var linkCancel = "<P><A HREF='window.history.back()'>Cancel</A>";

document.write(linkPhone);
//document.write(linkPay);
document.write(linkCancel);

var strOutput2 = "</BODY></HTML>";
document.write(strOutput2);

//document.close();

}

