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 setCookie (name, value) {
	var argv = setCookie.arguments;
	var argc = setCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	document.cookie = name + "=" + escape (value) +
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
	((path == null) ? "" : ("; path=" + path)) +
	((domain == null) ? "" : ("; domain=" + domain)) +
	((secure == true) ? "; secure" : "");
}

function deleteCookie (name) {
	var exp = new Date();
	exp.setTime (exp.getTime() - 1);
	var cval = getCookie (name);
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

function getCookieVal(offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
		endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

function URLDecode(encoded) {
   // Replace + with ' '
   // Replace %xx with equivalent character
   // Put [ERROR] in output if %xx is invalid.
   var HEXCHARS = "0123456789ABCDEFabcdef";
   var plaintext = "";
   var i = 0;
   while (i < encoded.length) {
      var ch = encoded.charAt(i);
      if (ch == "+") {
         plaintext += " ";
         i++;
      } else if (ch == "%") {
         if (i < (encoded.length-2)
               && HEXCHARS.indexOf(encoded.charAt(i+1)) != -1
               && HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
            plaintext += unescape( encoded.substr(i,3) );
            i += 3;
         } else {
            alert( 'Bad escape combination near ...' + encoded.substr(i) );
            plaintext += "%[ERROR]";
            i++;
         }
      } else {
         plaintext += ch;
         i++;

      }
   }
   return plaintext;
}
function getCookieValue(cookieName){
	var value = getCookie(cookieName);
	if (value == null) { value = ""; }
	value = URLDecode(value);
	return value;
}