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

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

<%@ page import="vkc.view.WebShare" %>
<%@ page import="vkc.view.form.ClusterDocumentViewForm" %>
<%@ page import="org.apache.struts.Globals" %>

<vkc:checkLogin/>
<vkc:init/>
<html:html locale="true">
<head>
    <meta http-equiv="content-type"  content="text/html; charset=iso-8859-1" />
    <meta http-equiv="cache-control" content="no-cache" />
    <meta http-equiv="pragma"        content="no-cache" />
    <meta http-equiv="expires"       content="0" />
    <meta http-equiv="robots"        content="noindex" />
    <meta http-equiv="robots"        content="nofollow" />
    <script type="text/javascript" src="<vkc:rewrite page='/common/utils.js'/>"></script>
  	<vkc:cssinclude />

    <script type="text/javascript">
    window.name = "CLUSTERDOCUMENTVIEW";
    var currentCalendar = null;
    var windowOpen = null;

    function init(){
		setAnchor();
    }

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

    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 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 unloadPage() {
    	if ( currentCalendar!=null ) {
      		hideCalendar();
    	}

	    if ( windowOpen != null ) {
	    	windowOpen.close();
	    }
    }

	</script>
</head>

<body onload="init();" onUnload="unloadPage();">
<html:form action="/clusterDocumentView" method="post">
<bean:define id="form" name="clusterDocumentViewForm" scope="request" type="vkc.view.form.ClusterDocumentViewForm" toScope="request"/>

<table width="100%" cellspacing="0" cellpadding="0" border="0">
  <html:hidden property="documentId" />
  <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>

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

  <bean:define id="userDocumentViewSettings" name="documentViewSettings" type="vkc.view.bean.DocumentViewSettings" toScope="request" />

  <tr>
    <td width="100%" valign="top">
    <logic:notEmpty name="form" property="document">
    <bean:define id="doc" name="form" property="document" 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>
        <td>
          <table width="100%" cellspacing="0" cellpadding="0" border="0">
            <tr>
              <td><a name='doc<vkc:write name="doc" property="documentId"/>'></a>
                <table width="100%" cellspacing="0" cellpadding="1" 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="4" height="20"/></td>
                      <td><vkc:img page='<%="/templates/${template.name}" + documentIcon%>' alt=""/></td>
                      <td><vkc:img page="/templates/${template.name}/gfx/trans.gif" alt="" width="2" height="10"/></td>
                      <td align="left" width="100%"><b><vkc:write name="doc" property="title"/></b></td>

                      <td><vkc:img page="/templates/${template.name}/gfx/trans.gif" alt="" width="5" height="10"/></td>
                      <td><vkc:img page="/templates/${template.name}/gfx/border.gif" alt="|" width="2" height="24"/></td>
                      <td><a href="#top" onclick="this.blur();" onfocus="this.blur();"><vkc:img page="/templates/${template.name}/gfx/button-top.gif" border="0" alt="" 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"%>'/>
            <tr><td><vkc:img page="/templates/${template.name}/gfx/trans.gif" width="10" height="10" alt=""/></td></tr>
          </table>
        </td>
      </tr>
    </table>
    </logic:notEmpty>
    </td>
  </tr>
</table>
</html:form>
</body>
</html:html>