// cookieEnabled - Determine JavaScript cookie support in client's browser
var cookieEnabled=(navigator.cookieEnabled)? true : false

//if not IE4+ nor NS6+
if (typeof navigator.cookieEnabled=="undefined" && !cookieEnabled) {
	document.cookie="testcookie"
	cookieEnabled=(document.cookie.indexOf("testcookie")!=-1)? true : false
}


// name - cookie name
// value - cookie value
// [expires] - expire date cookie (till the end of session by default)
// [path] - the path cookie works for (by default - the document where the cookie was set)
// [domain] - domain name for the cookie (defult - the domain  where the cookie was set)
// [secure] - boolean, do we need encypted cookie value
function setCookie(name, value, expires, path, domain, secure) {
	var curCookie = name + "=" + escape(value) +
		((expires) ? "; expires=" + expires.toGMTString() : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");
	if (!caution || (name + "=" + escape(value)).length <= 4000)
		document.cookie = curCookie;
	else
	if (confirm("Cookie size exceeds 4KB"))
		document.cookie = curCookie;
}

// name - cookie name
function getCookie(name) {
	var prefix = name + "="
	var cookieStartIndex = document.cookie.indexOf(prefix);
	if (cookieStartIndex == -1)
	return null;
	var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length);
	if (cookieEndIndex == -1)
		cookieEndIndex = document.cookie.length;
	return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex));
}

// name - cookie name
// [path] - cookie path
// [domain] - cookie domain
function deleteCookie(name, path, domain) {
	if (getCookie(name)) {
		document.cookie = name + "=" + 
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		"; expires=Thu, 01-Jan-70 00:00:01 GMT"
	}
}

function getLoggedUsername() {
	if (!cookieEnabled) return '';
	var user_session = getCookie('user_session');
	if (!user_session) return '';
	var user_login = getCookie('user_login');
	return user_login;
}

var loggedUsername = getLoggedUsername();

