// main javascript file for processing order.
//
// Modification Text: 
//
// 2011/10/01 m010 Prepare for liquidation sale.
// 
// 2005/11/02 m009 Change for godaddy.com web hosting.
//
// 2001/06/04 m008 Added "Ship to:" field. Already added new pay options.
//
// 2002/06/02 m007 Implemented changes for secure credit card page.
//
// 2001/02/08 m006 Fix problem calculating multiple items entered 
//               at different times. parseFloat vs parseInt
//
// 2000/12/08 m005 Add capability to list alpabetically or by item number.
//
// 2000/11/07 m004 set size for known sticker sizes
// 
// 2000/11/02 m003 Rewrite all code using tables in an attempt to load faster.
//
// 2000/10/30 m002 Removed unused code. 
//               Also, display number stickers ordered on catalog pages.
// 2000/10/19 m001 Change references in PayPal related code.
//
// for help see the following
// http://www.teleport.com/~danal/Pages/making.html
// http://www.newbie.net/sharky/frames/intro.htm
//
// Functions:   
//              function makeArray(totalSize)
//              function stickerInfo(numberOfStickers)
//              function searchCatalog(prodType)
//              function product (name,description,image,price,type,link,url)
//              function show(w,prodIndexNum)
//              function orderProd(obj,win,index)
//              function (w,prodIndex,stickerCounter)
//              function displayOrdered(w, prodIndex)
//              function add(id, oIndex)
//              function store(oID,totS,totQ)
//              function cartGoods(Indx, totSum, totQ)
//              function view()
//              function remove(item)
//              function checkOut()
//              function formData(form)
//              function reTotal(c,totalPrice)
//              function shipping(form, fSum)
//              function withTax(form)
//              function withoutTax(form)
//              function empty()
//              function currency(money)
//              function dispFrontPage(page)
//              function displayTOC()
//

  // make sure this is a multiple of 2
  var TRUE = 1;
  var FALSE = 0; 

  var gDiscount = 0;
  var gShipCost = 0     
  var gTotalNumStickers=0;  
  var gMenuColor="lightgrey";  // orange is #FFA500 green is #00FF00
  var gPageSize = 10;      // the number of stickers per page
  var gMaxDispChars = 30;  // number description chars to display on view
  var gPageNum = 0;        // current page number
  var gPageNumMax = 0;     // maximum number of pages of stickers
  var gOrderNum = 0;       // order number
  var productCounter;
  var formSave;
  var ccTotal;            // credit card total 
  var PriorityMailCost = 3.50; // assume one envelope for priority mail
  var SalesTax = 0.0775;
  var orderNumberString;   

function makeArray(totalSize)
{
  this.length = totalSize;

  for(var i = 1; i <= totalSize; i++) 
  {
    this[i] = 0;
  }

  return this;

}

var order = new makeArray(100);

function stickerInfo(numberOfStickers)
{

  gTotalNumStickers = numberOfStickers;

  // calculate number of pages necessary for stickers
  gPageNumMax = Math.floor(numberOfStickers / gPageSize);  // get maximum page numbers

  if (numberOfStickers % gPageSize)
    gPageNumMax++;

  orderOnPage = new Array(gPageNumMax);
}

function dispLink(link)
{  
  window.open(link);
}

function searchCatalog(prodType)
{
  productCounter = 0;
  stickerCounter = 0;  

  var match = false;
 
  tWin = parent.frames['catalog'].document;
 
  tWin.open();

  tWin.write("<HTML><HEAD><TITLE>Stickers "+  prodType + " </TITLE></HEAD>");

  tWin.write("<BODY TEXT=#000000 BGCOLOR=#000000>");

  if ("BLS" == prodType.substring(0,3))
  {
    // determine page number from cat_toc.htm page...
    // i.e.  "BLS-01"... "BLS-nn" where n = 01..99
    gPageNum = parseInt(prodType.substr(4,2),10);

    tWin.write("<TABLE BGCOLOR=lightgrey BORDER=1 COLS=2>");
	tWin.write("<TR><TD COLSPAN=2 BGCOLOR=black ALIGN=LEFT><CENTER><FONT COLOR=YELLOW SIZE=-1><b>Page "+gPageNum+" of "+gPageNumMax+"</b><br>At checkout, a <b>50% DISCOUNT WILL BE APPLIED TO YOUR ENTIRE ORDER!!</b>.  That's right... 50%!!</FONT></CENTER></TD></TR>");
	
    // search through the database
    for (var i = (((gPageNum-1)*gPageSize)+1); i <= prodID.length; i++)
    {
      // look for the "BLS" string
      if (prodType.substring(0,3) == prodID[i].type)
      {        
        stickerCounter++;

        prodID[i].show(tWin,i,stickerCounter);

        if (stickerCounter >= gPageSize)
          break;

        match = true;
      }
    }

    if (stickerCounter == 0)
      alert("No stickers available on this page");

    if (gPageNum == 1)
    {
      tWin.write("<TR><TD ALIGN=CENTER><< Previous</TD><TD ALIGN=CENTER><A HREF=javascript:parent.searchCatalog(&quot;BLS-"+(gPageNum+1)+"&quot;)> Next >></A></TD><TR>");
    }
    else if (gPageNum == gPageNumMax)
    {
      tWin.write("<TR><TD ALIGN=CENTER><A HREF=javascript:parent.searchCatalog(&quot;BLS-"+(gPageNum-1)+"&quot;)><< Previous</A></TD><TD ALIGN=CENTER>Next >></TD><TR>");
    }
    else
    {
      tWin.write("<TR><TD ALIGN=CENTER><A HREF=javascript:parent.searchCatalog(&quot;BLS-"+(gPageNum-1)+"&quot;)><< Previous</A></TD><TD ALIGN=CENTER><A HREF=javascript:parent.searchCatalog(&quot;BLS-"+(gPageNum+1)+"&quot;)> Next >></A></TD><TR>");
    }

    tWin.write("</TABLE></CENTER>");

  } 
  else 
  { 
    // normal product
    for (var i = 1; i <= prodID.length; i++)
    {

      if (prodType == prodID[i].type)
      {

        prodID[i].show(tWin,i);

        match = true;

      }  // else if

    }    // else for

  }      // end else

  tWin.write("</BODY></HTML>");

  tWin.close();

}


// This function is invoked in the javascript file database.js

function product (name,description,image,price,type,link,url)
{
  this.name = name;
  this.description = description;
  this.image = image
  this.price = price;
  this.type = type;
  if ("BLS" == type.substring(0,3))
  {
    this.show = showStickers;
    this.link = link;
  }
  else
  {
    this.show = show;

    if (link != "")
    {
      this.link = "<CENTER><TABLE BORDER=0><TR><TD><A HREF='" + url + "'><Font face=arial size=-2>" + link + "</FONT></A></TD></TR></TABLE></CENTER>";
    } 
    else
    {
      this.link = "";
    }
  }

}

function show(w,prodIndexNum)
{  
  w.write("<CENTER><TABLE BORDER= 0 WIDTH=300><TR><TD BGCOLOR=ivory><FONT FACE='arial' COLOR=blue><b>"  + this.name + "</b></FONT></TD></TR></TABLE></CENTER>");

  if (this.image.length > 1)
  {
    w.write("<CENTER><TABLE BORDER=0 COLS=2 WIDTH=300 BGCOLOR=ivory>");
    w.write("<TR BGCOLOR=#99CCFF><TD><FONT FACE = 'Arial' SIZE = 2 >Image</FONT></TD>");
    w.write("<TD><FONT FACE = 'Arial' SIZE = 2 >Description</FONT></TD></TR>");
    w.write("<TR><TD><IMG SRC='" + this.image + "'></TD>");
    w.write("<TD><FONT FACE = 'Arial' SIZE = 2 >" + this.description + "</TD></TR></Table></CENTER>");
  }
  
  if (this.link != "")
  {
    w.write(this.link);
  }

  w.write("<FORM NAME=isaiah>");

  orderProd(this,w,prodIndexNum);

  w.write("</FORM><HR SIZE=1 NOSHADE WIDTH=90%><br>");
          
}
    

function orderProd(obj,win,index)
{

  win.write("<CENTER><TABLE BORDER=0 COLS=2 WIDTH=300 BGCOLOR=#CCCCCC><TR><TD><FONT FACE = 'arial' size=-1><b>Price Each: $</b>" + currency(obj.price) +"</font></CENTER>");

  win.write("<CENTER>&nbsp;&nbsp;<FONT FACE = 'arial' size=-1><b>Enter Quantity:</b></font>  " + "<INPUT TYPE = 'text' SIZE = 3 NAME = 'q' VALUE = '1' onBlur = parent.reTotal("+ parent.productCounter + "," +  obj.price + ") onFocus = parent.reTotal("+ parent.productCounter + "," +  obj.price + ")><br></CENTER>");

  win.write("<CENTER>&nbsp;&nbsp;<FONT FACE = 'arial' size=-1><b>Total:" + " $</b></font><INPUT TYPE = 'text' SIZE=7 NAME=subTotal VALUE =" + currency(obj.price) + ">&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;" + "<INPUT TYPE ='button' VALUE = 'SubTotal' onClick = parent.reTotal("+ parent.productCounter + "," +  obj.price + ")></TR></TABLE></CENTER>");

  win.write("<CENTER><IMG SRC=images/pickit.gif ALIGN=TEXTTOP><A HREF=javascript:parent.add(" + parent.productCounter + "," + index + ")><IMG SRC=images/addtocart.gif border=0></A></CENTER>");

   productCounter++;

}

// this function depends upon the database.js to have the following format
//                                                              prod
//                         stk#  description    image     price type  link description    link url (null string)
// prodID[1] = new product("001","3x5/red,blue","001.gif",1.00, "BLS","This is the text","");

function showStickers(w,prodIndex,stickerCounter)
{                                
  if (this.image.length > 1)
  {
    if (stickerCounter % 2)  // if odd numbered index, start a new row
      w.write("<TR>");

    w.write("<TD BGCOLOR=lightgrey>");

    // firstLetter   = this.name.substring(0,1);
    stickerNumber = parseInt(this.name);

    // m004 set size for stickers of known size
    // if (stickerNumber < 1000 || firstLetter == "C") 
    if (stickerNumber < 1100)
    {        
      w.write("<IMG ALIGN=BOTTOM WIDTH=200 WIDTH=60 HSPACE=0 VSPACE=0 BORDER=0 SRC='newStickers/"+ this.image + "'>");
    }
    else
    {
      w.write("<IMG ALIGN=BOTTOM HSPACE=0 VSPACE=0 BORDER=0 SRC='newStickers/"+ this.image + "'>");
    }

    w.write("<br><FONT FACE='arial' SIZE=-2>#"+this.name+" </FONT><FONT face=arial size=-2 color=#FF3300>"+this.description+"</FONT>");

    displayOrdered(w,prodIndex); // m002 show how many ordered  

    w.write("<FORM NAME='"+this.name+"'><FONT FACE='arial' SIZE=-2>");

    w.write("<INPUT TYPE='TEXT' SIZE=2 NAME='q' VALUE='1'");

    w.write("onBlur=parent.reTotal("+parent.productCounter+","+this.price+") ");

    w.write("onFocus=parent.reTotal("+parent.productCounter+","+this.price+")> @ $"+currency(this.price)+" ");

    w.write("<INPUT TYPE=hidden NAME=subTotal VALUE="+currency(this.price)+"></FONT>");

    w.write("<A HREF=javascript:parent.add("+parent.productCounter+","+prodIndex+")><IMG SRC=images/addtocart.gif border=0 vspace=0 hspace=0></A>");

    w.write("</FORM></TD>");

    productCounter++;

    if (!(stickerCounter % 2))  // if odd numbered index, start a new row
      w.write("</TR>");
  }
}

// m002 make so user can see how many they've ordered of each sticker  
function displayOrdered(w, prodIndex)
{
  for (var i = 1; i <= gOrderNum; i++)
  {  
    if (order[i].ID == prodIndex)
    {
      w.write("<FONT face=arial size=-2 color=blue> - Your cart contains [ "+order[i].totQ+" ]</FONT>");
      break;
    }
  }   
}

// This pops up a confirmation box. The first is (0,1), next (1,2)
function add(id, oIndex)
{
  var theForm =  parent.frames['catalog'].document.forms[id];

  productName = prodID[oIndex].name;

  totalSum = parent.frames['catalog'].document.forms[id].subTotal.value;

  totalQuantity =  parent.frames['catalog'].document.forms[id].q.value;

  if (totalQuantity == 0)
  {
    alert("You entered a quantity of 0!\n We cannot process this order");

    parent.frames['catalog'].document.forms[id].q.value = 1;

    reTotal(id,prodID[oIndex].price);

  } 
  else
  {
    if (confirm("You are adding " + totalQuantity + " order/s of " + productName + " \n Subtotal: " + totalSum + " to your shopping cart."))
    {
      store(oIndex,totalSum,totalQuantity);

      // update screen need to scroll
      orderOnPage[gPageNum] = TRUE;

      parent.displayTOC();
    } 
    else
    {
      alert("\n\nThis order was not placed in your shopping cart.");
    }
  }
}


function store(oID,totS,totQ)
{
  var newOrder = TRUE;

  // m003 if an order already exists for this product, add to it
  for (var i = 1; i <= gOrderNum; i++)
  {
    if (order[i].ID == oID)
    {
      ts = parseFloat(order[i].totSum) + parseFloat(totS);
      tq = parseInt(order[i].totQ)   + parseInt(totQ);
      
      order[i].totSum = ts;
      order[i].totQ   = tq;      
      newOrder = FALSE;
    }
  }

  if (newOrder == TRUE)
  {
    // otherwise, create a new order
    gOrderNum++;

    order[gOrderNum] = new cartGoods(oID,totS,totQ);
  }

  showTotal = 0;

  for(var i = 1; i <= gOrderNum;i++)
  {
    showTotal += parseFloat(order[i].totSum);                
  }

  parent.frames['cart'].document.forms[0].runningTotal.value = currency(showTotal);

}

function cartGoods(Indx, totSum, totQ)
{
  this.ID = Indx;                   // ccc
  this.Indx = prodID[Indx].name;
  this.totSum = totSum;

  this.totQ = totQ;

  this.prodType = prodID[Indx].type; // so we can apply discounts for stickers
}


function view()
{
  vWin = parent.frames['catalog'].document;
  vWin.open();
  vWin.write("<HTML><BODY BGCOLOR=#D3D3D3 text=Black>");

  if (gOrderNum != 0)
  {
    vWin.write("<H2>Your Shopping Cart Contents</H2></CENTER>");
    vWin.write("<FORM><TABLE BORDER=1 WIDTH=100%>");
    vWin.write("<TD COLSPAN=1 BGCOLOR=#ffcc00><FONT face=arial COLOR=WindowText>Quantity</FONT></TD>");
    vWin.write("<TD COLSPAN=1 BGCOLOR=#ffcc00><FONT face=arial COLOR=WindowText>Product</FONT></TD>");
    vWin.write("<TD COLSPAN=1 BGCOLOR=#ffcc00><FONT face=arial COLOR=WindowText>Price</FONT></TD>");
    vWin.write("<TD COLSPAN=1 BGCOLOR=#ffcc00><FONT face='Arial' size=2 COLOR=WindowText></FONT></TD><TR>");

	// sort the order info
  	for (var i = 1; i <= gOrderNum; i++)
      for (var j = gOrderNum; j > i; j--)
	  {
		if (order[j-1].Indx > order[j].Indx)
		{
		  var T = order[j-1];
		  order[j-1] = order[j];
		  order[j] = T;
		}
      }

    for (var i = 1; i <= gOrderNum; i++)
    {
      vWin.write("<TD COLSPAN=1 align=center BGCOLOR=#D5D5FF><FONT COLOR=WindowText face='Arial' Size=3>"+order[i].totQ+"</FONT></TD>");
      vWin.write("<TD COLSPAN=1 align=left BGCOLOR=#D5D5FF><FONT COLOR=WindowText face='Arial' Size=3>"+order[i].Indx+"</FONT>");
      
      // --- changes for sticker description
      if ("BLS" == order[i].prodType)
      {
        vWin.write("-<FONT Size-1>"+prodID[order[i].ID].link.substring(0,gMaxDispChars));
         
        if (prodID[order[i].ID].link.length > gMaxDispChars)
          vWin.write("...</TD>");
        else
          vWin.write("</TD>");
      }
      else
        vWin.write("</TD>");
      
      vWin.write("<TD COLSPAN=1 align=center BGCOLOR=#D5D5FF><FONT COLOR=WindowText face='Arial' Size=3>"+parent.currency(order[i].totSum)+"</FONT></TD>");
      vWin.write("<TD VAlign=TOP align=center BGCOLOR=white><input type='checkbox' Name=checkbox"+i+" onclick=parent.remove("+i+")></Font>");
      vWin.write("<FONT COLOR=WindowText face='Arial' Size=1><b>Check here to remove item</b></FONT></TD></TR>");
    }

    vWin.write("</TABLE></FONT></FORM><br><TABLE BORDER=0 COLS=4 WIDTH=100% >");
    vWin.write("<TR><TD><A HREF = javascript:parent.checkOut(); return true;><font size=-2 face=arial>Check Out</font></A></TD><TD><A HREF=catalog.htm><font size=-2 face=arial>Store Front</font></A></TD></TR></TABLE>");

  }
  else
  {
    vWin.write("<FONT SIZE = 5 FACE = 'arial'><br>" + "<br><IMG SRC=images/noitem.gif border=0></FONT>");
    vWin.write("<A HREF = javascript:parent.checkOut(); return true;><font size=-2 face=arial>Check Out</font></A><A HREF=catalog.htm><font size=-2 face=arial>Store Front</font></A>");
  }
  
  vWin.write("</BODY></HTML>");

  vWin.close();
}


function remove(item)
{
  var newSum = 0;
  for (var i = item+1; i <= gOrderNum; i++)
  {
    if (item == gOrderNum)
    {
      order[i].ID = 0;

      order[i].Indx = "";
      order[i].totSum = 0 ;
      order[i].totQ = "";

      order[i].prodType = "";

      break;
          
    } 
    else
    {
      order[i-1].ID     = order[i].ID;
      order[i-1].Indx   = order[i].Indx;
      order[i-1].totSum = order[i].totSum;
      order[i-1].totQ   = order[i].totQ;
   
      order[i-1].prodType = prodID[order[i].ID].type;

    }
  }
  
  gOrderNum--;

  for(var i = 1; i <= gOrderNum; i++)
  {
    newSum += parseFloat(order[i].totSum);
  }
  
  parent.frames['cart'].document.forms[0].runningTotal.value = currency(newSum);

  view();
}


function checkOut()
{
  dateObj = new Date();
  date = dateObj.toLocaleString();
  tmpString = String(Number(dateObj));
  orderNumberString = tmpString.substring(tmpString.length-6, tmpString.length);

  stickerCount = 0;

  if (gOrderNum != 0)
  {
    cWin = parent.frames['catalog'].document;
    cWin.open();
    cWin.write("<HTML><BODY BGCOLOR=#D3D3D3 TEXT=#000000>");
    cWin.write("<H2>Check Out Page</H2><Table border=1><tr>");

    grandTotal = 0;

    cWin.write("<TD COLSPAN=1 BGCOLOR=#ffcc00><FONT face=arial COLOR=WindowText>Quantity</FONT></TD>");
    cWin.write("<TD COLSPAN=1 BGCOLOR=#ffcc00><FONT face=arial COLOR=WindowText>Product</FONT></TD>");
    cWin.write("<TD COLSPAN=1 BGCOLOR=#ffcc00><FONT face=arial COLOR=WindowText>Price</FONT></TD>");
    cWin.write("<TD COLSPAN=1 BGCOLOR=#ffcc00><FONT face=arial COLOR=WindowText>Total Price</FONT></TD></TR>");

	// sort the order info
    for (var i = 1; i <= gOrderNum; i++)
    {
      for (var j = gOrderNum; j > i; j--)
	  {
	 	if (order[j-1].Indx > order[j].Indx)
		{
		  var T = order[j-1];
		  order[j-1] = order[j];
		  order[j] = T;
		}
	  }
    }

    for(var i = 1; i <= gOrderNum; i++)
    {
      cWin.write("<TD COLSPAN=1 align=center BGCOLOR=#d5d5ff><FONT COLOR=WindowText face='Arial' Size=2>"+order[i].totQ+"</FONT></TD>");
      cWin.write("<TD COLSPAN=1 align=left BGCOLOR=#d5d5ff><FONT COLOR=WindowText face='Arial' Size=2>"+order[i].Indx+"</FONT>");

      // Changes to implement sticker text ---
      if ("BLS" == order[i].prodType)
      {
        cWin.write("-<FONT Size-1>"+prodID[order[i].ID].link.substring(0,gMaxDispChars));
         
        if (prodID[order[i].ID].link.length > gMaxDispChars)
          cWin.write("...</FONT></TD>");
        else
          cWin.write("</FONT></TD>");
      }
      else
        cWin.write("</TD>");

      cWin.write("<TD COLSPAN=1 align=center BGCOLOR=#d5d5ff><FONT COLOR=WindowText face='Arial' Size=2>"+parent.currency(order[i].totSum/order[i].totQ)+"</FONT></TD>");

      // count stickers so we can apply discount
      if ("BLS" == order[i].prodType.substring(0,3))
        stickerCount += parseInt(order[i].totQ);
 
      cWin.write("<TD COLSPAN=1 align=center BGCOLOR=#d5d5ff><FONT COLOR=WindowText face='Arial' Size=2>"+parent.currency(order[i].totSum)+"</FONT></TD></TR>");
      grandTotal += parseFloat(order[i].totSum); 
    }
 
    // Five sticker minimum
    if (grandTotal < 5.00)
    {
      alert("We appreciate your order. However, we ask that your order total at least $5. Thanks .");
    } 

    // calculate any discounts here
    // gDiscount = Math.floor(stickerCount / 6);
    gDiscount = (grandTotal * 0.50); 

    // show discounts here if applicable
    cWin.write("<TD COLSPAN=3 ALIGN=CENTER bgcolor='#009933'><font face=arial COLOR=#ffcc00 Size=3><b>Less 50% Discount</b></font></TD>");

    cWin.write("<TD COLSPAN=1 ALIGN=CENTER bgcolor='#009933'><font face=arial COLOR=#ffcc00 Size=2>-" + parent.currency(gDiscount) + "</font></TD></TR>");

    // calculate final sum here
    finalSum = currency(grandTotal - gDiscount);

    cWin.write("<TD COLSPAN=3 ALIGN=CENTER bgcolor='#009933'><font face=arial COLOR=#ffcc00><b>Total</b></font></TD>");
    cWin.write("<TD COLSPAN=1 ALIGN=CENTER bgcolor='#009933'><font face=arial COLOR=#ffcc00><b>$ " + currency(grandTotal - gDiscount) + " </b></font></TD></TR>");

    cWin.write("<TR><TD COLSPAN=4><FONT COLOR=RED SIZE=1>NOTE: MS Internet Explorer users should use the TAB key to move between fields. Using the ENTER key causes the incomplete form to be submitted. I'm trying to determine a fix for this. Thanks. <br> Chuck</FONT>");

    cWin.write("</TD></TR></TABLE>");

    // the following lines are specific to BFormMail defined below.
    // use this one to invoke the script that sends various fields to multiple recipients

    cWin.write("<FORM NAME='orderform' OnSubmit='return false' METHOD='POST' ACTION='/cgi/BFormMailOutpost.cgi'>");

    cWin.write("<input type='hidden' name='courtesy_reply' value='yes'>");
    cWin.write("<input type='hidden' name='courtesy_reply_texta' value='This is an automated order confirmation. Thank you for your order. Feel free to contact us regarding questions about your order or suggestions for the web site.'>");
    cWin.write("<input type='hidden' name='courtesy_reply_textb' value='Please note:  If you did not specify a payment option, your order will not be processed.'>");
    cWin.write("<input type=hidden name='courtesy_who_we_are' value='Chuck Cox'>");
    cWin.write("<input type=hidden name='courtesy_who_we_are2' value='Bikers&#39; Outpost'>");
    cWin.write("<input type=hidden name='courtesy_our_url' value='https://www.bikersoutpost.com'>");
    cWin.write("<input type=hidden name='courtesy_our_email' value='sales@bikersoutpost.com'>");

    // cWin.write("<input type=hidden name='bcc' value='coxcc@yahoo.com'>");
    // cWin.write("<input type=hidden name='return_link_url' value='http://www.bikersoutpost.com'>");
    // cWin.write("<input type=hidden name='return_link_title' value='Back to Main Page'>");

    cWin.write("<INPUT TYPE='hidden' NAME='recipient' VALUE='sales@bikersoutpost.com'>");
    cWin.write("<INPUT TYPE='hidden' NAME='title' VALUE='<center>Bikers&#39; Outpost<br>Order Form & Payment Option</center>'>");
    cWin.write("<INPUT TYPE='hidden' NAME='subject' VALUE='Bikers&#39; Outpost Order!'>");
    cWin.write("<INPUT TYPE='hidden' NAME='ordernum' VALUE=''>");

    cWin.write("<INPUT TYPE='hidden' NAME='required' VALUE='realname,address,city,state,zip,email'>");

    cWin.write("<INPUT TYPE='hidden' NAME='print_config' VALUE='orderNumberString,date,realname,address,city,state,zip,homephone,email,order,ccAmount,stickerCount'>")

    cWin.write("<table border='0' columns='4' width='90%' cellspacing='0' cellpadding='0'>");
    cWin.write("<tr><td><strong>Order:&nbsp;&nbsp;"+orderNumberString+"</strong></td>"); 
    cWin.write("<td colspan='3'><strong>"+date+"</strong></td></tr>");
    cWin.write("<tr><td colspan='4'><hr></td></tr>");
    
    // bill to address
    cWin.write("<tr><td colspan='4'><strong>Bill to:</strong></td></tr>");
    cWin.write("<tr><td><p><strong>Name:</strong></td>");
    cWin.write("<td ><input type='text' name='realname' size='44'></td></tr>");
    cWin.write("<tr><td><strong>Address:</strong></td>");
    cWin.write("<td ><input type='text' name='address' size='44'></td></tr>");
    cWin.write("<tr><td><strong>City:</strong></td>");
    cWin.write("<td ><input type='text' name='city' size='44'></td></tr>");
    cWin.write("<tr><td><strong>State/Province:</strong></td>");
    cWin.write("<td><input type='text' name='state' size='10'>");
    cWin.write("<strong>Zip/Postal Code:</strong><input type='text' name='zip' size='10'></td></tr>");
    cWin.write("<tr><td align='left'><strong>Country:</strong></td>");
    cWin.write("<td align='left' ><input type='text' name='country' size='40' value='United States'></td></tr>");
    cWin.write("<tr><td align='left'><strong>Phone:</strong></td>");
    cWin.write("<td align='left' ><input type='text' name='homephone' size='20'>&nbsp;&nbsp;ex: 111-222-3333</td></tr>");
    cWin.write("<tr><td align='left'><strong>E-Mail:</strong></td>");
    cWin.write("<td align='left' colspan='3'><input type='text' name='email' size='20'>&nbsp;&nbsp;(for order confirmation)</td></tr>");
    cWin.write("<tr><td colspan='4'><hr></td></tr>");

    // shipping address
    cWin.write("<tr><td colspan='4'><strong>Ship to: (if different than billing address)</strong></td></tr>");
    cWin.write("<tr><td><p><strong>Name:</strong></td>");
    cWin.write("<td ><input type='text' name='sh_name' size='44'></td></tr>");
    cWin.write("<tr><td><strong>Address:</strong></td>");
    cWin.write("<td ><input type='text' name='sh_address' size='44'></td></tr>");
    cWin.write("<tr><td><strong>City:</strong></td>");
    cWin.write("<td ><input type='text' name='sh_city' size='44'></td></tr>");
    cWin.write("<tr><td><strong>State/Province:</strong></td>");
    cWin.write("<td><input type='text' name='sh_state' size='10'>");
    cWin.write("<strong>Zip/Postal Code:</strong><input type='text' name='sh_zip' size='10'></td></tr>");
  	cWin.write("<tr><td align='left'><strong>Country:</strong></td>");
    cWin.write("<td align='left' ><input type='text' name='sh_country' size='44'></td></tr>");

    cWin.write("<tr><td colspan='4'><hr></td></tr>");
    cWin.write("<tr><td align='left'><p><strong>Sub-total</strong></td>");
    cWin.write("<td align='left' colspan='3'><input type='text' name='field_subTotal' size=6 value="+currency(grandTotal-gDiscount)+" readonly=true onFocus='this.blur()'></td></tr>");
    cWin.write("<tr><td align='left'><p><strong><u>Shipping</strong></td>");

    
    gShipCost = shipping();
    cWin.write("<td align='left' colspan='3'><u><input type='text' name='field_shipping' size=6 value="+currency(gShipCost)+" readonly=true onFocus='this.blur()'></u>&nbsp;&nbsp;(to all U.S. and most int'l customers)</td></tr>");

    ccTotal = grandTotal - gDiscount + gShipCost;

    cWin.write("<tr><td align='left'><p><strong>Total</strong></td>");   
    cWin.write("<td align='left' colspan='3'><input type='text' name='field_Total' size=6 value="+currency(ccTotal)+" readonly=true onFocus='this.blur()'>&nbsp;&nbsp;(this is the amount you owe)</td></tr>");

    cWin.write("<tr><td colspan='4'><hr></td></tr>");

    cWin.write("<tr><td colspan='4'><INPUT TYPE = 'submit' VALUE = 'Click Here to Select Payment Option' onClick = 'parent.formData(this.form)' onmouseover='window.status=&quot;Submit Order & Select Payment Option &quot;'></td></tr><tr><td colspan='4'><hr></td></tr>");

    // --- ccc note: the readonly attribute above may only be MS Explorer compatible 
 
    cWin.write("</table>");

    cWin.write("<input type=hidden name='stickerCount' VALUE="+stickerCount+">");
    
    cWin.write("<INPUT TYPE='hidden' NAME='subtotal' VALUE=''>");
    cWin.write("<INPUT TYPE='hidden' NAME='discount' VALUE=''>");
    cWin.write("<INPUT TYPE='hidden' NAME='shipping' VALUE=''>");
    cWin.write("<INPUT TYPE='hidden' NAME='total' VALUE=''>");
    cWin.write("&nbsp;&nbsp;<INPUT TYPE = 'hidden' NAME='order' VALUE = ''>");
//    cWin.write("<p><FONT SIZE=-1><b>To mail or FAX orders, click here >>></b> </FONT><INPUT TYPE = 'button' VALUE = 'Print Order' onClick = 'window.print()'>"); 

    cWin.write("</FORM>");
    cWin.write("</b></FONT><p></CENTER></BODY></HTML>");
    cWin.close();
  } 
  else
  {
    alert("\n\nYour shopping cart is empty!\n\n");
  }
}

function formData(form)
{
  var formElems = form.elements.length;
  formSave = new makeArray(formElems-3);
  for (var i = 1; i <= formElems; i++)
  {
    formSave[i] = form.elements[i-1].value;
  }

  for (var i = 1; i <= gOrderNum; i++)
  {
    form.elements['order'].value += "\n<br>Qty:" + order[i].totQ
    form.elements['order'].value += " #" + order[i].Indx
    form.elements['order'].value += " at " + currency(order[i].totSum/order[i].totQ)
  }

  form.elements['subtotal'].value = currency(grandTotal);

  form.elements['discount'].value = currency(-gDiscount);

  form.elements['shipping'].value = currency(gShipCost);
  
  form.elements['total'].value = currency(ccTotal);

  form.elements['subject'].value = "Bikers' Outpost Order " + orderNumberString;
	  
  form.elements['ordernum'].value = orderNumberString;
	  
  form.submit();
}


function reTotal(c,totalPrice)
{
  totalPrice = totalPrice * parent.frames['catalog'].document.forms[c].q.value;

  newTotal = currency(totalPrice); 

  parent.frames['catalog'].document.forms[c].subTotal.value = newTotal;    
}

 
function shipping()
{

  return (1.00);

  // gShipCost = form.shipSelection.options[form.shipSelection.selectedIndex].value;
  // gShipCost = "0.15" * fSum;

  // form.finalTot.value =currency( parseFloat(gShipCost) + parseFloat(fSum));

  
}


// Aledo, Texas tax rate of 7.75%
function withTax(form)
{
  form.finalTax.value =currency(grandTotal * 7.755/100);
}
	

function withoutTax(form)
{
  form.finalTax.value =0;
}


function empty()
{
  if (gOrderNum == 0)
  {
    alert("\n\nYour cart is already empty!\n\n");
  } 
  else
  {
    gOrderNum = 0;
    alert("\nYour cart has been emptied!\n");
  }   
}


function currency(money)
{
  money = money + ""           

  var monLen = money.length;

  var digPos = money.indexOf(".");

  if(digPos == -1 & monLen < 1)
  {
    money = money.substring(0,digPos+ 1) + "00";
  } 
  else if(digPos == -1 & monLen > 0)
  {
    money = money + ".00";
  }
  else
  {
    cents = money.substring(digPos + 1, monLen + 1);

    if(cents.length == 1)
    {
      money = money + "0";
    }
    else if (cents.length > 2)
    {
      roundVal = cents.charAt(2);

      if(roundVal  >= 5)
      {
        money = parseFloat(money) + .01;

        money = money + "";

        money = money.substring(0,digPos + 3)

      } 
      else
      {
        money = money.substring(0,digPos + 3)
      }
    }
  }

  return money;
}

function dispFrontPage(page)
{
  top.frames['catalog'].location = page;
}

function displayTOC()
{
  var page = 0;

  tWin = parent.frames['toc'].document;
  tWin.open();
  tWin.write("<HTML><STYLE TYPE='text/css'><!-- A:active  { color:#FF4500; } A:link    { color:#000000; } A:visited { color:#000000; } A:hover   { color:#FF4500; } --></STYLE><HEAD><TITLE>BLS Stickers Table of Contents </TITLE></HEAD>");
  tWin.write("<BODY BGCOLOR=#000000 LINK=#000000 VLINK=#000000>");

  tWin.write("<CENTER><TABLE BORDER=0><TH BGCOLOR="+gMenuColor+"><CENTER><FONT FACE=ARIAL size=-2>Bikers' Outpost Products</FONT></CENTER></TH>");

  // bells here
  // tWin.write("<TR><TD BGCOLOR="+gMenuColor+"><CENTER><FONT FACE=ARIAL size=-2><A HREF=javascript:parent.dispFrontPage('bells.htm') onmouseover='window.status=&quot;Guardian Bells&quot;' >Guardian Bells!</A></FONT></TD></TR>");
    tWin.write("<TR><TD BGCOLOR="+gMenuColor+"><CENTER><FONT FACE=ARIAL size=-2><A HREF=javascript:parent.searchCatalog('BELLS') onmouseover='window.status=&quot;Guardian Bells&quot;' >Guardian Bells!</A></FONT></TD></TR>");

  // pins here
  tWin.write("<TR><TD BGCOLOR="+gMenuColor+"><CENTER><FONT FACE=ARIAL size=-2><A HREF=javascript:parent.dispFrontPage('pins.htm') onmouseover='window.status=&quot;On Target Pins&quot;' >On Target Pins!</A></FONT></TD></TR>");

  // bullet hole decals here 
  //tWin.write("<TR><TD BGCOLOR="+gMenuColor+"><CENTER><FONT FACE=ARIAL size=-2><A HREF=javascript:parent.dispFrontPage('bullets.htm') onmouseover='window.status=&quot;Bullet hole decals!&quot;' > Bullet hole decals!</A></FONT></TD></TR>");
  tWin.write("<TR><TD BGCOLOR="+gMenuColor+"><CENTER><FONT FACE=ARIAL size=-2><A HREF=javascript:parent.searchCatalog('HDI') onmouseover='window.status=&quot;Bullet Hole Decals&quot;' >Bullet Hole Decals!</A></FONT></TD></TR>");

  // MagPaper goes here
  tWin.write("<TR><TD BGCOLOR="+gMenuColor+"><CENTER><FONT FACE=ARIAL size=-2><A HREF=javascript:parent.dispFrontPage('magpaper.htm') onmouseover='window.status=&quot;Make bike decals from your stickers!&quot;' > MagPaper</A></FONT></TD></TR>");

  // Helmet stickers go here  
  tWin.write("<TR><TD BGCOLOR="+gMenuColor+"><CENTER><FONT FACE=ARIAL size=-2><A HREF=javascript:parent.dispFrontPage('stickers.htm') onmouseover='window.status=&quot;Bottom Line Helmet Stickers&quot;'> Helmet Stickers</A></FONT></CENTER>");
  
  tWin.write("<FONT FACE=ARIAL size=-2><CENTER><A HREF=javascript:parent.dispAlpha()>List alphabetically</A><br>OR<br>")

  tWin.write("<A HREF=javascript:parent.dispNumeric()>List by item number</A><br>OR<br>")

  tWin.write("Select a page below <A HREF='javascript:alert(&quot;The asterisk (P*) means that a sticker has been ordered on that page.&quot;)'>(P*)</A></FONT></CENTER></TD></TR>");

  tWin.write("<TR><TD BGCOLOR="+gMenuColor+"><FONT FACE=ARIAL size=-2><CENTER>"); 
  
  //  alert("orderOnPage["+gPageNum+"] " + orderOnPage);

  for (page = 1; page <= gPageNumMax; page++)
  { 
    if (page < 10)
      ch="&nbsp;&nbsp;";
    else
      ch="";

    if (orderOnPage[page] == TRUE)
    {
      tWin.write("<A HREF=javascript:parent.searchCatalog(&quot;BLS-"+page+"&quot;)>P*"+ch+page+"</A>&nbsp;");
    }
    else
    {
      tWin.write("<A HREF=javascript:parent.searchCatalog(&quot;BLS-"+page+"&quot;)>P&nbsp;"+ch+page+"</A>&nbsp;");
    }

    if ((page % 5) == 0)
      tWin.write("<br>");
  }

  tWin.write("</CENTER></TD></TR>"); 

  tWin.write("<TD BGCOLOR="+gMenuColor+"><FONT FACE=ARIAL size=-2><CENTER><A HREF=javascript:parent.dispFrontPage('stickers.htm')>What are <b><i>Bottom Line Stickers</i>?</b></A></CENTER></FONT></TD>");

  tWin.write("</TABLE></CENTER></BODY></HTML>");

  tWin.close();

}

function dispNumeric()
{
  cWin = parent.frames['catalog'].document;
  cWin.open();
  cWin.write("<HTML><HEAD><STYLE TYPE='text/css'><!-- A:hover   { color:#FF0000; } --> </STYLE> </HEAD><BODY BGCOLOR=#D3D3D3 TEXT=#000000>");
  cWin.write("<TABLE BORDER=0 COLS=2><CAPTION ALIGN=LEFT><FONT SIZE=+2>Complete Listing by Item Number</FONT><br><FONT SIZE=-1>Click on the item number to view the page that contains the sticker you want to see.<hr></FONT></CAPTION>");
  cWin.write("<TR ALIGN=LEFT><TH><FONT FACE=ARIAL SIZE=-2><u>Item</u></FONT></TH><TH><FONT FACE=ARIAL SIZE=-2><u>Description</u></FONT></TH></TR>");
  for (var i = 1; i <= gTotalNumStickers; i++)
  {
    cWin.write("<TR><TD><FONT FACE=ARIAL SIZE=-2><A HREF=javascript:parent.dispNumericSort("+i+")>"+prodID[i].name+"</A></FONT></TD><TD NOWRAP><FONT FACE=ARIAL SIZE=-2>"+prodID[i].link+"</FONT></TD></TR>");
  }
  cWin.write("</CENTER></TABLE>");
  cWin.write("</FONT></BODY></HTML>");
  cWin.close();
}

function dispAlpha()
{
  cWin = parent.frames['catalog'].document;
  cWin.open();
  cWin.write("<HTML><HEAD><STYLE TYPE='text/css'><!-- A:hover   { color:#FF0000; } --> </STYLE> </HEAD> <BODY BGCOLOR=#D3D3D3 TEXT=#000000>");
  cWin.write("<TABLE BORDER=0 COLS=2><CAPTION ALIGN=LEFT><FONT SIZE=+2>Complete Alphabetical Listing</FONT><br><FONT SIZE=-1>Click on the item number to view the page that contains the sticker you want to see.<hr></FONT></CAPTION>");
  cWin.write("<TR ALIGN=LEFT><TH><FONT FACE=ARIAL SIZE=-2><u>Item</u></FONT></TH><TH><FONT FACE=ARIAL SIZE=-2><u>Description</u></FONT></TH></TR>");
  for (var i = 1; i <= gTotalNumStickers; i++)
  {
    cWin.write("<TR><TD><FONT FACE=ARIAL SIZE=-2><A HREF=javascript:parent.dispAlphaSort("+i+")>"+prodSortedID[i].name+"</A></FONT></TD><TD NOWRAP><FONT FACE=ARIAL SIZE=-2>"+prodSortedID[i].link+"</FONT></TD></TR>");
  }
  cWin.write("</CENTER></TABLE>");
  cWin.write("</FONT></BODY></HTML>");
  cWin.close();
}

// This function is invoked in the javascript file dbsorted.js
function prodSort(name,description,image,price,type,link,url)
{
  this.name = name;
  this.description = description;
  this.image = image
  this.price = price;
  this.type = type;
  this.show = "";
  this.link = link;
}

function dispAlphaSort(itemId)
{
  // derive prodID index from itemId
  for (var i = 1; i <= gTotalNumStickers; i++)
  {
    if (prodID[i].name == prodSortedID[itemId].name)
    {
      // use i to calculate page on which sticker resides, then display that page
      thisPageNum = Math.ceil(i / gPageSize);
      // alert("i name thisPageNum "+i+" "+prodSortedID[itemId].name+" " +thisPageNum);
      searchCatalog("BLS-"+thisPageNum);
      break;
    }
  }
}

function dispNumericSort(itemId)
{
  // use itemId to calculate page on which sticker resides, then display that page
  thisPageNum = Math.ceil(itemId / gPageSize);
  
  // alert("i name thisPageNum "+i+" "+prodSortedID[itemId].name+" " +thisPageNum);
  searchCatalog("BLS-"+thisPageNum);

}

