/*==================================/
*
*功能：
* 通过取在Cookie中的用户样式设置
* 给主页面加载不同的样式文件
*
*郭翔，2003-10
===================================*/

//按照用户的需要设置样式文件
if(document.all["mainStyle"])
{
	switch (getCookie("userStyle"))
	{
		case "yellow":
				document.all["mainStyle"].href = "http://" + window.location.host + "/TextBook/css/mainYellow.css";
			break;
		case "blue":
				document.all["mainStyle"].href = "http://" + window.location.host + "/TextBook/css/mainBlue.css";
			break;
		case "green":
				document.all["mainStyle"].href = "http://" + window.location.host + "/TextBook/css/mainGreen.css";
			break;
		case "navy":
				document.all["mainStyle"].href = "http://" + window.location.host + "/TextBook/css/mainNavy.css";
			break;
		default:
				document.all["mainStyle"].href = "http://" + window.location.host + "/TextBook/css/mainNavy.css";
	}
}

//获取用户存放在cookie中的样式
function getUserStyle()
{	
	return getCookie("userStyle");
}

//取cookie的内容
function getCookieVal (offset) 
{
    var endstr = document.cookie.indexOf (";", offset);
    if (endstr == -1)
        endstr = document.cookie.length;
    return unescape(document.cookie.substring(offset, endstr));
}

//获取指定cookie的值
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;
}

//保存cookie
function setCookie (name, value, expires, path, domain, secure) 
{
    document.cookie = name + "=" + escape (value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

//使cookie过期（删除）
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";
    }
}
