<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CompanySelect.aspx.cs" Inherits="eFrameWork.Plugins.CompanySelect" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>公司选择</title>
</head>
<link href="../Plugins/eControls/default/style.css?ver=<%=Common.Version %>" rel="stylesheet" type="text/css" />   
<link href="../Plugins/Theme/default/style.css?ver=<%=Common.Version %>" rel="stylesheet" type="text/css" />
<script src="../Scripts/jquery.js"></script>
<script src="../Scripts/eketeam.js?ver=<%=Common.Version %>"></script>
<style>
html, body {margin:0px;padding:0px;font-size:13px;width:100%;height:100%;}
body {overflow:auto;-webkit-user-select: none;-khtml-user-select: none;-moz-user-select: none;-ms-user-select: none;user-select: none;}
</style>
<script>
var objid = "<%=obj%>";
$(document).ready(function () {
	var tree = new eTree("etree");	
});
function setDepartment(id, name)
{
    cancelEvent(getEvent());
    if ($(parent.UserSelectParent).find("#" + objid + "_box").attr("etype") == "companyselect") {
        setSingle(id, name);
    }
    else {
        setMultiple(id, name);
    }
    
};
function setSingle(id, name) {
    var box = $(parent.UserSelectParent).find("#" + objid + "_box");
    var ovalue = $(parent.UserSelectParent).find("[postname='" + objid + "']").val();
   
    if (ovalue == id)//删除
    {
        $(parent.UserSelectParent).find("[postname='" + objid + "']").val("");
        $(parent.UserSelectParent).find("[postname='" + objid + "_text']").val("");
        box.find(".useritem").remove();
        if (typeof (parent.DepartmentSelect_callback) == "function") { parent.DepartmentSelect_callback(objid, "", ""); }
    }
    else {
        $(parent.UserSelectParent).find("[postname='" + objid + "']").val(id);
        $(parent.UserSelectParent).find("[postname='" + objid + "_text']").val(name);
        if (box.find(".useritem").length == 1)
        {
            box.find(".useritem p").html(name);
        }
        else {
            var html = '<a class="useritem" href="javascript:;">';
            html += '<p>' + name + '</p><img src="../images/none.gif" onclick="multipleuser_delete(this);"></a>';
            //box.find(".useritem_open").before(html);
            if (box.find(".useritem_open").length > 0) {
                box.find(".useritem_open").before(html);
            }
            else {
                box.append(html);
            }
            //box.append(html);
           
        }
        parent.layer.close(parent.arrLayerIndex.pop());
        if (typeof (parent.DepartmentSelect_callback) == "function") { parent.DepartmentSelect_callback(objid, id, name); }
    }
};
function setMultiple(id, name) {
    var box = $(parent.UserSelectParent).find("#" + objid + "_box");
    var ovalue = $(parent.UserSelectParent).find("[postname='" + objid + "']").val();
    //alert(ovalue + "::" + id);
    if (ovalue.indexOf(id) > -1) {
        var arr = ovalue.split(",");
        var idx = -1;
        var nvalue = "";
        var ntext = "";
        for (var i = 0; i < arr.length; i++) {
            if (arr[i] == id) {
                idx = i;
                continue;
            }
            if (nvalue.length > 0) { nvalue += ","; ntext += ","; }
            nvalue += arr[i];
            ntext += box.find(".useritem:eq(" + i + ") p").html();
        }
        $(parent.UserSelectParent).find("[postname='" + objid + "']").val(nvalue);
        $(parent.UserSelectParent).find("[postname='" + objid + "_text']").val(ntext);
        box.find(".useritem:eq(" + idx + ")").remove();
        if (typeof (parent.DepartmentSelect_callback) == "function") { parent.DepartmentSelect_callback(objid, nvalue, ntext); }
    }
    else {
        var ntext = $(parent.UserSelectParent).find("[postname='" + objid + "_text']").val();
        var nvalue = ovalue;
        if (nvalue.length > 0) { nvalue += ","; ntext += ","; }
        nvalue += id;
        ntext += name;
        $(parent.UserSelectParent).find("[postname='" + objid + "']").val(nvalue);
        $(parent.UserSelectParent).find("[postname='" + objid + "_text']").val(ntext);

        var html = '<a class="useritem" href="javascript:;">';
        html += '<p>' + name + '</p><img src="../images/none.gif" onclick="multipleuser_delete(this);"></a>';
        //box.find(".useritem_open").before(html);
        if (box.find(".useritem_open").length > 0) {
            box.find(".useritem_open").before(html);
        }
        else {
            box.append(html);
        }
        //box.append(html);
        if (typeof (parent.DepartmentSelect_callback) == "function") { parent.DepartmentSelect_callback(objid, nvalue, ntext); }
    }
};   
</script>
<body>
<div style="padding:10px;">
<asp:Literal id="litBody" runat="server" />
</div>
</body>
</html>