// Glycero cookie management

function setCookie(name, value, expires)
{
        var re = /(\w+\.\w+)$/ ;
        var host = window.location.host ;
	if (!host) return ;
        var matches = host.match(re) ;
	if (!matches)
	{
		re = /(\w+\.\w+):\d+$/ ;
        	matches = host.match(re) ;
		if (!matches)
			return ;
			// alert("can't match domain in host '"+host+"'") ;
	}
        var domain = matches[1] ;
        if (expires && expires.length)
        {
                expires = "; expires="+expires ;
        }
        else
        {
                expires = "" ;
        }
        document.cookie = name+"="+value+"; path=/; domain=."+domain+expires ;
        //alert(name+"="+value+"; path=/; domain=."+domain+expires) ;
}

function checkCookieSession()
{
	var bool = false ;
	document.cookie = "cksession=; expires=Fri, 02 Jan 1970 00:00:00 GMT" ;
	document.cookie = "cksession=yes" ;
	bool = (document.cookie.indexOf("cksession=yes") != -1) ;
	document.cookie = "cksession=; expires=Fri, 02 Jan 1970 00:00:00 GMT" ;
	return bool ;
}

function checkCookieDisk()
{
	var bool = false ;
	document.cookie = "ckdisk=; expires=Fri, 02 Jan 1970 00:00:00 GMT" ;
	var date = new Date() ;
	date.setFullYear(date.getFullYear()+1) ;
	document.cookie = "ckdisk=yes; expires="+date.toGMTString() ;
	bool = (document.cookie.indexOf("ckdisk=yes") != -1) ;
	document.cookie = "ckdisk=; expires=Fri, 02 Jan 1970 00:00:00 GMT" ;
	return bool ;
}

function getCookie(name)
{
	if (!name || !name.length) return "" ;
	var cookies = document.cookie ;
	var pattern = new RegExp("\s*"+name+"=([^;]*)") ;
	var matches = cookies.match(pattern) ;
	if (matches) return matches[1] ;
	return "" ;
}

// /Glycero cookie management
