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

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

<%@ 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:checkLogin />
<vkc:init/>
<html:html locale="true">
<head>

	<vkc:cssinclude />

    <meta http-equiv="content-type"  content="text/html; charset=iso-8859-1" />
	<script type="text/javascript" src="<vkc:rewrite page='/common/utils.js'/>"></script>

    <script type="text/javascript">
	window.name = "MAINVIEW";
	var associatedTabId = <%=TabId.SEARCH_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.SEARCH_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 changePage(id) {
        var form = document.forms[0];
        form.currentResultPageId.value = id;

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

        form.submit();
    }

    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();
    }
    </script>
</head>
<body onload="init();" marginwidth="5" marginheight="0" topmargin="0" bottommargin="5" leftmargin="5" rightmargin="5">
<html:form action="/searchRelatedDocuments" method="post">
<bean:define id="form" name="searchRelatedDocumentsForm" scope="request" type="vkc.search.form.SearchRelatedDocumentsForm" toScope="request"/>
<bean:define id="pageCount" name="form" property="pageCount"/>
<bean:define id="hitsCount" name="form" property="hitsCount"/>

<html:hidden property="categoryId"/>
<html:hidden property="documentId"/>
<html:hidden property="currentResultPageId"/>
  
<logic:greaterThan name="hitsCount" value="0">
<table width="100%" cellspacing="1" cellpadding="2" border="0">
  <tr>
    <td width="100%" align="center">
      <table width="100%" align="center" cellspacing="0" cellpadding="2" border="0">
        <tr>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td nowrap="nowrap">
            <table width="100%" cellspacing="0" cellpadding="2" border="0">
              <tr>
                <td nowrap="nowrap">
                  <table cellspacing="0" cellpadding="2" border="0">
                    <tr>
                      <td nowrap="nowrap"><vkc:message key="vkc.search.display"/></td>
                      <td nowrap="nowrap"><b><vkc:message key="vkc.search.for"/>&nbsp;<vkc:message key="vkc.search.sortResults"/></b></td>
                      <td width="100%">
                        <html:select property="documentSortMode" size="1" onchange="submit();">
                          <html:option value='<%= String.valueOf( SearchRelatedDocumentsForm.DOCUMENT_SORT_SCORE_UP ) %>'><vkc:message key="vkc.search.sortResults.ascendingByScore" /></html:option>
                          <html:option value='<%= String.valueOf( SearchRelatedDocumentsForm.DOCUMENT_SORT_SCORE_DOWN ) %>'><vkc:message key="vkc.search.sortResults.descendingByScore" /></html:option>
					      <html:option value='<%= String.valueOf( SearchRelatedDocumentsForm.DOCUMENT_SORT_PUBLISHING_DATE_UP ) %>'><vkc:message key="vkc.document.sort.ascbypublishingdate"/></html:option>
					      <html:option value='<%= String.valueOf( SearchRelatedDocumentsForm.DOCUMENT_SORT_PUBLISHING_DATE_DOWN ) %>'><vkc:message key="vkc.document.sort.descbypublishingdate"/></html:option>
					      <logic:equal name="categorySettings" property="showCreationDate" value="true">
					      <html:option value='<%= String.valueOf( SearchRelatedDocumentsForm.DOCUMENT_SORT_CREATION_DATE_UP ) %>'><vkc:message key="vkc.document.sort.ascbycreationdate"/></html:option>
					      <html:option value='<%= String.valueOf( SearchRelatedDocumentsForm.DOCUMENT_SORT_CREATION_DATE_DOWN ) %>'><vkc:message key="vkc.document.sort.descbycreationdate"/></html:option>
					      </logic:equal>
                          <html:option value='<%= String.valueOf( SearchRelatedDocumentsForm.DOCUMENT_SORT_TITLE_UP ) %>'><vkc:message key="vkc.document.sort.ascbytitle"/></html:option>
                          <html:option value='<%= String.valueOf( SearchRelatedDocumentsForm.DOCUMENT_SORT_TITLE_DOWN ) %>'><vkc:message key="vkc.document.sort.descbytitle"/></html:option>
                          <html:option value='<%= String.valueOf( SearchRelatedDocumentsForm.DOCUMENT_SORT_AUTHOR_UP ) %>'><vkc:message key="vkc.document.sort.ascbyauthor"/></html:option>
                          <html:option value='<%= String.valueOf( SearchRelatedDocumentsForm.DOCUMENT_SORT_AUTHOR_DOWN ) %>'><vkc:message key="vkc.document.sort.descbyauthor"/></html:option>
                          <html:option value='<%= String.valueOf( SearchRelatedDocumentsForm.DOCUMENT_SORT_PUBLISHER_UP ) %>'><vkc:message key="vkc.document.sort.ascbypublisher"/></html:option>
                          <html:option value='<%= String.valueOf( SearchRelatedDocumentsForm.DOCUMENT_SORT_PUBLISHER_DOWN ) %>'><vkc:message key="vkc.document.sort.descbypublisher"/></html:option>
                          <html:option value='<%= String.valueOf( SearchRelatedDocumentsForm.DOCUMENT_SORT_SIZE_UP ) %>'><vkc:message key="vkc.document.sort.ascbysize"/></html:option>
                          <html:option value='<%= String.valueOf( SearchRelatedDocumentsForm.DOCUMENT_SORT_SIZE_DOWN ) %>'><vkc:message key="vkc.document.sort.descbysize"/></html:option>
                          <html:option value='<%= String.valueOf( SearchRelatedDocumentsForm.DOCUMENT_SORT_TYPE_UP ) %>'><vkc:message key="vkc.document.sort.ascbytype"/></html:option>
                          <html:option value='<%= String.valueOf( SearchRelatedDocumentsForm.DOCUMENT_SORT_TYPE_DOWN ) %>'><vkc:message key="vkc.document.sort.descbytype"/></html:option>
                        </html:select>
                      </td>
                      <td nowrap="nowrap">&nbsp;</td>
                    </tr>
                    <tr>
                      <td nowrap="nowrap">&nbsp;</td>
                      <td nowrap="nowrap"><b><vkc:message key="vkc.search.for"/>&nbsp;<vkc:message key="vkc.search.numberOfResultsPerPage"/></b></td>
                      <td width="100%">
                        <html:select property="selectedNumberOfResultsPerPage" size="1" onchange="submit();">
                          <html:option value="5"><vkc:message key="vkc.search.numberOfResultsPerPage.5" /></html:option>
                          <html:option value="10"><vkc:message key="vkc.search.numberOfResultsPerPage.10Hits" /></html:option>
                          <html:option value="20"><vkc:message key="vkc.search.numberOfResultsPerPage.20Hits" /></html:option>
                          <html:option value="30"><vkc:message key="vkc.search.numberOfResultsPerPage.30Hits" /></html:option>
                          <html:option value="40"><vkc:message key="vkc.search.numberOfResultsPerPage.40Hits" /></html:option>
                          <html:option value="50"><vkc:message key="vkc.search.numberOfResultsPerPage.50Hits" /></html:option>
                        </html:select>
                      </td>
                      <td nowrap="nowrap"><vkc:button property="action.back" onclick="javascript:disableAllButtonsAndSubmit(this);"><vkc:message key="button.category.view"/></vkc:button></td>
                    </tr>
                  </table>
                </td>
              </tr>
            </table>
          </td>
        </tr>
        <tr><td><hr width="100%" size="1" noshade="noshade"/></td></tr>
      </table>
    </td>
  </tr>
</table>

<a name="results"></a>
<%-- BEGINN: Nochmal die Scroll-bar --%>
<table width="100%" cellspacing="1" cellpadding="4" border="0">
  <tr>
    <td class="search_block">
      <table width="100%" border="0">
        <tr>
          <td align="center" class="search_header">
            <font style="font-size:10pt;font-style:italic;"><vkc:write name="hitsCount"/>&nbsp;<vkc:message key="vkc.search.hitsFound" /></font>
          </td>
        </tr>
        <logic:greaterThan name="pageCount" value="1">
        <tr>
          <td align="center">
            <vkc:message key="vkc.search.resultPage" />&nbsp;
            <bean:define id="selectedPageId" name="form" property="currentResultPageId" type="java.lang.Integer"/>

            <logic:greaterThan name="selectedPageId" value="1">
            <bean:define id="previousPageId" name="form" property="previousPageId" type="java.lang.Integer"/>
            <vkc:link href='<%= "javascript:changePage(" + previousPageId + ");" %>'>
              <span style="text-decoration:underline"><vkc:message key="vkc.search.previousPage"/></span>
              </vkc:link>&nbsp;
            </logic:greaterThan>

            <logic:iterate id="pageItem" name="form" property="pagesIndex">
            <logic:notEqual name="pageItem" value='<%= String.valueOf( selectedPageId.toString() ) %>'>
            <vkc:link href='<%= "javascript:changePage(" + pageItem + ");" %>'>
              <span style="text-decoration:underline"><vkc:write name="pageItem"/></span>
            </vkc:link>&nbsp;
            </logic:notEqual>

            <logic:equal name="pageItem" value='<%= String.valueOf( selectedPageId.toString() ) %>'>
            <vkc:write name="pageItem" />&nbsp;
            </logic:equal>
            </logic:iterate>

            <logic:lessThan name="selectedPageId" value="<%= String.valueOf( pageCount.toString() ) %>">
            <bean:define id="nextPageId" name="form" property="nextPageId" type="java.lang.Integer"/>
            <vkc:link href='<%= "javascript:changePage(" + nextPageId + ");" %>'>
                <span style="text-decoration:underline"><vkc:message key="vkc.search.nextPage"/></span>
              </vkc:link>
            </logic:lessThan>
          </td>
        </tr>
        </logic:greaterThan>
      </table>
    </td>
  </tr>
</table>
</logic:greaterThan>
<%-- ENDE: Nochmal die Scroll-bar --%>

<logic:greaterThan name="hitsCount" value="0">
<%--  BEGINN: Darstellung der Suchergebnisse --%>
  <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" />
  <bean:define id="startIndex" name="form" property="startIndex" type="java.lang.Integer"/>

  <logic:iterate id="result" name="form" property="results" type="vkc.search.SearchResultEntry" indexId="ctr">
  <bean:define id="doc" name="result" property="toVKCDocument" 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 nowrap="nowrap" colspan="2">
		  <a name='doc<vkc:write name="doc" property="documentId"/>'></a>
		  <table width="100%" cellspacing="0" cellpadding="0" border="0">
		    <tr><td><vkc:img page="/templates/${template.name}/gfx/trans.gif" width="10" height="10" alt=""/></td></tr>
		    <tr>
		      <td>
		        <table width="100%" cellspacing="0" cellpadding="0" border="0">
		          <tr>
		            <td>
		              <table width="100%" cellspacing="0" cellpadding="0" border="0">
		                <tbody>
			              <tr class="color_doctitle">
					        <td><b>&nbsp;<vkc:message key="vkc.string.number"/>&nbsp;<%=startIndex.intValue() + ctr.intValue() + 1%>:&nbsp;&nbsp;</b></td>
						    <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>          
						    <td><vkc:img page="/templates/${template.name}/gfx/trans.gif" alt="" width="4" height="10"/></td>
		                    <td><vkc:img page='<%="/templates/${template.name}" + doc.getDocumentIcon()%>' alt='' border='0'/></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="title"/></b></td>
		      			    <td nowrap="nowrap">[&nbsp;<vkc:message key="vkc.search.score"/>&nbsp;<vkc:write name="result" property="percent" />%&nbsp;]</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="displayCategoryPath" type="java.lang.String" value="true" toScope="request"/>
	              <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>
	    </td>
	  </tr>
	</table>
  </logic:iterate>
<%-- ENDE: Darstellung der Suchergebnisse --%>
</logic:greaterThan>

<%-- BEGINN: Nochmal die Scroll-bar --%>
<logic:greaterThan name="hitsCount" value="0">
<table width="100%" cellspacing="1" cellpadding="4" border="0">
  <tr>
    <td class="search_block">
      <table width="100%" border="0">
        <tr>
          <td align="center" class="search_header">
            <font style="font-size:10pt;font-style:italic;"><vkc:write name="hitsCount"/>&nbsp;<vkc:message key="vkc.search.hitsFound" /></font>
          </td>
        </tr>
        <logic:greaterThan name="pageCount" value="1">
        <tr>
          <td align="center">
            <vkc:message key="vkc.search.resultPage" />&nbsp;
            <bean:define id="selectedPageId" name="form" property="currentResultPageId" type="java.lang.Integer"/>

            <logic:greaterThan name="selectedPageId" value="1">
            <bean:define id="previousPageId" name="form" property="previousPageId" type="java.lang.Integer"/>
            <vkc:link href='<%= "javascript:changePage(" + previousPageId + ");" %>'>
              <span style="text-decoration:underline"><vkc:message key="vkc.search.previousPage"/></span>
              </vkc:link>&nbsp;
            </logic:greaterThan>

            <logic:iterate id="pageItem" name="form" property="pagesIndex">
            <logic:notEqual name="pageItem" value='<%= String.valueOf( selectedPageId.toString() ) %>'>
            <vkc:link href='<%= "javascript:changePage(" + pageItem + ");" %>'>
              <span style="text-decoration:underline"><vkc:write name="pageItem"/></span>
            </vkc:link>&nbsp;
            </logic:notEqual>

            <logic:equal name="pageItem" value='<%= String.valueOf( selectedPageId.toString() ) %>'>
            <vkc:write name="pageItem" />&nbsp;
            </logic:equal>
            </logic:iterate>

            <logic:lessThan name="selectedPageId" value="<%= String.valueOf( pageCount.toString() ) %>">
            <bean:define id="nextPageId" name="form" property="nextPageId" type="java.lang.Integer"/>
            <vkc:link href='<%= "javascript:changePage(" + nextPageId + ");" %>'>
                <span style="text-decoration:underline"><vkc:message key="vkc.search.nextPage"/></span>
              </vkc:link>
            </logic:lessThan>
          </td>
        </tr>
        </logic:greaterThan>
      </table>
    </td>
  </tr>
</table>
</logic:greaterThan>
<%-- ENDE: Nochmal die Scroll-bar --%>

<logic:lessEqual name="hitsCount" value="0">
<table width="100%" cellspacing="0" cellpadding="0" border="0">
  <tr><td width="100%" align="center"><vkc:message key="vkc.search.relatedDocuments.empty"/></b></td></tr>
  <vkc:hline colspan="5" lineClass="hline" lineHeight="1" topSpace="5" bottomSpace="5"/>
  <tr><td width="100%" align="center"><vkc:button property="action.back" onclick="javascript:disableAllButtonsAndSubmit(this);"><vkc:message key="button.category.view"/></vkc:button></td></tr>
</table>    
</logic:lessEqual>
</html:form>
</body>
</html:html>