﻿var _gCookieCss = GetCookie('css');
setstyle(_gCookieCss);

var style_offset = (_gCookieCss != "pink");
function switchstyle(obj) {
    if (style_offset) {
        setstyle("pink");
        style_offset = false;
        obj.innerHTML = "返回默认";
    } else {
        setstyle("black");
        style_offset = true;
        obj.innerHTML = "女性专版";
    }
}

function setstyle(c) {
    switch (c) {
        case "black":
            var color = 'css';
            var imgpath = 'img';
            break;
        case "pink":
            var color = 'pink_css';
            var imgpath = 'pink_img';
            break;
        default: return;
    }
    //alert(color);
    var linktag = document.getElementsByTagName('link');
    var csstag = [];
    for (var i = 0; i < linktag.length; i++) {
        if (linktag[i].getAttribute('rel').indexOf('stylesheet') != -1) {
            csstag.push(linktag[i]);
        }
    }
    for (var i = 0; i < csstag.length; i++) {
        csstag[i].href = csstag[i].href.replace(/(.*)\/\w+?\/(.+?\.css)/, "$1/" + color + '/$2');
        //alert(csstag[i].href)
    }
    var imgicon = document.images;
    for (var i = 0; a = imgicon[i]; i++) {
        if (a.src.indexOf('img/') > -1 || a.src.indexOf('Img/') > -1) {
            a.src = a.src.replace(/[^\/]*img\//i, "/" + imgpath + '/');
        }
    }
    SetCookie('css', c);
}

function SetCookie(n, d) {
    var expTime = new Date(new Date().setDate(new Date().getDate() + 500));
    document.cookie = n + "=" + escape(d) + "$$; expires=" + expTime.toGMTString() + "; path=/";
}

function GetCookie(n) {
    var cookiesAll = document.cookie;
    var cookiesStart = cookiesAll.indexOf(n + "=");
    var cookiesEnd = cookiesAll.indexOf("$$", cookiesStart);
    var cookien = unescape(cookiesAll.substring(cookiesStart + n.length + 1, cookiesEnd));
    return cookien;
}

function setUserCity(obj) {
    //Need to include jQuery.Cookie plugin first.
    var area = $(obj).attr("val");
    $.cookie("UserCurrentInfo", "Area", area, null);
    $("#gotoAreadiv > a").after(" (正在加载中...) ");
    window.location.reload();
}
var __gCookieArea = $.cookie("UserCurrentInfo", "Area");
$(document).ready(function() {
    if (__gCookieArea == null) {
        $.cookie("UserCurrentInfo", "Area", "P01", null);
        __gCookieArea = "P01";
    }
    var b = $(".butold", ".topinfo");
    $("a", "#gotoCitydiv").each(function() {
        var t = $(this);
        if (__gCookieArea == t.attr("val")) {
            t.css("color", "red");
            b.html("(" + t.html() + ")");
        }
    });
});

//---显示切换城市用---
function POPUP(divID, W, H) {
    screenDiv = document.createElement("div");
    screenDiv.style.cssText = "position:absolute;width:100%;background:white;top:0;filter: Alpha(Opacity=70);Opacity:0.7;height:" + (document.body.scrollHeight + 10) + "px";
    shadowDiv = document.createElement("div");
    document.body.appendChild(screenDiv);
    shadowDiv.style.cssText = "position:absolute;filter: Alpha(Opacity=95);Opacity:0.95;background:gray;width:" + W + "px;height:" + H + "px;left:" + (parseInt(screenDiv.offsetWidth) / 2 - (W / 2)) + "px;top:" + ((document.documentElement.clientHeight / 10)) + "px;";
    screenDiv.appendChild(shadowDiv);
    datDiv = document.getElementById("gotoArea");
    datDiv.style.cssText = "display:block;z-index:2000;margin:-3px 0 0 -3px;width:" + (W - 7) + "px;height:" + (H - 7) + "px;left:" + shadowDiv.style.left + ";top:" + shadowDiv.style.top;
}
function ClosePOP() {
    document.body.removeChild(screenDiv);
    datDiv.style.display = "none"
}
function toOpen() {
    var url = window.location.href;
    url = url.replace("?", "[Wen]");
    url = url.replace("&", "[And]");
    var headUrl = "";
    window.open("/Zone/BugSubmit.aspx?url=" + url, 'newwindow', 'height=400, width=800,  top:' + (screen.availHeight - 400) / 2 + ',left=' + (screen.availWidth - 800) / 2 + ', toolbar=no, menubar=no, scrollbars=no, resizable=no,location=n o, status=no');
}