<html>
<head>
<title>Attachment Blocking - Global Approved List</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!--BASE HREF="$$BASE_URL$$"-->
<link href="css/trend-style-new.css" rel="stylesheet" type="text/css">
<script language="JavaScript" src="javascripts/localization.js"></script>
<script language="JavaScript" src="javascripts/trend-ui-new.js"></script>
<script language="JavaScript" src="javascripts/OLH_Mapping.js"></script>
<script language="JavaScript" src="javascripts/Server_Role_Dependency.js"></script>
<script language="JavaScript" type="text/JavaScript">
<!--

// for Account String join
var lenLength = 6;
var lenType = 2;
var windowAccountImport = null;
    
function jsInitPage()
{
    // show exist account setting to select account list
	var vItem;
	var vTemp;
	var vIndex;
    
    jsAddExistAccount();
    
    setListboxUI(document.getElementById("lstAvailableAccount"),document.getElementById("divAvailableAccountInner"),document.getElementById("divAvailableAccountOuter"));
    setListboxUI(document.getElementById("lstSelectedAccount"),document.getElementById("divSelectedAccountInner"),document.getElementById("divSelectedAccountOuter"));
}
function jsSubmit()
{
    setOption2Selected(document.getElementById("lstSelectedAccount"));
    jsAddCSRFToken(document.fmMain);
    document.fmMain.submit();
}
function jsCancel()
{
	if(windowAccountImport!=null)windowAccountImport.close();
    document.fmMain.FormAction.value = "Cancel";
    jsAddCSRFToken(document.fmMain);
    document.fmMain.submit();
}
// For import and Export Account
function jsImportAddItem(name,value)
{
     var targetList = document.getElementById("lstExistAccount");
     setUIAddItemWithValue(name,value,targetList);
}
function jsImportAccount()
{
    windowAccountImport = window.open("$$IMPORT_ACCOUNT_PAGE$$","Global_Approved_List_Import","width=600,height=250,scrollbars=yes");
	windowAccountImport.opener = self;
}
function jsAddExistAccount()
{
    var srcList = document.getElementById("lstExistAccount");
    var sDetail="";
	for (var i=0;i<srcList.options.length;i++) {
		vTemp = srcList.options[i].value;    //type\tAccountstring
		vItem = vTemp.split(String.fromCharCode(9));
		var vName = srcList.options[i].innerText;
        var vValue = vItem[1];
		vIndex = setUIAddItemWithValue(vName,vValue,document.getElementById("lstSelectedAccount"));
		
        sDetail = setHTMLString(sDetail);
		switch(vItem[0])                                       //Account type:ad user,ad group,special group,smtp address
		{
		     case "0":
		       vTemp= "<img src='images/ad_user.gif' onmouseout='hideToolTip(\"ifmToolTip\");' onmouseover='showToolTip1(event,\"ifmToolTip\",300,100,\"Detail\",\"\");'>";//\"Detail\",\""+sDetail+"\");'> ";
		       break;
		    case "1":
		       vTemp = "<img src='images/ad_group.gif' onmouseout='hideToolTip(\"ifmToolTip\");' onmouseover='showToolTip1(event,\"ifmToolTip\",300,100,\"Detail\",\"\");'>";//\"Detail\",\""+sDetail+"\");'> ";
		       break;
		    case "2":
		       vTemp= "<img src='images/Special_group.gif' onmouseout='hideToolTip(\"ifmToolTip\");' onmouseover='showToolTip1(event,\"ifmToolTip\",300,100,\"Detail\",\"\");'>";//\"Detail\",\""+sDetail+"\");'> ";
		       break;
		}
		insertTableRowByIndex(document.getElementById("tabSelectedAccountList"),vTemp,"",vIndex);
    }
    setListboxUI(document.getElementById("lstSelectedAccount"),document.getElementById("divSelectedAccountInner"),document.getElementById("divSelectedAccountOuter"));
}
function jsExportAccount()
{
   var lstMatch="";
   var name="";
    for(var i=0;i<document.fmMain.lstSelectedAccount.length;i++)
    {
        var objOpt = document.fmMain.lstSelectedAccount.options[i];
        var value = objOpt.value;
        var type = value.substr(lenLength,lenType);
        if (parseInt(type) == 0)
        {
            name = objOpt.innerText;
			name = name.replace(/\n|\r/g,""); 
		//	lstMatch+=objOpt.innerText+":ADUser\n"; //Name:Type
			lstMatch+=name+":ADUser\n"; //Name:Type
        }
        else 
        if (parseInt(type) == 1)
        {
            name = objOpt.innerText;
			name = name.replace(/\n|\r/g,""); 
         //   lstMatch+=objOpt.innerText+":ADGroup\n"; //Name:Type
           lstMatch+=name+":ADGroup\n"; //Name:Type
        }        
    }    
	document.fmExport.account_list.value=lstMatch;
    jsAddCSRFToken(document.fmExport);
	document.fmExport.submit(); 
}
// For account search
function jsAddSelectedAccount() {
    var oSourceList = document.getElementById("lstAvailableAccount");
    var oList = document.getElementById("lstSelectedAccount");
    var oTable = document.getElementById("tabSelectedAccountList");

	var nCount = 0;
	for (var i=0;i<oSourceList.options.length;i++) {
		if (oSourceList.options[i].selected) 
		{
		    nCount++;
		    for(var j=0;j<oList.options.length;j++)
		    {
		       var LItem = oList.options[j].value.split(String.fromCharCode(9));
		       var SItem = oSourceList.options[i].value.split(String.fromCharCode(9));
		       var Lguid=LItem[1];
		       var Sguid=SItem[1];
		       if(Lguid==Sguid)
		       {   
		           oSourceList.options[i].selected=false;
		       }
		    }
		}
	}
	if (nCount==0) return;
	
	for (i=0;i<oSourceList.options.length;i++) {
		if (oSourceList.options[i].selected) 
		{
		   jsAddItemOnce(oList,oTable,oSourceList.options[i].value);
		}
	}
    setListboxUI(document.getElementById("lstAvailableAccount"),document.getElementById("divAvailableAccountInner"),document.getElementById("divAvailableAccountOuter"));
    setListboxUI(document.getElementById("lstSelectedAccount"),document.getElementById("divSelectedAccountInner"),document.getElementById("divSelectedAccountOuter"));

}

function jsRemoveSelectedAccount()
{
   jsRemove();
   setListboxUI(document.getElementById("lstSelectedAccount"),document.getElementById("divSelectedAccountInner"),document.getElementById("divSelectedAccountOuter"));
}
function jsRemove()
{
    var oList = document.getElementById("lstSelectedAccount");
    var oTable = document.getElementById("tabSelectedAccountList");

    for (var i=0;i<oList.options.length;i++) 
	{
		if (oList.options[i].selected)
		{
			oList.remove(i);
			oTable.deleteRow(i);
		  //  setListboxUI(document.getElementById("lstSelectedAccount"),document.getElementById("divSelectedAccountInner"),document.getElementById("divSelectedAccountOuter"));

            jsRemove();
		}
	}
   
}

function jsSearchAccount(txtKeyword) {
    var strKeyword = document.getElementById(txtKeyword).value;	
	document.getElementById("btnSearchAccount").disabled = true;
    var bAdUser = document.getElementById("chkUser").checked;
    var bAdGroup = document.getElementById("chkGroup").checked;
    if (!bAdUser &&  !bAdGroup) 
    {
        alert(STR_ALERT_SEARCHACCOUNT_NO_TYPE);
        document.getElementById("btnSearchAccount").disabled = false;
        return;
    }
	ifmAccount.jsGetAccount(strKeyword, bAdUser, bAdGroup);
}

function jsAddSearch() {
	if (window.ifmAccount.document.fmMain.txtResultCount.value > INT_NMAX_SEARCH_RESULT) {
		alert(STR_WARN_SEARCH_RESULT_OVER);
		window.ifmAccount.document.fmMain.lstResult.options.length = INT_NMAX_SEARCH_RESULT;
	}
	//alert(window.ifmAccount.document.fmMain.txtResultCount.value);
	// empty the list box
	document.getElementById("btnSearchAccount").disabled = false;
	jsClearList(document.getElementById("lstAvailableAccount"));
	
    for (var i=document.getElementById("tabAvailableAccountList").rows.length;i>0;i--) {
		    document.getElementById("tabAvailableAccountList").deleteRow(i-1);
	}
	document.getElementById("lstAvailableAccount").style.width = "";
	document.getElementById("lstAvailableAccount").style.height= "";
    	
	// Add Search List, [NAME][GUID][TYPE]
	var vItem;
	var vTemp;
	var vIndex;
    var sDetail="";

	for (var i=0;i<window.ifmAccount.document.fmMain.lstResult.options.length;i++) {
		vTemp = window.ifmAccount.document.fmMain.lstResult.options[i].value;
		vItem = vTemp.split(String.fromCharCode(9));
		var vName = vItem[0];
        
		vIndex = setUIAddItemWithValue(vName,vTemp,document.getElementById("lstAvailableAccount"));
		sDetail = setHTMLString(sDetail);
		switch(vItem[2])                                       //Account type:ad user,ad group,special group,smtp address
		{
		     case "0":
		       vTemp= "<img src='images/ad_user.gif' onmouseout='hideToolTip(\"ifmToolTip\");' onmouseover='showToolTip1(event,\"ifmToolTip\",300,100,\"Detail\",\"\");'>";//\"Detail\",\""+sDetail+"\");'> ";
		       break;
		    case "1":
		       vTemp = "<img src='images/ad_group.gif' onmouseout='hideToolTip(\"ifmToolTip\");' onmouseover='showToolTip1(event,\"ifmToolTip\",300,100,\"Detail\",\"\");'>";//\"Detail\",\""+sDetail+"\");'> ";
		       break;
		    case "2":
		       vTemp= "<img src='images/Special_group.gif' onmouseout='hideToolTip(\"ifmToolTip\");' onmouseover='showToolTip1(event,\"ifmToolTip\",300,100,\"Detail\",\"\");'>";//\"Detail\",\""+sDetail+"\");'> ";
		       break;
		}
		insertTableRowByIndex(document.getElementById("tabAvailableAccountList"),vTemp,"",vIndex);
	}
	//jsContactListUI(document.getElementById("lst"+oSearchlocal),document.getElementById("div"+oSearchlocal),document.getElementById("div"+oSearchlocal+"List"));
    setListboxUI(document.getElementById("lstAvailableAccount"),document.getElementById("divAvailableAccountInner"),document.getElementById("divAvailableAccountOuter"));
}
function insertTableRowByIndex(oTable,sText,sValue,nIndex) {
	if (oTable == null || sText == "" || nIndex < 0) { return; }
	
	var oRow = oTable.insertRow(nIndex);
	var oCell = oRow.insertCell(0);
	oCell.className = "listNormal";
	oCell.innerHTML = sText;
	oCell.title = sValue;
}
// like "    32 08478a42db8cf3140a5ff23c95c1aa65f"
function joinAccountString(vtype,vguid)
{
    var iLen = vguid.length;
    var retValue="";
        
    //the first 6 bytes used to recode the lenght of each item.   
	var nLen=iLen;
	var j=0;
    if (nLen == 0)j =1;
    else
    {
	    while(parseInt(nLen)/10!=0) 
        {
            nLen=parseInt(nLen)/10;
            j++;
        }
    }
    for(;j<lenLength;j++)       
        retValue+=" ";
    retValue+=iLen;
    
    j=0;
    nLen = vtype;
    if (nLen == 0)j =1;
    else
    {
	    while(parseInt(nLen)/10!=0) 
        {
            nLen=parseInt(nLen)/10;
            j++;
        }
    }
    for(;j<lenType;j++)       
        retValue+=" ";
    retValue+=vtype;

    retValue+=vguid;
    return retValue; 
}
function jsAddItemOnce(oList, oTable, ItemValue)
{
    var vItem;
    var vTemp;
    var vIndex;
    var sDetail="";
    
    vTemp = ItemValue;
    vItem = vTemp.split(String.fromCharCode(9));
    var vName = vItem[0];
	var vGuid = vItem[1];
    var vType = vItem[2];
    var vValue = joinAccountString(vType,vGuid);
    
    vIndex = setUIAddItemWithValue(vName,vValue,oList);
   
    sDetail = setHTMLString(sDetail);
    switch(vItem[2])                                       //Account type:ad user,ad group,special group,smtp address
	{
	    case "0":
	       vTemp = "<img src='images/ad_user.gif' onmouseout='hideToolTip(\"ifmToolTip\");' onmouseover='showToolTip1(event,\"ifmToolTip\",300,100,\"Detail\",\"\");'>"; // \"Detail\",\""+sDetail+"\");'> ";
	       break;
	    case "1":
	       vTemp = "<img src='images/ad_group.gif' onmouseout='hideToolTip(\"ifmToolTip\");' onmouseover='showToolTip1(event,\"ifmToolTip\",300,100,\"Detail\",\"\");'>"; // \"Detail\",\""+sDetail+"\");'> ";
	       break;
	    case "2":
	       vTemp = "<img src='images/Special_group.gif' onmouseout='hideToolTip(\"ifmToolTip\");' onmouseover='showToolTip1(event,\"ifmToolTip\",300,100,\"Detail\",\"\");'>"; // \"Detail\",\""+sDetail+"\");'> ";
	       break;
	} 
    insertTableRowByIndex(oTable,vTemp,"",vIndex); 

}
function jsClearList(oTarget) {
	// Clear List
	for (var i=oTarget.length;i>0;i--) {
		oTarget.remove(i-1);
	}
}
 
//-->
</script>

</head>
<body onLoad="jsInitPage();">
<form id="fmMain" name="fmMain" action="$$FORM_ACTION$$" method="POST">
<input type="Hidden" name="FormAction" value="save">
<!--Page Title-->
<input type="hidden" id="ExceptionsString" name="ExceptionsString" value="">
<input type="hidden" id="DelExceptionIds" name="DelExceptionIds" value="">
<input type="hidden" id="txtSSTaskName" name="txtSSTaskName" value="$$SS_TASK_NAME$$" />
<input type="hidden" id="txtSSTaskBehavior" name="txtSSTaskBehavior" value="$$SS_TASK_BEHAVIOR$$" />
<table width="650" border="0" cellspacing="0" cellpadding="0">
<tr><td class="content-title">$$AB_CONTENT_TITLE$$: Edit Global Approved List</td>
	<td align="right" valign="bottom">
		<a href="javascript:jsMapOnlineHelp('scan\global_approved_list.htm');" class="moretestblue">
		<img src="images/question.gif" border="0"> Help</a></td></tr>
<tr><td colspan="2" height="4"></td></tr>
<tr><td colspan="2" height="1" background="images/dot.gif"></td></tr>
<tr><td colspan="2" height="10"></td></tr>
</table>
<!--/Page Title-->

<table width="650" border="0" cellpadding="0" cellspacing="0">
   <tr id="subTitle_newPolicy"><td  class="data1"><a href="javascript:jsCancel();"><u>Policy List </u></a>&gt; Global Approved List</td></tr>
   <tr><td  height="10"></td></tr>
   <tr><td width="100%" class="button"> 
       <input name="chkEnable" id="chkEnable" type="checkbox" $$OPT_GLOBAL_APPROVED_LIST_ENABLED$$ /> 
       Enable global approved list</td></tr>
   <tr><td  height="10"></td></tr>
        
    <tr><td>
        <table id="specifyAccounts" width="100%" border="0" cellpadding="0" cellspacing="0" class="border">
        <tr><td class="tableheadergreyS" >Select Accounts</td></tr>
		<tr><td height="5" ></td></tr>
		
		<tr><td>
            <table>
            <tr><td colspan="2" class="data1">Search for AD user(s)/group(s):</td></tr>
            <tr><td colspan="2"><input type=text class="text" id="txtSearch" name="txtSearch" style="width:220" ><input type=button class="text" value="Search" id="btnSearchAccount" name="btnSearchAccount" onClick="jsSearchAccount('txtSearch');"></td></tr>
		    <tr><td colspan="2">Search in:&nbsp;</td></tr>
	        <tr><td colspan="2"><table border="0" cellspacing="0" cellpadding="0"><tr>
                <td><input type=checkbox id="chkUser" name="chkUser" CHECKED></td><td>&nbsp;Users</td>
	            <td><input type=checkbox id="chkGroup" name="chkGroup" CHECKED></td><td>&nbsp;Groups</td></tr></table>
	        </td></tr>
            <tr><td>&nbsp;</td>
		        <td>
                <table id="tabSpecial" width="100%" border="0" cellpadding="0" cellspacing="0">					
		        <tr><td class="data1">
                    <table  id="tab1" width="280" height="240" class="border" cellpadding="0" cellspacing="0" >
					<tr><td class="grey-end" height="18">Avaliable Account(s)</td></tr>
					<tr><td>
                        <div id="divAvailableAccountOuter" style="overflow:auto;width:280;height:240">
						<table  border="0" cellpadding="0" cellspacing="0">
						<tr><td valign="top">
                            <table id="tabAvailableAccountList" border="0" cellpadding="0" cellspacing="0">
                            </table>
                            </td>
							<td valign="top" width="100%">
                            <div id="divAvailableAccountInner" style="position:relative;overflow:hidden;width:100%">
							<select id="lstAvailableAccount" name="lstAvailableAccount" multiple style="position:relative;top:-3;left:-3;font-size:13px;">
							</select>
                            </div>
                            </td>
                        </tr>
						</table>
                        </div>
                    </td></tr>
					</table>
					</td> 
					<td>
                    <table id="tab1_button">
                    <tr>
                    <td class="data1" valign="middle">
						<input type=button id="tab1_add" class="text" value="Add &gt;&gt;"  style="width:80px" onClick="jsAddSelectedAccount();"><br/>
						<input type=button id="tab1_remove"class="text" value="&lt;&lt; Remove" style="width:80px" onClick="jsRemoveSelectedAccount();">
                    </td></tr>
				    <tr height="40px"><td></td></tr>	
                    <tr>
                    <td class="data1" valign="middle">
						<input type=button id="tab1_import" class="text" value="Import"  style="width:80px" onClick="jsImportAccount();"><br/>
						<input type=button id="tab1_export" class="text" value="Export"  style="width:80px" onClick="jsExportAccount();">
                    </td></tr>
					</table>
					</td>      
					<td>
                    <table width="280" height="240" border="0" cellpadding="0" cellspacing="0" class="border">
					<tr><td class="grey-end" height="18">Selected Account(s)</td></tr>
					<tr><td valign="top">
                        <div id="divSelectedAccountOuter" style="overflow:auto;width:280;height:240;position:relative">
					    <table  border="0" cellpadding="0" cellspacing="0">
					    <tr><td  valign="top">
                            <table id="tabSelectedAccountList" border="0" cellpadding="0" cellspacing="0" valign="top">
                            </table>
                            </td>								                     
					    	<td valign="top" width="100%">
							<div id="divSelectedAccountInner" style="position:relative;overflow:hidden;width:100%">	
                            <select id="lstSelectedAccount" name="lstSelectedAccount" style="position:relative;top:-3;left:-3;font-size:13px;" multiple>
                            
                            </select>
                            <select id="lstExistAccount" style="display:none">$$EXIST_ACCOUNT_SETTING$$</select>
                            </div>
                            </td>
					    </tr>
                        </table>
					    </div>
                    </td></tr>
					</table>
					</td>
					<td>&nbsp;</td>
			    </tr>
				</table>
            </td></tr>
			</table>
        </td></tr>
						         
		<tr><td height="10" ></td></tr>
		<tr><td height="1"  background="images/dot.gif"></td></tr>
		
	 	<tr><td>
            <table>
            <tr>
                <td nowrap><img src="images/ad_user.gif" alt="AD Users" align="absmiddle"></td>
                <td nowrap class="data1"><span>-AD Users</span></td>
                <td width="22" align="right" nowrap><img src="images/ad_group.gif" alt="AD Groups" align="absmiddle"></td>
                <td nowrap class="data1"><span>-AD Groups</span></td>
            </tr>	
	 	    </table>
        </td></tr>
        
        </table>
    </td></tr>
</table>


<table id="tblButton" width="540" border="0" cellspacing="0" cellpadding="0"> 
  <tr> 
    <td height="28" valign="bottom">
      <input name="submitButton" id="submitButton" type="button" class="button" onClick="jsSubmit()" value="Save" style="width:50px">  
&nbsp;
      <input id="btnCancel" name="btnCancel" type="button" class="button" onClick="jsCancel()" value="Cancel" style="width:50px">
    </td> 
  </tr> 
</table>


</form>
<form action="$$EXPORT_FORM_ACTION$$" method="POST" id="fmExport" name="fmExport" target="iFrameForExportWBList">
<input type="hidden" name="account_list" id="account_list">
</form>

<iframe id="ifmAccount" name="ifmAccount" src="$$ACCOUNT_SEARCH_CGI_URL$$" frameBorder="0" width="0" height="0" style="display:none"/>
<iframe id="ifmToolTip" name="ifmToolTip" src="html/ToolTip.htm" frameborder="0" style="z-index:10000;position:absolute;width:0;height:0;overflow:hidden"/>
</body>
</html>


