 
/*	Versione del 15/2/2006	*/
/*	Versione del 19/2/2006	*/
/*	Versione del 12/3/2006	*/
/*	Versione del 30/12/2006 - 28/1/07 - 31/3/07 - 8/4/07 - 14/4/07 - 15/4/07 - 22/4/07 */
/*	Versione del 12-12-08	*/
/*	Versione del 03-11-09 - nuova funzione scrivi_div_border()	*/
/*	Versione del 12-11-09 */

/* *********************** Sezione comune, indipendente della lingua *************************** */

var gl_max_input = 1500;

/*	1) Caricamento del css in funzione della dimensione dello schermo			*/    
/*	2) Alcune funzioni JS                                                                */
/*	3) Parte comune della definizione del menu di navigazione                            */

var dim_schermo;
var tipo_browser;
var img_test = 0;

dim_schermo = get_screen();
tipo_browser = get_browser();


if (dim_schermo == "low")  		/* 800 x 600 */
{	document.write("<link rel=stylesheet href='bug_800.css' type=text/css>");
}
else if (dim_schermo == "high") 	/* 1024 x 768 */
{	document.write("<link rel=stylesheet href='bug_1024.css' type=text/css>");
}
else  if (dim_schermo == "large")	/* 1280 x 800 oppure 1024 */
{	document.write("<link rel=stylesheet href='bug_1280.css' type=text/css>");
}
else					/* 1400 x 1050 */
{	document.write("<link rel=stylesheet href='bug_1400.css' type=text/css>");
}

	document.write("<link rel=stylesheet href='bug_print.css' type=text/css media=print>");
	
	
/*      --------------------------------------------------------	*/
/*	Funzioni per il caricamento del logo di sinistra		*/
/*      --------------------------------------------------------	*/

function scrivi_logo_1 (lang)  {

    if (lang == "it")
    {	if (dim_schermo == "low")  		/* 800 x 600 */
	{	document.write("<img id='logo1' src='images/logox2_800.jpg' alt='Sito della Pontificia Università Gregoriana'>");
	}
	else if (dim_schermo == "high") 	/* 1024 x 768 */
	{	document.write("<img id='logo1' src='images/logox2_1024.jpg' alt='Sito della Pontificia Università Gregoriana'>");
	} 
	else  if (dim_schermo == "large")	/* 1280 x 800 oppure 1024 */
	{	document.write("<img id='logo1' src='images/logox2_1280.jpg' alt='Sito della Pontificia Università Gregoriana'>");
	}
	else
	{	document.write("<img id='logo1' src='images/logox2_1400.jpg' alt='Sito della Pontificia Università Gregoriana'>");
	}
    } else
    if (lang == "en")
    {	if (dim_schermo == "low")  		/* 800 x 600 */
	{	document.write("<img id='logo1' src='images/logox2_800.jpg' alt='Website of the Pontifical Gregorian University'>");
	}
	else if (dim_schermo == "high") 	/* 1024 x 768 */
	{	document.write("<img id='logo1' src='images/logox2_1024.jpg' alt='Website of the Pontifical Gregorian University'>");
	} 
	else  if (dim_schermo == "large")	/* 1280 x 800 oppure 1024 */
	{	document.write("<img id='logo1' src='images/logox2_1280.jpg' alt='Website of the Pontifical Gregorian University'>");
	}
	else
	{	document.write("<img id='logo1' src='images/logox2_1400.jpg' alt='Website of the Pontifical Gregorian University'>");
	}
    } else
    alert("Error function scrivi_logo_1 in bug_new.js");
	
    return true;
}

/*      --------------------------------------------------------	*/
/*	Funzioni per il caricamento del logo di destra		*/
/*      --------------------------------------------------------	*/

function scrivi_logo_2 (lang)  {

    if (lang == "it")
    {	if (dim_schermo == "low")  		/* 800 x 600 */
	{	document.write("<img id='logo2' src='images/logoy2_800.jpg' alt='Logo biblioteca'>");
	}
	else if (dim_schermo == "high") 	/* 1024 x 768 */
	{	document.write("<img id='logo2' src='images/logoy2_1024.jpg' alt='Logo biblioteca'>");
	} 
	else  if (dim_schermo == "large")	/* 1280 x 800 oppure 1024 */
	{	document.write("<img id='logo2' src='images/logoy2_1280.jpg' alt='Logo biblioteca'>");
	}
	else
	{	document.write("<img id='logo2' src='images/logoy2_1400.jpg' alt='Logo biblioteca'>");
	}
    } else
    if (lang == "en")
    {	if (dim_schermo == "low")  		/* 800 x 600 */
	{	document.write("<img id='logo2' src='images/logoy2_800.jpg' alt='Library logo'>");
	}
	else if (dim_schermo == "high") 	/* 1024 x 768 */
	{	document.write("<img id='logo2' src='images/logoy2_1024.jpg' alt='Library logo'>");
	} 
	else  if (dim_schermo == "large")	/* 1280 x 800 oppure 1024 */
	{	document.write("<img id='logo2' src='images/logoy2_1280.jpg' alt='Library logo'>");
	}
	else
	{	document.write("<img id='logo2' src='images/logoy2_1400.jpg' alt='Library logo'>");
	}
    } else
    alert("Error function scrivi_logo_2 in bug_new.js");
	
    return true;
}

/* ****************  ***************** */
	
	
function lo_slogan (lang) {

	if (lang == "it")
		document.write("Biblioteca della Pontificia Università Gregoriana")
	else
	if (lang == "en")
		document.write("Pontifical Gregorian University Library")
	else
		alert("Errore function scrivi_slogan()");
	return true;
}

/* ***********************  ********************** **************************** */
	
/*      --------------------    */
/*	Funzioni di servizio	*/
/*      --------------------    */

function get_browser ()  {
	var result;				/* Può valere: "ie", "n4", "mz", "xx"		*/

	if (document.layers) result = "n4"
	else
		if (document.all)
			result = "ie";
		else
			if (!document.all && document.getElementById)
				result = "mz";
			else
				result = "xx";
	return result;
}

/*	Versione 11/2/2006	*/
/*	low = 800 x 600		*/
/*	high = 1024 x 768	*/
/*	wide = 1280 x 800	*/
/*	large = 1280 x 1024	*/
/*	xl = 1400 x 1050	*/

function get_screen ()  {
	var result;	/* Può valere: "low", "high", "wide" e "large"	*/
	if (window.screen.width <= 801) result = "low";
	else 
	if (window.screen.width <= 1025) result = "high";
	else
	if (window.screen.width <= 1281) result = "large";
	else result = "xl";
	
	return result;
}

/*	**********************************************	*/

/*	Funzione scrivi_div () - Vers. 8/4/2007	*/
	
function scrivi_div (numero, lang) {

	var larghezza_div;
	var nome_immagine;
	var nome_variabile;
	var larghezza_img;
	var altezza;
	var testo_alt;
	
/*	Test variabili in Input	*/

	if (test_div_img(1,numero,lang) == false) return false;
	
/*	Inizio	della funzione	*/

	if (lang == "it")
	{	testo_alt = img_alt[numero][0]; }
	else
	if (lang == "en")
	{	testo_alt = img_alt[numero][1]; }

	nome_immagine = img_data[numero][0];
	
    	if (dim_schermo == "low")  				/* 800 x 600 */
    	{	nome_variabile = "800." + img_data[numero][1];
    		larghezza_img = img_data[numero][2];
    		altezza = img_data[numero][3];
    	}
	else if (dim_schermo == "high") 			/* 1024 x 768 */
    	{	nome_variabile = "1024." + img_data[numero][1];
    		larghezza_img = img_data[numero][4];
    		altezza = img_data[numero][5];
    	}
	else  if (dim_schermo == "large")			/* 1280 x 800 oppure 1024 */
    	{	nome_variabile = "1280." + img_data[numero][1];
    		larghezza_img = img_data[numero][6];
    		altezza = img_data[numero][7];
    	}
    	else							/* 1400 in poi	*/
    	{	nome_variabile = "1400." + img_data[numero][1];
    		larghezza_img = img_data[numero][8];
    		altezza = img_data[numero][9];
    	}
    	
    	larghezza_div = parseInt(larghezza_img) + parseInt(div_data[numero][1]) + "px;";
    	
	nome_immagine = img_directory + nome_immagine + nome_variabile;
	
	document.write("<div style='float:" + div_data[numero][0] + " width:" + larghezza_div + " margin-right:" + div_data[numero][2] + " margin-top:" + div_data[numero][3] + " padding:" + div_data[numero][4] + " margin-left:" + div_data[numero][5] + "'>");

	document.write("<img src='" + nome_immagine + "' width='" + larghezza_img + "' height='" + altezza + "' alt='" + testo_alt + "' title='" + testo_alt + "'></div>");
	
	return true;
}

/*	**********************************************	*/

/*	Funzione scrivi_div_border () - Vers. 3-11-09	*/
	
function scrivi_div_border (numero, lang) {

	var larghezza_div;
	var nome_immagine;
	var nome_variabile;
	var larghezza_img;
	var altezza;
	var testo_alt;
	
/*	Test variabili in Input	*/

	if (test_div_img(1,numero,lang) == false) return false;
	
/*	Inizio	della funzione	*/

	if (lang == "it")
	{	testo_alt = img_alt[numero][0]; }
	else
	if (lang == "en")
	{	testo_alt = img_alt[numero][1]; }

	nome_immagine = img_data[numero][0];
	
    	if (dim_schermo == "low")  				/* 800 x 600 */
    	{	nome_variabile = "800." + img_data[numero][1];
    		larghezza_img = img_data[numero][2];
    		altezza = img_data[numero][3];
    	}
	else if (dim_schermo == "high") 			/* 1024 x 768 */
    	{	nome_variabile = "1024." + img_data[numero][1];
    		larghezza_img = img_data[numero][4];
    		altezza = img_data[numero][5];
    	}
	else  if (dim_schermo == "large")			/* 1280 x 800 oppure 1024 */
    	{	nome_variabile = "1280." + img_data[numero][1];
    		larghezza_img = img_data[numero][6];
    		altezza = img_data[numero][7];
    	}
    	else							/* 1400 in poi	*/
    	{	nome_variabile = "1400." + img_data[numero][1];
    		larghezza_img = img_data[numero][8];
    		altezza = img_data[numero][9];
    	}
    	
    	larghezza_div = parseInt(larghezza_img) + parseInt(div_data[numero][1]) + "px;";
    	
	nome_immagine = img_directory + nome_immagine + nome_variabile;
	
	document.write("<div style='float:" + div_data[numero][0] + " width:" + larghezza_div + " margin-right:" + div_data[numero][2] + " margin-top:" + div_data[numero][3] + " padding:" + div_data[numero][4] + " margin-left:" + div_data[numero][5] + "'>");

	document.write("<img style='border: 1px solid #A70730;' src='" + nome_immagine + "' width='" + larghezza_img + "' height='" + altezza + "' alt='" + testo_alt + "' title='" + testo_alt + "'></div>");
	
	return true;
}

/*	**********************************************	*/

/*	Funzione scrivi_img ()	- Vers. 12/11/2009	*/

function scrivi_img (numero, lang) {

	var nome_immagine;
	var nome_variabile;
	var larghezza_img;
	var altezza;
	var testo_alt;
	var girax;
	
/*	Test variabili in Input	*/

	if (test_div_img(2,numero,lang) == false) return false;
	
/*	Inizio	della funzione	*/

	if (lang == "it")
	{	testo_alt = img_alt[numero][0]; }
	else
	if (lang == "en")
	{	testo_alt = img_alt[numero][1]; }
	
	pos = div_data[numero][0];	
	
	if (pos == "left;") girax = "girasinistra"
	else
	if (pos == "right;") girax = "giradestra"
	else girax= "std";

	nome_immagine = img_data[numero][0];
	
    	if (dim_schermo == "low")  				/* 800 x 600 */
    	{	nome_variabile = "800." + img_data[numero][1];
    		larghezza_img = img_data[numero][2];
    		altezza = img_data[numero][3];
    	}
	else if (dim_schermo == "high") 			/* 1024 x 768 */
    	{	nome_variabile = "1024." + img_data[numero][1];
    		larghezza_img = img_data[numero][4];
    		altezza = img_data[numero][5];
    	}
	else  if (dim_schermo == "large")			/* 1280 x 800 oppure 1024 */
    	{	nome_variabile = "1280." + img_data[numero][1];
    		larghezza_img = img_data[numero][6];
    		altezza = img_data[numero][7];
    	}
    	else							/* 1400 in poi	*/
    	{	nome_variabile = "1400." + img_data[numero][1];
    		larghezza_img = img_data[numero][8];
    		altezza = img_data[numero][9];
    	}
    	
	nome_immagine = img_directory + nome_immagine + nome_variabile;
	
	if (pos == "center;") document.write("<center>");
	
	document.write("<img class='" + girax + "' src='" + nome_immagine + "' width='" + larghezza_img + "' height='" + altezza + "' alt='" + testo_alt + "' title='" + testo_alt + "'>");
	
	if (pos == "center;") document.write("</center>");
	
	return true;
}

/*	********************************************** */

function test_div_img (caller, numero, lang) {

/*	caller = 1: scrivi_div()	*/
/*		 2: scrivi_img()	*/

	var img_max_img;
	var i, j, k, pos;

	if (img_test != 1)
	{	alert("E' stato richiesto l'immagine numero " + numero + ". Tuttavia e' probabile che la riga <script src='bug_immagini.js' type='text/javascript'></script> sia mancante all'inizio della pagina HTML");
		return false;
	}

	img_max_img = img_data.length - 1;

/*	Test variabili in Input	*/

	if (numero < 0)
	{	alert("E' stato richiesto l'immagine numero " + numero + ". Si tratta di un errore perché il numero è inferiore a zero");
		return false;
	}
	else
	if (numero > img_max_img)
	{	alert("E' stato richiesto l'immagine numero " + numero + ". Si tratta di un errore perché il valore non può essere superiore a " + img_max_img);
		return false;
	}
	
	if (lang != "it" && lang != "en")
	{	alert("E' stato richiesto l'immagine numero " + numero + ", ma la lingua richiesta è invalida: " + lang);
		return false;
	}
	
/*	Test congurenza dati	*/

	i = img_data.length;
	j = img_alt.length;
	k = div_data.length;
	
	if (i != j || i != k)
	{	alert("Errore interna. Incoerenza nella dimensione degli array");
		return false;
	}
	
	pos = div_data[numero][0];
	if (pos != "left;" && pos != "right;" && pos != "normal;")
	{	if (caller == 1 && pos == "center;")
		{	alert("Il posiozionamento Center; non è valido con la funzione scrivi_div()");
			return false;
 		}
 	 	if (caller == 2 && pos == "center;") return true;
 	 	else
 		{	alert("E' stato richiesto un posizionamento dell'immagine errato: " + pos);
 			return false;
 		}
 	}

	
	return true;
}

/*	--------------------------	*/
/*	FROM LIBRARY.JS - 01-12-08	*/
/*	--------------------------	*/

function str_vuota (stringa) {
	var i, dim, car;
	dim = stringa.length;
	if (dim <= 0) return true;
	for (i= 0; i<dim; i++)
	{	car = stringa.charAt(i);
		if (car == " ") continue;
		if (car == "\n" || car == "\r" || car == "\t" || car == "\f" || car == "\b") continue;
		return false;
	}
	return true;
}
function str_e_mail (stringa) {
	var dim;
	dim = stringa.length;
	if (dim <= 0) return false;
	l1 = stringa.indexOf("@");
	l2 = stringa.lastIndexOf("@");
	if (l1 != l2) return false;	
	if ((stringa.indexOf("@") == -1) | (stringa.indexOf(".") == -1) | (dim < 6)) return false;
	return true;
}
function str_numeri (stringa) {
	var i, dim, count;
	dim = stringa.length;
	count = 0;
	for (i=0; i<dim; i++)  {
		car = stringa.charAt(i);
		if (car == '0' || car == '1' || car == '2' || car == '3' || car == '4' || car == '5' || car == '6' || car == '7' || car == '8' || car == '9') count++;
	}
	if (count != dim) return false;
	return true;
}
function str_numeri_more (stringa) {
	var i, dim, count;
	dim = stringa.length;
	count = 0;
	for (i=0; i<dim; i++)  {
		car = stringa.charAt(i);
		if (car == '0' || car == '1' || car == '2' || car == '3' || car == '4' || car == '5' || car == '6' || car == '7' || car == '8' || car == '9' || car == '.' || car == ',' || car == '+' || car == '-' || car == ' ') count++;
	}
	if (count != dim) return false;
	return true;
}
function str_numero_telefonico (stringa) {
	var i, dim, count, count_plus, count_par_open, count_par_close;
	dim = stringa.length;
	count = 0;
	count_plus = 0;
	count_par_open = 0;
	count_par_close = 0;
	for (i=0; i<dim; i++)  {
		car = stringa.charAt(i);
		if (car == '0' || car == '1' || car == '2' || car == '3' || car == '4' || car == '5' || car == '6' || car == '7' || car == '8' || car == '9' || car == '(' || car == ')' || car == '+' || car == ' ') count++;
		if (car == '+') count_plus++;
		if (car == '(') count_par_open++;
		if (car == ')') count_par_close++;
	}
	if (count != dim) return false;
	if (count_plus > 1) return false;
	if (count_par_open > 1) return false;
	if (count_par_close > 1) return false;
	if (count_par_open != count_par_close) return false;
	return true;
}
function str_data (stringa) {
	var i, dim, giorno, mese, anno;
	dim = stringa.length;
	if (dim != 10) return 1;
	if (stringa.charAt(2) != "/") return 2;
	if (stringa.charAt(5) != "/") return 3;
	giorno = stringa.substr(0,2);
	if (str_numeri(giorno) != true) return 4;
	if (parseInt(giorno,10) > 31)  return 5;
	mese   = stringa.substr(3,2);
	if (str_numeri(mese) != true) return 6;
	if (parseInt(mese,10) > 12) return 7;
	anno   = stringa.substr(6,4);		
	if (str_numeri(anno) != true) return 8;
	if (parseInt(anno,10) < 1900) return 9;
	data = new Date(anno,mese-1,giorno);
	daa = data.getFullYear().toString();
	dmm = (data.getMonth()+1).toString();
	dmm = dmm.length == 1 ? "0" + dmm : dmm;
	dgg = data.getDate().toString();
	dgg = dgg.length == 1 ? "0" + dgg : dgg;
	data_calcolata = dgg + "/" + dmm + "/" + daa;
	if (data_calcolata != stringa) return 10;
	return 0;
}
function str_replace (stringa_in, car, pos) {
	var dim;
	var stringa_out = "";
	dim = car.length;
	if (dim != 1) { alert("Funz. str_replace() - errore car:" + car); return stringa_out; }
	dim = stringa_in.length;
	if (dim <= 0) return " ";
	if (pos < 0 || pos >= dim) { alert("Funz. str_replace() - errore pos = " + pos); return stringa_out; }
	if (pos == 0) stringa_out = car + stringa_in.substring(1,dim);
	else
	if (pos == dim-1) stringa_out = stringa_in.substring(0,pos) + car;
	else stringa_out = stringa_in.substring(0,pos) + car + stringa_in.substring(pos+1,dim);
	return stringa_out;
}
function str_pulire (stringa_in) {
	var i, dim, first, last;;
	var stringa_inter = "";
	var stringa_out = "";
	dim = stringa_in.length;
	if (dim == 0) return stringa_out;
	last = dim - 1;	
	first = -1;
	for (i=0; i<dim; i++)  
	{	car = stringa_in.charAt(i);
		if (car != " ") { first = i; break; }
	}
	if (first == -1) { return stringa_out; }
	stringa_inter = stringa_in.substring(first,last+1);
	dim = stringa_inter.length;	
	first = -1;
	last = dim - 1;
	for (i=last; i>=0; i--)
	{	car = stringa_inter.charAt(i);
		if (car != " ") { first = i; break; }
	}
	if (first == -1) stringa_out = stringa_inter;
	else stringa_out = stringa_inter.substring(0,first+1);
	return stringa_out;
}
function str_pulire_data (data_in) {
	var dim, car1, car2;
	var data_inter = "";
	var data_out = "";
	dim = data_in.length;
	if (dim != 10) return data_in;
	car1 = data_in.charAt(2);
	car2 = data_in.charAt(5);
	if (car1 == "." || car1 == "-") data_inter = str_replace(data_in, "/",2);
	else data_inter = data_in;
	if (car2 == "." || car2 == "-") data_out = str_replace(data_inter, "/",5);
	else data_out = data_inter;	
	return data_out;
}


