// Minicart Detail for YarnLady.com Website
// by BarefootChris.net. Copyright 2010

/**** REPLACE THE VALUES IN THESE LINES ****/
var serialnum="0001327368";
var cartURL="http://yarnlady.com/cgi-bin/sc/order.cgi?storeid=*1c368efac09b01d7112546fa6b486a8c&function=show";
var textColor="black";
var backgroundColor="transparent";
var showCart="no";       // only "yes" or "no"
var cartColor="black";    // only "black" or "white"
var textAlign="left";     // only "left" "right" or "center"

/**** DON'T CHANGE ANYTHING BELOW HERE ****/

var linkColor=textColor;
var cookies=document.cookie;  //read in all cookies
var start = cookies.indexOf("ss_cart_" + serialnum + "="); 
var cartvalues = "";
var linecount = 0;
var start1;
var end1;
var tmp;

// Start Output

if (start == -1)  //No cart cookie
{ // No items so don't display the Cart Detail at all
}
else   //cart cookie is present
document.write("<table>\n");
{
  start = cookies.indexOf("=", start) +1;  
  var end = cookies.indexOf(";", start);  

  if (end == -1)
  {
    end = cookies.length;
  }

  cartvalues = unescape(cookies.substring(start,end)); //read in just the cookie data

  start = 0;
  while ((start = cartvalues.indexOf("|", start)) != -1)
  {
    start++;
    end = cartvalues.indexOf("|", start);
    if (end != -1)
    {
      linecount++;

      if (linecount == 3)  // Product Subtotal
      {
        start1 = start;
        end1 = end;
        document.write("<tr><th>Qty</th>");
        document.write("<th align=\"center\">Product</th>");
        document.write("<th align=\"center\">Price</th></tr>\n");
      }

      if (linecount > 3)  // individual products
      {
        tmp = cartvalues.substring(start,end);
        colon = tmp.indexOf(":", 0);
        document.write("<tr>");
        document.write("<td>");
        document.write(tmp.substring(0,colon));
        document.write("</td><td>");
        colon2 = tmp.indexOf(":", colon+1);
        document.write(tmp.substring(colon2+1,end - start));
        document.write("</td><td align=\"right\">");
        document.write(tmp.substring(colon+1,colon2));
        document.write("</td></tr>\n");
      }

      start = end;
    }
    else
    {
      break;
    }
  } // end while loop

  //close minicart HTML
  document.write("<tr>");
  document.write("<td colspan=\"2\" align=\"right\">Subtotal</td>");
  document.write("<td align=\"right\">");
  tmp = cartvalues.substring(start1,end1);
  colon = tmp.indexOf(":", 0);
  document.write(tmp.substring(colon+1,end1 - start1));
  document.write("</td>");
  document.write("</tr>");
  document.write("<tr><td colspan=\"3\" align=\"center\"><a href=\"");
  document.write(cartURL + "\"");
  document.write("> View Basket</a>");
  document.write("</table>\n");
}
