function EnviaFormulario() {
	if (ValidaFormulario()) {
		sendForm('/group/detail','Formulario_norma','contenido_grupo');
	}
	return false;
}

function ValidaFormulario(){
	return true;
}

function validate_registration_form () {
		var msg ="";

		var emailFilter=/^.+@.+\..+$/;

		var usuario = document.getElementById("Usuario").value;
		var pass1 = document.getElementById("Pass").value;
		var pass2 = document.getElementById("Pass2").value;
		var nif = document.getElementById("GRU_IDENTIFICACION").value;
		var mail = document.getElementById("GRU_EMAIL").value;
		var movil = document.getElementById("GRU_MOVIL").value;
		var fijo = document.getElementById("GRU_TELEFONO").value;
		var condiciones = document.getElementById("Aceptar").checked;

		var GRU_ENTIDAD = document.getElementById("GRU_ENTIDAD").value;
		var GRU_SUCURSAL = document.getElementById("GRU_SUCURSAL").value;
		var GRU_DC = document.getElementById("GRU_DC").value;
		var GRU_NUM_CUENTA = document.getElementById("GRU_NUM_CUENTA").value;

		if (usuario=="") msg+="- Usuario\r\n";
		else if (usuario.length>12 || usuario.length<3) msg+="- Usuario (3 a 12 caracteres)\r\n";

		if (pass1=="") msg+="- Contraseña 1\r\n";
		if (pass2=="") msg+="- Contraseña 2\r\n";
		else if (pass1!=pass2) msg+="- Contraseñas distintas\r\n";
		else if (pass1.length>12 || pass1.length<3) msg+="- Contraseña (3 a 12 caracteres)\r\n";

		if (mail=="") msg+="- Email\r\n";
		else if (!emailFilter.test(mail)) msg+="- Email erroneo\r\n";

		if (movil=="" && fijo=="") msg+="- Teléfono móvil o fijo\r\n";
		if (condiciones==false) msg+="- Condiciones de uso\r\n";
		if (msg!="") {
			msg = "Por favor compruebe los siguientes campos:\r\n" +msg;
			alert (msg);
			return false;
		} else {
			if (ValidarCCC(GRU_ENTIDAD,GRU_SUCURSAL,GRU_DC,GRU_NUM_CUENTA)) {
				if (validarNIF(nif) || validarCIF(nif)) {
					validarUsuarioUnico(usuario);
					return false;
				}
		 		else {
		 			alert ("Por favor rellene el campo CIF/NIF");
					return false;
		 		}
			} else return false;
		}
}


function validarUsuarioUnico(usuario) {
	var handleSuccess = function(o){
		if(o.responseText !== undefined){
		   var respuesta = o.responseText;
		   if (respuesta == "OK") {
		   	document.getElementById("Formulario_Alta").submit();
		   	return true;
		   }
		   else {
			alert ("Ese nombre de usuario ya esta siendo utilizado. Seleccione otro por favor.");
		   	return false;
		   }
		}
	}
	var callback =
	{
	  success:handleSuccess
	};

	var request = YAHOO.util.Connect.asyncRequest('POST', '/admin/test-duplicate-user/user/'+usuario, callback );
}
/*******************************
 Validación del nif. Por Carlitos. carlosbernad@teleline.es
 Si usas este script, deja intactas estas líneas (créditos). Vale?
 También te agradecería un e-mail con tus comentarios.
*******************************/
function validarNIF(abc)
{
	//abc=document.formulario.nif.value
	dni=abc.substring(0,abc.length-1)
	let=abc.charAt(abc.length-1)
	if (!isNaN(let)) return false
	else {
		cadena="TRWAGMYFPDXBNJZSQVHLCKET"
		posicion = dni % 23
		letra = cadena.substring(posicion,posicion+1)
		if (letra!=let.toUpperCase()) return false
	}
	return true;
}
//Su explorador no soporta java o lo tiene deshabilitado; esta pagina necesita javascript para funcionar correctamente<!--
//Copyright © McAnam.com
	function validarCIF(texto){

		var pares = 0;
		var impares = 0;
		var suma;
		var ultima;
		var unumero;
		var uletra = new Array("J", "A", "B", "C", "D", "E", "F", "G", "H", "I");
		var xxx;

		texto = texto.toUpperCase();

		var regular = new RegExp(/^[ABCDEFGHKLMNPQS]\d\d\d\d\d\d\d[0-9,A-J]$/g);
		 if (!regular.exec(texto)) return false;

		 ultima = texto.substr(8,1);

		 for (var cont = 1 ; cont < 7 ; cont ++){
			 xxx = (2 * parseInt(texto.substr(cont++,1))).toString() + "0";
			 impares += parseInt(xxx.substr(0,1)) + parseInt(xxx.substr(1,1));
			 pares += parseInt(texto.substr(cont,1));
		 }
		 xxx = (2 * parseInt(texto.substr(cont,1))).toString() + "0";
		 impares += parseInt(xxx.substr(0,1)) + parseInt(xxx.substr(1,1));

		 suma = (pares + impares).toString();
		 unumero = parseInt(suma.substr(suma.length - 1, 1));
		 unumero = (10 - unumero).toString();
		 if(unumero == 10) unumero = 0;

		 if ((ultima == unumero) || (ultima == uletra[unumero]))
			 return true;
		 else
			 return false;

	}
//------------------------------------------------------------
// Rutina de validación del codigo cuenta cliente de un banco
// Justino Martinez, 2003
// http://www.webviva.com
// http://www.webviva.com/biblioteca
//------------------------------------------------------------

// Funcion que chequea los dos digitos de control
// Creada originalmente por Daniel Rodriguez y Joaquin
// Bravo y publicada en
// http://programacion.com/html/articulo/tw_ccc/
function DigitoControl(cadena){
	var cifras = new Array(1,2,4,8,5,10,9,7,3,6);
	var chequeo = 0;
	for (var i=0; i < cifras.length; i++){
		chequeo += parseInt(cadena.charAt(i)) * cifras[i];
	}
	chequeo = 11 - (chequeo % 11);
	if (chequeo == 11) {chequeo = 0;}
	if (chequeo == 10) {chequeo = 1;}
	return chequeo;
}

// Funcion que comprueba que "valor" es un numero entero
function EsNumeroEntero(valor){
	var cadena = valor.toString();
	var longitud = cadena.length;
	if (longitud == 0){return false;}
	var ascii = null;
	for (var i=0; i<longitud; i++) {
		ascii = cadena.charCodeAt(i);
		if (ascii < 48 || ascii > 57){return false;}
	}
	return true;
}

// Funcion que valida el codigo de cuenta cliente
function ValidarCCC(entidad,oficina,dc,nc) {

	// Comprobamos que solo hemos introducido numeros
	if (!EsNumeroEntero(entidad)){
		alert("Debe introducir el número de entidad bancaria");
		return false;
	}
	if (!EsNumeroEntero(oficina)){
		alert("Debe introducir el número de oficina");
		return false;
	}
	if (!EsNumeroEntero(dc)){
		alert("Debe introducir los dos dígitos de control");
		return false;
	}
	if (!EsNumeroEntero(nc)){
		alert("Debe introducir el número de cuenta");
		return false;
	}
	// Comprobamos el primer digito de control
	var primer_control="00"+entidad+oficina;
	var primer_digito=DigitoControl(primer_control);
	if (primer_digito != dc.charAt(0)){
		alert("El código de cuenta cliente proporcionado no es válido");
		return false;
	}

	// Comprobamos el segundo digito de control
	var segundo_control=nc;
	var segundo_digito=DigitoControl(segundo_control);
	if (segundo_digito != dc.charAt(1)){
		alert("El código de cuenta cliente proporcionado no es válido");
		return false;
	}

	// Si todo es correcto enviamos el formulario
	return true;
}

/*
var monthLength = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
function ValidaFecha(name)
{
	var x = document.forms[0].elements;
	var day = parseInt(x[name+"Dia"].options[x[name+"Dia"].selectedIndex].value);
	var month = parseInt(x[name+"Mes"].options[x[name+"Mes"].selectedIndex].value);
	var year = parseInt(x[name+"Ano"].options[x[name+"Ano"].selectedIndex].value);

	if (!day || !month || !year)
		return false;

	if (year/4 == parseInt(year/4))
		monthLength[1] = 29;

	if (day > monthLength[month-1])
		return false;

	monthLength[1] = 28;

	var now = new Date();
	now = now.getTime(); //NN3

	var dateToCheck = new Date();
	dateToCheck.setYear(year);
	dateToCheck.setMonth(month-1);
	dateToCheck.setDate(day);
	var checkDate = dateToCheck.getTime();

	var futureDate = (now < checkDate);
	var pastDate = (now > checkDate);

	return checkDate;
}
*/
function validate_testit_form() {
		var msg ="";

		var emailFilter=/^.+@.+\..+$/;
		//var webFilter = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
		//var webFilter=/^(http[s]?\:\/\/)?[0-9a-zA-Z][\-\w][\.\w\-]+$/i;
		//var webFilter=/^((ht|f)tp(s?)\:\/\/)?[0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*(:(0-9)*)*(\/?)( [a-zA-Z0-9\-\.\?\,\’\/\\\+&amp;%\$#_]*)?$/;

		var name = document.getElementById("name").value;
		var surname = document.getElementById("surname").value;
		var mail = document.getElementById("mail").value;
		var phone = document.getElementById("phone").value;
		var web = document.getElementById("web").value;
		var company = document.getElementById("company").value;

		if (name=="") 		msg+="- Nombre\r\n";
		if (surname=="") 	msg+="- Apellidos\r\n";
		if (mail=="") 		msg+="- Email\r\n";
		else if (!emailFilter.test(mail))
							msg+="- Email erroneo\r\n";
		if (company=="") 	msg+="- Compañia\r\n";
		//if (web!="" && !webFilter.test(web))
		//					msg+="- Web erronea\r\n";
		if (phone=="") 		msg+="- Teléfono\r\n";

		if (msg!="") {
			msg = "Por favor compruebe los siguientes campos:\r\n" +msg;
			alert (msg);
			return false;
		} else return true;
}

function validate_contact_form() {
		var msg ="";

		var emailFilter=/^.+@.+\..+$/;

		var nombre = document.getElementById("Nombre").value;
		var mail = document.getElementById("Mail").value;
		var telefono = document.getElementById("Telefono").value;
		var asunto = document.getElementById("Asunto").value;
		var observaciones = document.getElementById("Observaciones").value;

		if (nombre=="") 	msg+="- Nombre\r\n";
		if (telefono=="") 	msg+="- Teléfono\r\n";
		if (mail=="") 		msg+="- Email\r\n";
		else if (!emailFilter.test(mail))
							msg+="- Email erroneo\r\n";
		if (asunto=="") 	msg+="- Asunto\r\n";
		if (observaciones=="") msg+="- Observaciones\r\n";

		if (msg!="") {
			msg = "Por favor compruebe los siguientes campos:\r\n" +msg;
			alert (msg);
			return false;
		} else return true;
}
