// JavaScript Document
function nuevoAjax(){
	var xmlhttp=false;
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");  		// Creación del objeto ajax para navegadores diferentes a Explorer
	} catch (e) {
		try {								// o bien
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");		// Creación del objet ajax para Explorer
		} catch (E) {
			xmlhttp = false;
		}
	}

	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}
function fAjax(URL, Capa, theForm, Metodo, JS, BorraCapa) {
	var mAct = Math.random() * 1000;

	if (BorraCapa != '' && BorraCapa != null) document.getElementById(BorraCapa).innerHTML = '';

	document.getElementById('hStatusAjax').style.background = '#FF0000';
	document.getElementById('hStatusAjax').style.color = '#FFFFFF';
	document.getElementById('hStatusAjax').style.top = document.body.scrollTop;
	document.getElementById('hStatusAjax').style.left = 0;
	document.getElementById('hStatusAjax').innerHTML = '&nbsp;cargando ...';

	ajax=nuevoAjax();
	if (Metodo.toUpperCase() == 'POST') {
		ajax.open("POST", URL, true);
	}else {
		if (URL.search('=') == -1) {
			ajax.open("GET", URL+"?t="+mAct, true);
		}else {
			ajax.open("GET", URL+"&t="+mAct, true);
		}
	}
	ajax.onreadystatechange = function() {
		if (ajax.readyState == 4) {

			if (JS.toUpperCase() == 'SI') {
				var aRespuestaAjax = ajax.responseText.split("\n");
				var j = 0;
				var k = '';
				for (var i=0; i<aRespuestaAjax.length; i++) {
					if (aRespuestaAjax[i].substr(0, 9).toLowerCase() == '</script>') {
						j = 0;
					}	// if
					if (j == 1) {
						eval(aRespuestaAjax[i]);
					}else {
						k += aRespuestaAjax[i] + "\n";
					}	// if	// if	// if
					if (aRespuestaAjax[i].substr(0, 7).toLowerCase() == '<script') {
						j = 1;
					}	// if
				}	// for
				document.getElementById(Capa).innerHTML = k;
			}else {
				document.getElementById(Capa).innerHTML = ajax.responseText;
			}
			document.getElementById('hStatusAjax').style.background = '';
			document.getElementById('hStatusAjax').innerHTML = '';
		}
	}
	if (Metodo.toUpperCase() == 'POST') {
		ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');

		var nCampo;
		var Valores = '';
		for (var i=0; i<theForm.length; i++) {
			nCampo = theForm[i].name;
			if (nCampo != '') {
				if (Valores != '') {
					Valores += '&';
				}
				Valores += nCampo + '=' + escape(theForm[nCampo].value);
			}
		}
		ajax.send(Valores);
	}else {
		ajax.send(null);
	}
}
