>
<xbl:bindings xmlns:xbl="http://www.mozilla.org/xbl"
    xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
          type="text/javascript">
    <xbl:binding id="VirtualHtmlList">
        <xbl:content>
            <vbox flex="1">
                <!-- Iframe that contains the entry -->
                <iframe id="contentFrame" xbl:inherits="src" flex="1" class="iFrameVlist"/>
            </vbox>
            <vbox id="scrollBox" style="text-align:right;" collapsed="true">
                <scrollbar orient="vertical">
                    <scrollbarbutton id="scrollup" type="decrement" onmousedown="document.getBindingParent(this).scrollToTop()" onmouseup="document.getBindingParent(this).stopScroll()" onmouseout="document.getBindingParent(this).stopScroll()"/>
                </scrollbar>
                <hbox flex="1">
                    <slider id="foo-slider" maxpos="950" curpos="0" onmousedown="document.getBindingParent(this).g_TextThumb=true;document.getBindingParent(this).SetTooltipThumb()" onmouseup="document.getBindingParent(this).LoadFrameFromThumb();" increment="1" pageincrement="40" orient="vertical">
                        <thumb id="foo-thumb" flex="1"/>
                    </slider>
                </hbox>
                <scrollbar orient="vertical">
                    <scrollbarbutton id="scrolldown" type="increment" onmousedown="document.getBindingParent(this).scrollToBottom()" onmouseup="document.getBindingParent(this).stopScroll()" onmouseout="document.getBindingParent(this).stopScroll()"/>
                </scrollbar>
            </vbox>
        </xbl:content>
        <xbl:implementation>

            <xbl:field name="g_FloatingSelection">false</xbl:field>
            <xbl:field name="g_ScrollPad">40</xbl:field>
            <xbl:field name="g_ScrollStart">false</xbl:field>
            <xbl:field name="g_ScrollDirect">1</xbl:field>
            <xbl:field name="g_TextThumb">false</xbl:field>
            <xbl:field name="g_Loaded">true</xbl:field>
            <xbl:field name="g_DivTooltip">null</xbl:field>
            <xbl:field name="g_HtmlTooltip">1</xbl:field>

            <xbl:field name="g_ViewThumb">false</xbl:field>
            <xbl:field name="playSound">true</xbl:field>

            <xbl:field name="g_key_Top">38</xbl:field>
            <xbl:field name="g_key_Bottom">40</xbl:field>
            <xbl:field name="g_key_PageTop">34</xbl:field>
            <xbl:field name="g_key_PageBottom">33</xbl:field>

            <xbl:property name="contentWindow">
                <xbl:getter>
                    <![CDATA[
                        var browser = document.getAnonymousElementByAttribute(this, "id", "contentFrame");
                        return browser.contentWindow;
                    ]]>
                </xbl:getter>
            </xbl:property>
            <xbl:property name="contentDocument">
                <xbl:getter>
                    <![CDATA[
                        var browser = document.getAnonymousElementByAttribute(this, "id", "contentFrame");
                        return browser.contentDocument;
                    ]]>
                </xbl:getter>
            </xbl:property>

            <xbl:property name="currentPosition">
                <xbl:getter>
                <![CDATA[
                    return Number(this.getAttribute("currentPosition"));
                ]]>
                </xbl:getter>
                <xbl:setter>
                <![CDATA[
                    this.setAttribute("currentPosition",val);
                    var slider = document.getAnonymousElementByAttribute(this, "id", "foo-slider");
                    slider.setAttribute("curpos",val);
                    setTimeout("document.getElementById('"+this.id+"').LoadFrameFromThumb()",0);
                    return val;
                ]]>
                </xbl:setter>
            </xbl:property>
            <xbl:property name="maxElement">
                <xbl:getter>
                <![CDATA[
                    return Number(this.getAttribute("maxElement"));
                ]]>
                </xbl:getter>
                <xbl:setter>
                <![CDATA[
                    this.setAttribute("maxElement",val);
                    return val;
                ]]>
                </xbl:setter>
            </xbl:property>
            <xbl:property name="scrollAnchor"
                onget="return this.getAttribute('scrollAnchor');"
                onset="return this.setAttribute('scrollAnchor',val);"/>
            <xbl:property name="scrollId"
                onget="return this.getAttribute('scrollId');"
                onset="return this.setAttribute('scrollId',val);"/>
            <xbl:property name="xblChildClass"
                onget="return this.getAttribute('xblChildClass');"
                onset="return this.setAttribute('xblChildClass',val);"/>
            <xbl:property name="myFuncGetContent"
                onget="return this.getAttribute('myFuncGetContent');"
                onset="return this.setAttribute('myFuncGetContent',val);"/>
            <xbl:property name="HtmlStringTooltip"
                onget="return this.getAttribute('HtmlStringTooltip');"
                onset="return this.setAttribute('HtmlStringTooltip',val);"/>

            <xbl:property name="myFuncGetTooltipContent"
                onget="return this.getAttribute('myFuncGetTooltipContent');"
                onset="return this.setAttribute('myFuncGetTooltipContent',val);"/>
            <xbl:property name="selected"
                onget="return this.getAttribute('selected');" onset="return this.setAttribute('selected',val);"/>
            <xbl:property name="selectedTarget"
                onget="return this.getAttribute('selectedTarget');" onset="return this.setAttribute('selectedTarget',val);"/>

            <xbl:method name="LoadDico">
                <xbl:parameter name="pbIsFromThumb"/>
                <xbl:body>
                    <![CDATA[
                        try
                        {
                            var b_ScrollToBottom = false;
                            if (!pbIsFromThumb)
                                this.g_Loaded=false;
                            var firstEntries = 0;
                            this.g_DivTooltip = null;
                            if (pbIsFromThumb)
                                firstEntries = document.getAnonymousElementByAttribute(this, "id", "foo-slider").getAttribute("curpos");

                            var oIframe = document.getAnonymousElementByAttribute(this, "id", "contentFrame");
                            oIframe.contentWindow.windowparent = window;
                            var winFrame = oIframe.contentWindow;
                            var oBody = oIframe.contentDocument.getElementsByTagName("body")[0];
                            while (oBody.firstChild)
                                oBody.removeChild(oBody.firstChild);
                            
                            var i, domXml;
                            for( i = firstEntries;  i <= this.maxElement ; i++ )
                            {
                                domXml = eval(this.myFuncGetContent);
                                oBody.appendChild(domXml.firstChild);
                                if ( 0 < oBody.childNodes.length && Number(winFrame.innerHeight) * 2 < oBody.lastChild.offsetTop )
                                    break;
                            }
                            
                            if( pbIsFromThumb )
                            {
                                if (oBody.offsetHeight <winFrame.innerHeight)
                                {
                                    //Je rajoute des entrs avant celle seletionne
                                    var divToScrollId = oBody.firstChild.id;
                                    for( i = firstEntries - 1; 0 <= i; i-- )
                                    {
                                        domXml = eval(this.myFuncGetContent);
                                        oBody.insertBefore(domXml.firstChild,oBody.firstChild);
                                        if (winFrame.innerHeight * 2 < oBody.offsetHeight)
                                            break;
                                    }
                                    //winFrame.scrollTo(0,oIframe.contentDocument.getElementById(divToScrollId).offsetTop);
                                    b_ScrollToBottom = true;
                                }
                                else
                                    winFrame.scrollTo(0,0);
                            }
                            //J'affiche la scrollbar si le contenu du body est plus grand que la hauteur de l'iframe
                            this.DisplayScrollbar();
                            this.UpdateClass();
                            if (b_ScrollToBottom)
                                    winFrame.scrollTo(0,oIframe.contentDocument.getElementById(divToScrollId).offsetTop);
                            if (this.g_FloatingSelection && !this.scrollId && !this.scrollAnchor)
                                this.autoSelectContent();
                            if (this.scrollId)
                                this.scrollToId();

                            if (this.scrollAnchor)
                                this.scrollToAnchor();
                        } catch (err) {
                            //alert("ERROR Method LoadDico "+firstEntries+":\n" + err);
                        }
                    ]]>
                </xbl:body>
            </xbl:method>
            <xbl:method name="DisplayScrollbar">
                <xbl:body>
                    <![CDATA[
                         try
                        {
                            var oIframe = document.getAnonymousElementByAttribute(this, "id", "contentFrame");
                            var oBody = oIframe.contentDocument.getElementsByTagName("body")[0];
                            var winFrame = oIframe.contentWindow;
                            var bElement = (this.maxElement-1 <= oBody.childNodes.length)
                            var bSize = ((oBody.parentNode.offsetHeight <= winFrame.innerHeight))
                            var checkScrollBar = ((bSize && bElement))
                            if (checkScrollBar)
                                document.getAnonymousElementByAttribute(this, "id", "scrollBox").collapsed = true;
                            else
                            {
                                document.getAnonymousElementByAttribute(this, "id", "scrollBox").collapsed = (this.getAttribute("collapScroll")=="true");
                                var slider = document.getAnonymousElementByAttribute(this, "id", "foo-slider");
                                slider.setAttribute("maxpos",Number(this.maxElement));
                            }
                        } catch (err) {
                            //alert("ERROR Method DisplayScrollbar :\n" + err);
                        }
                    ]]>
                </xbl:body>
            </xbl:method>
            <xbl:method name="UpdateClass">
                <xbl:body>
                    <![CDATA[
                        try
                        {
                            var oIframe = document.getAnonymousElementByAttribute(this, "id", "contentFrame");
                            var oBody = oIframe.contentWindow.document.getElementsByTagName("body")[0];
                            if (this.xblChildClass)
                            {
                                var i;
                                if(!this.g_ViewThumb)
                                {
                                    for( i = 0; i < oBody.childNodes.length; i++ )
                                    {
                                        if(oBody.childNodes[i].className.indexOf(this.xblChildClass)==-1)
                                        {
                                            oBody.childNodes[i].className = oBody.childNodes[i].className + " " + this.xblChildClass;
                                        }
                                        if (this.hasAttribute("debug"))
                                            alert(oBody.childNodes.length);
                                    }
                                }
                                else
                                {
                                    var aTd = oBody.getElementsByTagName("td");
                                    for (i=0 ; i<aTd.length; i++)
                                    {
                                        if(aTd[i].className && aTd[i].className.indexOf(this.xblChildClass)==-1)
                                            aTd[i].className = aTd[i].className + " " + this.xblChildClass;
                                    }
                                }
                            }
                        } catch (err) {
                        }
                    ]]>
                </xbl:body>
            </xbl:method>
            <xbl:method name="LoadFrameFromThumb">
                <xbl:body>
                    <![CDATA[
                         try
                        {
                            this.g_TextThumb=false;
                            this.LoadDico(true);
                        } catch (err) {
                            //alert("ERROR Method LoadFrameFromThumb :\n" + err);
                        }
                    ]]>
                </xbl:body>
            </xbl:method>
            <xbl:method name="ClearList">
                <xbl:body>
                    <![CDATA[
                        try
                        {
                            var oIframe = document.getAnonymousElementByAttribute(this, "id", "contentFrame");
                            oIframe.contentWindow.windowparent = window;
                            var winFrame = oIframe.contentWindow;
                            var oBody = oIframe.contentDocument.getElementsByTagName("body")[0];
                            while (oBody.firstChild)
                                oBody.removeChild(oBody.firstChild);
                            document.getAnonymousElementByAttribute(this, "id", "scrollBox").collapsed = true;
                            document.getAnonymousElementByAttribute(this, "id", "foo-slider").setAttribute("curpos",0);
                            winFrame.scrollTo(0,0);
                        } catch (err) {
                            //alert("ERROR Method ClearList :\n" + err);
                        }
                    ]]>
                </xbl:body>
            </xbl:method>
            <xbl:method name="SetTooltipThumb">
                <xbl:body>
                    <![CDATA[
                        try
                        {
                            if (!this.g_TextThumb || !this.myFuncGetTooltipContent)
                            {
                                this.g_TextThumb=false;
                                return;
                            }
                            var myWin = window ;
                            if(myWin.opener)
                              myWin = myWin.opener;
                            var oIframe = document.getAnonymousElementByAttribute(this, "id", "contentFrame");
                            var oSrollTop = document.getAnonymousElementByAttribute(this, "id", "scrollup");
                            var oSlider = document.getAnonymousElementByAttribute(this, "id", "foo-slider");
                            var oThumb = document.getAnonymousElementByAttribute(this, "id", "foo-thumb");
                            var oWindow = oIframe.contentWindow;
                            if (!this.g_DivTooltip)
                            {
                                var oDoc = oIframe.contentDocument;
                                var oBody = oDoc.getElementsByTagName("body")[0];
                                var oDiv =  myWin.goDomParser.parseFromString(this.HtmlStringTooltip,"text/xml");
                                this.g_DivTooltip = oBody.appendChild(oDiv.firstChild);
                            }
                            var iPositionY = Number(oIframe.contentWindow.scrollY) + (Number(oThumb.boxObject.y) - Number(oSrollTop.boxObject.y));
                            this.g_DivTooltip.style.top = iPositionY + "px;"
                            this.g_DivTooltip.style.right = "0px;"
                            var iIndex = oSlider.getAttribute("curpos");

                            var oDivWithContent =this.g_DivTooltip.firstChild
                            oDivWithContent.className = 'divTooltip';

                            var toolTipContent = eval( this.myFuncGetTooltipContent );

                            if( 1 < oDivWithContent.childNodes.length )
                            {
                                while(oDivWithContent.firstChild)
                                    oDivWithContent.removeChild(oDivWithContent.firstChild);
                                if( toolTipContent )
                                    this.g_DivTooltip.firstChild.appendChild( document.createTextNode( toolTipContent ) );
                            }
                            else if( toolTipContent )
                                oDivWithContent.firstChild.data = toolTipContent;

                            setTimeout("document.getElementById('"+this.id+"').SetTooltipThumb()", 35);
                        } catch (err) {
                            //alert("ERROR Method SetTooltipThumb:\n" + err);
                        }
                    ]]>
                </xbl:body>
            </xbl:method>
            <xbl:method name="getFirstVisbleDivIndex">
                <xbl:body>
                    <![CDATA[
                        try
                        {
                            var oIframe = document.getAnonymousElementByAttribute(this, "id", "contentFrame");
                            var winFrame = oIframe.contentWindow;
                            var oBody = oIframe.contentDocument.getElementsByTagName("body")[0];
                            if( !oBody.childNodes.length )
                                return null;
                            var visibDiv = oBody.firstChild;
                            while( visibDiv.offsetTop < winFrame.scrollY )
                            {
                                if (visibDiv.nodeType==1 && (!visibDiv.nextSibling || winFrame.scrollY + oIframe.innerHeight < visibDiv.nextSibling.offsetTop))
                                {
                                    if (!visibDiv.id)
                                    {
                                        visibDiv = visibDiv.nextSibling;
                                        continue;
                                    }
                                    break;
                                }
                                visibDiv = visibDiv.nextSibling;
                            }

                            if('getAttribute' in visibDiv)
                                return visibDiv.id.replace(/doc([0-9]+)/,"$1");

                            return visibDiv.nextSibling.id.replace(/doc([0-9]+)/,"$1");
                        } catch (err) {
                            //alert("ERROR Method getFirstVisbleDivIndex:\n" + visibDiv + err);
                        }
                        return null;
                    ]]>
                </xbl:body>
            </xbl:method>
            <xbl:method name="getLastVisbleDivIndex">
                <xbl:body>
                    <![CDATA[
                        try
                        {
                            var oIframe = document.getAnonymousElementByAttribute(this, "id", "contentFrame");
                            var winFrame = oIframe.contentWindow;
                            var oBody = oIframe.contentDocument.getElementsByTagName("body")[0];
                            if( !oBody.childNodes.length )
                                return null;
                            var visibDiv = oBody.firstChild;
                            while( visibDiv.offsetTop < (winFrame.scrollY + winFrame.innerHeight) )
                            {
                                if (visibDiv.nodeType==1 && ((visibDiv.offsetTop  + visibDiv.offsetHeight) > (winFrame.scrollY + winFrame.innerHeight)))
                                {
                                    if (!visibDiv.id)
                                    {
                                        visibDiv = visibDiv.nextSibling;
                                        continue;
                                    }
                                    if (visibDiv.previousSibling)
                                        visibDiv = visibDiv.previousSibling;
                                    break;
                                }
                                if(!visibDiv.nextSibling)
                                    break;
                                visibDiv = visibDiv.nextSibling;
                            }

                            if('getAttribute' in visibDiv)
                                return visibDiv.id.replace(/doc([0-9]+)/,"$1");

                            return visibDiv.previousSibling.id.replace(/doc([0-9]+)/,"$1");
                        } catch (err) {
                            //alert("ERROR Method getLastVisbleDivIndex:\n" + visibDiv + err);
                        }
                        return null;
                    ]]>
                </xbl:body>
            </xbl:method>
            <xbl:method name="scrollToBottom">
                <xbl:body>
                    <![CDATA[
                        try
                        {
                            if(document.getAnonymousElementByAttribute(this, "id", "scrollBox").collapsed)
                                return;
                            var slider = document.getAnonymousElementByAttribute(this, "id", "foo-slider");
                            if (slider.getAttribute("curpos") >= this.maxElement)
                            {
                                slider.setAttribute("curpos",this.maxElement);
                                return;
                            }
                            this.g_ScrollStart = true;
                            this.g_ScrollDirect = 1;
                            setTimeout("document.getElementById('"+this.id+"').autoScroll()", 1);
                        } catch (err) {
                            //alert("ERROR Method scrollToBottom :\n" + err);
                        }
                    ]]>
                </xbl:body>
            </xbl:method>
            <xbl:method name="scrollToTop">
                <xbl:body>
                    <![CDATA[
                        try
                        {
                            if(document.getAnonymousElementByAttribute(this, "id", "scrollBox").collapsed)
                                return;
                            this.g_ScrollStart = true;
                            this.g_ScrollDirect = -1;
                            setTimeout("document.getElementById('"+this.id+"').autoScroll()", 1);
                        } catch (err) {
                            //alert("ERROR Method scrollToTop :\n" + err);
                        }
                    ]]>
                </xbl:body>
            </xbl:method>
            <xbl:method name="autoScroll">
                <xbl:parameter name="piForceDirect"/>
                <xbl:body>
                    <![CDATA[
                        try
                        {
                            if (this.g_DivTooltip)
                            {
                                this.g_DivTooltip.parentNode.removeChild(this.g_DivTooltip);
                                this.g_DivTooltip = null;
                            }
                            if (!this.g_ScrollStart && !piForceDirect)
                                return;
                            var oIframe = document.getAnonymousElementByAttribute(this, "id", "contentFrame");
                            var winFrame = oIframe.contentWindow;
                            var oBody = oIframe.contentDocument.getElementsByTagName("body")[0];
                            this.firstIndex = this.getFirstVisbleDivIndex();
                            this.lastIndex = this.getLastVisbleDivIndex();
                            var oLastDiv = oIframe.contentDocument.getElementById("doc" + this.lastIndex);
                            var oFirstDiv = oIframe.contentDocument.getElementById("doc" + this.firstIndex);
                            if (!piForceDirect)
                            {
                                winFrame.scrollTo(0,winFrame.scrollY + (this.g_ScrollDirect * this.g_ScrollPad));
                                if (oBody.offsetHeight <= winFrame.scrollY + winFrame.innerHeight && (this.maxElement==this.getLastVisbleDivIndex()))
                                {
                                    document.getAnonymousElementByAttribute(this, "id", "foo-slider").setAttribute("curpos",this.maxElement);
                                    return;
                                }
                                else
                                {
                                    if (document.getAnonymousElementByAttribute(this, "id", "foo-slider").getAttribute("curpos") == this.maxElement)
                                            document.getAnonymousElementByAttribute(this, "id", "foo-slider").setAttribute("curpos",this.maxElement -1);
                                }
                            }
                            else
                            {
                                winFrame.scrollTo(0,winFrame.scrollY + (1));
                                winFrame.scrollTo(0,winFrame.scrollY + (-1));
                            }
                            // on arrive presque dans le bas, il faut rajouter un sdocument
                            var domXml, i, num;
                            if ((piForceDirect == 1 || this.g_ScrollDirect == 1) && oBody.offsetHeight - winFrame.scrollY - winFrame.innerHeight < winFrame.innerHeight)
                            {
                                var LastDiv = oBody.lastChild;
                                var lastId = LastDiv.getAttribute("id");

                                num = Number(lastId.replace(/doc([0-9]+)/,"$1"));
                                if (num + 1 <= this.maxElement)
                                {
                                    for( i= num + 1;  i < this.maxElement+1; i++)
                                    {
                                        domXml = eval(this.myFuncGetContent);
                                        var oNode = oBody.appendChild(domXml.firstChild);
                                        var iTop = oNode.offsetTop;
                                        var iTop2 =LastDiv.offsetTop;
                                        var iHeight = Number(winFrame.innerHeight);
                                        if ( iHeight < iTop - iTop2)
                                            break;
                                    }
                                }
                            }
                            //On arrive presque en haut, il faut rajouter un document
                            if ((piForceDirect == -1 || this.g_ScrollDirect == -1) && winFrame.scrollY < winFrame.innerHeight)
                            {
                                var FirstDiv = oBody.firstChild;
                                var firstId = FirstDiv.id;
                                num = Number( firstId.replace(/doc([0-9]+)/,"$1") );
                                var firstHeight =0;
                                if ( 0 <= (num -1) )
                                {
                                    for( i = num - 1;  0<= i ; i-- )
                                    {
                                        domXml = eval(this.myFuncGetContent);
                                        oBody.insertBefore(domXml.firstChild,oBody.firstChild);
                                        myFirstDiv = oBody.childNodes[0];
                                        mySeconDiv = oBody.childNodes[1];
                                        firstHeight += Number(mySeconDiv.offsetTop) - Number(myFirstDiv.offsetTop);
                                        if (Number(winFrame.innerHeight < oFirstDiv.offsetTop ))
                                            break;
                                    }
                                    if (!piForceDirect)
                                        winFrame.scrollTo(0,winFrame.scrollY + firstHeight - this.g_ScrollPad);
                                }
                            }
                            this.UpdateClass();
                            if (this.g_FloatingSelection)
                                this.autoSelectContent();
                            //Positionner le Thumb
                            this.firstIndex = this.getFirstVisbleDivIndex();
                            document.getAnonymousElementByAttribute(this, "id", "foo-slider").setAttribute("curpos",this.firstIndex);
                            setTimeout("document.getElementById('"+this.id+"').autoScroll()", 50);
                        } catch (err) {
                            //alert("ERROR Method autoScroll :\n" + err);
                        }
                    ]]>
                </xbl:body>
            </xbl:method>
            <xbl:method name="stopScroll">
                <xbl:body>
                    <![CDATA[
                        try
                        {
                            this.g_ScrollStart = false;
                        } catch (err) {
                            //alert("ERROR Method stopScroll :\n" + err);
                        }
                    ]]>
                </xbl:body>
            </xbl:method>
            <xbl:method name="printContent">
                <xbl:body>
                    <![CDATA[
                        try {
                            var oIframe = document.getAnonymousElementByAttribute(this, "id", "contentFrame");
                            skPrint(oIframe.contentWindow, gxiSkPrintManager.kPrefsSettings);
                        } catch (err) {
                            //alert("ERROR Method printSelectedDocument :\n" + err)
                        }
                    ]]>
                </xbl:body>
            </xbl:method>
            <xbl:method name="printSelectedDocument">
                <xbl:parameter name="poWindow"/>
                <xbl:body>
                    <![CDATA[
                        try {
                            if (!poWindow)
                                poWindow = window;
                            var oIframe = document.getAnonymousElementByAttribute(this, "id", "contentFrame");
                            if (this.selectedTarget || this.selected || this.getAttribute("selectable") == "false")
                                poWindow.skPrint(oIframe.contentWindow, poWindow.gxiSkPrintManager.kPrefsSettings);
                        } catch (err) {
                            //alert("ERROR Method printSelectedDocument :\n" + err)
                        }
                    ]]>
                </xbl:body>
            </xbl:method>
            <xbl:method name="copySelectedDocument">
                <xbl:parameter name="poWindow"/>
                <xbl:body>
                    <![CDATA[
                        try {
                            if (!poWindow)
                                poWindow = window;
                            var oIframe = document.getAnonymousElementByAttribute(this, "id", "contentFrame");
                            var oDocument = oIframe.contentDocument;
                            var oWindow = oIframe.contentWindow;
                            var oSelection, oCloneRange;
                            if (poWindow.gxiSkSelection.GetUnicode(oWindow)) {
                                //Copy the selected text
                                oSelection = oWindow.getSelection();
                                oCloneRange = oSelection.getRangeAt(oSelection.rangeCount-1).cloneRange();
                                var oDiv = oDocument.createElement("div");
                                //var oText = oDocument.createTextNode(oCloneRange.toString());
                                var oContent = oCloneRange.cloneContents();
                                oDiv.appendChild(oContent);
                                poWindow.copyNode(oWindow, oDiv, false);
                            } else {
                                //Copy the selected entry
                                //Hack: Prevent the copy when the selected entry has been removed from the virtual list
                                if (oDocument.getElementById(this.selected)) {
                                    var oDocRange = oDocument.createRange();
                                    oSelection = oWindow.getSelection();
                                    oDocRange.selectNodeContents(oDocument.getElementById(this.selected));
                                    oSelection.addRange(oDocRange);
                                    oCloneRange = oSelection.getRangeAt(oSelection.rangeCount-1).cloneRange();
                                    var oDomDocumentFragment = oCloneRange.cloneContents();
                                    oSelection.removeAllRanges();
                                    poWindow.copyNode(oWindow, oDomDocumentFragment.ownerDocument.getElementById(this.selected), true);
                                }
                            }
                            //Give the focus to the window to set the selection active
                            oWindow.focus();
                        } catch(err) {
                            //alert("Error Method copySelectedDocument " + err);
                        }
                    ]]>
                </xbl:body>
            </xbl:method>
            <xbl:method name="copyContent">
                <xbl:body>
                    <![CDATA[
                        try {
                            var oIframe = document.getAnonymousElementByAttribute(this, "id", "contentFrame");
                            var oDocument = oIframe.contentDocument;
                            var oWindow = oIframe.contentWindow;
                            var oDocRange = oDocument.createRange();
                            var oSelection = oWindow.getSelection();
                            var oBody = oDocument.getElementsByTagName("body")[0];
                            oWindow.windowparent.copyNode(oWindow, oBody, false);
                        } catch(err) {
                            //alert("Error Method copyContent " + err);
                        }
                    ]]>
                </xbl:body>
            </xbl:method>
            <xbl:method name="scrollToId">
                <xbl:body>
                    <![CDATA[
                        try
                        {
                            var oIframe = document.getAnonymousElementByAttribute(this, "id", "contentFrame");
                            var oDocument = oIframe.contentDocument;
                            var oBody = oDocument.getElementsByTagName("body")[0];
                            var oDiv;
                            if(this.selected)
                                oDiv = oDocument.getElementById(this.selected);
                            else
                                oDiv = oDocument.getElementsByTagName("div")[0];
                            if (!oDiv)
                                return;
                            var walker = oDocument.createTreeWalker(oDiv, Components.interfaces.nsIDOMNodeFilter.SHOW_ELEMENT,null,true);
                            var result = null;
                            if(walker)
                            {
                                walker.showAnonymousContent = true;
                                walker.showSubDocuments = true;
                                while (true)
                                {
                                    if ('getAttribute' in walker.currentNode && walker.currentNode.getAttribute('url') == this.scrollId)
                                    {
                                    result = walker.currentNode;
                                    walker.nextNode();
                                    break;
                                    }
                                    curN = walker.currentNode;
                                    nextN = walker.nextNode();
                                    if (curN== nextN || !nextN)
                                        break;
                                }
                            }
                            this.scrollId = null;
                            if (!result)
                                return;
                            if(result.nodeName == "p:Head" && result.parentNode.nodeName == "p:Entry")
                                return;
                            var span = document.createElement("a");
                            span.style.display="inline";
                            span.appendChild(document.createTextNode("    "));
                            span = result.parentNode.insertBefore(span,result);
                            oIframe.contentWindow.scrollTo(0,span.boxObject.y);
                            span.parentNode.removeChild(span);
                        } catch (err) {
                            //alert("ERROR Method scrollToId :\n" + err);
                        }
                    ]]>
                </xbl:body>
            </xbl:method>
            <xbl:method name="scrollToAnchor">
                <xbl:body>
                    <![CDATA[
                        try
                        {
                            var oIframe = document.getAnonymousElementByAttribute(this, "id", "contentFrame");
                            var oDocument = oIframe.contentDocument;
                            sLocation = this.getAttribute("src") + this.scrollAnchor;
                            oDocument.location.href = sLocation;
                            this.scrollAnchor = null;
                        } catch (err) {
                            //alert("ERROR Method scrollToAnchor :\n" + err);
                        }
                    ]]>
                </xbl:body>
            </xbl:method>
            <xbl:method name="GetIframe">
                <xbl:body>
                    <![CDATA[
                         try {
                            return document.getAnonymousElementByAttribute(this, "id", "contentFrame");
                        } catch (err) {
                            //alert("ERROR Method GetIframe :\n" + err);
                        }
                        return null;
                    ]]>
                </xbl:body>
            </xbl:method>
            <xbl:method name="CheckResize">
                <xbl:body>
                    <![CDATA[
                         try {
                            var oIframe = document.getAnonymousElementByAttribute(this, "id", "contentFrame");
                            var oDocument = oIframe.contentDocument;
                            var oBody = oDocument.getElementsByTagName("body")[0];
                            if (!oBody.childNodes.length)
                                return;
                            if (!oBody.getElementsByTagName("div").length)
                                return;
                            this.autoScroll(1);
                            setTimeout("document.getElementById('"+this.id+"').DisplayScrollbar()", 300);
                        } catch (err) {
                        }
                    ]]>
                </xbl:body>
            </xbl:method>
            <xbl:method name="autoSelectContent">
                <xbl:body>
                    <![CDATA[
                         try {
                            var oIframe = this.GetIframe();
                            var oWinIframe = oIframe.contentWindow;
                            var scrollY = oWinIframe.scrollY;
                            var iFrameHeight = oWinIframe.innerHeight;
                            var iMaxPos = scrollY + iFrameHeight;
                            var oElement = oIframe.contentDocument.getElementById(this.selected);

                            this.firstIndex = this.getFirstVisbleDivIndex();
                            this.lastIndex = this.getLastVisbleDivIndex();
                            if (!oElement)
                            {
                                oElement = oIframe.contentDocument.getElementById("doc"+this.getFirstVisbleDivIndex());
                                oElement.select();
                                return;
                            }
                            if (oElement)
                            {
                              var currentIndex = this.selected.replace("doc","");
                              var bIsBelowTop = (currentIndex >= this.firstIndex);
                              var bIsAboveBottom = (currentIndex <= this.lastIndex);
                              if ( bIsBelowTop && bIsAboveBottom)
                                  return;
                            }

                            if (!bIsBelowTop)
                            {
                              var nextId = "doc"+this.firstIndex;
                              var nextElement = oIframe.contentDocument.getElementById(nextId);
                              if(!nextElement)
                                return;
                              if ((nextElement.offsetTop - 50)> scrollY)
                              {
                                nextId = "doc"+Number(this.firstIndex-1)
                                nextElement = oIframe.contentDocument.getElementById(nextId);
                              }
                              if(nextId != this.selected)
                                nextElement.select();
                            }

                            if (!bIsAboveBottom)
                            {
                              var prevId = "doc"+this.lastIndex;
                              var prevElement = oIframe.contentDocument.getElementById( prevId );
                              if(!prevElement)
                                return;
                              if ((prevElement.offsetTop + prevElement.offsetHeight + 50)< iMaxPos)
                              {
                                prevId = "doc"+Number(Number(this.lastIndex)+1);
                                prevElement = oIframe.contentDocument.getElementById(prevId);
                              }
                              if(prevId != this.selected)
                                prevElement.select();
                              //prevElement.select();
                            }
                        } catch (err) {
                            //alert("autoSelectContent erreur :\n"+err);
                        }
                    ]]>
                </xbl:body>
            </xbl:method>
            <xbl:method name="pageDownOrUP">
                <xbl:parameter name="piDirection"/>
                <xbl:body>
                    <![CDATA[
                        try {
                            this.autoScroll(piDirection);
                            this.stopScroll();
                        } catch (err) {
                            //alert("autoSelectContent erreur :\n"+err);
                        }
                    ]]>
                </xbl:body>
            </xbl:method>

        </xbl:implementation>
        <xbl:handlers>
            <xbl:handler event="focus" action="this.focused = true;"/>
            <xbl:handler event="blur" action="this.focused = false;"/>
            <xbl:handler event="keyup" keycode="vk_up" action="this.stopScroll();"/>
            <xbl:handler event="keydown" keycode="vk_up" action="this.scrollToTop();"/>
            <xbl:handler event="keyup" keycode="vk_down" action="this.stopScroll();"/>
            <xbl:handler event="keydown" keycode="vk_down" action="this.scrollToBottom();"/>
            <xbl:handler event="keyup" keycode="vk_page_up" action="this.pageDownOrUP(-1);"/>
            <xbl:handler event="keyup" keycode="vk_page_down" action="this.pageDownOrUP(1);"/>
        </xbl:handlers>
    </xbl:binding>
</xbl:bindings>
