var Destinazione;
//FUNZIONE PER OTTENERE L'OGGETTO XMLHttpRequest
function getXmlHttpRequestObject() { 

	var xmlhttp=false;

	try
	{
		xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');
	}
	catch (e)
	{
		try
		{
	  		xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
		}
		catch (E)
		{
	  		xmlhttp = false;
		}
 	}
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
    	xmlhttp = new XMLHttpRequest();
  	}
  	return xmlhttp;
}

//PRELOAD IMMAGINE
function PreloadImmagine(img,src_da_caricare) {
	img.src = 'images/loading.gif';
	var xmlhttp = getXmlHttpRequestObject();
	xmlhttp.onreadystatechange = function () {
		
		if (xmlhttp.readyState==4) {
			if (xmlhttp.status==200) {
				img.src = src_da_caricare;
			}
		}
	}
	xmlhttp.open("GET",src_da_caricare,true);
	xmlhttp.send(null);
}

//FUNZIONE PER OTTENERE I DATI DA UN FILE ASP       
//Initiate the asyncronous request. 
function ChiamaAjax(NomeDiv, NomePagina, Variabili)
{	
	Destinazione = NomeDiv;
	// branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        richiesta = new XMLHttpRequest();
		//alert('sono entrato nella funzione normale')
		var postData = Variabili;
		richiesta.open("POST", NomePagina, true);
  		richiesta.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
 		richiesta.setRequestHeader("Content-length", postData.length);
  		richiesta.setRequestHeader("Connection", "close");
		
        richiesta.onreadystatechange = StampaRisposta;
        richiesta.send(postData);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        richiesta = new ActiveXObject("Microsoft.XMLHTTP");
		//alert('sono entrato nella funzione Microsoft')
        if (richiesta) {
			var postData = Variabili;
			richiesta.open("POST", NomePagina, true);
			richiesta.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			richiesta.setRequestHeader("Content-length", postData.length);
			richiesta.setRequestHeader("Connection", "close");
			
			richiesta.onreadystatechange = StampaRisposta;
			richiesta.send(postData);
        }
    }
}
//STAMPO IL RISULTATO DELL'AJAX
function StampaRisposta() {
 	if (richiesta.readyState == 4) 
 	{
		if(richiesta.status == 200)
		{
			var ilDiv = document.getElementById(Destinazione)
			ilDiv.innerHTML = richiesta.responseText;
			ilDiv.style.display = ilDiv.style.display;
    	} else {
			var ilDiv = document.getElementById(Destinazione)
			ilDiv.innerHTML = richiesta.responseText;
			ilDiv.style.display = ilDiv.style.display;
			
		}
		Destinazione = "";
  	}
}

function gestisciCarrello(Cod,Desc, Price, act, URL, svuota)
{	
	var Valori = "codice="+Cod+"&desc="+Desc+"&prezzo="+Price+"&act="+act+"&svuota="+svuota;
	//if (URL!='') {
	//	window.location.href = URL;
	//}
	ChiamaAjax("contenitoreCarrello", "kernel/modules/shop/chart.asp", Valori, true);
}

//function confermaCarrello(pagamento, corriere)
//{	
//	ChiamaAjax("CarrelloConferma", "kernel/modules/shop/carrello.asp", "act=CONFERMA&pag="+pagamento+"&cor="+corriere);
//}


function SvuotaCarrello() {
	if (confirm('Sei sicuro di voler svuotare il carrello?')) {
		gestisciCarrello('','', '','EMPTY', '');
	} else {
		return;
	}
}
	
function confermaCarrello() {
	if (confirm("Sei sicuro di voler confermare l'ordine?")) {
		window.location.href = 'shop.asp?mod=i';
	} else {
		return;
	}
}

//VISUALIZZA NASCONDI CARRELLO
function NascondiCarrello() {
	var carrello = document.getElementById("contenitoreCarrello"); 
	if (carrello.style.display=='') {
		carrello.style.display = 'none';
	} else {
		carrello.style.display = '';
	}
}
