<%@ page language="java" %> 
<%@ page import="com.iplanet.jato.view.ViewBean" %>
<%@taglib uri="/WEB-INF/tld/com_iplanet_jato/jato.tld" prefix="jato"%> 
<%@taglib uri="/WEB-INF/tld/com_sun_web_ui/cc.tld" prefix="cc"%>

<%
    String formName = (request.getParameter("formName") != null)
	? request.getParameter("formName")
	: "";

    String pageTitle = (request.getParameter("pageTitle") != null)
	? request.getParameter("pageTitle")
	: "";
%>

<jato:pagelet>

<script language="javascript">

function initValues() {
    // Form names.
    var tf = document.eventFilterForm;
    var pf = window.opener.document.<%=formName %>;

    // Parent window hidden field name.
    var hostHFName = 
	"<cc:text name='HostHiddenFieldNameText'/>";
    var categoryHFName = 
	"<cc:text name='CategoryHiddenFieldNameText'/>";
    var severityHFName = 
	"<cc:text name='SeverityHiddenFieldNameText'/>";
    var maxSizeHFName = 
	"<cc:text name='MaxSizeHiddenFieldNameText'/>";	
     var aggrHFName = 
	"<cc:text name='AggrHiddenFieldNameText'/>";
    var eventTypeHFName = 
	"<cc:text name='EventTypeHiddenFieldNameText'/>";
    var eventBigTypeHFName = 
	"<cc:text name='EventBigTypeHiddenFieldNameText'/>";	
    var filter1HFName = 
	"<cc:text name='Filter1HiddenFieldNameText'/>";

    var host = pf.elements[hostHFName];
    var severity = pf.elements[severityHFName];
    var eventType = pf.elements[eventTypeHFName];
    var eventBigType = pf.elements[eventBigTypeHFName];
    var maxSize = pf.elements[maxSizeHFName];
    var aggr = pf.elements[aggrHFName];
    var category = pf.elements[categoryHFName];
    var filter1 = pf.elements[filter1HFName];

    // Menu name.
    var hostMenu = 
	tf.elements["<cc:text name='HostMenuNameText'/>"];
    var severityMenu = 
	tf.elements["<cc:text name='SeverityMenuNameText'/>"];
    var categoryMenu =              
	tf.elements["<cc:text name='CategoryMenuNameText'/>"];
    var eventTypeMenu = 
	tf.elements["<cc:text name='EventTypeMenuNameText'/>"];
    var eventBigTypeMenu = 
	tf.elements["<cc:text name='EventBigTypeMenuNameText'/>"];
    var maxSizeMenu = 
	tf.elements["<cc:text name='MaxSizeMenuNameText'/>"];	
    var aggrMenu = 
	tf.elements["<cc:text name='AggrMenuNameText'/>"];	
    
    // field name
    var filter1Field = tf.elements["<cc:text name='Filter1FieldNameText'/>"];	

    setSelection(hostMenu, host);
    setSelection(eventTypeMenu, eventType);
    setSelection(eventBigTypeMenu, eventBigType);
    setSelection(categoryMenu, category);
    setSelection(severityMenu, severity);  
    setSelection(maxSizeMenu, maxSize);
    setSelection(aggrMenu, aggr);

    filter1Field.value = filter1.value;      
}

function setSelection(select, element) {
    for (var i = 0; i < select.options.length; i++) {
          if (select.options[i].value == element.value) {
	        select.options[i].selected = true;
	        break;
	  }            
    }
}

function submitValues() {
    // Form names.
    var tf = document.eventFilterForm;
    var pf = window.opener.document.<%=formName %>;

    // Command child name.
    var commandChildName = "<cc:text name='FilterCommandNameText'/>";

    // Parent window hidden field name.
    var hostHFName = 
	"<cc:text name='HostHiddenFieldNameText'/>";
    var categoryHFName = 
	"<cc:text name='CategoryHiddenFieldNameText'/>";
    var severityHFName = 
	"<cc:text name='SeverityHiddenFieldNameText'/>";
    var maxSizeHFName = 
	"<cc:text name='MaxSizeHiddenFieldNameText'/>";	
    var aggrHFName = 
	"<cc:text name='AggrHiddenFieldNameText'/>";	
    var eventTypeHFName = 
	"<cc:text name='EventTypeHiddenFieldNameText'/>";
    var eventBigTypeHFName = 
	"<cc:text name='EventBigTypeHiddenFieldNameText'/>";	
    var filter1HFName = 
	"<cc:text name='Filter1HiddenFieldNameText'/>";


    // Menu name.
    var hostMenu = 
	tf.elements["<cc:text name='HostMenuNameText'/>"];
    var severityMenu = 
	tf.elements["<cc:text name='SeverityMenuNameText'/>"];
    var categoryMenu = 
	tf.elements["<cc:text name='CategoryMenuNameText'/>"];
    var eventTypeMenu = 
	tf.elements["<cc:text name='EventTypeMenuNameText'/>"];
    var eventBigTypeMenu = 
	tf.elements["<cc:text name='EventBigTypeMenuNameText'/>"];
    var maxSizeMenu = 
	tf.elements["<cc:text name='MaxSizeMenuNameText'/>"];
    var aggrMenu = 
	tf.elements["<cc:text name='AggrMenuNameText'/>"];

    // field name
    var filter1Field = tf.elements["<cc:text name='Filter1FieldNameText'/>"];	


    pf.elements[hostHFName].value =
	    hostMenu.options[hostMenu.selectedIndex].value;
    
    pf.elements[severityHFName].value =
	    severityMenu.options[severityMenu.selectedIndex].value;
   
    pf.elements[categoryHFName].value =
	    categoryMenu.options[categoryMenu.selectedIndex].value;
   
    pf.elements[eventTypeHFName].value =
	    eventTypeMenu.options[eventTypeMenu.selectedIndex].value;
  
    pf.elements[eventBigTypeHFName].value =
	    eventBigTypeMenu.options[eventBigTypeMenu.selectedIndex].value;

    pf.elements[maxSizeHFName].value =
	    maxSizeMenu.options[maxSizeMenu.selectedIndex].value;
    
    pf.elements[aggrHFName].value =
	    aggrMenu.options[aggrMenu.selectedIndex].value;

    pf.elements[filter1HFName].value =
            filter1Field.value;

    // Set form action url and submit.
    pf.action = pf.action + "?" + commandChildName + "=&jato.pageSession=" +
	pf.elements["<%=ViewBean.PAGE_SESSION_ATTRIBUTE_NVP_NAME %>"].value;
    pf.submit();	
}

</script>

<cc:i18nbundle id="appBundle"
 baseName="com.sun.netstorage.mgmt.esm.ui.resources.ApplicationResources" />

<jato:form name="eventFilterForm" method="post" onSubmit="javascript: submitValues(); window.close(); return false;">

<cc:pagetitle name="PageTitle"
 pageTitleText="<%=pageTitle %>"
 showPageButtonsTop="false"
 bundleID="appBundle">

 <cc:propertysheet 
   name="PropertySheet" 
   bundleID="appBundle" 	
   showJumpLinks="false"	
   addJavaScript="false" />		

</cc:pagetitle>
</jato:form>

<script language="javascript">
initValues();
</script>

</jato:pagelet>
