<%@ 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.performancegraphicFilterForm;
    var pf = window.opener.document.<%=formName %>;

    // Parent window hidden field name.
    var volumeportName =
	"<cc:text name='VolumePortHiddenFieldNameText'/>";

    var volumeport = pf.elements[volumeportName];

    // Menu name.
    var volumeportMenu =
	tf.elements["<cc:text name='VolumePortMenuNameText'/>"];

    if ((volumeport.value == null) || (volumeport.value == '')) {
      setSelection(volumeportMenu);

    } else {
      var volumePortToken = (volumeport.value).split('_');
      for (var i = 0; i <= volumePortToken.length; i++)  {
        var volPort = volumePortToken[i];
        setPortSelection(volumeportMenu, volPort);
      }
    }
}

function setSelection(select) {
    for (var i = 0; i < select.options.length; i++) {

      select.options[i].selected = true;
    }
}

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

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

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

    // Parent window hidden field name.
    var volumeportName =
	"<cc:text name='VolumePortHiddenFieldNameText'/>"

    // Menu name.
    var volumeportMenu =
	tf.elements["<cc:text name='VolumePortMenuNameText'/>"];


    var selectedValue = '';
    for (var i = 0; i < volumeportMenu.options.length; i++) {
        if (volumeportMenu.options[i].selected) {
          selectedValue = selectedValue + volumeportMenu.options[i].value +"_";
        }
    }
    pf.elements[volumeportName].value = selectedValue;
	    //volumeportMenu.options[volumeportMenu.selectedIndex].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="performancegraphicFilterForm" 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>
