// Funzione di apertura pagina di visualizzazione delle schede selezionate
function ApriScheda(idlibro,contatore){			
	document.getElementById("FormScheda").idlibro.value = idlibro;
	document.getElementById("FormScheda").contatore.value = contatore;
	document.getElementById("FormScheda").submit();
}

// Funzione di apertura pagina di visualizzazione delle schede selezionate
function SfogliaSchede(){		
		if (document.Form_searchResults.libriselezionati.value == ''){
			alert('Selezionare almeno una scheda')
		}else{	
			document.getElementById("FormScheda").libriselezionati.value = document.Form_searchResults.libriselezionati.value
			document.getElementById("FormScheda").submit();
			
		}
}

// stampa elenco libri
function ApriStampa(tipostampa, tipo){
		if (document.Form_searchResults.libriselezionati.value == ''){
			alert('Selezionare almeno una scheda')
		}else{
			if (tipostampa == 'stampante'){
				document.FormStampa.tipostampa.value = tipostampa;
				document.FormStampa.tipo.value = tipo;
				document.FormStampa.libriselezionati.value = document.Form_searchResults.libriselezionati.value
				document.FormStampa.target = '_blank';
				document.FormStampa.submit();
			}
			
			if (tipostampa == 'file'){
				document.FormStampa.target='content';
				document.FormSalva.tipostampa.value = tipostampa;
				document.FormSalva.tipo.value = tipo;
				document.FormSalva.libriselezionati.value = document.Form_searchResults.libriselezionati.value
				document.FormSalva.target = '_self';
				document.FormSalva.submit(); 
				;
			}
			
		}
}

// stampa scheda
function ApriStampaScheda(tipostampa, tipo){	
			if (tipostampa == 'stampante'){			
				document.FormStampa.tipostampa.value = tipostampa;		
				document.FormStampa.tipo.value = tipo;
				document.FormStampa.target = '_blank';
				document.FormStampa.submit();		
			}
			
			if (tipostampa == 'file'){
				document.FormSalva.tipostampa.value = tipostampa;
				document.FormSalva.tipo.value = tipo;
				document.FormSalva.target = '_self';
				document.FormSalva.submit();
			}		
	}
	
	
// Funzione di apertura pagine (avanti e indietro) relative alla ricerca
function ApriPagina(numeropagina){
	document.Form_searchResults.pagina.value = numeropagina;
	document.Form_searchResults.submit();
}
// Funzione di apertura pagine (avanti e indietro) relative alla visualizzazione delle schede
function ApriPaginaSchede(numeropagina, idScheda){
	document.Form1.pagina.value = numeropagina;
	document.Form1.idlibro.value = idScheda;
	document.Form1.submit();
}


// Funzione che permette la selezione di una o pił schede uscite dalla ricerca
function SelezionaBoxSingolo(contatorebox, idlibro){
	var aLibriSelezionati=new Array();
	var sNomeBox = eval("document.Form_searchResults.libri_selezionati"+contatorebox);
	if (sNomeBox.checked == true){
		if (document.Form_searchResults.libriselezionati.value != '') document.Form_searchResults.libriselezionati.value = document.Form_searchResults.libriselezionati.value + ', ';
		document.Form_searchResults.libriselezionati.value = document.Form_searchResults.libriselezionati.value + sNomeBox.value;
	}else{
		aLibriSelezionati = document.Form_searchResults.libriselezionati.value.split(', ');
		document.Form_searchResults.libriselezionati.value = '';
		for (var i=0; i<aLibriSelezionati.length; i++){
			if (aLibriSelezionati[i] != sNomeBox.value){
				if (document.Form_searchResults.libriselezionati.value != '') document.Form_searchResults.libriselezionati.value = document.Form_searchResults.libriselezionati.value + ', ';
				document.Form_searchResults.libriselezionati.value = document.Form_searchResults.libriselezionati.value + aLibriSelezionati[i];
			}
		}
	}
}


// Funzione che permette la SELEZIONE totale delle schede uscite dalla ricerca
function selectAll() {
	for (var i=0; i<aCheckbox.length; i++) {
		if (aCheckbox[i].checked == false) {				
			aCheckbox[i].checked = true;
			document.Form_searchResults.libri_tutti.checked = true;
			document.getElementById("Form_searchResults").libriselezionati.value = IdSelezionaTutti;
		}else{				
			aCheckbox[i].checked = false;
			document.Form_searchResults.libri_tutti.checked = false;					
			document.getElementById("Form_searchResults").libriselezionati.value = "";
		}
	}			
}


// funzione che cancella i dati immessi nella form di ricerca
function cancellaCampi() {
	var messaggio = window.confirm('Sei sicuro di voler cancellare tutto?');
	if (messaggio == true){
		document.getElementById("formcerca").reset();
	}
}	


//  verifica che il valore dei campi annoDA e annoA siano ordinati
function calcolaDifferenza(strDA, strA){
		if (strDA == ''){strDA = 0};
		if (strA == ''){strA = 0};
		
		if (strDA > strA){
			var messaggio = window.confirm('Attenzione! Non puoi selezionare nel campo A un valore inferiore al campo DA.');
			if (messaggio == true){
				document.getElementById("annoa").focus();
			}else{
				document.getElementById("annoa").focus();
			}
		}
}
//  verifica che il valore dei campi annoDA e annoA siano ordinati prima di procedere al submit
function requestRightYears(strDA, strA){
		if (strDA > strA){
			calcolaDifferenza(strDA, strA);
		}else{
			document.getElementById("formcerca").submit();
		}
}