/* librerías por Marcos Pérez (Gallaenet.com)
codificación de caracteres : utf8
*/

function nuevoAjax(){
	var xmlhttp=false;
	try {
		xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');
	} catch (e) {
		try {
			xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
		} catch (E) {
			xmlhttp = false;
		}
	}


	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		xmlhttp = new XMLHttpRequest();
	}

	return xmlhttp;
}

function cargarContenido(pagina, contenedor,aux){

	ajax=nuevoAjax();
	ajax.open('GET', pagina, true);
	ajax.onreadystatechange=function() {
		if(ajax.responseText) {
			document.getElementById(contenedor).innerHTML = ajax.responseText;

			if(!aux) {
				for(alto=0,tiempo=20; alto<=97; alto+=5,tiempo+=20) {
				
					setTimeout("document.getElementById('textocont').style.height='"+alto+"%'", tiempo);
				
				}
				for(alto=295,tiempo=20; alto<=450; alto+=8,tiempo+=20) {
			
					altos=alto+65;
				
					setTimeout("document.getElementById('cont').style.height='"+alto+"px'", tiempo);
					setTimeout("document.getElementById('todocont').style.height='"+altos+"px'", tiempo);
					setTimeout("document.getElementById('cont').style.maxHeight='"+alto+"px'", tiempo);
				
				}
				setTimeout("document.getElementById('textocont').style.overflow='auto'",tiempo);
			}
		}
	}

	ajax.send(null);

}

function cargacont(pagina, contenedor){

	ajax=nuevoAjax();
	ajax.open('GET', pagina, true);
	ajax.onreadystatechange=function() {
		if(ajax.responseText) {
			document.getElementById("confpass").value = ajax.responseText;
		}
	}

	ajax.send(null);

}
function cargaimg(pagina, contenedor){

	ajax=nuevoAjax();
	ajax.open('GET', pagina, true);
	ajax.onreadystatechange=function() {
		if(ajax.responseText) {
			document.getElementById(contenedor).src = ajax.responseText;
		}
	}

	ajax.send(null);

}
function cargarContenidoPOST(pagina, parametros, contenedor){

	contenedor = document.getElementById("capa"+contenedor);
	envio = new Array();
	parametro=parametros.split("|");

	for(i=0; i<parametro.length; i++) {
		valor = document.getElementById("cmp"+parametro[i]).value;
		envio[i]= "cmp"+parametro[i]+"="+valor;
	
	}

	ajax=nuevoAjax();
	ajax.open('POST', pagina, true);
	ajax.onreadystatechange=function() {
	
		if (ajax.readyState==4) {

			if(ajax.responseText!="" && ajax.responseText.substring(0, 9)!="redirect:" && ajax.responseText.substring(0, 7)!="alerta:") {
				contenedor.innerHTML = ajax.responseText;
			} else if (ajax.responseText.substring(0, 9) == "redirect:" && ajax.responseText != "") {
				window.location.href = ajax.responseText.substr(9);
			} else if (ajax.responseText != "" && ajax.responseText.substring(0, 7) == "alerta:") {
				alert(ajax.responseText.substr(7));
			}
		}

	}
	ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	ajax.send(envio.join("&"));

}

function cargarContenidoPOST2(pagina, parametros, contenedorium){

	contenedor = document.getElementById(contenedorium);
	envio = new Array();
	parametro=parametros.split("|");

	for(i=0; i<parametro.length; i++) {
		valor = document.getElementById("cmp"+parametro[i]).value;
		envio[i]= "cmp"+parametro[i]+"="+valor;
	
	}

	ajax=nuevoAjax();
	ajax.open('POST', pagina, true);
	ajax.onreadystatechange=function() {
	
		if (ajax.readyState==4) {

			if(ajax.responseText!="" && ajax.responseText.substring(0, 9)!="redirect:" && ajax.responseText.substring(0, 7)!="alerta:") {
				contenedor.innerHTML = ajax.responseText;
			} else if (ajax.responseText.substring(0, 9) == "redirect:" && ajax.responseText != "") {
				window.location.href = ajax.responseText.substr(9);
			} else if (ajax.responseText != "" && ajax.responseText.substring(0, 7) == "alerta:") {
				alert(ajax.responseText.substr(7));
			}
		}

	}
	ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	ajax.send(envio.join("&"));

}

function consultarAjax(pagina, contenedor, aceptar, cancelar) {
	var exito=0;
	ajax=nuevoAjax();
	ajax.open('GET', pagina, true);
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			if(ajax.responseText != "" && ajax.responseText.substring(0, 9) != "redirect:" && ajax.responseText.substring(0, 7) != "alerta:" && ajax.responseText.substring(0, 8) != "confirm:") {
				exito=1;
				document.getElementById(contenedor).innerHTML = ajax.responseText;
				return exito;
			} else if (ajax.responseText.substring(0, 9) == "redirect:" && ajax.responseText != "") {
       				window.location = ajax.responseText.substr(9);
        		} else if (ajax.responseText != "" && ajax.responseText.substring(0, 7) == "alerta:") {
        			alert(ajax.responseText.substr(7));
        		} else if (ajax.responseText != "" && ajax.responseText.substring(0, 8) == "confirm:") {
        			if(confirm(ajax.responseText.substr(8))) {
        				return self[aceptar]();
        			} else {
        				return self[cancelar]();
        			}
        		} else {
				exito=0; 
				return exito;
			}
		}
	}

	ajax.send(null);
}
