/*
        paginate table object v1.6 by frequency-decoder.com

        Released under a creative commons Attribution-ShareAlike 2.5 license (http://creativecommons.org/licenses/by-sa/2.5/)

        Please credit frequency decoder in any derivative work - thanks

        You are free:

        * to copy, distribute, display, and perform the work
        * to make derivative works
        * to make commercial use of the work

        Under the following conditions:

                by Attribution.
                --------------
                You must attribute the work in the manner specified by the author or licensor.

                sa
                --
                Share Alike. If you alter, transform, or build upon this work, you may distribute the resulting work only under a license identical to this one.

        * For any reuse or distribution, you must make clear to others the license terms of this work.
        * Any of these conditions can be waived if you get permission from the copyright holder.
*/
var imgsrcprevious ="/Style Library/ADV/img/spacer.gif";// "/Style Library/ADV/img/tra/setaBgVerdeLt.gif";
var imgsrcnext = "/Style Library/ADV/img/spacer.gif";//"/Style Library/ADV/img/tra/setaBgVerdeGt.gif";
var LabelNumtext = "Num. de linhas: ";
var globalTableId;
tablePaginater = {
		
        tableInfo: {},
        uniqueID:0,
        /*

        Localise the button titles here...

        %p is replaced with the appropriate page number
        %t is replaced with the total number of pages
        
        */
		
        text: ["First Page","Previous Page (Page %p)","Next Page (Page %p)","Last Page (Page %t)","Page %p of %t"],

        addEvent: function(obj, type, fn, tmp) {
                tmp || (tmp = true);
                if( obj.attachEvent ) {
                        obj["e"+type+fn] = fn;
                        obj[type+fn] = function(){obj["e"+type+fn]( window.event );};
                        obj.attachEvent( "on"+type, obj[type+fn] );
                } else {
                        obj.addEventListener( type, fn, true );
                };
        },

        addClass: function(e,c) {
                if(new RegExp("(^|\\s)" + c + "(\\s|$)").test(e.className)) return;
                e.className += ( e.className ? " " : "" ) + c;
        },

        /*@cc_on
        /*@if (@_win32)
        removeClass: function(e,c) {
                e.className = !c ? "" : e.className.replace(new RegExp("(^|\\s)" + c + "(\\s|$)"), " ").replace(/^\s*((?:[\S\s]*\S)?)\s*$/, '$1');
        },
        @else @*/
        removeClass: function(e,c) {
                e.className = !c ? "" : e.className.replace(new RegExp("(^|\\s)" + c + "(\\s|$)"), " ").replace(/^\s\s*/, '').replace(/\s\s*$/, '');
        },
        /*@end
        @*/
        
        init: function(tableId) {
			//alert('1');
			

                globalTableId = tableId;
                var tables = tableId && typeof(tableId) == "string" ? [document.getElementById(tableId)] : document.getElementsByTagName('table');
                var hook, maxPages, visibleRows, numPages, cp, cb, rowList, elemPage;
                
                for(var t = 0, tbl; tbl = tables[t]; t++) {
                        if(tbl.className.search(/paginate-([0-9]+)/) == -1) { continue; };

                        if(!tbl.id) { tbl.id = "fdUniqueTableId_" + tablePaginater.uniqueID++; };

                        maxPages = tbl.className.search(/max-pages-([0-9]+)/) == -1 ? null : Number(tbl.className.match(/max-pages-([0-9]+)/)[1]);
                        if(maxPages % 2 == 0 && maxPages > 1) { maxPages--; };
                        
                        hook = tbl.getElementsByTagName('tbody');
                        hook = (hook.length) ? hook[0] : tbl;

                        visibleRows = tablePaginater.calculateVisibleRows(hook);
                        
                        if(maxPages > (visibleRows / Number(tbl.className.match(/paginate-([0-9]+)/)[1]))) {
                                maxPages = null;
                        };
                        
                        elemPage = Number(tbl.className.match(/paginate-([0-9]+)/)[1]);
                        numPages = Math.ceil(visibleRows / Number(tbl.className.match(/paginate-([0-9]+)/)[1]));

/*                        
                        if(numPages < 2 && !(tbl.id in tablePaginater.tableInfo)) {
                                continue;
                        };
*/                        
                        cp = (tbl.id in tablePaginater.tableInfo) ? Math.min(tablePaginater.tableInfo[tbl.id].currentPage, numPages) : 1;

                        cb = tbl.className.search(/paginationcallback-([\S-]+)/) == -1 ? "" : tbl.className.match(/paginationcallback-([\S]+)/)[1];

                        // Replace "-" with "." to enable Object.method callbacks
                        cb = cb.replace("-", ".");


						/* joão carvalho */
						/* razão: totais para colunas numéricas */
						var colTotals;
//debugger;
						colTotals = document.getElementsBySelector("table[id='" + tbl.id + "'] tfoot tr td[class='ColTotal']");
						//colTotals = tbl.getElementsBySelector("tfoot tr td[class='ColTotal']");
						//fim

                        tablePaginater.tableInfo[tbl.id] = {
                                rowsPerPage:Number(tbl.className.match(/paginate-([0-9]+)/)[1]),
                                selectedViewNum:0,
                                currentPage:cp,
                                totalRows:hook.getElementsByTagName('tr').length,
                                hook:hook,
                                maxPages:maxPages,
                                numPages:numPages,
                                elementsPage:elemPage,
                                rowStyle:tbl.className.search(/rowstyle-([\S]+)/) != -1 ? tbl.className.match(/rowstyle-([\S]+)/)[1] : false,
                                callback:cb || "paginationCallback",
								colsToShowTotals: colTotals /* joão carvalho razão: totais para colunas numéricas */

                        };
                        
                        tablePaginater.showPage(tbl.id);
                        hook = null;

                };
              
           	

        },
        reinit: function(rows4view,tableId) {
        	//alert('2');
        	
               
                var tables = tableId && typeof(tableId) == "string" ? [document.getElementById(tableId)] : document.getElementsByTagName('table');
                var hook, maxPages, visibleRows, numPages, cp, cb, rowList, elemPage;
                
                for(var t = 0, tbl; tbl = tables[t]; t++) {
                
                        if(tbl.className.search(/paginate-([0-9]+)/) == -1 || rows4view==-1) { continue; };

                        if(!tbl.id) { tbl.id = "fdUniqueTableId_" + tablePaginater.uniqueID++; };

                        maxPages = tbl.className.search(/max-pages-([0-9]+)/) == -1 ? null : Number(tbl.className.match(/max-pages-([0-9]+)/)[1]);
                        if(maxPages % 2 == 0 && maxPages > 1) { maxPages--; };
                        
                        hook = tbl.getElementsByTagName('tbody');
                        hook = (hook.length) ? hook[0] : tbl;

                        visibleRows = tablePaginater.calculateVisibleRows(hook);
                        
                        if(maxPages > (visibleRows / Number(rows4view))) {
                                maxPages = null;
                        };
                        
                        elemPage = Number(tbl.className.match(/paginate-([0-9]+)/)[1]);
                        numPages = Math.ceil(visibleRows / Number(rows4view));
                        
                        if(numPages < 2 && !(tbl.id in tablePaginater.tableInfo)) {
                                continue;
                        };
                        
                        cp = (tbl.id in tablePaginater.tableInfo) ? Math.min(tablePaginater.tableInfo[tbl.id].currentPage, numPages) : 1;

                        cb = tbl.className.search(/paginationcallback-([\S-]+)/) == -1 ? "" : tbl.className.match(/paginationcallback-([\S]+)/)[1];

                        // Replace "-" with "." to enable Object.method callbacks
                        cb = cb.replace("-", ".");

						//totals 
						var colTotals;
						colTotals = document.getElementsBySelector("table[id='" + tbl.id + "'] tfoot tr td[class='ColTotal']");

                        tablePaginater.tableInfo[tbl.id] = {
                                rowsPerPage:Number(rows4view),
                                selectedViewNum:Number(rows4view)/Number(elemPage)-1,
                                currentPage:cp,
                                totalRows:hook.getElementsByTagName('tr').length,
                                hook:hook,
                                maxPages:maxPages,
                                numPages:numPages,
                                elementsPage:elemPage,
                                rowStyle:tbl.className.search(/rowstyle-([\S]+)/) != -1 ? tbl.className.match(/rowstyle-([\S]+)/)[1] : false,
                                callback:cb || "paginationCallback",
								colsToShowTotals: colTotals

                        };
                        
                        tablePaginater.showPage(tbl.id);
                        hook = null;
                };
        },
        calculateVisibleRows: function(hook) {
                var trs = hook.rows;
                var cnt = 0;
                var reg = /(^|\s)invisibleRow(\s|$)/;
                
                for(var i = 0, tr; tr = trs[i]; i++) {
                        if(tr.parentNode != hook || tr.getElementsByTagName("th").length || (tr.parentNode && tr.parentNode.tagName.toLowerCase().search(/thead|tfoot/) != -1)) continue;

                        if(tr.className.search(reg) == -1) {
                                cnt++;
                        };
                };
                return cnt;
        },
        currentPage: function(details,ul){
            var curr = document.createElement("strong");
            curr.appendChild(document.createTextNode(details.text));
            ul.appendChild(curr);    
        },
        createButton: function(details, ul, pseudo) {
                //alert('3');
                if(details.id == "theTable-currentPage" || details.id == "theTable-currentPageC"){
                    tablePaginater.currentPage(details,ul);
                    return;
                }
              
                //var li   = document.createElement("li");
                //var but  = document.createElement(pseudo ? "div" : "a");
                 var but  = document.createElement("a");
                //var span = document.createElement("span");

                if(!pseudo) { but.href = "#"; };
                if(!pseudo) { but.title = details.title; };
                
                but.className = details.className;
/*
                ul.appendChild(li);
                li.appendChild(but);
                */
                ul.appendChild(but);              
                
                //but.appendChild(span);
                //span.appendChild(document.createTextNode(details.text));
                if(details.className != "previous-page" && details.className != "next-page"){
                    but.appendChild(document.createTextNode(details.text));
                }
               // if(!pseudo) { li.onclick = but.onclick = tablePaginater.buttonClick; };
                
                if(details.className == "previous-page"){
/*
                    var imgprv = document.createElement("img");
                    imgprv.alt = "<";
                    imgprv.src = imgsrcprevious;

                    but.appendChild(imgprv);*/
					but.appendChild(document.createTextNode("<"));
                }
                if(details.className == "next-page"){

/*
                    var imgnext = document.createElement("img");
                    imgnext.alt = ">";
                    imgnext.src = imgsrcnext;

                    but.appendChild(imgnext);*/
					but.appendChild(document.createTextNode(">"));
                }
                
                if(!pseudo) { but.onclick = tablePaginater.buttonClick; };
                if(!pseudo && details.id) { but.id = details.id; };
                
                //li = but = span = null;
                li = but = null;
        },
        removePagination: function(tableId) {
            var wrapT = document.getElementById(tableId + "-tablePaginatermain" );
            var wrapB = document.getElementById(tableId + "-tablePaginaterClonemain");
            if(wrapT) { wrapT.parentNode.removeChild(wrapT); };
            if(wrapB) { wrapB.parentNode.removeChild(wrapB); };

        },
        ChangeNumView:function(val){
             tablePaginater.reinit(val,null);
           
        },
        ChangeNumTopView: function(){
            var ddlistT = document.getElementById("ddT");
            tablePaginater.ChangeNumView(ddlistT.options[ddlistT.selectedIndex].text);
			var ddlistB = document.getElementById("ddB");
			ddlistB.selectedIndex= ddlistT.selectedIndex;
        },
        ChangeNumBottomView:function(){
            var ddlistB = document.getElementById("ddB");
            tablePaginater.ChangeNumView(ddlistB.options[ddlistB.selectedIndex].text);
			var ddlistT = document.getElementById("ddT");
			ddlistT.selectedIndex= ddlistB.selectedIndex;
        },
        buildDropDown:function(labelInfo,details,ddname){

			//alert('4');
			var ddRegs = document.createElement("select");
			ddRegs.id = ddname;
			ddRegs.setAttribute('runat','server');
			
			var option1 = document.createElement("option");
			option1.appendChild(document.createTextNode(details.elementsPage));
			ddRegs.appendChild(option1);
			var option2 = document.createElement("option");
			option2.appendChild(document.createTextNode(Number(details.elementsPage)*2))
			ddRegs.appendChild(option2);
			var option3 = document.createElement("option");
			option3.appendChild(document.createTextNode(Number(details.elementsPage)*3))
			ddRegs.appendChild(option3);
			labelInfo.appendChild(ddRegs);
			
			ddRegs.selectedIndex = details.selectedViewNum;
			if(ddname == "ddT"){
			ddRegs.onchange = tablePaginater.ChangeNumTopView;
			}
			if(ddname == "ddB"){
			ddRegs.onchange = tablePaginater.ChangeNumBottomView;
			}
              
        },
        buildPagination: function(tblId) {
        
             	//alert('5');
                if(!(tblId in tablePaginater.tableInfo)) { return; };

                tablePaginater.removePagination(tblId);

                var details = tablePaginater.tableInfo[tblId];
                
                if(details.numPages < 2) return;
                
                function resolveText(txt, curr) {
                        curr = curr || details.currentPage;
                        return txt.replace("%p", curr).replace("%t", details.numPages);
                };

                if(details.maxPages) {
                        findex = Math.max(0, Math.floor(Number(details.currentPage - 1) - (Number(details.maxPages - 1) / 2)));
                        lindex = findex + Number(details.maxPages);
                        if(lindex > details.numPages) {
                                lindex = details.numPages;
                                findex = Math.max(0, details.numPages - Number(details.maxPages));
                        };
                } else {
                        findex = 0;
                        lindex = details.numPages; 
                };
                
                var mainDivT = document.createElement("div");
                mainDivT.className = "Paginacao";
                mainDivT.id = tblId + "-tablePaginatermain";
                
                var labelInfoT = document.createElement("label");
                labelInfoT.appendChild(document.createTextNode(LabelNumtext));
                tablePaginater.buildDropDown(labelInfoT,details,"ddT");

				/* jcarvalho */
				/* razao: mostrar sempre dropdown do nº de items por página */
                //mainDivT.appendChild(labelInfoT);

                var mainDivNLinhasTop = document.createElement("div");
				mainDivNLinhasTop.className = "Paginacao";
                mainDivNLinhasTop.id = tblId + "-tablePaginaterNLinhasTop";
				mainDivNLinhasTop.appendChild(labelInfoT);

				/* fim jcarvalho */

                
                var strongCountT = document.createElement("strong");

               /* var str = "Pag. " + details.currentPage + "/" + details.numPages; 
                strongCountT.appendChild(document.createTextNode(str));
                mainDivT.appendChild(strongCountT);
				*/
				
				var str = "Pag. " + details.currentPage + "/" + details.numPages; 
				mainDivT.appendChild(document.createTextNode("Pag. "));
                strongCountT.appendChild(document.createTextNode(details.currentPage));
                mainDivT.appendChild(strongCountT);
				mainDivT.appendChild(document.createTextNode("/" + details.numPages));
				
                var mainDivB = document.createElement("div");
                mainDivB.className = "Paginacao";
                mainDivB.id = tblId + "-tablePaginaterClonemain";
                
                
                var labelInfoB = document.createElement("label");
                labelInfoB.appendChild(document.createTextNode(LabelNumtext));
                tablePaginater.buildDropDown(labelInfoB,details,"ddB");
                
				/* jcarvalho */
				/* razao: mostrar sempre dropdown do nº de items por página */
				//mainDivB.appendChild(labelInfoB);
                
                var mainDivNLinhasBottom = document.createElement("div");
				mainDivNLinhasBottom.className = "Paginacao";
                mainDivNLinhasBottom.id = tblId + "-tablePaginaterNLinhasBottom";
				mainDivNLinhasBottom.appendChild(labelInfoB);

				/* fim jcarvalho */



                var strongCountB = document.createElement("strong");
                mainDivB.appendChild(document.createTextNode("Pag. "));
                strongCountB.appendChild(document.createTextNode(details.currentPage));
                mainDivB.appendChild(strongCountB);
                mainDivB.appendChild(document.createTextNode("/" + details.numPages));
                
                var wrapT = document.createElement("p");
                wrapT.className = "linksPaginas fdtablePaginaterWrap fdtablePaginater " + tblId + "-fdtablePaginaterWrapTop";
                wrapT.id = tblId + "-tablePaginater";
                mainDivT.appendChild(wrapT);
                
                var wrapB = document.createElement("p");
                wrapB.className = "linksPaginas  fdtablePaginaterWrap fdtablePaginater" + tblId + "-fdtablePaginaterWrapBottom";
                //wrapB.className = "fdtablePaginaterWrap";
                //wrapB.id = tblId + "-fdtablePaginaterWrapBottom";
                wrapB.id = tblId + "-tablePaginaterClone";
                mainDivB.appendChild(wrapB);
                
                // Create list scaffold
               /*
                var ulT = document.createElement("ul");
                ulT.id  = tblId + "-tablePaginater";
                */
                /*
                var ulB = document.createElement("ul");
                ulB.id  = tblId + "-tablePaginaterClone";
                */
                

                // Add to the wrapper DIVs
               /*
               wrapT.appendChild(ulT);
               wrapB.appendChild(ulB);
               */
               var ulT = wrapT;
               var ulB = wrapB;
               
                // FIRST (only created if maxPages set)
                if(details.maxPages) {
                        tablePaginater.createButton({title:tablePaginater.text[0], className:"first-page", text:"\u00ab"}, ulT, !findex);
                        tablePaginater.createButton({title:tablePaginater.text[0], className:"first-page", text:"\u00ab"}, ulB, !findex);
                };
                
                // PREVIOUS (only created if there are more than two pages)
                if(details.numPages > 2) {
                        tablePaginater.createButton({title:resolveText(tablePaginater.text[1], details.currentPage-1), className:"previous-page", text:"\u2039", id:tblId+"-previousPage"}, ulT, details.currentPage == 1);
                        tablePaginater.createButton({title:resolveText(tablePaginater.text[1], details.currentPage-1), className:"previous-page", text:"\u2039", id:tblId+"-previousPageC"}, ulB, details.currentPage == 1);
                };
                
                // NUMBERED
                for(var i = findex; i < lindex; i++) {
                        tablePaginater.createButton({title:resolveText(tablePaginater.text[4], i+1), className:i != (details.currentPage-1) ? "page-"+(i+1) : "currentPage page-"+(i+1), text:(i+1), id:i == (details.currentPage-1) ? tblId + "-currentPage" : ""}, ulT);
                        tablePaginater.createButton({title:resolveText(tablePaginater.text[4], i+1), className:i != (details.currentPage-1) ? "page-"+(i+1) : "currentPage page-"+(i+1), text:(i+1), id:i == (details.currentPage-1) ? tblId + "-currentPageC" : ""}, ulB);
                };

                // NEXT (only created if there are more than two pages)
                if(details.numPages > 2) {
                        tablePaginater.createButton({title:resolveText(tablePaginater.text[2], details.currentPage + 1), className:"next-page", text:"\u203a", id:tblId+"-nextPage"}, ulT, details.currentPage == details.numPages);
                        tablePaginater.createButton({title:resolveText(tablePaginater.text[2], details.currentPage + 1), className:"next-page", text:"\u203a", id:tblId+"-nextPageC"}, ulB, details.currentPage == details.numPages);
                };
                
                // LAST (only created if maxPages set)
                if(details.maxPages) {
                        tablePaginater.createButton({title:resolveText(tablePaginater.text[3], details.numPages), className:"last-page", text:"\u00bb"}, ulT, lindex == details.numPages);
                        tablePaginater.createButton({title:resolveText(tablePaginater.text[3], details.numPages), className:"last-page", text:"\u00bb"}, ulB, lindex == details.numPages);
                };
                
				/* jcarvalho */
				/* razao: mostrar sempre dropdown do nº de items por página */
				var nLinhasTop = document.getElementById(tblId+ "-tablePaginaterNLinhasTop");
				var nLinhasBottom = document.getElementById(tblId+ "-tablePaginaterNLinhasBottom");
				/* fim jcarvalho */


                // DOM inject wrapper DIVs (FireFox Bug: this has to be done here if you use display:table)
                if(document.getElementById(tblId+"-paginationListWrapTop")) {
						/* jcarvalho */
						/* razao: mostrar sempre dropdown do nº de items por página */
						if (!nLinhasTop) {
							document.getElementById(tblId+"-paginationListWrapTop").appendChild(mainDivNLinhasTop);
						}
						/* fim jcarvalho */
						
                        document.getElementById(tblId+"-paginationListWrapTop").appendChild(mainDivT);
                } else {
						/* jcarvalho */
						/* razao: mostrar sempre dropdown do nº de items por página */
						if (!nLinhasTop) {
							document.getElementById(tblId).parentNode.insertBefore(mainDivNLinhasTop, document.getElementById(tblId));
						}
						/* fim jcarvalho */

                        document.getElementById(tblId).parentNode.insertBefore(mainDivT, document.getElementById(tblId));
                };

                if(document.getElementById(tblId+"-paginationListWrapBottom")) {
						/* jcarvalho */
						/* razao: mostrar sempre dropdown do nº de items por página */
						if (!nLinhasBottom ) {
							document.getElementById(tblId+"-paginationListWrapBottom").appendChild(mainDivNLinhasBottom);
						}
						/* fim jcarvalho */

                        document.getElementById(tblId+"-paginationListWrapBottom").appendChild(mainDivB);

                } else {
						/* jcarvalho */			
						/* razao: mostrar sempre dropdown do nº de items por página */
						if (!nLinhasBottom ) {
							document.getElementById(tblId).parentNode.insertBefore(mainDivNLinhasBottom, document.getElementById(tblId).nextSibling);
						}

						/* fim jcarvalho */

                        document.getElementById(tblId).parentNode.insertBefore(mainDivB, document.getElementById(tblId).nextSibling);



                };
		
        },
        // The tableSort script uses this function to redraw.
        redraw: function(tableid, identical) {
        //alert('6');
       

                if(!tableid || !(tableid in fdTableSort.tableCache) || !(tableid in tablePaginater.tableInfo)) { return; };
                
                var dataObj     = fdTableSort.tableCache[tableid];
                var data        = dataObj.data;
                var len1        = data.length;
                var len2        = len1 ? data[0].length - 1 : 0;
                var hook        = dataObj.hook;
                var colStyle    = dataObj.colStyle;
                var rowStyle    = dataObj.rowStyle;
                var colOrder    = dataObj.colOrder;
                
                var page        = tablePaginater.tableInfo[tableid].currentPage - 1;
                var d1          = tablePaginater.tableInfo[tableid].rowsPerPage * page;
                var d2          = Math.min(tablePaginater.tableInfo[tableid].totalRows, d1 + tablePaginater.tableInfo[tableid].rowsPerPage);

                var cnt         = 0;
                var rs          = 0;
                var reg         = /(^|\s)invisibleRow(\s|$)/;
                
                var tr, tds, cell, pos;

                for(var i = 0; i < len1; i++) {
                        tr = data[i][len2];
                        
                        if(colStyle) {
                                tds = tr.cells;
                                for(thPos in colOrder) {
                                        if(!colOrder[thPos]) tablePaginater.removeClass(tds[thPos], colStyle);
                                        else tablePaginater.addClass(tds[thPos], colStyle);
                                };
                        };
                        
                        if(tr.className.search(reg) != -1) {
                                continue;
                        };
                        
                        if(!identical) {
                                cnt++;

                                if(cnt > d1 && cnt <= d2) {
                                        if(rowStyle) {
                                                if(rs++ & 1) tablePaginater.addClass(tr, rowStyle);
                                                else tablePaginater.removeClass(tr, rowStyle);
                                        };
                                        tr.style.display = "";
                                } else {
                                        tr.style.display = "none";
                                };

                                // Netscape 8.1.2 requires the removeChild call or it freaks out, so add the line if you want to support this browser
                                // hook.removeChild(tr);
                                hook.appendChild(tr);
                        };
                };
				
				/* joão carvalho */
				/* razão: totais para colunas numéricas */
				tablePaginater.callback(tableid);
				//

                tr = tds = hook = null;

        },
        showPage: function(tblId, pageNum) {
        		//alert('7');
                if(!(tblId in tablePaginater.tableInfo)) { return; };

                var page = !pageNum ? tablePaginater.tableInfo[tblId].currentPage - 1 : pageNum - 1;

                var d1  = tablePaginater.tableInfo[tblId].rowsPerPage * page;
                var d2  = Math.min(tablePaginater.tableInfo[tblId].totalRows, d1 + tablePaginater.tableInfo[tblId].rowsPerPage);
                var trs = tablePaginater.tableInfo[tblId].hook.rows;
                var cnt = 0;
                var rc  = 0;
                var len = trs.length;
                var rs  = tablePaginater.tableInfo[tblId].rowStyle;
                var reg = /(^|\s)invisibleRow(\s|$)/;
                
                for(var i = 0; i < len; i++) {
                        if(trs[i].getElementsByTagName("th").length || (trs[i].parentNode && trs[i].parentNode.tagName.toLowerCase().search(/thead|tfoot/) != -1)) continue;

                        if(trs[i].className.search(reg) != -1) {
                                continue;
                        };

                        cnt++;
                        
                        if(cnt > d1 && cnt <= d2) {
                                if(rs) {
                                        if(rc++ & 1) {
                                                tablePaginater.addClass(trs[i], rs);
                                        } else {
                                                tablePaginater.removeClass(trs[i], rs);
                                        }
                                };
                                trs[i].style.display = "";
                        } else {
                                trs[i].style.display = "none";
                        };
                };

				

                tablePaginater.buildPagination(tblId);
                tablePaginater.callback(tblId);
				
        },
        callback: function(tblId) {
        		//alert('8');
                var func;
                if(tablePaginater.tableInfo[tblId].callback.indexOf(".") != -1) {
                        var split = tablePaginater.tableInfo[tblId].callback.split(".");
                        func = window;
                        for(var i = 0, f; f = split[i]; i++) {
                                if(f in func) {
                                        func = func[f];
                                } else {
                                        func = "";
                                        break;
                                };
                        };
                } else if(tablePaginater.tableInfo[tblId].callback in window) {
                        func = window[tablePaginater.tableInfo[tblId].callback];
                };

                if(typeof func == "function") {
                        func(tblId);
                };

                func = null;
        },
        buttonClick: function(e) {
                
                   tblId = globalTableId;
                    
                e = e || window.event;

                var a = this.tagName.toLowerCase() == "a" ? this : this.getElementsByTagName("a")[0];

                if(a.className.search("currentPage") != -1) return false;

                var ul = this;
                while(ul.tagName.toLowerCase() != "p") ul = ul.parentNode;

                var tblId = ul.id.replace("-tablePaginaterClone","").replace("-tablePaginater", "");

                tablePaginater.tableInfo[tblId].lastPage = tablePaginater.tableInfo[tblId].currentPage;
                
                var showPrevNext = 0;
                
                if(a.className.search("previous-page") != -1) {
                        tablePaginater.tableInfo[tblId].currentPage = tablePaginater.tableInfo[tblId].currentPage > 1 ? tablePaginater.tableInfo[tblId].currentPage - 1 : tablePaginater.tableInfo[tblId].numPages;
                        showPrevNext = 1;
                } else if(a.className.search("next-page") != -1) {
                        tablePaginater.tableInfo[tblId].currentPage = tablePaginater.tableInfo[tblId].currentPage < tablePaginater.tableInfo[tblId].numPages ? tablePaginater.tableInfo[tblId].currentPage + 1 : 1;
                        showPrevNext = 2;
                } else if(a.className.search("first-page") != -1) {
                        tablePaginater.tableInfo[tblId].currentPage = 1;
                } else if(a.className.search("last-page") != -1) {
                        tablePaginater.tableInfo[tblId].currentPage = tablePaginater.tableInfo[tblId].numPages;
                } else {
                        tablePaginater.tableInfo[tblId].currentPage = parseInt(a.className.match(/page-([0-9]+)/)[1]) || 1;
                };

                tablePaginater.showPage(tblId);

                // Focus on the appropriate button (previous, next or the current page)
                // I'm hoping screen readers are savvy enough to indicate the focus event to the user
                if(showPrevNext == 1) {
                        var elem = document.getElementById(ul.id.search("-tablePaginaterClone") != -1 ? tblId + "-previousPageC" : tblId + "-previousPage");
                } else if(showPrevNext == 2) {
                        var elem = document.getElementById(ul.id.search("-tablePaginaterClone") != -1 ? tblId + "-nextPageC" : tblId + "-nextPage");
                } else {
                        var elem = document.getElementById(ul.id.search("-tablePaginaterClone") != -1 ? tblId + "-currentPageC" : tblId + "-currentPage");
                };
                
                if(elem && elem.tagName.toLowerCase() == "a") { elem.focus(); };

                if(e.stopPropagation) {
                        e.stopPropagation();
                        e.preventDefault();
                };

                /*@cc_on
                @if(@_win32)
                e.cancelBubble = true;
                e.returnValue  = false;
                @end
                @*/
                return false;
        },
        onUnLoad: function(e) {
               
        },

		/* joão carvalho */
		/* razão: totais para colunas numéricas */
		/* esta função é a função callback permitida */
		runNumericTotals: function (tblId ) {

			var sCols = tablePaginater.tableInfo[tblId].colsToShowTotals;
			var len = sCols.length;
			for (var i=0; i<len; i++) {
				var lsum = tablePaginater.sumColumns(tblId, sCols[i].id);				
				var el = document.getElementsBySelector("table[id='" + tblId  + "'] tfoot tr td[id='" + sCols[i].id + "']");
				

/*				alert('-' + el.innerHTML);
				alert('-' + lsum + el[0].innerHTML);
				if (lsum!='n/a') 
				{
alert(lsum);
alert(el[0].innerHTML);

					lsum = lsum + el[0].innerHTML;
				}
*/

				el.setHTML(lsum);
			}
		},
		/* fim */
		/* joão carvalho */
		/* razão: totais para colunas numéricas */


		/* joão carvalho */
		/* razão: totais para colunas numéricas */
        sumColumns: function(tblId, colId) {
                if(!(tblId in tablePaginater.tableInfo)) { return; };
                
				var trs = tablePaginater.tableInfo[tblId].hook.rows;
                var len = trs.length;
                var reg = /(^|\s)invisibleRow(\s|$)/;
				var sum = parseFloat(0);

//alert(len );

//debugger;
				

                for(var i = 0; i < len; i++) {
					if( trs[i].style.display != "") {
						continue;
					}
					
					if(trs[i].getElementsByTagName("th").length || (trs[i].parentNode && trs[i].parentNode.tagName.toLowerCase().search(/thead|tfoot/) != -1)) {
						continue;
					}
					if(trs[i].className.search(reg) != -1) {
						continue;
					};
					
					var els = [];
					if (document.all) {
						var lencols= trs[i].childNodes.length;
						for (var j=0; j<lencols; j++) {
							if (trs[i].childNodes[j].colname == colId) {
								els.push (trs[i].childNodes[j]);
								break; 
							} 
						}
					}
					else {
						els= trs[i].getElementsBySelector("td[colname='" + colId + "']");
					}

					if (!els || els.length==0 || els[0].innerHTML=='n/a' || els[0].innerHTML=='n/a&nbsp;\u20AC') {
						if (els[0].innerHTML=='n/a' || els[0].innerHTML=='n/a&nbsp;\u20AC')
						{
							return 'n/a';
						}	

						continue;
					};
					//els[0].innerHTML= els[0].innerHTML + " €";
					var n = parseFloat(els[0].innerHTML);
					//alert(n);
					sum = sum + n;
					//alert(sum);
					
                };


			return sum.toFixed(2) + ' ' + '\u20AC';
        }
		/* fim */
		/* joão carvalho */
		/* razão: totais para colunas numéricas */

};


function tablePaginaterInitializer()
{
//debugger;

if(document.getElementById('TabelDataList') && document.getElementById('LoadingLayer'))
			{
				document.getElementById('TabelDataList').style.visibility = 'hidden'; 
				document.getElementById('TabelDataList').style.display = 'none'; 
				document.getElementById('LoadingLayer').style.visibility = ''; 
				document.getElementById('LoadingLayer').style.display = ''; 
			}
			

	tablePaginater.addEvent(window, "load",   tablePaginater.init);

}
function tablePaginaterUnloader()
{
	tablePaginater.addEvent(window, "unload",   tablePaginater.onUnLoad);
}


function HideListTabel()
{

			if(document.getElementById('TabelDataList') && document.getElementById('LoadingLayer') && Page_ClientValidate())
			{
				document.getElementById('TabelDataList').style.visibility = 'hidden'; 
				document.getElementById('TabelDataList').style.display = 'none'; 
				document.getElementById('LoadingLayer').style.visibility = ''; 
				document.getElementById('LoadingLayer').style.display = ''; 
			}
			

}




