﻿function getHost() {
    var nohttp = window.location.href.split('//')[1];
    var hostPort = nohttp.split('/');
    var pagename = hostPort[hostPort.length - 1];
    return pagename.replace("#", "");
}
// 2009.12.07 美虹要求 要直接切換到首頁就好
function SwitchTemple(v) {
    var pagename = getHost();
    var Templt = GetCookie("WebStyle");
    var Path = location.protocol + "//" + location.host ;
    
    if (v == 'y') {
        if (Templt == null || Templt != "young") SetCookie("young");

//        if (pagename.toLowerCase() == "relatedwebsite.aspx") {
//            location.href = "RelatedWebsite_Y.aspx";
//            return;
//        }   
//        if (pagename.length == 0 || pagename.toLowerCase() == "index.aspx")
        location.href = Path + "/Index_Y.aspx";
//        else
//            location.reload();
    }
    else {
        DeleteCookie();

//        if (pagename.toLowerCase() == "relatedwebsite_y.aspx") {
//            location.href = "RelatedWebsite.aspx";
//            return;
//        }  
//        if (pagename.length == 0 || pagename.toLowerCase() == "index_y.aspx")
        location.href = Path + "/Index.aspx";
//        else
//            location.reload();
    }
}
function SetCookie(value) {
    var d = new Date();
    d.setDate(d.getDate() + 7);
    document.cookie = "WebStyle=" + value + "; expires=" + d.toGMTString() + "; path=/;";
}
function GetCookie(name) {

    var start = document.cookie.indexOf(name + "=");
    var len = start + name.length + 1;
    if ((!start) && (name != document.cookie.substring(0, name.length))) {
        return null;
    }
    if (start == -1) return null;
    var end = document.cookie.indexOf(";", len);
    if (end == -1) end = document.cookie.length;
    return unescape(document.cookie.substring(len, end));
}
function DeleteCookie() {
    var d = new Date();
    d.setDate(d.getDate() + 7);
    document.cookie = "WebStyle=; expires=" + d.toGMTString() + "; path=/;";
}
function ShowTemple() {
    var Templt = GetCookie("WebStyle");
    if (Templt != null && Templt == "young") {
        location.href = "Index_Y.aspx";
    }
}
function AddFavorite(temple) {
    if (temple == "n") {
        if (document.all)
            window.external.AddFavorite('http://law.moj.gov.tw', '全國法規資料庫');
        else
            window.sidebar.addPanel('全國法規資料庫', 'http://law.moj.gov.tw', '');
    }
    else {
        if (document.all)
            window.external.AddFavorite('http://law.moj.gov.tw/Index_Y.aspx', '全國法規資料庫 青少年版');
        else
            window.sidebar.addPanel('全國法規資料庫 青少年版', 'http://law.moj.gov.tw/Index_Y.aspx', '');
    }
}
