


function _id(id) {
    return !id ? null : document.getElementById(id);
}

function SelectAll(aControl) {

    var tempControl = aControl;
    var isChecked = tempControl.checked;

    elem = document.getElementsByTagName("input");

    for (i = 0; i < elem.length; i++)
        if (elem[i].type == "checkbox" && elem[i].id != tempControl.id) {
            if (elem[i].checked != isChecked)
                elem[i].click();
        }
}




function CheckHasSelect(aControl) {

    var tempControl = aControl;
    var isChecked = tempControl.checked;

    elem = document.getElementsByTagName("input");
    var count = 0;

    for (i = 0; i < elem.length; i++) {
        if (elem[i].type == "checkbox" && elem[i].id != "selectall") {
            if (elem[i].checked) {

                count = count + 1;
            }
        }
    }

    if (count > 0) {

        return confirm('确定删除选择的内容吗?');
    }
    else {
        alert("请选中要删除的内容");
        return false;
    }
}




function ShowCalendar(txt) {
        
    laydate();
}







function popUser(result, uid, username, displayname, dept, tel, email, staffcode) {

    var _result = result.split("$");
    if (uid != "") {
        $('#' + uid).val(_result[0]);
    }
    if (username != "") {
        $('#' + username).val(_result[1]);
    }

    if (displayname != "") {
        $('#' + displayname).val(_result[2]);
    }

    if (dept != "") {
        $('#' + dept).val(_result[3]);
    }

    if (tel != "") {
        $('#' + tel).val(_result[4]);
    }

    if (email != "") {
        $('#' + email).val(_result[5]);
    }

    if (staffcode != "") {
        $('#' + staffcode).val(_result[6]);
    }

}



/* 表格 行变色*/
function hover() {
    var $bg;
    $('#thetable table tr:not(:has("th"))').hover(

      function () {
          $bg = $(this).css('background-color');
          $(this).css('background-color', 'lightblue');
      },

      function () {
          $(this).css('background-color', $bg);
      }
     );
}






function isselect() {

    var checked = 0;
    var allvalue = '';

    var _c = 0;
    $(".ck_item").each(

     function () {
         if ($(this).is(':checked')) {
             checked++;

             if (checked > 1) {
                 allvalue += ',' + $(this).val();
             }
             else {
                 allvalue = $(this).val();
             }
         }

     });

    $("#hf_ids").val(allvalue);

    if (checked > 0) {
        return true;
    }
    else {
        layer.alert('请至少选择一条记录', 12);
        return false;
    }

}



function selectall(obj) {
    var checkFlag = $(obj).is(':checked');

    $(".ck_item").each(
        function () {
            if ($(this).prop('disabled') == false) {
                $(this).prop("checked", checkFlag);
            }
        }
        );


}












/* PopMenu */

var modclickcount = 0;
function modclick(obj, tableid) {
    var modcount = $('#modcount');
    var modlayer = $('#modlayer');
    if (obj.checked == true) {
        modclickcount++;
    }
    else {
        modclickcount--;
    }
    modcount.html(modclickcount);

    if (modclickcount > 0) {
        var top_offset = obj.offsetTop;

        while ((obj = obj.offsetParent).id != tableid) {
            top_offset += obj.offsetTop;
        }

        modlayer.css("top", top_offset + 20);
        modlayer.show();
    }
    else {
        modlayer.hide();
    }



    if (modclickcount > 1) {
        $(".export").hide();
    }
    else {
        $(".export").show();
    }

}





function checkall(obj) {
    var num = 0;
    var chks = $("#thetable input[name='listitem']");

    if ($(obj).is(':checked')) {
        chks.attr("checked", true);
        num = chks.length;
    }
    else {
        chks.attr("checked", false);
        num = 0;
    }

    modclickcount = num;

    $('#modcount').html(num);
    if (num <= 0) {
        $('#modlayer').hide();
    }
    else {
        $('#modlayer').show();
    }



    if (num > 1) {
        $(".export").hide();
    }
    else {
        $(".export").show();
    }

}







function op(action, url, popTitle, returnUrl, showIFrame) {


    var checked = 0;
    var allvalue = '';
    var chks = $("#thetable input[name='listitem']");

    chks.each(
     function () {
         if ($(this).is(":checked")) {
             checked++;
             if (checked > 1) {
                 allvalue += ',' + $(this).val();
             }
             else {
                 allvalue = $(this).val();
             }
         }
     }
    );





    $("#hf_ids").val(allvalue);




    if (!checked) {
        alert('请选择需要操作的记录');
    }
    else {

        if (action == "get") {
            return;
        }

        if (action == "delete") {
            return;
        }



        if (showIFrame) {
            ShowIframeNoScroll(url + "&ids=" + allvalue + "&returnUrl=" + returnUrl, "500", "350", popTitle);
        }
        else {
            location.href = url + "&ids=" + allvalue;
        }
    }

}

function Pop(_src, _width, _height, _title) {


    layer.open({
        type: 2,
        title: _title,
        shadeClose: true,
        shade: 0.8,
        area: [_width + 'px', _height + 'px'],
        content: _src
    });

}

function ShowIframeNoScroll(_src, _width, _height, _title) {

    layer.open({
        type: 2,
        title: _title,
        shadeClose: true,
        shade: 0.8,
        area: [_width + 'px', _height + 'px'],
        content: _src
    });

}



function ept(url) { 
    Pop(url, 450, 350, "导出/导入数据");

}


function openPop(url) {

  

    layer.open({
        type: 2,
        title: "",
        area: ['950px', '520px'],
        fix: false, //不固定
        maxmin: true,
        content: url
    });


}


function openprofile() {



    layer.open({
        type: 2,
        title: "更新我的档案",
        area: ['950px', '520px'],
        fix: false, //不固定
        maxmin: true,
        content: '../myprofile.aspx'
    });


}




function ftd(r) {
    if (r == "--" || r == "" ||r=="&nbsp;")
        return 0;
    return parseFloat(r);

}


function sumRow(tabid) {
    var col = "<td class=sumhead>行合计</td>";
    $("#" + tabid + " tr").append(col);


    $('#' + tabid + ' tr:not(:first)').each(function () {

        var rowsum = 0;
        tds = $(this).find('td');
        var index = 0;
        var len = tds.length - 1;
        for (var index = 0; index < len - 1; index++) {
            rowsum += ftd($(tds[index + 1]).html());
        }

        $(tds[len]).html(rowsum);

    });
}



function sumCol(tabid) {
    var result = "<tr style='border-bottom:solid 1px #ddd' > <td class='sumhead'>列合计</td> ";
    var colLen = $("#" + tabid + " th").length;
    var colArray = new Array(30);
    for (var k = 0; k < 30; k++) {
        colArray[k] = 0;
    }

    $.each($('#' + tabid + ' tr'), function (idx, _tr) {
        if (idx != 0) {

            for (var j = 0; j < colLen ; j++) {
                var _v = ($(_tr).find('td')[j + 1].innerHTML);

                colArray[j + 1] += ftd(_v);

            }

        }
    });

    for (var r = 1; r < colLen + 1; r++) {
        result += "<td class=sumhead>" + colArray[r] + "</td>"
    }

    $('#' + tabid + '').append(result);
}