function apriPopup(nome, titolo, lar, alt){
	var popFoto = window.open(nome, titolo, 'width=' + lar + ',height=' + alt + ',toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes');
	popFoto.moveTo(0,0);
	popFoto.focus();
}
function flyer() {
	var popFoto = window.open('/flyer/Flyer_BMW_S1_148x210.jpg', 'flyer', 'width=450,height=610,toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes');
	popFoto.moveTo(0,0);
	popFoto.focus();
}
function offerta() {
	var type = document.getElementById("offertalm").value;
	if (type == undefined || type == 0){
		return;
	}
	scheda("scheda.jsp?filtid=" +type);
}
function offerte() {
	var type = document.getElementById("offertalm").value;
	if (type == undefined || type == 0){
		return;
	}
	scheda("scheda.jsp?filtid=" +type);
}


function scheda(link, type){
	if (type == undefined){
		type = "";
	}
	else{
		document.getElementById("typeric").value = type;
	}
	document.getElementById("formSrcAuto").action = link;
	document.getElementById("formSrcAuto").submit();
}
function indietro(){
	if (document.getElementById("typeric").value != null && 
			document.getElementById("typeric").value.length > 0){
		if (document.getElementById("typeric").value == 0){
			window.location = "index.jsp";
			return;
		}
		if (document.getElementById("typeric").value == 10){
			window.location = "offerte.jsp";
			return;
		}
		if (document.getElementById("typeric").value == 6 || 
				document.getElementById("typeric").value == 2|| 
				document.getElementById("typeric").value == 5){
			window.location = "ricerca1.jsp?ls=" + document.getElementById("typeric").value;
			return;
		}
		else{
			document.getElementById("formSrcAuto").action = "ricerca.jsp?ls=" + document.getElementById("typeric").value;
		}
	}	
	document.getElementById("formSrcAuto").submit();
}
function indietroS(action){
	document.getElementById("formSrcAuto").action = action;
	document.getElementById("formSrcAuto").submit();
}

function deleteRow(link, qStr, filtid) {
	var answer = confirm("Vuoi cancellare la riga?");
	if (answer){
		document.location="/servlet/deleteservlet.do?"+qStr + "&filtid=" + filtid;
	}
}

function showdiv(id) 
{
	//safe function to show an element with a specified id
		  
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = '';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = '';
		}
		else { // IE 4
			document.all.id.style.display = '';
		}
	}
}
function hidediv (id)
{
	//safe function to show an element with a specified id
		  
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'none';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'none';
		}
		else { // IE 4
			document.all.id.style.display = 'none';
		}
	}
}
function expand_or_collapse(nameEl)
{
	if (nameEl == undefined || nameEl == null){
		nameEl = 'box_search';
	}
    if (document.getElementById(nameEl).style.display == 'none')
    {
        showdiv(nameEl);
        document.getElementById('expand_or_collapse').innerHTML = 'Nascondi Box Ricerca'; 
    }
    else
    {
        hidediv(nameEl);
        document.getElementById('expand_or_collapse').innerHTML = 'Visualizza Box Ricerca'; 
    }
}
function show_hide(nameEl)
{
	if (nameEl != undefined || nameEl != null){
	    if (document.getElementById(nameEl).style.display == 'none')
	    {
	        showdiv(nameEl);
	    }
	    else
	    {
	        hidediv(nameEl);
	    }
	}
}

function popfoto(popFoto, str) {
	if (!popFoto.closed && popFoto.location) {
		popFoto = '';
	}
	popFoto = window.open('','foto','scrollbars=no,resizable=yes,width=550,height=412,status=no,location=no,toolbar=no');
	popFoto.document.open();
	popFoto.document.write('<html><head><title>Malvestiti Group</title></head><body><center>');  
	popFoto.document.write('<img src=' + str + '?h=375&w=500 border="0"/>');
	popFoto.document.write('</center></body></html>');  
	popFoto.document.close();
	popFoto.moveTo(0,0);
	popFoto.focus();
}

function populateList(idSel, queryString) {
	var getString = ritornaTesto("/servlet/comboservlet.do?"
			+ queryString);
	clearList(idSel);
	var ary = eval(getString);
	var element = document.getElementById(idSel);
	for (i = 0; i < ary.length; i++) {
		element[element.length] = new Option(ary[i][1], ary[i][0]);
	}
	return;
}

function populateListByObject(queryString, idObj, idSel) {
	clearList(idSel);
	caricaTesto(queryString + "&idSel="+idSel, idObj);
}

function populateListAsync(idSel, aryValue, optionVoid) {
	var startLoop = 0;
	if (optionVoid == undefined){
		optionVoid = false;
	}
	else{
		startLoop = 1;
	}
	clearList(idSel);
	var ary = eval(aryValue);
	var element = document.getElementById(idSel);
	if (optionVoid == true){
		element[0] = new Option("", "");
	}
	for (i = startLoop; i < (ary.length+startLoop); i++) {
		element[element.length] = new Option(ary[i - startLoop][1], ary[i - startLoop][0]);
	}
	return;
}
function clearList(idSel) {
	var element = document.getElementById(idSel);
	var lengthElement = element.length - 1;
	for (i = lengthElement; i >= 0; i--) {
		element[i] = null;
	}

}

function clearTable(idSel) {
	var element = document.getElementById(idSel);
	while (element.rows.length > 0) { // deletes all rows of a table
		element.deleteRow(0);
	}

}
function orderBy(i, idForm){
	if (idForm == undefined){
		idForm = "formSrcAuto";
	}
	if (document.getElementById("ord").value==i){
		document.getElementById("ord").value=i + " desc";
	}
	else{
		document.getElementById("ord").value=i;
	}
	document.getElementById(idForm).submit();
}
function orderByFront(i, idForm){
	if (idForm == undefined){
		idForm = "formSrcAuto";
	}
	if (document.getElementById("ord").value==i){
		document.getElementById("ord").value=i + " desc";
	}
	else{
		document.getElementById("ord").value=i;
	}
	document.getElementById(idForm).submit();
}
function orderByFront1(i, ls,  idForm){
	if (ls == undefined){
		ls = "0";
	}
	if (idForm == undefined){
		idForm = "formSrcAuto";
	}
	if (document.getElementById("ord").value==i){
		document.getElementById("ord").value=i + " desc";
	}
	else{
		document.getElementById("ord").value=i;
	}
	document.getElementById(idForm).action = "ricerca1.jsp?ls=" + ls;
	document.getElementById(idForm).submit();
}
function pageSel(i, idForm){
	if (idForm == undefined){
		idForm = "formSrcAuto";
	}
	document.getElementById("pg").value=i;
	document.getElementById(idForm).submit();
}
function pageSel1(i, ls, idForm){
	if (idForm == undefined){
		idForm = "formSrcAuto";
	}
	document.getElementById(idForm).action = "ricerca1.jsp?ls=" + ls;
	document.getElementById("pg1").value=i;
	document.getElementById(idForm).submit();
}

function populateTabellaAuto(startPage, rowPage, header, righe, qStr, dettTabellaType) {
//	alert(qStr);
	if (dettTabellaType == undefined ) {
		dettTabellaType = "";
	}

	var numbColumnsTable = 8;
	clearTable('myTable');
	var i = 0;
	var x = document.getElementById('myTable').insertRow(0);
	x.className="row_light";
	for (i = 0; i < numbColumnsTable; i++) {
		x.insertCell(i).innerHTML = "<a href=\"#myTable\" onclick=\"orderBy("+(i+1)+")\">" +header[i] +"</a>";
	}
	var colSpan = i;
	var link = "dettaglio"+dettTabellaType+".jsp";
	if (righe != null && righe.length > 0) {

		if (startPage == undefined || startPage < 0) {
			startPage = 0;
		}
		if (rowPage == undefined || rowPage < 0) {
			rowPage = 0;
		}
		var posStart = 0;
		var posEnd = righe.length;
		var pages = posEnd / rowPage;
		var modulo = posEnd % rowPage;
		if (modulo > 0 && pages > 1) {
			pages = pages + 1;
		}
		var startLoop = posStart + (rowPage * (startPage - 1));
		var endLoop = startLoop + rowPage;
		if (rowPage == 0) {
			endLoop = posEnd;
		}
		if (startLoop < 0) {
			startLoop = 0;
			endLoop = startLoop + rowPage;
		}
		if (endLoop > posEnd) {
			endLoop = posEnd;
		}
		var ii = 0;
		var row_class = "row_dark";
		var brow = true;
		// navigazione
//		alert(pages);
		if (pages > 1) {
			x = document.getElementById('myTable').insertRow(0).insertCell(0);
			x.colSpan = colSpan;
			var linkPages = "pagina ";
			for (i = 1; i <= pages; i++) {
				linkPages += "<a href=\"#\" onclick=\"populateTabellaAuto(" + i
						+ ", 100, header, righe, '"+qStr+"&pg="+i+"' );\">" + i + "</a>&nbsp;";
			}
			x.innerHTML = linkPages;
		}
		// popola tabella
		
		for (i = startLoop; i < endLoop; i++) {
			pos = document.getElementById('myTable').rows.length;
			x = document.getElementById('myTable').insertRow(pos);
			if (brow) {
				row_class = "row_dark"
				brow = !brow;
			} else {
				row_class = "row_light"
				brow = !brow;
			}
			link = "index.jsp";
			if (qStr.indexOf("act=0") >= 0){
				link = "dettaglio"+dettTabellaType+".jsp"
			}
			var isFirst = true;
			x.className = row_class;
			var cellInserted;
			for (ii = 0; ii < numbColumnsTable; ii++) {
				cellInserted = x.insertCell(ii);
				if (isFirst){
//					cellInserted.innerHTML =  "<a href=\""+link+"?"+qStr+"&filtid="+righe[i][ii]+"\">"+righe[i][ii]+"</a>";
					cellInserted.innerHTML =  "<a href=\"#\" onclick=\"javascript:document.getElementById('formSrcAuto').action='"+link+"?"+qStr+"&filtid="+righe[i][ii]+"';document.getElementById('formSrcAuto').submit();\">"+righe[i][ii]+"</a>";
					isFirst = false;
					
				}
				else{
					cellInserted.innerHTML = righe[i][ii];
					if (ii == 5){
						cellInserted.className = "cell_disp" + righe[i][numbColumnsTable];
					}
					if (ii == 7){
//						alert(righe[i][ii]);
						if (righe[i][ii] <= 90){
							cellInserted.className = "cell_disp1";
						} 
						else if (righe[i][ii] > 90 && righe[i][ii] <= 150 ){
							cellInserted.className = "cell_disp2";
						}
						else {
							cellInserted.className = "cell_disp3";
						} 
					}
				}
			}
		}
	}
	// tasto nuovo
	x = document.getElementById('myTable').insertRow(0).insertCell(0);
	x.colSpan = colSpan;
	linkPages = "<input type=\"button\" value=\"Nuovo\" class=\"btn\" onclick=\"javascript:document.location='"+link+"?"+qStr+"&filtid=0'\"/>";
	x.innerHTML = linkPages;
	//
}
function populateTabellaAutoNM(startPage, rowPage, header, righe, qStr) {
//	alert(qStr);
	var numbColumnsTable = 19;
	clearTable('myTable');
	var i = 0;
	var x = document.getElementById('myTable').insertRow(0);
	x.className="row_headernm";
	x.insertCell(0).innerHTML = "&nbsp;";

	for (i = 1; i <= numbColumnsTable; i++) {
		x.insertCell(i).innerHTML = "<a href=\"#myTable\" onclick=\"orderBy("+(i)+")\">" +header[i-1] +"</a>";
	}
	var colSpan = i;
	var link = "dettaglionm.jsp";
	if (righe != null && righe.length > 0) {

		if (startPage == undefined || startPage < 0) {
			startPage = 0;
		}
		if (rowPage == undefined || rowPage < 0) {
			rowPage = 0;
		}
		var posStart = 0;
		var posEnd = righe.length;
		var pages = posEnd / rowPage;
		var modulo = posEnd % rowPage;
		if (modulo > 0 && pages > 1) {
			pages = pages + 1;
		}
		var startLoop = posStart + (rowPage * (startPage - 1));
		var endLoop = startLoop + rowPage;
		if (rowPage == 0) {
			endLoop = posEnd;
		}
		if (startLoop < 0) {
			startLoop = 0;
			endLoop = startLoop + rowPage;
		}
		if (endLoop > posEnd) {
			endLoop = posEnd;
		}
		var ii = 0;
		var row_class = "row_darknm";
		var brow = true;
		// navigazione
//		alert(pages);
		if (pages > 1) {
			x = document.getElementById('myTable').insertRow(0).insertCell(0);
			x.colSpan = colSpan;
			var linkPages = "pagina ";
			for (i = 1; i <= pages; i++) {
				linkPages += "<a href=\"#\" onclick=\"populateTabellaAuto(" + i
						+ ", 100, header, righe, '"+qStr+"&pg="+i+"' );\">" + i + "</a>&nbsp;";
			}
			x.innerHTML = linkPages;
		}
		// popola tabella

		for (i = startLoop; i < endLoop; i++) {
			pos = document.getElementById('myTable').rows.length;
			x = document.getElementById('myTable').insertRow(pos);
			if (brow) {
				row_class = "row_darknm"
				brow = !brow;
			} else {
				row_class = "row_lightnm"
				brow = !brow;
			}
			link = "index.jsp";
			if (qStr.indexOf("act=0") >= 0){
				link = "dettaglionm.jsp"
			}
			var isFirst = true;
			x.className = row_class;
			var cellInserted;
			cellInserted = x.insertCell(0);

//				alert(righe[i][ii]);

			if (righe[i][numbColumnsTable-3] <= 90){
				cellInserted.className = "cell_disp1";
			} 
			else if (righe[i][numbColumnsTable-3] > 90 && righe[i][numbColumnsTable-3] <= 150 ){
				cellInserted.className = "cell_disp2";
			}
			else {
				cellInserted.className = "cell_disp3";
			} 
			for (ii = 1; ii <= numbColumnsTable; ii++) {
				cellInserted = x.insertCell(ii);
				if (isFirst){
					cellInserted.innerHTML =  "<a href=\""+link+"?"+qStr+"&filtid="+righe[i][ii-1]+"\">"+righe[i][ii-1]+"</a>";
					isFirst = false;
					
				}
				else{
					cellInserted.innerHTML = righe[i][ii-1];
				}
				if (ii == 8){
					cellInserted.title = righe[i][numbColumnsTable];
					cellInserted.align = "right";
				}
				if (ii == 13 || ii == 14 || ii == 15 || ii == 17 || ii == 18 || ii == 19){
					cellInserted.align = "right";
				}
				if (ii == numbColumnsTable-2){
					if (righe[i][numbColumnsTable-3] <= 90){
						cellInserted.className = "cell_disp1";
					} 
					else if (righe[i][numbColumnsTable-3] > 90 && righe[i][numbColumnsTable-3] <= 150 ){
						cellInserted.className = "cell_disp2";
					}
					else {
						cellInserted.className = "cell_disp3";
					} 
				}
				
			}
//			join();
		}
	}
	// tasto nuovo
	x = document.getElementById('myTable').insertRow(0).insertCell(0);
	x.colSpan = colSpan;
	linkPages = "<input type=\"button\" value=\"Nuovo\" class=\"btn\" onclick=\"javascript:document.location='"+link+"?"+qStr+"&filtid=0'\"/>";
	x.innerHTML = linkPages;
	x.className="row_darknm";

	//
}
function populateTabellaPre( startPage, rowPage, header, righe, qStr, viewButtonNew, exportxls, mod, xlsPath ) {
//	alert(qStr);
	if (viewButtonNew == undefined){
		viewButtonNew = true;
	}
	var testoBottone = "";
	var modifica = true;
	if ( mod != undefined )
	{
		modifica = mod;
	}
	clearTable('myTable');
	var i = 0;
	var x = document.getElementById('myTable').insertRow(0);
	x.className="row_light";
	// colonna delete
	x.insertCell(i)
	//
	for (i = 0; i < header.length; i++) {
		x.insertCell(i+1).innerHTML = "<a href=\"#\" onclick=\"orderBy("+(i+1)+")\">" +header[i] +"</a>";
	}
	var colSpan = i + 1;
	var link = "index.jsp";
	if (qStr.indexOf("act=0") >= 0){
		link = "dettaglio.jsp";
	}
	else if (qStr.indexOf("act=15") >= 0)
	{
		link = "contatti.jsp";
	}
	else if (qStr.indexOf("act=16") >= 0)
	{
		link = "newsletter.jsp";
	}	
	if (righe != null && righe.length > 0) {

		if (startPage == undefined || startPage < 0) {
			startPage = 0;
		}
		if (rowPage == undefined || rowPage < 0) {
			rowPage = 0;
		}
		var posStart = 0;
		var posEnd = righe.length;
		var pages = posEnd / rowPage;
		var modulo = posEnd % rowPage;
		if (modulo > 0 && pages > 1) {
			pages = pages + 1;
		}
		var startLoop = posStart + (rowPage * (startPage - 1));
		var endLoop = startLoop + rowPage;
		if (rowPage == 0) {
			endLoop = posEnd;
		}
		if (startLoop < 0) {
			startLoop = 0;
			endLoop = startLoop + rowPage;
		}
		if (endLoop > posEnd) {
			endLoop = posEnd;
		}
		var ii = 0;
		var row_class = "row_dark";
		var brow = true;
		// navigazione
//		alert(pages);
		if (pages > 1) {
			x = document.getElementById('myTable').insertRow(0).insertCell(0);
			x.colSpan = colSpan;
			var linkPages = "pagina ";
			for (i = 1; i <= pages; i++) {
				linkPages += "<a href=\"#\" onclick=\"populateTabellaPre(" + i
						+ ", 100, header, righe, '"+qStr+"&pg="+i+"', viewButtonNew );\">" + i + "</a>&nbsp;";
			}
			x.innerHTML = linkPages;
		}
		// popola tabella
		for (i = startLoop; i < endLoop; i++) {
			pos = document.getElementById('myTable').rows.length;
			x = document.getElementById('myTable').insertRow(pos);
			if (brow) {
				row_class = "row_dark"
				brow = !brow;
			} else {
				row_class = "row_light"
				brow = !brow;
			}
			var isFirst = true;
			x.className = row_class;
			// colonna tasto delete
			//alert(link);
			//alert(qStr);
			//alert(righe[i][0]);
			x.insertCell(0).innerHTML = "<a href=\"#\" onclick=\"javascript:deleteRow('"+link+"','"+qStr+"', "+righe[i][0]+");\"><img src=\"../img/cestino.gif\" border=\"0\"/></a>";
			//
			for (ii = 0; ii < righe[i].length; ii++) {
				if (isFirst)
				{
					if ( modifica )
					{
						x.insertCell(ii + 1).innerHTML =  "<a href=\""+link+"?"+qStr+"&filtid="+righe[i][ii]+"\">"+righe[i][ii]+"</a>";
					}
					else
					{
						x.insertCell(ii + 1).innerHTML =  righe[i][ii];
					}
					
					isFirst = false;
				}
				else{
					x.insertCell(ii + 1).innerHTML = righe[i][ii];
				}
			}
		}
		// BOTTONE INSERIMENTO NUOVO ELEMENTO

	}
	if (viewButtonNew){
		x = document.getElementById('myTable').insertRow(0).insertCell(0);
		x.colSpan = colSpan;
		var linkPages = "";
		if ( exportxls != undefined )
		{
			//linkPages = "<a href=\"" + xlsPath + "\">Export excel</a>";
			linkPages = "<a href=\"/servlet/generaxls.do?xls=" + xlsPath +"\">Export excel</a>";
		}
		else
		{
			linkPages = "<input type=\"button\" value=\"Nuovo\" class=\"btn\" onclick=\"javascript:document.location='"+link+"?"+qStr+"&filtid=0'\"/>";
		}
		
		x.innerHTML = linkPages;
		x.className="row_light";
	}

}

function populateTabella(url, startPage, rowPage, act) {

	var header = "";
	var sleep = 0;
	while ((header == null || header.length == 0) && sleep < 1000) {
		sleep = sleep + 1;
		header = eval(ritornaTesto(url + "MetaData"));
	}
	var righe = "";
	sleep = 0;
	while ((righe == null || righe.length == 0) && sleep < 1000) {
		sleep = sleep + 1;
		righe = eval(ritornaTesto(url));
	}

	var i = 0;
	var x = document.getElementById('myTable').insertRow(0);
	x.className = "row_header";
	for (i = 0; i < header.length; i++) {
		x.insertCell(i).innerHTML = header[i];
	}
	if (startPage == undefined || startPage < 0) {
		startPage = 0;
	}
	if (rowPage == undefined || rowPage < 0) {
		rowPage = 0;
	}
	var posStart = 0;
	var posEnd = righe.length;
	var startLoop = posStart + (rowPage * (startPage - 1));
	var endLoop = startLoop + rowPage;
	if (rowPage == 0) {
		endLoop = posEnd;
	}
	if (startLoop < 0) {
		startLoop = 0;
		endLoop = startLoop + rowPage;
	}
	if (endLoop > posEnd) {
		endLoop = posEnd;
	}
	var ii = 0;
	var row_class = "row_dark";
	var brow = true;

	for (i = startLoop; i < endLoop; i++) {
		pos = document.getElementById('myTable').rows.length;
		x = document.getElementById('myTable').insertRow(pos);
		if (brow) {
			row_class = "row_dark"
			brow = !brow;
		} else {
			row_class = "row_light"
			brow = !brow;
		}
		alert("1");
		var isFirst = true;
		x.className = row_class;
		for (ii = 0; ii < righe[i].length; ii++) {
			if (isFirst){
				x.insertCell(ii).innerHTML =  "<a href=\"index.jsp?act="+act+"&filtid="+righe[i][ii]+"\">"+righe[i][ii]+"</a>";
				isFirst = false;
			}
			else{
				x.insertCell(ii).innerHTML = righe[i][ii];
			}
		}
	}
}

function caricaTesto(nomeFile, nome_elemento) {
	// variabili di funzione

	// assegnazione oggetto XMLHttpRequest
	var ajax = assegnaXMLHttpRequest();
	// assegnazione elemento del documento
	var elemento = prendiElementoDaId(nome_elemento);

	// ale: senza il controllo errori a valanga lato js soprattutto su ie
	// perchÃ¨ trova elemento non valorizzato
	if (elemento == null) {
		return;
	}
	// risultato booleano di funzione
	var usaLink = true;

	// se l'oggetto XMLHttpRequest non ï¿½ nullo
	if (ajax) {
		// il link al file non deve essere usato
		usaLink = false;

		// impostazione richiesta asincrona in GET
		// del file specificato
		ajax.open("get", nomeFile, true);

		// rimozione dell'header "connection" come "keep alive"
		ajax.setRequestHeader("connection", "close");

		// impostazione controllo e stato della richiesta
		ajax.onreadystatechange = function() {
			// alert("1");
			// verifica dello stato
			if (ajax.readyState === readyState.COMPLETATO) {
				// verifica della risposta da parte del server
				if (statusText[ajax.status] === "OK") {
					// alert(nome_elemento);
					// operazione avvenuta con successo
					var vtxt = ajax.responseText;
//					alert(vtxt);
//					alert(elemento.value);
					elemento.innerHTML = vtxt;
				} else {
					// errore di caricamento
					elemento.innerHTML = "Impossibile effettuare l'operazione richiesta.<br />";
					elemento.innerHTML += "Errore riscontrato: "
							+ statusText[ajax.status];
				}
			}
		};

		// invio richiesta
		ajax.send(null);
	}
	return usaLink;
}
function caricaTestoValue(nomeFile, nome_elemento) {
	// variabili di funzione

	// assegnazione oggetto XMLHttpRequest
	var ajax = assegnaXMLHttpRequest();
	// assegnazione elemento del documento
	var elemento = prendiElementoDaId(nome_elemento);
	// ale: senza il controllo errori a valanga lato js soprattutto su ie
	// perchÃ¨ trova elemento non valorizzato
	if (elemento == null) {
		return;
	}
	// risultato booleano di funzione
	var usaLink = true;

	// se l'oggetto XMLHttpRequest non ï¿½ nullo
	if (ajax) {
		// il link al file non deve essere usato
		usaLink = false;

		// impostazione richiesta asincrona in GET
		// del file specificato
		ajax.open("get", nomeFile, true);

		// rimozione dell'header "connection" come "keep alive"
		ajax.setRequestHeader("connection", "close");

		// impostazione controllo e stato della richiesta
		ajax.onreadystatechange = function() {
			// alert("1");
			// verifica dello stato
			if (ajax.readyState === readyState.COMPLETATO) {
				// verifica della risposta da parte del server
				if (statusText[ajax.status] === "OK") {
					// alert(nome_elemento);
					// operazione avvenuta con successo
					
					var vtxt = ajax.responseText;
					elemento.value = vtxt;
				} else {
					// errore di caricamento
					elemento.value = "Impossibile effettuare l'operazione richiesta.<br />";
					elemento.value += "Errore riscontrato: "
							+ statusText[ajax.status];
				}
			}
		};

		// invio richiesta
		ajax.send(null);
	}
	return usaLink;
}

function ritornaTesto(nomeFile) {
	// variabili di funzione

	// assegnazione oggetto XMLHttpRequest
	var ajax = assegnaXMLHttpRequest();
	// inizializzazione variabile del testo
	var vText = "";

	// se l'oggetto XMLHttpRequest non ï¿½ nullo
	if (ajax) {

		// impostazione richiesta asincrona in GET
		// del file specificato
		ajax.open("get", nomeFile, true);

		// rimozione dell'header "connection" come "keep alive"
		ajax.setRequestHeader("connection", "close");

		// impostazione controllo e stato della richiesta
		ajax.onreadystatechange = function() {
			// alert("1");
			// verifica dello stato
//			alert(ajax.readyState + " :: " + readyState.COMPLETATO);
			if (ajax.readyState === readyState.COMPLETATO) {
				// verifica della risposta da parte del server
				if (statusText[ajax.status] === "OK") {
					// alert(nome_elemento);
					// operazione avvenuta con successo
					vText = ajax.responseText;
//					alert(vText);
				} else {
					// errore di caricamento
					vText = "Impossibile effettuare l'operazione richiesta.<br />";
//					alert(vText + "::" + ajax.readyState);
					// vText += "Errore riscontrato: " +
					// statusText[ajax.status];
				}
			}
		};

		// invio richiesta
		ajax.send(null);
	}
	return vText;
}
function ritornaTestoExec(nomeFile, async){

	  // variabili di funzione
	  var
	    // assegnazione oggetto XMLHttpRequest
	    ajax = assegnaXMLHttpRequest();
	    // assegnazione elemento del documento
		var vText = "";
	    // risultato booleano di funzione
	    usaLink = true;
	  
	  // se l'oggetto XMLHttpRequest non è nullo
	  if(ajax) {
	    // il link al file non deve essere usato
	    usaLink = false;

	    // impostazione richiesta asincrona in GET
	    // del file specificato
	    ajax.open("get", nomeFile, async);

	    // rimozione dell'header "connection" come "keep alive"
	    ajax.setRequestHeader("connection", "close");

	    // impostazione controllo e stato della richiesta
	    ajax.onreadystatechange = function() {
	      
	      // verifica dello stato
	      if(ajax.readyState === readyState.COMPLETATO) {
	        // verifica della risposta da parte del server
	        if(statusText[ajax.status] === "OK")
	          // operazione avvenuta con successo
	        	vText = ajax.responseText;
	        else {
	          // errore di caricamento
	        	vText = "Impossibile effettuare l'operazione richiesta.<br />";
	        	vText += "Errore riscontrato: " + statusText[ajax.status];
	        }
	      } 
	    }

	    // invio richiesta
	    ajax.send(null);
	  }
	   
	  return vText;
	}

/*
function ritornaTestoExec(nomeFile, async) {
	// variabili di funzione

	// assegnazione oggetto XMLHttpRequest
	var ajax = assegnaXMLHttpRequest();
	// inizializzazione variabile del testo
	var vText = "";

	// se l'oggetto XMLHttpRequest non ï¿½ nullo
	if (ajax) {

		// impostazione richiesta asincrona in GET
		// del file specificato
		alert(async + ":" + "http://localhost:8080" + nomeFile);
		ajax.open("get", "http://localhost:8080" +nomeFile, true);


		// rimozione dell'header "connection" come "keep alive"
		ajax.setRequestHeader("connection", "close");

		// impostazione controllo e stato della richiesta
		ajax.onreadystatechange = function() {
			// verifica dello stato
//			alert(ajax.readyState + " :: " + readyState.COMPLETATO);
			if (ajax.readyState === readyState.COMPLETATO) {
				// verifica della risposta da parte del server
				if (statusText[ajax.status] === "OK") {
					// alert(nome_elemento);
					// operazione avvenuta con successo
					vText = ajax.responseText;
//					alert(vText);
				} else {
					// errore di caricamento
					vText = "Impossibile effettuare l'operazione richiesta.<br />";
//					alert(vText + "::" + ajax.readyState);
					// vText += "Errore riscontrato: " +
					// statusText[ajax.status];
				}
			}
		};

		// invio richiesta
		ajax.send(null);
	}
	return vText;
}
*/
function listDocChildsElements() {
	var elemento;
	var allDocs;
	var docnodes = document.getElementsByTagName("label");
	for (i = 0; i < docnodes.length; i++) {
		if (docnodes[i].id.indexOf("@@") >= 0) {
			// alert("servlet/propertiesManager.do?valProp=" + docnodes[i].id);
			caricaTesto("servlet/propertiesManager.do?valProp="
					+ docnodes[i].id, docnodes[i].id);
		}
	}
	docnodes = document.getElementsByTagName("a");
	for (i = 0; i < docnodes.length; i++) {
		if (docnodes[i].id.indexOf("@@") >= 0) {
			// alert(docnodes[i].firstChild.nodeName);
			docnodes[i].firstChild.nodeValue = ritornaTesto("servlet/propertiesManager.do?valProp="
					+ docnodes[i].id);
		}
	}
}

/** (C) HTML.IT - insieme di funzioni ed oggetti utili per interagire con ajax */
/** FUNZIONI */

// funzione per prendere un elemento con id univoco
function prendiElementoDaId(id_elemento) {
	var elemento;
	if (document.getElementById) {
		elemento = document.getElementById(id_elemento);
	} else {
		elemento = document.all[id_elemento];
	}
	// document.getElementsByName()
	return elemento;
}

// funzione per assegnare un oggetto XMLHttpRequest
function assegnaXMLHttpRequest() {
	var XHR = null, browserUtente = navigator.userAgent.toUpperCase();
	if (typeof (XMLHttpRequest) === "function"
			|| typeof (XMLHttpRequest) === "object") {
		XHR = new XMLHttpRequest();
	} else {
		if (window.ActiveXObject && browserUtente.indexOf("MSIE 4") < 0) {
			if (browserUtente.indexOf("MSIE 5") < 0) {
				XHR = new ActiveXObject("Msxml2.XMLHTTP");
			} else {
				XHR = new ActiveXObject("Microsoft.XMLHTTP");
			}
		}
	}
	return XHR;
}

function loseCredential(action) {
	if (action == "lostPassword") {
		window.location = "loseCredential.jsp?act=lostPassword";
	} else {
		if (action == "lostUsername") {
			window.location = "loseCredential.jsp?act=lostUsername";
		}
	}
}

/** OGGETTI / ARRAY */

// oggetto di verifica stato
var readyState = {
	INATTIVO :0,
	INIZIALIZZATO :1,
	RICHIESTA :2,
	RISPOSTA :3,
	COMPLETATO :4
};

// array descrittivo dei codici restituiti dal server
// [la scelta dell' array ï¿½ per evitare problemi con vecchi browsers]
var statusText = new Array();
statusText[100] = "Continue";
statusText[101] = "Switching Protocols";
statusText[200] = "OK";
statusText[201] = "Created";
statusText[202] = "Accepted";
statusText[203] = "Non-Authoritative Information";
statusText[204] = "No Content";
statusText[205] = "Reset Content";
statusText[206] = "Partial Content";
statusText[300] = "Multiple Choices";
statusText[301] = "Moved Permanently";
statusText[302] = "Found";
statusText[303] = "See Other";
statusText[304] = "Not Modified";
statusText[305] = "Use Proxy";
statusText[306] = "(unused, but reserved)";
statusText[307] = "Temporary Redirect";
statusText[400] = "Bad Request";
statusText[401] = "Unauthorized";
statusText[402] = "Payment Required";
statusText[403] = "Forbidden";
statusText[404] = "Not Found";
statusText[405] = "Method Not Allowed";
statusText[406] = "Not Acceptable";
statusText[407] = "Proxy Authentication Required";
statusText[408] = "Request Timeout";
statusText[409] = "Conflict";
statusText[410] = "Gone";
statusText[411] = "Length Required";
statusText[412] = "Precondition Failed";
statusText[413] = "Request Entity Too Large";
statusText[414] = "Request-URI Too Long";
statusText[415] = "Unsupported Media Type";
statusText[416] = "Requested Range Not Satisfiable";
statusText[417] = "Expectation Failed";
statusText[500] = "Internal Server Error";
statusText[501] = "Not Implemented";
statusText[502] = "Bad Gateway";
statusText[503] = "Service Unavailable";
statusText[504] = "Gateway Timeout";
statusText[505] = "HTTP Version Not Supported";
statusText[509] = "Bandwidth Limit Exceeded";

function isValidEmail(nameField) {
	var result = true;
	var el = document.getElementById(nameField);
	if (el.value.length) {
		for ( var i = 0; i < el.value.length; i++) {
			if (symbols.indexOf(el.value.charAt(i)) == -1) {
				result = false;
				break;
			}
		}
		if (el.value.indexOf("@") < 0) {
			result = false;
		}
		if (el.value.indexOf(".") < 0) {
			result = false;
		}
		var s = el.value.substring(el.value.indexOf("@"), el.value.length);
		if (s.indexOf(".") < 0) {
			result = false;
		}
		var j = 0;
		for ( var i = 0; i < el.value.length; i++) {
			if ("@".indexOf(el.value.charAt(i)) >= 0) {
				if (j++ > 1) {
					break;
				}
			}
		}
		if (j > 1) {
			result = false;
		}
		var isSign = true;
		for ( var i = 0; i < el.value.length; i++) {
			if (".@".indexOf(el.value.charAt(i)) > -1) {
				if (isSign) {
					break;
				} else {
					isSign = true;
				}
			} else {
				isSign = false;
			}
		}
		if (isSign) {
			result = false;
		}
	}
	if (result == false) {
		el.className = "inp_err";
	}
	if (result == false) {
		errmsg += "Invalid Email format\n";
	}
	// document.all.EMailErr.innerText = (err.length ? err : "");
	return result;
}

function leftTrim(sString) {
	while (sString.substring(0,1) == ' ') {
		sString = sString.substring(1, sString.length);
	}
	return sString;
}


function rightTrim(sString) {
	while (sString.substring(sString.length-1, sString.length) == ' ') {
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}

function Trim(sString)  {
	while (sString.substring(0,1) == ' '){
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' '){
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}