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("Clickez Ok pour supprimer cet article de votre panier.")) {
    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("SVP entrez une quantité valide");
    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. collier</b>: Pendentif avec cordon en cuir grec de 45cm et fermoir en argent sterling.</dt>" +
       "<dt><b>2. anneau brisé</b>: Pendentif avec anneau brisé de 16mm en argent sterling, pour attacher à l'anneau d'un collier pour chien ou chat, ou aux maillons d'un collier en chaîne, à une lanière de cellulaire, ou à un quelconque collier ou porte-clés.</dt>" +
       "<dt><b>3. glissière</b>: Pendentif avec glissière de 12, 19, ou 25mm assortie à nos colliers de 12, 19 ou 25mm de large, ou à un collier épais de 4mm max.</dt>" +
       "<dt><b>4. porte-clés</b>: Pendentif avec chaîne à maillons carrés et anneau brisé de 25mm.</dt>" +
       "</dl></div>" +
       "<div style=\"text-align: center;\"><a href=\"javascript:setvisible('pendantstyleslayer')\" class=\"link16\" title=\"cliquez pour fermer cette fenêtre et retourner au pendentif\"><br>cliquez ici pour continuer</a></div><div class=\"lb8\"></div>";
   document.write(o);
   document.close();
}

