	function getCookieVal(offset) {
		var endstr = document.cookie.indexOf (";", offset);
		if (endstr == -1) {
			endstr = document.cookie.length;
		}
		return unescape(document.cookie.substring(offset, endstr));
	}
	
	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 writeCookie(p_sName, p_sValue){
		var w_aArgv       = writeCookie.arguments;
		var w_iArgc       = writeCookie.arguments.length;
		var p_sExpireDays = ((w_iArgc > 2) &&  (w_aArgv[2] != '')) ? w_aArgv[2] : null;
	 	SetCookie(p_sName, p_sValue, p_sExpireDays);
	}

	function SetCookie(p_sName, p_sValue) {
		var w_aArgv       = SetCookie.arguments;
		var w_iArgc       = SetCookie.arguments.length;
		var p_sExpireDays = ((w_iArgc > 2) &&  (w_aArgv[2] != '')) ? w_aArgv[2] : null;
		var p_sPath       = ((w_iArgc > 3) &&  (w_aArgv[3] != '')) ? w_aArgv[3] : null;
		var p_sDomain     = ((w_iArgc > 4) &&  (w_aArgv[4] != '')) ? w_aArgv[4] : null;
		var p_bSecure     = ((w_iArgc > 5) &&  (w_aArgv[5] != '')) ? w_aArgv[5] : false;
		if(p_sExpireDays){
			var today = new Date();
			today.setTime(today.getTime());
			var p_sExpires = new Date(today.getTime() + (p_sExpireDays*24*60*60*1000));
		}
		else{
			var p_sExpires = null;
		}
		
		document.cookie =
			p_sName + '=' + escape(p_sValue)
			+ ((p_sExpires == null) ? '' : ('; expires=' + p_sExpires.toGMTString()))
			+ ((p_sPath == null) ? '' : ('; path=' + p_sPath))
			+ ((p_sDomain == null) ? '' : ('; domain=' + p_sDomain))
			+ ((p_bSecure == true) ? '; secure' : '')
		;
	}
	
	function DeleteCookie(name) {
		var exp = new Date();
		exp.setTime (exp.getTime() - 1000000000);  // This cookie is history (changed -1 to make it previous time)
		var cval = GetCookie (name);
		document.cookie = name + '=' + cval + '; expires=' + exp.toGMTString();
		alert(name + 'The cookie has been deleted.');
	}
	