//################################################
//代码功能：打开模式窗口
//编写时间：2013-03-12
//################################################
function UsOpenDialogTree(paraurl, src, txtValue) {
    var url = paraurl;
    var res;
    res = showModalDialog(url, 'careff2013', 'dialogWidth: 300px; dialogHeight: 500px; center: yes; resizable: no; scroll: no; status: no;');
    if (res == undefined) {
        window.alert("系统提示您：您没有选择相关需要的信息！");
    }
    else {
        try {
            //alert(res);
            var strs = res.split("#")
            var m = $id(src)
            //m.title = strs[0];
            m.value = strs[1];
            var m1 = $id(txtValue)
            m1.value = strs[0];
        }
        catch (e) {
            alert(e);
        }
    }
}


function UsOpenDialogTreeBack(paraurl, src, txtValue, callback) {
    var url = paraurl;
    var res;
    res = showModalDialog(url, 'careff2013', 'dialogWidth: 300px; dialogHeight: 500px; center: yes; resizable: no; scroll: no; status: no;');
    if (res == undefined) {
        window.alert("系统提示您：您没有选择相关需要的信息！");
    }
    else {
        try {
            //alert(res);
            var strs = res.split("#")
            var m = $id(src)
            //m.title = strs[0];
            m.value = strs[1];
            var m1 = $id(txtValue)
            m1.value = strs[0];
            callback();
        }
        catch (e) {
            alert(e);
        }
    }
}


function UsOpenURLInfo(webURL) {
    //var webURL = "evaluationDetail.aspx?id=" + ID;
    var win = window.open(webURL, '2013', "height=500, width=750, top=0, left=0,toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, status=no")
    win.focus();
}


function UsView(src) {
    var m = $id(src)
    if (m.value != "") {
        window.open(m.value);
    }
    else {
        alert("暂无数据，不能查看！");
    }
}
function UsOpenDialog(txt) {
    //alert(txt);
    var webURL = "/admin/document/documentuploadself.aspx"
    var picname = window.showModalDialog(webURL, window, "dialogWidth:550px;status:no;dialogHeight:150px");
    //alert(picname);
    if (picname != undefined) $id(txt).value = picname;
}

function UsClear(txt) {
    $id(txt).value = "";
}

function UsCopyRight() {
    var k = window.showModalDialog("/admin/ussoft.aspx", window, 'dialogWidth:500px;status:no;dialogHeight:320px');
}

//防止非法打开
function UsURLNoSrc() {

    //2015-01-07 关闭
    return;

    try {
        var srcURL = window.opener.location;
        var doURL = document.domain.toString();

        var strObj = new String(srcURL);
        if (strObj.indexOf(doURL) < 0) {
            //2015-01-22关闭
            //window.location.href = "/";
        }
    }
    catch (err) {
        //在此处理错误
        //window.close();
        //alert(err);

        //2015-01-22关闭
        //window.location.href = "/";
    }


}

function skySelectCheckList() {

    var slist;
    slist = $id("chkselect");
    var t;
   
    var nName;
    t = slist.checked;
    var dom = document.getElementsByTagName("*");
    var el = event.srcElement ? event.srcElement : event.target;
    for (i = 0; i < dom.length; i++) {
        if (dom[i].tagName == "INPUT" && dom[i].type.toLowerCase() == "checkbox") {
            nName = dom[i].id;
            //dom[i].checked = t;
            if (nName.indexOf("chkselect") != -1) {
                //alert(dom[i].disabled == false);
                if (dom[i].disabled == false) {
                    dom[i].checked = t;
                }
            }
            if (nName.indexOf("chkIsMakeup") != -1) {
                if (dom[i].disabled == false)
                    dom[i].checked = t;
            }

        }
    }
}


//careff.com
//2014-10-25  我的文档功能完善
function SkyOpen(txt) {
    var url = "/admin/document/uploadone2.aspx?id=" + txt;
    CareffArtOpen4(url, '上传文件', 600, 200, function (path) {
         
        if (path == null) { return false; }
        $("#" + txt).val(path);
    });
   
}

function SkyOpenimg(txt, img) {
    var url = "/admin/document/uploadone2.aspx?id=" + txt;
    CareffArtOpen4(url, '上传文件', 600, 200, function (path) {

        if (path == null) { return false; }
        $("#" + txt).val(path);
        $("#" + img).attr("src", path);
    });
}
function SkyOpenUploadMuti(txt) {
    //alert(txt);
    var path = document.getElementById(txt).value;
    if ($("#careff_mdiv").length <= 0) {
        $(document.body).append("<div id='careff_mainmul'><iframe src='' id='selectfile' frameborder='0' width='100%' height='100%'></iframe></div><div id='careff_mdiv'></div>");
    }
    $('#careff_mdiv').show();
    $('#careff_mainmul').show();
    $('#selectfile').attr("src", "/admin/document/uploadmulti.aspx?path=" + path);

    var left = ($(window).width() - $('#careff_mainmul').outerWidth()) / 2;
    var top = ($(window).height() - $('#careff_mainmul').outerHeight()) / 2;

    if (left < 0) {
        left = 0;
    }
    if (top < 0) {
        top = 0;
    }

    //alert($(window).width() + "," + $(window).height());

    //alert($('#careff_mainmul').outerWidth() + "," + $('#careff_mainmul').outerHeight());
    //top = 20;

    //alert(left + "," + top);
    $('#careff_mainmul').css({
        position: 'absolute',
        left: left,
        top: top
    });

    $('#careff_mdiv').css({
        position: 'absolute',
        left: 0,
        top: 0,
        width: $(window).width(),
        height: $(window).height()
    });
    return false;
}


function UsOpenDialog2015(url) {
    //alert(txt);
    var webURL = url;
    var picname = window.showModalDialog(webURL, window, "dialogWidth:850px;status:no;dialogHeight:750px");
   
}


function ustoolsJsSum1(table, column, il) {//合计，表格对象，对哪一列进行合计，第一列从0开始
    if (table == null) {
        return;
    }
    var trs = table.getElementsByTagName('tr');
    var start = 1,//忽略第一行的表头
        end = trs.length - 1;//忽略最后合计的一行
    var total = 0;
    for (var i = start; i < end; i++) {
        var td = trs[i].getElementsByTagName('td')[column];
        var t = parseFloat(td.innerHTML);
        if (t) total += t;
    }
    trs[end].getElementsByTagName('td')[column].innerHTML = total.toFixed(il);
}

function ustoolsJsSum2(table, column, il) {
    var sArr = column.split(",");
    for (var j = 0; j < sArr.length; j++) {
        var c1 = parseInt(sArr[j])
        ustoolsJsSum1(document.getElementById("" + table), c1, il);
    }
}
function ustoolsJsSum(table, column) {
    ustoolsJsSum2(table, column, 1);
}

function toFloat(src) {
    var ret = parseFloat(src);
    if (isNaN(ret)) {
        return 0;
    }
    return ret;
}

//zTree搜索专用
function ztreeinitsearch(zid, inputid) {
    ztreeID = zid;
    ztreeInput = inputid;
    $("#" + ztreeInput).bind("keyup", clickRadio);
    $("#" + ztreeInput).bind("blur", clickRadio);
}
var ztreeID = "";
var ztreeInput = "";
var lastValue = "", nodeList = [], fontCss = {};
function clickRadio(e) {
    //console.debug(e);
    lastValue = "";
    searchNode(e);
}
function searchNode(e) {
    var zTree = $.fn.zTree.getZTreeObj(ztreeID);
    updateNodes(false);
    var value1 = $("#" + ztreeInput).val();
    if (value1 != "") {
        nodeList = zTree.getNodesByParamFuzzy("name", value1);
        updateNodes(true);
    } else {
        //nodeList = zTree.getNodes()
        //updateNodes(false);
    }
}
function updateNodes(highlight) {
    var zTree = $.fn.zTree.getZTreeObj(ztreeID);
    for (var i = 0, l = nodeList.length; i < l; i++) {
        nodeList[i].highlight = highlight;
        zTree.updateNode(nodeList[i]);
        //console.debug(i);
    }
}
function getFontCss(treeId, treeNode) {
    return (!!treeNode.highlight) ? { color: "#A60000", "font-weight": "bold" } : { color: "#333", "font-weight": "normal" };
}
//zTree搜索专用

$(function () {
    //var d = $('select').select2();
    var d = $('select').not("*[multiple]").select2();
});

function usfontcolor() {
    $(".usfontcolor").each(function () {
        var html = $(this).html()
        var v = parseInt(html);
        var addclass = "us-span-greenv2";
        if (v <= 0) {
            addclass = "us-span-redv2";
        }
        $(this).addClass(addclass);
    });
}