﻿;(function() {
//声明一个名称空间,对象

var cits = {};

    /*功能：清除文本框默认文字
	 *initValue:默认表单元素的值
	 *id：表单元素的id
	 */
    cits.initValue = function(initValue, id) {
		if(typeof initValue !="string"){
			 throw "initValue必须是一个字符串";
		 }
        $("#" + id).focus(function() {
			$(this).css({ color: "#333", border: "1px #71716E solid" });
            if (initValue == $(this).val()) {
                $(this).val("");
            }

        }).blur(function() {
			 $(this).css("border","1px #e2dea4 solid")
            if ($(this).val() == "") {
                $(this).val(initValue);
				$(this).css("color","#cfcaca");
            }
        });
    }
	/*
	 *功能：表格变色
	 *oTable：表格元素的ID，或者类别注意别漏掉"#","."
	 *sColor:  行应用的样式类别
	 */
	cits.tableHoverColor=function(oTable,sColor){
		$(oTable).find("tr:gt(0)").hover(function(){
	         $(this).addClass(sColor);									
		},function(){
			  $(this).removeClass(sColor);	
		});
		
	}
	/*
	 *tablist:菜单项容器ID
	 *tabcon：菜单对应的内容容器ID
	 *num:是点击还是移动触发
	 */
cits.tabmenu=function(tablist,tabcon,num){
	$("#"+tabcon+">div:gt(0)").hide();  //默认显示第一个菜单内容
	switch(num){
		case 1:
				$("#"+tablist).find("li").click(function(){
					var menu_list=$("#"+tablist).find("li")	;									 
					var tabindex=menu_list.index(this);
					$(this).addClass("selected").siblings().removeClass("selected");
					$("#"+tabcon+">div").eq(tabindex).show().siblings().hide()
				});
		break;
		case 2:
		$("#"+tablist).find("li").mouseover(function(){
					var menu_list=$("#"+tablist).find("li")	;									 
					var tabindex=menu_list.index(this);
					$(this).addClass("selected").siblings().removeClass("selected");
					$("#"+tabcon+">div").eq(tabindex).show().siblings().hide()
				});
		break;
	}
}
cits.RegCkElement=function(a, b, c, d, e, f) {
    var g = document.getElementById(a);
    if (!g) return false;
    if (typeof dfstr != "string") dfstr = "";
    if (typeof f != "boolean") f = true;
    if (typeof g.value == "string" && g.value.replace(/\s*/g, "") != "" && g.value != dfstr) {
        if (typeof c == "string") {
            var h = eval(c);
            var i = h.test(g.value);　
            if (!i) {
                if (typeof b == "string") {
                    this.ShowE(a, b, e)
                }
                if (f) FocusE(g);
                return false
            }
        }
        return true
    }
    if (typeof b == "string") {
        this.ShowE(a, b, e)
    }
    if (f) FocusE(g);
    return false
};
cits.IsEmptyOrNotNum=function(a, b, c, d, e) {
    var f = document.getElementById(a);
    if (!f) return false;
    if (typeof dfstr != "string") dfstr = "";
    if (typeof e != "boolean") e = true;
    if (typeof f.value == "string" && f.value.replace(/\s*/g, "") != "" && f.value != c) {
        if (isNaN(f.value)) {
            if (typeof b == "string") {
                this.ShowE(a, b, d)
            }
            if (e) this.FocusE(f);
            return false
        }
        return true
    }
    if (typeof b == "string") {
        this.ShowE(a, b, d)
    }
    if (e) this.FocusE(f);
    return false
}
cits.StrIsNullOrEmpty=function(a, b, c, d, e) {
    var f = document.getElementById(a);
    if (!f) return false;
    if (typeof dfstr != "string") dfstr = "";
    if (typeof e != "boolean") e = true;
    if (typeof f.value == "string" && f.value.replace(/\s*/g, "") != "" && f.value != c) {
        return true
    }
    if (typeof b == "string") {
        this.ShowE(a, b, d)
    }
    if (e) this.FocusE(f);
    return false
}
cits.FocusE=function(e) {
    if (e) {
        if (e.getAttribute("visible") == "true" || e.style.display != "none") {
            e.focus()
        }
    }
};
cits.ShowE=function(a, b, c) {
    var d;
    d = document.getElementById(c);
    if (d) {
        d.style.display = "";
        d.innerHTML = b
    } else {
        b = this.AddArrowhtml(b);
        this.OpenMsg(a, b)
    }
};
cits.AddArrowhtml=function(s) {
    return s + "<div class='arrowDown'><img src='/image/pic/whiteArrow.png'/></div>"
}
cits.OpenMsg=function(e, a) {
    if (typeof e != "string") return;
    var b,
    ele;
    ele = $("#" + e);
    b = ele.offset();
    this.appDivCke(b.top - 24, b.left, e + "ediv", a, "arrowDownTest");
    ele.one("blur", 
    function() {
        $("#" + e + "ediv").replaceWith()
    })
};
cits.appDivCke=function(t, l, n, a, b) {
    $("body").prepend("<div class='" + b + "' style='top:" + t + "px;left:" + l + "px;' id='" + n + "'>" + a + "</div>")
}
cits.isTravelDate=function(a, b, c, d, e, f) {
    var g = document.getElementById(a);
    var h = document.getElementById(b);
    if (!g) return false;
    if (!h) return false;
    if (typeof dfstr != "string") dfstr = "";
    if (typeof f != "boolean") f = true;
    if (this.isValidTravelDate(g.value, h.value)) {
        return true
    }
    if (typeof c == "string") {
        this.ShowE(a, c, e)
    }
    if (f) this.FocusE(g);
    return false
}
cits.isValidTravelDate=function(a, b) {
    var a = a.replace(/(^\s+|\s+$)/g, '');
    var b = b.replace(/(^\s+|\s+$)/g, '');
    if (a == "" || b == "") {
        return false
    }
    var c = this.StrToDate(a);
    var d = this.StrToDate(b);
    if (c == false || d == false) {
        return false
    } else {
        var e = new Date();
        if (this.DateDiff('d', e, c) < 0) {
            return false
        }
        if (this.DateDiff('d', c, d) <= 0) {
            return false
        }
        return true
    }
}
cits.isDate=function(a) {
    var r = a.match(/^(\d{1,2})(-|\/)(\d{1,2})\2(\d{1,4})$/);
    if (r == null) return false;
    var d = new Date(r[4], r[1] - 1, r[3]);
    return (d.getFullYear() == r[4] && (d.getMonth() + 1) == r[1] && d.getDate() == r[3])
}
cits.StrToDate=function(a) {
    if (isDate(a)) {
        var r = a.match(/^(\d{1,2})(-|\/)(\d{1,2})\2(\d{1,4})$/);
        return new Date(r[4], r[1] - 1, r[3])
    } else {
        return false
    }
}
cits.DateDiff=function(a, b, c) {
    switch (a) {
    case 's':
        return parseInt((c - b) / 1000);
    case 'n':
        return parseInt((c - b) / 60000);
    case 'h':
        return parseInt((c - b) / 3600000);
    case 'd':
        return parseInt((c - b) / 86400000);
    case 'w':
        return parseInt((c - b) / (86400000 * 7));
    case 'm':
        return (c.getMonth() + 1) + ((c.getFullYear() - b.getFullYear()) * 12) - (b.getMonth() + 1);
    case 'y':
        return c.getFullYear() - b.getFullYear()
    }
}
    window["cits"] = cits;

})();
