if (typeof SEAT.COOKIE === "undefined") {
  SEAT.COOKIE = {};
}

//myName= cookie name
//myValue= cookie value
//myDate= Date to expire or false for a session cookie
//myDomain= all cookies set to myDomain, can be read or false for no domain
//myPath= Cookie path or false for complete visibility within this domain
//enc: If true, "encodeURIComponent" is used to encode all characters in UTF-8 otherwise "escape" is used
//     for backwards compatibility
SEAT.COOKIE.setCookie = function (myName, myValue, myDate, myDomain, myPath, enc) {

	var myProperties = myName + "=" + ((enc) ? encodeURIComponent(myValue) : escape(myValue));
	
	if (myDate) {
		myProperties += ";expires=" + myDate.toGMTString();
	}
	
	if (myDomain) {
		myProperties += ";domain=" +myDomain;
	}

	// Default to a session cookie
	if(!myPath) {
		myPath= "/";
	}
	myProperties += ";path=" + myPath;

	document.cookie = myProperties;
}

// This function scans through the input string str 
// searching for the input key. 
// The delimiter input specifies the delimiter which follows the key
// dec: If true, "decodeURIComponent" is used to decode all characters from UTF-8 otherwise "unescape" is used
//     for backwards compatibility
SEAT.COOKIE.getCookieValue = function(myStr, myKey, myDelimiter, dec) {
	
	var iBegin,
	    iEnd,
	    s;
	    
	// Case A: no cookie
 	if (myStr === null) {
   	return null;
 	}
 	
	if (myStr.length > 0) {
    iBegin = myStr.indexOf(myKey);
    if (iBegin !== -1) {
      iBegin += myKey.length;
      iEnd = myStr.indexOf(myDelimiter, iBegin);
      if (iEnd === -1) {
        iEnd = myStr.length;
      }
      
      // Case B: cookie exists with this name
      s = myStr.substring(iBegin, iEnd);
      return (dec) ? decodeURIComponent(s) : unescape(s);
    }
  }
  // Case C: no cookie with this name
  return null;
}

// Scans through document.cookie until the the cookie 
// in question is found and then returns that  cookie's value.
SEAT.COOKIE.getCookie = function(myName, dec) {
	myName = myName + "=";
	return SEAT.COOKIE.getCookieValue(document.cookie, myName, ";", dec);
}

// Delete this cookie setting date to 01 gen 1970 00:00:10
SEAT.COOKIE.delCookie = function(myName, myDomain, myPath) {
  SEAT.COOKIE.setCookie(myName, "", new Date(10000) ,myDomain, myPath);
}


