/*  Copyright © 2001, 2002 OGMA Consulting Corp. */

/* cookie.js
 *
 */

function getCookie(cookieName) {

	var result = "";

	var allCookies = document.cookie;
	var pos        = allCookies.indexOf(cookieName + "=");

	if (pos != -1) {

		var start = pos + cookieName.length + 1;
		var end   = allCookies.indexOf(";", start);

		if (end == -1) end = allCookies.length;

		result = allCookies.substring(start, end);
	}

	return result;
}


function setCookie(cookieName, cookieValue) {

	document.cookie = cookieName + "=" + cookieValue + ";path=/";
}


function addSessionId(sessionId) {

	var currentSessionIds = getCookie("sessionID");

	if (currentSessionIds.indexOf("|" + sessionId + "|") == -1) {

	  currentSessionIds += "|" + sessionId + "|";

	  setCookie("sessionID", currentSessionIds);
	}
}


function removeSessionId(sessionId) {

  var currentSessionIds = getCookie("sessionID");
  var pos               = currentSessionIds.indexOf("|" + sessionId + "|");

  if (pos > -1) {

    var before = currentSessionIds.substr(0, pos);
    var after  = currentSessionIds.substr(pos + sessionId.length + 2);

    setCookie("sessionID", before + after);
  }
}
