function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&ia.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&id.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
var free_shipping = 49;
var free_gift = 60;
function DisplayMiniCart(name,style,is_fg) {
  var cookies=document.cookie;  //read in all cookies
  var start = cookies.indexOf(name + "=");  //set start to beginning of ss_cart cookie
  var cartvalues = "";
  var linecount = 0;
  var start1;
  var end1;
  var tmp;
  if (is_fg == undefined) {
      is_fg = false;
  }
  // Start Output
  document.write("<div class=\"MiniCart\">\n");
  if (style == "Detail")
  {
   document.write("<table class=\"MiniCart\" border=\"0\">\n");
    document.write("<tr>\n");
    document.write("<th class=\"MiniCart\" colspan=\"3\">");
    document.write("<a class=\"MiniCart\" href=\"/cgi-cleopatraschoice/sb/order.cgi?storeid=*12486e1c03690f7516403a&function=show\">");
    document.write("Your Shopping Cart");
    document.write("</a></th></tr>");
  }
  else if (style == "Summary")
  {
    document.write("<a class=\"MiniCart\" href=\"/cgi-cleopatraschoice/sb/order.cgi?storeid=*12486e1c03690f7516403a&function=show\">");
    document.write("Your Shopping Cart");
    document.write("</a>");
  }
  else
  {
    document.write("<a class=\"MiniCart\" href=\"/cgi-cleopatraschoice/sb/order.cgi?storeid=*12486e1c03690f7516403a&function=show\">");
    document.write("</a>&nbsp;");
  }
  if (start == -1)  //No cart cookie
  {
    if (style == "Detail")
    {
      document.write("</table>\n");
    }
    else if ((style == "ItemCount") || (style == "Subtotal"))
    {
      document.write("<a class=\"MiniCart\" href=\"/cgi-cleopatraschoice/sb/order.cgi?storeid=*12486e1c03690f7516403a&function=show\">");
      document.write("0 Items");
      document.write(freeShippingTxt(free_shipping, 0));
      if (is_fg) {
          document.write(freeGiftTxt(free_gift, 0));
      }
      document.write("</a>&nbsp;");
      document.write("</div>\n");
    }
    else
    {
      document.write("</div>\n");
    }      
  }
  else   //cart cookie is present
  {
    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 == 2) && (style != "Detail"))  // Total Quantity of Items
        {
          tmp = cartvalues.substring(start,end);
          colon = tmp.indexOf(":", 0);
          if ((style == "ItemCount") || (style == "Subtotal"))
          {
            document.write("<a class=\"MiniCart\" href=\"/cgi-cleopatraschoice/sb/order.cgi?storeid=*12486e1c03690f7516403a&function=show\">");
          }
          if (style == "Summary")
         {
           document.write("<br>Contains <b>");
          } 
          document.write(tmp.substring(colon+1,end - start));
          if (style == "Summary")
         {
           document.write("</b>");
          }
          if ((tmp.substring(colon+1,end - start)) == 1 )
          {
            document.write(" Item");
          }
          else
          {
            document.write(" Items");
          }
          if (style == "ItemCount")
          {
            document.write("</a>");
          } 
          else if (style == "Subtotal")
          {
            document.write(": ");
          } 
          else if (style == "Summary")
          {
            document.write("<br>Subtotal: <b>");
          }
        }
        if (linecount == 3)  // Product Subtotal
       {
         if ((style == "Subtotal") || (style == "Summary"))
          {
            tmp = cartvalues.substring(start,end);
            colon = tmp.indexOf(":", 0);
            document.write(tmp.substring(colon+1,end - start));
            document.write(freeShippingTxt(free_shipping, tmp.substring(colon+1,end - start)));
            if (is_fg) {
                document.write(freeGiftTxt(free_gift, tmp.substring(colon+1,end - start)));
            }
            if (style == "Summary") 
            {
              document.write("</b>");
            }
            else
            {
            document.write("</a>");
            }
          }
          else if (style == "Detail")
          {
            start1 = start;
            end1 = end;
            document.write("<tr><td class=\"MiniCartHead\">Qty</td>");
            document.write("<td class=\"MiniCartHead\">Product</td>");
            document.write("<td class=\"MiniCartHead\">Price</td></tr>\n");
          }
        }
       if ((linecount > 3) && (style == "Detail"))  // individual products
        {
          tmp = cartvalues.substring(start,end);
          colon = tmp.indexOf(":", 0);
          document.write("<tr>");
          document.write("<td class=\"MiniCartQty\">");
          document.write(tmp.substring(0,colon));
          document.write("</td><td class=\"MiniCartProduct\">");
          colon2 = tmp.indexOf(":", colon+1);
          document.write(tmp.substring(colon2+1,end - start));
          document.write("</td><td class=\"MiniCartPrice\">");
          document.write(tmp.substring(colon+1,colon2));
          document.write("</td></tr>\n");
        }
        start = end;
      }
      else
        break;
    } // end while loop
    //close minicart HTML
    if (style != "Detail")
    {
      document.write("</div>\n");
    }
    else
    {
      document.write("<tr>");
      document.write("<td class=\"MiniCartSubtotalText\" colspan=\"2\">Subtotal</td>");
      document.write("<td class=\"MiniCartSubtotal\">");
      tmp = cartvalues.substring(start1,end1);
      colon = tmp.indexOf(":", 0);
      document.write(tmp.substring(colon+1,end1 - start1));
      document.write(freeShippingTxt(free_shipping, tmp.substring(colon+1,end1 - start1)));
      if (is_fg) {
          document.write(freeGiftTxt(free_gift, tmp.substring(colon+1,end1 - start1)));
      }
      document.write("</td>");
      document.write("</tr>");
      document.write("</table>\n");
      document.write("</div>\n");
    }
  }
}
function MoreToBuy(name,style) {
  var cookies=document.cookie;  //read in all cookies
  var start = cookies.indexOf(name + "=");  //set start to beginning of ss_cart cookie
  var cartvalues = "";
  var linecount = 0;
  var start1;
  var end1;
  var tmp;
  // Start Output
  if (start != -1)  //No cart cookie
  {
    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 == 2) && (style != "Detail"))  // Total Quantity of Items
        {
          tmp = cartvalues.substring(start,end);
          colon = tmp.indexOf(":", 0);
          if ((style == "ItemCount") || (style == "Subtotal"))
          {
          }
          if (style == "Summary")
         {
          } 
          if (style == "Summary")
         {
          }
          if ((tmp.substring(colon+1,end - start)) == 1 )
          {
          }
          else
          {
          }
          if (style == "ItemCount")
          {
          } 
          else if (style == "Subtotal")
          {
          } 
          else if (style == "Summary")
          {
          }
        }
        if (linecount == 3)  // Product Subtotal
       {
         if ((style == "Subtotal") || (style == "Summary"))
          {
            tmp = cartvalues.substring(start,end);
            colon = tmp.indexOf(":", 0);
            //document.write(tmp.substring(colon+1,end - start));
            document.write(BuyMoreTxt(free_shipping, tmp.substring(colon+1,end - start)));
            if (style == "Summary") 
            {
              document.write("</b>");
            }
            else
            {
            document.write("</a>");
            }
          }
          else if (style == "Detail")
          {
            start1 = start;
            end1 = end;
            document.write("<tr><td class=\"MiniCartHead\">Qty</td>");
            document.write("<td class=\"MiniCartHead\">Product</td>");
            document.write("<td class=\"MiniCartHead\">Price</td></tr>\n");
          }
        }
       if ((linecount > 3) && (style == "Detail"))  // individual products
        {
          tmp = cartvalues.substring(start,end);
          colon = tmp.indexOf(":", 0);
          document.write("<tr>");
          document.write("<td class=\"MiniCartQty\">");
          document.write(tmp.substring(0,colon));
          document.write("</td><td class=\"MiniCartProduct\">");
          colon2 = tmp.indexOf(":", colon+1);
          document.write(tmp.substring(colon2+1,end - start));
          document.write("</td><td class=\"MiniCartPrice\">");
          document.write(tmp.substring(colon+1,colon2));
          document.write("</td></tr>\n");
        }
        start = end;
      }
      else
        break;
    } // end while loop
    //close minicart HTML
    if (style != "Detail")
    {
      document.write("</div>\n");
    }
    else
    {
      document.write("<tr>");
      document.write("<td class=\"MiniCartSubtotalText\" colspan=\"2\">Subtotal</td>");
      document.write("<td class=\"MiniCartSubtotal\">");
      tmp = cartvalues.substring(start1,end1);
      colon = tmp.indexOf(":", 0);
      document.write(tmp.substring(colon+1,end1 - start1));
      document.write(freeShippingTxt(free_shipping, tmp.substring(colon+1,end1 - start1)));
      document.write("</td>");
      document.write("</tr>");
      document.write("</table>\n");
      document.write("</div>\n");
    }
  }
}



function formatCurrency(num) {
  num = currencyToNum(num);
  sign = (num >= 0.0);
  num = Math.abs(num);
  num = Math.floor(num*100+0.50000000001);
  cents = num%100;
  num = Math.floor(num/100).toString();
  if(cents<10) {
    cents = "0" + cents;
  }
  for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++) {
    num = num.substring(0,num.length-(4*i+3))+','+ num.substring(num.length-(4*i+3));
  }
  return (((sign)?'':'-') + '$' + num + '.' + cents);
}

function currencyToNum(num) {
  num = num.toString().replace(/\$|\,/g,'');
  if (isNaN(num)) {
    num = "0";
  }
  return num;
}

function freeShippingTxt(fs, st) {
  msg = "&nbsp;";
  fs_val = currencyToNum(fs);
  st_val = currencyToNum(st);
  diff = fs_val - st_val;
  if (diff <= 0.0) {
    msg = "<br>Free U.S. Shipping for this order!!";
  } else {
    msg = "<br>Free U.S. Shipping:<br>" + formatCurrency(diff) + " to go!";
  }
  return msg;
}
function freeGiftTxt(fg, st) {
  msg = "&nbsp;";
  fg_val = currencyToNum(fg);
  st_val = currencyToNum(st);
  diff = fg_val - st_val;
  if (diff <= 0.0) {
      msg = "<br>Free Gift with this order!!";
  } else {
    msg = "<br>Free Gift: " + formatCurrency(diff) + " to go!";
  }
  return msg;
}
function BuyMoreTxt(fs, st) {
  msg = "&nbsp;";
  fs_val = currencyToNum(fs);
  st_val = currencyToNum(st);
  diff = fs_val - st_val;
  if (diff <= 0.0) {
    msg = "<br>You've Earned Free U.S. Shipping for this order!!";
  } else {
    msg = "<br>You're  " + formatCurrency(diff) + " Away From FREE U.S. Shipping!";
  }
  return msg;
}
function img_freeship(prc) {
  if (prc) {
    var p = currencyToNum(prc);
    if (p >= free_shipping) {
      document.write("<img src=\"/images/cleo-freeshipping.gif\" border=\"0\" alt=\"Free Shipping\"");
      document.write("<br />");
    }
  }
}
