<%@  page pageEncoding="utf-8" contentType="text/html;charset=utf-8" import="com.novell.webaccess.common.JSPConduit, com.novell.emframe.dev.eMFrameUtils,
                                                                             com.novell.emframe.dev.eMFrameFactory,
                                                                             com.novell.emframe.dev.DirUtils" %>
<%   JSPConduit c = JSPConduit.getJSPConduit(request);
   c.stringTable("DevResources");
   c.stringTable("FwResources");
   c.stringTable("BaseResources"); %>


<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/iman.tld" prefix="iman" %>


<HTML>
<HEAD>
   <TITLE><%= c.string("ProductName") %></TITLE>

   <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" />

   <LINK rel='stylesheet' href='<%= c.getModulesUrl() + "/dev/css/hf_style.css" %>'>
   <jsp:include page='<%= c.getPath("dev/PageScripts_inc.jsp") %>' flush="true" />
   <SCRIPT language="JavaScript">
      var changed = false;
      var copied = false;
      function onInit()
      {
         var form=document.forms[0];
         //initWidgetFromXml(form._Given_Name, "<%= c.toScript(c.var("eDir$target$Given_Name")) %>"); // for Given Name
         initWidgetFromXml(form._SA, "<%= c.toScript(c.var("eDir$target$SA")) %>");   // for SA
         initWidgetFromXml(form._Postal_Office_Box, "<%= c.toScript(c.var("eDir$target$Postal_Office_Box")) %>");   // for Postal Office Box
         initWidgetFromXml(form._Physical_Delivery_Office_Name, "<%= c.toScript(c.var("eDir$target$Physical_Delivery_Office_Name")) %>");   // for Physical_Delivery_Office_Name
         initWidgetFromXml(form._S, "<%= c.toScript(c.var("eDir$target$S")) %>");   // for S
         initWidgetFromXml(form._Postal_Code, "<%= c.toScript(c.var("eDir$target$Postal_Code")) %>");   // for Postal Code
         // init for Postal Address
         var xStr="<%= c.toScript(c.var("eDir$target$Postal_Address")) %>";
         if(xStr!=null && xStr!="")
         {
            var xml = parseXml(xStr);
            if(xml.getChildren().length>0)
            {
               form._eDir$target$Postal_Addressitem0.value=xml.getChildren()[0].getChildren()[0].getText();
               form._eDir$target$Postal_Addressitem1.value=xml.getChildren()[0].getChildren()[1].getText();
               form._eDir$target$Postal_Addressitem2.value=xml.getChildren()[0].getChildren()[2].getText();
               form._eDir$target$Postal_Addressitem3.value=xml.getChildren()[0].getChildren()[3].getText();
               form._eDir$target$Postal_Addressitem4.value=xml.getChildren()[0].getChildren()[4].getText();
               form._eDir$target$Postal_Addressitem5.value=xml.getChildren()[0].getChildren()[5].getText();
            }

            initMooMode("_Postal_Address", xStr);
         }

      }

      function isPageValid() // called when user leaves this page or applys changes
      {
         // What should this method do?
         // -data validation
         // -gather applet values
         // -if this method returns false, the page will not be saved

         var form=document.forms[0];
         form.eDir$target$SA.value = getWidgetValueAsXml(form._SA);   // for SA
         form.eDir$target$Postal_Office_Box.value = getWidgetValueAsXml(form._Postal_Office_Box);   // for Postal Office Box
         form.eDir$target$Physical_Delivery_Office_Name.value = getWidgetValueAsXml(form._Physical_Delivery_Office_Name);   // for Physical_Delivery_Office_Name
         form.eDir$target$S.value = getWidgetValueAsXml(form._S);   // for S
         form.eDir$target$Postal_Code.value = getWidgetValueAsXml(form._Postal_Code);   // for Postal Code


         // exit for Postal Address
         var xml = new XmlElement("attribute");
         var val = new XmlElement("value");
         val.add(new XmlElement("item",form._eDir$target$Postal_Addressitem0.value));
         val.add(new XmlElement("item",form._eDir$target$Postal_Addressitem1.value));
         val.add(new XmlElement("item",form._eDir$target$Postal_Addressitem2.value));
         val.add(new XmlElement("item",form._eDir$target$Postal_Addressitem3.value));
         val.add(new XmlElement("item",form._eDir$target$Postal_Addressitem4.value));
         val.add(new XmlElement("item",form._eDir$target$Postal_Addressitem5.value));
         xml.add(val);

         //Update the copy to label field, when it is changed after the copy has been selected
         if(form._Postal_Address_mode)
         {
            var s=form._Postal_Address_mode
            xml.addAttribute('mode', s[s.selectedIndex].value);
         }
         form.eDir$target$Postal_Address.value=xml.toString();
         return true;
      }

      function copyToMailingLabel()
      {
         var form=document.forms[0];
         // added to copy the name of the object in name field
         <% if (c.var("Task.moo").equals("true") == false) { %>
            <%
               String[] names = eMFrameUtils.unpack((c.var("eDir$target")), eMFrameFactory.getMContext(request));
               String name = DirUtils.getLeftMostName(names[0]);
            %>
            form.elements["name"].value = "<%= eMFrameUtils.toScript(name) %>";
         <% } %>
         form._eDir$target$Postal_Addressitem0.value = form.elements["name"].value;
         form._eDir$target$Postal_Addressitem1.value = form._SA.value;
         form._eDir$target$Postal_Addressitem2.value = form._Postal_Office_Box.value;
         form._eDir$target$Postal_Addressitem3.value = form._Physical_Delivery_Office_Name.value;
         form._eDir$target$Postal_Addressitem4.value = form._S.value;
         form._eDir$target$Postal_Addressitem5.value = form._Postal_Code.value;
         changed=true;
         copied=true;

      }

   </SCRIPT>
</HEAD>

<BODY onLoad="onInit();">
<FORM name="form" method=post action="webacc">
   <jsp:include page='<%= c.getPath("dev/Messagebar_inc.jsp") %>' flush="true" />
   <jsp:include page='<%= c.getPath("dev/BookVars_inc.jsp") %>' flush="true" />

   <!---- Shared Form Code ---->

   <!---- UI Created by UiHandlers ---->

      <TABLE class="mediumtext" width=90% border='0' bgcolor='#FFFFFF' cellpadding='3' cellspacing='0'>
         <!-- SA -->
         <TR>
            <TD width="27%">
               <%= c.string("PostalAddressItem1") %>:
            </TD>
            <TD>
                <INPUT name='name' type=hidden value="<%= c.var("name") %>">
                <INPUT name='eDir$target$SA' type=hidden value="<%= c.var("eDir$target$SA") %>">
                <INPUT type=text name=_SA size=<%= c.string("UI.textboxSize") %> style="padding-left:3;padding-right:3;width:<%= c.string("UI.textboxPixel") %>"  onChange='var addr1=document.forms[0]._eDir$target$Postal_Addressitem1; if((copied)){addr1.value=this.value}' maxlength=128 <% if (c.var("eDirRights$target$SA").equals("R") || c.var("eDirRights$target$SA").equals("NONE")) { %>DISABLED<% } %> >
            </TD>
            <TD valign=top>
               <% if (c.var("Task.moo").equals("true")) {    c.set("ModeSelector.name", "_SA_mode"); %>&nbsp;&nbsp;<jsp:include page='<%= c.getPath("dev/ModeSelector_inc.jsp") %>' flush="true" /><% } %>
            </TD>
         </TR>
         <!-- Postal Office Box -->
         <TR>
            <TD width="27%">
               <%= c.toDisplay(c.string("PostalAddressItem2")) %>:&nbsp;
            </TD>
            <TD>
               <INPUT name='eDir$target$Postal_Office_Box' type=hidden value="<%= c.var("eDir$target$Postal_Office_Box") %>">
               <INPUT type=text name=_Postal_Office_Box size=<%= c.string("UI.textboxSize") %> style="padding-left:3;padding-right:3;width:<%= c.string("UI.textboxPixel") %>" onChange='var addr2=document.forms[0]._eDir$target$Postal_Addressitem2; if((copied)){addr2.value=this.value}'  maxlength=40 <% if (c.var("eDirRights$target$Postal_Office_Box").equals("R") || c.var("eDirRights$target$Postal_Office_Box").equals("NONE")) { %>DISABLED<% } %> >
            </TD>
            <TD valign=top>
               <% if (c.var("Task.moo").equals("true")) {    c.set("ModeSelector.name", "_Postal_Office_Box_mode"); %>&nbsp;&nbsp;<jsp:include page='<%= c.getPath("dev/ModeSelector_inc.jsp") %>' flush="true" /><% } %>
            </TD>
         </TR>
         <!-- Physical_Delivery_Office_Name -->
         <TR>
            <TD width="27%">
               <%= c.string("PostalAddressItem3") %>:&nbsp;
            </TD>
            <TD>
               <INPUT name='eDir$target$Physical_Delivery_Office_Name' type=hidden value="<%= c.var("eDir$target$Physical_Delivery_Office_Name") %>">
               <INPUT type=text name=_Physical_Delivery_Office_Name size=<%= c.string("UI.textboxSize") %> style="padding-left:3;padding-right:3;width:<%= c.string("UI.textboxPixel") %>"  onChange='var addr3=document.forms[0]._eDir$target$Postal_Addressitem3;if((copied)){addr3.value=this.value}'  maxlength=128 <% if (c.var("eDirRights$target$Physical_Delivery_Office_Name").equals("R") || c.var("eDirRights$target$Physical_Delivery_Office_Name").equals("NONE")) { %>DISABLED<% } %> >
            </TD>
            <TD valign=top>
               <% if (c.var("Task.moo").equals("true")) {    c.set("ModeSelector.name", "_Physical_Delivery_Office_Name_mode"); %>&nbsp;&nbsp;<jsp:include page='<%= c.getPath("dev/ModeSelector_inc.jsp") %>' flush="true" /><% } %>
            </TD>
         </TR>
         <!-- S -->
         <TR>
            <TD width="27%">
               <%= c.var("SDisplayName") %>:&nbsp;
            </TD>
            <TD>
               <INPUT name='eDir$target$S' type=hidden value="<%= c.var("eDir$target$S") %>">
               <INPUT type=text name=_S size=<%= c.string("UI.textboxSize") %> style="width:<%= c.string("UI.textboxPixel") %>" onChange='var addr4=document.forms[0]._eDir$target$Postal_Addressitem4;if((copied)){addr4.value=this.value}' maxlength=128 <% if (c.var("eDirRights$target$S").equals("R") || c.var("eDirRights$target$S").equals("NONE")) { %>DISABLED<% } %> >
            </TD>
            <TD valign=top>
               <% if (c.var("Task.moo").equals("true")) {    c.set("ModeSelector.name", "_S_mode"); %>&nbsp;&nbsp;<jsp:include page='<%= c.getPath("dev/ModeSelector_inc.jsp") %>' flush="true" /><% } %>
            </TD>
         </TR>
         <!-- Postal Code -->
         <TR>
            <TD width="27%">
               <%= c.var("Postal_CodeDisplayName") %>:&nbsp;
            </TD>
            <TD>
               <INPUT name='eDir$target$Postal_Code' type=hidden value="<%= c.var("eDir$target$Postal_Code") %>">
               <INPUT type=text name=_Postal_Code size=<%= c.string("UI.textboxSize") %> style="width:<%= c.string("UI.textboxPixel") %>" onChange='var addr5=document.forms[0]._eDir$target$Postal_Addressitem5;if((copied)){addr5.value=this.value}' maxlength=40 <% if (c.var("eDirRights$target$Postal_Code").equals("R") || c.var("eDirRights$target$Postal_Code").equals("NONE")) { %>DISABLED<% } %> >
            </TD>
            <TD valign=top>
               <% if (c.var("Task.moo").equals("true")) {    c.set("ModeSelector.name", "_Postal_Code_mode"); %>&nbsp;&nbsp;<jsp:include page='<%= c.getPath("dev/ModeSelector_inc.jsp") %>' flush="true" /><% } %>
            </TD>
         </TR>
         <TR>
            <INPUT name='eDir$target$Postal_Address' type=hidden>
            <c:if test="${edasRights.target.Postal_Address.writeable}">
               <td width="27%" height="15">&nbsp;</td>
               <td class="smalltext" height="15"><a href="javascript:copyToMailingLabel();" ><%= c.string("PostalAddress.CopyToMailingLabel") %></a></td>
               </TD>
            </c:if>
         </TR>
         <tr><td>&nbsp;</td></tr>
         <tr>
            <td colspan="2" class="tablesubhead1"><%= c.string("ModifyOrg.MailingLabel") %></td>
         </tr>
         <tr><td style="height:10"></td></tr>
         <!-- Postal Address -->
         <tr>
            <TD width="27%"><%= c.string("PostalAddressUiHandlerN") %>: </td>
            <td><INPUT type=text size="<%= c.string("UI.textboxSize") %>" style="padding-left:3;padding-right:3;width:<%= c.string("UI.textboxPixel") %>" name="_eDir$target$Postal_Addressitem0" onChange="changed=true;"  <% if (c.var("eDirRights$target$Postal_Address").equals("R") || c.var("eDirRights$target$Postal_Address").equals("NONE")) { %>DISABLED<% } %> ></td>
         </tr>
         <tr>
            <TD width="27%"><%= c.string("PostalAddressItem1") %>: </td>
            <td><INPUT type=text size="<%= c.string("UI.textboxSize") %>" style="padding-left:3;padding-right:3;width:<%= c.string("UI.textboxPixel") %>" name="_eDir$target$Postal_Addressitem1" onChange="changed=true" <% if (c.var("eDirRights$target$Postal_Address").equals("R") || c.var("eDirRights$target$Postal_Address").equals("NONE")) { %>DISABLED<% } %>  ></td>
         </tr>
         <tr>
            <TD width="27%"><%= c.toDisplay(c.string("PostalAddressItem2")) %>: </td>
            <td><INPUT type=text size="<%= c.string("UI.textboxSize") %>" style="padding-left:3;padding-right:3;width:<%= c.string("UI.textboxPixel") %>" name="_eDir$target$Postal_Addressitem2" onChange="changed=true"  <% if (c.var("eDirRights$target$Postal_Address").equals("R") || c.var("eDirRights$target$Postal_Address").equals("NONE")) { %>DISABLED<% } %>  ></td>
         </tr>
         <tr>
            <TD width="27%"><%= c.string("PostalAddressItem3") %>: </td>
            <td><INPUT type=text size="<%= c.string("UI.textboxSize") %>" style="padding-left:3;padding-right:3;width:<%= c.string("UI.textboxPixel") %>" name="_eDir$target$Postal_Addressitem3" onChange="changed=true"<% if (c.var("eDirRights$target$Postal_Address").equals("R") || c.var("eDirRights$target$Postal_Address").equals("NONE")) { %>DISABLED<% } %>  ></td>
         </tr>
         <tr>
            <TD width="27%"><%= c.string("PostalAddressItem4") %>: </td>
            <td><INPUT type=text size="<%= c.string("UI.textboxSize") %>" style="padding-left:3;padding-right:3;width:<%= c.string("UI.textboxPixel") %>" name="_eDir$target$Postal_Addressitem4" onChange="changed=true" <% if (c.var("eDirRights$target$Postal_Address").equals("R") || c.var("eDirRights$target$Postal_Address").equals("NONE")) { %>DISABLED<% } %>  ></td>
         </tr>
         <tr>
            <TD width="27%"><%= c.var("Postal_CodeDisplayName") %>: </td>
            <td><INPUT type=text size="<%= c.string("UI.textboxSize") %>" style="padding-left:3;padding-right:3;width:<%= c.string("UI.textboxPixel") %>" name="_eDir$target$Postal_Addressitem5" onChange="changed=true" <% if (c.var("eDirRights$target$Postal_Address").equals("R") || c.var("eDirRights$target$Postal_Address").equals("NONE")) { %>DISABLED<% } %>  ></td>
         </tr>
      </TABLE>
</FORM>
</BODY>
</HTML>

