<!--
var shipping = 1;     // How much for shipping PER ITEM?  There MUST be a ; after the number!
var freeshipping = 1; // When is shipping free? If never, put in a very large number. There MUST be a ; after the number!
var taxrate = 0.06;   // Tax rate for your state, must be in decimal form (eg. 8.750 becomes 0.0875)
var taxstate = "Kentucky";    //The state you collect tax in (Your home state)
// var business = "pamelashaw";
var business = "dvu9djyp";
var emailaddress =  "jerryshaw@insightbb.com";
// var returnURL = "http://www.pamelashaw.com/N2designingYourLifeProducts.html";
var returnURL = "http://www.pamelashaw.com/N2designingYourLifeProducts.html";
var tableheadcolor = "#496555"; //Table Header and Footer Color
var tablebodycolor = "#E5E2CE"; //Body Color
var tablefontcolor = "#FFFFFF"; //Font Color
var vbasketTransaction = 1;
var cookieVal = "";
var i;
var j;
var cartHtm = "cart.htm";
var kyresident = 0;                 // 0 == not a ky resident
var CookieName = "vShoppingCart";

cook = getCookie(CookieName);
//alert("IN cookie='"+cook+"'");

if ( cook.length > 0 ) {
   kyresstr = cook.substr(0,1);
   cook = cook.substr(i);
   if ( kyresstr == "1" )
      kyresident = 1;
   else
      kyresident = 0;
   i = cook.indexOf("[");
   if ( i < 0 )
      cook = "";
   else
      if ( i > 0 )
         cook = cook.substr(i);
}
//alert("kyresident="+kyresident+" cook='"+cook+"'");

if ( cook.length == 0 )
   num_items = 0;
else {
   items = cook.split(/\[\]|\[|\]/);
   var item;
   num_items = items.length;
   item_name  = new Array(num_items);
   item_price = new Array(num_items);
   item_count = new Array(num_items);
   for (i=0;i<num_items;i++) {
      item = items[i].split(/\|/);
      item_name[i]  = item[0];
      item_price[i] = item[1];
      item_count[i] = item[2];
   }
}

combineItems();

// ====================================
function getCookie(name) {
   var cookie = " " + document.cookie;
   var search = " " + name + "=";
   var setStr = "";
   var offset = 0;
   var end = 0;
   if (cookie.length > 0) {
      offset = cookie.indexOf(search);
      if (offset != -1) {
         offset += search.length;
         end = cookie.indexOf(";", offset)
         if (end == -1) {
            end = cookie.length;
         }
         setStr = unescape(cookie.substring(offset, end));
      }
   }
   return(setStr);
}

// ====================================
function combineItems() {
   var i;
   var j;
   for (i=0;i<num_items-1;i++) {
      for (j=i+1;j<num_items;j++) {
         if ( item_name[i] == item_name[j] ) {
            item_count[i] = 1*item_count[i] + 1*item_count[j];
            item_name[j] = "";
         }
      }
   }
}

// ====================================
function putCartCookie () {
   combineItems();
   var i;
   cookieVal = kyresident;
   for (i=0;i<num_items;i++) {
      if ( item_name[i].length > 0 )
         if ( 1*item_count[i] > 0 )
            cookieVal = cookieVal+"["+item_name[i]+"|"+item_price[i]+"|"+item_count[i]+"]";
   }
   var expDays = 365;
   var exp = new Date();
   exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
   cookieVal = CookieName+"="+cookieVal+";path=/;expires="+exp.toGMTString();
//alert("put cookie: '"+cookieVal+"'");
   document.cookie = cookieVal;
}

// ====================================
// alterError - fixes a rounding bug
function alterError(value) {
   if (value<=0.99)
      newDollars = '0';
   else
      newDollars = parseInt(value);
   newCents = parseInt((value+.0008 - newDollars)* 100);
   if (eval(newCents) <= 9)
      newCents = '0' + newCents;
   newString = newDollars + '.' + newCents;
   return (newString)
}


// ====================================
// buyItem - adds an item to the shopping basket
function buyItem ( newItem, newPrice, newQuantity ) {
   if ( num_items == 0 ) {
      item_name  = new Array(1);
      item_price = new Array(1);
      item_count = new Array(1);
   }
   item_name[num_items]  = newItem;
   item_price[num_items] = newPrice;
   item_count[num_items] = newQuantity;
   num_items = num_items + 1;

   putCartCookie();

   if ( vbasketTransaction ) {
      window.location.href = cartHtm;
   }

   return false;
}


// ====================================
// showItems() - displays shoppingcart contents in a drop down select array
function showItems() {
//       var CookieName = "vShoppingCart";
     var cookieFound = false;
     var start = 0;
     var end = 0;
     var cookieString = document.cookie;
     var i = 0;
     while (i <= cookieString.length) {
       start = i;
       end = start + CookieName.length;
       if (cookieString.substring(start,end) == CookieName) {
         cookieFound = true;
        break;
       }
       i++;
     }
     if (cookieFound) {
       start = end + 1;
       end = document.cookie.indexOf(";",start);
       if (end < start)
         end = document.cookie.length;
       document.cookie.substring(start,end);
      }
      cookieVal = document.cookie.substring(start, end);
                subtotal = 0;
                howmany = 0;
                document.writeln('<FORM><TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0><TR><TD><select><option>Click For ShoppingCart Contents</OPTION>');
                itemlist = 0;
                for (var i = 0; i <= cookieVal.length; i++) {
                        if (cookieVal.substring(i,i+1) == '[') {
                                itemstart = i+1;

                                thisitem = 1;
                        } else if (cookieVal.substring(i,i+1) == ']') {
                                itemend = i;
                                thequantity = cookieVal.substring(itemstart, itemend);
                                itemtotal = 0;
                                howmany = howmany + 1;
                                itemtotal = (eval(theprice*thequantity));
                                temptotal = itemtotal * 100;
                                subtotal = subtotal + itemtotal;
                                itemlist=itemlist+1;
                                document.write('<OPTION>'+thequantity+' -   '+theitem+'</OPTION>');
                        } else if (cookieVal.substring(i,i+1) == '|') {
                                if (thisitem==1) theitem = cookieVal.substring(itemstart, i);
                                if (thisitem==2) theprice = cookieVal.substring(itemstart, i);
                                if (thisitem==3) theoption = cookieVal.substring(itemstart, i);
                                thisitem++;
                                itemstart=i+1
                                }
                }
                document.writeln('</SELECT><BR><CENTER><FONT SIZE="1" COLOR="#000000" FACE="Arial, Helvetica, sans-serif">');
                document.writeln('&nbsp;'+ howmany +'&nbsp;Item(s)&nbsp;&nbsp;Sub Total: $'+ alterError(subtotal) +'</FONT></CENTER></TD></TR></TABLE></FORM>');
           }




// ====================================
//Show vbuy.htm contents
function showvbuy() {
   totprice = 0;
   document.writeln('<p><TABLE CELLSPACING=1 CELLPADDING=3 BGCOLOR="' + tablebodycolor + '">');
   document.writeln('<TR bgcolor=' + tableheadcolor + '><TD><b><font size=3 color=' + tablefontcolor + '>Item</FONT></B></TD>');
   document.writeln('<TD><B><FONT SIZE=3 COLOR=' + tablefontcolor + '>Quantity</FONT></B></TD><TD><B><FONT SIZE=3 COLOR=' + tablefontcolor + '>Cost Each</FONT></B></TD><TD><B><FONT SIZE=3 COLOR=' + tablefontcolor + ' >Sub Total</FONT></B></TD></TR>');
   cookieVal = "";
   putCartCookie();   // sets cookieVal
   for (var i=0;i<num_items;i++) {
      if ( item_name[i].length > 0 ) {
         theitem = item_name[i];
         theprice = item_price[i];
         thequantity = item_count[i];
         thisitem = i + 1;
         itemtotal = Number(theprice*thequantity);
//       if ( theitem == "The_Design_Book" ) {
//          x = thequantity % 2;
//          x = (thequantity - x) / 2;
//          itemtotal = itemtotal - 6*x;
//       }
         totprice = totprice + itemtotal;
         document.write('<TR><TD>'+theitem+'</TD>');
         document.writeln('<TD ALIGN=RIGHT>'+thequantity+'</TD><TD ALIGN=RIGHT>'+theprice+'</TD><TD ALIGN=RIGHT>'+alterError(itemtotal)+'</TD></TR>');
      }
   }

   if ( num_items > 1 ) {
      document.writeln('<TR><TD BGCOLOR=' + tableheadcolor + ' COLSPAN=3><FONT COLOR=' + tablefontcolor + '><B>Sub Total</B></FONT></TD><TD BGCOLOR=' + tableheadcolor + ' ALIGN=RIGHT><FONT COLOR=' + tablefontcolor + '><B>$'+alterError(totprice)+'</B></FONT></TD></TR>');
   }

   if       (totprice <= .02 ) shippingcharge = 0;
   else  if (totprice <= 6)    shippingcharge = 6;
   else  if (totprice <= 24)   shippingcharge = 8;
   else  if (totprice <= 59)   shippingcharge = 9;
   else  if (totprice <= 110)  shippingcharge = 10;
   else  if (totprice <= 150)  shippingcharge = 15;
   else  if (totprice <= 200)  shippingcharge = 20;
   else  shippingcharge = 25;

   var subtax = 0.00;
   if ( kyresident == 1 ) {
      subtax = totprice * taxrate;
      var taxpct = 100*taxrate;
      document.writeln('<TR><TD COLSPAN=3><B>'+taxpct+'% '+taxstate+' Sales Tax</B></TD><TD ALIGN=RIGHT>'+alterError(subtax)+'</TD></TR>');
   }

   totprice = totprice + subtax;
   totprice = totprice + shippingcharge;

   var ID = "";
   ID = getCookie("CustID");
// alert("ID='"+ID+"'");
   document.writeln('<TR><TD COLSPAN=3><B>Shipping</B></TD><TD ALIGN=RIGHT>'+alterError(shippingcharge)+'</TD></TR>');
   document.writeln('<TR><TD BGCOLOR=' + tableheadcolor + ' COLSPAN=3><FONT COLOR=' + tablefontcolor + '><B>Total To Be Charged</B></FONT></TD><TD BGCOLOR=' + tableheadcolor + ' ALIGN=RIGHT><FONT COLOR=' + tablefontcolor + '><B>$'+alterError(totprice)+'</B></FONT></TD></TR>');
   document.writeln('</TABLE>');

//   document.writeln('<FORM action="https://secure.authorize.net/gateway/transact.dll" METHOD=POST OnSubmit="clearBasket2()">');
   document.writeln('<FORM action="https://secure.authorize.net/gateway/transact.dll" METHOD=POST>');
// document.writeln('<INPUT TYPE=hidden NAME="x_Version" VALUE="3.1">');
   document.writeln('<INPUT TYPE=hidden NAME="x_Login" VALUE="' + business + '">');
   document.writeln('<INPUT TYPE=hidden NAME="x_Receipt_Link_URL"  VALUE="' + returnURL + '">');
   document.writeln('<INPUT TYPE=hidden NAME="x_Receipt_Link_Method" VALUE=Link>');
   document.writeln('<INPUT TYPE=hidden NAME="x_Receipt_Link_Text" VALUE=Continue>');
   document.writeln('<INPUT TYPE=hidden NAME="x_Show_Form" VALUE="PAYMENT_FORM">');
   document.writeln('<INPUT TYPE=hidden NAME=x_Cust_ID VALUE=' + ID + '>');
   document.writeln('<INPUT TYPE=hidden NAME=x_Invoice_Num VALUE=' + ID + '>');
   document.writeln('<INPUT TYPE="hidden" NAME="x_Amount" VALUE="'+alterError(totprice)+'">');
   document.writeln('<INPUT TYPE="hidden" NAME="x_Description" VALUE="'+cook+'">');
   document.writeln('<INPUT TYPE=hidden NAME="x_Color_Background" VALUE="#E5E2CE">');
   document.writeln('<INPUT TYPE=hidden NAME="x_Header_HTML_Payment_Form" VALUE="<h2>Pamela Shaw Design Products</h2>">');
   document.writeln('<INPUT TYPE=hidden NAME="x_Header_HTML_Receipt" VALUE="<h2>Pamela Shaw Design Products</h2>">');
   document.writeln('<INPUT TYPE=hidden NAME="x_Header_Email_Receipt" VALUE="Pamela Shaw Design Products">');
   document.writeln('<INPUT TYPE=hidden NAME="x_Footer_Email_Receipt" VALUE="Thank you so much for purchasing my Creative Works. I pray you will WORK these tools and that as you do, they will support you on your Success Journey! God bless you and may you grow in wisdom, in knowledge, and in favor with God and man.">');
// document.writeln('<INPUT TYPE=hidden NAME="x_Test_Request" VALUE="TRUE">');
   document.writeln('<P><INPUT TYPE=SUBMIT NAME=Submit VALUE="  Proceed To Secure Payment System  "><BR>');
   document.writeln('<p><INPUT TYPE=IMAGE NAME=submit_order SRC="images/VisaMasterCardAmexDisc.jpg" ALIGN=BOTTOM><P>');
// document.writeln('<INPUT TYPE="image" NAME="submit_order" SRC="images/vShoppingCart-50.gif" WIDTH=143 HEIGHT=41 ALIGN=BOTTOM>');
   document.writeln('</FORM>');
// document.writeln('<FONT SIZE=2><I>Your Customer Id=' + ID +'</I></FONT>');
}


// ====================================
//Show vbasket.htm contents
function showvbasket() {
   totprice = 0;
   var checked = "";
   if ( kyresident == 1 )
      checked = "checked";
   document.writeln('<FORM NAME="updateform">');
// document.writeln('<INPUT TYPE="button" NAME="clear" VALUE="Clear Entire ShoppingCart" ONCLICK="clearBasket()"><P>');
   document.writeln('<TABLE CELLSPACING=1 CELLPADDING=3 BGCOLOR="' + tablebodycolor + '">');
   document.writeln('<TR><TD COLSPAN=5 BGCOLOR=' + tableheadcolor + '><FONT COLOR=' + tablefontcolor + '><B>Please click here if you are a resident of Kentucky &rarr; <input type=checkbox id=kyres name=kyres ' + checked + ' onClick="changeKyRes()"></B></FONT></TD></TR>');
   document.writeln('<TR bgcolor=' + tableheadcolor + '><TD><b><font size=3 color=' + tablefontcolor + '>Item</FONT></B></TD><TD ALIGN=CENTER><B><FONT SIZE=3 COLOR=' + tablefontcolor + '>Quantity</FONT></B></TD><TD><B><FONT SIZE=3 COLOR=' + tablefontcolor + '>Cost Each</FONT></B></TD>');
   document.writeln('<TD><B><FONT SIZE=3 COLOR=' + tablefontcolor + '>Sub Total </FONT></B><TD><B><FONT SIZE=3 COLOR=' + tablefontcolor + '>Remove from Cart</FONT></B></TD></TR>');
   for (var i=0;i<num_items;i++) {
      if ( item_name[i].length > 0 ) {
         theitem = item_name[i];
         theprice = item_price[i];
         thequantity = item_count[i];
         thisitem = i + 1;
         itemtotal = Number(theprice*thequantity);
//       if ( theitem == "The_Design_Book" ) {
//          x = thequantity % 2;
//          x = (thequantity - x) / 2;
//          itemtotal = itemtotal - 6*x;
//       }
         totprice = totprice + itemtotal;
         document.write('<TR><TD>'+theitem+'</TD>');
         document.write('<TD ALIGN=CENTER><INPUT TYPE=TEXT NAME="quant'+thisitem+'" VALUE="'+thequantity+'" SIZE=3><BR><FONT SIZE=1 COLOR=' + tablefontcolor + '><A HREF="javascript:amendItem('+thisitem+',document.updateform.quant'+thisitem+'.value)"><FONT SIZE="1" FACE="Arial, Helvetica, sans-serif">Change This Quantity</A></FONT></TD>');
         document.write('<TD ALIGN=RIGHT>'+theprice+'</TD><TD ALIGN=RIGHT><B>'+alterError(itemtotal)+'</B></TD><TD align=center><FONT SIZE=3><a href="javascript:removeItem('+thisitem+')">Remove</A></FONT></TD></TR>');
      }
   }
   document.writeln('<TR><TD COLSPAN=3 BGCOLOR=' + tableheadcolor + '><FONT COLOR=' + tablefontcolor + '><B>Sub Total</B></FONT></TD><TD BGCOLOR=' + tableheadcolor + ' ALIGN=RIGHT><FONT COLOR=' + tablefontcolor + '><B>'+alterError(totprice)+'</B></FONT></TD><TD  BGCOLOR=' + tableheadcolor + '></TD></TR>');
   document.writeln('</TABLE></FORM>');
   document.writeln('');
}


// ====================================
// change the value of the KyRes cookie
function changeKyRes() {
   kyresident = 1 - kyresident;   //  1 -> 0 and  0 -> 1
//   alert("changing kyresident to "+kyresident);
   putCartCookie();
   self.location = cartHtm;
}


// ====================================
// adjust quantity of vbasket.htm
function amendItem(itemno, newquant) {
   if (newquant == "" || newquant == " " || newquant == "0")
      removeItem(itemno);
   else
      if ( itemno <= num_items && item_name[itemno-1].length > 0 ) {
         item_count[itemno-1] = newquant;
         putCartCookie();
         self.location = cartHtm;
      }
}


// ====================================
//Remove item from vbasket.htm
function removeItem(itemno) {
   if ( itemno <= num_items && item_name[itemno-1].length > 0 ) {
      item_count[itemno-1] = 0;
      putCartCookie();
      self.location = cartHtm;
   }
}


// ====================================
// clearBasket() - removes all items from the basket
function clearBasket() {
   if ( confirm('Are you sure you want to ERASE everything in your Cart?') ) {
      num_items = 0;
      putCartCookie();
      self.location = cartHtm;
   }
}


// ====================================
// clearBasket2() - removes all items from the basket without prompting
function clearBasket2() {
      num_items = 0;
      putCartCookie();
      return true;          // Allow submit to continue on to next page.
}

//-->
