<%@ taglib prefix="bean" uri="http://struts.apache.org/tags-bean" %>
<%@ taglib prefix="logic" uri="http://struts.apache.org/tags-logic" %>
<%@ page language="java" pageEncoding="ISO-8859-15" contentType="text/html; charset=ISO-8859-15" import="fr.gouv.finances.dgfip.xemelios.services.Menu" %>
<html>
    <head>
        <link rel="icon" type="image/png" href="${pageContext.request.contextPath}/img/favicon.png"/>
   <!--[if IE 6]>
    <link rel="stylesheet" href="css/ie6.css" type="text/css"/>
   <![endif]-->
   <!--[if IE 5]>
    <link rel="stylesheet" href="css/ie6.css" type="text/css"/>
    <link rel="stylesheet" href="css/ie5.5.css" type="text/css"/>
   <![endif]-->
        <link rel="stylesheet" href="${pageContext.request.contextPath}/css/standard.css" type="text/css"/>
        <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/yui-2/reset-fonts-grids/reset-fonts-grids.css"/>
        <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/yui-2/menu/assets/skins/sam/menu.css"/>
		<script type="text/javascript" src="${pageContext.request.contextPath}/yui-2/yahoo-dom-event/yahoo-dom-event.js"></script>
        <script type="text/javascript" src="${pageContext.request.contextPath}/yui-2/container/container_core.js"></script>
        <script type="text/javascript" src="${pageContext.request.contextPath}/yui-2/menu/menu.js"></script>
        <script>
            YAHOO.util.Event.onContentReady("menubar", function () {
                var oMenuBar = new YAHOO.widget.MenuBar("menubar", { autosubmenudisplay: true, hidedelay: 500, lazyload: true });
                oMenuBar.render();
            });

            function trim(text) {
                return text.replace(/^\s+/, "").replace(/\s+$/, "");
            }

            function createComplexElement(complexElement) {
                var fake = document.createElement("div");
                fake.innerHTML = trim(complexElement);
                var toReturn = fake.childNodes[0];
                return toReturn;
            }

            function replaceAll(strToTreat, strToReplace, strReplacement){
                var aRemplacer = eval("/\\" + strToReplace + "/g");
                return strToTreat.replace(aRemplacer, strReplacement)
            }

            Tab = function(id, label, src) {
                this.id_ = id;
                this.domItem_ = null;
                this.iframe_ = null;
                this.div_ = null;
                this.isSelected_ = false;
                this.frameContainer_ = null;

                this.getId = function getId() {
                    return this.id_;
                }

                this.getDomItem = function getDomItem() {
                    return this.domItem_;
                }

                this.isSelected = function isSelected() {
                    return this.isSelected_;
                }

                this.setSelected = function setSelected(value) {
                    if (value == true && this.isSelected_ == false) {
                        this.domItem_.className = "rTabActive";
                        this.div_.style.display = "block";
                        this.isSelected_ = true;
                    } else if (value == false && this.isSelected_ == true) {
                        this.domItem_.className = "rTab";
                        this.div_.style.display = "none";
                        this.isSelected_ = false;
                    }
                }

                this.destroy = function destroy() {
                    this.getFrameContainer_().removeChild(this.div_);
                }

                this.getFrameContainer_ = function getFrameContainer_() {
                    if (this.frameContainer_ == null)
                        this.frameContainer_ = document.getElementById("frameContainer");
                    return this.frameContainer_;
                }

                this.getFrameName = function getFrameName() {
                    return "content_" + this.getId();
                }

                this.setLabel = function setLabel(label) {
                    var labelContainer = document.getElementById("tabItemLabel_" + this.getId());
                    labelContainer.innerHTML = label;
                    // FireFox trick ro resize the tab :
                    var tabItemTable = document.getElementById("tabItemTable_" + this.getId());
                    tabItemTable.parentNode.style.width = "1px";
                    setTimeout("document.getElementById('tabItemTable_" + this.getId() + "').parentNode.style.width = '0px'", 0);
                    // End of trick
                }

                this.domItem_ = createComplexElement(replaceAll(replaceAll(document.getElementById("tabItemModel").innerHTML, "@@id@@", id), "@@label@@", label));
                this.div_ = createComplexElement("<div style=\"height: 100%; display: none\"></div>");
                if (src) {
                    this.iframe_ = createComplexElement("<iframe src=\"" + src + "\" width=\"100%\" height=\"100%\" marginHeight=\"0\" marginWidth=\"0\" frameBorder=\"0\" name=\"" + this.getFrameName() + "\" id=\"" + this.getFrameName() + "\"/>");
                } else {
                    this.iframe_ = createComplexElement("<iframe width=\"100%\" height=\"100%\" marginHeight=\"0\" marginWidth=\"0\" frameBorder=\"0\" name=\"" + this.getFrameName() + "\" id=\"" + this.getFrameName() + "\"/>");
                }
                this.iframe_ = this.div_.appendChild(this.iframe_);
                this.getFrameContainer_().appendChild(this.div_);
            };

          TabManager = function() {

            this.tabItemContainer_ = null;

            this.idGenerator_ = 1;
            this.tabs_ = new Array();

            this.getTabItemContainer_ = function getTabItemContainer_() {
              if (this.tabItemContainer_ == null) this.tabItemContainer_ = document.getElementById("tabItemContainer");
              return this.tabItemContainer_;
            };

            this.createTab = function createTab(src) {
                var sequenceValue = this.idGenerator_++;
                var tabId = "tab_" + sequenceValue;
                var tabLabel = "Sans&nbsp;titre";
                var tab = new Tab(tabId, tabLabel, src ? src : "${pageContext.request.contextPath}/accueil.do?dispatchMethod=showAccueilContent");
                this.tabs_[this.tabs_.length] = tab;
                var firstRow = null;
                if (this.getTabItemContainer_().rows.length <= 0) {
                    firstRow = this.getTabItemContainer_().insertRow(-1);
                } else {
                    firstRow = this.getTabItemContainer_().rows[0];
                }
                var newCell = firstRow.insertCell(-1);
                //var newCell = firstRow.insertCell(firstRow.cells.length - 1);
                newCell.appendChild(tab.getDomItem());
                this.select_(tab);
            };

            this.getTabIndexById_ = function getTabIndexById_(tabId) {
              for (var i=0; i<this.tabs_.length; i++) {
                if (this.tabs_[i].getId() == tabId) return i;
              }
            };

            this.getTabById_ = function getTabById_(tabId) {
              var tabIndex = this.getTabIndexById_(tabId);
              if (tabIndex >=0) return this.tabs_[tabIndex];
              return null;
            };

            this.onTabLabelClick = function onTabLabelClick(tabId) {
              this.select_(this.getTabById_(tabId));
			  // Fix pour fireFox permettant de stoper l'icone de chargement :
			  var tempIframe = createComplexElement("<iframe style=\"display: none\"/>");
			  document.getElementById("frameContainer").appendChild(tempIframe);
			  document.getElementById("frameContainer").removeChild(tempIframe);
			  // Fin fix
            };

            this.select_ = function select_(tab) {
                for (var i=0; i<this.tabs_.length; i++) {
                    if (this.tabs_[i].getId() == tab.getId()) {
                        this.tabs_[i].setSelected(true);
                    } else {
                        this.tabs_[i].setSelected(false);
                    }
                }
            }

            this.onTabCloseClick = function onTabCloseClick(tabId) {
                if (this.tabs_.length > 1) {
                    var tabIndex = this.getTabIndexById_(tabId);
                    var tab = this.tabs_[tabIndex];
                    if (tab.isSelected()) {
                        this.select_(this.tabs_[tabIndex > 0 ? tabIndex - 1 : 1]);
                    }
                    this.getTabItemContainer_().childNodes[0].childNodes[0].deleteCell(tabIndex);
                    tab.destroy();
                    this.tabs_.splice(tabIndex, 1);
                }
            }

            this.getSelectedTab = function getSelectedTab() {
              for (var i=0; i<this.tabs_.length; i++) {
                if (this.tabs_[i].isSelected()) {
                  return this.tabs_[i];
                }
              }
            }

          };

          var tabManager = new TabManager();

            function simpleExport() {
                if (parent.frames[tabManager.getSelectedTab().getFrameName()].isExportPossible
                    && parent.frames[tabManager.getSelectedTab().getFrameName()].isExportPossible()) {
                        var searchSessionId = parent.frames[tabManager.getSelectedTab().getFrameName()].getSearchSessionId();
                        document.getElementById(tabManager.getSelectedTab().getFrameName()).src = "<%=request.getContextPath()%>/simpleExport.do?searchSessionId=" + searchSessionId;
                }
            }

            function configExport() {
                parent.frames[tabManager.getSelectedTab().getFrameName()]._configExport();
            }

            function complexExport() {
                if (parent.frames[tabManager.getSelectedTab().getFrameName()].isExportPossible
                    && parent.frames[tabManager.getSelectedTab().getFrameName()].isExportPossible()) {
                        var searchSessionId = parent.frames[tabManager.getSelectedTab().getFrameName()].getSearchSessionId();
                        parent.frames[tabManager.getSelectedTab().getFrameName()]._complexExport(searchSessionId);
                }
            }
            function openNavigation(documentId) {
                parent.frames[tabManager.getSelectedTab().getFrameName()]._openNavigation(documentId);
            }

            function menuClick(url, caption, updateMenuCaption) {
              if (updateMenuCaption) {
                  tabManager.getSelectedTab().setLabel(replaceAll(caption, " ", "&nbsp;"));
              }
              if (url.indexOf("javascript:") == 0) {
                  document.location = url;
              } else {
                document.getElementById(tabManager.getSelectedTab().getFrameName()).src = url;
              }
            }
            var BrowserDetect = {
                init: function () {
                    this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
                    this.version = this.searchVersion(navigator.userAgent)
                        || this.searchVersion(navigator.appVersion)
                        || "an unknown version";
                    this.OS = this.searchString(this.dataOS) || "an unknown OS";
                },
                searchString: function (data) {
                    for (var i=0;i<data.length;i++)	{
                        var dataString = data[i].string;
                        var dataProp = data[i].prop;
                        this.versionSearchString = data[i].versionSearch || data[i].identity;
                        if (dataString) {
                            if (dataString.indexOf(data[i].subString) != -1)
                                return data[i].identity;
                        }
                        else if (dataProp)
                            return data[i].identity;
                    }
                },
                searchVersion: function (dataString) {
                    var index = dataString.indexOf(this.versionSearchString);
                    if (index == -1) return;
                    return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
                },
                dataBrowser: [
                    {
                        string: navigator.userAgent,
                        subString: "Chrome",
                        identity: "Chrome"
                    },
                    { 	string: navigator.userAgent,
                        subString: "OmniWeb",
                        versionSearch: "OmniWeb/",
                        identity: "OmniWeb"
                    },
                    {
                        string: navigator.vendor,
                        subString: "Apple",
                        identity: "Safari",
                        versionSearch: "Version"
                    },
                    {
                        prop: window.opera,
                        identity: "Opera"
                    },
                    {
                        string: navigator.vendor,
                        subString: "iCab",
                        identity: "iCab"
                    },
                    {
                        string: navigator.vendor,
                        subString: "KDE",
                        identity: "Konqueror"
                    },
                    {
                        string: navigator.userAgent,
                        subString: "Firefox",
                        identity: "Firefox"
                    },
                    {
                        string: navigator.vendor,
                        subString: "Camino",
                        identity: "Camino"
                    },
                    {		// for newer Netscapes (6+)
                        string: navigator.userAgent,
                        subString: "Netscape",
                        identity: "Netscape"
                    },
                    {
                        string: navigator.userAgent,
                        subString: "MSIE",
                        identity: "Explorer",
                        versionSearch: "MSIE"
                    },
                    {
                        string: navigator.userAgent,
                        subString: "Gecko",
                        identity: "Mozilla",
                        versionSearch: "rv"
                    },
                    { 		// for older Netscapes (4-)
                        string: navigator.userAgent,
                        subString: "Mozilla",
                        identity: "Netscape",
                        versionSearch: "Mozilla"
                    }
                ],
                dataOS : [
                    {
                        string: navigator.platform,
                        subString: "Win",
                        identity: "Windows"
                    },
                    {
                        string: navigator.platform,
                        subString: "Mac",
                        identity: "Mac"
                    },
                    {
                           string: navigator.userAgent,
                           subString: "iPhone",
                           identity: "iPhone/iPod"
                    },
                    {
                        string: navigator.platform,
                        subString: "Linux",
                        identity: "Linux"
                    }
                ]

            };
            BrowserDetect.init();
        </script>

    </head>
    <body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" class="yui-skin-sam" scroll="no" onload="tabManager.createTab('${pageContext.request.contextPath}/accueil.do?dispatchMethod=showAccueilContent');">
        <div id="tabItemModel" style="display: none">
            <table border="0" class="rTabActive" cellpadding="0" cellspacing="0" id="tabItemTable_@@id@@">
                <tr>
                    <td nowrap class="rTabCell1"><img style="width: 5px; height: 20px" src="${pageContext.request.contextPath}/img/tabs/dot.gif"/></td>
                    <td nowrap class="rTabCell2"><a id="tabItemLabel_@@id@@" href="javascript:tabManager.onTabLabelClick('@@id@@')">@@label@@</a>&nbsp;<a style="text-decoration: none;" href="javascript:tabManager.onTabCloseClick('@@id@@')"><img border="0" src="${pageContext.request.contextPath}/img/tabs/close.gif"/>&nbsp;</a></td>
                </tr>
            </table>
        </div>
        <table border="0" height="100%" width="100%">
            <tr>
                <td height="0">
                    <div id="bd">
                    <div id="yui-main">
                    <div class="yui-b">
                    <div id="menubar" class="yuimenubar yuimenubarnav">
                        <div class="bd">
                            <ul class="first-of-type">
                                <%Menu rootMenu = (Menu)session.getAttribute("menu");
                                  if(rootMenu!=null) {
                                    for(int menuCount=0;menuCount<rootMenu.getChilds().size();menuCount++) {
                                        Menu menu = rootMenu.getChilds().get(menuCount);
                                %>
                                        <li class="yuimenubaritem<%=(menuCount==0?" first-of-type":"")%>"><a class="yuimenubaritemlabel" href="<%= menu.getHref() != null ? "javascript:menuClick('" + menu.getHref() + "', '" + menu.getCaption() + "', " + menu.isPage() + ")" : "#" %>"><%=menu.getCaption()%></a>
                                        <% if(menu.getChilds().size() > 0) { %>
                                            <div id="<%=menu.getId()%>" class="yuimenu">
                                                <div class="bd">
                                                    <ul>
                                                        <% for(Menu subMenu:menu.getChilds()) { %>
                                                        <li class="yuimenuitem"><a class="yuimenuitemlabel" href="<%= (subMenu.getHref() != null ? "javascript:menuClick('" + subMenu.getHref() + "', '" + subMenu.getCaption() + "', " + subMenu.isPage() + ")" : "#") %>"><%= subMenu.getCaption() %></a>
                                                            <% if(subMenu.getChilds().size()>0) { %>
                                                                <div id="<%=subMenu.getId()%>" class="yuimenu">
                                                                    <div class="bd">
                                                                        <ul class="first-of-type">
                                                                        <% for(Menu subsubMenu:subMenu.getChilds()) { %>
                                                                            <li class="yuimenuitem"><a class="yuimenuitemlabel" href="<%= (subsubMenu.getHref() != null ? "javascript:menuClick('" + subsubMenu.getHref() + "', '" + subsubMenu.getCaption() + "', " + subsubMenu.isPage() + ")" : "#") %>"><%= subsubMenu.getCaption() %></a>
                                                                            <% if(subsubMenu.getChilds().size()>0) { %>
                                                                                <div id="<%=subsubMenu.getId()%>" class="yuimenu">
                                                                                    <div class="bd">
                                                                                        <ul>
                                                                                            <% for(Menu lastMenu:subsubMenu.getChilds()) { %>
                                                                                                <li class="yuimenuitem"><a class="yuimenuitemlabel" href="<%= (lastMenu.getHref() != null ? "javascript:menuClick('" + lastMenu.getHref() + "', '" + lastMenu.getCaption() + "', " + lastMenu.isPage() + ")" : "#") %>"><%= lastMenu.getCaption() %></a></li>
                                                                                            <% } %>
                                                                                        </ul>
                                                                                    </div>
                                                                                </div>
                                                                            <% } %>
                                                                            </li>
                                                                        <% } %>
                                                                        </ul>
                                                                    </div>
                                                                </div>
                                                            <% } %>
                                                            </li>
                                                        <% } %>
                                                    </ul>
                                                </div>
                                            </div>
                                        <% }  %>
                                        </li>
                                    <% }
                                   } %>
                            </ul>
                        </div>
                    </div>
                    </div>
                    </div>
                    </div>
                </td>
            </tr>
            <tr>
                <td id="frameContainer" height="100%"></td>
            </tr>
            <tr>
                <td width="100%" class="tabContainer">
                    <table cellpadding="0" cellspacing="0" width="0px">
                        <tr>
                            <td nowrap width="0px">
                                <table border="0" id="tabItemContainer" cellspacing="0" cellpadding="0" width="0px"><tr></tr></table>
                            </td>
                            <td nowrap width="0px">
                                <a style="font-family: Verdana,Helvetica,sans-serif; font-weight: bold; font-size: 12px; text-decoration: none; color: #626667;" href="javascript:tabManager.createTab();">Nouvel onglet</a>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
    </body>
</html>