<!DOCTYPE HTML >
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<title translate="yes" data-res="GROUPS_EDITOR.GROUPS"></title>
		<link rel="stylesheet" href="../../../theme/css/censusmain.css" type="text/css"/>
		<link rel="stylesheet" href="../../../theme/css/grid.css" type="text/css"/>
		<script type="text/javascript" src="../../../js/mqsysutils.js"></script>
		<script type="text/javascript" src="../../../js/window.js"></script>
		<script type="text/javascript" src="../../../js/cmqsysmsg.js" ></script>
		<script type="text/javascript" src="../../../js/cmqhttprequest.js"></script>
		<script type="text/javascript" src="../../../js/mqlist.js"></script>
		<script type="text/javascript" src="../../js/usersmgr/groupmgrutils.js"></script>
		<script type="text/javascript" src="../../../js/mqformelements.js"></script>
		
		<script type="text/javascript">
			//he should always define this object for the system messages
			var objSysMsg = new CMqSysMsg;
			var m_objMqButton=new MqButton();
			var m_objGroupList=new CMqFormElement();
			
			
			var MSG_REMOVE_GROUP=g_MqRef.RESX["USERMGR_MSG_REMOVE_GROUP"];
			var MSG_GROUP_CANNOT_BE_DELETED=g_MqRef.RESX["MSG_GROUP_CANNOT_BE_DELETED"];
		
			var objUsrMgrAdminRefs;
			var mobjHTTPrequest;
			
			if(parent){
				if(parent.parent){
					objUsrMgrAdminRefs=parent.parent;
				}
			}
			if(objUsrMgrAdminRefs){			
				if(objUsrMgrAdminRefs.objAdmin){
					mobjHTTPrequest=objUsrMgrAdminRefs.objAdmin.GetHTTPRequest();
				}
			}
			var mstrCurrentLocation=g_MqRef.MqFS.GetCurrentLocation(window);
			
			// If want to disallow removing features from Admins, uncomment the line below and comment the one after
			// var m_arrUnremovableGroups="<WC@UNREMOVEABLE_GROUPS>;</WC@UNREMOVEABLE_GROUPS>".split(";");			
			var m_arrUnremovableGroups=new Array();

			var m_arrGroups=new Array();
			
			function Initialize()
			{
				m_objGroupList.Initialize("lstGroups", CTRL_TYPE_COMBO, "document");
				
				var arrGroups="<WC@GROUPS>;</WC@GROUPS>".split(";");
				var lngCount;
				var strGroupName;
				
				for(lngCount=0; lngCount<arrGroups.length; lngCount++){
					strGroupName=g_MqRef.MqStr.MqDecodeURIComponent(arrGroups[lngCount]);
					m_arrGroups[lngCount]=new Array(strGroupName, strGroupName);
				}
			
				SetListHeight();
				
				FillGroupList(m_arrGroups);
				
				g_MqRef.ResMgr.ProcessAll(document);
			}
						
			function FillGroupList(arrGroups)
			{
				m_objGroupList.SetPossibleValues(arrGroups, false);

				HandleButtonStates();
			}

			
			function SelectOneGroup()
			{
				var strGroupName=GetSelectedGroupName();
				
				HandleButtonStates(strGroupName);
			}
			
			function AddGroup()
			{
				OpenChildWindow("TmplAddGroup.htm", "AddGroup", "toolbar=no,directories=no,resizable=yes,scrollbars=auto,width=350,height=150", true, 350, 150);	
			}
			
			function DeleteGroup()
			{
				var strGroupName=GetSelectedGroupName();
				var strMsg;
				
				if(strGroupName){
					if(strGroupName.length>0){
						if(IsOKToDeleteGroup(strGroupName)){
							strMsg=g_MqRef.MqStr.FormatString(MSG_REMOVE_GROUP, strGroupName);
				
							if(window.confirm(strMsg)){
								var co=mobjHTTPrequest.Get(mstrCurrentLocation + "WCCMqUserMgr.ASP?WCI=wciDeleteGroup" 
											+ "&Group=" + g_MqRef.MqStr.MqEncodeURIComponent(strGroupName) 
											+ "&Referrer=AdminReferrer");
				
								if (co!=mobjHTTPrequest.CANCEL_PROCESS){
										
									var objResponse=mobjHTTPrequest.Response(co);
									if (objResponse){
										if (objResponse.HasErrors()){
											objResponse.ProcessErrors("",true);
										}else{
											RemoveItemFromArray(strGroupName, m_arrGroups);
											FillGroupList(m_arrGroups);
										}
									}
								}
							}
						}else{
							strMsg=g_MqRef.MqStr.FormatString(MSG_GROUP_CANNOT_BE_DELETED, strGroupName); 
							alert(strMsg);
						}
					}
				}
			}
			
			function IsOKToDeleteGroup(strGroupName)
			{
				var blnReturn=true;
				var lngCount;
				var strLCaseGroupName;
				
				for(lngCount=0; lngCount<m_arrUnremovableGroups.length; lngCount++){
					strLCaseGroupName=strGroupName.toLowerCase();
					if(strLCaseGroupName==m_arrUnremovableGroups[lngCount].toLowerCase()){
						blnReturn=false;
						lngCount=m_arrUnremovableGroups.length;
					}
				}
				return blnReturn
			}
			
			function GetSelectedGroupName()
			{								
				return m_objGroupList.GetValue();
			}
			
			function SelectGroupName(strGroupName)
			{
				m_objGroupList.SetValue(strGroupName);
				
				HandleButtonStates(strGroupName);
			}
			
			function HandleButtonStates(strGroupName)
			{
				if(!strGroupName){
					m_objMqButton.DisableButton("DeleteGroup");
					m_objMqButton.DisableButton("Features");
					m_objMqButton.DisableButton("Projects");
					m_objMqButton.DisableButton("Users");
				}else{
					if(IsOKToDeleteGroup(strGroupName)){
						m_objMqButton.EnableButton("DeleteGroup");
					}else{
						m_objMqButton.DisableButton("DeleteGroup");
					}
					m_objMqButton.EnableButton("Features");
					m_objMqButton.EnableButton("Projects");
					m_objMqButton.EnableButton("Users");
				}
			}
			
			
			function SetGroupProps(lngGroupPropType)
			{
				var strGroupName=GetSelectedGroupName();
				
				var lngWidth=800;
				var lngHeight=600;
				
				if(strGroupName){
					if(strGroupName.length>0){
						
						if(lngGroupPropType==SHOW_PROJECTS_TYPE){
							lngWidth=800;
							lngHeight=355;
						}
						OpenChildWindow("WCCMqUserMgr.ASP?WCI=wciSetGroupProps&Referrer=AdminReferrer&Type=" + lngGroupPropType + "&Group=" +
											g_MqRef.MqStr.MqEncodeURIComponent(strGroupName), "GroupProps" + lngGroupPropType, 
											"toolbar=no,directories=no,resizable=yes,scrollbars=yes,width=" + lngWidth+
											",height=" + lngHeight, true, lngWidth, lngHeight);
				
					}
				}
			}
			
			function SortGroupListCol(blnKeepCurrentSort)
			{
				var objHeader=document.getElementById("GroupListHeader")
				var objImg=document.getElementById("imgGroupSort");
				
				SortListValues(m_objGroupList, objHeader, objImg, m_arrGroups, 
									blnKeepCurrentSort, false);
			}
		
			function AddGroupToList(strGroup)
			{
				AddItemToArray(strGroup, strGroup, m_arrGroups);
				
				SortGroupListCol(true);
				
				SelectGroupName(strGroup);
			}
			
			function SetListHeight()
			{
				var intBodyHeight;
				var NON_LIST_SPACE=70;
				if (document.all){
				    if (document.documentElement && document.documentElement.offsetHeight){
						intBodyHeight=document.documentElement.offsetHeight;
					}else{
						intBodyHeight=document.body.offsetHeight;
					}
				}else{
				    intBodyHeight=window.innerHeight;
				}
				var strNewHeight=(intBodyHeight-NON_LIST_SPACE);
				
				if(strNewHeight>300){
					document.getElementById("lstGroups").style.height=strNewHeight + "px";
				}
			}
		</script>
	</head>
	<body class="RecordBody" marginheight="0" marginwidth="0" topmargin="0" leftmargin="0" onload="Initialize();" onresize="SetListHeight()">
				
		
		<table style="position:absolute;width:100%;height:97%;top:2px;left:0%" cellpadding="0" cellspacing="0" border="0" >
	  <!--Box Top Border -->
		<tr height="20" >
			<td width="14" ><div class="BoxTLeft"></div></td>
			<td class="BoxTCenter">&nbsp;</td>
			<td width="14" ><div class="BoxTRight"></div></td>
		</tr>
	<!--End of Box Top Border -->
	<!--Box Middle w/table-->
		<tr style="width:100%;" >
			<td width="14" class="BoxMLeft">&nbsp;</td>
			<td style="width:100%;" class="BoxMCenter">
                
                <table width="100%" height="100%">
					<tr>
						<td width="60%" height="100%" valign="top">
							<div id="GroupListHeader" style="width:100%;height:20px; top:25px;display: table" class="ListHeader" 
								onmouseover="this.className='ListHeader ListHeaderOver';" onmouseout="this.className='ListHeader';" 
								onclick="SortGroupListCol(false);" MqSort="asc" translate="yes" data-res="GROUPS_EDITOR.GROUPS"> <img id="imgGroupSort" 
								src="../../../Theme/images/images/sortasc.gif" /></div>
							<div style="width:100%; height:95%; top:45px;" id="GroupList" class="ListBorder">
								<select class="ListStyle" name="lstGroups" id="lstGroups" onclick="SelectOneGroup()" size="10" 
								onkeypress="m_MqAutoList.OnKeyPress()" onclick="m_MqAutoList.OnClick()" onblur="m_MqAutoList.OnBlur()"></select>
							</div>
						</td>
						<td valign="top" width="40%" align="left"> 
							<table width="100%">
								<tr>
									<td style='text-align:center; padding:8px' width="50" class='HeaderIconText'>               
										<script type="text/javascript">
										<!--
											m_objMqButton.WriteButtonHTML("AddGroup","AddGroup();","AddGroup",false,m_objMqButton.STATE_1,g_MqRef.RESX["USERMGR_BUTTON_ADD_GROUP"]);
										//-->
										</script>
										<a href="#" class="HeaderIconText" style="text-decoration:none" onclick="AddGroup();return false;" translate="yes" data-res="USERMGR_HEADER_ADD"></a>
									</td>
									<td valign="top" style="padding-top:10px">
										<a href="#" class="TextMenuItem" onclick="AddGroup();return false;" translate="yes" data-res="USERMGR_HEADER_ADD_GROUP"></a>
									</td>
								</tr>
								<tr>
									<td style='text-align:center; padding:8px' width="50" class='HeaderIconText'>               
										<script type="text/javascript">
										<!--
											m_objMqButton.WriteButtonHTML("DeleteGroup","DeleteGroup();","DeleteGroup",false,m_objMqButton.STATE_DIS,
																	g_MqRef.RESX["USERMGR_BUTTON_DELETE_GROUP"]);
										//-->
										</script>
										<a href="#" class="HeaderIconText" style="text-decoration:none" onclick="DeleteGroup();return false;" translate="yes" data-res="USERMGR_HEADER_DELETE"></a>
									</td>
									<td valign="top" style="padding-top:10px">
										<a href="#" class="TextMenuItem" onclick="DeleteGroup();return false;" translate="yes" data-res="USERMGR_HEADER_DELETE_GROUP"></a>
									</td>
								</tr>
								<tr>
									<td colspan="2">
										<hr class="LineSep">
									</td>
								</tr>
								<tr>
									<td style='text-align:center; padding:8px' width="50" class='HeaderIconText'>               
										<script type="text/javascript">
										<!--
											m_objMqButton.WriteButtonHTML("Features","SetGroupProps(SHOW_FEATURES_TYPE);","GroupFeatures",false,
																	m_objMqButton.STATE_1,g_MqRef.RESX["USERMGR_BUTTON_FEATURES"]);
										//-->
										</script>
										<a href="#" class="HeaderIconText" style="text-decoration:none" onclick="SetGroupProps(SHOW_FEATURES_TYPE);return false;" 
											translate="yes" data-res="HEADER_FEATURES"></a>
									</td>
									<td valign="top" style="padding-top:10px">
										<a href="#" class="TextMenuItem" onclick="SetGroupProps(SHOW_FEATURES_TYPE);return false;" translate="yes" 
											data-res="USERMGR_HEADER_FEATURES_DESC"></a>
									</td>
								</tr>
								<tr>
									<td style='text-align:center; padding:8px' width="50" class='HeaderIconText'>               
										<script type="text/javascript">
										<!--
											m_objMqButton.WriteButtonHTML("Projects","SetGroupProps(SHOW_PROJECTS_TYPE);","GroupProjects",false,
																			m_objMqButton.STATE_1,g_MqRef.RESX["BUTTON_SELECT_PROJECT"]);
										//-->
										</script>
										<a href="#" class="HeaderIconText" style="text-decoration:none" onclick="SetGroupProps(SHOW_PROJECTS_TYPE);return false;" 
											translate="yes" data-res="HEADER_PROJECTS"></a>
									</td>
									<td valign="top" style="padding-top:10px">
										<a href="#" class="TextMenuItem" onclick="SetGroupProps(SHOW_PROJECTS_TYPE);return false;" 
											translate="yes" data-res="USERMGR_HEADER_SELECT_PROJECT_DESC"></a>
									</td>
								</tr>
								<tr>
									<td style='text-align:center; padding:8px' width="50" class='HeaderIconText'>               
										<script type="text/javascript">
										<!--
											m_objMqButton.WriteButtonHTML("Users","SetGroupProps(SHOW_USERS_TYPE);","GroupUsers",false,m_objMqButton.STATE_1,
																			g_MqRef.RESX["USERMGR_BUTTON_SELECT_USERS"]);
										//-->
										</script>
										<a href="#" class="HeaderIconText" style="text-decoration:none" onclick="SetGroupProps(SHOW_USERS_TYPE);return false;" 
											translate="yes" data-res="HEADER_USERS"></a>
									</td>
									<td valign="top" style="padding-top:10px">
										<a href="#" class="TextMenuItem" onclick="SetGroupProps(SHOW_USERS_TYPE);return false;" 
										translate="yes" data-res="USERMGR_HEADER_SELECT_USERS_DESC"></a>
									</td>
								</tr>
							</table>
						</td>
					</tr>
				</table>
			</td>
			<td width="14" class="BoxMRight">&nbsp;</td>
		</tr>
	<!--End of Box Middle w/table-->
	<!--Box Bottom Border -->
		<tr height="20" >
			<td width="14" ><div class="BoxBLeft"></div></td>
			<td class="BoxBCenter">&nbsp;</td>
			<td width="14" ><div class="BoxBRight"></div></td>
		</tr>
	<!--End of Box Bottom Border -->
	</table>	

	
	</body>
</html>

