<%@ page language="java" buffer="100kb" errorPage="/common/error.jsp"%>
<%@ page import="vkc.db.entities.VKCDocument" %>
<%@ 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:checkLogin />
<vkc:init/>
<html:html locale="true">
<head>

    <title><vkc:message key="vkc.string.historyList"/></title>

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

	<vkc:cssinclude />

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

    <script type="text/javascript">
   	window.name = "MAINVIEW";
   	var associatedTabId = <%=TabId.FAVORITES_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.FAVORITES_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 deleteSelectedDocumentFavorites(elem) {
        var form = document.forms[ 0 ];
        var numChecked = getNumberOfCheckedEntries();
        	        
        if ( numChecked == 0 ) {
            alert( '<vkc:message javascript="true" filter="false" key="error.noitem_checked"/>' );
            return;
        }

        if ( !confirm( '<vkc:message javascript="true" filter="false" key="vkc.string.confirm.delete.selection"/>' ) ) {
            return;
		}               

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

        disableAllButtons(elem);
        form.submit();
    }
    
	function checkAll( mForm ) {			
		for( var i=0 ; i<mForm.elements.length ; i++ ) { 
			var elem = mForm.elements[i];
			if( elem.name!='allItems' ) {
			    elem.checked=mForm.allItems.checked;
			}
		}
	}
	
	function getNumberOfCheckedEntries() {
        var form  = document.forms[ 0 ];
        var field = form.selectedIds;

        if ( !field )
        	return 0;

        if ( !field.length ) {

            <%-- nur eine Checkbox auf der Seite --%>
            if ( field.checked ) {
                return 1;
            } else {
                return 0;
            }
        }

        var checked = 0;
        for ( var i=0 ; i<field.length ; i++ ) {
            if ( field[i].checked ) {
                checked++;
            }
        }
        return checked;
	}
	
    </script>
</head>

<body onload="init();" topmargin="0" marginheight="0">
<table width="100%" align="center" cellspacing="0" cellpadding="0" border="0">
  <tr><td><vkc:img page="/templates/${template.name}/gfx/trans.gif" alt="" width="1" height="5"/></td></tr>
  <tr>
    <td nowrap="nowrap"><vkc:img page="/templates/${template.name}/gfx/button-add-catfavorites.gif" border="0" alt=""/></td>
    <td nowrap="nowrap">&nbsp;</td>
    <td nowrap="nowrap"><vkc:link page="/showCategoryFavorites.do" style="font-weight:normal;"><vkc:message key="vkc.favorites.catfavorites"/></vkc:link>&nbsp;&nbsp;</td>
    <td nowrap="nowrap">&nbsp;&nbsp;&nbsp;&nbsp;</td>
    <td nowrap="nowrap"><vkc:img page="/templates/${template.name}/gfx/button-add-docfavorites.gif" border="0" alt=""/></td>
    <td nowrap="nowrap">&nbsp;</td>
    <td nowrap="nowrap"><vkc:link page="/showDocumentFavorites.do" style="font-weight:bold;"><vkc:message key="vkc.favorites.docfavorites"/></vkc:link>&nbsp;&nbsp;</td>
    <td width="100%" nowrap="nowrap">&nbsp;</td>
  </tr>
  <vkc:hline colspan="15" lineClass="hline" lineHeight="1" topSpace="10" bottomSpace="5"/>
</table>
<html:form action="/showDocumentFavorites" method="post">
<bean:define id="form" name="showDocumentFavoritesForm" type="vkc.profile.form.ShowDocumentFavoritesForm" toScope="request"/>

<logic:notEmpty name="form" property="documents">
<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" />
  
<logic:iterate id="udf" name="form" property="documents" type="vkc.db.entities.VKCUserDocFavorite" indexId="index">
<bean:define id="doc" name="udf" property="document" type="vkc.db.entities.VKCDocument"/>
<logic:equal name="doc" property="flag" value="<%=String.valueOf(VKCDocument.FLAG_PUBLISHED)%>">
<bean:define id="documentId" name="doc" property="documentId" type="java.lang.Integer"/>
<table width="100%" cellspacing="0" cellpadding="0" border="0">
  <tr>
    <td width="1%" valign="top">
      <html:multibox name="form" property="selectedIds" onfocus="this.blur();"><vkc:write name="doc" property="documentId"/></html:multibox>        
    </td>

    <td width="100%">
      <table width="100%" cellspacing="0" cellpadding="0" border="0">
        <tr>
		  <a name='<%="doc" + doc.getDocumentId()%>'></a>
          <td>
            <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>&nbsp;</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>&nbsp;</td>
				  </logic:equal>          

                  <bean:define id="documentIcon" name="doc" property="documentIcon" type="java.lang.String"/>
                  <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 width="100%" align="left"><b><vkc:write name="doc" property="title"/></b></td>
				  <td nowrap="nowrap"><b>[&nbsp;<vkc:message key="vkc.favorites.document.created"/>:</b>&nbsp;<vkc:write name="udf" property="created" formatKey="date.medium.format"/>&nbsp;<b>]</b></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"%>'/>

        <tr><td><vkc:img page="/templates/${template.name}/gfx/trans.gif" alt="" width="10" height="10"/></td></tr>
      </table>
    </td> 
  </tr>
</table>
</logic:equal>
</logic:iterate>
  
<table width="100%" cellspacing="0" cellpadding="0" border="0">
  <tr><td align="left"><input type="checkbox" name="allItems" value="allItems" onclick="javascript:checkAll(this.form);">&nbsp;<vkc:message key="vkc.string.checkAll"/></td></tr>
</table>

<table width="100%" cellspacing="0" cellpadding="0" border="0">
  <vkc:hline colspan="15" lineClass="hline" lineHeight="1" topSpace="10" bottomSpace="5"/>
  <tr>
    <td align="left"><vkc:button property="deleteButton" onclick="javascript:deleteSelectedDocumentFavorites(this);"><vkc:message key="vkc.favorites.deleteselectedfavorites"/></vkc:button></td>
    <td width="100%" align="left">&nbsp;</td>
  </tr>
</table>
</logic:notEmpty>
<logic:empty name="form" property="documents">
<table width="100%" cellspacing="0" cellpadding="0" border="0">
  <tr><td align="left"><b><vkc:message key="vkc.favorites.nodocfavorites"/></b></td></tr>
</table>
</logic:empty>
</html:form>
</body>
</html:html>