//******************************************
//*                                        *
//* JS-iCart                               *
//*                                        *
//* Client Side JavaScript Shopping Cart   *
//*                                        *
//* Copyright (c) 2004 by Iron Images      *
//* All rights reserved.                   *
//*                                        *
//* No part of this document may be copied *
//* modified or used without permission of *
//* Iron Images.                           *
//******************************************

// ***** Global variables *****
var CartDB=new Array();
var Qty,PartNo,Desc,Price,Amount;

var Finishes=new Array("AG","Antique Gold",
                       "AW","Antique White",
                       "CV","Copper Vein",
                       "AB","Antique Black",
                       "IS","Ivory Stucco",
                       "NG","Neutral Gray",
                       "VG","Verde Green");

var Letters=new Array("5","3.19",
                      "6","4.84",
                      "8","6.27",
                      "10","8.02",
                      "12","9.62",
                      "14","12.82",
                      "16","14.65",
                      "18","16.41");

var LetterFonts=new Array("CP","CopperPlate",
                          "LW","Latin Wide",
                          "TB","Thunderbird",
                          "SI","Souvenir Italic",
                          "ZB","Zurich Bold");

//******************************************
//* View an item in detail.                *
//*                                        *
//* Used in gardenhome, furniturehome.htm  *
//******************************************
function ViewItem(PartNo)
{  Details="images/"+PartNo+".jpg"+"|"+PartNo+"|"+Items[PartNo][0]+"|"+Items[PartNo][1]+"|"+Items[PartNo][2]+"|"+Items[PartNo][3]+"|"+Items[PartNo][4];
   window.location.href="addpart.htm?"+Details;
}

//******************************************
//* Add item to shopping cart directly     *
//* from 'Add to Cart' button.             *
//*                                        *
//* Used in: addpart.htm                   *
//******************************************
function AddToCart(PartNo)
{  var a,e,f,q=-1,Qty,PtNo,Desc,Price,suffix="";
   if(!CookiesEnabled()||PartNo=="") return;
   // if there is a "SelectForm" on the page,
   // check if there is a "Select" field for
   // the part.  If so, append the selected value
   // to the part no.
   for(f=0;f<document.forms.length;f++)
     if(document.forms[f].name=="SelectForm") break;
   if(f<document.forms.length)
   {  for(e=0;e<document.forms[f].elements.length;e++)
      {  if(document.forms[f].elements[e].name==PartNo+"Qty") q=e;
         if(document.forms[f].elements[e].name==PartNo+"Select")
           break;
      }
      if(e<document.forms[f].elements.length)
      {  a=document.forms[f].elements[e];
         suffix="/"+a.options[a.selectedIndex].value;
      }
   }
   if(q>-1)
     Qty=pad(document.forms[f].elements[q].value,3);
   else
     Qty=pad("1",3);
   if(!isValidQty(Qty))
   {  alert("Quantity must be between 1 and 999");
      return;
   }
   PtNo=pad(PartNo+suffix,20);
   Desc=pad(Items[PartNo][0],40);
   Price=pad(Items[PartNo][1],7);
   GetCartFromCookie();
   i=FindItem(PartNo+suffix);
   CartDB[i]=PtNo+Qty+Desc+Price;
   document.cookie="ShoppingCart="+escape(DoJoin())+";";
   GotoViewCart();//alert(unescape(document.cookie));
}

//***** A D D P A R T . H T M *****
//******************************************
//* Add part to shopping cart.             *
//*                                        *
//* Used in: addpart.htm                   *
//******************************************
function AddItem()
{  var Qty,PartNo,Desc,Price;
   if(!CookiesEnabled()||apPartNo.innerText=="")return;
   Qty=pad(document.f1.Qty.value,3);
   PartNo=pad(apPartNo.innerText,20);
   Desc=pad(apDesc.innerText,40);
   Price=pad(apPrice.innerText,7);
   GetCartFromCookie();
   i=FindItem(PartNo);
   CartDB[i]=PartNo+Qty+Desc+Price;
   document.cookie="ShoppingCart="+escape(DoJoin())+";";
   GotoViewCart();//alert(unescape(document.cookie));
}

//******************************************
//* Go to viewcart.htm.                    *
//*                                        *
//* Used in addpart.htm                    *
//******************************************
function GotoViewCart()
{  if(!CookiesEnabled())return;
   window.location.href="viewcart.htm";
}

//******************************************
//* Load Item Details from query string.   *
//*                                        *
//* Used in addpart.htm                    *
//******************************************
function LoadItemDetails()
{  s=unescape(window.location.search);
   s=s.substr(1,s.length-1);
   if(s=="") return;
   a=s.split("|");
   document.LargeImage.src=a[0];
   apPartNo.innerText=a[1];
   apDesc.innerText=a[2];
   apPrice.innerText=a[3];
   apFinish.innerText=a[4];
   if(a[5]==""||a[5]=="Size")
     apSize.innerText="Not Available";
   else
     apSize.innerText=a[5];
   if(a[6]==""||a[6]=="Description")
      apLDesc.innerText="";
   else
      apLDesc.innerText=a[6];
}

// ***** V I E W C A R T . H T M *****
function FindItem(PartNo)
{  if(CartDB.length)
   {  for(i=0;i<CartDB.length;i++)
        if(Trim(CartDB[i].substr(0,20))==Trim(PartNo))
            return i;
   }
   return CartDB.length;
}

//******************************************
//* Join the shopping cart array into a str*
//*                                        *
//* Used in viewcart.htm                   *
//******************************************
function DoJoin()
{  a="";
   if(CartDB.length)
   {  for(i=0;i<CartDB.length;i++)
      {  if(CartDB[i]!="")
           a+=CartDB[i]+"|";
      }
   }
   return a;
}

//******************************************
//* Build the view shopping cart HTML.     *
//*                                        *
//* Used in: viewcart.htm                  *
//******************************************
function ViewCart()
{  var Finish="",f=0;
   GetCartFromCookie();
   if(!CartDB.length) return;
   document.write("<table border='1' bordercolor='#336600' cellpadding='2' cellspacing='0' bgcolorr='#FFFFFF' style='border-collapse: collapse; font-family: Tahoma; font-size: 10pt'>");
   Total=0;
   for(i=0;i<CartDB.length;i++)
   {  //aCrumb=aCookie[i].split("=");
      ParseDetail(CartDB[i]);
      Amount=Qty*Price;Total+=Amount;
      if(i==0)
        document.write("<tr><td align='center' bgcolor='#A2B194'>Delete</td><td align='center' bgcolor='#A2B194'>Qty</td><td align='center' bgcolor='#A2B194' width='75'>Part No</td><td align='center' bgcolor='#A2B194' width='300'>Description</td><td align='center' bgcolor='#A2B194' width='70'>Price</td><td align='center' bgcolor='#A2B194' width='70'>Amount</td></tr>");
      if(i&1) b="#D0D0D0"; else b="#E0E0E0";
      p='"'+PartNo+'"';
      f=PartNo.indexOf('/');
      if(f>-1) Finish=', '+GetFinishDesc(PartNo.substr(f+1,2));
      else Finish="";
      document.write("<tr><td align='center' bgcolor="+b+"><a href='javascript:DeleteItem("+p+");'><img border='0' src='images/deletebtn.gif' width='16' height='16'></a></td><td bgcolor="+b+">"+Qty+"</td><td width='75' bgcolor="+b+" nowrap>"+PartNo+"</td><td width='300' bgcolor="+b+">"+Desc+Finish+"</td><td align='right' width='70' bgcolor="+b+">"+FormatDecimal(Price)+"</td><td align='right' width='70' bgcolor="+b+">"+FormatDecimal(Amount)+"</td></tr>");
   }
   document.write("</table><br>");
   document.write("<table border='1' bordercolor='#336600' cellpadding='2' cellspacing='0' style='border-collapse: collapse; font-family: Tahoma; font-size: 10pt'>");
   document.write("<tr><td bgcolor='#A2B194' width='70'>Total</td><td bgcolor='#FFFFFF' width='70' align='right'>"+FormatDecimal(Total)+"</td></tr></table>");
}

//******************************************
//* Empty the shopping cart.               *
//*                                        *
//* Used in: viewcart.htm                  *
//******************************************
function EmptyCart()
{  GetCartFromCookie();
   if(CartDB.length&&confirm("Empty Your Shopping Cart?"))
      document.cookie="ShoppingCart=";
   history.back(1);
}

//******************************************
//* Delete an item from the shopping cart. *
//*                                        *
//* Used in: viewcart.htm                  *
//******************************************
function DeleteItem(PartNo)
{  if(confirm("Remove "+PartNo+" from the shopping cart?"))
   {  i=FindItem(PartNo);
      CartDB[i]="";
      document.cookie="ShoppingCart="+escape(DoJoin())+";";
      CartDB.length--;
      location.reload(1);
   }
}

// ***** O R D E R I N F O . H T M *****
//******************************************
//* List the contents of the shopping cart *
//* in a table format.                     *
//*                                        *
//* Used in:  orderinfo.htm                *
//******************************************
function ListCart(Info)
{  var Finish="",f=0,hiddenfield="",s="";
   GetCartFromCookie();
   if(!CartDB.length) return s;
   if(Info)
      document.write("<table border='1' cellpadding='2' cellspacing='0' bordercolor='#336600' style='border-collapse: collapse; font-family: Tahoma; font-size: 10pt'>");
   else
      s="<table border='1' cellpadding='2' cellspacing='0' bordercolor='#000000' style='border-collapse: collapse; font-family: Tahoma; font-size: 10pt' width='640'>";
   SubTotal=0;
   for(i=0;i<CartDB.length;i++)
   {  ParseDetail(CartDB[i]);
      Amount=Qty*Price;SubTotal+=Amount;
      f=PartNo.indexOf('/');
      if(f>-1) Finish=", "+GetFinishDesc(PartNo.substr(f+1,2));
      else Finish="";
      if(!i)
      {  hiddenfield="<input type='hidden' name='Items' value='"+CartDB.length+"'>";
         if(Info)
           document.write("<tr><td align='center' bgcolor='#A2B194'>Qty</td><td align='center' bgcolor='#A2B194' width='75'>Part No</td><td align='center' bgcolor='#A2B194' width='200'>Description</td><td align='center' bgcolor='#A2B194' width='70'>Price</td><td align='center' bgcolor='#A2B194' width='70'>Amount"+hiddenfield+"</td></tr>");
        else
           s+="<tr><td align='center' bgcolor='#F0F0F0'>Qty</td><td align='center' bgcolor='#F0F0F0' width='75'>Part No</td><td align='center' bgcolor='#F0F0F0'>Description</td><td align='center' bgcolor='#F0F0F0' width='70'>Price</td><td align='center' bgcolor='#F0F0F0' width='70'>Amount"+hiddenfield+"</td></tr>";
      }
      if(i&1)b="#B0B0B0";else b="#F0F0F0";
      hiddenfield="<input type='hidden' name='Item"+i+"' value='"+Qty+"-"+PartNo+"-"+Desc+Finish+"-"+FormatDecimal(Price)+"-"+FormatDecimal(Amount)+"'>";
      if(Info)
          document.write("<tr><td bgcolor="+b+">"+Qty+"</td><td width='75' bgcolor="+b+">"+PartNo+"</td><td width='200' bgcolor="+b+">"+Desc+Finish+"</td><td align='right' width='70' bgcolor="+b+">"+FormatDecimal(Price)+"</td><td align='right' width='70' bgcolor="+b+">"+FormatDecimal(Amount)+hiddenfield+"</td></tr>");
      else
      {  b="#FFFFFF";
         s+="<tr><td bgcolor="+b+">"+Qty+"</td><td width='75' bgcolor="+b+">"+PartNo+"</td><td bgcolor="+b+">"+Desc+Finish+"</td><td align='right' width='70' bgcolor="+b+">"+FormatDecimal(Price)+"</td><td align='right' width='70' bgcolor="+b+">"+FormatDecimal(Amount)+hiddenfield+"</td></tr>";
      }
   }
   SalesTax=SubTotal*.0725;Shipping=5.00+(SubTotal*.10);Total=SubTotal+SalesTax+Shipping;
   if(Info)
   {  document.write("</table><br>");
      document.write("<table id='TotalsTable' border='1' bordercolor='#336600' cellpadding='2' cellspacing='0' style='border-collapse: collapse; font-family: Tahoma; font-size: 10pt'>");
      document.write("<tr><td width='70' bgcolor='#A2B194'>Sub Total</td><td bgcolor='#FFFFFF' width='70' align='right'>"+FormatDecimal(SubTotal)+"<input type='hidden' name='SubTotal' value='"+FormatDecimal(SubTotal)+"'></td></tr>");
      document.write("<tr><td width='70' bgcolor='#A2B194'>Sales Tax (7.25%)</td><td bgcolor='#FFFFFF' width='70' align='right'>"+FormatDecimal(SalesTax)+"<input type='hidden' name='SalesTax' value='"+FormatDecimal(SalesTax)+"'></td></tr>");
      document.write("<tr><td width='70' bgcolor='#A2B194'>Shipping</td><td bgcolor='#FFFFFF' width='70' align='right'>"+FormatDecimal(Shipping)+"<input type='hidden' name='Shipping' value='"+FormatDecimal(Shipping)+"'></td></tr>");
      document.write("<tr><td width='70' bgcolor='#A2B194'><b>Total</b></td><td bgcolor='#FFFFFF' width='70' align='right'><b>"+FormatDecimal(Total)+"</b><input type='hidden' name='Total' value='"+FormatDecimal(Total)+"'></td></tr></table>");
   }
   else
   {  s+="</table><br>";
      s+="<table id='TotalsTable' border='1' bordercolor='#000000' cellpadding='2' cellspacing='0' style='position: relative; left: 490; top: 0; border-collapse: collapse; font-family: Tahoma; font-size: 10pt'>";
      s+="<tr><td width='70' bgcolor='#F0F0F0'>Sub Total</td><td bgcolor='#FFFFFF' width='70' align='right'>"+FormatDecimal(SubTotal)+"<input type='hidden' name='SubTotal' value='"+FormatDecimal(SubTotal)+"'></td></tr>";
      s+="<tr><td width='70' bgcolor='#F0F0F0'>Sales Tax (7.25%)</td><td bgcolor='#FFFFFF' width='70' align='right'>"+FormatDecimal(SalesTax)+"<input type='hidden' name='SalesTax' value='"+FormatDecimal(SalesTax)+"'></td></tr>";
      s+="<tr><td width='70' bgcolor='#F0F0F0'>Shipping</td><td bgcolor='#FFFFFF' width='70' align='right'>"+FormatDecimal(Shipping)+"<input type='hidden' name='Shipping' value='"+FormatDecimal(Shipping)+"'></td></tr>";
      s+="<tr><td width='70' bgcolor='#F0F0F0'><b>Total</b></td><td bgcolor='#FFFFFF' width='70' align='right'><b>"+FormatDecimal(Total)+"</b><input type='hidden' name='Total' value='"+FormatDecimal(Total)+"'></td></tr></table>";
   }
   return s;
}

//******************************************
//* Validate order info input and submit   *
//* the data                               *
//*                                        *
//*                                        *
//* Used in: orderinfo.htm                 *
//******************************************
function SubmitOrder()
{  var s="",pmttype="",shipinfo=0;
   if(Trim(document.frm.BillLname.value)=="") s="Blank last name\r\n";
   if(Trim(document.frm.BillFname.value)==""&&Trim(document.frm.BillLname.value)=="") s+="Blank first name\r\n";
   if(Trim(document.frm.BillAddress1.value)=="") s+="Blank address\r\n";
   if(Trim(document.frm.BillCity.value)=="") s+="Blank city\r\n";
   if(Trim(document.frm.BillState.options[document.frm.BillState.selectedIndex].value)=="none") s+="No state selected\r\n";
   if(!ValidateZip(document.frm.BillZip.value)) s+="Invalid zip code\r\n";

   if(Trim(document.frm.ShipLname.value)!="")
   {  t="Invalid Shipping Info - ";
      if(Trim(document.frm.ShipAddress1.value)=="") s+=t+"Blank address\r\n";
      if(Trim(document.frm.ShipCity.value)=="") s+=t+"Blank city\r\n";
      if(Trim(document.frm.ShipState.options[document.frm.BillState.selectedIndex].value)=="none") s+=t+"No state selected\r\n";
      if(!ValidateZip(document.frm.ShipZip.value)) s+=t+"Invalid zip code\r\n";
   }

   if(!ValidatePhone(document.frm.Phone.value)) s+="Invalid phone number\r\n";
   if(Trim(document.frm.Email.value)=="") s+="\r\n";
   pmttype=Trim(document.frm.PmtMethod.options[document.frm.PmtMethod.selectedIndex].value);
   if(pmttype=="none") s+="No payment method selected\r\n";
   if(!ValidateCardNo(pmttype,StripFormat(document.frm.CardNo.value))) s+="Invalid card number\r\n";
   if(Trim(document.frm.ExpMon.options[document.frm.ExpMon.selectedIndex].value)=="99") s+="No Exp. Date Month selected\r\n";
   if(Trim(document.frm.ExpYr.options[document.frm.ExpYr.selectedIndex].value)=="99") s+="No Exp. Date Year selected\r\n";
   if(s!="")
   {  alert(s);
      return;
   }
   BuildOrderFormOnline();//window.navigate("c:\\ironages/orderform.htm?"+s);
}

//******************************************
//* Build the order form HTML              *
//*                                        *
//* Used in: orderinfo.htm                 *
//******************************************
function BuildOrderFormOnline()
{  var s="";
   s="<html><head>";
   s+="<title>Confirm Order</title>";
   s+="</head><body style='font-family: Tahoma; font-size: 10pt'>";
   s+="<p align='center'><font size='3'><b>Iron Images</b></font><br>";
   s+="<font size='2'>7584 W.Azusa Rd.<br>Dos Palos, CA  93620<br>(209) 387-4235<br></font><font size='1'>www.ironages.com</font></p>";
   s+="<form name='frm' action='https://host80.ipowerweb.com/~ironages/cgi-bin/js-icart/processorder.cgi' method='POST'>"+PrintHeader()+ListCart(0);
   s+="<p align='left'><font size='2'>Please verify that your order information is correct and click the &quot;Submit your order&quot; button to place your order online. Otherwise, use your browser's &lt;Back&gt; button to return to the order information page and make your corrections.<br><br>Optionally, you may <a href='javascript:print();'>print</a> this page and <b>Fax</b> your order to Iron Images at <b>(209) 392-6133</b></font></p>";
   s+="<p align='center'><input type='submit' name='PrintButton' onclickk='frm.submit();' value='Submit your order'></p>";
   s+="<p align='center'><font size='5'>***** Thank you for your order! *****</font></p>";
   s+="</form></body></html>";
   var d=document.open("text/html","");d.write(s);d.close();
}

//******************************************
//* Build the order form HTML - FAX version*
//*                                        *
//* Used in: orderinfo.htm                 *
//******************************************
function BuildOrderForm()
{  var s="";
   s="<html><head>";
   s+="<title>Confirm Order</title>";
   s+="</head><body style='font-family: Tahoma; font-size: 10pt'>";
   s+="<p align='center'><font size='3'><b>Iron Images</b></font><br>";
   s+="<font size='2'>7584 W.Azusa Rd.<br>Dos Palos, CA  93620<br>(209) 387-4235<br></font><font size='1'>www.ironages.com</font></p>";
   s+="<form name='frm'>"+PrintHeader()+ListCart(0);
   s+="<p align='left'><font size='2'>Please verify that your order information is correct, print this page, and <b>Fax</b> it to Iron Images at<br><b>(209) 392-6133</b></font></p>";
   s+="<p align='center'></p>";//<input type='button' name='PrintButton' onclick='javascript:print();' value='Print your order'></p>";
   s+="<p align='center'><font size='5'>***** Thank you for your order! *****</font></p>";
   s+="</form></body></html>";
   var d=document.open("text/html","");d.write(s);d.close();
}

//******************************************
//* Build the order form header HTML       *
//*                                        *
//* Used by: BuildOrderForm()              *
//******************************************
function PrintHeader()
{  var s="",billz="",shipz="",billcsz="",shipcsz="";
   var billfname="",billlname="",billaddr1="",billaddr2="",billcity="",billst="",billzip="";
   var shipfname="",shiplname="",shipaddr1="",shipaddr2="",shipcity="",shipst="",shipzip="";
   var phone="",p="",email="",pmtmethod="",pmtstr="",cardno="",expmo="",expyr="",expdate="";

   billlname=Trim(document.frm.BillLname.value);billfname=Trim(document.frm.BillFname.value);
   billaddr1=Trim(document.frm.BillAddress1.value);billaddr2=Trim(document.frm.BillAddress2.value);
   billcity=Trim(document.frm.BillCity.value);
   billst=Trim(document.frm.BillState.options[document.frm.BillState.selectedIndex].value);
   billz=StripFormat(document.frm.BillZip.value);
   if(billz.length==5)
     billzip=billz;
   else
     billzip=billz.substr(0,5)+"-"+billz.substr(5,4);
   billcsz=billcity+", "+billst+"  "+billzip;

   shiplname=Trim(document.frm.ShipLname.value);
   if(shiplname!="")
   {  shipfname=Trim(document.frm.ShipFname.value);
      shipaddr1=Trim(document.frm.ShipAddress1.value);shipaddr2=Trim(document.frm.ShipAddress2.value);
      shipcity=Trim(document.frm.ShipCity.value);
      shipst=Trim(document.frm.ShipState.options[document.frm.ShipState.selectedIndex].value);
      shipz=StripFormat(document.frm.ShipZip.value);
      if(shipz.length==5)
        shipzip=shipz;
      else
        shipzip=shipz.substr(0,5)+"-"+shipz.substr(5,4);
      shipcsz=shipcity+", "+shipst+"  "+shipzip;
   }

   p=StripFormat(document.frm.Phone.value);
   phone=p.substr(0,3)+"-"+p.substr(3,3)+"-"+p.substr(6,4);
   email=Trim(document.frm.Email.value);
   pmtmethod=Trim(document.frm.PmtMethod.options[document.frm.PmtMethod.selectedIndex].value);
   pmtstr=GetPmtMethodStr(pmtmethod);cardno=Trim(document.frm.CardNo.value);
   expmo=Trim(document.frm.ExpMon.options[document.frm.ExpMon.selectedIndex].value);
   expyr=Trim(document.frm.ExpYr.options[document.frm.ExpYr.selectedIndex].value);
   expdate=expmo+"/"+expyr;
   s="<input type='hidden' name='BillLname' value='"+billlname+"'>";
   s+="<input type='hidden' name='BillFname' value='"+billfname+"'>";
   s+="<input type='hidden' name='BillAddress1' value='"+billaddr1+"'>";
   s+="<input type='hidden' name='BillAddress2' value='"+billaddr2+"'>";
   s+="<input type='hidden' name='BillCity' value='"+Trim(document.frm.BillCity.value)+"'>";
   s+="<input type='hidden' name='BillState' value='"+billst+"'>";
   s+="<input type='hidden' name='BillZip' value='"+billz+"'>";

   s+="<input type='hidden' name='ShipLname' value='"+shiplname+"'>";
   s+="<input type='hidden' name='ShipFname' value='"+shipfname+"'>";
   s+="<input type='hidden' name='ShipAddress1' value='"+shipaddr1+"'>";
   s+="<input type='hidden' name='ShipAddress2' value='"+shipaddr2+"'>";
   s+="<input type='hidden' name='ShipCity' value='"+Trim(document.frm.ShipCity.value)+"'>";
   s+="<input type='hidden' name='ShipState' value='"+shipst+"'>";
   s+="<input type='hidden' name='ShipZip' value='"+shipz+"'>";

   s+="<input type='hidden' name='Phone' value='"+p+"'>";
   s+="<input type='hidden' name='Email' value='"+email+"'>";
   s+="<input type='hidden' name='PmtMethod' value='"+pmtmethod+"'>";
   s+="<input type='hidden' name='CardNo' value='"+cardno+"'>";
   s+="<input type='hidden' name='ExpMon' value='"+expmo+"'>";
   s+="<input type='hidden' name='ExpYr' value='"+expyr+"'>";

   s+="<table border='0' width='640'>";
   s+=("<tr><td><table cellpadding='0' cellspacing='0'style='font-family: Tahoma; font-size: 10pt; border-top: 1 solid #000000; border-left: 1 solid #000000; border-bottom: 1 solid #000000; border-right: 1 solid #000000'>");
   if(billfname!="") billlname=billfname+" "+billlname;
   s+=("<tr><td>&nbsp;<b>Sold To:</b>&nbsp;</td><td>"+billlname+"&nbsp;</td></tr>");
   s+=("<tr><td>&nbsp;</td><td>"+billaddr1+"&nbsp;</td></tr>");
   if(billaddr2!="") s+=("<tr><td></td><td>"+billaddr2+"&nbsp;</td></tr>");
   s+=("<tr><td>&nbsp;</td><td>"+billcsz+"&nbsp;</td></tr></table></td>");

   s+=("<td align='right'><table cellpadding='0' cellspacing='0'style='font-family: Tahoma; font-size: 10pt; border-top: 1 solid #000000; border-left: 1 solid #000000; border-bottom: 1 solid #000000; border-right: 1 solid #000000'>");
   if(shipfname!="") shiplname=shipfname+" "+shiplname;
   if(shiplname=="") shiplname="Same";
   s+=("<tr><td>&nbsp;<b>Ship To:</b>&nbsp;</td><td>"+shiplname+"&nbsp;</td></tr>");
   s+=("<tr><td>&nbsp;</td><td>"+shipaddr1+"&nbsp;</td></tr>");
   if(shipaddr2!=""||billaddr2!="") s+=("<tr><td></td><td>"+shipaddr2+"&nbsp;</td></tr>");
   s+=("<tr><td>&nbsp;</td><td>"+shipcsz+"&nbsp;</td></tr></table></td></tr></table><br><br>");

   s+=("<table cellpadding='2' cellspacing='0' border='1' bordercolor='#000000' style='font-size: 10pt; border-collapse: collapse' width='640'>");
   s+=("<tr><td width='100' align='center' bgcolor='#F0F0F0'>Phone</td><td width='250' align='center' bgcolor='#F0F0F0'>Payment Method</td><td align='center' bgcolor='#F0F0F0'>E-Mail Address</td></tr>");
   s+=("<tr><td width=100'>"+phone+"</td><td width='270'>"+pmtstr+" "+cardno+"&nbsp;&nbsp;exp: "+expdate+"</td><td>"+email+"</td></tr></table><br><br>");
   return s;
}

//******************************************
//* Letter - Number functions              *
//*                                        *
//* Used by: BuildOrderForm()              *
//******************************************
function LetSizSel(Letter)
{  var pri,siz;
   siz=eval("document.frm."+Letter+"Size");
   pri=eval("document.frm."+Letter+"Price");
   pri.value=GetLetterPrice(siz.options[siz.selectedIndex].value);
}

function AddLetterToCart()
{  var a,chr,qty,fnt,ln,siz,objstr,ptno,desc,price;
   if(!CookiesEnabled()||PartNo=="") return;
   objstr="document.frm.";

   // Character.
   a=eval(objstr+"LetChr");
   chr=a.options[a.selectedIndex].value;

   // Qty.
   qty=eval(objstr+"LetQty.value");
   if(!isValidQty(qty))
   {  alert("Quantity must be between 1 and 999");
      return;
   }
   qty=pad(qty,3);

   // Font.
   a=eval(objstr+"LetFont");
   fnt=a.options[a.selectedIndex].value;

   // Size.
   a=eval(objstr+"LetSize");
   siz=a.options[a.selectedIndex].value;

   // Price.
   price=GetLetterPrice(siz);

   if(isdigit(chr)) ln="Number"; else ln="Letter";
   ptno=ln+chr+fnt+siz;

   GetCartFromCookie();
   i=FindItem(ptno);
   ptno=pad(ptno,20);
   desc=pad(ln+" &quot;"+chr+"&quot;, "+siz+" inch "+GetLetterFont(fnt),40);
   price=pad(price,7);
   CartDB[i]=ptno+qty+desc+price;
   document.cookie="ShoppingCart="+escape(DoJoin())+";";
   GotoViewCart();//alert(unescape(document.cookie));
}

function GetLetterPrice(Size)
{  var i;
   for(i=0;i<16;i+=2)
     if(Size==Letters[i])
       return(Letters[i+1]);
   return "0";
}

function GetLetterFont(Font)
{  var i;
   for(i=0;i<10;i+=2)
     if(Font==LetterFonts[i])
       return(LetterFonts[i+1]);
   return "";
}

// ***** Utility functions *****

// Extract the shopping cart cookie into an array.
function GetCartFromCookie()
{  aCookie=document.cookie.split("; ");
   for(i=0;i<aCookie.length;i++)
   {  aCrumb=aCookie[i].split("=");
      if(aCrumb[0]=="ShoppingCart")
      {  a=unescape(aCrumb[1]);
         CartDB=a.split("|");
         CartDB.length--;
         return;
      }
   }
   return;
}

// Extract individual fields from a line.
function ParseDetail(Line)
{  Qty=0;PartNo="";Desc="";Price=0;
   PartNo=Trim(Line.substr(0,20));
   Qty=parseInt(Line.substr(20,3));
   Desc=Trim(Line.substr(23,40));
   Price=parseFloat(Line.substr(63,7));
}

function GetFinishDesc(FinishCode)
{  var i=0;
   for(i=0;i<14;i++)
     if(Finishes[i]==FinishCode)
       return(Finishes[i+1]);
   return "";
}

// Pad a string with trailing spaces to a specified length.
function pad(s,l)
{  t=s;
   if(t.length>l)
     return t.substr(0,l);
   while(t.length<l)t+=" ";
   return t;
}

// Format a floating point number in xx.xx format.
function FormatDecimal(x)
{  var d=0,i=0,s="",s1="";
   i=Math.floor(x);
   d=Math.round((x-i)*100);
   if(d==100)
   {  i++;
      d=0;
   }
   s=i.toString();
   s1=d.toString();
   while(s1.length<2) s1='0'+s1;
   s=s+'.'+s1;
   return(s);
}

// Remove leading and trailing spaces from a string.
function Trim(s)
{  var b=0;
   if(s==""||s==' '||!s.length) return("");
   var e=s.length-1;
   while(b<s.length&&s.charAt(b)==' ') b++;
   if(b==s.length) return("");
   while(e>=0&&s.charAt(e)==' ') e--;
   if(e<0) return("");
   return(s.substring(b,e+1));
}

// Validate Qty.
function isValidQty(qty)
{  var i,q;
   qty=Trim(qty);
   q=qty.length;
   if(q<1||q>3) return(0);
   for(i=0;i<q;i++)
     if(qty.charAt(i)<'0'||qty.charAt(i)>'9') return(0);
   return(-1);
}

// Validate a telephone number.
function ValidatePhone(s)
{  var r="";
   s=Trim(s);
   r=StripFormat(s);
   return r.length==10;
}

// Validate Zip.
function ValidateZip(s)
{  var r="";
   s=Trim(s);
   r=StripFormat(s);
   return ((r.length==9)||(r.length==5));
}

// Validate credit card no.
function ValidateCardNo(pmttype,cardno)
{  if(pmttype==""||pmttype=="none") return 0;
   if(pmttype=="VS"&&(cardno.length==13||cardno.length==16)) return 1;
   if(pmttype=="MC"&&cardno.length==16) return 1;
   return 0;
}

// Return payment method string.
function GetPmtMethodStr(s)
{  if(s=="VS") return "Visa";
   if(s=="MC") return "MasterCard";
   return "";
}

// Check if cookies are enabled.
function CookiesEnabled()
{  if(navigator.appName.substr(0,5)=="Micro"&&!navigator.cookieEnabled)
   {  window.location.href="cookies-disabled.htm";
      // alert("Your browser must have cookies enabled to use JSCart");
      return(0);
   }
   return(1);
}

// Strip formatting characters from string.
function StripFormat(str)
{  var i,t="";
   for(i=0;i<str.length;i++)
     if(isdigit(str.charAt(i))) t+=str.charAt(i);
   return(t);
}

// Check for digit.
function isdigit(x){return (x>='0' && x<='9');}