function ocultarCapa(){
	document.getElementById('error-campos').style.visibility = "hidden";
}

function validarForm(){
	var error = "";
	var salto = "<br />"

	if(document.fqueharias.nombre.value == ""){
		error01 = "Nombre"
		error = error + salto + error01;
	}
	if(document.fqueharias.apellidos.value == ""){
		error02 = "Apellidos"
		error = error + salto + error02;
	}
	if(document.fqueharias.localidad.value == ""){
		error03 = "Localidad"
		error = error + salto + error03;
	}
	if(document.fqueharias.provincia.selectedIndex == 0){
		error04 = "Provincia"
		error = error + salto + error04;
	}
	if(document.fqueharias.tlf.value == "" || document.fqueharias.tlf.value.length != 9 || !esnumero(document.fqueharias.tlf.value)){
		error05 = "Tel&eacute;fono de contacto"
		error = error + salto + error05;
	}
	if(document.fqueharias.email.value == "" || !mira_email(document.fqueharias.email.value)){
		error06 = "E-mail de contacto"
		error = error + salto + error06;
	}
	if(document.fqueharias.url_video.value == "" || document.fqueharias.url_video.value.indexOf('http://www.youtube.com/watch?v=') == -1){ /* si se pone ...value.indexOf('http://') no lo cogerá por las barras. SI NO LO ENCUENTRA DARÁ -1*/
		error07 = "Enlace a tu v&iacute;deo en YouTube"
		error = error + salto + error07;
	}
		
	
	if(error != "" || document.fqueharias.legal.checked == false){
		document.getElementById('error-campos').style.visibility = "visible";
		document.getElementById('campos').innerHTML = "Por favor, revisa los siguientes campos:<br />" + error + "<br />.......................................<br /><span style='color:#666666'>No olvide leer y aceptar el aviso legal</span>";		
		return(false);	
		
	} else {
		document.fqueharias.submit();
		/*
		parametros = GenerarParametrosForm(document.getElementById("fqueharias"));
		makePOSTRequest('registro.jsp', parametros, enviar_registro_retorno);
		return(false);
		*/
	}
}

function enviar_registro_retorno()
{
	var retorno = alertContents();
	if (retorno != "")
	{
		array_retorno = retorno.split("=");
		array_retorno[1] = array_retorno[1].trim();
		if (array_retorno[1] == "0&")
		{
			document.getElementById("error").style.display = "none";
			document.getElementById("blqgracias").style.display = "block";
		}
		if (array_retorno[1] == "1&")
		{
			document.getElementById("blqgracias").style.display = "none";
			document.getElementById("error").style.display = "none";
		}
		if (array_retorno[1] != "1&" && array_retorno[1] != "0&")
		{ 
			document.getElementById("blqgracias").style.display = "none";
			document.getElementById("error").style.display = "block";
		}						
	}
}

function mira_email(cadena){
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	return (filter.test(cadena));
}	
function esnumero(cadena){
	var filter = /^([0-9])+$/;
	return (filter.test(cadena));
}

function homeemail(){
		
	if(document.herror.email.value == "" || !mira_email(document.herror.email.value)){
		document.getElementById('error').style.display = "block";	
		/*document.getElementById('avisook').style.display = "none";*/	
	}
	else{
		document.getElementById('error').style.display = "none";
		document.herror.submit();
	}
}
function validarqueharias()
{
	//alert("validarqueharias");
	var f = document.getElementById('fqueharias');
	var error = "";
	if(mira_email(f.email_registrado.value))
	{
		// error = "";
	}else if(!mira_email(f.email_registrado.value) && !mira_email(f.email.value)){
		error += "Dirección de e-mail<br />";
		// document.getElementById('queharias-formu-aviso').style.display = 'block';
	}else{
		if(f.nombre.value.length<1) error += "Nombre<br />";
		if(f.apellidos.value.length<1) error += "Apellidos<br />";
		if(f.localidad.value.length<1) error += "Localidad<br />";
		if(f.tlf.value.length<8) error += "Teléfono<br />";
		if(f.provincia.selectedIndex == 0) error += "Provincia<br />";
		if(!f.aviso.checked) error += "Aviso Legal";
		
		// alert("debe introducir todos los datos");
		// document.getElementById('queharias-formu-aviso').style.display = 'block';
	}
	if(error.length>1) {
		var divdivcampos = document.getElementById('error-campos');
		var divcampos = document.getElementById('campos');
		
		divcampos.innerHTML = "Por favor, revisa los siguientes campos:<br />" + error + "<br />.......................................<br /><span style='color:#666666'>No olvide leer y aceptar el aviso legal</span>";
		divdivcampos.style.visibility = "visible";
		
		return(false);	
	}else{
		/*
		//document.getElementById('queharias-gracias').style.display = "block";
		document.getElementById('queharias-cuentanos').style.display = "none";
		document.getElementById('queharias-form').style.display = "none";
		document.getElementById('queharias-botones-envio').style.display = "none";
		document.getElementById('queharias-div-email').style.display = "none";
		document.getElementById('queharias-div-nuevo').style.display = "none";
		*/
		f.submit();	
	}
}
function validarquehariasnuevo()
{	
	//alert("validarquehariasnuevo");
	var f = document.getElementById('fqueharias');
	var error = "";

	if(f.nombre.value.length<1) error += "Nombre<br />";
	if(f.apellidos.value.length<1) error += "Apellidos<br />";
	if(f.localidad.value.length<1) error += "Localidad<br />";
	if(f.tlf.value.length<1) error += "Teléfono<br />";
	if(!mira_email(f.email.value)) error += "Dirección de e-mail";
	
	if(error.length>1) {
		var divdivcampos = document.getElementById('error-campos');
		var divcampos = document.getElementById('campos');
		
		divcampos.innerHTML = "Por favor, revisa los siguientes campos:<br />" + error + "<br />.......................................<br /><span style='color:#666666'>No olvide leer y aceptar el aviso legal</span>";
		divdivcampos.style.visibility = "visible";
		
		return(false);	
	}else{
		f.submit();	
		//document.getElementById('queharias-gracias').style.display = "block";
		//document.getElementById('queharias-div-nuevo').style.display = "none";
	}
}
function validarquehariasnonuevo()
{
	//alert("validarquehariasnonuevo");
	var f = document.getElementById('fqueharias');
	var error = "";
	if(!mira_email(f.email_registrado.value))
	{
		error += "Dirección de e-mail<br />";
	}
	if(error.length>1) {
		var divdivcampos = document.getElementById('error-campos');
		var divcampos = document.getElementById('campos');
		
		divcampos.innerHTML = "Por favor, revisa los siguientes campos:<br />" + error + "<br />.......................................<br /><span style='color:#666666'>No olvide leer y aceptar el aviso legal</span>";
		divdivcampos.style.visibility = "visible";
		
		return(false);	
	}else{
		f.submit();	
		//document.getElementById('queharias-gracias').style.display = "block";
		//document.getElementById('queharias-div-email').style.display = "none";
	}
}
