<%-- $Id: AddMultiUser.jsp,v 1.1.2.3 2006/02/20 08:34:55 sudharshan Exp $ --%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>


<script type="text/javascript" language="JavaScript" src="/webclient/common/js/general.js"></script>
</head>


<body>
<form action="/admin/AddMultiUserForm.do" method="post" onSubmit="return configureGroup(this)">

<input type=hidden name="toPerform" value="<c:out value="${toPerform}"/>" />  


<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
      <td height="35" valign="bottom" ><span class="pageHeader"><fmt:message key='webclient.admin.addmultiple.header'/></span></td>
  </tr>
  <tr>
  	<td class="hline" height="1"><img src="images/trans.gif" height="1" width="1"></td>
  </tr>
</table>
<br>
  <div class="text"><fmt:message key='webclient.admin.addmultiple.count'/></div>

  <table id="userTable" width="80%" border="0" cellspacing="0" cellpadding="2" class="htableBorder">
    <tr class="header2bg"> 
      <td width="10%" height="25" nowrap class="text">&nbsp;</td>
      <td width="35%" nowrap class="text"><strong> <fmt:message key='webclient.admin.addmultiple.username'/></strong></td>
      <td nowrap class="text"><strong> <fmt:message key='webclient.admin.addmultiple.selgroup'/></strong></td>
        <td height="25" nowrap class="text">&nbsp;</td>
    </tr>
    
   
      <c:forEach begin="0" end="${11}" varStatus="status"> 
      
      <tr valign="top"> 
            <td nowrap class="text"> <div align="center"><fmt:message key='webclient.admin.addmultiple.usercount'/> <c:out value="${status.count}"/>:</div></td>
            <td><input name="userNameList" id="username" type="text" class="formStyle"></td>
            <td height="45" nowrap class="text">
				<select name="GroupList" multiple size="2" <c:if test="${status.count eq 1}"> 
					onChange="javascript:selectAll(getObj('selectall').checked,this);"
				</c:if>>
            	<c:forEach var="groupName" items="${groupVector}" varStatus="status1">
                <option value="<c:out value='${groupName}'/>" > <c:out value="${groupName}"/> </option>
                 </c:forEach> 
              </select></td>
            <td nowrap>
              	<c:if test="${status.count eq 1}" >
              <input id="selectall" name="selectall" type="checkbox" onClick="javascript:selectAll(this.checked,getObj('GroupList')[0]);">   <fmt:message key='webclient.admin.addmultiple.setgroup'/>   </c:if> </td>
    </tr>
                <input type="hidden" name="NewGroups" />
            
       </c:forEach> 
    
   
  </table> 
<br>
  <table width="70%" border="0" cellspacing="0" cellpadding="0">
    <tr> 
    <td class="text"><div align="center">
        <input type="submit" name="Button3" value="<fmt:message key='webclient.admin.addmultiple.save'/>" class="button">
        <input type="button" name="Button22" value="<fmt:message key='webclient.admin.addmultiple.cancel'/>" class="button">
      </div></td>
  </tr>
</table>
</form>
</body>
</html>
<script>
function selectAll(state,firstGroup) {
	for (var i=1;i<getObj("GroupList").length;i++) {
		if (state==true) {
            var selectedGroupSize = firstGroup.options.length;
            var groupInArray = getObj("GroupList")[i];
            for(var j=0; j<selectedGroupSize; j++)
            {
                if(firstGroup.options[j] != null)
                {
        	        if(firstGroup.options[j].selected == true) {
                        groupInArray.options[j].selected = true;
                    }
                    else {
                        groupInArray.options[j].selected = false;
                    }
                    
                }
            }
            //getObj("GroupList")[i].value=firstGroup.value;
        }
		getObj("GroupList")[i].disabled=state;
	}
}

function configureGroup(form)
{
    var groupList = getObj("GroupList");
    var groupLength = groupList.length;
    var userList = getObj("userNameList");
    var userLength = userList.length;
    var selectedUsers  = "";

    for (var i=0; i<groupLength; i++) {
	var user = userList[i].value;
        var selectedGroupSize = groupList[i].options.length;
        var groupInArray = groupList[i];
        var selectedGroup = '';
        var groupSelected = false;
        for(var j=0; j<selectedGroupSize; j++)
        {
            if(groupInArray.options[j] != null)
            {
        	    if(groupInArray.options[j].selected == true) {
			     groupSelected = true;
                    if(selectedGroup == '') {
                        selectedGroup = groupInArray.options[j].value;
                    }
                    else {
                        selectedGroup += ',' + groupInArray.options[j].value;
                    }
                }
            }
        }
        if(user != "" && !selectedGroup)
	 {
	     alert("<fmt:message key='webclient.admin.addmultiple.nogroupforuser'/> "+user);
	     return false;
	 }
	 if(selectedUsers == "")
	 {
		selectedUsers = user;
	 }
	 else 
	 {

		if(user!="")
		{
		var users = selectedUsers.split(",");
		for(var i=0;i<users.length;i++)
		{
		   if(users[i] == user)
		   {
		      alert("<fmt:message key='webclient.admin.addmultiple.repeateduser'/> "+user);
		      return false;
		   }
		}
		selectedUsers += "," + user;

		}
		        
	 }
        form.NewGroups[i].value = selectedGroup;
	}   
	if(selectedUsers == "")
	{
	   alert("<fmt:message key='webclient.admin.addmultiple.nouseradded'/> ");
	   return false;
 	}
    return true;
}



</script>