﻿
function CreatCssLink(style, src, head) {
    var headID = document.getElementsByTagName("head")[head];
    var newCss = document.createElement('link');
    var newsrc = src.replace("\./css\/", "\./css" + style + "\/");
    newCss.type = 'text/css';
    newCss.rel = "stylesheet";
    newCss.href = newsrc;
    headID.appendChild(newCss);
}

function CreatCssLink2(style, src, head) {
    var headID = document.getElementsByTagName("head")[head];
    var newCss = document.createElement('link');
    newCss.type = 'text/css';
    newCss.rel = "stylesheet";
    newCss.href = src;
    headID.appendChild(newCss);
}

function GetCookie() {
    var cookieStyle = readCookie("GPMstyle");
    var cookieFont = readCookie("GPMfont");
    setActiveStyleSheet(cookieStyle);
    setActiveStyleFont(cookieFont);
}

function createCookie(c_name, value)   // c_name: cookie name, value: cookie value, expiredays: cookie 有效天數 
{
    var expiredays = 365;
    var exdate = new Date()                        // 宣告 exdate
    exdate.setDate(exdate.getDate() + expiredays)  // 將 exdate 設成今天加上過期天數
    document.cookie = c_name + "=" + escape(value) + ";expires=" + exdate.toGMTString()  // 產生 cookie 內容  c_name=escape(value);expires=exdate
}

function DeleteCookie(c_name) {
    var expiredays = 365;
    var exdate = new Date()
    exdate.setDate(exdate.getDate() - expiredays)
    document.cookie = c_name + "=" + escape(0) + ";path=/" + ";domain=" + location.host + ((expiredays == null) ? "" : ";expires=" + exdate.toUTCString());
}

//function createCookie(c_name, value) {
//    alert(value);
//    var expiredays = 365;
//    var exdate = new Date()
//    exdate.setDate(exdate.getDate() + expiredays)
//    document.cookie = c_name + "=" + escape(value) + ";path=/" + ";domain=" + location.host + ((expiredays == null) ? "" : ";expires=" + exdate.toUTCString());
//    alert(document.cookie);
//}

function readCookie(c_name) {
    var cookieValue = null;
    var search = c_name + "=";
    if (document.cookie.length > 0) {
        offset = document.cookie.indexOf(search);
        if (offset != -1) {
            offset += search.length;
            end = document.cookie.indexOf(";", offset);
            if (end == -1) end = document.cookie.length;
            cookieValue = unescape(document.cookie.substring(offset, end))
        }
    }
    return cookieValue;
}

//function readCookie(c_name) {
//    if (document.cookie.length > 0) {
//        var c_list = document.cookie.split("\;");
//        for (i in c_list) {
//            var cook = c_list[i].split("=");
//            if (cook[0] == c_name) {
//                return unescape(cook[1]);
//            }
//        }
//    }
//}

