<%@ page language="java" %> 
<%@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"%>
<%@taglib uri="/WEB-INF/lib/sa.tld" prefix="sa"%>

<%
  String isSystemEdition = "0";

  if(com.sun.netstorage.mgmt.fm.storade.ui.util.SystemUtil.isSystemEdition())
	isSystemEdition = "1";
%>


<jato:useViewBean className="com.sun.netstorage.mgmt.fm.storade.ui.viewbeans.admin.GeneralSetupViewBean">

<sa:primarymasthead name="Masthead">

<jato:form name="generalSetupForm">

<script language="javascript">	
  
  function initPage() {
	var type = document.getElementById("patchDatabaseType");
	if (type.value == "CD") {
	   disable("patchDatabaseLocationFor", "#NOCHANGE#");
           disable("patchDatabaseProxyAddressFor", "#NOCHANGE#");
           disable("patchDatabaseProxyLoginNameFor", "#NOCHANGE#");
           disable("patchDatabaseProxyPasswordFor", "#NOCHANGE#");
	} else if(type.value == "remote") {
	   disable("patchDatabaseLocationFor", "#NOCHANGE#");
           enable("patchDatabaseProxyAddressFor", "#NOCHANGE#");
           enable("patchDatabaseProxyLoginNameFor", "#NOCHANGE#");
           enable("patchDatabaseProxyPasswordFor", "#NOCHANGE#");
          
        } else {
	   enable("patchDatabaseLocationFor", "#NOCHANGE#");
	   disable("patchDatabaseProxyAddressFor", "#NOCHANGE#");	
           disable("patchDatabaseProxyLoginNameFor", "#NOCHANGE#");
           disable("patchDatabaseProxyPasswordFor", "#NOCHANGE#");
	}
  }

  function changePatchDatabaseType() {
	var type = document.getElementById("patchDatabaseType");
	if (type.value == "CD") {
	   disable("patchDatabaseLocationFor", "");
           disable("patchDatabaseProxyAddressFor", "");
           disable("patchDatabaseProxyLoginNameFor", "");
           disable("patchDatabaseProxyPasswordFor", "");
	} else if(type.value == "remote") {
	   disable("patchDatabaseLocationFor", "");
           enable("patchDatabaseProxyAddressFor", "");	
           enable("patchDatabaseProxyLoginNameFor", "");
           enable("patchDatabaseProxyPasswordFor", "");
        } else {
	   enable("patchDatabaseLocationFor", "");
           disable("patchDatabaseProxyAddressFor", "");	
           disable("patchDatabaseProxyLoginNameFor", "");
           disable("patchDatabaseProxyPasswordFor", "");
	}
  }

  function enable(id, val) {
        var obj = document.getElementById(id);
        obj.disabled = false;
	if(val != "#NOCHANGE#") {
	    obj.value = val;
	}
  }

  function disable(id, val) {
	var obj = document.getElementById(id);
        obj.disabled = true;
        if(val != "#NOCHANGE#") {
	    obj.value = val;
	} 
  }

  function testPatchDatabase() {

     if(!confirm("<cc:text name="JSAlert" bundleID="appBundle" defaultValue="js.alert.testPatchDatabase.info" escape="false"/>")) 
	return false;

     var win = window.open('/storade/admin/PreTestPatchPro','secondaryWindow','scrollbars,resizable,height=400,width=700,top='+((screen.height-(screen.height/1.618))-(400/2))+',left='+((screen.width-700)/2));

     win.focus();

     return false;
  }
</script>




<!-- Page Title --> 
<cc:pagetitle 
  name="PageTitle" 
  bundleID="appBundle"
  pageTitleText="page.title.generalSetup" 
  showPageTitleSeparator="true"
  showPageButtonsTop="true"
  showPageButtonsBottom="true">

<!-- PropertySheet -->
  <cc:propertysheet 
   name="GeneralSetupPropertySheet" 
   bundleID="appBundle" 
   showJumpLinks="true"
   addJavaScript="true" />

</cc:pagetitle>

</jato:form>

<script language="JavaScript">
function validate() {

    if(!ps_CheckRequiredFields()) return false;
    if(!qty_check(document.getElementById("refreshRateFor"),
	          5, -999, 
	         "<cc:text name="JSAlert" bundleID="appBundle" defaultValue="js.alert.refreshRate" escape="false"/>")) 
        return false;
       
    if(!qty_check(document.getElementById("maxSizeFor"),
	          1, -999, 
	         "<cc:text name="JSAlert" bundleID="appBundle" defaultValue="js.alert.logMaxSize" escape="false"/>")) 
        return false;

    if(<%=isSystemEdition%>) {
    	var type = document.getElementById("patchDatabaseType");
	if(type.value == "local") {
	    if(!empty_check(document.getElementById("patchDatabaseLocationFor"), 
	         	"<cc:text name="JSAlert" bundleID="appBundle" defaultValue="js.alert.patchDatbaseLocation.empty" escape="false"/>")) 
            return false;

	}

        var proxyServer = document.getElementById("patchDatabaseProxyAddressFor").value;
        if(proxyServer.toLowerCase().indexOf("http:") == 0 ||
           proxyServer.toLowerCase().indexOf("https:") == 0) {
	   alert("<cc:text name="JSAlert" bundleID="appBundle" defaultValue="js.alert.proxyServer.format" escape="false"/>");
	   return false;
	}

        var patchServer = document.getElementById("patchDatabaseLocationFor").value;
	if(patchServer != "" && patchServer != "CD" &&
           patchServer.toLowerCase().indexOf("http:") != 0 &&
           patchServer.toLowerCase().indexOf("https:") != 0) {
	   alert("<cc:text name="JSAlert" bundleID="appBundle" defaultValue="js.alert.patchServer.format" escape="false"/>");
	   return false;
	}

    }
    
    return true;


}

initPage();

</script>

</sa:primarymasthead>

</jato:useViewBean>

