
function SweetSpot_SetCookie(sName, sValue)
{
  //alert("SweetSpot_SetCookie()");
  date = new Date();
  date.setTime(date.getTime() + (365 * 24 * 3600 * 1000));
  document.cookie = sName + "=" + escape(sValue) +"; path=\"/\"; expires=" + date.toGMTString();
  //alert("SweetSpot_SetCookie("+sName+","+sValue+") - " + sName + "=" + escape(sValue) +"; path=\"/\"; expires=" + date.toGMTString() );
}


function CtcIDInRequest()
{
 	
	var url = document.URL.toLowerCase();
	var start = url.indexOf('ctcid=');
	
	if (start == -1)
		return(null);	
	start += 6;
	var end = url.indexOf('&',start);
	if (end == -1) end = url.length;
	
	var valctcid = url.substring(start,end);
	
	return( valctcid);
}

function SweetSpot_GetCookie(sName)
{
  //alert("SweetSpot_GetCookie()");
  // cookies are separated by semicolons
  var aCookie = document.cookie.split("; ");
  for (var i=0; i < aCookie.length; i++)
  {
    var aCrumb = aCookie[i].split("=");
    if (sName == aCrumb[0]) 
      return unescape(aCrumb[1]);
  }

  // a cookie with the requested name does not exist
  return null;
}

function SaveTracking()
{
	// Should be changed accordingly
	CustomerCode = 'DISTELL_HUN';
   	var CtcID = 	CtcIDInRequest();
		
   	var r =			document.referrer;
   	if (CtcID == null)
    {
   		CtcID = SweetSpot_GetCookie('DISTELL_CTCID_HUN');
			
    }
   	else 
    {		
   		SweetSpot_SetCookie('DISTELL_CTCID_HUN',CtcID);
    }
    LiquoriceID = SweetSpot_GetCookie('DISTELL_LID_HUN');
		
   	if (CtcID != null || LiquoriceID != null) 
    {
		 	if(CtcID == null) CtcID = "0";			
		 	if(LiquoriceID == null) LiquoriceID = "0";
					
			document.write('<IMG WIDTH="1" HEIGHT="1" SRC="track.php?CustomerCode=' + CustomerCode + '&CtcID=' + CtcID + '&LiquoriceID=' + LiquoriceID + '&p=' + document.URL + '&Referer=' + r + '">');
    }
}