<%@ page language="java" buffer="64kb" %>

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

<%@ page import="vkc.view.TabId" %>
<%@ page import="vkc.view.WebShare" %>

<vkc:checkLogin />

<vkc:init/>

<html:html locale="true">
<bean:define id="form" name="functionalViewForm" type="vkc.procoba.function.FunctionalViewForm" toScope="request"/>

<head>

    <meta http-equiv="Content-Type"        content="text/html; charset=iso-8859-1">
    <meta http-equiv="Content-Script-Type" content="text/javascript">
    <meta http-equiv="Content-Style-Type"  content="text/css">
    <meta http-equiv="cache"               content="no-cache">
    <meta http-equiv="cache-control"       content="no-cache">
    <meta http-equiv="pragma"              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 viewId = <%= vkc.view.PageId.FUNCTIONAL_VIEW.toString() %>;
    var selectedTabId = <vkc:write name="form" property="functionalViewId"/>;
    var selectedViewId = <%= vkc.view.PageId.FUNCTIONAL_VIEW.toString() %>;
    var currentCalendar = null;
	var markedDoc = 0;

	function unloadPage() {

    	if ( currentCalendar!=null ) {
      		hideCalendar();
    	}
    }

    function init() {
        var tabView = getTabView();
  		var systemviewtype = "procobaview";
  		
        if (tabView && tabView.systemviewtype == "procobaview" && tabView.selectedTabId == selectedTabId) {
            tabView.lastFunctionalId = '<vkc:write name="form" property="functionalViewId"/>';
            var tabViewForm = tabView.document.forms[0];
            tabViewForm.lastFunctionalId.value = tabView.lastFunctionalId;
        }

        if (tabView && tabView.systemviewtype == "procobaview" && tabView.selectedTabId != selectedTabId) {
            tabView.lastFunctionalId = '<vkc:write name="form" property="functionalViewId"/>';
            var tabViewForm = tabView.document.forms[0];
            tabViewForm.lastFunctionalId.value = tabView.lastFunctionalId;
            tabView.location.replace("<%=ctxPath%>/procobaTab.do?viewId=" + viewId 
            					   + "&selectedTabId=<vkc:write name="form" property="functionalViewId"/>&selectedViewId=" + selectedViewId
          						   + "&lastCategoryId=" + tabViewForm.lastCategoryId.value
          						   + "&lastFunctionalId=" + tabViewForm.lastFunctionalId.value
          						   + "&lastProjectId=" + tabViewForm.lastProjectId.value);
        }

        <logic:present name="<%=WebShare.INFO_KEY%>" scope="request">
            <bean:define id="msg" type="java.lang.String" name="<%=WebShare.INFO_KEY%>" scope="request"/>
            alert( '<vkc:message javascript="true" filter="false" key="<%=msg%>"/>' );
        </logic:present>

        <logic:present name="<%=org.apache.struts.Globals.MESSAGE_KEY%>">
        <html:messages id="message" property="info" message="true">
          alert( '<vkc:write name="message" javascript="true" filter="false"/>' );
        </html:messages>
        <% request.getSession().removeAttribute( org.apache.struts.Globals.MESSAGE_KEY ); %>
        </logic:present>

		<logic:present name="<%=WebShare.MESSAGE_KEY%>" scope="request">
          <bean:define id="message" type="java.lang.String" scope="request" name="<%=WebShare.MESSAGE_KEY%>"/>
          alert( '<vkc:write name="message" javascript="true" filter="false"/>' );
        </logic:present>

		setAnchor();
    }

    function setAnchor() {
        <logic:present parameter="anchor">
            <bean:parameter id="anchor2" name="anchor"/>
            this.location.hash = '<%=anchor2%>';
            Mark("#" + '<%=anchor2%>');
        </logic:present>
        
        <logic:notPresent parameter="anchor">
        var anchorValue = this.location.hash;  
        
        if (anchorValue != '') {
            Mark(anchorValue);
        }
        </logic:notPresent>
    }

    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 deleteDocument(id) {
        if ( !confirm('<vkc:message javascript="true" filter="false" key="vkc.string.confirm.delete.document"/>') ) {
            return;
        } else {
            var form = document.forms[ 0 ];
            form.selectedId.value = id;

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

            form.submit();
        }
    }

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

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

        form.submit();
    }

    function changeDocumentSortMode() {
        var form = document.forms[0];

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

        form.submit();
    }
    
    function confirmDeleteCategory() {
        return confirm('<vkc:message javascript="true" filter="false" key="vkc.string.confirm.delete.category"/>');
    }
	    
  	function Mark(id) {
		var c1 = null;
		var c2 = null;
		var c3 = null;

		if (markedDoc != 0) {
			if (markedDoc.substring(1,4) == "doc") {
				c1 = document.getElementById(markedDoc.substring(4));
				c2 = document.getElementById(markedDoc.substring(4) + "a");
				c3 = document.getElementById(markedDoc.substring(4) + "alt");

				if (c1) {
				    c1.className = "unselecteddocument";	
				}
				
				if (c2) {
				    c2.className = "unselecteddocumentheader";
				}
				
				if (c3) {
				    c3.className = "unselecteddocumentalternate";
				}
			}
			
			if (markedDoc.substring(1,4) == "tbp") {
				c1 = document.getElementById(markedDoc.substring(4));
				c2 = document.getElementById(markedDoc.substring(4) + "a");
				c3 = document.getElementById(markedDoc.substring(4) + "alt");

				if (c1) {
				    c1.className = "unselecteddocument";	
				}
				
				if (c2) {
				    c2.className = "unselecteddocumentheader";
				}
				
				if (c3) {
				    c3.className = "unselecteddocumentalternate";
				}
			}
		}
		
		if (id != "#top") {
			markedDoc = id;

			c1 = document.getElementById(markedDoc.substring(4));
			c2 = document.getElementById(markedDoc.substring(4) + "a");
			c3 = document.getElementById(markedDoc.substring(4) + "alt");

			if (c1) {
			    c1.className = "selecteddocument";	
			}
			
			if (c2) {
			    c2.className = "selecteddocumentheader";
			}
			
			if (c3) {
			    c3.className = "selecteddocumentalternate";
			}
		}
	}

    </script>    

</head>
  
<body topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" onload="init();" onUnload="unloadPage();">
<table width="100%" height="100%" cellspacing="0" cellpadding="0" border="0">
<html:form action="/functionalView" method="post">

  <html:hidden property="functionalViewId" />
  <html:hidden property="subfolderId" />
  <html:hidden property="selectedId" />
  <html:hidden property="categorySortMode" />
  <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:present name="<%=org.apache.struts.Globals.ERROR_KEY%>">
  <html:messages id="error" message="false">
  <tr><td nowrap="nowrap" colspan="1" align="left" valign="top"><span class="error"><b><vkc:write name="error"/></b></span></td></tr>
  </html:messages>
  <tr><td colspan="1"><vkc:img page="/templates/${template.name}/gfx/trans.gif" alt="" height="5" border="0"/></td></tr>
  </logic:present>

  <logic:notEmpty name="form" property="category">  

    <bean:define id="category" name="form" property="category" type="vkc.db.entities.VKCCategory"/>

    <tr>
      <td height="100%" valign="top">
        <table width="100%" height="100%" cellspacing="0" cellpadding="0" border="0">
          <tr>
            <td valign="top" width="100%" height="100%" class="projectView">
              <table width="100%" cellpadding="0" cellspacing="0" border="0">
                <tr>
                  <td width="100%" height="100%" valign="top" class="projectView">
                    <table width="100%" cellspacing="0" cellpadding="0" border="0">
                      <%-- Metainformationen etc. --%>
				      <tr>
				        <td nowrap="nowrap" valign="top" width="100%">  
				          <table width="100%">
				            <tr><td nowrap="nowrap"><b><vkc:message key="function.label.description" />:</b></td></tr>
				            <tr>
				              <td>
				              <font class="smallFont">
					          <logic:equal name="form" property="tinyMCECompatible" value="true">
					          <vkc:write name="category" property="description" displayAsHTML="true" renderNewLine="true"/>
					          </logic:equal>
					          <logic:equal name="form" property="tinyMCECompatible" value="false">
					          <vkc:write name="category" property="description" stripHTML="true" renderNewLine="true"/>
					          </logic:equal>
				              </font>
				              </td>
				            </tr>
				          </table>  
				        </td>                
				      </tr>
                      <tr><td valign="top" width="100%" background="<vkc:rewrite page='/templates/${template.name}/gfx/dotted-line-h.gif'/>"><vkc:img page="/templates/${template.name}/gfx/trans.gif" alt="" height="1"/></td></tr>
                      <tr>
                        <td valign="top" width="100%">
			              <jsp:include page="FunctionalViewFolderView.jsp" flush="true" />   
                        </td>
                      </tr>
			        </table>
			      </td>
			    </tr>
              </table>  
            </td>
		  </tr>
        </table>
      </td>
    </tr>    
  </logic:notEmpty>
</html:form>
</table>
</body>
</html:html>