<!--

function GetCookie(name)
{
 if (document.cookie.length != 0) {
  var cookies = document.cookie.split("; ");

  for (i = 0; i < cookies.length; i++) {
   var cookie = cookies[i].split("=");
   if (cookie[0] == name)
    return (cookie[1] == ".") ? "" : cookie[1];
  }
 }
 return "";
}

function AddToCookie(newCookie, item)
{
 if (typeof(newCookie) == "undefined" || newCookie.length == 0)
  return item;
 return newCookie + "\t" + item;
}

function Add(theForm, aref)
{
 var oldCookie = GetCookie("caddie");
 var newCookie = "";
 var i;
 var aqty = parseInt(theForm.q.value);

 if (aqty == 0)
  return false;

 if (oldCookie.length != 0) {
  var items = oldCookie.split("\t");

  for (i = 0; i < items.length; i++) {
   var item = items[i].split("\x01");

   if (item[0] == aref) {
    aqty = parseInt(item[1]) + aqty;
    newCookie = AddToCookie(newCookie, item[0] + "\x01" + aqty);
    aqty = 0;
   } else
    newCookie = AddToCookie(newCookie, items[i]);
  }
 }

 if (aqty)
  newCookie = AddToCookie(newCookie, aref + "\x01" + aqty);

 document.cookie = "caddie=" + newCookie + ";path=/";
 return true;
}

function Control(theForm)
{
 var i;
 var objStr;
 var obj;
 var oldCookie = GetCookie("caddie");
 var newCookie = "";
 var qty;

 if (oldCookie.length != 0) {
  var items = oldCookie.split("\t");

  for (i = 0; i < items.length; i++) {
   var item = items[i].split("\x01");

   objStr = "document.forms." + theForm.name + ".q" + i;
   obj = eval(objStr);

   if (typeof(obj) == "object") {
    qty = parseInt(obj.value, 10);

    if (qty < 0) {
     alert("Les quantités doivent être égales ou supérieures à zéro");
     return false;
    }
   } else
    break;

   if (qty > 0)
    newCookie = AddToCookie(newCookie, item[0] + "\x01" + qty);
  }
 }

 document.cookie = "caddie=" + ((newCookie.length == 0) ? "." : newCookie) + ";path=/";

 return true;
}

function SetNavigation(theForm)
{
 /*
 var principal = theForm.elements["cadre_principal"].value;
 var quantite = theForm.elements["cadre_quantite"].value;
 
 if (GetCookie("caddie").length == 0) {
  top.frames[principal].document.location.replace(theForm.elements["principale_caddie_vide"].value);
  top.frames[quantite].document.location.replace(theForm.elements["quantite_caddie_vide"].value);
 } else {
  top.frames[principal].document.location.replace(theForm.elements["principale_caddie"].value);
  top.frames[quantite].document.location.replace(theForm.elements["quantite_caddie"].value);
 }
 */
 var lnks = top.frames.nav.document.links;
 
 if (GetCookie("caddie").length == 0) {
  top.frames[lnks[1].target].document.location.replace(lnks[1].href);
  top.frames[lnks[2].target].document.location.replace(lnks[2].href);
 } else {
  top.frames[lnks[3].target].document.location.replace(lnks[3].href);
  top.frames[lnks[4].target].document.location.replace(lnks[4].href);
 }
}

function Recalc(theForm)
{
 if (Control(theForm)) {
  SetNavigation(theForm);
  return true;
 }
 return false;
}

function Remove(theForm, line)
{
 objStr = "document.forms." + theForm.name + ".q" + line;
 obj = eval(objStr);

 if (typeof(obj) == "object") {
  obj.value = "0";

  if (Control(theForm)) {
   SetNavigation(theForm);
   return true;
  }
 }
 return false;
}
//-->
