/*-----------------------------------------------*/
/*------------ 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');
	}

}
/*-----------------------------------------------*/
/*-----------------------------------------------*/
/*-----------------------------------------------*/

/*-----------------------------------------------*/
/*------------ IMMAGINE PRELOAD -----------------*/
/*-----------------------------------------------*/

Testo_Check_Av = "";
Testo_Check_Av = Testo_Check_Av + "<center><img src='../ICONE/loading/4.gif' border='0' style='margin-top:20px;margin-bottom:20px;'></center>"

/*-----------------------------------------------*/
/*-----------------------------------------------*/

/*-----------------------------------------------*/
/*-----------------------------------------------*/
/*-----------------------------------------------*/

function AccessoAreaRiservata(UrlPagina){

createXMLHttpRequest();

f = document.forms.form1;
b = document.form1;


if (f.username.value == ''   ){
	alert("Inserire la login !");
	f.username.focus();
	return false;
}


if (f.password.value == ''   ){
	alert("Inserire la password !");
	f.password.focus();
	return false;
}


		var	postData = ""
		
		//************************************************************************************************************
		// IL VALORE DELLA PAGINA VA' REPERITO IN QUESTA MANIERA IN QUANTO FUORI DAL FORM DI ACCESSO *****************
		//************************************************************************************************************
		postData = postData + "&id_pagina_area_riservata=" + document.getElementById("id_pagina_area_riservata").value
		//************************************************************************************************************
		//************************************************************************************************************
		//************************************************************************************************************
		
		postData = postData + "&username=" + f.username.value
		postData = postData + "&password=" + f.password.value
		
		xmlHttp.open("POST", "AREA_RISERVATA/areariservata-check.asp", true);
		xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", postData.length);
		xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.onreadystatechange = handleStateVerificaAccesso;
		xmlHttp.send(postData);
}

function handleStateVerificaAccesso(){

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 elemento ...</center>"
Messaggio = Messaggio + "  </td></tr>"
Messaggio = Messaggio + "</table>"

		if (xmlHttp.readyState==4){

			if (xmlHttp.status == 200){

				document.getElementById("AreaRiservata_Div").innerHTML = xmlHttp.responseText;
				
				if ( document.getElementById("trovato") != null ) {
				
					if ( document.getElementById("trovato").value == 1 ) {
						
						location.href = "../?id_pagina=" + document.getElementById("id_pagina_area_riservata").value ;
						
					}else{
						
						location.href = "../?id_pagina=102&login_err=1" ;
						
					}
					
				}
				
			}else{

				// INTERCETTO ERRORE E VISUALIZZO
				handleErrFullPage(xmlHttp.responseText);
				//-------------------------------
				
				document.getElementById("AreaRiservata_Div").innerHTML = Messaggio;
			}
		
		}else{
				
			document.getElementById("AreaRiservata_Div").innerHTML = Testo_Check_Av
			
		}


}
/*-----------------------------------------------*/
/*-----------------------------------------------*/
/*-----------------------------------------------*/

/*-----------------------------------------------*/
/*-----------------------------------------------*/
/*-----------------------------------------------*/

function LogOut(UrlPagina){
	
	location.href = UrlPagina ;
	
}
	
/*-----------------------------------------------*/
/*-----------------------------------------------*/
/*-----------------------------------------------*/

/*-----------------------------------------------*/
/*--- 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);
		}

}

/*-----------------------------------------------*/
/*-----------------------------------------------*/
/*-----------------------------------------------*/
