<%@ page pageEncoding="utf-8" contentType="text/html;charset=utf-8" %>
<%@ page import="com.novell.webaccess.common.JSPConduit" %>
<%@ page import="com.novell.emframe.dev.eMFrameUtils" %>
<%@ page import="com.novell.emframe.dev.propertyBook.*" %>
<%@page import="com.novell.emframe.dev.PropertyBookPage;"%>

<%
   JSPConduit c = JSPConduit.getJSPConduit(request);
   c.stringTable("DevResources");
   c.stringTable("FwResources");
%>
<%@ taglib uri="/WEB-INF/iman.tld" prefix="iman" %>

<HTML>
<HEAD>
   <iman:eMFrameScripts/>
   <jsp:include page='<%= c.getPath("dev/HelpScripts_inc.jsp") %>' flush="true" />

   <SCRIPT language="JavaScript" src="<%= c.getModulesUrl() %>/dev/javascripts/BookScripts.js"></SCRIPT>
   <SCRIPT language="JavaScript" src="<%= c.getModulesUrl() %>/dev/javascripts/BookScriptsDefault.js"></SCRIPT>
   <LINK rel="stylesheet" href="<%= c.getModulesUrl() %>/fw/css/bookStyles.css">
   <STYLE>body,td { background-color: #ffffff; color: #000000 }</STYLE>

   <SCRIPT>

      function createNewWindow(url,myname,w,h)
      {
         var scrollbars = true;
         LeftPosition=(screen.width)?(screen.width-w)/2:100;
         TopPosition=(screen.height)?(screen.height-h)/2:100;
         settings='width='+w+',height='+h+',top='+TopPosition+',left='+ LeftPosition+',scrollbars='+scrollbars+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
         win=window.open(url,myname,settings);
         if(win.focus)
         {
            win.focus();
         }
      }

      function showPrefs()
      {
         createNewWindow("frameservice?taskId=<%= c.var("taskId")%>&nextState=showPageOrder&activePage=0", "iManager", 600, 500);
      }

      function showHelp()
      {
         if(parent.bookBody.document.forms[0].helpfile)
         {
            var helpFile = parent.bookBody.document.forms[0].helpfile.value;
            if(helpFile != null && helpFile.length>0)
            {
               launchHelp(helpFile);
            }
            else
            {
               alert("<%= c.string("Book.NoHelp") %>");
            }
         }
      }

      <%-- save vars for later use --%>
      vars_taskId = "<%= c.var("taskId") %>";
      vars_isMoo = <% if (c.var("Task.moo").equals("true")) { %>true<% } else { %>false<% } %>;
      rc_pageLoading = "<%= c.string("Book.pageLoading") %>";

      function init()
      {
         window.isLoaded=true;

         <% if (c.var("Book.countWarnOnOpen").equals("") == false) { %>
            alert("<%= c.toScript(c.var("Book.countWarning")) %>");
         <% } %>
			reposition();
      }
    </SCRIPT>
</HEAD>
<BODY onload="init()">

<TABLE style="margin-bottom:10" width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#ffffff">
   <TR>
      <TD>
      <%
        String targetDisplayName = c.var("Book.Target.displayName");
      %>
            <FONT class=headpb><%= c.var("Task.displayName") %>:&nbsp;</FONT>
            <% if ( c.def("Book.Target.icon") && c.var("Book.Target.icon").equals("") == false) { %><IMG src="<%= c.getModulesUrl() %>/dev/images/dir/<%= c.var("Book.Target.icon") %>" alt="<%= c.toDisplay(c.var("Book.Target.Type.displayName")) %>" title="<%= c.toDisplay(c.var("Book.Target.Type.displayName")) %>" border=0 ALIGN="absmiddle"><% } %>
            <div class=head1pb style="position:absolute; width:70%; display:inline; overflow:hidden;" title="<%= c.var("Book.Target.displayName")%>"><%= c.toHTML(targetDisplayName)%></div>
            <% if (c.var("Book.countWarning").equals("") == false) { %>&nbsp;<A href="#" onClick="alert('<%= c.toScript(c.var("Book.countWarning")) %>')" style="color: #039; text-decoration: underline; font-size:13px"><%= c.toDisplay(c.string("General.countWarningLink")) %></A><% } %>
      <%
      	if(targetDisplayName.length() < 30)
      	{
      		//dont need to move the help/prefs button.
      		out.print("</TD><TD width=\"8%\" height=\"26\">");
      	}
      %>
      
         <SPAN id="helpButton" style="visibility:visible; z-index:30000; float:right">&nbsp;<A href="Javascript: parent.bookHeader.showHelp();"><IMG name="Help" alt="<%= c.string("Button.Help.alt") %>" title="<%= c.string("Button.Help.alt") %>" src="<%= c.getModulesUrl() + "/dev/images/help_16.gif" %>" border=0></A></SPAN>
         <SPAN id="prefrencesButton" style="visibility:visible; z-index:30000; float:right">&nbsp;<A href="Javascript: showPrefs();"><IMG name="Prefs" alt="<%= c.string("Book.Preferences") %>" title="<%= c.string("Book.Preferences") %>" src="<%= c.getModulesUrl() + "/dev/images/prefs_16.gif" %>" border=0></A></SPAN>
      </TD>
   </TR>
   <TR style="height:2;background-color:#458ab9;"><td colspan=2 style="font-size:2">&nbsp;</td></tr>
</TABLE>





<%
   int selectedChapter = 0;
   int chapterCount = c.toInt("chapter.count");
   int nCols = chapterCount*2 +3;
%>


<% for(int tabi=0; tabi<chapterCount; tabi++) { %>
<DIV id="tab<%= tabi %>" style="position:absolute; left:1px; top:35px; width:500px; height:62px; overflow:auto; display:none;">
<TABLE border="0" cellpadding="0" cellspacing="0" width="100%">
   <TR><TD HEIGHT="3px"></TD></TR>
   <TR>
      <TD width="5"><img src="spacer.gif" width="5" height="1" border="0"></TD>
		<TD><IMG src="<%= c.getModulesUrl() %>/dev/images/first_left_<% if (tabi==0) { %>on<% } else { %>off<% } %>.gif" width="18" height="20" border="0"></TD>


      <% for(int tabj=0; tabj<chapterCount; tabj++) { %>

         <TD class="<% if (tabi==tabj) { %>tab1s<% } else { %>tab1u<% } %>" nowrap><NOBR><A href="#" onClick="if(showPage('<%= c.var("chapter."+tabj+ ".0.id") %>')==true)selectChapter(<%= tabj %>); return false;"><SPAN class="<% if (tabi==tabj) { %>tab1s<% } else { %>tab1u<% } %>"><%= c.var("chapter."+tabj+ ".name") %></SPAN></A></NOBR></TD>

         <%
            String image = null;
            if (tabj+1 == chapterCount)
            {
               if (tabi==tabj)
               {
                  image = "last_right_on.gif";
               }
               else
               {
                  image = "last_right_off.gif";
               }
            }
            else
            {
               if (tabi==tabj)
               {
                  image = "overlap_on_off.gif";
               }
               else if (tabi==tabj+1)
               {
                  image = "overlap_off_on.gif";
               }
               else
               {
                  image = "overlap_off_off.gif";
               }
            }
         %>

         <TD><IMG src="<%= c.getModulesUrl() %>/dev/images/<%= image %>" width="18" height="20" border="0"></TD>

         <% if (tabj+1==chapterCount) { %><TD width="100%"></TD><% }
      } %>
   </TR>
</TABLE>
<TABLE border="0" cellpadding="0" cellspacing="0" width="100%">

   <TR>
      <TD class=tab2u colspan=<%= nCols %> HEIGHT="24px">
         <%
            int currentChapterSize = c.toInt("chapter."+tabi+ ".count");
            for(int subtabi=0; subtabi<currentChapterSize; subtabi++)
            {
               String chapterId=c.var("chapter."+tabi+ "."+subtabi+ ".id");
               String chapterName=c.var("chapter."+tabi+ "."+subtabi+ ".name");

               %>&nbsp;<A href="#" onClick="showPage('<%= chapterId %>');" <% if (chapterId.equals(c.var("activePage"))) { selectedChapter=tabi; } %>><SPAN id="tab_<%= chapterId %>" <% if (tabi==0 && subtabi==0) { %>class="tab2s"<% } else { %>class="tab2u"<% }%>><%= chapterName %></SPAN></A>&nbsp;<% if (subtabi+1 < currentChapterSize) { %>|<% } 
            }
         %>
      </TD>
   </TR>
</TABLE>
</DIV>
<% } %>



<SCRIPT>
	var pageIndiciesByPageId = new Object();
	 <%
	 java.util.Vector pages = (java.util.Vector)request.getAttribute("pages");
	 int pageSize = pages.size();
	 for(int pagei=0; pagei<pageSize; pagei++)
	 {
			
         out.print("pageIndiciesByPageId[\"" + ((PropertyBookPage)(pages.get(pagei))).getId() + "\"] =  \"" + pagei + "\";");
	 }
	 %>
	
   tabs = [
   <%
      int tabiSize = c.toInt("chapter.count");
      for(int tabi=0; tabi<tabiSize; tabi++)
      {
         out.print("[");

         int tabjSize = c.toInt("chapter."+tabi+ ".count");
         for(int tabj=0; tabj<tabjSize; tabj++)
         {
            String key="chapter."+tabi+ "."+tabj;
            out.print("[\"" + c.var(key+ ".id") + "\", \"" + c.var(key+ ".name") + "\"]");

            if(tabj < tabjSize-1)
            {
               out.print(",");
            }
         }

         out.print("]");

         if(tabi < tabiSize-1)
         {
            out.print(",");
         }
      }
   %>
   ]


   <%
      for(int i=0; i<chapterCount; i++)
      {
         out.print("activePage");
         out.print(c.var("chapterIndex"));
         out.println("=0;");
      }
   %>

    selectChapter(<%= selectedChapter %>);
</SCRIPT>
</BODY>
</HTML>
