// JavaScript Document


function ajaxFunction() {
	var xmlHttp;
	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
		return xmlHttp;
	} catch (e) {
		// Internet Explorer
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			return xmlHttp;
		} catch (e) {
			try {
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
				return xmlHttp;
			} catch (e) {
				alert("Tu navegador no soporta AJAX!");
				return false;
			}
		}
	}
}

function Enviar(_pagina, capa) {
	document.getElementById('contenido').style.textAlign = 'left';
	document.getElementById('contenido').style.paddingTop = '20px';
	var ajax;
	ajax = ajaxFunction();
	
	ajax.open("POST", _pagina, true);
	
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	ajax.onreadystatechange = function() {
	
		if (ajax.readyState == 1) {
			document.getElementById(capa).style.textAlign = 'center';
			document.getElementById(capa).style.paddingTop = '100px';
			document.getElementById(capa).innerHTML = "<img src=\"img/gen/81.gif\" width=\"160\" height=\"24\" border=\"0\" />";
		}
		if (ajax.readyState == 4) {
			document.getElementById(capa).innerHTML = ajax.responseText;
			document.getElementById(capa).style.textAlign = 'left';
			document.getElementById(capa).style.paddingTop = '20px';
	        Shadowbox.clearCache(); 
            Shadowbox.setup();

		}
	}
	
	ajax.send(null);
}


function enviarFormulario(url, formid){
	var peticion;
	peticion = ajaxFunction();
        var Formulario = document.getElementById(formid);
        var longitudFormulario = Formulario.elements.length;
        var cadenaFormulario = "";
        var sepCampos;
        sepCampos = "";
        for (var i=0; i <= Formulario.elements.length-1;i++) {
			//alert(Formulario.elements[i].name);
            cadenaFormulario += sepCampos+Formulario.elements[i].name+'='+encodeURI(Formulario.elements[i].value);
            sepCampos="&";
   		}
	document.getElementById('contenido').style.textAlign = 'center';
	document.getElementById('contenido').style.paddingTop = '100px';
	document.getElementById('contenido').innerHTML = "<img style=\"vertical-align:middle;\" src=\"img/gen/81.gif\" width=\"160\" height=\"24\" border=\"0\" />";

    peticion.open("POST", url, true);
    peticion.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=ISO-8859-1');
    
    peticion.onreadystatechange = function() {
          if (peticion.readyState == 4){
			  document.getElementById('contenido').innerHTML = "<img style=\"vertical-align:middle;\" src=\"img/gen/Ok.png\" width=\"64\" height=\"64\" border=\"0\" /><br /><br />";
              document.getElementById('contenido').innerHTML += peticion.responseText; 
          }
    }
	
	peticion.send(cadenaFormulario);
}


