<%@  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._street, "<%= c.toScript(c.var("eDir$target$street")) %>");   // for street
         initWidgetFromXml(form._postOfficeBox, "<%= c.toScript(c.var("eDir$target$postOfficeBox")) %>");   // for postOfficeBox
         initWidgetFromXml(form._physicalDeliveryOfficeName, "<%= c.toScript(c.var("eDir$target$physicalDeliveryOfficeName")) %>");   // for physicalDeliveryOfficeName
         initWidgetFromXml(form._st, "<%= c.toScript(c.var("eDir$target$st")) %>");   // for st
         initWidgetFromXml(form._postalCode, "<%= c.toScript(c.var("eDir$target$postalCode")) %>");   // for postalCode
         // init for postalAddress
         var xStr="<%= c.toScript(c.var("eDir$target$postalAddress")) %>";
         if(xStr!=null && xStr!="")
         {
            var xml = parseXml(xStr);
            if(xml.getChildren().length>0)
            {
               form._eDir$target$postalAddressitem0.value=xml.getChildren()[0].getChildren()[0].getText();
               form._eDir$target$postalAddressitem1.value=xml.getChildren()[0].getChildren()[1].getText();
               form._eDir$target$postalAddressitem2.value=xml.getChildren()[0].getChildren()[2].getText();
               form._eDir$target$postalAddressitem3.value=xml.getChildren()[0].getChildren()[3].getText();
               form._eDir$target$postalAddressitem4.value=xml.getChildren()[0].getChildren()[4].getText();
               form._eDir$target$postalAddressitem5.value=xml.getChildren()[0].getChildren()[5].getText();
            }

            initMooMode("_postalAddress", 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$street.value = getWidgetValueAsXml(form._street);   // for street
         form.eDir$target$postOfficeBox.value = getWidgetValueAsXml(form._postOfficeBox);   // for postOfficeBox
         form.eDir$target$physicalDeliveryOfficeName.value = getWidgetValueAsXml(form._physicalDeliveryOfficeName);   // for physicalDeliveryOfficeName
         form.eDir$target$st.value = getWidgetValueAsXml(form._st);   // for st
         form.eDir$target$postalCode.value = getWidgetValueAsXml(form._postalCode);   // for postalCode


         // exit for postalAddress
         var xml = new XmlElement("attribute");
         var val = new XmlElement("value");
         val.add(new XmlElement("item",form._eDir$target$postalAddressitem0.value));
         val.add(new XmlElement("item",form._eDir$target$postalAddressitem1.value));
         val.add(new XmlElement("item",form._eDir$target$postalAddressitem2.value));
         val.add(new XmlElement("item",form._eDir$target$postalAddressitem3.value));
         val.add(new XmlElement("item",form._eDir$target$postalAddressitem4.value));
         val.add(new XmlElement("item",form._eDir$target$postalAddressitem5.value));
         xml.add(val);

         //Update the copy to label field, when it is changed after the copy has been selected
         if(form._postalAddress_mode)
         {
            var s=form._postalAddress_mode
            xml.addAttribute('mode', s[s.selectedIndex].value);
         }
         form.eDir$target$postalAddress.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$postalAddressitem0.value = form.elements["name"].value;
         form._eDir$target$postalAddressitem1.value = form._street.value;
         form._eDir$target$postalAddressitem2.value = form._postOfficeBox.value;
         form._eDir$target$postalAddressitem3.value = form._physicalDeliveryOfficeName.value;
         form._eDir$target$postalAddressitem4.value = form._st.value;
         form._eDir$target$postalAddressitem5.value = form._postalCode.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'>
         <!-- street -->
         <TR>
            <TD width="27%">
               <%= c.string("PostalAddressItem1") %>:
            </TD>
            <TD>
                <INPUT name='name' type=hidden value="<%= c.var("name") %>">
                <INPUT name='eDir$target$street' type=hidden value="<%= c.var("eDir$target$street") %>">
                <INPUT type=text name=_street 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$postalAddressitem1; if((copied)||(addr1.value != "")){addr1.value=this.value}' maxlength=128 <% if (c.var("eDirRights$target$street").equals("R") || c.var("eDirRights$target$street").equals("NONE")) { %>DISABLED<% } %> >
            </TD>
            <TD valign=top>
               <% if (c.var("Task.moo").equals("true")) {    c.set("ModeSelector.name", "_street_mode"); %>&nbsp;&nbsp;<jsp:include page='<%= c.getPath("dev/ModeSelector_inc.jsp") %>' flush="true" /><% } %>
            </TD>
         </TR>
         <!-- postOfficeBox -->
         <TR>
            <TD width="27%">
               <%= c.toDisplay(c.string("PostalAddressItem2")) %>:&nbsp;
            </TD>
            <TD>
               <INPUT name='eDir$target$postOfficeBox' type=hidden value="<%= c.var("eDir$target$postOfficeBox") %>">
               <INPUT type=text name=_postOfficeBox 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$postalAddressitem2; if((copied)||(addr2.value != "")){addr2.value=this.value}'  maxlength=40 <% if (c.var("eDirRights$target$postOfficeBox").equals("R") || c.var("eDirRights$target$postOfficeBox").equals("NONE")) { %>DISABLED<% } %> >
            </TD>
            <TD valign=top>
               <% if (c.var("Task.moo").equals("true")) {    c.set("ModeSelector.name", "_postOfficeBox_mode"); %>&nbsp;&nbsp;<jsp:include page='<%= c.getPath("dev/ModeSelector_inc.jsp") %>' flush="true" /><% } %>
            </TD>
         </TR>
         <!-- physicalDeliveryOfficeName -->
         <TR>
            <TD width="27%">
               <%= c.string("PostalAddressItem3") %>:&nbsp;
            </TD>
            <TD>
               <INPUT name='eDir$target$physicalDeliveryOfficeName' type=hidden value="<%= c.var("eDir$target$physicalDeliveryOfficeName") %>">
               <INPUT type=text name=_physicalDeliveryOfficeName 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$postalAddressitem3;if((copied)||(addr3.value != "")){addr3.value=this.value}'  maxlength=128 <% if (c.var("eDirRights$target$physicalDeliveryOfficeName").equals("R") || c.var("eDirRights$target$physicalDeliveryOfficeName").equals("NONE")) { %>DISABLED<% } %> >
            </TD>
            <TD valign=top>
               <% if (c.var("Task.moo").equals("true")) {    c.set("ModeSelector.name", "_physicalDeliveryOfficeName_mode"); %>&nbsp;&nbsp;<jsp:include page='<%= c.getPath("dev/ModeSelector_inc.jsp") %>' flush="true" /><% } %>
            </TD>
         </TR>
         <!-- st -->
         <TR>
            <TD width="27%">
               <%= c.var("stDisplayName") %>:&nbsp;
            </TD>
            <TD>
               <INPUT name='eDir$target$st' type=hidden value="<%= c.var("eDir$target$st") %>">
               <INPUT type=text name=_st size=<%= c.string("UI.textboxSize") %> style="width:<%= c.string("UI.textboxPixel") %>" onChange='var addr4=document.forms[0]._eDir$target$postalAddressitem4;if((copied)||(addr4.value != "")){addr4.value=this.value}' maxlength=128 <% if (c.var("eDirRights$target$st").equals("R") || c.var("eDirRights$target$st").equals("NONE")) { %>DISABLED<% } %> >
            </TD>
            <TD valign=top>
               <% if (c.var("Task.moo").equals("true")) {    c.set("ModeSelector.name", "_st_mode"); %>&nbsp;&nbsp;<jsp:include page='<%= c.getPath("dev/ModeSelector_inc.jsp") %>' flush="true" /><% } %>
            </TD>
         </TR>
         <!-- postalCode -->
         <TR>
            <TD width="27%">
               <%= c.var("postalCodeDisplayName") %>:&nbsp;
            </TD>
            <TD>
               <INPUT name='eDir$target$postalCode' type=hidden value="<%= c.var("eDir$target$postalCode") %>">
               <INPUT type=text name=_postalCode size=<%= c.string("UI.textboxSize") %> style="width:<%= c.string("UI.textboxPixel") %>" onChange='var addr5=document.forms[0]._eDir$target$postalAddressitem5;if((copied)||(addr5.value != "")){addr5.value=this.value}' maxlength=40 <% if (c.var("eDirRights$target$postalCode").equals("R") || c.var("eDirRights$target$postalCode").equals("NONE")) { %>DISABLED<% } %> >
            </TD>
            <TD valign=top>
               <% if (c.var("Task.moo").equals("true")) {    c.set("ModeSelector.name", "_postalCode_mode"); %>&nbsp;&nbsp;<jsp:include page='<%= c.getPath("dev/ModeSelector_inc.jsp") %>' flush="true" /><% } %>
            </TD>
         </TR>
         <TR>
            <INPUT name='eDir$target$postalAddress' type=hidden>
            <c:if test="${edasRights.target.postalAddress.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>
         <!-- postalAddress -->
         <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$postalAddressitem0" onChange="changed=true;"  <% if (c.var("eDirRights$target$postalAddress").equals("R") || c.var("eDirRights$target$postalAddress").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$postalAddressitem1" onChange="changed=true" <% if (c.var("eDirRights$target$postalAddress").equals("R") || c.var("eDirRights$target$postalAddress").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$postalAddressitem2" onChange="changed=true"  <% if (c.var("eDirRights$target$postalAddress").equals("R") || c.var("eDirRights$target$postalAddress").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$postalAddressitem3" onChange="changed=true"<% if (c.var("eDirRights$target$postalAddress").equals("R") || c.var("eDirRights$target$postalAddress").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$postalAddressitem4" onChange="changed=true" <% if (c.var("eDirRights$target$postalAddress").equals("R") || c.var("eDirRights$target$postalAddress").equals("NONE")) { %>DISABLED<% } %>  ></td>
         </tr>
         <tr>
            <TD width="27%"><%= c.var("postalCodeDisplayName") %>: </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$postalAddressitem5" onChange="changed=true" <% if (c.var("eDirRights$target$postalAddress").equals("R") || c.var("eDirRights$target$postalAddress").equals("NONE")) { %>DISABLED<% } %>  ></td>
         </tr>
      </TABLE>
</FORM>
</BODY>
</HTML>

