
/* --------------------------------------------------------------- */
var http_request = false;
var http = XML_HTTP_Object();		// Creo l'oggetto XHR.
/* --------------------------------------------------------------- */


/* --------------------------------------------------------------- */
function XML_HTTP_Object() 
{
	var xml_http;

	if (window.ActiveXObject) 
	{
		// instanzio l'oggetto
		if (_XML_ActiveX)
		{
			xml_http = new ActiveXObject(_XML_ActiveX);
		} 
		else 
		{
			// ciclo attraverso le varie versioni
			var versions = ["MSXML2.XMLHTTP", "Microsoft.XMLHTTP", "Msxml2.XMLHTTP.7.0", "Msxml2.XMLHTTP.6.0", "Msxml2.XMLHTTP.5.0", "Msxml2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0"];
			for (var i = 0; i < versions.length ; i++)
			{
				try {
					xml_http = new ActiveXObject(versions[i]);		// creo l'oggetto
					if (xml_http)
					{
						var _XML_ActiveX = versions[i];
						break;
					}
				}
				catch (e) {
					// TRAP
				};
			};
		}
	} // se non c'è ActiveX allora sono su un browser diverso da Internet Explorer

	if (!xml_http && typeof XMLHttpRequest != 'undefined')
	{
		try {
			xml_http = new XMLHttpRequest();
		} catch (e) {
			xml_http = false;
		}
	}

	return xml_http;
}
/* --------------------------------------------------------------- */


/* --------------------------------------------------------------- */
function ShowMenu(nMenu)
{
	if (false)
	{
		var cParam = "";

		if (nMenu == 1)
		{
			//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
			// cParam += "C=" + encodeURI(cCampo);
			// cParam += "R=" + cTipoRic;
			// cParam += "&M=" + cMarca;
			// cParam += "&C=" + cCat;
			//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

			alert(cParam);
			xPopup = window.open ("../Catalogo/MenuProduttori.asp", "ShowMenu", "")
			xPopup.focus();
		}
		else if (nMenu == 2)
		{
			//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
			// cParam += "C=" + encodeURI(cCampo);
			// cParam += "R=" + cTipoRic;
			// cParam += "&C=" + cCat;
			//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

			alert(cParam);
			xPopup = window.open ("../Catalogo/MenuProdotti.asp", "ShowMenu", "")
			xPopup.focus();
		}
	}
	else
	{
		if (!http_request && http)
		{
			var cParam = "";
			var cURL = "";

			//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
			if (nMenu == 1)
			{
				// cParam = "R=" + cTipoRic + "&M=" + cMarca + "&C=" + cCat;
				cURL = "../Catalogo/MenuProduttori.asp";
			}
			else if (nMenu == 2)
			{
				// cParam = "R=" + cTipoRic + "&C=" + cCat;
				cURL = "../Catalogo/MenuProdotti.asp";
			}
			//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

			Wait(1);
			http_request = true;

			// alert(cParam);
			http.open("POST", cURL, true);
			http.onreadystatechange = Response_Menu;
			http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			http.setRequestHeader("Content-length", cParam.length);
			http.send(cParam);
		}
	}
}

function Response_Menu()
{
	// alert('sono entrato nella funzione Response');
	if (http.readyState == 4)
	{
		Wait(0);
		http_request = false;

		if(http.status == 200) {
			document.getElementById('MenuCat').innerHTML = http.responseText;
		} else {
			var results = "C'è stato un errore di Comunicazione !";
			document.getElementById('MenuCat').innerHTML = results; 
		}
	}
}
/* --------------------------------------------------------------- */


/* --------------------------------------------------------------- */
function Catalogo(cTipoRic, cMarca, cCat)
{
	if (false)
	{
		var cParam = "";

		if (cTipoRic == 1)
		{
			//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
			// cParam += "C=" + encodeURI(cCampo);
			cParam += "R=" + cTipoRic;
			cParam += "&M=" + cMarca;
			cParam += "&C=" + cCat;
			//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
		}
		else if ((cTipoRic == 3) || (cTipoRic == 2) || (cTipoRic == 0))
		{
			//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
			// cParam += "C=" + encodeURI(cCampo);
			cParam += "R=" + cTipoRic;
			cParam += "&C=" + cCat;
			//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
		}

		alert(cParam);
		xPopup = window.open ("../Catalogo/Catalogo.asp?" + cParam, "ShowMutuo", "")
		xPopup.focus();
	}
	else
	{
		if (!http_request && http)
		{
			var cParam = "";

			//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
			if (cTipoRic == 1)
			{
				cParam = "R=" + cTipoRic + "&M=" + cMarca + "&C=" + cCat;
			}
			else if ((cTipoRic == 3) || (cTipoRic == 2) || (cTipoRic == 0))
			{
				cParam = "R=" + cTipoRic + "&C=" + cCat;
			}
			//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
			// alert(cParam);

			Wait(1);
			http_request = true;

			// alert(cParam);
			http.open("POST", "../Catalogo/CatalogoAjax.asp", true);
			http.onreadystatechange = Response_Catalogo;
			http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			http.setRequestHeader("Content-length", cParam.length);
			http.send(cParam);
		}
	}
}

function Response_Catalogo()
{
	// alert('sono entrato nella funzione Response');
	if (http.readyState == 4)
	{
		Wait(0);
		http_request = false;

		if(http.status == 200) {
			document.getElementById('ContenutoPagine').innerHTML = http.responseText;
		} else {
			var results = "C'è stato un errore di Comunicazione !";
			document.getElementById('ContenutoPagine').innerHTML = results; 
		}
	}
}
/* --------------------------------------------------------------- */


/* --------------------------------------------------------------- */
function AddCarrello(nPos)
{
	var cParam = '';
	var nQta = eval("document.frm" + nPos + ".QtaProd.value");

	if (!IsNumber(nQta))
	{
		alert("Nulla da inserire nel carrello o Quantità espressa in modo Errato !\nInserire un Numero Positivo Maggiore di 0 per indicare la Quantità.");
	}
	else if (parseInt(nQta) == 0)
	{
		alert("Nulla da inserire nel carrello o Quantità espressa in modo Errato !\nInserire un Numero Positivo Maggiore di 0 per indicare la Quantità.");
	}
	else
	{
		if (!http_request && http)
		{
			cParam += 'Pos=' + nPos;
			cParam += '&Qta=' + nQta;
			// alert(cParam);

			eval("document.frm" + nPos + ".ImgCarrello.src='../Catalogo/Img/Carrello/CarrelloON.gif'");

			Wait(1);
			http_request = true;

			// alert(cParam);
			http.open("POST", "../Catalogo/exe/exeAddCarrello.asp", true);
			http.onreadystatechange = Response_Carrello;
			http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			http.setRequestHeader("Content-length", cParam.length);
			http.send(cParam);
		}
	}
}

function Response_Carrello()
{
	// alert('sono entrato nella funzione Response');
	if (http.readyState == 4)
	{
		Wait(0);
		http_request = false;

		if(http.status == 200) {
			document.getElementById('Carrello').innerHTML = http.responseText;
		} else {
			var results = "C'è stato un errore di Comunicazione !";
			document.getElementById('Carrello').innerHTML = results; 
		}
	}
}
/* --------------------------------------------------------------- */


/* --------------------------------------------------------------- */
function SumCarrello(nPos, nQta)
{
	var cParam = '';

	if (!http_request && http)
	{
		cParam += 'Pos=' + nPos;
		cParam += '&Qta=' + nQta;
		// alert(cParam);

		Wait(1);
		http_request = true;

		// alert(cParam);
		http.open("POST", "../Catalogo/exe/exeSumCarrello.asp", true);
		http.onreadystatechange = Response_Catalogo;
		http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		http.setRequestHeader("Content-length", cParam.length);
		http.send(cParam);
	}
}
/* --------------------------------------------------------------- */


/* --------------------------------------------------------------- */
function exeDelCarrello(nPos)
{
	var cParam = '';
	var bConfirm = true;

	if (parseInt(nPos) == 0)
	{
		bConfirm = confirm ('Confermi Eliminazione Contenuto Carrello ?');
	}

	if (parseInt(nPos) > 0)
	{
		bConfirm = confirm ('Confermi Eliminazione Prodotto ?');
	}

	if (bConfirm)
	{
		if (!http_request && http)
		{
			cParam = 'Pos=' + nPos;
			// alert(cParam);

			Wait(1);
			http_request = true;

			// alert(cParam);
			http.open("POST", "../Catalogo/exe/exeDelCarrello.asp", true);
			http.onreadystatechange = Response_Catalogo;
			http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			http.setRequestHeader("Content-length", cParam.length);
			http.send(cParam);
		}
	}
}
/* --------------------------------------------------------------- */

/* --------------------------------------------------------------- */
function Wait (nStato)
{
	document.getElementById('WaitGif').style.visibility = nStato == 0 ? 'hidden' : 'visible';
}
/* --------------------------------------------------------------- */


function Alert(cTesto)
{
	alert(cTesto);
}

function TestCatalogo(cPage)
{
	var cParam = "";

	xPopup = window.open ("CatalogoAjax.asp?C=" + cPage, "Catalogo", "")
	xPopup.focus();
}


// ---------------------------------------------------------------
// Verifica CAP
// ---------------------------------------------------------------
function IsNumber(cNumber)
{
	var i = new RegExp("[0-9]");
	return i.test(cNumber);
}
// ===============================================================



