var ruta_procesador = "http://www.constitucionalismovasco.org/procesador.php";
var ruta_mail = "http://www.constitucionalismovasco.org/mailer.php";

//   =========================================================
//   || Funcion que muestra o oculta las secciones del menu ||
//   =========================================================
function muestra(id){
	obj=document.getElementById(id);
	if(obj.style.display=="block") obj.style.display="none";
	else obj.style.display="block";
}

//   =======================================================
//   || Funcion para cambiar de estilo al pasar el cursor ||
//   =======================================================
function mOvr(src,clrOver,txt) {
	window.status = txt;
	document.getElementById(src).className= clrOver;
}

//   ==================================================================
//   || Funcion para cambiar de estilo al quitar el cursor de encima ||
//   ==================================================================
function mOut(src,clrIn) {
	window.status='';
	document.getElementById(src).className= clrIn;
}

//   ==================================================================
//   || Funcion para cambiar de estilo al quitar el cursor de encima ||
//   ==================================================================
function contenido(id){
	var obj=document.getElementById("contenido");
	obj.style.display='none';
	var ojeto=document.getElementById("cargando");
	ojeto.style.display='block';
	var objcon = true;
	objcon = objeto();
//	alert("hola");
	if (objcon){
		var parametros = "?funcion=contenido&valor="+id;
		objcon.open("GET",ruta_procesador+parametros,true);
		objcon.onreadystatechange = function(){
			if (objcon.readyState==1){
				obj.innerHTML = "";
			}
			else{
				if (objcon.readyState==4){
					if (objcon.status==200){
						obj.innerHTML = objcon.responseText;
						ojeto.style.display='none';
						obj.style.display='block';
					}
				}
			}
		}
		objcon.send(null);
	}
	else{
		alert("Ha ocurrido un error");
	}
}

//   ==================================================================
//   || Funcion para enviar un POST asíncrono para enviar los mails  ||
//   ==================================================================
function mail(){
	var objcon = true;
	objcon = objeto();
	if (objcon){
		var parameters = "mail_contacto="+document.getElementById("mail_contacto").value;
		parameters += "&mail_telefono="+document.getElementById("mail_telefono").value;
		parameters += "&mail_direccion="+document.getElementById("mail_direccion").value;
		parameters += "&mail_cp="+document.getElementById("mail_cp").value;
		parameters += "&mail_email="+document.getElementById("mail_email").value;
		parameters += "&mail_mensaje="+document.getElementById("mail_mensaje").value;
		objcon.open("POST",ruta_mail,true);
      objcon.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      objcon.setRequestHeader("Content-length", parameters.length);
      objcon.setRequestHeader("Connection", "close");
      objcon.send(parameters);
		objcon.onreadystatechange = function(){
			if (objcon.readyState==1){
				obj.innerHTML = "";
			}
			else{
				if (objcon.readyState==4){
					if (objcon.status==200){
						document.getElementById("infomail").innerHTML = "<font color=\"green\">Mensaje enviado correctamente.</font>";
						alert(objcon.responseText);
					}
				}
			}
		}
		objcon.send(null);
	}
	else{
		alert("Ha ocurrido un error");
	}
}

//   ==================================================================
//   || Funciónn AJAX de conexión									 ||
//   ==================================================================
function objeto(){
	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
}
