
var tmpform="", confstr = "", cart=null, cartwin, itemcount=1, itemname="", loaded=false, pagechg=false;

function closeaccessories(doc) {
   for (acc=1; acc<6; acc++) {
   accobj1 = "accessories1" + acc; 
   accobj2 = "accessories2" + acc;
   accobj3 = "accessories3" + acc;
   accobj4 = "accessories4" + acc;
   accobj5 = "accessories5" + acc;
   accobj6 = "accessories6" + acc;
   accobj7 = "accessories7" + acc;
   accobj8 = "accessories8" + acc;
   accobj9 = "accessories9" + acc;
   accobj10 = "accessories10" + acc;
   accobj11 = "accessories11" + acc;
   accobj12 = "accessories12" + acc;
   try {doc.forms[accobj1].innerHTML = "<input type='button' name='Button2' value='Other Sizes & Accessories' onClick='openaccessories"+acc+"()'>";} catch (Exception){;}
   try {doc.forms[accobj2].innerHTML = "";} catch (Exception){;}
   try {doc.forms[accobj3].innerHTML = "";} catch (Exception){;}
   try {doc.forms[accobj4].innerHTML = "";} catch (Exception){;}
   try {doc.forms[accobj5].innerHTML = "";} catch (Exception){;}
   try {doc.forms[accobj6].innerHTML = "";} catch (Exception){;}
   try {doc.forms[accobj7].innerHTML = "";} catch (Exception){;}
   try {doc.forms[accobj8].innerHTML = "";} catch (Exception){;}
   try {doc.forms[accobj9].innerHTML = "";} catch (Exception){;}
   try {doc.forms[accobj10].innerHTML = "";} catch (Exception){;}
   try {doc.forms[accobj11].innerHTML = "";} catch (Exception){;}
   try {doc.forms[accobj12].innerHTML = "";} catch (Exception){;}

   try {doc.forms[accobj2].outerHTML = "<form name='"+accobj2+"' method='post' action=''></form>";} catch (Exception){;}
   try {doc.forms[accobj3].outerHTML = "<form name='"+accobj3+"' method='post' action=''></form>";} catch (Exception){;}
   try {doc.forms[accobj4].outerHTML = "<form name='"+accobj4+"' method='post' action=''></form>";} catch (Exception){;}
   try {doc.forms[accobj5].outerHTML = "<form name='"+accobj5+"' method='post' action=''></form>";} catch (Exception){;}
   try {doc.forms[accobj6].outerHTML = "<form name='"+accobj6+"' method='post' action=''></form>";} catch (Exception){;}
   try {doc.forms[accobj7].outerHTML = "<form name='"+accobj7+"' method='post' action=''></form>";} catch (Exception){;}
   try {doc.forms[accobj8].outerHTML = "<form name='"+accobj8+"' method='post' action=''></form>";} catch (Exception){;}
   try {doc.forms[accobj9].outerHTML = "<form name='"+accobj9+"' method='post' action=''></form>";} catch (Exception){;}
   try {doc.forms[accobj10].outerHTML = "<form name='"+accobj10+"' method='post' action=''></form>";} catch (Exception){;}
   try {doc.forms[accobj11].outerHTML = "<form name='"+accobj11+"' method='post' action=''></form>";} catch (Exception){;}
   try {doc.forms[accobj12].outerHTML = "<form name='"+accobj12+"' method='post' action=''></form>";} catch (Exception){;}

   // try {doc.all["acctable"+acc].bgColor='#EFEFFF';} catch (Exception) {;}
   try {doc.all["itemtable"+acc].refresh();} catch (Exception) {;}
   // try {doc.getElementById("acctable"+acc).bgColor='#EFEFFF';} catch (Exception) {;}
   try {doc.getElementById("itemtable"+acc).refresh();} catch (Exception) {;}
   }
}

function get_cookie(Name) {
  var search = Name + "="
  var returnvalue = "";
  if (document.cookie.length > 0) {
    offset = document.cookie.indexOf(search)
    // if cookie exists
    if (offset != -1) { 
      offset += search.length
      // set index of beginning of value
      end = document.cookie.indexOf(";", offset);
      // set index of end of cookie value
      if (end == -1) end = document.cookie.length;
      returnvalue=unescape(document.cookie.substring(offset, end))
      }
   }
  return returnvalue;
}

function checknumeric(nval) {

}


function additem (productnum, productname, productqty, productprice) {

  var rdon=" READONLY";
  if (navigator.appName.indexOf("Microsoft")>-1) {rdon = "";}
  qtyitem = "productqty"+itemcount;
  qtyselect = "<input type='text'" +rdon+ " name='productqty" +itemcount+ "' size='2' value='" +productqty+ "' maxlength='2'>";
  confstr += "Add the item\r\n("+productname+")\r\nto your shopping cart";
  if (productqty != "1") {confstr += "Add "+productqty+" of the item\r\n("+productname+")\r\nto your shopping cart";}
  confstr += "\r\nYour Shopping Cart is displayed Below";
  if (!confirm(confstr)) {return;}

  productname = productname.replace(/\"/i, "``");
  productname = productname.replace(/'/i, "`");
  productname = productname.replace(/</i, "«");
  productname = productname.replace(/>/i, "»");

  productnum = productnum.replace(/\"/i, "``");
  productnum = productnum.replace(/'/i, "`");
  productnum = productnum.replace(/</i, "«");
  productnum = productnum.replace(/>/i, "»");

  tmpform+= "<input type='hidden' name='productnum" + itemcount + "' value='" + productnum + "'> ";
  tmpform+= "<input type='button' name='productCancel"+itemcount+"' value='Cancel..' onClick='Cancelitem("+itemcount+")'> ";
  tmpform+= qtyselect ;
  tmpform+= " <input type='text' name='productname" + itemcount + "' READONLY size='45' value='" + productname + "'> ";
  tmpform+= " <input type='text' name='productprice" + itemcount + "' READONLY size='7' value='" + productprice + "'> <br>";

  document.chform.innerHTML = tmpform; 
  itemcount++;
  formupdate();
}


function addtocart(productnum, productname, productqty, productprice) {
   if (itemcount > 12) {
      alert("Your shopping cart is Full.\r\nPlease Check-Out your current order before choosing more products.");
      return;
   }

   if (productnum.value.length < 2 || productprice.value.length < 2) {
      alert("Sorry, this item is cannot be added to your cart.\r\nPlease choose accessories or another item.");
      return;
   }
   if (loaded == false) {return;}
   confstr = "";
   for (ii=0; ii<document.chform.elements.length; ii++) {
      if (document.chform.elements[ii].value == productnum.value) {
         confstr = "This item is already in your cart.\r\nYou can however change this item's quantity\r\n";
         alert (confstr);
         return;
      }
   }
   additem(productnum.value, productname.value, productqty.value, productprice.value);
   document.formutil.Button3.disabled=false;

  formupdate();
}


function submitproc2() {
   chkoutstr = "Proceed to our Secure Server to enter your billing and payment information ?";
   if (confirm (chkoutstr)) {
      document.outform.submit();
   } else { return (false);}
}


function completeorder() {
   chkoutstr = "Complete your order and accept the charges to this\r\n";
   chkoutstr += "credit card for all of the items you have selected ?";
   if (confirm (chkoutstr)) {
      document.cookie = "cartinner=";
      document.chform.submit();
   } else { return (false);}
}


function checkout() {
   chkoutstr = "Checkout Shopping Cart\r\n";
   chkoutstr += "Confirm your order, and proceed to checkout shopping cart?";
   for (ii=0; ii<document.chform.elements.length; ii++) {
      if (document.chform.elements[ii].disabled == true) {
         chkoutstr = "There are some 'Canceled' items in your shopping cart.\r\nAny canceled items will not be submitted.\r\nPress 'OK' if you are ready to Confirm your order, and proceed to checkout shopping cart";
         break;
      }
   }

   if (document.chform.elements.length < 4) {
      alert ("Your shopping cart is empty.\r\nPlease select one or more items");
      return (false);
   }

   if (confirm (chkoutstr)) {
      document.chform.submit();
   } else { return (false);}
}


function formupdate() {
   document.cookie = "cartinner="+tmpform;
   document.cookie = "itemcount="+itemcount;

  // document.cookie = "cartinner="+tmpform+"; expires=Thu, 01-Jan-2009 00:00:01 GMT";
  // document.cookie = "itemcount="+itemcount+"; expires=Thu, 01-Jan-2009 00:00:01 GMT";
}


function pagechange() {
   tmpform = document.chform.innerHTML;
   formupdate();
  // alert(document.cookie);
}


function pageload() {
if (get_cookie("cartinner")=="")
     {document.formutil.Button3.disabled=true;
       return;
     }
   tmpform = get_cookie("cartinner");
   itemcount = get_cookie("itemcount").valueOf();
   if (itemcount <1) {itemcount = 1;}
   document.chform.innerHTML = tmpform;
}


function Cancelitem(itemnum) {
   var qty="", nam="", num="", but="";
   qty = "productqty" + itemnum;
   nam = "productname" + itemnum;
   num = "productnum" + itemnum;
   prc = "productprice" + itemnum;
   but = "productCancel" + itemnum;
   if (document.chform.elements[qty].disabled == true) {
      if (confirm("Restore the item\r\n("+document.chform.elements[nam].value+")\r\nPlace this item back onto your shopping list")) {

         document.chform.elements[but].value = "Cancel..";
         document.chform.elements[qty].disabled = false;
         document.chform.elements[nam].disabled = false;
         document.chform.elements[num].disabled = false;
         document.chform.elements[prc].disabled = false;
      }
   } else {
      if (confirm("Cancel the item\r\n("+document.chform.elements[nam].value+")\r\nThis item will not appear on the checkout page")) {

         document.chform.elements[but].value = "Restore";
         document.chform.elements[qty].disabled = true;
         document.chform.elements[nam].disabled = true;
         document.chform.elements[num].disabled = true;
         document.chform.elements[prc].disabled = true;
      }
   }
}


function pageclose(pgstr) {
   // fix this
   if (document.chform.elements.length < 0) {
      return (pgstr); 
   }
}

if (get_cookie("referrer") == "") {document.cookie = "referrer=" + document.referrer}


