
/* --------------------------------------------------------------- */
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 ShowMutuo(nMutuo)
{
	if (false)
	{
		var cParam = "";

		//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
		// cParam += "C=" + encodeURI(cCampo);
		cParam += "M=" + nMutuo;
		// cParam += "&Pos=" + nPos;
		alert(cParam);
		//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

		xPopup = window.open ("exe/exeShowMutuo.asp?" + cParam, "ShowMutuo", "")
		xPopup.focus();
	}
	else
	{
		if (!http_request && http)
		{
			var cParam = "";

			//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
			// cParam += "C=" + encodeURI(cCampo);
			cParam += "M=" + nMutuo;
			// cParam += "&Pos=" + nPos;

			// alert(cParam);
			//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

			Wait(1);
			http_request = true;

			// alert(cParam);
			http.open("POST", "exe/exeShowMutuo.asp", true);
			http.onreadystatechange = Response_ShowMutuo;
			http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			http.setRequestHeader("Content-length", cParam.length);
			http.send(cParam);
		}
	}
}

function Response_ShowMutuo()
{
	// alert('sono entrato nella funzione Response');
	if (http.readyState == 4)
	{
		Wait(0);
		http_request = false;

		if(http.status == 200) {
			document.getElementById('ShowMutuo').innerHTML = http.responseText;
		} else {
			var results = "C'è stato un errore di Comunicazione !";
			document.getElementById('ShowMutuo').innerHTML = results;
		}
	}
}
/* --------------------------------------------------------------- */


/* --------------------------------------------------------------- */
function CalcolaRata()
{
	if (CheckField())
	{
		// alert("CheckField OK !");
		if (false)
		{
			var cParam = "";

			//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
			// cParam += "M=" + encodeURI(cCampo);
			cParam += "M=" + document.frmMutuo.Mutuo.value;
			cParam += "&V=" + document.frmMutuo.Immobile.value;
			cParam += "&I=" + document.frmMutuo.Importo.value;
			cParam += "&D=" + document.frmMutuo.Durata.value;
			// alert(cParam);
			//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

			xPopup = window.open ("exe/exeCalcolaRata.asp?" + cParam, "CalcolaRata", "")
			xPopup.focus();
		}
		else
		{
			if (!http_request && http)
			{
				var cParam = "";

				//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
				// cParam += "M=" + encodeURI(cCampo);
				cParam += "M=" + document.frmMutuo.Mutuo.value;
				cParam += "&V=" + document.frmMutuo.Immobile.value;
				cParam += "&I=" + document.frmMutuo.Importo.value;
				cParam += "&D=" + document.frmMutuo.Durata.value;
				// alert(cParam);
				//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

				Wait(1);
				http_request = true;

				// alert(cParam);
				http.open("POST", "exe/exeCalcolaRata.asp", true);
				http.onreadystatechange = Response_CalcolaRata;
				http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				http.setRequestHeader("Content-length", cParam.length);
				http.send(cParam);
			}
		}
	}
}

function Response_CalcolaRata()
{
	// alert('sono entrato nella funzione Response');
	if (http.readyState == 4)
	{
		Wait(0);
		http_request = false;

		if(http.status == 200) {
			document.getElementById('CalcolaRata').innerHTML = http.responseText;
		} else {
			var results = "C'è stato un errore di Comunicazione !";
			document.getElementById('CalcolaRata').innerHTML = results;
		}
	}
}
/* --------------------------------------------------------------- */


/* --------------------------------------------------------------- */
function Wait (nStato)
{
	document.getElementById('WaitGif').style.visibility = nStato == 0 ? 'hidden' : 'visible';
}
/* --------------------------------------------------------------- */