//Crea un objeto XML-http
function getXmlHttpObject() {
	var xmlhttp;
		try {
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			try {
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {
				try {
					xmlhttp = new XMLHttpRequest();
				}
				catch (e) {
					xmlhttp = false;
					alert ('Error');
				}
			}
		}
	return xmlhttp;
}
//Porcesar la peticion XMLHttpReuest
function procesarajax(archivo,id,metodo,datos) {
	//Obtener el objeto XMLHttpRequest a utilizar
	xmlhttp = getXmlHttpObject();
	if (metodo=="get") {
		xmlhttp.open("GET",archivo,true);
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState==1) {
				document.getElementById(id).innerHTML = "<img align='center' src='imagen/cargar.gif' width='17' style='margin-right:5px; border:none' /> Cargando ...";
			} else if (xmlhttp.readyState==4 && xmlhttp.status==200) {
				document.getElementById(id).innerHTML = xmlhttp.responseText;
			}
		}
		xmlhttp.send(null); //Como es GET no mandamos nada en al cuerpo
	} else {
		xmlhttp.open("POST",archivo,true);
		xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState==1) {
				document.getElementById(id).innerHTML = "<div align='center' style='padding:5px 0px 5px 0px;text-align:center'><img src='imagen/cargar.gif' style='margin-right:10px' /> Cargando ...</div>";
			} else if (xmlhttp.readyState==4 && xmlhttp.status==200) {
				document.getElementById(id).innerHTML = xmlhttp.responseText;
			}
		}
		xmlhttp.send(datos);
	}
}
function submenu(archivo,id,metodo,datos) {
	document.getElementById('submenu').style.height=22+"px";
	procesarajax(archivo,id,metodo,datos);
}
function rotativa(id,idfoto,dir) {
	procesarajax("inc/otrafoto.php?id="+id+"&idfoto="+idfoto+"&dir="+dir,"rotativa"+id,"get","");
}
function rotativa2(id,idfoto,dir) {
	procesarajax("inc/otrafoto2.php?id="+id+"&idfoto="+idfoto+"&dir="+dir,"rotativa"+id,"get","");
}
function rotagaleria(id,idfoto,dir) {
	procesarajax("inc/rotagaleria.php?idgaleria="+id+"&idfoto="+idfoto+"&dir="+dir,"rotagaleria"+id,"get","");
}
function ingresarform(formulario,archivo,id) {
	var datos = datosformulario(formulario);
	procesarajax(archivo,id,"post",datos);
}
function datosformulario (formulario) {
	var datos="";
	//Recorro el formulario obteniendo los valores
	for (var i=0;i<formulario.elements.length;i++) {
		if (formulario.elements[i].type=="checkbox") {
			if (formulario.elements[i].checked) datos +=formulario.elements[i].name+"="+escape(formulario.elements[i].value)+"&";
		} else {
			datos +=formulario.elements[i].name+"="+escape(formulario.elements[i].value)+"&";
		}
	}
	return datos;
}
function abrir(archivo,w,h,nombre) { 
		var windowprops= "top=0,left=0,toolbar=no,location=no,status=no,menubar=no,scrollbars=yes, resizable=no,width=" + w + ",height=" + h;
	window.open(archivo,nombre,windowprops);
} 