<!DOCTYPE HTML >
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<title></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_objDisableItemsButton;
			
			var DISABLED_ITEMS_LIST_ID=1;
			var ENABLED_ITEMS_LIST_ID=2;
			
			var FEATURES_HEADER=g_MqRef.RESX["HEADER_FEATURES"];
			var FEATURES_DESC=g_MqRef.RESX["USERMGR_FEATURE_DESC"];
			var FEATURES_TITLE=g_MqRef.RESX["USERMGR_FEATURES_TITLE"];
			var FEATURES_ENABLED_LIST_TITLE=g_MqRef.RESX["FEATURES_ENABLED_TITLE"];
			var FEATURES_DISABLED_LIST_TITLE=g_MqRef.RESX["FEATURES_DISABLED_TITLE"];
			var FEATURES_IMAGE_PATH="../../../Theme/images/images/features48.gif";
			var PROJECTS_HEADER=g_MqRef.RESX["HEADER_PROJECTS"];
			var PROJECTS_DESC=g_MqRef.RESX["USERMGR_PROJECTS_DESC"];
			var PROJECTS_TITLE=g_MqRef.RESX["USERMGR_PROJECTS_TITLE"];
			var PROJECTS_ENABLED_LIST_TITLE=g_MqRef.RESX["PROJECTS_ENABLED_TITLE"];
			var PROJECTS_DISABLED_LIST_TITLE=g_MqRef.RESX["PROJECTS_DISABLED_TITLE"];
			var PROJECTS_IMAGE_PATH="../../../Theme/images/images/projects48.gif";
			var USERS_HEADER=g_MqRef.RESX["HEADER_USERS"];
			var USERS_DESC=g_MqRef.RESX["USERMGR_USERS_DESC"];
			var USERS_TITLE=g_MqRef.RESX["USERMGR_USERS_TITLE"];
			var USERS_ENABLED_LIST_TITLE=g_MqRef.RESX["USERMGR_USERS_ENABLED_TITLE"];
			var USERS_DISABLED_LIST_TITLE=g_MqRef.RESX["USERMGR_USERS_DISABLED_TITLE"];
			var USERS_IMAGE_PATH="../../../Theme/images/images/users48.gif";
			
			var BTN_DISABLE_ITEMS="DisableItems";
			var BTN_ENABLE_ITEMS="EnableItems";
			
			var GROUP_LIST_DELIM=";";
			
			var MSG_LOSE_CHANGES=g_MqRef.RESX["MSG_LOSE_CHANGES"];

			// If want to disallow removing features from Admins, uncomment the lines below and comment the one after
 			
			//var m_arrUnremovableGroups_Features="<WC@UNREMOVEABLE_GROUPS_FEATURES>GROUP_LIST_DELIM</WC@UNREMOVEABLE_GROUPS_FEATURES>".split(GROUP_LIST_DELIM);
			var m_arrUnremovableGroups_Features=new Array();

			//var m_arrUnremovableGroups_Projects="<WC@UNREMOVEABLE_GROUPS_PROJECTS>GROUP_LIST_DELIM</WC@UNREMOVEABLE_GROUPS_PROJECTS>".split(GROUP_LIST_DELIM);
			var m_arrUnremovableGroups_Projects=new Array();

			//var m_arrUnremovableGroups_Users="<WC@UNREMOVEABLE_GROUPS_USERS>GROUP_LIST_DELIM</WC@UNREMOVEABLE_GROUPS_USERS>".split(GROUP_LIST_DELIM);
			var m_arrUnremovableGroups_Users=new Array();
			
			var m_strDisabledItems="<WC@DISABLED_ITEMS></WC@DISABLED_ITEMS>";
			var m_strEnabledItems="<WC@ENABLED_ITEMS></WC@ENABLED_ITEMS>";
			
			
			var m_arrChangedItems_Enabled=new Array();
			var m_arrChangedItems_Disabled=new Array();
			
			var m_arrEnabledItems=new Array();
			var m_arrDisabledItems=new Array();
			
			var m_objEnabledItemsList=new CMqFormElement();
			var m_objDisabledItemsList=new CMqFormElement();
			
			var ASC_IMG_PATH = "../../../Theme/images/images/sortasc.gif";
			var DESC_IMG_PATH = "../../../Theme/images/images/sortdesc.gif";
			
			var m_lngType;
			var m_strGroupName;
			
			var m_blnIsDirty=false;
			
			function FormOnLoad()
			{
				InitializeListItemValues();
				
				LoadFormDisplaySettings();				
				
				m_objEnabledItemsList.Initialize("lstEnabledItems", CTRL_TYPE_LIST, "document");
				m_objDisabledItemsList.Initialize("lstDisabledItems", CTRL_TYPE_LIST, "document");
				
				LoadLists(m_arrEnabledItems, m_arrDisabledItems);	
				
				m_objDisableItemsButton=document.getElementById(m_objMqButton.GetButtonHTMLName(BTN_DISABLE_ITEMS));
			}
			
			function LoadFormDisplaySettings()
			{
				var strHeaderText="";
				var strInstructionsText="";
				var strTitleText="";
				var strEnabledListTitle="";
				var strDisabledListTitle="";
				var strPropImgPath="";
				
				m_lngType=g_MqRef.MqStr.GetQueryStringValue(location.search, "Type");
				m_strGroupName=g_MqRef.MqStr.GetQueryStringValue(location.search, "Group");
				
				if(m_lngType==SHOW_FEATURES_TYPE){
					strHeaderText=FEATURES_HEADER;
					strInstructionsText=FEATURES_DESC;
					strTitleText=FEATURES_TITLE;
					strEnabledListTitle=FEATURES_ENABLED_LIST_TITLE;
					strDisabledListTitle=FEATURES_DISABLED_LIST_TITLE;
					strPropImgPath=FEATURES_IMAGE_PATH;
				}else{
					if(m_lngType==SHOW_PROJECTS_TYPE){
						strHeaderText=PROJECTS_HEADER;
						strInstructionsText=PROJECTS_DESC;
						strTitleText=PROJECTS_TITLE;
						strEnabledListTitle=PROJECTS_ENABLED_LIST_TITLE;
						strDisabledListTitle=PROJECTS_DISABLED_LIST_TITLE;
						strPropImgPath=PROJECTS_IMAGE_PATH;
					}else{
						if(m_lngType==SHOW_USERS_TYPE){
							strHeaderText=USERS_HEADER;
							strInstructionsText=USERS_DESC;
							strTitleText=USERS_TITLE;
							strEnabledListTitle=USERS_ENABLED_LIST_TITLE;
							strDisabledListTitle=USERS_DISABLED_LIST_TITLE;
							strPropImgPath=USERS_IMAGE_PATH;
						}
					}
				}
				
				var objHeader=document.getElementById("HeaderTitle");
				if(objHeader){
					objHeader.innerHTML=strHeaderText;
				}
				
				var objInstructions=document.getElementById("InstructionsText");
				if(objInstructions){
					strInstructionsText=g_MqRef.MqStr.FormatString(strInstructionsText, m_strGroupName);
					objInstructions.innerHTML=strInstructionsText;
				}
				
				var objDisabledItemsListHeader=document.getElementById("DisHeader");
				if(objDisabledItemsListHeader){
					objDisabledItemsListHeader.innerHTML=strDisabledListTitle + " <img id='imgSortDis' src='" + 
							ASC_IMG_PATH + "'>";
				}

				var objEnabledItemsListHeader=document.getElementById("EnHeader");
				if(objEnabledItemsListHeader){
					objEnabledItemsListHeader.innerHTML=strEnabledListTitle + " <img id='imgSortEn' src='" + 
							ASC_IMG_PATH + "'>";
				}
				
				var objPropImage=document.getElementById("PropImage");
				if(objPropImage){
					objPropImage.innerHTML="<img src='" + strPropImgPath + "'>";
				}
				
				document.title=g_MqRef.MqStr.FormatString(strTitleText, m_strGroupName);
				
				SetListsHeight();
				HandleMoveButtons(m_strGroupName, m_lngType);
			}
			
			function InitializeListItemValues()
			{
				var lngCount;
				var lngElementCount=0;
				var arrAllEnabled=m_strEnabledItems.split(GROUP_LIST_DELIM);
				var arrAllDisabled=m_strDisabledItems.split(GROUP_LIST_DELIM);
				
				
			
				if(m_strEnabledItems!=""){
					m_arrEnabledItems.length=arrAllEnabled.length/2;
					for(lngCount=0; lngCount<arrAllEnabled.length; lngCount+=2){
						m_arrEnabledItems[lngElementCount]=new Array(arrAllEnabled[lngCount], g_MqRef.MqStr.MqDecodeURIComponent(arrAllEnabled[lngCount+1]));
						lngElementCount++;
					}
				}
								
				if(m_strDisabledItems!=""){
					m_arrDisabledItems.length=arrAllDisabled.length/2;
					lngElementCount=0;
				
					for(lngCount=0; lngCount<arrAllDisabled.length; lngCount+=2){
						m_arrDisabledItems[lngElementCount]=new Array(arrAllDisabled[lngCount], g_MqRef.MqStr.MqDecodeURIComponent(arrAllDisabled[lngCount+1]));
						lngElementCount++;
					}
				}
			}
			
			function HandleMoveButtons(strGroupName, lngType)
			{
				var arrGroups;
				var lngCount;
				var blnFound=false;
				
				if(lngType==SHOW_FEATURES_TYPE){
					arrGroups=m_arrUnremovableGroups_Features;
				}else{
					if(lngType==SHOW_PROJECTS_TYPE){
						arrGroups=m_arrUnremovableGroups_Projects;
					}else{
						if(lngType==SHOW_USERS_TYPE){
							arrGroups=m_arrUnremovableGroups_Users;
						}
					}
				}	

				if(arrGroups){
					for(lngCount=0; lngCount<arrGroups.length; lngCount++){
						if(arrGroups[lngCount]==strGroupName){
							blnFound=true;
							break;
						}
					}
					
					if(blnFound){
						m_objMqButton.DisableButton(BTN_DISABLE_ITEMS);
					}
				}
				
				if(m_arrDisabledItems.length>0){
					m_objMqButton.EnableButton(BTN_ENABLE_ITEMS);
				}else{
					m_objMqButton.DisableButton(BTN_ENABLE_ITEMS);
				}
				
				if(!blnFound){
					if(m_arrEnabledItems.length>0){
						m_objMqButton.EnableButton(BTN_DISABLE_ITEMS);
					}else{
						m_objMqButton.DisableButton(BTN_DISABLE_ITEMS);
					}
				}
			}
			
			function LoadLists(arrEnabledItems, arrDisabledItems)
			{
				m_objDisabledItemsList.SetPossibleValues(arrDisabledItems, false);
				m_objEnabledItemsList.SetPossibleValues(arrEnabledItems, false);
			}
			
			function Enable()
			{
				var arrSelectedItems=GetSelectedRows(DISABLED_ITEMS_LIST_ID);
				var lngCount;
				var lngIndex;
				var strItemID;
				var strItemValue;
				var arrItem;
				
				for(lngCount=0; lngCount<arrSelectedItems.length; lngCount++){
					arrItem=arrSelectedItems[lngCount];
					strItemID=arrItem[ID_ELEMENT];
					strItemValue=arrItem[VALUE_ELEMENT];
					
					if(!g_MqRef.MqArr.IsValueInArray(strItemID, m_arrChangedItems_Enabled)){
						lngIndex=m_arrChangedItems_Enabled.length;
						m_arrChangedItems_Enabled.length++;
						m_arrChangedItems_Enabled[lngIndex]=strItemID;
					}
						
					if(g_MqRef.MqArr.IsValueInArray(strItemID, m_arrChangedItems_Disabled)){
						lngIndex=g_MqRef.MqArr.GetIndex(strItemID, m_arrChangedItems_Disabled);
						m_arrChangedItems_Disabled.splice(lngIndex, 1);
					}
						
					RemoveItemFromArray(strItemID, m_arrDisabledItems);
					AddItemToArray(strItemID, strItemValue, m_arrEnabledItems);
				}
				
				if(arrSelectedItems.length>0){		
					SortCol(ENABLED_ITEMS_LIST_ID, true);
					m_objDisabledItemsList.SetPossibleValues(m_arrDisabledItems, false);
					HandleMoveButtons(m_strGroupName, m_lngType);
					m_blnIsDirty=true;
				}
			}
			
			function Disable()
			{
				var blnDoDisable=true;
				if(m_objDisableItemsButton){
					if(m_objMqButton.IsDisabled(m_objDisableItemsButton)){
						blnDoDisable=false;
					}
				}
				if(blnDoDisable){
					var arrSelectedItems=GetSelectedRows(ENABLED_ITEMS_LIST_ID);
					var lngCount;
					var lngIndex;
					var strItemID;
					var strItemValue;
					var arrItem;
						
					for(lngCount=0; lngCount<arrSelectedItems.length; lngCount++){
						arrItem=arrSelectedItems[lngCount];
						strItemID=arrItem[ID_ELEMENT];
						strItemValue=arrItem[VALUE_ELEMENT];
							
						if(!g_MqRef.MqArr.IsValueInArray(strItemID, m_arrChangedItems_Disabled)){
							lngIndex=m_arrChangedItems_Disabled.length;
							m_arrChangedItems_Disabled.length++;
							m_arrChangedItems_Disabled[lngIndex]=strItemID;
						}
							
						if(g_MqRef.MqArr.IsValueInArray(strItemID, m_arrChangedItems_Enabled)){
							lngIndex=g_MqRef.MqArr.GetIndex(strItemID, m_arrChangedItems_Enabled);
							m_arrChangedItems_Enabled.splice(lngIndex, 1);
						}
						RemoveItemFromArray(strItemID, m_arrEnabledItems);
						AddItemToArray(strItemID, strItemValue, m_arrDisabledItems);
					}
				
					if(arrSelectedItems.length>0){
						SortCol(DISABLED_ITEMS_LIST_ID, true);
						m_objEnabledItemsList.SetPossibleValues(m_arrEnabledItems, false);
						HandleMoveButtons(m_strGroupName, m_lngType);
						m_blnIsDirty=true;
					}
				}
			}
						
			function GetSelectedRows(lngListID)
			{
				var objList=GetFormElement(lngListID);

				return objList.GetSelectedValues();
			}
						
			function GetFormElement(lngListID)
			{
				var objList;
				if(lngListID==DISABLED_ITEMS_LIST_ID){
					objList=m_objDisabledItemsList;
				}else{
					if(lngListID==ENABLED_ITEMS_LIST_ID){
						objList=m_objEnabledItemsList;
					}
				}
				return objList;
			}
			
			function GetList(lngListID)
			{
				var objList;
				if(lngListID==DISABLED_ITEMS_LIST_ID){
					objList=document.getElementById("lstDisabledItems");
				}else{
					if(lngListID==ENABLED_ITEMS_LIST_ID){
						objList=document.getElementById("lstEnabledItems");
					}
				}
				return objList;
			}
			
			function ApplyGroupProps()
			{
				
				var strDisabled = m_arrChangedItems_Disabled.join(GROUP_LIST_DELIM);
				var strEnabled = m_arrChangedItems_Enabled.join(GROUP_LIST_DELIM);

				var objRequest=opener.mobjHTTPrequest;	
				var strCurrentLocation=opener.mstrCurrentLocation;
				
				if(objRequest){
					var co=objRequest.Post(strCurrentLocation + "WCCMqUserMgr.ASP?WCI=wciDoSetGroupProps&Referrer=AdminReferrer", 
								"Group=" + g_MqRef.MqStr.MqEncodeURIComponent(m_strGroupName) + "&Type=" + m_lngType + "&Dis=" 
								+ strDisabled + "&En=" + strEnabled);
				
					if (co!=objRequest.CANCEL_PROCESS){
								
						var objResponse=objRequest.Response(co);
						if (objResponse){
							if (objResponse.HasErrors()){
								objResponse.ProcessErrors("",true);
							}else{
								window.close();
							}
						}
					}
				}
			}
			
			function OnClose()
			{
				if(m_blnIsDirty){
					if(window.confirm(MSG_LOSE_CHANGES)){
						ApplyGroupProps();
					}else{
						window.close();
					}
				}else{
					window.close();
				}
			}
			
			function SortCol(lngListID, blnKeepCurrentSort)
			{
				var objHeader;
				var objImg;
				var arrListArray;
				var objFormElementList=GetFormElement(lngListID);
				
				if(lngListID==DISABLED_ITEMS_LIST_ID){
					objHeader=document.getElementById("DisHeader");
					objImg=document.getElementById("imgSortDis");
					arrListArray=m_arrDisabledItems;
				}else{
					if(lngListID==ENABLED_ITEMS_LIST_ID){
						objHeader=document.getElementById("EnHeader");
						objImg=document.getElementById("imgSortEn");
						arrListArray=m_arrEnabledItems;
					}
				}
				SortListValues(objFormElementList, objHeader, objImg, arrListArray, blnKeepCurrentSort, false);
			}
			
			function FormOnResize()
			{	
				SetListsHeight();
			}
			
			function SetListsHeight()
			{
				var intBodyHeight;
				// 143= 85 (top position of list) + 58 (bottom buttons + extra margin at the bottom)
				var NON_LIST_SPACE=143;
				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);
				
				var objEnabledItemsList=GetList(ENABLED_ITEMS_LIST_ID);
				var objDisabledItemsList=GetList(DISABLED_ITEMS_LIST_ID);
				
				if(strNewHeight>0){
					if(objEnabledItemsList){
						objEnabledItemsList.style.height=strNewHeight+ "px";
					}
					if(objDisabledItemsList){
						objDisabledItemsList.style.height=strNewHeight+ "px";
					}
				}
			}
		//-->
		</script>

</head>
<body class="RecordBody" style="margin: 10px" marginheight="0" marginwidth="0" topmargin="0" leftmargin="0" 
		onload="FormOnLoad()" onresize="FormOnResize()" style="overflow:auto">
	<table border="0">
		<tr>
			<td rowspan="2">
				<div id="PropImage"></div>
			</td>
			<td>
				<div id="HeaderTitle" class="TaskLinkTitle"></div>
			</td>
		</tr>
		<tr>
			<td>
				<div id="InstructionsText" class="TaskLinkDescription"></div>
			</td>
		</tr>
	</table>
	
	<table width="100%" border="0" >
		<tr>
			<td width="40%" style="vertical-align: top">
					<div id="DisHeader" id="HeaderTitle" class="ListHeader" 
			onmouseover="this.className='ListHeader ListHeaderOver';" onmouseout="this.className='ListHeader';" onclick="SortCol(DISABLED_ITEMS_LIST_ID, false);" MqSort="asc"></div>
				<div style="top:85px" id="DisabledItems" class="ListBorder">
		<select class="ListStyle" name="lstDisabledItems" id="lstDisabledItems" multiple
			onkeypress="m_MqAutoList.OnKeyPress()" onclick="m_MqAutoList.OnClick()" onblur="m_MqAutoList.OnBlur()" ondblclick="Enable()"></select>
	</div>
			</td>
			<td width="20%" style="vertical-align: center;">
				<div  id="Buttons" align="center">
					<script type="text/javascript">
					<!--
						m_objMqButton.WriteButtonHTML(BTN_ENABLE_ITEMS,"Enable();","MoveRight",false,m_objMqButton.STATE_1,g_MqRef.RESX["USERSMGR_BUTTON_ENABLE_ITEM"]);
						document.write("<br />");
						m_objMqButton.WriteButtonHTML(BTN_DISABLE_ITEMS,"Disable();","MoveLeft",false,m_objMqButton.STATE_1,g_MqRef.RESX["USERSMGR_BUTTON_DISABLE_ITEM"]);
						
					//-->
					</script>
				</div>
			</td>
			<td width="40%" style="vertical-align: top">
					<div id="EnHeader" id="HeaderTitle" class="ListHeader" 
			onmouseover="this.className='ListHeader ListHeaderOver';" onmouseout="this.className='ListHeader';" onclick="SortCol(ENABLED_ITEMS_LIST_ID, false);" MqSort="asc"></div>
				<div style="top:85px;" id="EnabledItems" class="ListBorder">
		<select class="ListStyle" name="lstEnabledItems" id="lstEnabledItems" multiple
			onkeypress="m_MqAutoList.OnKeyPress()" onclick="m_MqAutoList.OnClick()" onblur="m_MqAutoList.OnBlur()" ondblclick="Disable()"></select>
	</div>
			</td>
		</tr>
	</table>
	<div style="position:absolute; right:10px; bottom:10px">
		<table><tr><td>
			<script type="text/javascript">
			<!--
				m_objMqButton.WriteButtonHTML("OK","ApplyGroupProps();","OK",false,m_objMqButton.STATE_1,g_MqRef.RESX["BUTTON_OK"]);
			//-->
			</script>	
		</td><td>
			<script type="text/javascript">
			<!--
				m_objMqButton.WriteButtonHTML("Close","OnClose();","Close",false,m_objMqButton.STATE_1,g_MqRef.RESX["BUTTON_CLOSE"]);
			//-->
			</script>
		</td></tr></table>
	</div>
</body>

</html>