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

<%@ 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.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);
        }
    }
    
    function deleteSelectedCategoryFavorites(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:bold;"><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:normal;"><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="/showCategoryFavorites" method="post">
<bean:define id="form" name="showCategoryFavoritesForm" type="vkc.profile.form.ShowCategoryFavoritesForm"/>

<logic:notEmpty name="form" property="favoriteCats">
<table cellspacing="2" cellpadding="0" border="0">
  <logic:iterate id="ucf" name="form" property="favoriteCats" type="vkc.db.entities.VKCUserCatFavorite">
  <bean:define id="favCat" name="ucf" property="category" type="vkc.db.entities.VKCCategory"/>
  <tr>
    <bean:define id="folderImage" name="favCat" property="folderImage" type="java.lang.String"/>
    <td align="left"><html:multibox name="form" property="selectedIds" onfocus="this.blur();"><vkc:write name="favCat" property="categoryId"/></html:multibox></td>
    <td width="17" align="center"><vkc:img page='<%= "/templates/${template.name}/gfx/" + folderImage %>' border="0" alt=""/></td>
    <td width="100%" align="left"><vkc:link page="/showCategory.do" paramId="categoryId" paramName="favCat" paramProperty="categoryId">&nbsp;<vkc:write name="favCat" property="absPathDescrString"/></vkc:link></td>
  </tr>
  </logic:iterate>
</table>

<table width="100%" cellspacing="2" 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:deleteSelectedCategoryFavorites(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="favoriteCats">
<table width="100%" cellspacing="0" cellpadding="0" border="0">
  <tr><td align="left"><b><vkc:message key="vkc.favorites.nocatfavorites"/></b></td></tr>
</table>
</logic:empty>
</html:form>
</body>
</html:html>