﻿Date.prototype.FormatDate = function(fmt) {
    //author: meizz 
    var o =
    {
        "M+": this.getMonth() + 1, //月份 
        "d+": this.getDate(), //日 
        "h+": this.getHours(), //小时 
        "m+": this.getMinutes(), //分 
        "s+": this.getSeconds(), //秒 
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度 
        "S": this.getMilliseconds() //毫秒 
    };
    if (/(y+)/.test(fmt))
        fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
        if (new RegExp("(" + k + ")").test(fmt))
        fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}


HoriseCommon = new function() {
    this.$ = function() { if (document.getElementById) { return eval('document.getElementById("' + id + '")') } else { return eval('document.all.' + id) } };

    this.LoadScript = function(url) {
        document.write('<script type="text/javascript" src="' + url + '"><\/script>');
    }
    this.ConvertJSONDateToJSDateObject = function(JSONDateString) {// Convert JSON date
        //var date = new Date(parseInt(JSONDateString.replace("/Date(", "").replace(")/", ""), 10));
        //var JSONDateString = '/Date(1233323754523+0100)/'
        var date = new Date(parseInt(/\/Date\((\d+).*/.exec(JSONDateString)[1]))

        return date.FormatDate("yyyy-MM-dd");
    }
    this.getsec = function(str) {
        var str1 = str.substring(1, str.length) * 1;
        var str2 = str.substring(0, 1);
        if (str2 == "s") {
            return str1 * 1000;
        } else if (str2 == "m") {
            return str1 * 60 * 1000;
        } else if (str2 == "h") {
            return str1 * 60 * 60 * 1000;
        } else if (str2 == "d") {
            return str1 * 24 * 60 * 60 * 1000;
        }
    }
    this.setCookie = function(name, value, time) {//time: d，day.h,hour.s,second
        var strsec = this.getsec(time);
        var exp = new Date();
        exp.setTime(exp.getTime() + strsec * 1);
        document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
    }
    this.getCookie = function(name) {
        var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
        if (arr = document.cookie.match(reg)) return unescape(arr[2]);
        else return null;
    }

    this.clearClass = function(id, count) {
        for (var i = 1; i <= count; i++) {
            this.$(id + i).style.display = 'none';
            this.$('tagName_' + id + i).className = '';
        }
    }

    this.switchTag = function(id, num, count, cssName) {
        this.clearClass(id, count);
        this.$('tagName_' + id + num).className = cssName;
        this.$(id + num).style.display = '';
    }

}
