﻿var w = window, d = document;
Array.prototype.forEach = function (c) {
    for (var i = 0; i < this.length; i++) c.call(this[i], this[i], i);
}
Array.prototype.indexOf = function (c) {
    for (var i = 0; i < this.length; i++) if (this[i] == c) return i;
    return -1;
}
Array.prototype.remove = function (x) {
    var indx = this.indexOf(x);
    if (indx == -1) return this;
    return this.removeAt(indx);
}
Array.prototype.removeAt = function (from, to) {
    var rest = this.slice((to || from) + 1 || this.length);
    this.length = from < 0 ? this.length + from : from;
    return this.push.apply(this, rest);
}
String.prototype.toJSON = function () {
    if (this == null || this == undefined || this == "") return null;
    var strValue = this.replace("\r", "\\r").replace("\n", "\\n");
    return new Function("return " + strValue + ";")();
}
String.prototype.trim = function () {
    if (this == null || this == undefined || this == "") return this;
    return this.replace(/^\s+|\s+$/ig, "");
}
String.prototype.toDate = function () {
    var d = new Date(); try { d = Date.pause(this); } catch (e) { }
}
String.prototype.TryParseDate = function (df) {
    var dt = new Date();
    if (df == undefined) df = new Date();
    try {
        dt = Date.parse(this); if (dt instanceof Date) return dt;
    } catch (e) { }
    if (!(/^(\d|-|\/)*$/ig).test(this)) return df;
    var vl = this.split("-");
    if (vl.length < 3) return df;
    dt = new Date(parseInt(vl[0]), parseInt(vl[1]) - 1, parseInt(vl[2]));
    if (dt instanceof Date) return dt;
    return df;
}
Date.prototype.AddYear = function (num) {
    if (isNaN(num) || num == "" || num == null) num = 1; this.setYear(this.getFullYear() + num); return this;
}
Date.prototype.AddMonth = function (num) {
    if (isNaN(num) || num == "" || num == null) num = 1; this.setMonth(this.getMonth() + num); return this;
}
Date.prototype.AddDate = function (num) {
    if (isNaN(num) || num == "" || num == null) num = 1; this.setDate(this.getDate() + num); return this;
}
Date.prototype.getDays = function () {
    var d = new Date(this); d.setDate(1); d.setMonth(this.getMonth() + 1); d.setDate(0); return d.getDate();
}
Date.prototype.isLastDay = function () { var dt = new Date(this); return (dt.getDate() == dt.getDays()); }
Date.prototype.isToday = function () {
    var dt = new Date(); return (dt.getFullYear() == this.getFullYear() && dt.getMonth == this.getMonth() && dt.getDate() == this.getDate());
}
Date.prototype.getWeek = function (weekFirst) {
    ///<summary>
    /// 获取当前时间是一年中的第几周,默认从周一开始
    ///</summary>
    ///<param name="weekFirst">1:为周一开始,0:为周日开始</param>
    if (weekFirst == undefined) weekFirst = 1;
    var theDate = new Date(this.getFullYear(), this.getMonth(), this.getDate(), 24, 0, 0);
    var yDate = new Date(this.getFullYear(), 0, 1);
    var yDay = yDate.getDay();
    var day = theDate.getDay();
    if (weekFirst == 1) {
        if (day == 0) day = 7;
        if (yDay == 0) yDay = 7;
        if (yDay > 1) yDate = yDate.setDate(yDate.getDate() + (1 - yDay));
        if (day > 1) theDate = theDate.setDate(theDate.getDate() + (8 - day));
    } else {
        if (yDay > 0) yDate = yDate.setDate(yDate.getDate() - yDay);
        if (day > 0) theDate = theDate.setDate(theDate.getDate() + (7 - day));
    }
    return (theDate - yDate) / (24 * 60 * 60 * 1000) / 7;
}
Date.prototype.getQuarter = function () {
    var month = this.getMonth();
    return (month < 3 ? 1 : month < 6 ? 2 : month < 9 ? 3 : 4);
}
Date.prototype.Format = function (fmt) {
    var o = {
        "M+": this.getMonth() + 1, "d+": this.getDate(), "h+": this.getHours() % 12 == 0 ? 12 : this.getHours() % 12, //小时      
        "H+": this.getHours(), //小时      
        "m+": this.getMinutes(), //分      
        "s+": this.getSeconds(), //秒      
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度      
        "S": this.getMilliseconds() //毫秒      
    };
    var week = { "0": "\u65e5", "1": "\u4e00", "2": "\u4e8c", "3": "\u4e09", "4": "\u56db", "5": "\u4e94", "6": "\u516d" };
    if (/(y+)/.test(fmt)) {
        fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    }
    if (/(E+)/.test(fmt)) {
        fmt = fmt.replace(RegExp.$1, ((RegExp.$1.length > 1) ? (RegExp.$1.length > 2 ? "\u661f\u671f" : "\u5468") : "") + week[this.getDay() + ""]);
    }
    if (/(W+)/.test(fmt)) {
        fmt = fmt.replace(RegExp.$1, ((RegExp.$1.length > 1) ? (RegExp.$1.length > 2 ? "第" + this.getWeek() + "周" : this.getWeek() + "周") : this.getWeek()));
    }
    if (/(Q+)/.test(fmt)) {
        fmt = fmt.replace(RegExp.$1, ((RegExp.$1.length > 1) ? (RegExp.$1.length > 2 ? "第" + this.getQuarter() + "季度" : this.getQuarter() + "季") : this.getQuarter()));
    }
    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))); }
    }
    delete o, week;
    return fmt;
}
Date.prototype.getHoursString = function () {
    var hours = this.getHours();
    if (hours >= 0 && hours < 6) {
        return "凌晨";
    } else if (hours < 7) {
        return "清晨";
    } else if (hours < 9) {
        return "早上";
    } else if (hours < 12) {
        return "上午";
    } else if (hours < 14) {
        return "中午";
    } else if (hours < 18) {
        return "下午";
    } else if (hours < 19) {
        return "傍晚";
    } else {
        return "晚上";
    }
}
var dataCache =
{
    exists: function (key) { return (this[key] != undefined); },
    remove: function (key) { var obj = this[key]; if (obj != null) delete this[key]; },
    removeAll: function () { for (var n in this) { if (n != "exists" && n != "remove" && n != "removeAll") delete this[n]; } }
}
function ElementCollectionToArray(ems) { var es = []; if (ems) for (var i = 0; i < ems.length; i++) es.push(ems[i]); return es; }
function $G(objName) { if (objName) if (typeof (objName) != "object") objName = document.getElementById(objName); return objName; }
function $GV(objName) { var obj = $G(objName); return (obj != null ? obj.value : null); }
function $ts(tagName, o) { var ts = [], o = $G(o) || d; if (o) ts = ElementCollectionToArray(o.getElementsByTagName(tagName)); return ts; }
function $ns(name, o) { var ts = [], o = $G(o) || d; if (o) ts = ElementCollectionToArray(o.getElementsByName(name)); return ts; }
function $rd(o) { o = $G(o); if (o.parentNode == undefined || o.parentNode == null) delete o; else o.parentNode.removeChild(o); }
function $att(o, opt) {
    o = $G(o); if (o && opt) for (var n in opt) try { o[n] = opt[n]; } catch (e) { try { o.setAttribute(n, opt[n]); } catch (e) { } };
}
function $C(tagName, options) {
    if (options == undefined || options == null || options == "") options = {};
    if (tagName == undefined || tagName == null || tagName == "") return options;
    var obj = document.createElement(tagName); $att(obj, options);
    return obj;
}

function re(e, f, o) {
    ///<summary>
    ///事件注册
    ///</summary>
    o = $G(o) || document, e = e.split(",");
    if (o == undefined || o == null) return;
    var fun = function () { return f.apply(o, arguments); };
    e.forEach(function (e) {
        e = e.replace(/^on/ig, "");
        if (window.attachEvent) o.attachEvent("on" + e, fun);
        else o.addEventListener(e, fun, false);
    });
}
function setCookie(name, value, dates, path, domain) {
    var exp = null
    if (!isNaN(dates)) {
        exp = new Date();
        exp.setTime(exp.getTime() + dates * 24 * 60 * 60 * 1000);
    }
    var cookieString = [name + "=" + escape(value)];
    if (exp != null) cookieString.push("expires=" + exp.toGMTString());
    if (path && path.length > 0) cookieString.push("path=" + escape(path));
    if (domain && domain.length > 0) cookieString.push("domain=" + escape(domain));
    document.cookie = cookieString.join(";");
}
function getCookie(name) {
    var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
    if (arr != null) return unescape(arr[2]); return null;
}
function SetCheckBoxsEvent(everySelector, allSelector, event) {
    var _self = this;
    this.SelectClick = function () {
        var cbs = $(everySelector);
        var cbd = 0;
        for (var i = 0; i < cbs.length; i++) {
            if (cbs[i].checked) cbd++;
        }
        $(allSelector).each(function () {
            this.checked = cbs.length == cbd;
        });
        if (event != undefined) {
            if (event instanceof Array) {
                for (var i = 0; i < event.length; i++) {
                    event[i].call(this, cbd > 0, cbd, cbs);
                }
            } else event.call(this, cbd > 0, cbd, cbs);
        }
    }
    this.SelectAll = function () {
        var cbs = $(everySelector);
        for (var i = 0; i < cbs.length; i++) {
            cbs[i].checked = this.checked;
        }
        _self.SelectClick();
    }
    $(document).ready(function () {
        $(everySelector).each(function (index, domEle) {
            $(domEle).bind("click", _self.SelectClick);
        });
        $(allSelector).each(function (index, domEle) {
            $(this).bind("click", _self.SelectAll);
        });
        _self.SelectClick();
    });
}

var Query = {};
var sl = window.location.search;
if (sl.length > 0) sl = sl.substring(1);
sl = sl.split("&");
if (sl.length > 0) {
    for (var i = 0; i < sl.length; i++) {
        var ql = sl[i].split("=");
        var vl = ql;
        if (ql.length > 1) try { vl = decodeURIComponent(ql[1]); } catch (e) { vl = ql[1]; }
        Query[ql[0]] = vl;
    }
}
function Include(url, callback) {
    if (url == null || url == "" || url == undefined) return;
    var t = "js";
    if (url.lastIndexOf(".") > 0) t = url.substring(url.lastIndexOf(".") + 1);
    var obj = null;
    if (document.readyState == "complete") {
        if (t.toLowerCase() == "css") {
            obj = $C("link", { type: 'text/css', rel: 'stylesheet', href: url })
        } else {
            obj = $C("script", { type: 'text/javascript', scr: url });
        }
        if (callback != null && callback != undefined) {
            obj.onreadystatechange = function () {
                if (obj.readyState == "complete") {
                    callback.call(obj);
                }
            }
        }
        document.getElementsByTagName("head")[0].appendChild(obj);
    } else {
        var cb = "";
        if (callback != null && callback != undefined) cb = " onload=\"" + callback.toString().replace("\"", "\\\"") + "\" ";
        if (t.toLowerCase() == "css") {
            document.writeln("<link href=\"" + url + "\" rel=\"stylesheet\"  type=\"text/css\" " + cb + "/>");
        } else {
            document.writeln("<script type=\"text/javascript\" src=\"" + url + "\" " + cb + "></script>");
        }
    }
}
var nuag = navigator.userAgent.toLowerCase(), isIE = nuag.indexOf("msie") != -1, isIE6 = (isIE && nuag.indexOf("msie 6") != -1);
function myEvent() {
    var o = { ns: {} };
    o.add = function (name, obj) {
        if (!obj) obj = name;
        if (typeof (name) != 'string') name = name.toString().replace(" ", "");
        o.ns[name] = obj;
    }
    o.remove = function (name) {
        if (typeof (name) != 'string') name = name.toString().replace(" ", "");
        delete o.ns[name];
    }
    o.active = function (obj) {
        for (var n in o.ns) o.ns[n].apply(obj, arguments);
    }
    return o;
}
function selectList(elementsId, getChildNodeList, initOptions, changeEvent,defaultValues) {
    var o = { showFields: ["text", "value"], controls: elementsId, getFunc: getChildNodeList, initOptions: 1, changeEvent: new myEvent() };
    if (changeEvent != undefined) o.changeEvent.add(changeEvent);
    initOptions = initOptions.toString();
    if (initOptions != null && initOptions != "" && !isNaN(initOptions)) o.initOptions = parseInt(initOptions);
	o.getSelectValue = function(obj,index)
	{
		if(defaultValues != undefined && defaultValue != null && defaultValue != "" && defaultValue.length > index)
		{
			return defaultValues[index];
		}
		return obj.getAttribute("selectValue");
	}
    o.bindData = function (obj, sid, index) {
        var list = [];
        if (index > 0 && $G(o.controls[index - 1]).selectedIndex < o.initOptions) {
        } else{
			 list = this.getFunc.call(this, sid,obj,index);
		}
        var text = this.showFields[0], value = this.showFields[1];
		if(list == undefined || list == "" || list ==null) list = [];
        for (var i = 0; i < list.length; i++) {
            var selectValue = this.getSelectValue(obj,index), isSelected = false;
            if (selectValue == null || selectValue == undefined) selectValue = obj.getAttribute("value");
            isSelected = selectValue == list[i][value];
            obj.appendChild($C("option", { innerHTML: list[i][text], text: list[i][text], value: list[i][value], selected: isSelected }));
        }
        this.onchange(index);
    }
    o.onchange = function (index) {
        var obj = $G(o.controls[index]);
        o.changeEvent.active(obj, index);
        if (index >= o.controls.length - 1) return;
        var child = $G(o.controls[index + 1]);
		if(child == null)return;
        while (child.options.length > initOptions) child.remove(initOptions);
        o.bindData(child, obj.value, index + 1);
    }
    o.init = function () {
        var obj = $G(this.controls[0]);
        this.controls.forEach(function (e, i) {
            re("change", function () { o.onchange(i); }, e);
        });
        this.bindData(obj, -1, 0);
    }
    if (document.readyState == "complete" || document.readyState == "loaded") { o.init(); } else {
        re("load", function () { o.init(); }, w);
    }
	return o;
}
function setSelectListValue() {
    var sl = document.getElementsByTagName("select");
    var original;
    for (var i = 0; i < sl.length; i++) {
        var vl = sl[i].getAttribute("selectedValue");
        if (vl == null || vl == undefined) vl = sl[i].getAttribute("value");
        if (vl != undefined && vl != null && vl != "" && sl[i].options.length > 0) {
            original = (sl[i].selected == -1 ? 0 : sl[i].selected);
            sl[i].value = vl;
            if (sl[i].selectedIndex == -1) sl[i].selectedIndex = original;
        }
    }
}
function setSelectAllBox() {
    var btns = document.getElementsByName("selectAll");
    for (var i = 0; i < btns.length; i++) {
        re("click", function () {
            var sbtn = document.getElementsByName(this.value);
            for (var j = 0; j < sbtn.length; j++) {
                if (sbtn[j].type == "checkbox") sbtn[j].checked = this.checked;
            }
        }, btns[i]);
    }

}
re("load", function () {
    setSelectListValue();
    setSelectAllBox();
}, window);


/******************** 
函数名称：IsTelephone 
函数功能：固话，手机号码检查函数，合法返回true,反之,返回false 
函数参数：obj,待检查的号码 
检查规则： 
(1)电话号码由数字、"("、")"和"-"构成 
(2)电话号码为3到8位 
(3)如果电话号码中包含有区号，那么区号为三位或四位 
(4)区号用"("、")"或"-"和其他部分隔开 
(5)移动电话号码为11或12位，如果为12位,那么第一位为0 
(6)11位移动电话号码的第一位和第二位为"13" 
(7)12位移动电话号码的第二位和第三位为"13" 
********************/
function IsTelephone(obj)// 正则判断
{
    var pattern = /(^[0-9]{3,4}\-[0-9]{3,8}$)|(^[0-9]{3,8}$)|(^\([0-9]{3,4}\)[0-9]{3,8}$)|(^0{0,1}1[0-9]{10}$)/;
    if (pattern.test(obj)) {
        return true;
    }
    else {
        return false;
    }
}
function tbData(sd, vd) {
    ///<summary>
    ///连动值
    ///</summary>
    if ($G(sd) == null || $G(vd) == null) return;
    var func = function () {
        $G(vd).value = $G(sd).value;
    }
    re("change", func, sd);
    re("input", func, sd);
    re("propertychange", func, sd);
}
function getFuncName(func) {
    var funString = func.toString();
    var funcName = func.toString().substring(funString.indexOf("function") + 8, funString.indexOf("(")).trim();
    if (funcName == "") {
        var code = Math.round(Math.random() * 10000);
        window["Temp_Func_" + code] = func;
        return "Temp_Func_" + code;
    }
    return funcName;
}
function reXObjEvent(eventName, objId, func) {
    ///<summary>
    /// 注册控制事件
    ///</summary>
    //<param name="eventName">事件名称</param>
    if (!func) return;
    var strFuncString = (typeof (func) == "string" ? func : getFuncName(func));
    var html = '<script type="text/javascript" for="' + objId + '" event="' + eventName + '()">' +
        strFuncString + ".apply(this,arguments);" +
        '<\/script>';
    if (document.readyState == "complete") {
        var obj = document.createElement("div");
        obj.innerHTML = html;
        document.body.appendChild(obj);
    } else {
        document.writeln(html);
    }
}
function cacheEvent(e) {
    ///<summary>
    ///取消事件的传播
    ///</summary>
    e = e || window.event;
    if (!e) return;
    e.returnValue = false;
    if (e.stopPropagation) e.stopPropagation();
    if (e.preventDefault) e.preventDefault();
    if (!e.cancelBubble) e.cancelBubble = true;
}
