// JavaScript Document
function crearXMLHttpRequest() {
  var xmlHttp=null;
  if (window.ActiveXObject) 
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  else 
    if (window.XMLHttpRequest) 
      xmlHttp = new XMLHttpRequest();
  return xmlHttp;
}
function recibirDatos(){
	var resultados = document.getElementById("results");
	var boton = document.getElementById("enviar");
	var contacto = document.getElementById("contactForm");
	if (conexion1.readyState == 4) {
    	contacto.innerHTML = conexion1.responseText;
		resultados.innerHTML = ""
    }
	else{
		boton.value = "Enviando...";
		resultados.innerHTML = ""
	}
}
var conexion1;
function enviarMensaje(){
	var nombre = document.getElementById("nombre").value;
	var correo = document.getElementById("mail").value;
	var asunto = document.getElementById("asunto").value;
	var texto = document.getElementById("texto").value;
	conexion1 = crearXMLHttpRequest();
	conexion1.onreadystatechange = recibirDatos;
	conexion1.open("POST", "contact.php", true);
	conexion1.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	conexion1.send("nombre="+nombre+"&asunto="+asunto+"&mail="+correo+"&texto="+texto);
}
function validarMensaje(){
	var resultados = document.getElementById("results");
	var nombre = document.getElementById("nombre").value;
	var correo = document.getElementById("mail").value;
	var asunto = document.getElementById("asunto").value;
	var texto = document.getElementById("texto").value;
	var areatexto = document.getElementById("mail");
	var expRegular = /[\w-\.]{3,}@([\w-]{2,}\.)*([\w-]{2,}\.)[\w-]{2,4}/;
	if (nombre == "" || correo == "" || asunto == "" || texto == ""){
		resultados.innerHTML = "<p>No ha rellenado todos los campos</p>";
		areatexto.className = "textfield";
		}
	else if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(correo))){
		resultados.innerHTML = "<div id=\"error\">El correo electr\u00f3nico escrito no es v\u00e1lido<div>";
		areatexto.className = "textfield2";
		}
	else {
		enviarMensaje();
	}
}
var conexion2;
function procesarInscripcion(){
	var resultados = document.getElementById("results");
	var boton = document.getElementById("enviar");
	var inscripcion = document.getElementById("fi_body");
	if (conexion2.readyState == 4) {
    	inscripcion.innerHTML = conexion2.responseText;
		resultados.innerHTML = ""
    }
	else{
		boton.value = "Enviando...";
		resultados.innerHTML = ""
	}
}
function enviarInscripcion(){
	var resultados = document.getElementById("results");
	var nombrePadre = document.getElementById("nombrePadre").value;
	var apellidosPadre = document.getElementById("apellidosPadre").value;
	var nombre = document.getElementById("nombre").value;
	var apellidos = document.getElementById("apellidos").value;
	var sexo = document.getElementById("sexo").value;
	var dia = document.getElementById("dia").value;
	var mes = document.getElementById("mes").value;
	var ano = document.getElementById("ano").value;
	var residencia = document.getElementById("residencia").value;
	var localidad = document.getElementById("localidad").value;
	var provincia = document.getElementById("provincia").value;
	var cp = document.getElementById("cp").value;
	var telefono = document.getElementById("telefono").value;
	var observaciones = document.getElementById("observaciones").value;
	conexion2 = crearXMLHttpRequest();
	conexion2.onreadystatechange = procesarInscripcion;
	conexion2.open("POST", "formulario1.php", true);
	conexion2.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	conexion2.send("nombre="+nombre+"&apellidos="+apellidos+"&nombrePadre="+nombrePadre+"&apellidosPadre="+apellidosPadre+"&dia="+dia+"&mes="+mes+"&ano="+ano+"&residencia="+residencia+"&localidad="+localidad+"&provincia="+provincia+"&cp="+cp+"&telefono="+telefono+"&observaciones="+observaciones+"&sexo="+sexo);
}
function validarInscripcion(){
	var resultados = document.getElementById("results");
	var nombrePadre = document.getElementById("nombrePadre").value;
	var apellidosPadre = document.getElementById("apellidosPadre").value;
	var nombre = document.getElementById("nombre").value;
	var apellidos = document.getElementById("apellidos").value;
	var dia = document.getElementById("dia").value;
	var mes = document.getElementById("mes").value;
	var ano = document.getElementById("ano").value;
	var residencia = document.getElementById("residencia").value;
	var localidad = document.getElementById("localidad").value;
	var provincia = document.getElementById("provincia").value;
	var cp = document.getElementById("cp").value;
	var telefono = document.getElementById("telefono").value;
	if (nombre == "" || telefono == "" || apellidos == "" || nombrePadre == "" || apellidosPadre == "" || dia == "" || mes == "" || ano == "" || residencia == "" || localidad == "" || provincia == "" || cp == ""){
		resultados.innerHTML = "<p>No ha rellenado todos los campos</p>";
		}
	else if (!(/^([0-9])*$/.test(cp))){
		resultados.innerHTML = "<p>El c\u00f3digo postal escrito no es v\u00e1lido</p>";
		}
	else if (!(/^([0-9])*$/.test(telefono))){
		resultados.innerHTML = "<p>El telefono escrito no es v\u00e1lido</p>";
	}
	else {
		enviarInscripcion();
	}
}
var aux = 0;
function mostrarOcultarInfo(){
	var info = document.getElementById("moreInfo");
	if(aux == 0){
		info.style.display = "";
		aux = 1;
	}
	else {
		info.style.display = "none";
		aux = 0;		
	}
}
var aux2 = 0;
function mostrarOcultarInfo2(){
	var info = document.getElementById("moreInfo2");
	if(aux2 == 0){
		info.style.display = "";
		aux2 = 1;
	}
	else {
		info.style.display = "none";
		aux2 = 0;		
	}
}