function setCookie( name, value, path, domain, secure )
{
	//set value
    var cookie_string = name + "=" + value;

	//set expire date
	var expDays = 360;
	var exp = new Date();
	exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
	cookie_string += "; expires=" + exp.toGMTString();

	//set path
    if ( path )
        cookie_string += "; path=" + escape(path);

	//set domain
    if ( domain )
        cookie_string += "; domain=" + escape(domain);

	//set secure
    if ( secure )
        cookie_string += "; secure";

	//write the cookie
    document.cookie = cookie_string;
}

function deleteCookie( cookie_name )
{
    var cookie_date = new Date();
    // current date & time
    cookie_date.setTime(cookie_date.getTime() - 1);
    document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
}

function getCookie( cookie_name )
{
    var results = document.cookie.match('(^|;) ?' + cookie_name + '=([^;]*)(;|$)');

    if ( results )
        return ( unescape(results[2]) );
    else
        return null;
}

function getParameter ( queryString, parameterName ) {
   // Add "=" to the parameter name (i.e. parameterName=value)
   var parameterName = parameterName + "=";
   if ( queryString.length > 0 ) {
      // Find the beginning of the string
      begin = queryString.indexOf ( parameterName );
      // If the parameter name is not found, skip it, otherwise return the value
      if ( begin != -1 ) {
         // Add the length (integer) to the beginning
         begin += parameterName.length;
         // Multiple parameters are separated by the "&" sign
         end = queryString.indexOf ( "&" , begin );
      if ( end == -1 ) {
         end = queryString.length
      }
      // Return the string
      return unescape ( queryString.substring ( begin, end ) );
   }
   // Return "null" if no parameter has been found
   return "null";
   }
}

//init cDomain
var cDomain = self.location.hostname;
if(cDomain.indexOf(".") < cDomain.lastIndexOf("."))
{
  var domainOffset = cDomain.indexOf(".")+1
  cDomain = cDomain.substr(domainOffset);
}

//set cookie only if it hasn't been set yet
//do not overwrite the same cookie!
if(document.referrer.indexOf(cDomain)==-1 && document.referrer!="" && document.cookie.indexOf("Referrer=")==-1)
{
  //set the cookie
  setCookie('Referrer',document.referrer,'../../../index.html','babyjellybeans.com',false);
}


