/*
funzione che sostituisce il contenuto di un div con id = 'divID' con il contento del file 'url'
by Matteo Guardini
method = GET/POST
url = file contenente il nuovo contenuto del DIV
bool = true/false
divID = id del div il cui contenuto verrą sostituito
divIDattendere = id del div nascosta con l'immagine o la scritta attendere
*/
function AJAXReq( method, url, bool, divID, divIDattendere )
{
	
	/* funzioni per visualizzare un div */
	var loading = document.getElementById( divIDattendere );
	loading.style.display = '';
	
	if(window.XMLHttpRequest)
	{
		myReq = new XMLHttpRequest();
	}
	else if(window.ActiveXObject)
	{
		myReq = new ActiveXObject("Microsoft.XMLHTTP");
		if(!myReq)
		{
			myReq = new ActiveXObject("Msxml2.XMLHTTP");
		}
	}
	if(myReq)
	{
		myReq.onreadystatechange = function handleResponseInner()
		{
			if(myReq.readyState == 4)
			{
				if(myReq.status == 200)
				{
					var target = document.getElementById( divID );
					target.innerHTML = myReq.responseText;
				}
				else
				{
					alert("Contenuto non trovato!");
				}
			}
		}
		
		myReq.open( method, url, bool );
		myReq.send(null);
	}
	else
	{
		alert("Error AJAX");
	}
}

/*
funzione che sostituisce il contenuto di un div con id = 'divID' con il contento del file 'url' e lo fa apparire in dissolvenza
by Matteo Guardini
method = GET/POST
url = file contenente il nuovo contenuto del DIV
bool = true/false
divID = id del div il cui contenuto verrą sostituito
divIDattendere = id del div nascosta con l'immagine o la scritta attendere
divAppear = div contente tutto il codice, impostato su display: none per poi apparire in dissolvenza
*/
function AJAXReqAppear( method, url, bool, divID, divIDattendere, divAppear )
{
	
	/* funzioni per visualizzare il div di attesa (loading) */
	var loading = document.getElementById( divIDattendere );
	loading.style.display = '';
	
	if(window.XMLHttpRequest)
	{
		myReq = new XMLHttpRequest();
	}
	else if(window.ActiveXObject)
	{
		myReq = new ActiveXObject("Microsoft.XMLHTTP");
		if(!myReq)
		{
			myReq = new ActiveXObject("Msxml2.XMLHTTP");
		}
	}
	if(myReq)
	{
		myReq.onreadystatechange = function handleResponseInner()
		{
			if(myReq.readyState == 4)
			{
				if(myReq.status == 200)
				{
					var target = document.getElementById( divID );
					target.innerHTML = myReq.responseText;
					
					// effetto appear
					Effect.Appear(divAppear, { duration: 3.0 }); // questa e' una funzione di scriptacolous, quindi devono essere inseriti i js di scriptacolous
					
					// effetto BlindDown
					//Effect.BlindDown(divAppear, { duration: 3.0 });
					
					// effettoSlideDown
					//Effect.SlideDown(divAppear, { duration: 3.0 });
					
				}
				else
				{
					alert("Contenuto non trovato!");
				}
			}
		}
		
		myReq.open( method, url, bool );
		myReq.send(null);
	}
	else
	{
		alert("Error AJAX");
	}
}

/*
funzione che sostituisce il contenuto di un div con id = 'divID' con il contento del file 'url' e lo fa apparire in dissolvenza
by Matteo Guardini
method = GET/POST
url = file contenente il nuovo contenuto del DIV
bool = true/false
divID = id del div il cui contenuto verrą sostituito (div contente tutto il codice, impostato su display: none per poi apparire in dissolvenza)
divIDattendere = id del div nascosta con l'immagine o la scritta attendere
In questo caso il div divIDattendere non dovra' essere ricaricato
*/
function AJAXReqLoadAppear( method, url, bool, divID, divIDattendere )
{
	/* funzioni per visualizzare il div di attesa (loading) */
	var dissolvenza = document.getElementById( divID );
	dissolvenza.style.display = 'none';
	
	/* funzioni per visualizzare il div di attesa (loading) */
	var loading = document.getElementById( divIDattendere );
	loading.style.display = '';
	
	if(window.XMLHttpRequest)
	{
		myReq = new XMLHttpRequest();
	}
	else if(window.ActiveXObject)
	{
		myReq = new ActiveXObject("Microsoft.XMLHTTP");
		if(!myReq)
		{
			myReq = new ActiveXObject("Msxml2.XMLHTTP");
		}
	}
	if(myReq)
	{
		myReq.onreadystatechange = function handleResponseInner()
		{
			if(myReq.readyState == 4)
			{
				if(myReq.status == 200)
				{
					// inserisco il contenuto del file chiamato in background nel div divID
					var target = document.getElementById( divID );
					target.innerHTML = myReq.responseText;

					// nascondo il div del loading
					loading.style.display = 'none';

					// effetto appear (il div deve essere settato su display: none!!!)
					Effect.Appear(divID, { duration: 2.0 }); // questa e' una funzione di scriptacolous, quindi devono essere inseriti i js di scriptacolous
					
					// effetto BlindDown (il div deve essere settato su display: none!!!)
					//Effect.BlindDown(divID, { duration: 3.0 });
					
					// effettoSlideDown (il div deve essere settato su display: none!!!)
					//Effect.SlideDown(divID, { duration: 3.0 });
					
				}
				else
				{
					// nascondo il div del loading
					loading.style.display = 'none';
					alert("Contenuto non trovato!");
				}
			}
		}
		myReq.open( method, url, bool );
		myReq.send(null);
	}
	else
	{
		alert("Error AJAX");
	}
}


/*
funzione che sostituisce il contenuto di un div con id = 'divID' con il contento del file 'url' e lo fa apparire in dissolvenza
by Matteo Guardini
method = GET/POST
url = file contenente il nuovo contenuto del DIV
bool = true/false
divID = id del div il cui contenuto verrą sostituito (div contente tutto il codice, impostato su display: none per poi apparire in dissolvenza)
divIDattendere = id del div nascosta con l'immagine o la scritta attendere
In questo caso il div divIDattendere non dovra' essere ricaricato
*/
function AJAXReqLoad( method, url, bool, divID, divIDattendere )
{

	/* funzioni per visualizzare il div di attesa (loading) */
	var loading = document.getElementById( divIDattendere );
	loading.style.display = '';
	
	if(window.XMLHttpRequest)
	{
		myReq = new XMLHttpRequest();
	}
	else if(window.ActiveXObject)
	{
		myReq = new ActiveXObject("Microsoft.XMLHTTP");
		if(!myReq)
		{
			myReq = new ActiveXObject("Msxml2.XMLHTTP");
		}
	}
	if(myReq)
	{
		myReq.onreadystatechange = function handleResponseInner()
		{
			if(myReq.readyState == 4)
			{
				if(myReq.status == 200)
				{
					// inserisco il contenuto del file chiamato in background nel div divID
					var target = document.getElementById( divID );
					target.innerHTML = myReq.responseText;

					// nascondo il div del loading
					loading.style.display = 'none';
					
				}
				else
				{
					// nascondo il div del loading
					loading.style.display = 'none';
					alert("Contenuto non trovato!");
				}
			}
		}
		myReq.open( method, url, bool );
		myReq.send(null);
	}
	else
	{
		alert("Error AJAX");
	}
}
