/*-----------------------------------------------*/
/*------------ INIZIALIZZO OGGETTO --------------*/
/*-----------------------------------------------*/

var xmlHttp;

function createXMLHttpRequest(){

	if (window.XMLHttpRequest) {
	   xmlHttp = new XMLHttpRequest();
	} else if (window.ActiveXObject) { // IE
	   xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
	   alert('Impossibile continuare: il tuo browser non supporta XMLHttpRequest');
	}

}
/*-----------------------------------------------*/
/*-----------------------------------------------*/
/*-----------------------------------------------*/












/*-----------------------------------------------*/
/*------------ CARICAMENTO MENU -----------------*/
/*-----------------------------------------------*/

function CaricaMenu(Id_Pagina,Lang,UrlPagina,TitoloPaginaNew){

		createXMLHttpRequest();

		document.title = TitoloPaginaNew;
		document.getElementById("id_pagina_controllo").value = Id_Pagina;
		document.getElementById("Lingua").value = Lang;

		xmlHttp.onreadystatechange = handleStateChangeMenu;
		xmlHttp.open("GET", "menu.asp"+UrlPagina, true);
		xmlHttp.send(null);
		
}

function handleStateChangeMenu(){

Messaggio = "";
Messaggio = Messaggio + "<table border='0' cellpadding='0' cellspacing='0' style='width:100%; FONT-SIZE: 11px;COLOR: #000000; FONT-FAMILY: Trebuchet MS, Verdana;'>"
Messaggio = Messaggio + "  <tr><td>"
Messaggio = Messaggio + "<center>Impossibile caricare il menu di navigazione ....</center>"
Messaggio = Messaggio + "  </td></tr>"
Messaggio = Messaggio + "</table>"

		if (xmlHttp.readyState==4){

			if (xmlHttp.status == 200){
				document.getElementById("Menu_Lang").innerHTML = xmlHttp.responseText;

				//---------------------------------------------------------------
				// --- QUANDO FINISCO DI CARICARE IL MENU ALLORA CARICO LA PAGINA
				//---------------------------------------------------------------
				Id_Pagina = document.getElementById("id_pagina_controllo").value;
				UrlPagina = "?id_pagina="+document.getElementById("id_pagina_controllo").value+"&Lang="+document.getElementById("Lingua").value+"&id_email="+document.getElementById("id_email").value;
				TitoloPaginaNew = document.title;
				Lang = document.getElementById("Lingua").value;
				
				CaricaPagina(Id_Pagina,Lang,UrlPagina,TitoloPaginaNew);
				//---------------------------------------------------------------
				//---------------------------------------------------------------
				//---------------------------------------------------------------

			}else{

				// INTERCETTO ERRORE E VISUALIZZO
				handleErrFullPage(xmlHttp.responseText);
				//-------------------------------
				
				document.getElementById("Menu_Lang").innerHTML = Messaggio;
			}
		
		}else{
			document.getElementById("Menu_Lang").innerHTML = "<center><img src='BANNER/loading_2.gif'></center>"
		}


}
/*-----------------------------------------------*/
/*-----------------------------------------------*/
/*-----------------------------------------------*/



















/*-----------------------------------------------*/
/*------------ CARICAMENTO PAGINA ---------------*/
/*-----------------------------------------------*/

function CaricaPagina(Id_Pagina,Lang,UrlPagina,TitoloPaginaNew){

		createXMLHttpRequest();
		
		document.title = TitoloPaginaNew;
		document.getElementById("id_pagina_controllo").value = Id_Pagina;
		document.getElementById("Lingua").value = Lang;

		xmlHttp.onreadystatechange = handleStateChange;
		xmlHttp.open("GET", "content.asp"+UrlPagina, true);
		xmlHttp.send(null);
		
}

function handleStateChange(){

Messaggio = "";
Messaggio = Messaggio + "<table border='0' cellpadding='0' cellspacing='0' style='width:100%; height:100%; FONT-SIZE: 11px;COLOR: #000000; FONT-FAMILY: Trebuchet MS, Verdana;'>"
Messaggio = Messaggio + "  <tr><td  style='padding-top:25px;'>"
Messaggio = Messaggio + "<center>Impossibile caricare la pagina richiesta ....</center>"
Messaggio = Messaggio + "  </td></tr>"
Messaggio = Messaggio + "</table>"


		// if xmlHttp shows "loaded"
		if (xmlHttp.readyState == 4){

			if (xmlHttp.status == 200){				
				document.getElementById("Contenuto_Pagina").innerHTML = xmlHttp.responseText;

				//---------------------------------------------------------------
				// --- QUANDO FINISCO DI CARICARE LA PAGINA ALLORA CARICO LE FOTO
				//---------------------------------------------------------------

				Larghezza = 190
				Altezza = 280

				Id_Pagina = document.getElementById("id_pagina_controllo").value;
				Tabella_Padre = document.getElementById("tabella_pagina_controllo").value;

				UrlPagina = "?id_pagina="+document.getElementById("id_pagina_controllo").value+"&Lang="+document.getElementById("Lingua").value+"&id_email="+document.getElementById("id_email").value;

				TitoloPaginaNew = document.title;
				Lang = document.getElementById("Lingua").value;
				
				CaricaImmagini(Id_Pagina,Lang,UrlPagina,TitoloPaginaNew,Larghezza,Altezza,Tabella_Padre);

				//---------------------------------------------------------------
				//---------------------------------------------------------------
				//---------------------------------------------------------------

			}else{	

				// INTERCETTO ERRORE E VISUALIZZO
				handleErrFullPage(xmlHttp.responseText);
				//-------------------------------
				
				document.getElementById("Contenuto_Pagina").innerHTML = Messaggio;
			}
		
		}else{
				document.getElementById("Contenuto_Pagina").innerHTML = "<center><img src='BANNER/loading.gif' style='margin-top:25px;'></center>"
		}

}

/*-----------------------------------------------*/
/*-----------------------------------------------*/
/*-----------------------------------------------*/

















/*--------------------------------------------------------*/
/*------------ CARICAMENTO IMMAGINI PAGINA ---------------*/
/*--------------------------------------------------------*/

function CaricaImmagini(Id_Pagina,Lang,UrlPagina,TitoloPaginaNew,Larghezza,Altezza,Tabella_Padre){

		Immagine = "";
		Immagine = Immagine + "<iframe "
		Immagine = Immagine + "src='immagini.asp?id_pagina="+Id_Pagina+"&Tabella_Padre="+Tabella_Padre+"&Larghezza="+Larghezza+"&Altezza="+Altezza+"' "
		Immagine = Immagine + "width='"+Larghezza+"' Height='"+Altezza+"' "
		Immagine = Immagine + "scrolling='no' frameborder='0' style='margin-bottom:15px;'> "
		Immagine = Immagine + "</iframe> "
		
		document.getElementById("Immagini_Pagina_Ajax").innerHTML = Immagine

}

/*-----------------------------------------------*/
/*-----------------------------------------------*/
/*-----------------------------------------------*/
















/*-----------------------------------------------*/
/*------------ ISCRIZIONE NEWSLETTER ------------*/
/*-----------------------------------------------*/

function Check_Iscrivi_Newsletter(UrlPagina){

f = document.forms.form4;
b = document.form4;

if (f.email.value == ''   ){
	alert("Inserire indirizzo email !");
	f.email.focus();
	return false;
}

		if (f.email.value != ''   ){		   
			   var i=new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
			   if(!i.test(f.email.value)) {
			   alert("L'indirizzo email inserito non e' valido !");
			   f.email.focus();
			   return false;
			}
		}

	if (document.getElementById("radiobutton_iscriviti").checked == true){
		radiobutton = 'iscriviti';
	}else{
		radiobutton = 'cancellati';
	}

	var postData = "nome="+document.getElementById("nome").value+"&cognome="+document.getElementById("cognome").value+"&email="+document.getElementById("email").value+"&radiobutton="+radiobutton;

	xmlHttp.open("POST", "content.asp"+UrlPagina, true);
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", postData.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.onreadystatechange = handleStateChange;
	xmlHttp.send(postData);

}

/*-----------------------------------------------*/
/*-----------------------------------------------*/
/*-----------------------------------------------*/

/*-----------------------------------------------*/
/*------------ SELEZIONE LINGUA -----------------*/
/*-----------------------------------------------*/

function Seleziona_Lingua(Lingua) {

	Id_Pagina = document.getElementById("id_pagina_controllo").value;
	UrlPagina = "?id_pagina="+document.getElementById("id_pagina_controllo").value+"&Lang="+Lingua;
	TitoloPaginaNew = document.title;

	document.title = TitoloPaginaNew;
	document.getElementById("id_pagina_controllo").value = Id_Pagina;
	document.getElementById("Lingua").value = Lingua;
	
	CaricaMenu(Id_Pagina,Lingua,UrlPagina,TitoloPaginaNew);

} 

/*-----------------------------------------------*/
/*-----------------------------------------------*/
/*-----------------------------------------------*/



/*-----------------------------------------------*/
/*--- GESTIONE E VISUALIZZAZIONE ERRORI ---------*/
/*-----------------------------------------------*/

function handleErrFullPage(strIn) {	

        var errorWin;

        // Create new window and display error
        try {
			errorWin = window.open('', 'errorWin');
			errorWin.document.body.innerHTML = strIn;
        }
        // If pop-up gets blocked, inform user
        catch(e) {
			alert(strIn);
		}

}

/*-----------------------------------------------*/
/*-----------------------------------------------*/
/*-----------------------------------------------*/