// functions to get/set/remove cookies

// setting a server spanning cookie
function setCookie(name, value)
{
	var url = document.location + "";
	var urlStart = url.substring(url.indexOf(".")) + "";
	var domain = urlStart.substring(0, urlStart.indexOf("/"));
	if(domain.indexOf(":") != -1){
		domain = domain.substring(0, domain.indexOf(":"));
	}
	document.cookie = name +"="+ value +";path=/;domain=" + domain ;
}

// get cookie and return fallback value if not found or empty
function getCookie(name, fallback)
{
	cookies = document.cookie +";";       // ensure terminator
	valStart = cookies.indexOf(name+"=")  // look for cookie
	if(valStart < 0) return fallback;     // if not found return fallback
	valEnd = cookies.indexOf(";", valStart); // find end of value
	if(valStart + name.length + 1 == valEnd) return fallback; // for my dear Netscape, which puts ='s
	return cookies.substring(valStart + name.length + 1, valEnd); // return value part
}

// removes cookie by emptying its value
function removeCookie(name)
{
	setCookie(name, "");
}

// acts like getCookie but prints the value on the document
function printCookie(name, fallback)
{
	document.write(getCookie(name, fallback));
}
