var XMLHTTP;

function Richiesta(ACT, Codice, Prodotto, Qty, Min_Qty, Prezzo, Prezzo_promo, bottiglie_carrello, nota_dispo, lang, prezzo_in_valuta)
{
	if (ACT == 'ADD')
	{
		if (lang == 'eng')
		{
		var stringa1 = 'This product is out of stock and cannot be added to the shopping cart.';
		var stringa2 = 'Invalid quantity!\n\nMust be a multiple of ';
		var stringa3 = 'Invalid quantity!\n\nMust be greater than zero and must not exceed 72.';
		var stringa4 = 'Cannot add to the cart!\n\nThe shopping cart capacity is 72 bottles.\nBottles in your shopping cart now: '
		var stringa5 = 'Product: '
		var stringa6 = '\n\nUnit Price: '
		var stringa7 = '\nPart number: '
		var stringa8 = '\nQuantity: '
		var stringa9 = '\n\nThis product has been added to the shopping cart.\nThe shopping cart contains now '
		var stringa10 = ' bottles.'
		}	else	{
		var stringa1 = 'Il prodotto è esaurito e non è possibile aggiungerlo al carrello.';
		var stringa2 = 'Quantità non valida!\n\nLa quantità deve essere un multiplo di ';
		var stringa3 = 'Quantità non valida!\n\nLa quantità deve essere maggiore di zero e non deve eccedere 72.';
		var stringa4 = 'Impossibile aggiungere queste bottiglie al carrello!\n\nIl carrello può contenere al massimo 72 bottiglie.\nBottiglie attualmente nel vostro carrello: ';
 		var stringa5 = 'Prodotto: '
		var stringa6 = '\n\nPrezzo unitario: '
		var stringa7 = '\nCodice: '
		var stringa8 = '\nQuantità: '
		var stringa9 = '\n\nIl prodotto è stato aggiunto al carrello nella quantità richiesta.\nIl carrello contiene ora '
		var stringa10 = ' bottiglie.'
		}
			
		if (nota_dispo == "NO") {
			alert(stringa1)
			return(false);
		}
				
		if ( Qty%Min_Qty > 0 ) {
			rc = alert(stringa2 + Min_Qty + '.');
			return(false);
		} 

		if (Qty <=0 | Qty >= 73) {
			rc = alert(stringa3);
			return(false);
		} 
		
		if ((parseInt(bottiglie_carrello) + parseInt(Qty)) >= 73) {
			rc = alert(stringa4 + bottiglie_carrello +'.');
			return(false);
		} 
		alert(stringa5 + unescape(Prodotto) + stringa6 + unescape(prezzo_in_valuta) + stringa7 + Codice + stringa8 + Qty + stringa9 + (parseInt(bottiglie_carrello) + parseInt(Qty)) + stringa10)
	}			

	var url = "../acquisto/carrellino.asp?act=" + ACT + "&codice=" + Codice + "&Prodotto=" + Prodotto + "&qty=" + Qty + "&Min_Qty=" + Min_Qty + "&Prezzo=" + Prezzo + "&Prezzo_promo=" + Prezzo_promo;

   XMLHTTP = RicavaBrowser(CambioStato);
   XMLHTTP.open("GET", url, true);
   XMLHTTP.send(null);
}

function CambioStato()
{
    if (XMLHTTP.readyState == 4)
    {
        var R = document.getElementById("risultato");
        R.innerHTML = XMLHTTP.responseText;
    }
}

function RicavaBrowser(QualeBrowser)
{
    if (navigator.userAgent.indexOf("MSIE") != (-1))
    {
        var Classe = "Msxml2.XMLHTTP";
        if (navigator.appVersion.indexOf("MSIE 5.5") != (-1));
        {
            Classe = "Microsoft.XMLHTTP";
        } 
        try
        {
            OggettoXMLHTTP = new ActiveXObject(Classe);
            OggettoXMLHTTP.onreadystatechange = QualeBrowser;
            return OggettoXMLHTTP;
        }
        catch(e)
        {
            alert("Errore: l'ActiveX non verrà eseguito!");
        }
    }
    else if (navigator.userAgent.indexOf("Mozilla") != (-1))
    {
        OggettoXMLHTTP = new XMLHttpRequest();
        OggettoXMLHTTP.onload = QualeBrowser;
        OggettoXMLHTTP.onerror = QualeBrowser;
        return OggettoXMLHTTP;
    }
    else
    {
        alert("Solo MSIE o Mozilla! MSIE or Mozilla only!");
    }
}

