// gets the client message, displays it, then sets the message to blank
function checkMessage() {
	var msg = getGlobal('Message');
	if (msg != '') {
		alert(msg.replace(/\\n/g,'\n').replace(/\\r/g,'\r'));
		setGlobal('Message', '')
	}
}

function getUserInfo(name) {
// gets a retained User Infomation value for the current application
	return getCookie(appName, name);
}

function setUserInfo(name, value) {
// sets a retained User Infomation value for the current application
	var dt = new Date();
	dt = new Date(dt.setFullYear(dt.getFullYear() + 1));
	setCookie(appName, name, value, dt.toGMTString());
}

function getGlobal(name) {
// gets a session-level value
	return getCookie(appName + 'SessInfo', name);
}

function setGlobal(name, value) {
// sets a session-level value
	setCookie(appName + 'SessInfo', name, value);
}

// retrieves a cookie.
function getCookie(cookie, key) {
	key = key.toUpperCase();
	var allCookies = document.cookie;
	if (allCookies == "") return "";
	var start = allCookies.indexOf(cookie + '=');
	while (start > 0 && allCookies.substr(start-2,1)!=';') 
		start = allCookies.indexOf(cookie + '=',start+1);
	if (start == -1) return "";
	start += cookie.length + 1;
	var end = allCookies.indexOf(';', start);
	if (end == -1) end = allCookies.length;
	var cookieVal = allCookies.substring(start, end);
	var a = cookieVal.split('&');
	if (key == '') return a;
	var result;
	for (var i=0; i < a.length; i++) {
		result = a[i].split('=');
		if (result[0] == key) return unescape(result[1].replace(/\+/g,' '));
	}
	return "";
}

function setCookie(cookie, key, value, expires) {
// sets a value in the document cookie.
	key = key.toUpperCase();
	var cookieVal = '';
	var allCookies = document.cookie;
	var start = allCookies.indexOf(cookie + '=');
	while (start > 0 && allCookies.substr(start-2,1)!=';') 
		start = allCookies.indexOf(cookie + '=',start+1);
	if (start != -1) {
		start += cookie.length + 1;
		var end = allCookies.indexOf(';', start);
		if (end == -1) end = allCookies.length;
		var cookieVal = allCookies.substring(start, end);
	}
	var a = cookieVal.split('&');
	var i=0;
	if (key == '') {
		a = (value!='')?[escape(value)]:[];
	} else for (i=0; i < a.length; i++) {
		if (a[i].split('=')[0] == key) {
			if (value == '') {
				if (i==0 && a.length==1) {a.length == 0} else
				if (i == a.length-1) {a = a.slice(0,i)} else
				a = a.slice(0,i).concat(a.slice(i+1));
			} else {
				a[i] = key + '=' + escape(value);
			}
			break;
		}
	}
	if (value != '' && i == a.length) a[a.length] = key + '=' + escape(value);
	if (a.length != 0)
		var st = cookie + '=' + a.join('&') + "; path=" + siteRoot;
	else var st = cookie + '=' + (navigator.appName.indexOf("Netscape") >= 0)?' ':'' + "; path=/";
	if (arguments.length == 4) 
		st += "; expires=" + expires;
	document.cookie = st;
}
