/*   NovaPA - 888 Software Products S.r.l.                                   

Il codice è di esclusiva proprietà di 888SP ed è protetto dal Codice della Proprietà Industriale e Intellettuale (D.Lgs. n. 30/2005), dalla legge italiana sul diritto d'autore (L. 633/1941), dalle norme contenute nei trattati internazionali, nonché dalle leggi in vigore nel Paese in cui esso viene usato. La struttura, l'organizzazione e il codice del SOFTWARE costituiscono importanti segreti industriali, commerciali ed informazioni confidenziali di 888SP e dei suoi fornitori e pertanto l’utilizzatore si obbliga a non divulgare in alcun modo le suddette informazioni riservate. Fatta eccezione per quanto espressamente previsto nel contratto di LICENZA D’USO, non è concesso alcun diritto di proprietà intellettuale sul codice. Tutti i diritti non espressamente concessi sono riservati da 888SP e dei suoi FORNITORI. Ogni abuso nella commercializzazione o nell'utilizzo del codice verrà punito secondo la normativa italiana, comunitaria ed internazionale.

*/
  
  
function salva() {  
		if (document.all) {  
									document.execCommand("SaveAs");  
								}else{  
									alert('Disponibile solo per Internet Explorer.');  
								} 
	} 
	
function myLink(){
    if (document.all) {  
								    v_myLink= "javascript:salva()";
								}else{  
							        v_myLink= window.location.href.toString();
								} 
   return v_myLink;
}

function Contenuto (myCell){
	 Esito = "Nessun valore definito"
	if (myCell.innerText)
			Esito =  myCell.innerText;
	else 
	 Esito =  myCell.textContent;
	return Esito;
}

function dettaglioCella (oRiga,nColonna,idHTML){
   var vHTML=document.getElementById(idHTML);
   newHTML = oRiga.cells[nColonna].innerHTML;
   vHTML.innerHTML = newHTML;
 }
 

 
 function visualizza(tabella){
             var odiv = document.getElementById(tabella);
             odiv.style.display = '';
}

function nascondi(oggetto){
             var vOggetto = document.getElementById(oggetto);
             vOggetto.style.display = 'none';
}   

function setBGC (idOggetto, vBGC){
		var vOggetto= document.getElementById(idOggetto);
             vOggetto.style.backgroundColor = vBGC;
}         
    
function controlla(){
						   var myFiltro = document.Ricerca.FindCIG.value;
						  pager.serch (myFiltro);
						   var nRighe  =  document.Ricerca.NumRighe.value;
						   pager.change(nRighe);
							pager.showPageNav('pager', 'pageNavPosition'); 
						   pager.showPage(1,'pager', 'pageNavPosition');
							pager.viewRecords('pageRecords');
 } 


function Pager(tableName, itemsPerPage) {
    this.tableName = tableName;
    this.itemsPerPage = itemsPerPage;
    this.currentPage = 1;
    this.currentRow = null;
    this.pages = 0;
    this.inited = false;
    this.Records = 0;
    this.serchRecords=0;
    this.Filtro=""
  
 // ******** Funzione viewRecords **********  
 this.viewRecords = function( lbl_pageRecords) {
       
	var element2 = document.getElementById(lbl_pageRecords);
    	
    	var pagerHtml = '<span > Appalti individuati: <b>' + this.serchRecords +'</b> ( su '  + this.Records +' totali)</span>';
        element2.innerHTML = pagerHtml;        
     }     
       
// ******** Funzione serch(myFiltro) **********
  this.serch = function(myFiltro){
		   var rows = document.getElementById(tableName).rows;
		   var serchRecords = 0;
		 
		  <!--alert ("Valore cercato: " + myFiltro);-->
		   // i starts from 1 to skip table header row
        for (var i = 1; i < rows.length; i++) {
            var myCell = Contenuto (rows[i].cells[0]); 
            myCell = myCell + Contenuto (rows[i].cells[1]);
            <!--  Confronto stringhe convertite in minuscolo-->
            myCell = myCell.toLowerCase();
            myFiltro = myFiltro.toLowerCase();
            <!--alert ("Stringa : " + myCell); -->
            if (myCell.indexOf(myFiltro) != -1) {
                serchRecords = serchRecords +1; }
              
        }
       <!-- alert ("Corrispondenze trovate: " + serchRecords);-->
     this.serchRecords=serchRecords;
     this.Filtro = myFiltro;
    } 
  
  // ******** Funzione init() **********
   
  this.init = function() {
        var rows = document.getElementById(tableName).rows;
        var records = (rows.length - 1); 
        this.pages = Math.ceil(records / itemsPerPage);
        this.inited = true;
        this.Records=records;
        this.serchRecords=records;
    }   
     
  // ******** Funzione selectRow (oRow) *********   
   this.selectRow = function (oRow){
    if (this.currentRow == null) {
         oRow.style.backgroundColor = '#ABCDEF';
          }
     else {
       this.currentRow.style.backgroundColor = '#FFFFFF';
       oRow.style.backgroundColor = '99CBFF';
       }
       this.currentRow = oRow; 
 }    
    
 // ******** Funzione change(NewItemsPerPage) *********

    this.change = function(NewItemsPerPage) {
        <!--var rows = document.getElementById(tableName).rows;-->
       <!-- var records = (rows.length - 1); -->
      
         var records = this.serchRecords; 
        <!--  alert ("Info: " + records);-->
        itemsPerPage = NewItemsPerPage;
        this.itemsPerPage = itemsPerPage;
        
        pages = Math.ceil(records / itemsPerPage);
        this.pages = pages;
        this.currentPage = 1;
    }  

  // ******** Funzione showRecordsSerch **********   
  
    this.showRecordsSerch = function(from, to) {        
        var myFiltro = this.Filtro;  
     <!--   alert ("myFiltro: " + myFiltro)  -->   
        var rows = document.getElementById(tableName).rows;
        var j = 0;
        // i starts from 1 to skip table header row
     <!--   alert ("Valore From:" + from + " Valore TO: " + to);-->
        for (var i = 1; i < rows.length; i++) {
            var myCell = Contenuto (rows[i].cells[0]); 
			myCell = myCell + Contenuto (rows[i].cells[1]); 
			   <!--  Confronto stringhe convertite in minuscolo-->
            myCell = myCell.toLowerCase();
            myFiltro = myFiltro.toLowerCase();
            
            if (myCell.indexOf(myFiltro) != -1)
             {
             j = j +1
			if (j < from || j > to)  
                rows[i].style.display = 'none';
            else 
                rows[i].style.display = '';             
             }
            else
            {
             rows[i].style.display = 'none';
            }
        }
       <!-- alert ("variabile j: " + j);-->
    }
    
 // ******** Funzione showPage **********     
    
    this.showPage = function(pageNumber,pagerName, positionId) {
    	if (! this.inited) {
    		alert("not inited");
    		return;
			} 
			
		if (pageNumber > this.pages)	{ this.showRecordsSerch(0,0);}
		else {
					<!-- Ripristino la formattazione alla pagine deselezionata --->
					var oldPageAnchor = document.getElementById('pg'+this.currentPage);
					oldPageAnchor.className = 'pg-normal';
				   <!--Aggiorno la pagina corrente-->
					this.currentPage = pageNumber;
					<!--Ridisegno la barra di navigazione-->
					this.showPageNav('pager', 'pageNavPosition'); 
					<!--Applico la formattazione per la pagina selezionata-->
					var newPageAnchor = document.getElementById('pg'+this.currentPage);
					newPageAnchor.className = 'pg-selected';   
				   
					
				   var from = (pageNumber - 1) * itemsPerPage + 1;
					var iniziale = parseInt(from)
					var step = parseInt(itemsPerPage)
					var to = iniziale+step-1;
					this.showRecordsSerch(from,to);
				} 
    }  
    
  // ******** Funzione prev **********    
    this.prev = function() {
        if (this.currentPage > 1)
            this.showPage(this.currentPage - 1);
           
    }
    
 // ******** Funzione next **********     
    this.next = function() {
        if (this.currentPage < this.pages) {
            this.showPage(this.currentPage + 1);
        }
     }    
     
 // ******** Funzione last **********   
     this.last = function() {
         if (this.pages > 0) {
            this.showPage(this.pages);
        }
     }                    
     
  // ******** Funzione first ********** 
    this.first = function() {
         if (this.pages > 0) {
            this.showPage(1);
        }
     }   
  
 // ******** showPageNav ********** 
    this.showPageNav = function(pagerName, positionId) {
    	if (! this.inited) {
    		alert("not inited");
    		return;
    	}
    	var element = document.getElementById(positionId);
   
    var maxviewpage = 9;
    var multiplo = (maxviewpage -1 )/2;
    
    	if (this.currentPage < (multiplo+1)) {PaginaInizio = 1}
							else { if( (this.pages - this.currentPage) < (multiplo) )
							                            {PaginaInizio = (this.pages - maxviewpage)+1}
												else  {PaginaInizio = (this.currentPage - multiplo);}	
									}
		if (PaginaInizio  < 1) {PaginaInizio = 1}							
    	if (this.pages < maxviewpage) {PaginaFine = this.pages;}
							else {   PaginaFine = this.currentPage +multiplo;
									  if  (PaginaFine < maxviewpage) PaginaFine =  maxviewpage;
									  if  (PaginaFine > this.pages) PaginaFine =  this.pages;
									 }	
    	
      
		<!--Visualizzazione pulsante Inizio-->
        var  pagerHtml = '<span onclick="'+pagerName+'.first();" class="pg-normal">  &#171; Inizio</span>'; 
       <!--Visualizzazione pulsante Indietro -->
    	pagerHtml += '<span onclick="' + pagerName + '.prev();" class="pg-normal"> | Indietro </span> | ';
    	<!--Ciclo visualizzazione elenco pagine-->
        for (var page = PaginaInizio; page <= PaginaFine; page++) 
            pagerHtml += '<span id="pg' + page + '" class="pg-normal" onclick="' + pagerName + '.showPage(' + page + ',' + pagerName + ',' + positionId + ');">' + page + '</span>  ';
        <!--Visualizzazione pulsante Avanti -->
        pagerHtml += '<span onclick="'+pagerName+'.next();" class="pg-normal">| Avanti |</span>';            
        <!--Visualizzazione pulsante Fine-->
        pagerHtml += '<span onclick="'+pagerName+'.last();" class="pg-normal"> Fine &#187;</span>'; 
        
        element.innerHTML = pagerHtml;
    }
}


