// FUNCIONES DEL ARCHIVO SusDatos.jsp

	var control=1;
	var postal=0;

	 	
	function recogeOrdenElementos(oForm)
	{
	 var sElementos = "";
	 var obj = eval("document." + oForm);
	 obj.formaContacto.disabled = false;
	 for(i=0; i<obj.length; i++)
	 {
	  if( (obj.elements[i].type != "hidden") && (sElementos.indexOf(obj.elements[i].name) == -1) ){
	   if(obj.elements[i].disabled == false  && obj.elements[i].name!=null)
		   sElementos += obj.elements[i].name + "$";
	  }
	  else
	  {
	   if( (obj.elements[i].type == "hidden") && ((obj.elements[i].id == "TITULO") || (obj.elements[i].id2 == "TITULO"))){
	    if(obj.elements[i].disabled == false  && obj.elements[i].name!=null)
	     sElementos += obj.elements[i].name + "$";
	   }
	  }  

	 } 
	 
	 sElementos = sElementos.substring(0, sElementos.lastIndexOf("$"));
	 obj.ordenElementos.value = sElementos; 
	 }

	 
	function validaLinea(){
		if(document.frm.Negocio[document.frm.Negocio.selectedIndex].value==""){
			alert("Por favor, debes seleccionar una linea de producto");
			document.frm.Negocio.focus();
			return false;
		}
		return true;
	}
	function validoProducto(){

		if(document.frm.Producto[document.frm.Producto.selectedIndex].value.indexOf("--")!=-1){
			alert("Por favor, debes seleccionar un producto");
			document.frm.Producto.focus();
			return false;
		}
		return true;
	}
	
	//Función que comprueba que algún checkbox esté marcado.
	function activoAlgunCheckbox(checkboxes){
		for (i = 0; i < checkboxes.length; i++){ 
			if(checkboxes[i].checked==1){
				return true;
			}
		}
		return false; 
	
	}
	// Fin exclusividad
	function emailValido(valor) 
	{
	  if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor))
	  {
	  
	    return true;
	  } 
	  else 
	  {
		alert("Por favor, indica una dirección de correo electrónico válida");
	    return false;
	  }
	}
	
	
	function validaFecha(fecha){
		if(!validoFormato("[0-9]{2}\/[0-9]{2}\/[0-9]{4}",fecha.value)){
			alert("La fecha de nacimiento debería tener el formato dd/mm/aaa.Ej: 01/02/2005");
			fecha.focus();
			return false;		
		}
		if(!validarFecha(fecha.value)){
			alert("Por favor, introduce una fecha correcta");
			fecha.focus();
			return false;		
		}		
		return true;
	
	}


	function validarFecha(cValorFecha){
	      var cFormatoFecha =  "DD/MM/YYYY" //gcFormatoFecha;
	      var bCorrecto = false;
	      var cMensaje = 'Fecha incorrecta, por favor revisa su formato (DD/MM/AAAA)';
	      var arrDM = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
	      var y = 0;
	      var m = -1;
	      var d = 0;
	      var a = cValorFecha.split(/\W+/);
	      var b = cFormatoFecha.split(/\W+/);
	      var c = '';
	      if(cValorFecha != '' && cValorFecha != 'dd/mm/yyyy'){
	            for(i = 0; i < a.length; ++i){
	                  c = b[i].toUpperCase();
	                  if(c == "D" || c == "DD"){d = parseInt(a[i], 10);}
	                  if(c == "M" || c == "MM"){m = parseInt(a[i], 10) - 1;}
	                  if(c == "Y" || c == "YY" || c == "YYYY"){y = parseInt(a[i], 10);}
	            }
	            // si alguno de los campos no es numérico:
	            if(isNaN(d) || isNaN(m) || isNaN(y)){
	                  bCorrecto = false;
	            }else{
	                  // mes de febrero (años bisiestos):
	                  if((y % 400) == 0 || (((y % 4) == 0) && ((y % 100) != 0))){arrDM[1] = 29;}
	                  if(y != 0 && (m != -1 && m < 12) && (d != 0 && d <= arrDM[m])){bCorrecto = true;}
	            }
	      }else{// (cValorFecha != '')
	            bCorrecto = true;
	      }
	      return bCorrecto;
	}

	function validaFormacionAcademica2(){
		var tipoEstudios = eval("document.getElementById('Tipo_Estudios1')");
		var nombreEstudios = eval("document.getElementById('Nombre_Estudios')");
		var estudianteSi = eval("document.getElementById('estudianteSi')");
		var estudianteNo = eval("document.getElementById('estudianteNo')");
		var Nivel=eval("document.getElementById('Nivel')");
		var direccionCentro=eval("document.getElementById('Direccion_Centro')");
		var cpCentro = eval("document.getElementById('Código_Postal_Centro')");	
		var centroEst= eval("document.getElementById('Centro_Estudios')");	
		
		if(!validarRadioButton(estudianteSi,estudianteNo)){
			alert("Por favor, debes seleccionar si todavía eres o no eres estudiante");
			estudianteSi.focus();	
			return false;
		}
		if(!validarListaDesplegable(tipoEstudios)){
			alert("Por favor, debes seleccionar el tipo de estudios realizados");
			tipoEstudios.focus();	
			return false;
		}
		if(!valido(nombreEstudios, " un nombre para los estudios seleccionados")){
			return false;
		}
		if(!valido(Nivel," el curso en el que estudias")){
			return false;	
		}
		if(!valido(centroEst, " un centro de estudios")){
			return false;
		}
		if(!valido(direccionCentro, " la dirección del centro de estudios")){
			return false;		
		}
		if(!valido(cpCentro, " el código postal")||!validoCP(cpCentro)){
			return false;		
		} 
		return true;
	}
	function validaFormacionAcademica(){
		var tipoEstudios = eval("document.getElementById('Tipo_Estudios1')");
		var nombreEstudios = eval("document.getElementById('Nombre_Estudios1')");
		var finEstudios1 = eval("document.getElementById('Fin_Estudios1')");
		var anyoInicio1=eval("document.getElementById('Año_Inicio1')");
		var anyoFin1=eval("document.getElementById('Año_Fin1')");
		var anyoInicio2=eval("document.getElementById('Año_Inicio2')");
		var anyoFin2=eval("document.getElementById('Año_Fin2')");
		var anyoInicio3=eval("document.getElementById('Año_Inicio3')");
		var anyoFin3=eval("document.getElementById('Año_Fin3')");
		var centroEst1=eval("document.getElementById('Centro_Estudios1')");
        var lugar1=eval("document.getElementById('Lugar_Centro_Estudios1')");
		
/*	
		if(!validarListaDesplegable(tipoEstudios)){
			alert("Por favor, debes seleccionar el tipo de estudios realizados");
			tipoEstudios.focus();	
			return false;
		}else if(!valido(nombreEstudios, " un nombre para los estudios seleccionados")){
			return false;
		}else if(!validarRadioButton(finEstudios1)){
			alert("Por favor, debes seleccionar si has finalizado o no los estudios");
			finEstudios1[1].focus();	
			return false;
		}else if(!valido(anyoInicio1," un año de inicio")){
			return false;		
		}else if(!validarAnyos(anyoInicio1,anyoFin1)){
			return false;
		}else if(!valido(centroEst1, " un centro de estudios")){
			return false;
		}else if(!valido(lugar1, " el centro donde realizaste los estudios")){
			return false;
		}
		return true;
*/		
		if(!validarAnyos(anyoInicio1,anyoFin1)){
			return false;
		}
		if(!validarAnyos(anyoInicio2,anyoFin2)){
			return false;
		}
		if(!validarAnyos(anyoInicio3,anyoFin3)){
			return false;
		}
		return true;
	}

	function validarAnyos(anyoInicio,anyoFin){
		var valor1 = parseInt(anyoInicio.value); 
		var valor2 = parseInt(anyoFin.value); 
	    //Compruebo si es un valor numérico 
		if(anyoInicio.value.length>0){
		    if (!validoFormato("[0-9]{4}",anyoInicio.value)) { 
				alert("Por favor, el año de inicio tiene que tener el formato \"aaaa\". Por ej: 1995.");
				anyoInicio.focus();
	  	        return false; 
		    }
		}
	    if(anyoFin.value.length>0){
  		    if (!validoFormato("[0-9]{4}",anyoFin.value)) { 
				alert("Por favor, el año de fin tiene que tener el formato \"aaaa\". Por ej: 1995.");
				anyoFin.focus();
	  	        return false;  		    
  		    }
	    	if(valor1>valor2){
	    		alert("El año de finalización deber ser superior al año de inicio");
	    		anyoFin.focus();
	    		return false;
	    	}
	    }
		return true;	
	}
		
	function validoFormato(expresion, textoValidar){
		var expRegular = new RegExp(expresion); 
		if(!expRegular.test(textoValidar)){
			return false;
		}
		return true;	
	}
		
		
		
	function validarListaDesplegable(lista){
		if(lista.selectedIndex <= 0){
			return false;
		}
		return true;
	}

	function validarRadioButton(buttonSi, buttonNo){
		
	   if (buttonSi.checked || buttonNo.checked) 
	        return true; 
		else	          
			return false;
	}
	
	
	function validosDatosUsuario2(){
		var nacionalidad = eval("document.getElementById('Nacionalidad')");
		var movilidadGeografica = eval("document.getElementById('Movilidad')");
		var permisoTrabajoSi = eval("document.getElementById('permisoSi')");
		var permisoTrabajoNo = eval("document.getElementById('permisoNo')");
		var telefono = eval("document.getElementById('Telefono')");		
		var fecha = eval("document.getElementById('Fecha_Nacimiento')");
	
		if(!validaFecha(fecha)){
				return false;
		}
		if(!valido(nacionalidad," la Nacionalidad")){
			return false;
		}
		if (!validarListaDesplegable(movilidadGeografica)){
			alert("Por favor, debes seleccionar una movilidad geográfica");
			movilidadGeografica.focus();
			return false;
		}
		if(!validarRadioButton(permisoTrabajoSi, permisoTrabajoNo)){
			alert("Por favor, debes seleccionar necesitas o no permiso de trabajo");
			permisoTrabajoSi.focus();	
			return false;
		}
		if(!valido(telefono, " el teléfono")||!validoTelefono(telefono)){			
			return false;		
		}
		
		return true;
	}
	
	function validosDatosUsuario(){
		
		if(document.getElementById("Nombre").value == ""){
			alert("Por favor, debes introducir un nombre");
			document.getElementById("Nombre").focus();
			return false;
		}
		else if(document.getElementById("Apellido1").value == ""){
			alert("Por favor, debes introducir el Apellido1");
			document.getElementById("Apellido1").focus();
			return false;
		}		
		else if (document.getElementById("Correo").value == "")	{		    
			alert("Por favor, debes introducir una dirección de correo");
			document.getElementById("Correo").focus();
			return false;
		}
		else if (!emailValido(document.getElementById("Correo").value)) {
			document.getElementById("Correo").focus();
			return false;
		}		
		else if (document.getElementById("Telefono").value == "") {
			alert("Por favor, debes introducir un teléfono");
			document.getElementById("Telefono").focus();
			return false;
		}
	    else if (!validoTelefono(document.getElementById("Telefono"))) {
			document.getElementById("Telefono").focus();
			return false;
		}
		else if (document.getElementById("Codigo_Postal").value == "") {
			alert("Por favor, debes introducir un código postal");
			document.getElementById("Codigo_Postal").focus();
			return false;
		}
		else if (!validoCP(document.getElementById("Codigo_Postal"))) {
			document.getElementById("Codigo_Postal").focus();
			return false;		
		}		

		return true;
	}
	
	
	function validoDatosEmpresa(){

		if(document.getElementById("Compania").value == ""){
			alert("Por favor, debes introducir una compañía");
			document.getElementById("Compania").focus();
			return false;
		}
		else if (document.getElementById("Sector_de_negocio").value == "") {
			alert("Por favor, debes introducir una sector de negocio");
			document.getElementById("Sector_de_negocio").focus();
			return false;
		}		
		else if (document.getElementById("Persona_de_Contacto").value == "") {
			alert("Por favor, debes introducir una persona de contacto");
			document.getElementById("Persona_de_Contacto").focus();
			return false;
		}
		else if (document.getElementById("Cargo").value == "") {
			alert("Por favor, debes introducir un cargo");
			document.getElementById("Cargo").focus();
			return false;
		}
		else if (document.getElementById("CorreoElectronico").value == "")	{		    
			alert("Por favor, debes introducir una dirección de correo electrónico");
			document.getElementById("CorreoElectronico").focus();
			return false;
		}
		else if (!emailValido(document.getElementById("CorreoElectronico").value)) {
			document.getElementById("CorreoElectronico").focus();
			return false;
		}
		else if (document.getElementById("Telefono").value == "") {
			alert("Por favor, debes introducir un teléfono");
			document.getElementById("Telefono").focus();
			return false;
		}
	    else if (!validoTelefono(document.getElementById("Telefono"))) {
			document.getElementById("Telefono").focus();
			return false;
		}
		else if (document.getElementById("CPostal").value == "") {
			alert("Por favor, debes introducir un código postal");
			document.getElementById("CPostal").focus();
			return false;
		}
		else if (!validoCP(document.getElementById("CPostal"))) {
			document.getElementById("CPostal").focus();
			return false;		
		}
		
		return true;		
	}
	
	//comprueba que el código postal no sea mayor que 5 caracteres y que 
	//sea un número.
	function validoCP(cpdato){
		/*if(cpdato.value.length>5){
			alert("El código postal no puede tener más de 5 caracteres---");
			cpdato.focus();
			return false;
		}*/
		return true;		
	}
	//función que comprueba que para el teléfono no haya más de 11 caracteres	
	function validoTelefono(telefono){  
		if(telefono.value.length>11){
			alert("El teléfono no puede contener más de 11 dígitos");
			telefono.focus();
			return false;
		}
		for(i=0;i<telefono.value.length;i++){
			if(!validoFormato("^[0-9]{1}",telefono.value.charAt(i))){
				alert("El teléfono no puede contener caracteres no numéricos");
				telefono.focus();
				return false;
			}
		}
		return true;
		
	}		
	//función que comprueba que el mensaje no sea superior a 3000 caracteres.
	function validoMensaje(mensaje){
		if(!maxCaracteres(mensaje,3000)){
			alert("El mensaje no puede contener más de 3000 caracteres");
			mensaje.focus();
			return false;
		}
		return true;
	}	
	
	function maxCaracteres(texto,caracteres){
		if(texto.length>caracteres){
			return false;
		}
		return true;

	}
	
	function seleccionarComboTexto(combo, texto){
		for(i=0;i < combo.length;i++) {
		   if (combo[i].text == texto) {
		   	  combo.selectedIndex = i;			  
		   	  return 1;		   	  
		   }
		}
		
	}
		
	
	//Si el valor de postal es =1 se le pasa en el onload del formulario
	function valido(objeto,campo){
		if(objeto!=null&&objeto.value==""){
			objeto.focus();
			alert("Por favor, especifique" + campo + ".");
			return false;
		}
		return true;				
	}
	
	//función que comprueba que esté aceptada la cláusula	
	function validarClausula(){
		if (document.frm.Clausula[0].checked == false){
			alert("Debe aceptar la cláusula para poder solicitar más información");
			return false;
		}
		return true;
	}	
	
/*	
	function mostrar()
	{
		if(document.frm.pais[document.frm.pais.selectedIndex].value=="ESPAÑA"){
			document.getElementById('imgcp').style.visibility="visible";
			control=1;
		}
		
		//para los formularios en los que aunque el país no sea España es necesario un cod postal 
		if((document.frm.pais[document.frm.pais.selectedIndex].value!="ESPAÑA")&&(postal==1)){
			document.getElementById('imgcp').style.visibility="visible";
			control=1;
		}
		
		//formularios con país !="ESPAÑA"
		if((document.frm.pais[document.frm.pais.selectedIndex].value!="ESPAÑA")&&(postal==0)){
			document.getElementById('imgcp').style.visibility="hidden";
			control=0;
		}
		
		//Guardar el codigo del país seleccionado
		if (document.frm.codPais) //EL CAMPO CODPAIS SOLO EXISTIRA EN LOS FORMULARIOS DE PARTICULARES
		{
			var index = document.frm.pais.selectedIndex;
			document.frm.codPais.value=codigosPais[index+1];
		}
	}
*/
	

