// JavaScript Document
function saluda(){
	alert ("hola");
}

function fvalido(formu){
	if(formu.nombre.value==""){
		alert("Debe completar los campos obligatorios");
		return false;
	}
	if(formu.apellidos.value==""){
		alert("Debe completar los campos obligatorios");
		return false;
	}
	if(formu.mail.value==""){
		alert("Debe completar los campos obligatorios");
		return false;
	}
	
	if(formu.sexo.value=="-1"){
		alert("Debe indicar su sexo, hombre/mujer");
		return false;
	}
	if(formu.pais.value=="-1"){
		alert("Debe indicar su País");
		return false;
	}
	if(formu.cargo.value=="-1"){
		alert("Debe indicar su cargo");
		return false;
	}
	if(formu.corpo.value==""){
		alert("Corporación es un campo obligatorio");
		return false;
	}	
	if(formu.mail.value.search(/^[A-Za-z][A-Za-z0-9._-]*@[A-Za-z0-9_-]+\.[A-Za-z0-9_.]+[A-za-z]$/))
	{
		if(formu.mail.value!="917402458@telefonica.net"){
        	alert("La direccion Mail no es valida. Formato correcto: nombre@servidor.dominio");
        	return false;
		}
    }
	if(formu.domicilio.value==""){
		alert("Debe completar los campos obligatorios");
		return false;
	}
	if(formu.provincia.value==""){
		alert("Debe completar los campos obligatorios");
		return false;
	}	
	if(formu.pais.value==""){
		alert("Debe completar los campos obligatorios");
		return false;
	}
	if(formu.fpago.value==""){
		alert("Debe completar los campos obligatorios");
		return false;
	}

	var $estado;
	for(i=0;i<formu.fpago.length; i++){
		if(formu.fpago[i].checked){
			$estado="si";
			if(formu.fpago[i].value=="p_mexico"){ 
				if(formu.pais.value!="MÃ©xico"){
					alert("Esta forma de pago es para residentes en mexico");
					return false;
				}
				else{
					return true;	
				}
			}
			else{
				return true;	
			}
		}else{
			$estado="no";
		}
	}
	if($estado=="no"){
		alert("Debe seleccionar una Forma de Pago");
		return false;
	}
}

function validaResponsableStand(formu){
	if(formu.nombre.value==""){
		alert("Nombre es un campo obligatorio");
		document.getElementById('fnresponsable').nombre.style.backgroundColor="yellow";
		return false;
	}else{
		document.getElementById('fnresponsable').nombre.style.backgroundColor="white";		
	}
	if(formu.apellidos.value==""){
		alert("Apellidos es un campo obligatorio");		
		document.getElementById('fnresponsable').apellidos.style.backgroundColor="yellow";		
		return false;
	}else{
		document.getElementById('fnresponsable').apellidos.style.backgroundColor="white";		
	}
	if((formu.dni.value=="")&&(formu.pasaporte.value=="")){
		alert("DNI o PASAPORTE son campos obligatorios");		
		document.getElementById('fnresponsable').dni.style.backgroundColor="yellow";		
		return false;
	}else{
		document.getElementById('fnresponsable').dni.style.backgroundColor="white";		
	}	
	if((formu.dni.value.length>0)&&(formu.dni.value.length<5)){
		alert("DNI no valido");		
		document.getElementById('fnresponsable').dni.style.backgroundColor="yellow";		
		return false;
	}else{
		document.getElementById('fnresponsable').dni.style.backgroundColor="white";		
	}	
	if(formu.mail.value==""){
		alert("eMail es un campo obligatorio");		
		document.getElementById('fnresponsable').mail.style.backgroundColor="yellow";		
		return false;
	}else{
		document.getElementById('fnresponsable').mail.style.backgroundColor="white";		
	}		
	if(formu.mail.value.search(/^[A-Za-z][A-Za-z0-9._-]*@[A-Za-z0-9_-]+\.[A-Za-z0-9_.]+[A-za-z]$/)){
		alert("eMail no valido.");		
		document.getElementById('fnresponsable').mail.style.backgroundColor="yellow";		
		return false;
	}else{
		document.getElementById('fnresponsable').mail.style.backgroundColor="white";		
	}
	if(formu.sexo.value=="-1"){
		alert("Sexo es un campo obligatorio...");		
		document.getElementById('fnresponsable').sexo.style.backgroundColor="yellow";		
		return false;
	}else{
		document.getElementById('fnresponsable').sexo.style.backgroundColor="white";		
	}	
	if(formu.domicilio.value==""){
		alert("domicilio es un campo obligatorio");		
		document.getElementById('fnresponsable').domicilio.style.backgroundColor="yellow";		
		return false;
	}else{
		document.getElementById('fnresponsable').domicilio.style.backgroundColor="white";		
	}
	if(formu.localidad.value==""){
		alert("localidad es un campo obligatorio");		
		document.getElementById('fnresponsable').localidad.style.backgroundColor="yellow";		
		return false;
	}else{
		document.getElementById('fnresponsable').localidad.style.backgroundColor="white";		
	}
	if(formu.provincia.value==""){
		alert("provincia es un campo obligatorio");		
		document.getElementById('fnresponsable').provincia.style.backgroundColor="yellow";		
		return false;
	}else{
		document.getElementById('fnresponsable').provincia.style.backgroundColor="white";		
	}
	if(formu.pais.value=="-1"){
		alert("pais es un campo obligatorio");		
		document.getElementById('fnresponsable').pais.style.backgroundColor="yellow";		
		return false;
	}else{
		document.getElementById('fnresponsable').pais.style.backgroundColor="white";		
	}	
	if(formu.cargo.value=="-1"){
		alert("cargo es un campo obligatorio");		
		document.getElementById('fnresponsable').cargo.style.backgroundColor="yellow";		
		return false;
	}else{
		document.getElementById('fnresponsable').cargo.style.backgroundColor="white";		
	}		
	return true;
}

function fvalidoOficio(formu){
	if(formu.nombre.value==""){
		alert("Debe completar los campos obligatorios");
		return false;
	}
	if(formu.apellidos.value==""){
		alert("Debe completar los campos obligatorios");
		return false;
	}
	if(formu.sexo.value=="-1"){
		alert("Debe indicar su sexo, hombre/mujer");
		return false;
	}
		
	if(formu.pais.value=="-1"){
		alert("Debe indicar su País");
		return false;
	}
	if(formu.cargo.value=="-1"){
		alert("Debe indicar su cargo");
		return false;
	}	
	if(formu.pais.value==""){
		alert("Debe completar los campos obligatorios");
		return false;
	}
	if(formu.fpago.value==""){
		alert("Debe completar los campos obligatorios");
		return false;
	}
	var $estado;
	for(i=0;i<formu.fpago.length; i++){
		if(formu.fpago[i].checked){
			$estado="si";
			return true;
		}else{
			$estado="no";
		}
	}
	if($estado=="no"){
		alert("Debe seleccionar una Forma de Pago");
		return false;
	}		
}

function fvalidoStand(formu){
	if(formu.nombreins.value==""){
		alert("Debe completar los campos obligatorios");
		return false;
	}
	if(formu.dedicacion.value==""){
		alert("Debe completar los campos obligatorios");
		return false;
	}
	if(formu.domicilioins.value==""){
		alert("Debe completar los campos obligatorios");
		return false;
	}
	if(formu.paisins.value==""){
		alert("Debe indicar su País");
		return false;
	}
	if(formu.mailins.value==""){
		alert("Corporación es un campo obligatorio");
		return false;
	}	
	if(formu.mailins.value.search(/^[A-Za-z][A-Za-z0-9._-]*@[A-Za-z0-9_-]+\.[A-Za-z0-9_.]+[A-za-z]$/))
	{
        alert("La direccion Mail no es valida. Formato correcto: nombre@servidor.dominio");
        return false;
    }
	if(formu.telefonoins.value==""){
		alert("Debe completar los campos obligatorios");
		return false;
	}
	return true;
}

function fvalidoDeclaracion(formu){ 
	if(formu.nombre.value==""){ 
		alert("Debe completar los campos obligatorios");
		return false;
	}
	if(formu.apellidos.value==""){ 
		alert("Debe completar los campos obligatorios");
		return false;
	}
	if(formu.pais.value==""){ 
		alert("Debe completar los campos obligatorios");
		return false;
	} 
	if(formu.email.value==""){ 
		alert("Debe completar los campos obligatorios");
		return false;
	}
	if(formu.comentario.value==""){ 
		alert("Debe completar los campos obligatorios");
		return false;
	}
	else{  
		var filtro=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
		if(filtro.test(formu.email.value)){
			return true;
		}else{
			alert("Introduzca un Mail válido: nombre@dominio");
			return false;
		}
	}
	
	
	return true;
}

function wopen(url, name, w, h)
{
	w += 32;
	h += 96;
	wleft = (screen.width - w) / 2;
	wtop = (screen.height - h) / 2;
	var win = window.open(url,
	name,
	'width=' + w + ', height=' + h + ', ' +
	'left=' + wleft + ', top=' + wtop + ', ' +
	'location=no, menubar=no, ' +
	'status=no, toolbar=no, scrollbars=no, resizable=no');
	// Just in case width and height are ignored
	win.resizeTo(w, h);
	// Just in case left and top are ignored
	win.moveTo(wleft, wtop);
	win.focus();
}
function wopen2(url, name, w, h){
	w += 32;
	h += 96;
	wleft = (screen.width - w) / 2;
	wtop = (screen.height - h) / 2;
	var win = window.open(url,
	name,
	'width=' + w + ', height=' + h + ', ' +
	'left=' + wleft + ', top=' + wtop + ', ' +
	'location=no, menubar=no, ' +
	'status=no, toolbar=no, scrollbars=yes, resizable=yes');
	// Just in case width and height are ignored
	win.resizeTo(w, h);
	// Just in case left and top are ignored
	win.moveTo(wleft, wtop);
	win.focus();
}
function enviaInscripcion(formu){
	if(fvalido(formu)){
		formu.submit();
	}
}
function enviaInscripcionOficio(formu){
	if(fvalidoOficio(formu)){
		formu.submit();
	}
}

function enviaSolicitudStand(formu){	
	if(fvalidoStand(formu)){
		formu.submit();
	}else{
		return false;
	}
}

function enviaDeclaracion(formu){ 
	if(fvalidoDeclaracion(formu)){ 
		formu.submit();	
	}else{ 
		return false;	
	}
}

function validarValor(evento, caja, formu){ 
	if (evento != 8 && evento != 9 && evento != 13 && evento != 46 && evento != 37 && evento != 38 && evento != 39 && evento != 40){
		var valor = document.getElementById(caja).value;
		if(valor >= 1 && valor <= 3){
			for(var i=0; i < formu.elements.length; i++){
				if(formu.elements[i].name != caja){		// si el elemento no es la caja de texto que ha lanzado el evento...
					if(formu.elements[i].name != "idinscrito"){
						if(formu.elements[i].value == valor){	// se comprueba si se le ha asignado ese número a otra opción
							alert("Ya le ha asignado este valor a otra temática");
							document.getElementById(caja).value = "";
							return;
						}
					}
				}
			}
		}
		else{
			alert("Debe de poner un número entre 1 y 3");
			document.getElementById(caja).value = "";
			return;	
		}
	}

	var total=0; 
	for(var i=0; i < formu.elements.length; i++){
		if(formu.elements[i].name != "enviar" && formu.elements[i].name != "valores" && formu.elements[i].name != "idinscrito"){
			if(formu.elements[i].value.length != 0){
				total++;	
			}
		}
	}

	if(total == 3){ 
		document.getElementById("enviar").style.visibility = "visible";
	}
	else{
		document.getElementById("enviar").style.visibility = "hidden";
	}
}

function fvalidoAcodel(formu){
	var	numeros = new Array();	// Array para almacenar los valores elegidos en el formulario
	var valores = "";			// cadena que almacenará la opción elegida y el valor seleccionado separados por ;
	
	for(var i=0; i < formu.elements.length; i++){
		var valor = formu.elements[i].value;
		if(valor == "1"){ 
			var v = parseInt(valor, 10); 
			numeros[v] = v;
			valores += formu.elements[i].name;
			valores += v;
			valores += ";"
		}
		else if(valor == "2"){
			var v = parseInt(valor, 10); 
			numeros[v] = v;
			valores += formu.elements[i].name;
			valores += v;
			valores += ";"			
		}
		else if(valor == "3"){
			var v = parseInt(valor, 10); 
			numeros[v] = v;
			valores += formu.elements[i].name;
			valores += v;
			valores += ";"			
		}
	}
	
	
	if(numeros.length == 4){ // numeros[0] = ""; numeros[1] = 1; numeros[2] = 2; numeros[3] = 3;
		if(numeros[1]==1 && numeros[2]==2 && numeros[3]==3){  	
			document.getElementById('valores').value = valores;		// almacenamos en el formulario la cadena con los valores escritos
			formu.submit();
		}
		else{
			alert("Los valores introducidos son incorrectos");
		}
	}
	else{
		alert("Hay que introducir tres valores");	
	}
}


