var blnk_e=/^\s*$/;
var v;
var oqty;

function getCookieVal(offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1) endstr = document.cookie.length;
  return(unescape(document.cookie.substring(offset, endstr)));
}

function getCookie(name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg) return(getCookieVal (j));
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break;
  }
  return(null);
}

function setCookie(name,value,expires,path,domain,secure) {
  document.cookie = name + "=" + escape (value) +
                    ((expires) ? "; expires=" + expires.toGMTString() : "") +
                    ((path) ? "; path=" + path : "") +
                    ((domain) ? "; domain=" + domain : "") +
                    ((secure) ? "; secure" : "");
}

function delCookie(name,path,domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
                      ((path) ? "; path=" + path : "") +
                      ((domain) ? "; domain=" + domain : "") +
                      "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

function atsb(f_a) {
  var nib = 0;
  var isb = false;
  nib = getCookie("accomplice_itemsInBag");
  if (nib == null) nib = 0;
  if (f_a.it_l == null) str_it_l = "";
  else str_it_l = f_a.it_l.value;
  if (f_a.it_q == null) str_it_q = "1";
  else str_it_q = f_a.it_q.value;
  if (f_a.it_p == null) str_it_p = "0";
  else str_it_p = f_a.it_p.value;
  if (f_a.it_n == null) str_it_n = "";
  else str_it_n = f_a.it_n.value;
  if (f_a.it_s == null) {
    str_it_s = "";
  }
  else {
    str_it_s = f_a.it_s[f_a.it_s.selectedIndex].value.substring(0, f_a.it_s[f_a.it_s.selectedIndex].value.indexOf("$", 0));
  }
  for (c = 1; c <= nib; c++) {
    n_it = "accomplice_item." + c;
    are = "";
    are = getCookie(n_it);
    nt0 = are.indexOf("|", 0);
    nt1 = are.indexOf("|", nt0+1);
    nt2 = are.indexOf("|", nt1+1);
    nt3 = are.indexOf("|", nt2+1);
    lmn = new Array;
    lmn[0] = are.substring(0, nt0);
    lmn[1] = are.substring(nt0+1, nt1);
    lmn[2] = are.substring(nt1+1, nt2);
    lmn[3] = are.substring(nt2+1, nt3);
    lmn[4] = are.substring(nt3+1, are.length);
    if (lmn[0] == str_it_l && lmn[2] == str_it_p && lmn[3] == str_it_n && lmn[4] == str_it_s) {
      isb = true;
      upol = str_it_l + "|" +
             (parseInt(str_it_q)+parseInt(lmn[1])) + "|" +
             str_it_p + "|" +
             str_it_n + "|" +
             str_it_s;
      str_n_it = "accomplice_item." + c;
      delCookie(str_n_it, "/");
      setCookie(str_n_it, upol, null, "/");
      break;
    }
  }
  if (!isb) {
    nib++;
    upol = str_it_l + "|" + 
           str_it_q + "|" +
           str_it_p + "|" +
           str_it_n + "|" +
           str_it_s;
    str_n_it = "accomplice_item." + nib;
    setCookie(str_n_it, upol, null, "/");
    setCookie("accomplice_itemsInBag", nib, null, "/");
  }
}

function rfsb(x) {
  if (confirm("Click Ok to remove this item from your shopping bag.")) {
    nio = getCookie("accomplice_itemsInBag");
    for (j=x; j<nio; j++) {
      n_it_1 = "accomplice_item." + (j+1);
      n_it_2 = "accomplice_item." + (j);
      are = getCookie(n_it_1);
      setCookie (n_it_2, are, null, "/");
    }
    n_it = "accomplice_item." + nio;
    setCookie ("accomplice_itemsInBag", nio-1, null, "/");
    delCookie(n_it, "/");
  }
  location.href=location.href;
}

function chiq(it,it_q) {
  v = it_q.value;
  if(blnk_e.test(v)) {
    it_q.focus();
  }
  else {
    if (isNaN(v)) {
      location.href=location.href;
    }
    else {
      if (v == 0) {
        rfsb(it);
      }
      else {
        n_it = "accomplice_item." + it;
        are = "";
        are = getCookie(n_it);
        nt0 = are.indexOf("|", 0);
        nt1 = are.indexOf("|", nt0+1);
        nt2 = are.indexOf("|", nt1+1);
        nt3 = are.indexOf("|", nt2+1);
        lmn = new Array;
        lmn[0] = are.substring(0, nt0);
        lmn[1] = are.substring(nt0+1, nt1);
        lmn[2] = are.substring(nt1+1, nt2);
        lmn[3] = are.substring(nt2+1, nt3);
        lmn[4] = are.substring(nt3+1, are.length);
        upol = lmn[0] + "|" +
               v + "|" +
               lmn[2] + "|" +
               lmn[3] + "|" +
               lmn[4];
        str_n_it = "accomplice_item." + it;
        delCookie(str_n_it, "/");
        setCookie(str_n_it, upol, null, "/");
        location.href=location.href;
      }
    }
  }
}

function upd8(ster) {
  c = ster.indexOf("$", 0);
  d = ster.substring(0, c);
  p = ster.substring(c+1, ster.length);
  document.getElementById("it_p").value = p;
  document.getElementById("it_p").value = p;
}

function ckiq(q) {
  if (isNaN(q.value)) {
    location.href=location.href;
  }
}

function vdiq(k) {
  if(blnk_e.test(k.value) || k.value == 0) {    
    oqty = true;
  }
  else {
    oqty = false;
  }
}

function stsb(f_b) { 
  if(oqty) {
    alert("Please enter a valid quantity");
    return (false);
  }
  else {
    atsb(f_b);
    return (true);
  }
}

function dspps() {
   var o = "";
   o = "<div class=\"left\">" +
       "<div class=\"lb8\"></div><img src=\"accomplice/pendantstyles.jpg\" alt=\"pendant styles\" height=150 width=610 />" +
       "<div class=\"lb8\"></div><div class=\"lb8\"></div><dl>" +
       "<dt><b>1. necklace</b>: Pendants with 18'' black fine greek leather cord and silver clasp.</dt>" +
       "<dt><b>2. split O-ring</b>: Pendants with 5/8'' diameter silver split O-ring can be attached to an existing collar's O-ring or D-ring, to links on chain collars, to cell phone lanyards, or to existing key chains or necklaces.</dt>" +
       "<dt><b>3. slide</b>: Pendants with 1/2'', 3/4'' or 1'' slides fit onto our 1/2'', 3/4'' or 1'' collars, or onto your existing collars up to 5/32'' thick.</dt>" +
       "<dt><b>4. key chain</b>: Pendants with silver box chain and 1'' diameter silver split O-ring.</dt>" +
       "</dl></div>" +
       "<div style=\"text-align: center;\"><a href=\"javascript:setvisible('pendantstyleslayer')\" class=\"link16\" title=\"click to close this frame and resume\"><br>continue</a></div><div class=\"lb8\"></div>";
   document.write(o);
   document.close();
}

