﻿var idSplitter;
var SplitterOrientation;
var idBuscador;
var idMapa;
function SetVarIDs(id, id1, id2,orientation) {
    idMapa = "map_canvas" + id;
    idSplitter = id1;
    idBuscador = id2;
    SplitterOrientation = orientation;
}
function HideSplitter(){

    document.getElementById(idSplitter).style.display="none";
    document.getElementById(idBuscador).style.display="none";
    }

function ShowSplitter() {
    document.getElementById(idSplitter).style.display="";
    document.getElementById(idBuscador).style.display="";
    }
    
function Alternar() {
    if (ToolTip) { ToolTip.style.visibility = "hidden"; }
    var Seccion = document.getElementById(idBuscador);
    var MapaDiv=document.getElementById(idMapa);
    var ancho = Seccion.offsetWidth ;
    var alto = Seccion.offsetHeight;
    if (Seccion.style.display=="none") {
        Seccion.style.display = "";
        if (SplitterOrientation == "v") {
            MapaDiv.style.width = AnchoMap; }
        else {
            MapaDiv.style.height = AltoMap;
            }
        
    }else{
        Seccion.style.display = "none";
        if (SplitterOrientation == "v") {
            MapaDiv.style.width = AnchoMap + ancho;
        }
        else {
            MapaDiv.style.height = AltoMap + alto;
        }
    }
    if (map != null) { map.checkResize(); }

}

function ValidarCustomField(source, arguments)
{            
        var Valido=true;
        var TD=document.getElementById("tdReorder");
        var a;
        if(document.all)
        {
           a= TD.childNodes[0]}
        else{
            a=TD.childNodes[1]
        }

            for (var i=0; i<a.length; i++) {
                if(a[i].value==arguments.Value)
                {
                Valido=false;
                i=a.length;
                }
            }   
        arguments.IsValid=Valido;
        return;
  }
var pager;

function VerTabla()
{
        if (ToolTip) { ToolTip.style.visibility = "hidden"; }
        pager = new Pager("TablaPag", RecordPP);
        pager.init();
        pager.showPageNav("pager", "Paginator");
        pager.showPage(1);
        document.getElementById("pnlList").style.display = "block";
        document.getElementById("Paginator").style.display = "block";
        document.getElementById("TablaPag").style.display = "block";
        document.getElementById("pnlList").style.height = AltoMap;
        document.getElementById("pnlSearch").style.display = "none";
        var Seccion = document.getElementById("pnlList");
        var MapaDiv = document.getElementById(idMapa);
        var alto = Seccion.offsetHeight;
        if ((SplitterOrientation == "v") && (alto > MapaDiv.offsetHeight)) {
            MapaDiv.style.height = alto;
            if (map != null) { map.checkResize(); }
        }
}
function OcultarTabla() {
    if (ToolTip) { ToolTip.style.visibility = "hidden"; }

    document.getElementById("pnlList").style.display = "none";
    document.getElementById("Paginator").style.display = "none";
    document.getElementById("TablaPag").style.display = "none";
    document.getElementById("pnlSearch").style.display = "block";
    var MapaDiv = document.getElementById(idMapa);
    if ((SplitterOrientation == "v") && (AltoMap < MapaDiv.offsetHeight)) {
        MapaDiv.style.height = AltoMap;
        if (map != null) { map.checkResize(); }

    } 
}

function Pager(tableName, itemsPerPage) {
    this.tableName = tableName;
    this.itemsPerPage = itemsPerPage;
    this.currentPage = 1;
    this.pages = 0;
    this.inited = false;
    this.rows=null;
    
    this.showRecords = function(from, to) { 
        for (var i = 0; i < this.rows.length; i++) {
            if (i < from || i > to)  
                this.rows[i].style.display = 'none';
            else
                this.rows[i].style.display = '';
        }
    }
    
    this.showPage = function(pageNumber) {
    	if (! this.inited) {
    		alert("not inited");
    		return;
    	}
        if (document.getElementById('pg'+this.currentPage)){
        var oldPageAnchor = document.getElementById('pg'+this.currentPage);
        oldPageAnchor.className="";
        this.currentPage = pageNumber;
        var newPageAnchor = document.getElementById('pg'+this.currentPage);
        newPageAnchor.className = 'pg-selected';
        
        var from = (pageNumber - 1) * itemsPerPage ;
        var to = from + itemsPerPage - 1;
        this.showRecords(from, to, this.rows);
        }
    }   
    
    this.prev = function() {
        if (this.currentPage > 1)
            this.showPage(this.currentPage - 1);
    }
    
    this.next = function() {
        if (this.currentPage < this.pages) {
            this.showPage(this.currentPage + 1);
        }
    }                        
    
    this.init = function() {
        this.rows = document.getElementById(tableName).rows;
        var records = (this.rows.length - 1); 
        this.pages = Math.ceil(records / itemsPerPage);
        this.inited = true;
    }

    this.showPageNav = function(pagerName, positionId) {
    	if (! this.inited) {
    		alert("not inited");
    		return;
    	}
    	var element = document.getElementById(positionId);
    	
    	var pagerHtml = '<div class="pag-bottom"><a href="javascript:' + pagerName + '.prev();"> &#171 </a>';
        for (var page = 1; page <= this.pages; page++) 
        pagerHtml += '<a href="javascript:' + pagerName + '.showPage(' + page + ');" id="pg' + page + '" >' + page + '</a>';
        
        pagerHtml += '<a href="javascript:'+pagerName+'.next();" >  &#187;</a></div>';               element.innerHTML = pagerHtml;
    }
}

