/*
	Copyright © 1996-2000 Gorp.com, Inc. All rights reserved. 
	You may not use this (or any part of this) code 
	without written permission from Gorp.com
*/

	function setCookie (cookieName, cookieValue, expires, domain, path,  secure) {
	  document.cookie = 
	    escape(cookieName) + '=' + escape(cookieValue) 
	    + (expires ? '; EXPIRES=' + expires.toGMTString() : '')
	    + (path ? '; PATH=' + path : '')
	    + (domain ? '; DOMAIN=' + domain : '')
	    + (secure ? '; SECURE' : '');
	}
	
	function setCookieForSession (cookieName, cookieValue, domain, path,  secure) {
	  document.cookie = 
	    escape(cookieName) + '=' + escape(cookieValue) 
	    + (path ? '; PATH=' + path : '')
	    + (secure ? '; SECURE' : '');
	}
	
	function setCookieForSession_bak (cookieName, cookieValue, domain, path,  secure) {
	  document.cookie = 
	    escape(cookieName) + '=' + escape(cookieValue) 
	    + (path ? '; PATH=' + path : '')
	    + (domain ? '; DOMAIN=' + domain : '')
	    + (secure ? '; SECURE' : '');
	}
	
	function getCookie (cookieName) {
	  var cookieValue = null;
	  var posName = document.cookie.indexOf(escape(cookieName) + '=');
	  if (posName != -1) {
	    var posValue = posName + (escape(cookieName) + '=').length;
	    var endPos = document.cookie.indexOf(';', posValue);
	    if (endPos != -1)
	      cookieValue = unescape(document.cookie.substring(posValue, endPos));
	    else
	      cookieValue = unescape(document.cookie.substring(posValue));
	  }
	  return cookieValue ? cookieValue : '';
	}

	function replace(val, replaceStr, replaceWith){
		var rtn = "";
		var search= replaceStr;
		start = 0;
		offset = val.indexOf(search,start);
		while (offset != -1){
			rtn = rtn + val.substring(start, offset) + replaceWith;
			start = offset + search.length;
			offset = val.indexOf(search,start);
		}
		rtn = rtn + val.substring(start, val.length);
		return rtn;
	}
	
	function getCookieKey(Key, Cookie) {
		if (Cookie == null) {
			return null;
		}
		var search=Key + "=";
		offset = Cookie.indexOf(search);
		if (offset != -1){
	  		offset += search.length;
	  		end = Cookie.indexOf("&",offset);
	  		if (end == -1)
	   			end = Cookie.length;
	  		var rtn = unescape(Cookie.substring(offset, end));
	  		return replace(rtn, "+", " ");
		}
	}
	
