var xmlHttp;
var url;

/**
 * seccion: El módulo en el cual va a buscar datos comenzando la primera letra con mayúscula (ej. para '?mod=testimonios' se pasará el parámetro 'Testimonios').
 * direccion: La dirección hacia la cual quiere ir el usuario. Puede tomar los valores 'arriba' o 'abajo'
 * idActual: El primer ID de testimonial actual.
 */
function obtenerDatos(modulo, direccion, idActual, loading) {
	if(loading == 'true') {
		document.getElementById("loading").innerHTML = "Cargando...<img src='images/varios/loader.gif' alt='cargando...'/>";
	} 
	xmlHttp = getXmlHttpObject();
	if (xmlHttp == null) {
		alert("El explorador no soporta peticiones HTTP");
		return;
	}
	
	if(direccion == 'arriba') {
		idActual -= 4;
	} else if(direccion == 'abajo') {
		idActual += 4;
	}
	
	url = "mods/ajax/ajax" + modulo + ".php";
	url = url + "?id=" + idActual;
	xmlHttp.onreadystatechange = stateChanged;
	if (loading == 'true' && (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete")) {
		document.getElementById("loading").innerHTML = "";
	}
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}

function stateChanged() { 
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
		document.getElementById("mainContent").innerHTML = xmlHttp.responseText;
	} 
}

function getXmlHttpObject() {
	var xmlHttp = null;
	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp = new XMLHttpRequest();
	} catch (e) {
		//Internet Explorer
		try {
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}