<%@ page language="java" buffer="100kb" errorPage="/common/error.jsp"%>

<%@ page import="vkc.view.*" %>

<%@ taglib uri="struts-bean"  prefix="bean"  %>
<%@ taglib uri="struts-html"  prefix="html"  %>
<%@ taglib uri="struts-logic" prefix="logic" %>
<%@ taglib uri="vkc-taglib"   prefix="vkc"   %>

<vkc:init/>
<html:html locale="true">
<head>

    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <meta http-equiv="cache" content="no-cache">
    <meta http-equiv="expires" content="0">

    <title><vkc:message key="vkc" /></title>

	<vkc:cssinclude />

	<script type="text/javascript" src="<vkc:rewrite page='/common/utils.js'/>"></script>

    <script type="text/javascript">
    window.name = "MAINVIEW";
    var associatedTabId = <%=TabId.DOCUMENT_TAB%>;

    function init() {
      	var tabView = getTabView();
        var tabViewForm = tabView.document.forms[0];

        if (tabView && tabView.systemviewtype == "categoryview" && tabView.selectedTabId != associatedTabId) {
           	tabView.location.replace("<%=ctxPath%>/vkcTabView.do?selectedTabId=<%=TabId.DOCUMENT_TAB%>"
          						   + "&lastCategoryId=" + tabViewForm.lastCategoryId.value
          						   + "&lastFunctionalId=" + tabViewForm.lastFunctionalId.value
          						   + "&lastProjectId=" + tabViewForm.lastProjectId.value);
        }
        

        
      	setAnchor();
    }

	function setAnchor() {
		<logic:present parameter="anchor">
			<bean:parameter id="anchor2" name="anchor"/>
			this.location.hash = '<%=anchor2%>';
		</logic:present>
	}

    function openUserInfoWindow( id ) {
        var w = 800;
        var h = 600;
        var leftPosition = screen.width/2  - w/2;
        var topPosition  = screen.height/2 - h/2;
        var settings ='height=' + h + ', width=' + w + ', top=' + topPosition + ', left=' + leftPosition;
        settings += ',scrollbars=yes,resizable';
        settings += ',toolbar=no, location=no, directories=no, status=true, menubar=no';
        var win = window.open( '<vkc:rewrite page="/displayUserInfo.do"/>?userId=' + id, 'USERINFO_MAINVIEW', settings );
        win.focus();                              
    }

    function showDocumentDetails(id) {
        var form = document.forms[0];
        form.selectedId.value = id;

        if (form.action.indexOf('?') == -1) {
          form.action = form.action + "?action.show.document.details=true";
        } else {
          form.action = form.action + "&action.show.document.details=true";
        }

        form.submit();
    }

    function hideDocumentDetails(id) {
        var form = document.forms[0];
        form.selectedId.value = id;

        if (form.action.indexOf('?') == -1) {
          form.action = form.action + "?action.hide.document.details=true";
        } else {
          form.action = form.action + "&action.hide.document.details=true";
        }

        form.submit();
    }

    function confirmDeleteDocument(elem) {
        if (confirm('<vkc:message javascript="true" filter="false" key="vkc.string.confirm.delete.document"/>')) {
             var form = document.forms[0];
             disableAllButtons(elem);
             form.submit();
        }
    }

    </script>

</head>
<body onload="init();" marginwidth=5 marginheight=0 topmargin="0" bottommargin="5" leftmargin="5" rightmargin="5">
<html:form action="/showDocumentVersions" method="post">

<bean:define id="form" name="showDocumentVersionsForm" type="vkc.view.form.ShowDocumentVersionsForm" toScope="request"/>

<html:hidden property="sourcePageId"/>
<html:hidden property="documentId"/>
<html:hidden property="categoryId"/>
<html:hidden property="selectedId" />

<logic:iterate id="id" name="form" property="showDocumentDetails" type="java.lang.Integer">
  <html:hidden property="showDocumentDetails" name="form" value='<%=String.valueOf(id.toString())%>'/>
</logic:iterate>
<logic:notEmpty name="form" property="targetId">
  <html:hidden property="targetId" name="form"/>
</logic:notEmpty>
<logic:notEmpty name="form" property="subTargetId">
  <html:hidden property="subTargetId" name="form"/>
</logic:notEmpty>
  
<bean:define id="userDocumentViewSettings" name="documentViewSettings" type="vkc.view.bean.DocumentViewSettings" toScope="request" />

<table width="100%" cellspacing="0" cellpadding="0" border="0">
  <logic:present name="<%=org.apache.struts.Globals.ERROR_KEY%>">
  <html:messages id="error" message="false">
  <tr><td align="left" nowrap="nowrap" colspan="2"><span class="error"><b><vkc:write name="error"/></b></span></td></tr>
  </html:messages>  
  <tr><td colspan="2"><vkc:img page="/templates/${template.name}/gfx/trans.gif" alt="" height="5" border="0"/></td></tr>
  </logic:present>
  <tr><td><b><vkc:message key="vkc.document.versions"/>:</b></td></tr>  
  <vkc:hline colspan="2" lineClass="hline" lineHeight="1" topSpace="5" bottomSpace="5"/>
</table>
<!-- Dokumente -->
<logic:notEmpty  name="form" property="documents">
<logic:iterate id="doc" name="form" property="documents" type="vkc.db.entities.VKCDocument">
<bean:define id="documentId" name="doc" property="documentId" type="java.lang.Integer"/>
<table width="100%" cellspacing="0" cellpadding="0" border="0">
  <tr>
    <logic:equal name="form" property="manageDocumentVersions" value="true">
    <td width="1%" valign="top">
      <html:radio name="form" property="deleteId" value='<%=documentId.toString()%>'/>
    </td>
    </logic:equal>

    <td width="100%">
      <table width="100%" cellspacing="0" cellpadding="0" border="0">
        <tr>
		  <a name='doc<vkc:write name="doc" property="documentId"/>'></a>
          <td>
            <table width="100%" cellspacing="0" cellpadding="0" border="0">
              <tbody>
                <tr class="color_doctitle">
				  <logic:equal name="form" property='<%= "showDocDetails[" + documentId + "]" %>' value="false">
				  <td><vkc:link href='<%= "javascript:showDocumentDetails(" + documentId + ");" %>'><vkc:img page="/templates/${template.name}/gfx/plus.gif" border="0" titleKey="vkc.tooltip.show.document.details"/></vkc:link></td>
				  </logic:equal>          

				  <logic:equal name="form" property='<%= "showDocDetails[" + documentId + "]" %>' value="true">
				  <td><vkc:link href='<%= "javascript:hideDocumentDetails(" + documentId + ");" %>'><vkc:img page="/templates/${template.name}/gfx/minus.gif" border="0" titleKey="vkc.tooltip.hide.document.details"/></vkc:link></td>
				  </logic:equal>          

                  <bean:define id="documentIcon" name="doc" property="documentIcon" type="java.lang.String"/>
				  <td><vkc:img page="/templates/${template.name}/gfx/trans.gif" alt="" width="5" height="10"/></td>
                  <td><vkc:img page='<%="/templates/${template.name}" + documentIcon%>' alt=""/></td>
				  <td><vkc:img page="/templates/${template.name}/gfx/trans.gif" alt="" width="5" height="10"/></td>
                  <td align="left" width="100%"><b><vkc:write name="doc" property="header"/></b></td>
                  
                  <logic:equal name="form" property="comparable" value="true">
                 	 <td><html:multibox property="selectedDocuments" value='<%=documentId.toString()%>'/></td>
                  </logic:equal>
				  <td><vkc:img page="/templates/${template.name}/gfx/border.gif" alt="|" width="2" height="24"/></td>
                  <td><vkc:img page="/templates/${template.name}/gfx/trans.gif" alt="" width="5" height="10"/></td>
                  <td><a href="#top" onclick="this.blur();" onfocus="this.blur();"><vkc:img page="/templates/${template.name}/gfx/button-top.gif" alt="" border="0" titleKey="vkc.tooltip.gototop"/></a></td>
				  <td><vkc:img page="/templates/${template.name}/gfx/trans.gif" alt="" width="5" height="10"/></td>
                </tr>
              </tbody>
            </table>
          </td>
        </tr>

        <bean:define id="document" name="doc" type="vkc.db.entities.VKCDocument" toScope="request" />
      	<bean:define id="currentUser" name="form" property="user" type="vkc.db.entities.VKCUser" toScope="request"/>

	    <logic:equal name="form" property='<%= "showDocDetails[" + documentId + "]" %>' value="true">
        <bean:define id="documentViewSettings" name="documentViewSettings" property="fullviewDocumentViewSettings" type="vkc.view.bean.DocumentViewSettings" toScope="request" />
	    </logic:equal>          
	    <logic:equal name="form" property='<%= "showDocDetails[" + documentId + "]" %>' value="false">
        <bean:define id="documentViewSettings" name="userDocumentViewSettings" type="vkc.view.bean.DocumentViewSettings" toScope="request" />
	    </logic:equal>          

   		<jsp:include page='<%="/templates/" + template + "/common/DocumentView.jsp"%>'/>
      </table>
    </td> 
  </tr>
</table>
</logic:iterate>
</logic:notEmpty>

<table width="100%" cellspacing="1" cellpadding="0" border="0">
  <vkc:hline colspan="2" lineClass="hline" lineHeight="1" topSpace="5" bottomSpace="5"/>
  <tr>
    <td align="center" nowrap="nowrap">
      <logic:equal name="form" property="manageDocumentVersions" value="true">
      <vkc:button property="action.delete.document.version" onclick="confirmDeleteDocument(this);"><vkc:message key="button.delete"/></vkc:button>
	  </logic:equal>
      <vkc:button property="action.back" onclick="javascript:disableAllButtonsAndSubmit(this);"><vkc:message key="button.back"/></vkc:button>
    </td>
	
	<logic:equal name="form" property="comparable" value="true">
	<td align="right" nowrap="nowrap">
      <vkc:button property="action.compare.documents" onclick="javascript:disableAllButtonsAndSubmit(this);"><vkc:message key="button.compare"/></vkc:button>
    </td>
	</logic:equal>
  </tr>
</table>

</html:form>
</body>
</html:html>