﻿///Desarrollador: Cristian Pereira 
///Fecha:Mayo 08, 2007 
///Funciones para rollover filas y paginación en una tabla
var	ie=((typeof document.all == 'undefined')?false:true);
function disableAnchor(obj, disable)
{
      
  if(disable)
  {
    var href = obj.getAttribute("href");
    if(href && href != "" && href != null)
    {
       obj.setAttribute('href_bak', href);
   }
    obj.removeAttribute('href');
    obj.style.color="#006699";    
    obj.style.fontSize="12px";
    obj.style.fontWeight="bold";
  }
  else
  {
    if(obj.attributes['href_bak']!=null)
    {
	   obj.setAttribute('href', obj.attributes['href_bak'].nodeValue);
       obj.style.color="black";     
       obj.style.fontSize="11px"; 
       obj.style.fontWeight="normal";
     }   
  }
}
var isclick=1;
function popup(url, w, h)
{
	newWindow = window.open(url,'daughter','toolbar=no,location=no,scrollbars=yes,resize=no,width=' + w + ',height=' + h + ',screenX=100,screenY=100,top=100,left=100');
	isclick=0;
}

function pop_window(url) {
  var popit = window.open(url,'videoWin','menubar=no,toolbar=no,location=no,directories=no,status,scrollbars=no,resizable=no,width=450,height=320');
 }

function RowsToLinksEdit(tblID,indexStartRow,indexAnchor,indexCellID,indexCellTemplate,indexCellDelete)
{
    
    if(document.getElementById(tblID)==null)
        return;
    
    var rows = document.getElementById(tblID).getElementsByTagName("tr");
    for(i=indexStartRow;i<rows.length;i++){
	    var link = rows[i].getElementsByTagName("a")
	    //alert(link[1].href);
	    if(link.length>1)
	    {   rows[i].setAttribute('title','Modificar Ficha ID:' + rows[i].cells[indexCellID].innerHTML);
	        rows[i].cells[indexCellDelete].setAttribute('title','Borrar Ficha ID:' + rows[i].cells[indexCellID].innerHTML);
	        rows[i].cells[indexCellTemplate].setAttribute('title','Crear Ficha a partir de Ficha ID:' + rows[i].cells[indexCellID].innerHTML);
		    rows[i].onclick = new Function("if(isclick){document.location.href='" + link[indexAnchor].href + "'} else {isclick=1; return false;}");
		    rows[i].onmouseover = new Function("this.className='highlight'");
		    rows[i].onmouseout = new Function("this.className='nohighlight'");
	    }
    }
}

function RowsToLinksEdit2(tblID,indexStartRow,indexCellEdit,indexCellID,indexCellTemplate,indexCellDelete)
{
    
    if(document.getElementById(tblID)==null)
        return;
    
    var rows = document.getElementById(tblID).getElementsByTagName("tr");
    for(i=indexStartRow;i<rows.length;i++){	   
	    rows[i].cells[indexCellEdit].setAttribute('title','Modificar Ficha ID:' + rows[i].cells[indexCellID].innerHTML);
        rows[i].cells[indexCellDelete].setAttribute('title','Borrar Ficha ID:' + rows[i].cells[indexCellID].innerHTML);
        rows[i].cells[indexCellTemplate].setAttribute('title','Crear Ficha a partir de Ficha ID:' + rows[i].cells[indexCellID].innerHTML);
	    //rows[i].onclick = new Function("if(isclick){document.location.href='" + link[indexAnchor].href + "'} else {isclick=1; return false;}");
	    rows[i].onmouseover = new Function("this.className='highlight2'");
	    rows[i].onmouseout = new Function("this.className='nohighlight'");
	    
    }
}

function RowsToLinksEdit3(tblID,indexStartRow,indexCellID,arrIndex,arrMsg)
{
    var i;
    var j;
    var k;
    
    if(document.getElementById(tblID)==null)
        return;
    
    var rows = document.getElementById(tblID).getElementsByTagName("tr");
    var lenIndex=arrIndex.length;
    var lenMsg=arrMsg.length;
    //## =>ID
    for(i=indexStartRow;i<rows.length;i++)
    {	   
        for(j=0;j<lenIndex;j++)
            rows[i].cells[arrIndex[j]].setAttribute('title',arrMsg[j].replace('##',rows[i].cells[indexCellID].innerHTML));
        
	    rows[i].onmouseover = new Function("this.className='highlight2'");
	    rows[i].onmouseout = new Function("this.className='nohighlight'");	    
    }
}

function RowsToLinksEdit4(tblID,indexStartRow,indexCellID,arrIndex,arrMsg,actionRow)
{
    var i;
    var j;
    var k;
    
    if(document.getElementById(tblID)==null)
    { 
      
       return;
    }
    
    var rows = document.getElementById(tblID).getElementsByTagName("tr");
    var lenIndex=arrIndex.length;
    var lenMsg=arrMsg.length;
    //## =>ID
    for(i=indexStartRow;i<rows.length;i++)
    {	   
        for(j=0;j<lenIndex;j++)
            rows[i].cells[arrIndex[j]].setAttribute('title',arrMsg[j].replace('##',rows[i].cells[indexCellID].innerHTML));
            
        rows[i].onclick=new Function(actionRow.replace('##',rows[i].cells[indexCellID].innerHTML));
	    rows[i].onmouseover = new Function("this.className='highlight'");
	    rows[i].onmouseout = new Function("this.className='nohighlight'");	    
    }
}

function RowsToLinksEdit5(tblID,indexStartRow,indexCellID,Msg,actionRow,isIndexed)
{
    var i;
   
    if(document.getElementById(tblID)==null)
    {       
       return;
    }
    
    var rows = document.getElementById(tblID).getElementsByTagName("tr");   
    //## =>ID
    for(i=indexStartRow;i<rows.length;i++)
    {	   
        rows[i].setAttribute('title',Msg.replace('##',rows[i].cells[indexCellID].innerHTML));            
        rows[i].onclick=new Function(actionRow.replace('##',rows[i].cells[indexCellID].innerHTML));
        rows[i].onmouseover = new Function("this.className='highlight'");
        rows[i].onmouseout = new Function("this.className='nohighlight'");	    
    }
    
}

function RowsToLinksEdit6(tblID,indexStartRow)
{
    var i;
   
    if(document.getElementById(tblID)==null)
    {       
       return;
    }
    
    var rows = document.getElementById(tblID).getElementsByTagName("tr");   
    //## =>ID
    for(i=indexStartRow;i<rows.length;i++)
    {	               
        rows[i].onmouseover = new Function("this.className='highlight2'");
        rows[i].onmouseout = new Function("this.className='nohighlight'");	    
    }
    
}


//Paging
var ispaging=0;
var indexPage=0;
var numRecords=9;
var npages=1;

function DoPages(tblID,divID)
{   
     ispaging=1;
     
     if(document.getElementById(tblID)==null)
     {
        document.getElementById(divID).style.display='none';
        return;
     }
        
     var totalRows=document.getElementById(tblID).rows.length -1;
    
     npages= parseInt(totalRows/(numRecords+1))+ 1;
     var i=0;
     var objpages=document.getElementById(divID);
     //first page
     objpages.innerHTML="&nbsp;<a onmouseout='javascript:window.status=&quot;&quot;' onmousemove='javascript:window.status=&quot;Pagina Inicial&quot;' onmouseover='javascript:window.status=&quot;Pagina Inicial&quot;' id='lnkpageini'  href='javascript:viewpage(0,&quot;" + tblID + "&quot;)' title='Pagina Inicial' ><<</a> | ";
     //prev page
     objpages.innerHTML= objpages.innerHTML + "<a onmouseout='javascript:window.status=&quot;&quot;' onmousemove='javascript:window.status=&quot;Pagina Anterior&quot;' onmouseover='javascript:window.status=&quot;Pagina Anterior&quot;' id='lnkpageprev'  href='javascript:viewpage(indexPage-1,&quot;" + tblID + "&quot;)' title='Pagina Anterior' ><</a> | ";
     for(i=0;i<npages;i++)
     {
        objpages.innerHTML = objpages.innerHTML + "<a onmouseout='javascript:window.status=&quot;&quot;' onmousemove='javascript:window.status=&quot;Pagina " + (i+1).toString() + "&quot;' onmouseover='javascript:window.status=&quot;Pagina " + (i+1).toString() + "&quot;' id='lnkpage" + i + "'  href='javascript:viewpage("+ i  +",&quot;" + tblID + "&quot;)' title='Pagina " + (i+1).toString() + "' >" + (i+1).toString() + "</a> | ";
     }
     //next page
     objpages.innerHTML= objpages.innerHTML + "<a onmouseout='javascript:window.status=&quot;&quot;' onmousemove='javascript:window.status=&quot;Pagina Siguiente&quot;' onmouseover='javascript:window.status=&quot;Pagina Siguiente&quot;' id='lnkpagenext'  href='javascript:viewpage(indexPage+1,&quot;" + tblID + "&quot;)' title='Pagina Siguiente' >></a> | ";
     //last page
     objpages.innerHTML= objpages.innerHTML + "<a onmouseout='javascript:window.status=\"\"' onmousemove='javascript:window.status=\"Ultima Pagina\"' onmouseover='javascript:window.status=\"Ultima Pagina\"' id='lnkpageend'  href='javascript:viewpage(" + (npages-1).toString() + ",&quot;" + tblID + "&quot;)' title='Ultima Pagina'>>></a> ";
     //document.getElementById('lnkpage0').style.fontWeight='bold'; 
     //disableAnchor(document.getElementById('lnkpage0'), true);   
     viewpage(0,tblID)  

}

function viewpage(newindex,tblID)
{
    
    if(newindex==-1)
        return;
               
    disableAnchor(document.getElementById('lnkpageini'),false);
    disableAnchor(document.getElementById('lnkpageend'),false);
    disableAnchor(document.getElementById('lnkpageprev'),false);
    disableAnchor(document.getElementById('lnkpagenext'),false);
    
    if(newindex<=0)
    {   
        disableAnchor(document.getElementById('lnkpageini'),true);
        disableAnchor(document.getElementById('lnkpageprev'),true);
        newindex=0;
    }
    if(newindex>=(npages-1))
    {    
        disableAnchor(document.getElementById('lnkpageend'),true);
        disableAnchor(document.getElementById('lnkpagenext'),true);
        newindex=npages-1;
    }
   
    disableAnchor(document.getElementById('lnkpage' + indexPage),false); 
    
    if(document.getElementById(tblID + '_pc')!=null)
           document.getElementById(tblID + '_pc').value=newindex;       
           
    //DoCrossRequest('page_client=' + newindex + ',' + tblID);        
    
    var table=document.getElementById(tblID);
    var i=0;   
    var topStartRow=(newindex)*numRecords + 1;
    var topEndRow=(newindex + 1)*numRecords;
    //alert(topStartRow + ' - ' + topEndRow);
    for (i=1;i<table.rows.length;i++)
    {   
        if(i<topStartRow || i>topEndRow)
           table.rows[i].style.display='none';
        else
           table.rows[i].style.display=(ie)?'block':'table-row';      
    }
    
    disableAnchor(document.getElementById('lnkpage' + newindex),true);               
    indexPage=newindex;    
       
}

