
function valida_correo(email){
    regx = /^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$/;
    return regx.test(email);
}


/***************************************************************/
function limpiarFormulario(){
	document.form.action="central_temario.jsp";
	document.form.submit();
}


/******************************************************/


function soloNumero1(e)
{
  var key //= (window.event) ? event.keyCode : e.which;
  if (window.event)
    key = event.keyCode
  else
    key = e.which
  // Caracteres Numericos(0-9) o backspace (8)?
  if ( key > 47 && key < 58 || key == 8 )
    return; 
  else 
    if (window.event) //IE
      window.event.returnValue = null;     
	else //Firefox
      e.preventDefault();
}
/*****************************************************************/
function textCounter(field, countfield, maxlimit) {
	if (field.value.length > maxlimit) 
		field.value = field.value.substring(0, maxlimit);
	else 
		countfield.value = maxlimit - field.value.length;
}

/*************************************************************/
function trimReplace(cadena)
{
	for(i=0; i<cadena.length; )
	{
		if(cadena.charAt(i)==" ")
			cadena=cadena.substring(i+1, cadena.length);
		else
			break;
	}
	for(i=cadena.length-1; i>=0; i=cadena.length-1)
	{
		if(cadena.charAt(i)==" ")
			cadena=cadena.substring(0,i);
		else
			break;
	}	

	return cadena;
}

/************************************************************/

function validarFormulario()
{

	var vNombre;
	var vCalle;
	var vNumero;
	var vPiso;
	var vLocalidad;
	var vPoblacion;
	var vCodigoPostal;
	var vPais;
	var vTelefono;
	var vMail;
	var vMotivo;
	var vAceptado='';
	var vTurno='';
	
	var tNombre;
	var tCalle;
	var tNumero;
	var tPiso;
	var tLocalidad;
	var tPoblacion;
	var tCodigoPostal;
	var tPais;
	var tTelefono;
	var tMail;
	var tMotivo;
		
	vNombre=trimReplace(document.getElementById("nombre").value);
	vCalle=trimReplace(document.getElementById("calle").value);
	vNumero=trimReplace(document.getElementById("numero").value);
	vPiso=trimReplace(document.getElementById("piso").value);
	vLocalidad=trimReplace(document.getElementById("localidad").value);
	vPoblacion=trimReplace(document.getElementById("poblacion").value);
	vCodigoPostal=trimReplace(document.getElementById("codigo_postal").value);
	vPais=trimReplace(document.getElementById("pais").value);
	vTelefono=trimReplace(document.getElementById("telefono").value);
	vMail=trimReplace(document.getElementById("email").value);
	vMotivo=trimReplace(document.getElementById("motivo").value);

	if(document.getElementById("aceptadoN").checked){
		vAceptado='N';
	}

	if(document.getElementById("aceptadoS").checked){
		vAceptado='S';
	}

	if(document.getElementById("turnoL").checked){
		vTurno='L';
	}

	if(document.getElementById("turnoP").checked){
		vTurno='P';
	}	

	tNombre=vNombre.length;
	tCalle=vCalle.length;
	tNumero=vNumero.length;
	tPiso=vPiso.length;
	tLocalidad=vLocalidad.length;
	tPoblacion=vPoblacion.length;
	tCodigoPostal=vCodigoPostal.length;
	tPais=vPais.length;
	tTelefono=vTelefono.length;
	tMail=vMail.length;
	tMotivo=vMotivo.length;
	
	
	if (tNombre>0){
		if (tCalle>0){
			if (tNumero>0){
				if (tLocalidad>0){
					if (tPoblacion>0){
						if (tCodigoPostal>=5){
							if (tPais>0){
								if (tTelefono>=9){
									if ((tMail>0) && (valida_correo(vMail))){
										if (tMotivo>0){
											document.form.action="central_temario2.jsp?a=" + vAceptado + "&t=" + vTurno;
											document.form.submit();
										}else{
											alert("Por favor escriba el Motivo");
											document.getElementById("motivo").focus();
										}
									}else{
										alert("Por favor escriba un email válido");
										document.getElementById("email").focus();
									}
								}else{
									alert("Por favor un Teléfono válido");
									document.getElementById("telefono").focus();
								}
							}else{
								alert("Por favor escriba el País");
								document.getElementById("pais").focus();
							}
						}else{
							alert("Por favor escriba un Código Postal válido");
							document.getElementById("codigo_postal").focus();
						}
					}else{
						alert("Por favor escriba la Población");
						document.getElementById("poblacion").focus();
					}
				}else{
					alert("Por favor escriba la Localidad");
					document.getElementById("localidad").focus();
				}
			}else{
				alert("Por favor escriba el número de la calle");
				document.getElementById("numero").focus();
			}
		}else{
			alert("Por favor escriba la calle");
			document.getElementById("calle").focus();
		}
	}else{
		alert("Por favor introduzca el Nombre y apellidos");
		document.getElementById("nombre").focus();
	}
}	
	
function abrirPopupImagen(http){

	var opciones="toolbar=no,location=no, directories=no, status=no, menubar=no, scrollbars=1, resizable=no, width=650px; height=920px;";
	window.open(http,"",opciones);

	
}