<%@  page pageEncoding="utf-8" contentType="text/html;charset=utf-8" import="com.novell.webaccess.common.JSPConduit, com.novell.emframe.dev.eMFrameUtils" %>
<%
   JSPConduit c = JSPConduit.getJSPConduit(request);
   c.stringTable("DevResources");
   c.stringTable("FwResources");
   c.stringTable("BaseResources");
%>
<HTML>
<HEAD>
   <LINK href="<%= c.getModulesUrl() + "/dev/css/hf_style.css" %>" rel="styleSheet" type="text/css"/>

   <jsp:include page='<%= c.getPath("dev/eMFrameScripts_inc.jsp") %>' flush="true" />
   <jsp:include page='<%= c.getPath("dev/XmlScripts_inc.jsp") %>' flush="true" />
   <jsp:include page='<%= c.getPath("dev/ValidateIntegerScripts_inc.jsp") %>' flush="true" />

   <SCRIPT LANGUAGE="JavaScript">

      var ENABLED_COLOR = "white";
      var DISABLED_COLOR = "#EFEEE9";
      var initPml = null;
      var initPei = null;
      var initGla = null;
      var initRgl = null;
      var initPet = null;

      function onInit()
      {
         with( document.forms[0])
         {
            <%-- Password_Allow_Change --%>
            pac.checked = (getValueFromXml("<%= c.toScript(c.var("eDir$target$Password_Allow_Change")) %>") != "false")

            <%-- Password Required --%>
            if(getValueFromXml("<%= c.toScript(c.var("eDir$target$Password_Required")) %>") == "true")
               pr.checked=true;

            <%-- Password Minimum Length --%>
            initWidgetFromXml(pml, "<%= c.toScript(c.var("eDir$target$Password_Minimum_Length")) %>");
            initPml=pml.value;

            <%-- Password Expiration Interval --%>
            initWidgetFromXml(pei, "<%= c.toScript(c.var("eDir$target$Password_Expiration_Interval")) %>");
            if ((pei.value != null) && (pei.value.length > 0))
            {
               pei.value = pei.value/86400;
               initPei=pei.value;
            }

            <%-- Password Expiration Time --%>
            initWidgetFromXml(pet, "<%= c.toScript(c.var("eDir$target$Password_Expiration_Time")) %>");

            var msecs = parseInt(pet.value);
            if( msecs > 0 )
            {
               var date = new Date(msecs);
               dateStr = date.toLocaleString();
               dateStrLoc = dateStr.indexOf(", ");
               dateStr = dateStr.substring(dateStrLoc+2, dateStr.length);
               pet.value=dateStr;
               initPet=pet.value;
            }

            <%-- Password Unique Required --%>
            rup.checked = (getValueFromXml("<%= c.toScript(c.var("eDir$target$Password_Unique_Required")) %>") == "true")

            <%-- Login Grace Limit --%>
            initWidgetFromXml(gla, "<%= c.toScript(c.var("eDir$target$Login_Grace_Limit")) %>");
            initGla=gla.value;

            <%-- Login Grace Remaining --%>
            initWidgetFromXml(rgl, "<%= c.toScript(c.var("eDir$target$Login_Grace_Remaining")) %>");
            initRgl=rgl.value;

            <%-- periodic passwaord changes --%>
            if( pei.value.length != 0 && pet.value.length != 0 )
            {
               fppc.checked = true;
            }

            if( gla.value.length > 0 && rgl.value.length > 0 )
            {
               lgl.checked = true;
            }

            checkControls();
         }
      }

      function disableControl(control)
      {
         control.disabled = true;
         control.style.backgroundColor = DISABLED_COLOR;
      }

      function enableControl(control)
      {
         control.disabled = false;
         control.style.backgroundColor = ENABLED_COLOR;
      }

      function checkControls()
      {
         with( document.forms[0] )
         {
            disableControl(pml);
            disableControl(pei);
            disableControl(pet);
            disableControl(gla);
            disableControl(rgl);

            <%-- If password is required --%>
            if(pr.checked)
            {
               pml.value = (initPml!=null ? initPml : "5");
               fppc.disabled = false;
            }
            else
            {
               pml.value="";
               disableControl(fppc);
               disableControl(lgl);
               disableControl(rup);
            }

            if(fppc.checked && !fppc.disabled)
            {
               enableControl(pei);
               pei.value = (initPei!=null ? initPei : "40");

               enabledControl(pet);

               if(initPet==null)
               {
                  var today = new Date();
                  dateStr = today.toLocaleString();
                  dateStrLoc = dateStr.indexOf(", ");
                  dateStr = dateStr.substring(dateStrLoc+2, dateStr.length);
                  pet.value = dateStr;
               }
               else
               {
                  pet.value = initPet;
               }

               lgl.disabled=false;
               rup.disabled=false;
            }

            if(!fppc.checked)
            {
               disableControl(pei);
               disableControl(pet);
               disableControl(gla);
               disableControl(rgl);
               disableControl(lgl);
               disableControl(rup);

               pei.value="";
               pet.value="";
            }

            if(lgl.checked && !lgl.disabled)
            {
               enableControl(gla);
               enableControl(rgl);

               gla.value = (initGla.length>0 ? initGla : "6");
               rgl.value = (initRgl.length >0 ? initRgl : "6");
            }

            if(!lgl.checked && !lgl.disabled)
            {
               disableControl(gla);
               disableControl(rgl);
               gla.value = "";
               rgl.value = "";
            }
         }
      }

      function onExit()
      {
         with( document.forms[0] )
         {
            if((!pml.value && pr.checked)|| (!pei.value && fppc.checked) || (!rgl.value && lgl.checked) || (!gla.value && lgl.checked) )
            {
               alert("<%= c.string("PasswordRestrictionsEmptyField") %>");
               pml.focus();
               return false;
            }

            if( parseInt(rgl.value) > parseInt(gla.value))
            {
               alert("<%= c.string("PasswordRemainingGraceLoginsErrorKey") %>");
               rgl.focus();
               return false;
            }

            if( parseInt(gla.value) < 1 || parseInt(gla.value) > 200 )
            {
               alert("<%= c.string("PasswordGraceLoginsErrorKey") %>");
               gla.focus();
               return false;
            }

            <%-- Password Allow Change --%>
            eDir$target$Password_Allow_Change.value = toXmlString("" + pac.checked <% if (c.var("Task.moo").equals("true")) { %>, form._pac_mode.value<% } %>);

            <%-- Password Allow Change --%>
            eDir$target$Password_Required.value = toXmlString("" + pr.checked <% if (c.var("Task.moo").equals("true")) { %>, form._pr_mode.value<% } %>);

            <%-- Password Minimum Length --%>
            if( pml.value.length != 0 )
            {
               eDir$target$Password_Minimum_Length.value = toXmlString(pml.value <% if (c.var("Task.moo").equals("true")) { %>, form._pml_mode.value<% } %>);
            }

            <%-- Password Expiration Interval --%>
            if( pei.value.length != 0 )
            {
               seconds = parseInt(pei.value) * 86400;
               eDir$target$Password_Expiration_Interval.value = toXmlString(""+seconds <% if (c.var("Task.moo").equals("true")) { %>, form._pei_mode.value<% } %>);
            }

            <%-- Password Expiration Time --%>
            var value = "";
            if(fppc.checked && pet.value.length!=0)
            {
               value = "" + Date.parse(pet.value);
            }

            eDir$target$Password_Expiration_Time.value = toXmlString(value <% if (c.var("Task.moo").equals("true")) { %>, form._pet_mode.value<% } %>);

            <%-- Password Unique Required --%>
            eDir$target$Password_Unique_Required.value = toXmlString("" + rup.checked <% if (c.var("Task.moo").equals("true")) { %>, form._rup_mode.value<% } %>);

            <%-- Login Grace Limit --%>
            document.forms[0].eDir$target$Login_Grace_Limit.value = toXmlString(gla.value <% if (c.var("Task.moo").equals("true")) { %>, form._gla_mode.value<% } %>);

            <%-- Login Grace Remaining --%>
            document.forms[0].eDir$target$Login_Grace_Remaining.value = toXmlString(rgl.value <% if (c.var("Task.moo").equals("true")) { %>, form._rgl_mode.value<% } %>);

            return true;
         }
      }

   </SCRIPT>
</HEAD>


<BODY bgcolor="#FFFFFF" TEXT="#000000" LINK="#000000" VLINK="#000000" ALINK="#000000" onload="onInit();" >
<FORM name=form method=post action=webacc onSubmit="onExit();">

   <!---- WEBACC VARIABLES ---->
   <INPUT type=hidden name="taskId" value="<%= c.var("taskId") %>">
   <INPUT type=hidden name="User.context" value="<%= c.var("User.context") %>">
   <!---- eDir Access Service VARIABLES ---->
   <INPUT type=hidden name="eDirCommand" value="Write">
   <INPUT type=hidden name="eDir$target" value="<%= c.toHTML(c.var("eDir$target")) %>">
   <INPUT type=hidden name="merge" value="dev.GenConf">
   <INPUT type=hidden name="error" value="dev.GenErr">


   <%
      String s = c.formatMessage(c.string("PasswordRestrictionsTitleKey"), new String[]{c.var("eDir$target")});
      c.set("TaskHeader.title", c.plus(c.plus(s, " - "), c.var("Task.targetDisplayName")));
      c.set("TaskHeader.iconUrl", "dir/User.gif");
      c.set("Task.Icon.alt", c.string("ObjectType.User"));
   %>
   <jsp:include page='<%= c.getPath("dev/TaskHeader_inc.jsp") %>' flush="true" /><BR>


   <TABLE border="0" bgcolor="#FFFFFF" cellpadding="3" cellspacing="0">

    <!-- Password_Allow_Change -->
	<TR>
	    <TD align=left>
	        <INPUT name="eDir$target$Password_Allow_Change" type=hidden value="<%= c.var("eDir$target$Password_Allow_Change") %>">
	        <INPUT name=pac type=checkbox onClick="checkControls();">
        </TD>
        <TD>
	        <FONT face="Trebuchet MS,Helvetica,Arial" size=2><NOBR><%= c.string("PasswordRestrictionsPACPrompt") %></NOBR></FONT>
        </TD>
    </TR>

	<!-- Password_Required -->
	<TR>
	    <TD align=left>
	        <INPUT name="eDir$target$Password_Required" type=hidden value="<%= c.var("eDir$target$Password_Required") %>">
	        <INPUT TYPE=CHECKBOX name=pr value=yes onClick="checkControls();">
        </TD>
        <TD>
	        <FONT face="Trebuchet MS,Helvetica,Arial" size=2><NOBR><%= c.string("PasswordRestrictionsPRPrompt") %></NOBR></FONT>
        </TD>
    </TR>

    <!-- Password Minimum Length -->
	<TR>
	    <TD align=left>
        </TD>
        <TD>
	        <FONT face="Trebuchet MS,Helvetica,Arial" size=2><NOBR><%= c.string("PasswordRestrictionsPMLPrompt") %></NOBR></FONT>
	        &nbsp;
	        <input type=text name=pml size=5 maxlength=3 onChange='if(!validateIntegerField(pml,1,128)){this.focus();return false;}'>
            <INPUT name='eDir$target$Password_Minimum_Length' type=hidden value="<%= c.var("eDir$target$Password_Minimum_Length") %>">
        </TD>
    </TR>

    <!-- Force Periodic Password Changes -->
	<TR>
	    <TD align=left>
	        <INPUT TYPE=CHECKBOX name=fppc value=yes onClick="checkControls();">
        </TD>
        <TD>
	        <FONT face="Trebuchet MS,Helvetica,Arial" size=2><NOBR><%= c.string("PasswordRestrictionsFPPCPrompt") %></NOBR></FONT>
        </TD>
    </TR>

    <!-- Password_Expiration_Interval -->
	<TR>
	    <TD align=left>
        </TD>
        <TD>
	        <FONT face="Trebuchet MS,Helvetica,Arial" size=2><NOBR><%= c.string("PasswordRestrictionsPEIPrompt") %></NOBR></FONT>
	        &nbsp;
	        <input type=text name=pei size=5 maxlength=3 onChange='if(!validateIntegerField(pei, 1, 365)){this.focus();return false;}'>
            <INPUT name='eDir$target$Password_Expiration_Interval' type=hidden value="<%= c.var("eDir$target$Password_Expiration_Interval") %>">
        </TD>
    </TR>

    <!-- Prompt -->
	<TR>
	    <TD align=left>
        </TD>
        <TD>
	        <FONT face="Trebuchet MS,Helvetica,Arial" size=2><NOBR><%= c.string("PasswordRestrictionsPETPrompt") %></NOBR></FONT>
        </TD>
    </TR>

    <!-- Password_Expiration_Time -->
	<TR>
	    <TD align=left>
        </TD>
        <TD>
	        <input type=text name=pet size=40>
            <INPUT name='eDir$target$Password_Expiration_Time' type=hidden><br>
            <font face="Trebuchet MS" size=-2>&nbsp;&nbsp;&nbsp;ex: August 22, 2002 hh:mm:ss am/pm  (time is optional)</font>
        </TD>
    </TR>

	<!-- Password_Unique_Required -->
	<TR>
	    <TD align=left>
	        <INPUT TYPE=CHECKBOX name=rup>
	        <INPUT name="eDir$target$Password_Unique_Required" type=hidden value="<%= c.var("eDir$target$Password_Unique_Required") %>">
        </TD>
        <TD>
	        <FONT face="Trebuchet MS,Helvetica,Arial" size=2><NOBR><%= c.string("PasswordRestrictionsRUPPrompt") %></NOBR></FONT>
        </TD>
    </TR>

    <!-- Limit Grace Logins -->
	<TR>
	    <TD align=left>
	        <INPUT TYPE=CHECKBOX name=lgl onClick="checkControls();">
        </TD>
        <TD>
	        <FONT face="Trebuchet MS,Helvetica,Arial" size=2><NOBR><%= c.string("PasswordRestrictionsLGLPropmt") %></NOBR></FONT>
        </TD>
    </TR>

	<!-- Login_Grace_Limit -->
	<TR>
	    <TD align=left>
        </TD>
        <TD>
	        <FONT face="Trebuchet MS,Helvetica,Arial" size=2><NOBR><%= c.string("PasswordRestrictionsGLAPrompt") %></NOBR></FONT>
	        &nbsp;
            <INPUT type=text name=gla size=5 maxlength=3 onChange='if(!validateIntegerField(gla,1,200)){this.focus(); return false;}' >
	        <INPUT name='eDir$target$Login_Grace_Limit' type=hidden value="<%= c.var("eDir$target$Login_Grace_Limit") %>">

        </TD>
    </TR>

	<!-- Login_Grace_Remaining -->
	<TR>
	    <TD align=left>
        </TD>
        <TD>
	        <FONT face="Trebuchet MS,Helvetica,Arial" size=2><NOBR><%= c.string("PasswordRestrictionsRGLPrompt") %></NOBR></FONT>
	        &nbsp;
	        <INPUT type=text name=rgl size=5 maxlength=3 onChange='if(!validateIntegerField(rgl,1,200)){this.focus();return false;}' >
            <INPUT name='eDir$target$Login_Grace_Remaining' type=hidden value="<%= c.var("eDir$target$Login_Grace_Remaining") %>">
        </TD>
    </TR>

    </TABLE>

   <BR>
   <A href="Javascript: if(onExit() != false) document.forms[0].submit();"><IMG src="<%= c.getModulesUrl() + "/dev/images/" + c.string("Button.OK.image") %>" border=0></A> <jsp:include page='<%= c.getPath("dev/Cancel_inc.jsp") %>' flush="true" />
   <HR color="#6B8899" size="2">


</FORM>
</BODY>
</HTML>

