/*
	map.cookie.js
	
	The map.cookie code provides functions for modifyng and traversing cookies
   
 */   

// DEFINE COOKIE CLASS
cookieClass = function() {}; // empty class constructor


//*****************************************************************************
// BEGIN COOKIE METHODS
//*****************************************************************************


//*****************************************************************************
// FUNCTION GETCOOKIEVALUE
//*****************************************************************************

cookieClass.prototype.getCookieValue = function(searchArg){
  //give this function the name of a cookie name/value pair and it returns the value of that cookie, if it exists
  var dc = document.cookie;
  var retVal="";
  var cookieName = new String();
  var cookieValue = new String()
  var myArray = dc.split(";");
  for (i=0 ; i < myArray.length ; i++) {
    cookieName = myArray[i].substr(0,myArray[i].indexOf("="));
    cookieValue = myArray[i].substr(myArray[i].indexOf("=")+1);
    if (cookieName.indexOf(searchArg) != -1) retVal = cookieValue;
  }
  return retVal;     
}
// END FUNCTION GETCOOKIEVALUE
//*****************************************************************************


//*****************************************************************************
// FUNCTION SETCOOKIEVALUE
//*****************************************************************************

cookieClass.prototype.setCookieValue = function(cookieName,cookieValue,expireDays){
	var today = new Date();
	today.setTime(today.getTime());
	if (expireDays == "") expireDays = "false"; 
	//sets a cookie of cookieName with the value cookieValue
	if (expireDays != "false") {
		expireDays = expireDays * 1000 * 60 * 60 * 24;
		var expireDate = new Date(today.getTime() + (expireDays) );
		document.cookie = cookieName + "=" + cookieValue + ";path=/;domain=mit.edu" + "; expires=" + expireDate.toUTCString();
	} else document.cookie = cookieName + "=" + cookieValue + ";path=/;domain=mit.edu";
}
// END FUNCTION GETCOOKIEVALUE
//*****************************************************************************




// END COOKIE METHODS
//*****************************************************************************


//*****************************************************************************
// ADD COOKIE CLASS TO MAPCLASS
//*****************************************************************************
mapClass.prototype.cookie = new cookieClass();



