function checkCookie(thisProd)
{
  var prods= "";
  var updatedList= "";
  prods = readCookie('recentprods');
  if ((prods == null) || (prods == ""))
  {
    createCookie("recentprods",".1. "+thisProd+"\,","30");
    return null;
  }
  if ((prods.indexOf(".2.") == -1)&& (prods.indexOf(thisProd) == -1 ))
    // we can add the second prod (if it's not in there already)
     {
    createCookie("recentprods",prods+".2. "+thisProd+"\,","30");
    return null;
     }
  if ((prods.indexOf(".3.") == -1)&& (prods.indexOf(thisProd) == -1 ))
    // we can add the third prod (if it's not in there already)
     {
    createCookie("recentprods",prods+".3. "+thisProd+"\,","30");
    return null;
     }
  if ((prods.indexOf(".4.") == -1)&& (prods.indexOf(thisProd) == -1 ))
    // we can add the 4th prod (if it's not in there already)
     {
    createCookie("recentprods",prods+".4. "+thisProd+"\,","30");
    return null;
     }
  if ((prods.indexOf(".5.") == -1)&& (prods.indexOf(thisProd) == -1 ))
    // we can add the 5th prod (if it's not in there already)
     {
    createCookie("recentprods",prods+".5. "+thisProd+"\,","30");
    return null;
     }
// if there are already 5 products and the one to be added is not already there....
  if ((prods.indexOf(".5.") != -1)&& (prods.indexOf(thisProd) == -1 ))
       {
         updatedList = prods.substring(prods.indexOf(".2."),prods.length);
         updatedList = updatedList.replace(".2.",".1.");
         updatedList = updatedList.replace(".3.",".2.");
         updatedList = updatedList.replace(".4.",".3.");
         updatedList = updatedList.replace(".5.",".4.");

    createCookie("recentprods",updatedList+".5. "+thisProd+"\,","30");
    return null;

       }
}


function createCookie(name,value,days) {
// executed just if the cookie is empty -> so value will contain just one product

	var date = new Date();
	date.setTime(date.getTime()+(days*24*60*60*1000));
	var expires = "; expires="+date.toGMTString();
	document.cookie = name+"="+value+expires+"; path=/";
}



function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}


