//BORRAR campos
function borrarCampos(fr,origen){
	//si venimos desde formulario de contacto (tanto parte privada como pública)
	if (origen=="contacto"){
	fr.nombre.value = "";
	fr.apellidos.value = "";
	//fr.centro.value = "";
	fr.direccion.value = "";
	fr.cp.value = "";
	fr.ciudad.value = "";
	fr.provincia.value = "";
	fr.pais.value = "";
	fr.mail.value = "";
	fr.tfno.value = "";
	fr.comentarios.value = "";
	document.getElementById('mensajeError').innerHTML="";
	document.getElementById('mail').className = 'camposOK';
	document.getElementById('apellidos').className = 'camposOK';
	document.getElementById('nombre').className = 'camposOK';
	}
	//si venimos desde formulario de registro online de nuevo socio
	else if (origen=="nuevoSocio"){
	fr.dia.value = "--";
	fr.mes.value = "---------";
	fr.anio.value = "----";
	fr.tratamiento.value = "------";
	fr.nombre.value = "";
	fr.apellidos.value = "";
	//fr.centro.value = "-------------";
	fr.direccion.value = "";
	fr.cp.value = "";
	fr.ciudad.value = "";
	fr.provincia.value = "";
	fr.pais.value = "España";
	fr.tfno1.value = "";
	fr.tfno2.value = "";
	//fr.tfnoMovil.value = "";
	fr.mail.value = "";
	fr.dni.value = "";
	fr.fax.value = "";
	fr.direccionBanco.value = "";
	fr.ciudadBanco.value = "";
	fr.entidadBancaria.value = "";
	fr.entidad.value = "";
	fr.oficina.value = "";
	fr.dc.value = "";
	fr.cuenta.value = "";
	document.getElementById('mensajeError').innerHTML="";
	document.getElementById('tratamiento').className = 'camposOK';
	document.getElementById('nombre').className = 'camposOK';
	document.getElementById('apellidos').className = 'camposOK';
	//document.getElementById('centroTrabajo').className = 'camposOK';
	document.getElementById('direccio').className = 'camposOK';
	document.getElementById('coPos').className = 'camposOK';
	document.getElementById('ciudad').className = 'camposOK';
	document.getElementById('provincia').className = 'camposOK';
	document.getElementById('pais').className = 'camposOK';
	document.getElementById('tfno1').className = 'camposOK';
	document.getElementById('mail').className = 'camposOK';
	document.getElementById('campoDNI').className = 'camposOK';
	document.getElementById('direccionBanco').className = 'camposOK';
	document.getElementById('ciudadBanco').className = 'camposOK';
	document.getElementById('entidadBancaria').className = 'camposOK';
	document.getElementById('CCC').className = 'camposOK';
	document.getElementById('entidad').className = 'camposSubOK';
	document.getElementById('oficina').className = 'camposSubOK';
	document.getElementById('dc').className = 'camposSubOK';
	document.getElementById('cuenta').className = 'camposSubOK';
	}
	//si venimos desde buzón de sugerencias (parte privada)
	else{
	fr.asunto.value = "";
	fr.sugerencias.value = "";
	document.getElementById('mensajeError').innerHTML="";
	document.getElementById('sugerencias').className = 'camposOK';
	document.getElementById('asunto').className = 'camposOK';
	}
}

//////////////////////////////////////////////////////////////////////////
// Validacion de campos de la pantalla de CONTACTOS (pUBLICA Y PRIVADA) //
//////////////////////////////////////////////////////////////////////////
function chequeaContacto(fr){
//Nombre
	if (fr.nombre.value == ""){
	document.getElementById('nombre').className = 'camposERROR';
	nom=0;
	}
	else{
	document.getElementById('nombre').className = 'camposOK';
	nom=1;
	}

//Apellidos
	if (fr.apellidos.value == ""){
	document.getElementById('apellidos').className = 'camposERROR';
	apell=0;
	}
	else{
	document.getElementById('apellidos').className = 'camposOK';
	apell=1;
	}

// mail
	if (fr.mail.value == ""){
	document.getElementById('mail').className = 'camposERROR';
	email=0;
	}
	else{
	document.getElementById('mail').className = 'camposOK';
	email=1;
	}

mensajesError=new Array()
mensajesError[0]="<table width='497'  border='0' cellspacing='0' cellpadding='0'><tr>  <td height='25' align='right' bgcolor='#FFF2F2' class='camposERROR'>Por favor, rellene todos los <U>campos obligatorios</U> que aparecen marcados en rojo&nbsp;&nbsp;&nbsp;&nbsp;</td></tr></table>";
mensajesError[1]="";

	//cuando ya está todo correcto
	if (nom!=0 && apell!=0 && email!=0){	
		//una vez que está todo relleno, miramos si la dirección de correo es correcta;
		var valor=fr.mail.value;
		if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor)){
		document.getElementById('mail').className = 'camposOK';
		document.getElementById('mensajeError').innerHTML=mensajesError[1];
		fr.submit();
		}
		else{ 
		document.getElementById('mensajeError').innerHTML="<table width='497'  border='0' cellspacing='0' cellpadding='0'><tr>  <td height='25' align='right' bgcolor='#FFF2F2' class='camposERROR'>El correo electrónico: '" + valor + "'  no es correcto.&nbsp;&nbsp;&nbsp;&nbsp;</td></tr></table>";
		document.getElementById('mail').className = 'camposERROR';
		fr.mail.focus();
		}
	}
	else{
	document.getElementById('mensajeError').innerHTML=mensajesError[0];
	}
}

/////////////////////////////////////////////////////////////
// Validacion de campos de la pantalla de REGISTRO ONLINE. //
/////////////////////////////////////////////////////////////
function BuscaLetra(cadena,fr){
var numero=0;
	for(i=0;i<cadena.length;i++){
		if(cadena.charAt(i)=="'") numero++;
	}
	if (numero!=0){
	fr.nombre.value=fr.nombre.value.replace("'","\'");
	}
}

function chequeaRegistro(fr){	
//Tratamiento
	if (fr.tratamiento.value == "------"){
	document.getElementById('tratamiento').className = 'camposERROR';
	trata=0;
	}
	else{
	document.getElementById('tratamiento').className = 'camposOK';
	trata=1;
	}

//Nombre
	if (fr.nombre.value == ""){
	document.getElementById('nombre').className = 'camposERROR';
	nom=0;
	}
	else{
	document.getElementById('nombre').className = 'camposOK';
	nom=1;
	}
	
//Apellidos
	if (fr.apellidos.value == ""){
	document.getElementById('apellidos').className = 'camposERROR';
	apell=0;
	}
	else{
	document.getElementById('apellidos').className = 'camposOK';
	apell=1;
	}
	
//Centro		
	//if (fr.centro.value == "-------------"){
	//document.getElementById('centroTrabajo').className = 'camposERROR';
	//centr=0;
	//}
	//else{
	//document.getElementById('centroTrabajo').className = 'camposOK';
	//centr=1;
	//}

//Direccion
	if (fr.direccion.value == ""){
	document.getElementById('direccio').className = 'camposERROR';
	direcc=0;
	}
	else{
	document.getElementById('direccio').className = 'camposOK';
	direcc=1;
	}

//CP
	if (fr.cp.value == ""){
	document.getElementById('coPos').className = 'camposERROR';
	codigoPostal=0;
	}
	else{
	document.getElementById('coPos').className = 'camposOK';
	codigoPostal=1;
	}

//ciudad
	if (fr.ciudad.value == ""){
	document.getElementById('ciudad').className = 'camposERROR';
	ciud=0;
	}
	else{
	document.getElementById('ciudad').className = 'camposOK';
	ciud=1;
	}
	
//provincia
	if (fr.provincia.value == ""){
	document.getElementById('provincia').className = 'camposERROR';
	prov=0;
	}
	else{
	document.getElementById('provincia').className = 'camposOK';
	prov=1;
	}

//pais
	if (fr.pais.value == ""){
	document.getElementById('pais').className = 'camposERROR';
	pai=0;
	}
	else{
	document.getElementById('pais').className = 'camposOK';
	pai=1;
	}
	
//telefono
	if (fr.tfno1.value == ""){
	document.getElementById('tfno1').className = 'camposERROR';
	telef=0;
	}
	else{
	document.getElementById('tfno1').className = 'camposOK';
	telef=1;
	}

// mail
	if (fr.mail.value == ""){
	document.getElementById('mail').className = 'camposERROR';
	email=0;
	}
	else{
	document.getElementById('mail').className = 'camposOK';
	email=1;
	}
	
// DNI
	if (fr.dni.value == ""){
	document.getElementById('campoDNI').className = 'camposERROR';
	dni=0;
	}
	else{
	document.getElementById('campoDNI').className = 'camposOK';
	dni=1;
	}
	
// direccionBanco
	if (fr.direccionBanco.value == ""){
	document.getElementById('direccionBanco').className = 'camposERROR';
	dBanco=0;
	}
	else{
	document.getElementById('direccionBanco').className = 'camposOK';
	dBanco=1;
	}
	
// ciudadBanco
	if (fr.ciudadBanco.value == ""){
	document.getElementById('ciudadBanco').className = 'camposERROR';
	cBanco=0;
	}
	else{
	document.getElementById('ciudadBanco').className = 'camposOK';
	cBanco=1;
	}

// entidad Bancaria
	if (fr.entidadBancaria.value == ""){
	document.getElementById('entidadBancaria').className = 'camposERROR';
	nBanco=0;
	}
	else{
	document.getElementById('entidadBancaria').className = 'camposOK';
	nBanco=1;
	}
	
// entidad CUENTA
	if (fr.entidad.value == ""){
	document.getElementById('CCC').className = 'camposERROR';
	document.getElementById('entidad').className = 'camposSubERROR';
	cuentaEntidad=0;
	}
	else{
	document.getElementById('CCC').className = 'camposOK';
	document.getElementById('entidad').className = 'camposSubOK';
	cuentaEntidad=1;
	}

// oficina CUENTA
	if (fr.oficina.value == ""){
	document.getElementById('CCC').className = 'camposERROR';
	document.getElementById('oficina').className = 'camposSubERROR';
	cuentaOficina=0;
	}
	else{
	document.getElementById('CCC').className = 'camposOK';
	document.getElementById('oficina').className = 'camposSubOK';
	cuentaOficina=1;
	}

// digito control CUENTA
	if (fr.dc.value == ""){
	document.getElementById('CCC').className = 'camposERROR';
	document.getElementById('dc').className = 'camposSubERROR';
	cuentaDC=0;	
	}
	else{
	document.getElementById('CCC').className = 'camposOK';
	document.getElementById('dc').className = 'camposSubOK';
	cuentaDC=1;
	}

// número de cuenta CUENTA
	if (fr.cuenta.value == ""){
	document.getElementById('CCC').className = 'camposERROR';
	document.getElementById('cuenta').className = 'camposSubERROR';
	cuentaNumero=0;
	}
	else{
	document.getElementById('CCC').className = 'camposOK';
	document.getElementById('cuenta').className = 'camposSubOK';
	cuentaNumero=1;
	}
mensajesError=new Array()
mensajesError[0]="<table width='100%'  border='0' cellspacing='0' cellpadding='0'><tr>  <td height='25' align='right' bgcolor='#FFF2F2' class='camposERROR'>Por favor, rellene todos los <U>campos obligatorios</U> que aparecen marcados en rojo&nbsp;&nbsp;&nbsp;&nbsp;</td></tr></table>";
mensajesError[1]="";

	//cuando ya está todo correcto
	if (trata!=0 && nom!=0 && apell!=0 && direcc!=0 && codigoPostal!=0 && ciud!=0 && prov!=0 && pai!=0 && telef!=0 && email!=0 && dni!=0 && dBanco!=0 && cBanco!=0 && nBanco!=0 && cuentaEntidad!=0 && cuentaOficina!=0 && cuentaDC!=0 && cuentaNumero!=0){	
		//una vez que está todo relleno, miramos si la dirección de correo es correcta
        var valor=fr.mail.value;
		if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor)){
		document.getElementById('mail').className = 'camposOK';
		document.getElementById('mensajeError').innerHTML=mensajesError[1];
			//el email es correcto y debemos controlar que el DNI también lo sea (por lo menos cuando sea un documento español)
			if (fr.pais.value==64){
				valorDNI= fr.dni.value;
				numero = valorDNI.substr(0,valorDNI.length-1);
				let = valorDNI.substr(valorDNI.length-1,1);
				numero = numero % 23;
				letra='TRWAGMYFPDXBNJZSQVHLCKET';
				letra=letra.substring(numero,numero+1);
				if (letra!=let){ 
				document.getElementById('mensajeError').innerHTML="<table width='100%'  border='0' cellspacing='0' cellpadding='0'><tr>  <td height='25' align='right' bgcolor='#FFF2F2' class='camposERROR'>El DNI: '" + valorDNI + "'  no es correcto.&nbsp;&nbsp;&nbsp;&nbsp;</td></tr></table>";
				}
				else{
				fr.submit();
				}
			}
			else{
			fr.submit();
			}
		}
		else{ 
		document.getElementById('mensajeError').innerHTML="<table width='100%'  border='0' cellspacing='0' cellpadding='0'><tr>  <td height='25' align='right' bgcolor='#FFF2F2' class='camposERROR'>El correo electrónico: '" + valor + "'  no es correcto.&nbsp;&nbsp;&nbsp;&nbsp;</td></tr></table>";
		document.getElementById('mail').className = 'camposERROR';
		fr.mail.focus();
		}
	}
	else{
	document.getElementById('mensajeError').innerHTML=mensajesError[0];
	}
}


/////////////////////////////////////////////////////////////
// Validacion de campos de la pantalla de SUGERENCIAS. //
/////////////////////////////////////////////////////////////

function chequeasugerencias(fr){	
// asunto
	if (fr.asunto.value == ""){
	document.getElementById('asunto').className = 'camposERROR';
	asun=0;
	}
	else{
	document.getElementById('asunto').className = 'camposOK';
	asun=1;
	}
	
// sugerencias
	if (fr.sugerencias.value == ""){
	document.getElementById('sugerencias').className = 'camposERROR';
	suger=0;
	}
	else{
	document.getElementById('sugerencias').className = 'camposOK';
	suger=1;
	}

mensajesError=new Array()
mensajesError[0]="<table width='470'  border='0' cellspacing='0' cellpadding='0'><tr><td height='25' align='right' bgcolor='#FFF2F2' class='camposERROR'>Por favor, rellene todos los <U>campos obligatorios</U> que aparecen marcados en rojo&nbsp;&nbsp;&nbsp;&nbsp;</td></tr></table>";
mensajesError[1]="";
	
	//cuando ya está todo correcto
	if ( asun!=0 && suger!=0){	
		document.getElementById('mensajeError').innerHTML=mensajesError[1];
		fr.submit();
	}
	else{
	document.getElementById('mensajeError').innerHTML=mensajesError[0];
	}
}
