var LETRAS = "TRWAGMYFPDXBNJZSQVHLCKET"; // Tabla predefinida de letras para el N.I.F y tarjeta de residencia

$ = jQuery;

var jquery= { 										
	muestratlf : function() {
		if($("#telefono").val()==""){
			$("#marca").hide();
			$("#p1").hide();
		}	
	else{							
			for( i=0; i < manufacturer.length; i++) {
				var manufacturerOption = document.createElement('option');
				manufacturerOption.value = manufacturer[i];
				manufacturerOption.innerHTML = manufacturer[i];
				$("#marca").append(manufacturerOption);			
			}
			$("#marca").show();
			$("#p1").show();
		}														
	},
	esEnter : function(e, url){
		var code = (e.keyCode ? e.keyCode : e.which);
		if(code==13){ //Intro			
			if(jquery.validaURLs(url)){
				document.getElementById("legal2").focus();
			}
		}
		
	},
	muestramarca : function(manufacturer){
		if($("#marca").val()=="Seleccionar Marca..."){
			$("#modelo").hide();
			$("#p2").hide();
		}	
		else{					
			modelSelect = document.getElementById('modelo');
			while (modelSelect.firstChild) {
	 			modelSelect.removeChild(modelSelect.firstChild);
			}

			var modelsList = model[''+manufacturer+''];

			for( i=0; i < modelsList.length; i++) {
				var modelOption = document.createElement('option');
				modelOption.value = modelsList[i];
				modelOption.innerHTML = modelsList[i];
				$("#modelo").append(modelOption);
			}
			
			$("#modelo").show();
			$("#p2").show();
		}								
	},				
	muestradni : function(){			
		$("#eleccionDoc").val("1");
		$("#documento").val("[12345678X]");
	},
	muestranie : function(){		
		$("#eleccionDoc").val("2");
		$("#documento").val("[X89878348]");
	},
	muestrapas : function(){	
		$("#eleccionDoc").val("3");
		$("#documento").val("[2210394585984-ESP]");
	},
	clear : function(){
		$("#documento").val("");										
	},	
	buscarPais : function(pais, lenguaje, lenguajeUsuario){
		if(lenguaje==lenguajeUsuario || lenguajeUsuario == ""){
			return pais;
		}
		else{
			for( i=0; i < numeroPaisesES; i++){
				if(lenguajeUsuario=="es"){				
					if(jquery.componer(pais) == jquery.componer(arrayPaisesEsBusqueda[i])){
						return arrayPaisesEnBusqueda[i];
					}				
				}
				else{
					if(jquery.componer(pais) == jquery.componer(arrayPaisesEnBusqueda[i])){
						return arrayPaisesEsBusqueda[i];
					}
				}
			}
			return "..........";
		}
	},
	buscarSector : function(sector, lenguaje, lenguajeUsuario){
		if(lenguaje==lenguajeUsuario || lenguajeUsuario == ""){
			return sector;
		}
		else{			
			for( i=0; i < numeroSectoresES; i++){			
				if(lenguajeUsuario=="es"){
					if(jquery.componer(sector) == jquery.componer(arraySectorEsBusqueda[i])){
						return arraySectorEnBusqueda[i];
					}
				}
				else{
					if(jquery.componer(sector) == jquery.componer(arraySectorEnBusqueda[i])){
						return arraySectorEsBusqueda[i];
					}
				}
			}
			return "..........";
		}
	},
	cargarCombos : function(pais, provincia, prefijo, sector, lenguaje, lenguajeUsuario){	
		//alert("Lenguaje de sistema: " + lenguaje + " Lenguaje de usuario: " + lenguajeUsuario);
		elPais = jquery.buscarPais(pais,lenguaje, lenguajeUsuario);
		elSector = jquery.buscarSector(sector,lenguaje, lenguajeUsuario);
		//alert("Voy a cargar los combos... pais vale: " + elPais + " provincia: " + provincia + " prefijo: " + prefijo + " sector: " + elSector + " lenguaje: " + lenguaje);	
		var ini = 0;
		var fin = 137;		
		if(elPais==".........."){
			elPais = "";
		}		
		if(lenguaje=="es"){ ini=0; fin=numeroPaisesES;} else{ ini=numeroPaisesES; fin=numeroTotalPaisesIdiomas;}
		for( i=ini; i < fin; i++) {
			var arrayPaisesOption = document.createElement('option');
			arrayPaisesOption.value = arrayPaises[i];
			arrayPaisesOption.innerHTML = arrayPaises[i];			
			if(jquery.evalua(arrayPaisesOption.value, elPais)){
					arrayPaisesOption.selected="selected";	
					var prefijoList = arrayPrefijos[''+arrayPaisesOption.value+''];					
					for( j=0; j < prefijoList.length; j++) {						
						var prefijosOption = document.createElement('option');
						prefijosOption.value = prefijoList[j];
						prefijosOption.innerHTML = prefijoList[j];
						if(jquery.evalua(prefijosOption.value, prefijo)){							
							prefijosOption.selected="selected";	
						}
						$("#selectPrefijo").append(prefijosOption);
					}
					
					
					var provinciasList = arrayProvincias[''+arrayPaisesOption.value+''];					
					for( k=0; k < provinciasList.length; k++) {						
						var provinciaOption = document.createElement('option');
						provinciaOption.value = provinciasList[k];
						provinciaOption.innerHTML = provinciasList[k];
						if(jquery.evalua(provinciaOption.value, provincia)){
							provinciaOption.selected="selected";
						}
						$("#selectProvincia").append(provinciaOption);
					}
			}			
			$("#selectPais").append(arrayPaisesOption);			
		}		

		if(lenguaje=="es"){ ini=0; fin=numeroSectoresES;} else{ ini=numeroSectoresES; fin=numeroTotalSectoresIdiomas;}
		for( i=ini; i < fin; i++) {
			var arraySectorOption = document.createElement('option');
			arraySectorOption.value = arraySector[i];
			arraySectorOption.innerHTML = arraySector[i];
			if(jquery.evaluaSector(arraySectorOption.value, elSector, lenguaje)){
				arraySectorOption.selected="selected";			
		    }
			$("#selectSector").append(arraySectorOption);			
		}
		
	},
	muestraProvincias : function(pais){
		
		prefijosSelect = document.getElementById('selectPrefijo');		
		while (prefijosSelect.firstChild) {
			prefijosSelect.removeChild(prefijosSelect.firstChild);
		}
		
		var prefijoList = arrayPrefijos[''+pais+''];
		
		for( i=0; i < prefijoList.length; i++) {
			var prefijosOption = document.createElement('option');
			prefijosOption.value = prefijoList[i];
			prefijosOption.innerHTML = prefijoList[i];
			$("#selectPrefijo").append(prefijosOption);
		}
		
		if(prefijoList.length==1){
			$("#prefijoActivo").val($("#selectPrefijo").val());
		}
				
		provinciaSelect = document.getElementById('selectProvincia');
		while (provinciaSelect.firstChild) {
			provinciaSelect.removeChild(provinciaSelect.firstChild);
		}
		
		var provinciasList = arrayProvincias[''+pais+''];		

		for( i=0; i < provinciasList.length; i++) {
			var provinciaOption = document.createElement('option');
			provinciaOption.value = provinciasList[i];
			provinciaOption.innerHTML = provinciasList[i];
			$("#selectProvincia").append(provinciaOption);
		}
			
	},
	evalua : function (utftext, ntext) {
		var stringUtf = jquery.componer(utftext);		
		return (stringUtf==jquery.componer(ntext));
	},
	replaceAll: function(text,busca,reemplaza){
		while (text.toString().indexOf(busca) != -1){
		      text = text.toString().replace(busca,reemplaza);
		}
		return text;
	},
	componer : function(cadena){		
		var laCadena = cadena;
		laCadena = jquery.replaceAll(laCadena,"&aacute;","á"); 
		laCadena = jquery.replaceAll(laCadena,"&eacute;","é"); 
		laCadena = jquery.replaceAll(laCadena,"&iacute;","í"); 
		laCadena = jquery.replaceAll(laCadena,"&oacute;","ó"); 
		laCadena = jquery.replaceAll(laCadena,"&uacute;","ú"); 
		laCadena = jquery.replaceAll(laCadena,"&ntilde;","ñ"); 
		laCadena = jquery.replaceAll(laCadena,"&Aacute;","Á"); 
		laCadena = jquery.replaceAll(laCadena,"&Eacute;","É"); 
		laCadena = jquery.replaceAll(laCadena,"&Iacute;","Í"); 
		laCadena = jquery.replaceAll(laCadena,"&Oacute;","Ó"); 
		laCadena = jquery.replaceAll(laCadena,"&Uacute;","Ú"); 
		laCadena = jquery.replaceAll(laCadena,"&Ntilde;","Ñ");
		return laCadena;
	},
	evaluaSector : function (utftext, ntext, lenguaje) {		
		var stringUtf = jquery.componer(utftext);
		return (stringUtf==jquery.componer(ntext));	
	},
	validaURLs : function (url){
		//var re=/^(ht|f)tp(s?)\:\/\/[0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*(:(0-9)*)*(\/?)( [a-zA-Z0-9\-\.\?\,\'\/\\\+&%\$#_]*)?$/;		
		var re=  /^(?:ftp|https?):\/\/(?:(?:(?:[\w\.\-\+!$&'\(\)*\+,;=]|%[0-9a-f]{2})+:)*(?:[\w\.\-\+%!$&'\(\)*\+,;=]|%[0-9a-f]{2})+@)?(?:(?:[a-z0-9\-\.]|%[0-9a-f]{2})+|(?:\[(?:[0-9a-f]{0,4}:)*(?:[0-9a-f]{0,4})\]))(?::[0-9]+)?(?:[\/|\?](?:[\w#!:\.\?\+=&@$'~*,;\/\(\)\[\]\-]|%[0-9a-f]{2})*)?$/;
		if(jQuery.trim(url.value)!=""){
			if(!re.test(url.value)){			
				document.getElementById("span"+url.id).style.display="block";
				document.getElementById(url.id).value="";
				return false;
			}	
			else{
				document.getElementById("span"+url.id).style.display="none";
				return true;
			}
		}
		else{
			document.getElementById("span"+url.id).style.display="none";
			return true;
		}
		
	},
	borrarPonentes : function (elIdioma){	
		var decision = confirm(elIdioma);		
		if (decision){
			document.getElementById("myForm").action="inscripcion_ponente?accion=3&puid=" + document.getElementById("puidParam").value;
			document.getElementById("myForm").submit();
		}	
	}
};	

$(document).ready(function(){
	
	$("#BtnContacto1").click(function(){									 
		if ($("#FormContact1").is(":hidden")) 
		{
			$("#FormContact1").slideDown("slow");
		}
		else
		{
			$("#nameBlog").val("");
			$("#FormContact1").slideUp("slow");
		}
    });
   
    
    $("#BtnContacto2").click(function(){									 
		if ($("#FormContact2").is(":hidden")) 
		{
			$("#FormContact2").slideDown("slow");
		}
		else
		{
			$("#nameWeb").val("");
			$("#FormContact2").slideUp("slow");
		}
		
    });  
   
    $("#BtnContacto3").click(function(){									 
		if ($("#FormContact3").is(":hidden")) 
		{
			$("#FormContact3").slideDown("slow");
		}
		else
		{
			$("#nameTwiter").val("");
			$("#FormContact3").slideUp("slow");
		}
    });   
	
   
    $("#BtnContacto4").click(function(){									 
		if ($("#FormContact4").is(":hidden")) 
		{
			$("#FormContact4").slideDown("slow");
		}
		else
		{
			$("#nameFacebook").val("");
			$("#FormContact4").slideUp("slow");
		}		
    });  
   
    $("#BtnContacto5").click(function(){									 
		if ($("#FormContact5").is(":hidden")) 
		{
			$("#FormContact5").slideDown("slow");
		}
		else
		{
			$("#nameFlickr").val("");
			$("#FormContact5").slideUp("slow");
		}
		
    });
   
    $("#BtnContacto6").click(function(){									 
		if ($("#FormContact6").is(":hidden")) 
		{
			$("#FormContact6").slideDown("slow");
		}
		else
		{
			$("#nameFotolog").val("");
			$("#FormContact6").slideUp("slow");
		}
		
    });
   
    $("#BtnContacto7").click(function(){									 
		if ($("#FormContact7").is(":hidden")) 
		{
			$("#FormContact7").slideDown("slow");
		}
		else
		{
			$("#namePicasa").val("");
			$("#FormContact7").slideUp("slow");
		}
		
    });
   
    $("#BtnContacto8").click(function(){									 
		if ($("#FormContact8").is(":hidden")) 
		{
			$("#FormContact8").slideDown("slow");
		}
		else
		{
			$("#nameLinkedIn").val("");
			$("#FormContact8").slideUp("slow");
		}
		
    });
   
    $("#BtnContacto9").click(function(){									 
		if ($("#FormContact9").is(":hidden")) 
		{
			$("#FormContact9").slideDown("slow");
		}
		else
		{
			$("#nameSlideshare").val("");
			$("#FormContact9").slideUp("slow");
		}
		
    });
   
    $("#BtnContacto10").click(function(){									 
		if ($("#FormContact10").is(":hidden")) 
		{
			$("#FormContact10").slideDown("slow");
		}
		else
		{
			$("#nameRSS").val("");
			$("#FormContact10").slideUp("slow");
		}		
    });
   
    $("#BtnContacto11").click(function(){									 
		if ($("#FormContact11").is(":hidden")) 
		{
			$("#FormContact11").slideDown("slow");
		}
		else
		{
			$("#nameDelicious").val("");
			$("#FormContact11").slideUp("slow");
		}
		
    });   
   
    $("#BtnContacto12").click(function(){									 
		if ($("#FormContact12").is(":hidden")) 
		{
			$("#FormContact12").slideDown("slow");
		}
		else
		{
			$("#nameStumbleUpon").val("");
			$("#FormContact12").slideUp("slow");
		}
		
    });   
   
    $("#BtnContacto13").click(function(){									 
		if ($("#FormContact13").is(":hidden")) 
		{
			$("#FormContact13").slideDown("slow");
		}
		else
		{
			$("#nameGoogle").val("");
			$("#FormContact13").slideUp("slow");
		}
		
    });   
   
    $("#BtnContacto14").click(function(){									 
		if ($("#FormContact14").is(":hidden")) 
		{
			$("#FormContact14").slideDown("slow");
		}
		else
		{
			$("#nameMenea").val("");
			$("#FormContact14").slideUp("slow");
		}
		
    });   
   
    $("#BtnContacto15").click(function(){									 
		if ($("#FormContact15").is(":hidden")) 
		{
			$("#FormContact15").slideDown("slow");
		}
		else
		{
			$("#nameYoutube").val("");
			$("#FormContact15").slideUp("slow");
		}
		
    });
    
    
    $("#BtnContacto16").click(function(){									 
		if ($("#FormContact16").is(":hidden")) 
		{
			$("#FormContact16").slideDown("slow");
		}
		else
		{			
			$("#FormContact16").slideUp("slow");
		}
		
    });
    
    $("#BtnCaptcha").click(function(){									 
		if ($("#FormCaptcha").is(":hidden")) 
		{
			$("#FormCaptcha").slideDown("slow");
		}
		else
		{			
			$("#FormCaptcha").slideUp("slow");
		}
		
    });
   
    
    $("#BtnContacto17").click(function(){									 
		if ($("#FormContact17").is(":hidden")) 
		{
			$("#FormContact17").slideDown("slow");
		}
		else
		{			
			$("#FormContact17").slideUp("slow");
		}
		
    });
    
    $("#BtnContacto18").click(function(){									 
		if ($("#FormContact18").is(":hidden")) 
		{
			$("#FormContact18").slideDown("slow");
		}
		else
		{			
			$("#FormContact18").slideUp("slow");
		}
		
    });
    
    
    $("#BtnContactLegalMaquetacion").click(function(){									 
		if ($("#FormContactLegalMaquetacion").is(":hidden")) 
		{
			$("#FormContactLegalMaquetacion").slideDown("slow");
		}
		else
		{			
			$("#FormContactLegalMaquetacion").slideUp("slow");
		}
		
    });
   
    
	$("#aceptar")	
		.click(function (event) {			
			var errores_validacion = comprobarCampos();
			if(!hayErrores(errores_validacion)){				
				muestraErrores(errores_validacion);				
				document.getElementById("myForm").action="inscription?accion=1";
				document.getElementById("myForm").submit();
			}
			else{
				muestraErrores(errores_validacion);
				if(document.getElementById("spanErroresSubmit")!=null){
					document.getElementById("spanErroresSubmit").style.display="none";
				}
				document.getElementById("spanErroresDatos").style.display="block";
				scroll(0,0);
			}			
	});
	
	$("#aceptarPonente")	
		.click(function (event) {			
			var errores_validacion = comprobarCampos();
			if(!hayErroresPonente(errores_validacion)){
				document.getElementById("myForm").action="inscripcion_ponente?accion=1";
				document.getElementById("myForm").submit();				
			}
			else{				
				muestraErrores(errores_validacion);
				if(document.getElementById("spanErroresSubmit")!=null){
					document.getElementById("spanErroresSubmit").style.display="none";
				}
				document.getElementById("spanErroresDatos").style.display="block";				
				scroll(0,0);
			}			
	});

	$("#aceptarPonenteUpdate")	
		.click(function (event) {			
			var errores_validacion = comprobarCampos();
			if(!hayErroresPonente(errores_validacion)){											
				document.getElementById("myForm").action="inscripcion_ponente?accion=2&puid=" + document.getElementById("puidParam").value;
				document.getElementById("myForm").submit();				
			}
			else{
				muestraErrores(errores_validacion);		
				if(document.getElementById("spanErroresSubmit")!=null){
					document.getElementById("spanErroresSubmit").style.display="none";
				}
				document.getElementById("spanErroresDatos").style.display="block";				
				scroll(0,0);
			}			
	});
	

	function comprobarCampos(){
		var array_campos = $("input.obligatoria");
		var errores = new Array(array_campos.length);		
		for (i=0; i<array_campos.length; i++)
		{			
			var valor = $(array_campos[i]).val();
			var nombre_campo = $(array_campos[i]).attr("name");
			valor = jQuery.trim(valor);
			//Comprobamos el mail			 
			if(nombre_campo=="mail"){				
				var er_email = /^(.+\@.+\..+)$/		
				if(valor=="" || !er_email.test(valor)){ errores[i] = 1;	}
				else{ errores[i] = 0; }						
			}	//Comprobamos las contrasenyas
			
			if(nombre_campo=="password"){
				valor = jQuery.trim(valor);
				if(valor=="" && jQuery.trim($("#password2").val())==""){
					errores[i] = 2;
				}
				else if(valor!=$("#password2").val()){
					errores[i] = 1;	
				}				
				else{ 
					errores[i] = 0; 
				}
			}
			
			//Comprobamos las contrasenyas
			if(nombre_campo=="password2"){
				valor = jQuery.trim(valor);
				if(valor=="" && jQuery.trim($("#password").val())==""){
					errores[i] = 2;
				}
				else if(valor!=$("#password").val()){
					errores[i] = 1;	
				}				
				else{ 
					errores[i] = 0; 
				}
			}
			
			//Comprobamos el nombre
			if(nombre_campo=="nombre"){
				var er_nombre = /^([0-9]|[a-z]|[A-Z]|ª|º|á|é|í|ó|ú|ñ|ü|Á|É|Í|Ó|Ú|Ñ|Ü|\s|\.|-)+$/ 
				if(valor==""){
					errores[i] = 1;	
				}
				else if(!er_nombre.test(valor)){
					errores[i] = 2;	
				}
				else{ 
					errores[i] = 0; 
				}				
			}
			
			//Comprobamos los apellidos
			if(nombre_campo=="apellidos"){
				var er_apellidos = /^([0-9]|[a-z]|[A-Z]|ª|º|á|é|í|ó|ú|ñ|ü|Á|É|Í|Ó|Ú|Ñ|Ü|\s|\.|-)+$/
				if(valor==""){
					errores[i] = 1;	
				}
				else if(!er_apellidos.test(valor)){
					errores[i] = 2;	
				}
				else{ 
					errores[i] = 0; 
				}	
			}
			
			//Comprobar el documento
			if(nombre_campo=="documento"){	
				var consulta = false;
				if(document.getElementById("dni").checked){					
					consulta = validarNIF(valor);					
				}
				if(document.getElementById("nie").checked){					
					consulta = validarNIE(valor);					
				}
				if(document.getElementById("pasaporte").checked){
					consulta = true;
				}	
				if(valor=="" || !consulta){ errores[i] = 1;	}
				else{ errores[i] = 0; }
			}
			
			//Comprobar el direccion
			if(nombre_campo=="direccion"){
				if(valor==""){ errores[i] = 1;	}
				else{ errores[i] = 0; }
			}
			
			//Comprobar el cp
			if(nombre_campo=="cp"){
				if(valor==""){ errores[i] = 1;	}
				else{ errores[i] = 0; }
			}
			
			
			//Comprobamos los apellidos
			if(nombre_campo=="empresa"){
				//var er_apellidos = /^([A-Z a-z \s\+\-])+$/
				//if(valor=="" || !er_apellidos.test(valor)){ errores[i] = 1;	}
				if(valor==""){ errores[i] = 1;	}
				else{ errores[i] = 0; }
			}
			
			if(nombre_campo=="cargo"){
				//var er_apellidos = /^([A-Z a-z \s\+\-])+$/
				//if(valor=="" || !er_apellidos.test(valor)){ errores[i] = 1;	}
				if(valor==""){ errores[i] = 1;	}
				else{ errores[i] = 0; }
			}
		
			if(nombre_campo=="selectSector"){
				//var er_apellidos = /^([A-Z a-z \s\+\-])+$/
				//if(valor=="" || !er_apellidos.test(valor)){ errores[i] = 1;	}				
				if(valor==""){ errores[i] = 1;	}
				else{ errores[i] = 0; }
			}
			
			if(nombre_campo=="legal1"){				
				if(!document.getElementById("legal1").checked){ errores[i] = 1;	}
				else{ errores[i] = 0; }
			}
			
			if(nombre_campo=="captchastring"){					
				if(valor==""){ errores[i] = 1;	}
				else{ errores[i] = 0; }
			}
		}
		
		return errores;
	}
	
	function hayErroresPonente(vErrores){	
		for (i=0; i<vErrores.length; i++)
		{				
			if(vErrores[i]>0) return true;
		}
		
		//comparobamos el select obligario		
		var array_select = $("select.obligatoria");		
		for (i=0; i<array_select.length; i++)
		{
			
			var valor = $(array_select[i]).val();
			if(valor==".........."){
				return true;
			}
		}
		
		return false;		
	}
	
	function hayErrores(vErrores){
		
		for (i=0; i<vErrores.length; i++)
		{	
			if(vErrores[i]>0) return true;
		}
		
		//comparobamos el select obligario		
		var array_select = $("select.obligatoria");		
		for (i=0; i<array_select.length; i++)
		{
			
			var valor = $(array_select[i]).val();
			if(valor==".........."){
				return true;
			}
		}
		
		//Comprobamos que los check hay como mucho 4 selecionados.
		var array_select_ienteresado4 = $("input.interesado4");
		var contador = 0;
		if(document.getElementById("inversor").checked) contador++;
		if(document.getElementById("creador").checked) contador++;
		if(document.getElementById("supplier").checked) contador++;
		if(document.getElementById("customer").checked) contador++;
		if(document.getElementById("producer").checked) contador++;
		if(document.getElementById("distributor").checked) contador++;
		if(document.getElementById("consumer").checked) contador++;
		if(document.getElementById("institution").checked) contador++;
		if(document.getElementById("information").checked) contador++;
		if(document.getElementById("organiser").checked) contador++;
		if(document.getElementById("developer").checked) contador++;
		if(document.getElementById("entrepreneur").checked) contador++;
		if(document.getElementById("speaker").checked) contador++;
		if(document.getElementById("exhibitor").checked) contador++;
		if(document.getElementById("educator").checked) contador++;
		if(document.getElementById("sponsor").checked) contador++;
		if(document.getElementById("others").checked) contador++;		
		if(contador>4){
			return true;
		}
		
		//Comprobamos que los check hay como mucho 4 selecionados.		
		var array_select_esado4 = $("input.es4");		
		var contador2=0;
		if(document.getElementById("inversor2").checked) contador2++;
		if(document.getElementById("creador2").checked) contador2++;
		if(document.getElementById("supplier2").checked) contador2++;
		if(document.getElementById("customer2").checked) contador2++;
		if(document.getElementById("producer2").checked) contador2++;
		if(document.getElementById("distributor2").checked) contador2++;
		if(document.getElementById("consumer2").checked) contador2++;
		if(document.getElementById("institution2").checked) contador2++;
		if(document.getElementById("information2").checked) contador2++;
		if(document.getElementById("organiser2").checked) contador2++;
		if(document.getElementById("developer2").checked) contador2++;
		if(document.getElementById("entrepreneur2").checked) contador2++;
		if(document.getElementById("speaker2").checked) contador2++;
		if(document.getElementById("exhibitor2").checked) contador2++;
		if(document.getElementById("educator2").checked) contador2++;
		if(document.getElementById("sponsor2").checked) contador2++;
		if(document.getElementById("others2").checked) contador2++;	
		if(contador2>4){
			return true;
		}
		
		//Comprobamos el telefono
		var telefono = document.getElementById("telefono").value;		
		if(telefono!=""){
			var er_telefono = /^([0-9\s\+\-])+$/		
			if(!er_telefono.test(telefono)){ return true; }			
		}
		
		return false;
	}
	
	function muestraErrores(vErrores){
		
		var array_campos = $("input.obligatoria");
		for (i=0; i<vErrores.length; i++)
		{
			var valor = $(array_campos[i]).val();			
			var nombre_campo = $(array_campos[i]).attr("name");			
			if(vErrores[i]>0){				
				$(array_campos[i]).addClass("erronea");
				if(nombre_campo=="mail"){		
					document.getElementById("spanMail").style.display="block";					
				}				
				if(nombre_campo=="password"){
					if(vErrores[i]==1){
						document.getElementById("spanPassword").style.display="block";
						document.getElementById("spanPasswordVacio").style.display="none";
					}
					else if(vErrores[i]==2){
						document.getElementById("spanPassword").style.display="none";
						document.getElementById("spanPasswordVacio").style.display="block";
					}				
				}
				if(nombre_campo=="password2"){
					if(vErrores[i]==1){
						document.getElementById("spanPassword2").style.display="block";
						document.getElementById("spanPasswordVacio2").style.display="none";
					}
					else if(vErrores[i]==2){
						document.getElementById("spanPassword2").style.display="none";
						document.getElementById("spanPasswordVacio2").style.display="block";
					}	
				}
				if(nombre_campo=="nombre"){	
					if(vErrores[i]==1){
						document.getElementById("spanName").style.display="block";
						document.getElementById("spanNameCaracter").style.display="none";
					}
					else if(vErrores[i]==2){
						document.getElementById("spanName").style.display="none";
						document.getElementById("spanNameCaracter").style.display="block";
					}
				}
				if(nombre_campo=="apellidos"){
					if(vErrores[i]==1){
						document.getElementById("spanApellidos").style.display="block";
						document.getElementById("spanApellidosCaracter").style.display="none";
					}
					else if(vErrores[i]==2){
						document.getElementById("spanApellidos").style.display="none";
						document.getElementById("spanApellidosCaracter").style.display="block";
					}
				}
				if(nombre_campo=="documento"){
					document.getElementById("spanDocumento").style.display="block";
				}
				if(nombre_campo=="direccion"){
					document.getElementById("spanDireccion").style.display="block";
				}
				if(nombre_campo=="cp"){
					document.getElementById("spanCP").style.display="block";
				}
				if(nombre_campo=="empresa"){
					document.getElementById("spanEmpresa").style.display="block";
				}
				if(nombre_campo=="cargo"){
					document.getElementById("spanCargo").style.display="block";
				}
				if(nombre_campo=="legal1"){ 
					document.getElementById("spanLegal1").style.display="block";
				}
				if(nombre_campo=="captchastring"){ 
					document.getElementById("spanCaptchastring").style.display="block";
				}
			}
			else{
				$(array_campos[i]).removeClass("erronea");
				if(nombre_campo=="mail"){		
					document.getElementById("spanMail").style.display="none";					
				}				
				if(nombre_campo=="password"){
					document.getElementById("spanPassword").style.display="none";
					document.getElementById("spanPasswordVacio").style.display="none";
				}
				if(nombre_campo=="password2"){
					document.getElementById("spanPassword2").style.display="none";
					document.getElementById("spanPasswordVacio2").style.display="none";
				}
				if(nombre_campo=="nombre"){					
					document.getElementById("spanName").style.display="none";
					document.getElementById("spanNameCaracter").style.display="none";
				}
				if(nombre_campo=="apellidos"){					
					document.getElementById("spanApellidos").style.display="none";
					document.getElementById("spanApellidosCaracter").style.display="none";
				}
				if(nombre_campo=="documento"){
					document.getElementById("spanDocumento").style.display="none";
				}
				if(nombre_campo=="direccion"){
					document.getElementById("spanDireccion").style.display="none";
				}
				if(nombre_campo=="cp"){
					document.getElementById("spanCP").style.display="none";
				}
				if(nombre_campo=="empresa"){
					document.getElementById("spanEmpresa").style.display="none";
				}
				if(nombre_campo=="cargo"){
					document.getElementById("spanCargo").style.display="none";
				}			
				if(nombre_campo=="legal1"){ 
					document.getElementById("spanLegal1").style.display="none";
				}
				if(nombre_campo=="captchastring"){ 
					document.getElementById("spanCaptchastring").style.display="none";
				}
			}
		}
		
		//comparobamos el select obligario		
		var array_select = $("select.obligatoria");		
		for (i=0; i<array_select.length; i++)
		{
			
			var valor = $(array_select[i]).val();
			if(valor==".........."){
				document.getElementById("spanSector").style.display="block";
			}
			else{
				document.getElementById("spanSector").style.display="none";
			}
		}
		
		
		//Comprobamos que los check hay como mucho 4 selecionados.
		var array_select_ienteresado4 = $("input.interesado4");
		//alert(array_select_ienteresado4.length);
		if(array_select_ienteresado4.length>0){
			var contador = 0;
			if(document.getElementById("inversor").checked) contador++;
			if(document.getElementById("creador").checked) contador++;
			if(document.getElementById("supplier").checked) contador++;
			if(document.getElementById("customer").checked) contador++;
			if(document.getElementById("producer").checked) contador++;
			if(document.getElementById("distributor").checked) contador++;
			if(document.getElementById("consumer").checked) contador++;
			if(document.getElementById("institution").checked) contador++;
			if(document.getElementById("information").checked) contador++;
			if(document.getElementById("organiser").checked) contador++;
			if(document.getElementById("developer").checked) contador++;
			if(document.getElementById("entrepreneur").checked) contador++;
			if(document.getElementById("speaker").checked) contador++;
			if(document.getElementById("exhibitor").checked) contador++;
			if(document.getElementById("educator").checked) contador++;
			if(document.getElementById("sponsor").checked) contador++;
			if(document.getElementById("others").checked) contador++;		
			if(contador>4){
				document.getElementById("spanInteresado4").style.display="block";
			}
			else{
				document.getElementById("spanInteresado4").style.display="none";
			}
		}
		
		//Comprobamos que los check hay como mucho 4 selecionados.		
		var array_select_esado4 = $("input.es4");
		//alert(array_select_esado4.length);
		if(array_select_esado4.length>0){
			var contador2=0;
			if(document.getElementById("inversor2").checked) contador2++;
			if(document.getElementById("creador2").checked) contador2++;
			if(document.getElementById("supplier2").checked) contador2++;
			if(document.getElementById("customer2").checked) contador2++;
			if(document.getElementById("producer2").checked) contador2++;
			if(document.getElementById("distributor2").checked) contador2++;
			if(document.getElementById("consumer2").checked) contador2++;
			if(document.getElementById("institution2").checked) contador2++;
			if(document.getElementById("information2").checked) contador2++;
			if(document.getElementById("organiser2").checked) contador2++;
			if(document.getElementById("developer2").checked) contador2++;
			if(document.getElementById("entrepreneur2").checked) contador2++;
			if(document.getElementById("speaker2").checked) contador2++;
			if(document.getElementById("exhibitor2").checked) contador2++;
			if(document.getElementById("educator2").checked) contador2++;
			if(document.getElementById("sponsor2").checked) contador2++;
			if(document.getElementById("others2").checked) contador2++;	
			if(contador2>4){
				document.getElementById("spanEs4").style.display="block";
			}
			else{
				document.getElementById("spanEs4").style.display="none";
			}
		}
		
		//Comprobamos el telefono
		if(document.getElementById("telefono")!=null){
			var telefono = document.getElementById("telefono").value;		
			if(telefono!=""){
				var er_telefono = /^([0-9\s\+\-])+$/		
				if(!er_telefono.test(telefono)){ document.getElementById("spanTelefono").style.display="block"; }
				else {document.getElementById("spanTelefono").style.display="none"; }
			}
		}

	}
	
	function validarNIF(sIdentificacion)
	{
		sIdentificacion=sIdentificacion.toUpperCase();
		
		var z=sIdentificacion.charAt(0);
		
		if ((sIdentificacion.length>9)||(sIdentificacion.length==0))
		{		   		                    
			  return false;    
		}
		   iContador = 0           
	       do
	       {                
	               sCaracter = sIdentificacion.substr (iContador, 1);                
	               if (sCaracter !=  "0")
	               {                     
	                       break;                    
	               }                
	               iContador ++;              
	       } 
	       while (iContador<sIdentificacion.length)	           
	       if (iContador > 1){              
	               sIdentificacion = sIdentificacion.substring ( iContador  , sIdentificacion.length);             
	       }
		                     
	       if (sIdentificacion.charAt(sIdentificacion.length -1) <'A' || sIdentificacion.charAt(sIdentificacion.length -1) > 'Z' )
		   {    
				  return false;
	       }
	                         
	       if ( isNaN (sIdentificacion.substr (0,sIdentificacion.length-1 )))
	       {
				return false;
		   }
	       
		   var dValor =  sIdentificacion.substr (0 , sIdentificacion.length -1); 
	       var iNumero = (dValor %  23);  		                      
	       if (LETRAS.charAt (iNumero) != sIdentificacion.charAt(sIdentificacion.length-1))
			{                           
				 return false;                           
	        }	
		return true;
	}
	
	function validarNIE(sIdentificacion){		
		sIdentificacion=sIdentificacion.toUpperCase();		
		if (sIdentificacion.substr(0,1).toUpperCase()!= "X" && sIdentificacion.substr(0,1).toUpperCase()!= "Y" && sIdentificacion.substr(0,1).toUpperCase()!= "Z") {		
			return false;
		}
		                  
		if ( isNaN (sIdentificacion.substr (1,sIdentificacion.length-2 ))){   		                    		  	
			return false;
		}	                  
		var dValor =  sIdentificacion.substr (1 , sIdentificacion.length-2);                    
		  
	    dValor = dValor * 1;
		if (sIdentificacion.substr(0,1).toUpperCase() == "X")
		{
			dValor = dValor + 0;
		}
		else if (sIdentificacion.substr(0,1).toUpperCase() == "Y")
		{
			dValor = dValor + 10000000;
		}
		else if (sIdentificacion.substr(0,1).toUpperCase() == "Z")
		{
			dValor = dValor + 20000000;
		}
		var iNumero = (dValor % 23);
		if (LETRAS.charAt (iNumero) != sIdentificacion.charAt(sIdentificacion.length-1))
		{                             		                    	
				return false;                           
		}  
		return true;	
	}
	
});