function addItemToList(itemID)
{
//	alert ("Item Added: " + itemID);
	if(canUseTripPlanner())
	{
		addItemToSCC(itemID);
		SetCookie('HMTripPlanner', scc, null, "/");
		return true;
	}
	else
	{
		return false;
	}
}


function addItemToSCC (itemID)
{
	// if it is NOT in the list add it
	if (scc.indexOf("." + itemID) < 0)
	{
		scc = "" + scc + itemID + ".";
	}
}


function canUseTripPlanner()
{
	if(cookieEnabled())
	{
		return true;
	}
	else
	{
		alert("Sorry, you must have cookies enabled to use the Trip Planner.");
		return false;
	}
}


function cookieEnabled()
{
	SetCookie("cookieEnabled", "TRUE");
	if (GetCookie("cookieEnabled"))
	{
		DeleteCookie("cookieEnabled");
		return true;
	}
	else
	{
		return false;
	}
}


function DeleteCookie (name,path,domain) {
  if (GetCookie(name)) {
    document.cookie = name + "=" +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}


function GetCookie (name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
      return getCookieVal (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break; 
  }
  return null;
}


function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}


function removeItemFromList(itemID)
{
//	alert ("Item Removed: " + itemID);
	if(canUseTripPlanner())
	{
		removeItemFromSCC(itemID);
		SetCookie('HMTripPlanner', scc, null, "/");
		return true;
	}
	else
	{
		return false;
	}
}


function removeItemFromSCC (itemID)
{
//	alert ("itemID: " + itemID);
	if (scc.indexOf("." + itemID) >= 0)
	{
		var startpoint = scc.indexOf("." + itemID);
		var endpoint = scc.indexOf(".", scc.indexOf("." + itemID)+1);
		var temp = scc.substring(startpoint, endpoint);
		var firsthalf = scc.substring(0, startpoint);
		var lasthalf = scc.substring(endpoint, scc.length);
	
		scc = firsthalf + lasthalf;
	}
//	alert ("startpoint: " + startpoint + ", endpoint: " + endpoint + ", temp: " + temp);
//	alert ("firsthalf: " + firsthalf + ", lasthalf: " + lasthalf);
//	alert ("scc: " + scc);
}


function SetCookie (name,value,expires,path,domain,secure) {
  document.cookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}

var scc = new String();
if (GetCookie('HMTripPlanner'))
{
	scc = new String(GetCookie('HMTripPlanner'));
}
else
{
	scc = ".";
}

function readTripCookie()
{
	GetCookie('HMTripPlanner');
	scc = new String(GetCookie('HMTripPlanner'));
	alert (scc);
}

function deleteTripCookie()
{
	DeleteCookie('HMTripPlanner');
}
