
var mensaje = "Para poder participar, por favor rellene todos los campos";

function pasarVariables(pagina, nombres) {
  pagina +="?";
  nomVec = nombres.split(",");
  for (i=0; i<nomVec.length; i++)
    pagina += nomVec[i] + "=" + escape(eval(nomVec[i]))+"&";
  pagina = pagina.substring(0,pagina.length-1);
   window.open(pagina,'voto','width=450,height=500,top=100,left=100,scrollbars=yes');	
}

function comprueba_cp()
{
    var error=0;  
    if (isNaN(document.forms.formtest.cp.value))
    {  
     alert("El campo Código postal debe ser numérico");
	 document.forms.formtest.cp.value="";	
     document.forms.formtest.cp.focus();
    }

	else if (eval('document.forms.formtest.cp.value.length')<5)
   	{
	alert('El Código postal debe contener 5 dígitos');
    document.forms.formtest.cp.value="";
	document.forms.formtest.cp.focus();
    }

    num=eval('document.forms.formtest.cp.value');
    prime=num.substring(0,2);

    if ((prime>52) || (eval('prime')=="00") )
    {
	alert('El Código postal introducido no es correcto'); 
    document.forms.formtest.cp.value="";
	document.forms.formtest.cp.focus();
    }
}




function asigna()
{
	w=document.forms.formtest.listado.selectedIndex;
	v=w;

}



function esVacia(palabra) {

  if (palabra==""){
     return true;

	}else{
		if (palabra.charAt(0)== " "){
			var indice = 1;
	 	    while (indice < palabra.length) {
		      if (palabra.charAt(indice) != " "){
			      return false;
		 	  }
	          indice++;
		    }
			return true;

		}else{
			return false;
		}
	}

	return true;
}
 
 
function quitablancos(string) {
var temp = "";
string = '' + string;
splitstring = string.split(" ");
for(i = 0; i < splitstring.length; i++)
temp += splitstring[i];
return temp;
}


function quitablancos(string) {
var temp = "";
string = '' + string;
splitstring = string.split(" ");
for(i = 0; i < splitstring.length; i++)
temp += splitstring[i];
return temp;
}


function no_codigo(campo) {
var txt1="";
var campo1=eval("document.forms.formtest."+campo+".value");
var mensaje="No puedes introducir código en éste campo de texto.";
campo=eval('campo');
txt=eval("document.forms.formtest."+campo+".value");
txt=quitablancos(txt);
txt1= txt.indexOf('<script');
txt2=  txt.indexOf('<font');
txt3=  txt.indexOf('<br');
txt4=  txt.indexOf('<body');

if ((txt1!= -1)||(txt2!= -1)||(txt3!= -1)||(txt4!= -1))
	{
		alert(mensaje);
		eval("document.forms.formtest."+campo+".value=''");
		eval("document.forms.formtest."+campo+".focus()");
	}
}
function valida()
 {

	
	if (document.forms.formtest.listado.selectedIndex==0)
	{
	  alert (' Debe seleccionar un castillo');
     	  document.forms.formtest.listado.focus();
	  return false;

	}

	if (document.forms.formtest.nombre.value=="" || esVacia(document.forms.formtest.nombre.value)) 
	{	
	  alert (' Debe introducir su nombre');
     	  document.forms.formtest.nombre.focus();
	  return false;
	}
	if (document.forms.formtest.apellidos.value=="" || esVacia(document.forms.formtest.apellidos.value)) 
	{	
	  alert (' Debe introducir sus apellidos');
     	  document.forms.formtest.apellidos.focus();
	  return false;
	}	
	
	if (document.forms.formtest.telefono.value=="" || esVacia(document.forms.formtest.telefono.value)) 
	{
	  alert (' Debe introducir su número de teléfono');
     	  document.forms.formtest.telefono.focus();
	  return false;
	}
	else if (isNaN(document.forms.formtest.telefono.value))
	{
	
	  alert ('El número de télefono introducido no es correcto');
	 document.forms.formtest.telefono.value="";			
     	  document.forms.formtest.telefono.focus();
	  return false;

	} else if (document.forms.formtest.telefono.value.length<9)
	 {
	  alert ('El número de télefono debe contener 9 dígitos');
	 document.forms.formtest.telefono.value="";			
     	  document.forms.formtest.telefono.focus();
	  return false;
	}	

		
	if (document.forms.formtest.cp.value=="" || esVacia(document.forms.formtest.cp.value)) 
	{	
	  alert (' Debe introducir su código postal');
     	  document.forms.formtest.cp.focus();
	  return false;
	}
	
	if (document.forms.formtest.provincia.selectedIndex==0)
	{
	  alert (' Debe seleccionar su provincia');
     	  document.forms.formtest.provincia.focus();
	  return false;

	}
	if (document.forms.formtest.email.value=="" || esVacia(document.forms.formtest.email.value)) 
	     {	
	          alert (' Debe introducir su dirección de correo');
     	          document.forms.formtest.email.focus();
	           return false;
	      }
	      else   if (document.forms.formtest.email.value.indexOf("@") == -1)
        	      {
	          alert('Debe introducir una dirección de correo valida');
                               document.forms.formtest.email.value="";		
	         document.forms.formtest.email.focus();	
	          return false;
	     }

	v=eval("document.forms.formtest.r1[0].checked");
	w=eval("document.forms.formtest.r1[1].checked");
	if (( v == false)&& (w==false))
		{
		alert ('Debe introducir su sexo');
		return false;
		}

	e1=eval("document.forms.formtest.r2[0].checked");
	e2=eval("document.forms.formtest.r2[1].checked");
	e3=eval("document.forms.formtest.r2[2].checked");
	e4=eval("document.forms.formtest.r2[3].checked");
	e5=eval("document.forms.formtest.r2[4].checked");
	if (( e1 == false)&& (e2==false)&&(e3==false)&&(e4==false)&&(e5==false))
		{
		alert ('Debe introducir su edad');
		return false;
		}

	f1=eval("document.forms.formtest.r3[0].checked");
	f2=eval("document.forms.formtest.r3[1].checked");
	f3=eval("document.forms.formtest.r3[2].checked");
	f4=eval("document.forms.formtest.r3[3].checked");
	f5=eval("document.forms.formtest.r3[4].checked");
	if (( f1 == false)&& (f2==false)&&(f3==false)&&(f4==false)&&(f5==false))
		{
		alert ('Por favor valore la iniciativa de restaurar un castillo');
		return false;
		}
		
   document.forms.formtest.submit();
   return enviado();

}

//David
var cuenta=0;

function enviado() {
   if (cuenta == 0)
      {
      cuenta++;
      return true;
      }
   else
      {
      alert("Su solicitud ya ha sido cursada, muchas gracias.");
      return false;
      }
   }

