// SetCart
// Gestion du panier

function checkRef(ref) {
 var beginId=0;
 var endId=0;
 zeCart = GA_readCookie('lsCart');
 if (!zeCart) zeCart='';
 beginId = zeCart.indexOf(ref, 0);
 if (beginId!=-1) { // la ref existe, on l'enleve
 // endId = zeCart.indexOf('!', beginId);
 // cart2=zeCart.slice(0, beginId) + zeCart.slice(endId+1);
  cart2=zeCart;
  alert('Cette photo est deja dans le panier');
 } else { // la ref n'existe pas, on l'ajoute
  cart2=zeCart+ref+'!';
  alert('La photo a ete ajoute au panier');
 }
 GA_setCookie('lsCart',cart2,'1','/','');
}

function GA_setCookie (nom, valeur, heures, chemin, domaine) {
 document.cookie = nom + '=' + valeur + ((heures)?(';expires=' + ((new Date((new Date()).getTime() + parseInt(heures)*3600000)).toGMTString())):'') + ((chemin)?';path=' + chemin:'') + ((domaine)?';domain=' + domaine:'');
}

function GA_readCookie(name) {
 if(document.cookie != '') {
  var actualValue, outputElement, firstChar, lastChar;
  var theBigCookie = document.cookie;
  firstChar = theBigCookie.indexOf(name);
  if(firstChar != -1) {
   firstChar += name.length + 1;
   lastChar = theBigCookie.indexOf(';', firstChar);
   if(lastChar == -1) lastChar = theBigCookie.length;
   actualValue = theBigCookie.substring(firstChar, lastChar);
  } else {
   actualValue = '';
  }
  return actualValue;
 }
}

function GA_killCookie(name, path, domain) {
 var firstChar, lastChar, theValue;
 var theBigCookie = document.cookie;
 firstChar = theBigCookie.indexOf(name);
 if(firstChar != -1) {
  firstChar += name.length + 1;
  lastChar = theBigCookie.indexOf(';', firstChar);
  if(lastChar == -1) lastChar = theBigCookie.length;
   theValue = theBigCookie.substring(firstChar, lastChar);
  } else {
   theValue = false;
 }
 if(theValue) {
  document.cookie = name + '=' + theValue + '; expires=Fri, 13-Apr-1970 00:00:00 GMT' + ((path)?(';path=' + path):('')) + ((domain)?(';domain=' + domain):(''));
 }
}