<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="bean" uri="http://struts.apache.org/tags-bean" %>
<c:set var="codeEcran" scope="request"><bean:message key="search.codeEcran"/></c:set>
<c:set var="titreEcran" scope="request"><bean:message key="search.titreEcran" arg0="${documentTitle}"/></c:set>
<%@ include file="/WEB-INF/jsp/include/entete.jsp" %>
  <!--[if IE 6]>
  <link rel="stylesheet" href="${pageContext.request.contextPath}/css/ie6.css" type="text/css"/>
  <![endif]-->
  <!--[if IE 5]>
  <link rel="stylesheet" href="${pageContext.request.contextPath}/css/ie6.css" type="text/css"/>
  <link rel="stylesheet" href="${pageContext.request.contextPath}/css/ie5.5.css" type="text/css"/>
  <![endif]-->

<script type="text/javascript" src="${pageContext.request.contextPath}/js/sarissa/sarissa-compressed.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/overlib.js"><!-- overLIB (c) Erik Bosrup --></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/getHttpObject.js"></script>
<script>
    var xsl = Sarissa.getDomDocument();
    xsl.async = false;
    xsl.load(contextPath+"/js/search/searchArray.xsl");
        var xsltProcessor = new XSLTProcessor();
        xsltProcessor.importStylesheet(xsl);
        var xml = null;
        
        function sort(sortIndex, sortOrder) {
            document.getElementById("resultTableContainer").innerHTML = "<center><img src=\"" + contextPath + "/img/searching.gif\"/></center>";
            xsltProcessor.clearParameters();
            xsltProcessor.setParameter(null, "sortIndex", sortIndex);
            xsltProcessor.setParameter(null, "sortOrder", sortOrder);
            document.getElementById("resultTableContainer").innerHTML = new XMLSerializer().serializeToString(xsltProcessor.transformToDocument(xml));
        }
        
        function transformXml(xmlToTransform) {
            xml = new DOMParser().parseFromString(xmlToTransform, "text/xml");
            return new XMLSerializer().serializeToString(xsltProcessor.transformToDocument(xml));
        }
        function setPointer(theRow, thePointerColor) {
            if (thePointerColor == '' || typeof(theRow.style) == 'undefined') {
                return false;
            }
            if (typeof(document.getElementsByTagName) != 'undefined') {
                var theCells = theRow.getElementsByTagName('td');
            }
            else if (typeof(theRow.cells) != 'undefined') {
                var theCells = theRow.cells;
            }
            else {
                return false;
            }
            
            var rowCellsCnt  = theCells.length;
            for (var c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = thePointerColor;
            }
            
            return true;
        } // end of the 'setPointer()' function
        function doClickOnRow(row,documentId,etatId,elementId,collCode,collLib,budgCode,budgLib) {
            try {
                bFound=false;
                cells = row.getElementsByTagName("td");
                var s="";
                var docId="";
                var additionalParams = "";
                for(i=0;i<cells.length;i++) {
                    var cellName=cells[i].attributes["name"].value;
                    if(cellName=="docId") {
                        //alert("click: "+cells[i].innerHTML);
                        docId = cells[i].innerHTML;
                        bFound=true;
                    } else if(cellName.substr(0,10)=="xsl-param:") {
                        additionalParams += "&"+cellName+"="+cells[i].innerHTML;
                    }
                }
                s="docId="+docId+
                    "\r\ndocumentId="+documentId+
                    "\r\netatId="+etatId+
                    "\r\nelementId="+elementId+
                    "\r\ncollCode="+collCode+
                    "\r\ncollLib="+collLib+
                    "\r\nbudgCode="+budgCode+
                    "\r\nbudgLib="+budgLib;
                var url = contextPath+"/displayDocument.do?coll-code="+collCode+
                    "&coll-lib="+collLib+
                    "&budg-code="+budgCode+
                    "&budg-lib="+budgLib+
                    "&documentId="+documentId+
                    "&etatId="+etatId+
                    "&elementId="+elementId+
                    "&docId="+docId+
                    additionalParams;
                encodedUrl = encodeUrl(url);
                window.open(encodedUrl);
            } catch(e) {
                alert(e.description);
        }
    }
    function displayMenu(id,datatype,searchSessionId) {
        <% java.util.Hashtable<String,fr.gouv.finances.dgfip.utils.Pair[]> operators = (java.util.Hashtable<String,fr.gouv.finances.dgfip.utils.Pair[]>)request.getAttribute("operators");%>
        var operators = new Array;
        <% for(String dt:operators.keySet()) {
            fr.gouv.finances.dgfip.utils.Pair[] pairs = operators.get(dt);
            %>
                    var data = new Array; <%
            for(int i=0;i<pairs.length;i++) {
                fr.gouv.finances.dgfip.utils.Pair p = pairs[i]; %>
                var o = new Object;
                o.key="<%=p.key%>";
                o.libelle="<%=p.libelle%>";
                data[<%=i%>]=o;
           <% } %>
             operators["<%=dt%>"]=data;
        <% } %>
        var HTML = "<ul style=\"list-style-type:none;list-style-position:outside;background-color:#f6f7ee; margin:0 0 0 0; border: #c4c4be solid 1px;\">";
        data = operators[datatype];
        for(i=0;i<data.length;i++) {
            HTML = HTML+"<li onclick=\"aggregate('"+searchSessionId+"','"+id+"','"+data[i].key+"');\" style=\"cursor:pointer;white-space:nowrap;\" onmouseover=\"javascript:this.style.backgroundColor='#d4e1ec';\" onmouseout=\"this.style.backgroundColor='#f6f7ee';\">"+data[i].libelle+"</li>";
        }
        HTML = HTML+"<li style=\"cursor:pointer;white-space:nowrap;\">&nbsp;</li>";
        HTML = HTML+"<li style=\"cursor:pointer;white-space:nowrap;\" onmouseover=\"javascript:this.style.backgroundColor='#d4e1ec';\" onmouseout=\"this.style.backgroundColor='#f6f7ee';\" onclick=\"return nd();\"/>Fermer</li>";
        HTML = HTML+"</ul>";
        return overlib(HTML,FULLHTML,STICKY);
    }
    function aggregate(searchSessionId,idCol,operator) {
        var ret = nd();
        var httpObject;
        /*@cc_on
          @if(@_jscript_version >= 5)
          try {
                httpObject = new ActiveXObject("Msxml2.XMLHTTP");
          } catch(e) {
                try {
                    httpObject = new ActiveXObject("Microsoft.XMLHTTP");
                } catch(e) {
                    httpObject = false;
                }
          }
          @else
                xmlhttp=false;
        @end @*/
        if(!httpObject && typeof XMLHttpRequest != 'undefined') {
            try {
                httpObject = new XMLHttpRequest();
            } catch(e) {
                httpObject = false;
            }
        }
        if(httpObject) {
            httpObject.onreadystatechange=function() {
                var text="";
                if(httpObject.readyState==4) {
                    if(httpObject.status==200) {
                        response = httpObject.responseXML;
                        text = response.getElementsByTagName("resultat").item(0).textContent;
                    }
                }
                if(text.length>0) alert(text);
            }
            httpObject.open("POST","${pageContext.request.contextPath}/aggregate.do");
            httpObject.setRequestHeader('Content-type','application/x-www-form-urlencoded');
            httpObject.send("searchSessionId="+escape(searchSessionId)+"&idCol="+escape(idCol)+"&operator="+escape(operator));
        } else {
            alert("httpObject no initialized!");
        }
        return ret;
    }
    function hideMenu(id) {
        document.getElementById("menu-"+id).style.display='none';
    }

    function encodeUrl(url) {
        if (url.indexOf("?")>0) {
            encodedParams = "?";
            parts = url.split("?");
            params = parts[1].split("&");
            for(i = 0; i < params.length; i++) {
                if (i > 0) {
                    encodedParams += "&";
                }
                if (params[i].indexOf("=")>0) {
                    //Avoid null values
                    p = params[i].split("=");
                    encodedParams += (p[0] + "=" + escape(encodeURI(p[1])));
                } else {
                    encodedParams += params[i];
                }
            }
            url = parts[0] + encodedParams;
        }
        return url;
    }

    function showPj(collectivite,pjName) {
        var url = "<%=request.getContextPath()%>/attachment.do?collectivite="+collectivite+"&pjId="+pjName;
        window.open(url);
    }
    function downloadUrl(url) {
        window.location.href=url;
    }
//    function simpleExport() {
//        searchSessionId = "1";
//        document.location = "<%=request.getContextPath()%>/simpleExport.do?searchSessionId="+searchSessionId;
//    }
</script>
<style>
    body { overflow: hidden }
    
    .imageButton a:hover {
        border: 1px outset #000000;
    }
    
    .imageButton a {
        border: 1px outset;
    }
    
    .imageButton a img {
        margin: 0px;
        border: 0px;
    }
    .lighRow {
        background-color: #DDDDEE;
    }
    .darkRow {
        background-color: #EEEEFF;
    }
    </style>
    <div di="overDiv" style="position:absolute; visibility:hidden; z-index:1000; background-color:#6666FF; border: #000033 solid 1px;"></div>
<table left="0" border="0" width="100%" height="100%" style="margin:0; padding:0; border-spacing:0;">
    <tr>
        <td devInfo="Widget GWT pour la recherche" valign="top" width="100%" id="criteriaContainer" documentId="${documentId}" etatId="${etatId}" elementId="${elementId}"></td>
    </tr>
</table>
<script language="javascript" src="${pageContext.request.contextPath}/fr.gouv.finances.dgfip.xemelios.web.gwt.Main/fr.gouv.finances.dgfip.xemelios.web.gwt.Main.nocache.js"></script>
<iframe src="javascript:''" id="__gwt_historyFrame" style="width:0;height:0;border:0"></iframe>
<%@ include file="/WEB-INF/jsp/include/pied.jsp" %>