﻿
var _popup;
var _url;
function OpenPopup(popup, url, header, width, height)
{
    popup.Show();
    popup.SetHeaderText(header);
    popup.SetFooterText("正在加载...");
    
    if (popup.IsVisible) {
        _popup = popup;
        _url = url;
        setTimeout("OperPopupShow();", 200);
    }
    
}
function OperPopupShow()
{
    _popup.SetContentUrl(_url);
}

function SetPopupFooter(popup, str)
{
    if (popup)
        popup.SetFooterText(str);
}

function SetPopupHide(popup)
{
    if (popup)
        popup.Hide();
}

function Jet_Open(url, obj, width, height) {
    var str = 'dialogWidth:' + width + 'px; dialogHeight:' + height + 'px; status:0;';
    showModalDialog(url, obj, str);
}

function Jet_OpenWin(url, name, width, height) {
    var ow = window.open(url, name, 'status=yes,scrollbars=yes,resizable=yes,width=' + width + ',height=' + height);
    ow.focus();
}

function Jet_Checkbox(c) {
    var checkid = $(".checkid");
    if (typeof(c) == 'undefined') {
        for (var i = 0; i < checkid.length; i++)
            if (checkid[i].checked)
                checkid[i].checked = false;
            else
                checkid[i].checked = true;
    }
    else {
        for (var i = 0; i < checkid.length; i++)
            checkid[i].checked = c;
    }
}

function Jet_CheckboxSelect(css)//list_checked
{
    var checkid = $(".checkid");
    var td, tr;

    for (var i = 0; i < checkid.length; i++) {
		td = $(checkid[i]).attr("parentNode");
		tr = $(td).attr("parentNode");
        if (checkid[i].checked)
            $(tr).addClass(css);
        else
            $(tr).removeClass(css);
    }
}

function Jet_CheckboxClick(css)
{
	$(".checkid").click(function(){
		var td = $(this).attr("parentNode");
		var tr = $(td).attr("parentNode");

 		if ($(this).attr("checked"))
 		    $(tr).addClass(css);
 		else
 		    $(tr).removeClass(css);
	});
}

function Jet_CheckboxGetId() {
    var idlist = '';
    var checkid = $(".checkid");

    for (var i = 0; i < checkid.length; i++) {
        if (checkid[i].checked) {
            if (idlist == '')
                idlist = checkid[i].value;
            else
                idlist = idlist + ',' + checkid[i].value;
        }
    }
    
    return idlist;
}

function Jet_DataTableCss(obj, css)//list_over
{
	for(var i = 0; i < obj.length; i++){
		$(obj[i]).mouseover(function(){
		    $(this).addClass(css);
		});
	
		$(obj[i]).mouseout(function(){
		    $(this).removeClass(css);
		});
	}
}

function Jet_DataTableCssOverOut(obj, over, out) {
    for (var i = 0; i < obj.length; i++) {
        $(obj[i]).addClass(out);
        $(obj[i]).mouseover(function() {
            $(this).addClass(over);
            $(this).removeClass(out);
        });

        $(obj[i]).mouseout(function() {
            $(this).addClass(out);
            $(this).removeClass(over);
        });
    }
}

// 输入数据检测
function InputNum() {
	if (window.event.keyCode==13||window.event.keyCode ==27){
		window.event.keyCode=0;
	}
	else if (window.event.keyCode<48||window.event.keyCode>57) {
		if (window.event.keyCode != 46)
			window.event.keyCode=0;
	}
}

function Jet_Redirect(url)
{
    if (url != '')
        self.location.href = url;
}

function Jet_CheckIKey(obj)
{
	SerialNumber = obj.getSerialNumber();

	if (SerialNumber == "") {
		alert("请插入iKey加密狗！");
		return false;
	}
	
	return true;
}




function CheckND(sType, obj, str) {

		obj.value = obj.value.trim();
		
		if (sType == '必填项') {
			if (obj.value == '') { alert(str); obj.select(); return false; }
		}
	
		if (obj.value == '') return true;
	
	if (sType == '日期') {
		if (CheckDate(obj.value) == 0) { alert(str); obj.select(); return false; }
	}
	else if (sType == '数字') {
		if (isNaN(Math.abs(obj.value))) { alert(str); obj.select(); return false; } 
	}
	else if (sType == '正数') {
		if (isNaN(Math.abs(obj.value))) { alert(str); obj.select(); return false; }
		if (obj.value.indexOf('-') >= 0 || Math.abs(obj.value) == 0) { alert(str); obj.select(); return false; }
	}
	else if (sType == '整数') {
		if (isNaN(Math.abs(obj.value))) { alert(str); obj.select(); return false; }
		if (obj.value.indexOf('.') >= 0) { alert(str); obj.select(); return false; };
	}
	else if (sType == '正整数') {
		if (isNaN(Math.abs(obj.value))) { alert(str); obj.select(); return false; }
		if (obj.value.indexOf('.') >= 0 || obj.value.indexOf('-') >= 0) { alert(str); obj.select(); return false; };
	}
	else if (sType == '小数') {
		if (isNaN(Math.abs(obj.value))) { alert(str); obj.select(); return false; }
		if (Math.abs(obj.value) >= 1 || Math.abs(obj.value) == 0) { alert(str); obj.select(); return false; };
	}
	return true;
}
  
// 去头尾空格
String.prototype.trim = function ()  
{ 
return this.replace(/(^[\s]*)|([\s]*$)/g, ""); 
};   
  
  //函数名称：CheckDate
  //功能介绍：检查是否为日期
  //参数说明：要检查的字符串
  //返回值：1 是日期，0 不是日期
  function CheckDate(datestr)
  {
	var lthdatestr
	if (datestr != "")
		lthdatestr= datestr.length ;
	else
		lthdatestr=0;
		
	var tmpy="";
	var tmpm="";
	var tmpd="";
	var status;
	status=0;
	if ( lthdatestr== 0)
		return 0

	
	for (i=0;i<lthdatestr;i++)
	{	if (datestr.charAt(i)== '-')
		{
			status++;
		}
		if (status>2)
		{
			//alert("Invalid format of date!");
			return 0;
		}
		if ((status==0) && (datestr.charAt(i)!='-'))
		{
			tmpy=tmpy+datestr.charAt(i)
		}
		if ((status==1) && (datestr.charAt(i)!='-'))
		{
			tmpm=tmpm+datestr.charAt(i)
		}
		if ((status==2) && (datestr.charAt(i)!='-'))
		{
			tmpd=tmpd+datestr.charAt(i)
		}

	}

	year=new String (tmpy);
	month=new String (tmpm);
	day=new String (tmpd)
	//tempdate= new String (year+month+day);
	//alert(tempdate);
	if ((tmpy.length!=4) || (tmpm.length>2) || (tmpd.length>2))
	{
		//alert("Invalid format of date!");
		return 0;
	}
	if (!((1<=month) && (12>=month) && (31>=day) && (1<=day)) )
	{
		//alert ("Invalid month or day!");
		return 0;
	}
	if (!((year % 4)==0) && (month==2) && (day==29))
	{
		//alert ("This is not a leap year!");
		return 0;
	}
	if ((month<=7) && ((month % 2)==0) && (day>=31))
	{
		//alert ("This month is a small month!");
		return 0;
	
	}
	if ((month>=8) && ((month % 2)==1) && (day>=31))
	{
		//alert ("This month is a small month!");
		return 0;
	}
	if ((month==2) && (day==30))
	{
		//alert("The Febryary never has this day!");
		return 0;
	}
	
	return 1;
}

//函数说明：合并指定表格（表格id为_w_table_id）指定列（列数为_w_table_colnum）的相同文本的相邻单元格
//参数说明：_w_table_id 为需要进行合并单元格的表格的id。如在HTMl中指定表格 id="data" ，此参数应为 #data 
//参数说明：_w_table_colnum 为需要合并单元格的所在列。为数字，从最左边第一列为1开始算起。
function _w_table_rowspan(_w_table_id, _w_table_colnum) {
    _w_table_firsttd = "";
    _w_table_currenttd = "";
    _w_table_SpanNum = 0;
    _w_table_Obj = $(_w_table_id + " tr td:nth-child(" + _w_table_colnum + ")");
    _w_table_Obj.each(function(i) {
        if (i == 0) {
            _w_table_firsttd = $(this);
            _w_table_SpanNum = 1;
        } else {
            _w_table_currenttd = $(this);
            if (_w_table_firsttd.text() == _w_table_currenttd.text()) {
                _w_table_SpanNum++;
                _w_table_currenttd.hide(); //remove();
                _w_table_firsttd.attr("rowSpan", _w_table_SpanNum);
            } else {
                _w_table_firsttd = $(this);
                _w_table_SpanNum = 1;
            }
        }
    });
}
//函数说明：合并指定表格（表格id为_w_table_id）指定行（行数为_w_table_rownum）的相同文本的相邻单元格
//参数说明：_w_table_id 为需要进行合并单元格的表格id。如在HTMl中指定表格 id="data" ，此参数应为 #data 
//参数说明：_w_table_rownum 为需要合并单元格的所在行。其参数形式请参考jQuery中nth-child的参数。
//          如果为数字，则从最左边第一行为1开始算起。
//          "even" 表示偶数行
//          "odd" 表示奇数行
//          "3n+1" 表示的行数为1、4、7、10.......
//参数说明：_w_table_maxcolnum 为指定行中单元格对应的最大列数，列数大于这个数值的单元格将不进行比较合并。
//          此参数可以为空，为空则指定行的所有单元格要进行比较合并。
function _w_table_colspan(_w_table_id, _w_table_rownum, _w_table_maxcolnum) {
    if (_w_table_maxcolnum == void 0) { _w_table_maxcolnum = 0; }
    _w_table_firsttd = "";
    _w_table_currenttd = "";
    _w_table_SpanNum = 0;
    $(_w_table_id + " tr:nth-child(" + _w_table_rownum + ")").each(function(i) {
        _w_table_Obj = $(this).children();
        _w_table_Obj.each(function(i) {
            if (i == 0) {
                _w_table_firsttd = $(this);
                _w_table_SpanNum = 1;
            } else if ((_w_table_maxcolnum > 0) && (i > _w_table_maxcolnum)) {
                return "";
            } else {
                _w_table_currenttd = $(this);
                if (_w_table_firsttd.text() == _w_table_currenttd.text()) {
                    _w_table_SpanNum++;
                    _w_table_currenttd.hide(); //remove();
                    _w_table_firsttd.attr("colSpan", _w_table_SpanNum);
                } else {
                    _w_table_firsttd = $(this);
                    _w_table_SpanNum = 1;
                }
            }
        });
    });
}
