<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="index.aspx.cs" Inherits="KstCMS.KstCMS_Manager.Module.role_select.index" %>

<script Language="JavaScript">		
var rolelist=new Array();
<%=StrRoleList%>
var parent_window;
if(window.navigator.appName.toLowerCase().indexOf("netscape") > -1)
	parent_window = window.parent.opener;
else
	parent_window = parent.dialogArguments;

function click_Role(role_id)
{
  TO_VAL=parent_window.document.getElementById("<% =ViewState["ToId"] %>").value;
  TO_NAME=parent_window.document.getElementById("<% =ViewState["ToName"] %>").value;
  targetelement=document.getElementById("ROLE_"+role_id);
  role_name=targetelement.getAttribute("name");

  if(TO_VAL.indexOf(","+role_id+",")>0 || TO_VAL.indexOf(role_id+",")==0)
  {
    if(TO_VAL.indexOf(role_id+",")==0)   
       parent_window.document.getElementById("<% =ViewState["ToId"] %>").value=parent_window.document.getElementById("<% =ViewState["ToId"] %>").value.replace(role_id+",","");
    
    if(TO_VAL.indexOf(","+role_id+",")>0)    
       parent_window.document.getElementById("<% =ViewState["ToId"] %>").value=parent_window.document.getElementById("<% =ViewState["ToId"] %>").value.replace(","+role_id+",",",");
          
    if(TO_NAME.indexOf(role_name+",")==0)     
       parent_window.document.getElementById("<% =ViewState["ToName"] %>").value=parent_window.document.getElementById("<% =ViewState["ToName"] %>").value.replace(role_name+",","");       
    
    if(TO_NAME.indexOf(","+role_name+",")>0)
       parent_window.document.getElementById("<% =ViewState["ToName"] %>").value=parent_window.document.getElementById("<% =ViewState["ToName"] %>").value.replace(","+role_name+",",",");
    
    borderize_off(targetelement);
  }
  else
  {
    parent_window.document.getElementById("<% =ViewState["ToId"] %>").value+=role_id+",";
    parent_window.document.getElementById("<% =ViewState["ToName"] %>").value+=role_name+",";
    borderize_on(targetelement);
  }
}

function borderize_on(targetelement)
{
 color="#003FBF";
 targetelement.style.borderColor="black";
 targetelement.style.backgroundColor=color;
 targetelement.style.color="white";
 targetelement.style.fontWeight="bold";
}

function borderize_off(targetelement)
{
  targetelement.style.backgroundColor="";
  targetelement.style.borderColor="";
  targetelement.style.color="";
  targetelement.style.fontWeight="";
}

function begin_set()
{
  TO_VAL=parent_window.document.getElementById("<% =ViewState["ToId"] %>").value;  
  if(TO_VAL=="ALL_ROLE")
  {
     parent_window.document.getElementById("<% =ViewState["ToId"] %>").value="";
     parent_window.document.getElementById("<% =ViewState["ToName"] %>").value="";
  }  

  for (step_i=0; step_i<rolelist.length; step_i++)
  {
	 role_id=rolelist[step_i];
     if(TO_VAL.indexOf(","+role_id+",")>0 || TO_VAL.indexOf(role_id+",")==0)
		borderize_on(document.getElementById("ROLE_"+rolelist[step_i]));
  }
}

function add_all()
{
  TO_VAL=parent_window.document.getElementById("<% =ViewState["ToId"] %>").value;
  for (step_i=0; step_i<rolelist.length; step_i++)
  {
    role_id=rolelist[step_i];
    role_name=document.getElementById("ROLE_"+rolelist[step_i]).getAttribute("name");

    if(TO_VAL.indexOf(","+role_id+",")<=0 && TO_VAL.indexOf(role_id+",")!=0)
    {
        parent_window.document.getElementById("<% =ViewState["ToId"] %>").value+=role_id+",";
        parent_window.document.getElementById("<% =ViewState["ToName"] %>").value+=role_name+",";
        borderize_on(document.getElementById("ROLE_"+rolelist[step_i]));
    }
  }
}

function add_all_dept()
{
	parent_window.document.getElementById("<% =ViewState["ToId"] %>").value="ALL_ROLE";
    parent_window.document.getElementById("<% =ViewState["ToName"] %>").value="所有角色";   
    parent.close();
}

function del_all()
{  
  for (step_i=0; step_i<rolelist.length; step_i++)
  {  
	TO_VAL=parent_window.document.getElementById("<% =ViewState["ToId"] %>").value;
	TO_NAME=parent_window.document.getElementById("<% =ViewState["ToName"] %>").value;
	 
    role_id=rolelist[step_i];
    role_name=document.getElementById("ROLE_"+rolelist[step_i]).getAttribute("name");
    
	if(TO_VAL.indexOf(role_id+",")==0)   
		parent_window.document.getElementById("<% =ViewState["ToId"] %>").value=parent_window.document.getElementById("<% =ViewState["ToId"] %>").value.replace(role_id+",","");
	    
	if(TO_VAL.indexOf(","+role_id+",")>0)    
		parent_window.document.getElementById("<% =ViewState["ToId"] %>").value=parent_window.document.getElementById("<% =ViewState["ToId"] %>").value.replace(","+role_id+",",",");
	          
	if(TO_NAME.indexOf(role_name+",")==0)     
		parent_window.document.getElementById("<% =ViewState["ToName"] %>").value=parent_window.document.getElementById("<% =ViewState["ToName"] %>").value.replace(role_name+",","");       
    
    if(TO_NAME.indexOf(","+role_name+",")>0)
       parent_window.document.getElementById("<% =ViewState["ToName"] %>").value=parent_window.document.getElementById("<% =ViewState["ToName"] %>").value.replace(","+role_name+",",",");
      
    borderize_off(document.getElementById("ROLE_"+rolelist[step_i]));
  }
}

		</script> 
<html>
<head  runat="server">
    <title>选择角色</title>    
</head>
<body onload="begin_set();">
    <form id="form1" runat="server">
    <asp:Repeater ID="Repeater1" runat="server">
<HeaderTemplate>
<table width="100%" border="0" align="center" cellpadding="3" cellspacing="1" class="TableBorder">

  <tr>
    <td align="center" bgcolor="#FFFFFF" onclick="javascript:del_all();" style="cursor:pointer">全部清除</td>
  </tr>
</HeaderTemplate>
<ItemTemplate>
  <tr>
    <td id="ROLE_<%#DataBinder.Eval(Container.DataItem,"RoleId") %>" name="<%#DataBinder.Eval(Container.DataItem,"RoleName") %>" align="center" bgcolor="#FFFFFF" onclick="javascript:click_Role('<%#DataBinder.Eval(Container.DataItem,"RoleId") %>');" style="cursor:pointer"><%#DataBinder.Eval(Container.DataItem,"RoleName") %></td>
  </tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
    </asp:Repeater>
    <div style="padding:10px; text-align:center"> <input type="button" value="关 闭" class="bigButton" onclick="window.close();" /></div>
    </form>
</body>
</html>
