﻿var Temp;
var TimerId = null;
var TimerRunning = false;
Seconds = 0
Minutes = 0
Hours = 0
function showtime() {
    if (Seconds >= 59) {
        Seconds = 0
        if (Minutes >= 59) {
            Minutes = 0
            if (Hours >= 23) {
                Seconds = 0
                Minutes = 0
                Hours = 0
            }
            else {
                ++Hours
            }
        }
        else {
            ++Minutes
        }
    }
    else {
        ++Seconds
    }
    if (Seconds != 1) { var ss = "s" } else { var ss = "" }
    if (Minutes != 1) { var ms = "s" } else { var ms = "" }
    if (Hours != 1) { var hs = "s" } else { var hs = "" }

    Temp = '已进行了：' + ((Hours < 10 ? "0" : "") + Hours) + ':' + ((Minutes < 10 ? "0" : "") + Minutes) + ':' + ((Seconds < 10 ? "0" : "") + Seconds);
    $('clock').set('html', Temp);
    $('usetime').set('value', Hours * 3600 + Minutes * 60 + Seconds);
    TimerId = setTimeout("showtime()", 1000);
    TimerRunning = true;
}
var TimerId = null;
var TimerRunning = false;
function stopClock() {
    if (TimerRunning)
        clearTimeout(TimerId);
    TimerRunning = false;
}
function startClock() {
    stopClock();
    showtime();
}
var changeTime = function(val) {
    location.href = "?tm=" + val;
}
var changeNav = function(v) {    
    var styleName = '';
    switch (v) {
        case 1:
            styleName = 'blue';
            break;
        case 2:
            styleName = 'yellow';
            break;
        case 3:
            styleName = 'green';
            break;
        case 4:
            styleName = 'pink';
            break;
        case 5:
            styleName = 'red';
            break;
        case 6:
            styleName = 'brown';
            break;
        default:
            styleName = 'blue';
            break;

    }
    var pObj = $$("#setStyle span")
    pObj.each(function(item) { item.removeClass('click'); });
    pObj[v].addClass('click');
    document.cookie = "chapterstyle=" + v + "; path=/;expires=Thursday,01-Jan-2099 00:00:00 GMT;"; ;
    $("FinalBox").set('class', styleName);
}
var inbj = function() {
    var cs = 1;
    try {
        cs = Cookie.read("chapterstyle");
        if (!cs) { cs = 1; }
        cs = parseInt(cs);
    }
    catch (e) {
        cs = 1;
    }
    changeNav(cs);
}
var Overlay = new Class({
    Implements: [Event, Options],
    options: {
        colour: "#000",
        opacity: 0.1,
        zIndex: 99,
        container: document.body,
        wid: "modal",
        onClick: new Class()
    },
    initialize: function(a) {
        this.setOptions(a);
        this.options.container = $(this.options.container);
        if ($(this.options.wid + "_mod")) {
            $(this.options.wid + "_mod").dispose();
            return false;
        }
        this.container = new Element("div", {
            id: this.options.wid + "_mod$",
            styles: {
                position: "absolute",
                left: "0px",
                top: "0px",
                width: "100%",
                height: Window.getScrollHeight() + "px",
                display: "none",
                overflow: "hidden",
                backgroundColor: this.options.colour,
                "z-index": this.options.zIndex
            }
        }).injectInside(this.options.container);

        this.iframe = new Element("iframe", {
            frameborder: "0",
            src: "/blank",
            styles: {
                position: "absolute",
                "z-index": 1,
                opacity: 0.1,
                filter: "progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=1)",
                width: "100%",
                height: "100%",
                top: 0,
                left: 0,
                scrolling: "no"
            }
        }).inject(this.container, "top");

        this.container.addEvent("click", function() {
            this.options.onClick()
        } .bind(this));

        this.fade = new Fx.Morph(this.container, { duration: 100 }).set({ opacity: 0 });

        window.addEvent("resize", this.position.bind(this));
    },
    position: function() {
        this.container.setStyles({ height: window.getScrollSize().y + "px" });
    },
    show: function() {
        this.fade.start({ opacity: [0, this.options.opacity], display: "block" });
    },
    hide: function() { this.container.destroy() }
});
function OnLogin() {
    var FrmBox = $('loginFrmBox');
    FrmBox.overlay = new Overlay({ container: document.body, wid: "box" });
    FrmBox.setStyle("top", (window.getScrollTop() + (window.getHeight() - 205) / 2) + "px");
    FrmBox.setStyle("left", (window.getScrollLeft() + (window.getWidth() - 324) / 2) + "px")
    FrmBox.setStyle('display', '');

    FrmBox.overlay.show();
    window.addEvent("scroll", function() {
        FrmBox.morph({
            top: (window.getScrollTop() + (window.getHeight() - 205) / 2) + "px"
        })
    });
    window.addEvent("resize", function() {
        FrmBox.morph({
            top: (window.getScrollTop() + (window.getHeight() - 205) / 2) + "px",
            left: (window.getScrollLeft() + (window.getWidth() - 324) / 2) + "px"
        });
    });

}
function userLogut() {
    var url = 'http://passport.ciwong.com/SignOut?reurl=' + escape(window.location.href);    
    if (confirm('是否确定退出系统？')) {
        window.location.href = url;
    }
}
function AutoLogin(userid, pass) {
    $("u").set('value', userid);
    $("p").set('value', pass);
    $("loginFrm").submit();
}
function checkLoginFrom(frm) {
    var uu = frm.uu.value.trim();
    if (uu == "") {
        alert("对不起，请填写您的用户帐号");
        frm.uu.focus();
        return false;
    }
    frm.u.value = uu;
    var pp = frm.pp.value;
    if (pp == "") {
        alert("对不起，请填写您的习网密码");
        frm.pp.focus();
        return false;
    }
    frm.p.value = pp;    
    return true;
}

function Boxclose() {
    $('loginFrmBox').setStyle('display', 'none');
    $('loginFrmBox').overlay.hide();
}