// ---------------- IDENTIFICAMOS EL TIPO DE NAVEGADOR --------------------------- //

var NAVEGADOR="";
var brow = (navigator.appName);
if (brow == "Netscape")
	NAVEGADOR = "NS";
else if (brow == "Microsoft Internet Explorer")
	NAVEGADOR = "IE"	

// ------------------------------------------------------------------------------- //


// ************************** VARIABLES GLOBALES MENSAJES ************************ //
// ******************************************************************************* //

var seleccioneopcion;
var nohayelementos;
var maximasareasseleccionada;
var maximasofertasseleccionada;

var introducirNombre;
var introducirApellido1;
var introducirApellido2;
var introducirFechaNacimiento;
var introducirDireccion;
var introducirTelefono;
var introducirEmail;
var introducirProvincia;
var introducirPais;
var introducirNacionalidad;

var introducirTitulacion;
var introducirPeriodoTitulacion;

var introducirTipoDisponibilidad;
var introducirTipoMovilidad;

var introducirRangoSalarial;
var introducirNombreConocido;

var introducirLPD;

var ficheroExtensionIncorrecta;
var campoDemasiadoLargo;

var maxLongTextArea = 1990;

// ******************************************************************************* //
// ************************ FIN VARIABLES GLOBALES MENSAJES ********************** //


function valoresIniciales()
{
	cambioDisponibilidad();
	cambioMovilidad();
	cambioSolicitud();
	cambioConocido();
	cambioTitulacion();
	
	if (NAVEGADOR == "NS")
	{	
		document.getElementById("bloqueEspecialidadAux").style.visibility='collapse';	
	}
	else if (NAVEGADOR = "IE")
	{	
		document.getElementById("bloqueEspecialidadAux").style.display='none';
	}

}


function compruebaFechaValida()
{
	var objDIA = document.getElementById("dia");
	var objMES = document.getElementById("mes");
	var objANIO = document.getElementById("anio");
	
	var valorDIA =  objDIA.options[objDIA.selectedIndex].value;
	var valorMES =  objMES.options[objMES.selectedIndex].value;
	var valorANIO = objANIO.options[objANIO.selectedIndex].value;
	 
	if (valorMES != "-1")
	{
		var maxDIA;
		maxDIA = getDIM(valorMES);
		
		if  (valorANIO!="-1")
			maxDIA = getDIMCompleto(valorMES, valorANIO);
		
		// ANALIZAMOS ENTONCES EL MES y LOS DIA QUE TIENE ACTUALMENTE
		var valorMaximoUltimoDIA = objDIA.options.length;
		var ultimoDia = objDIA.options[(valorMaximoUltimoDIA-1)].value;
		
		
		// COMPROBAMOS SI TENEMOS MÁS DIAS DE LOS PERMITIDO
		if (ultimoDia > maxDIA)
		{
			var diaSeleccionado = valorDIA;
			
			// TENEMOS QUE QUITAR DIAS, SEGUN LA DIFERENCIA ENTRE AMBOS
			var totalDiasQuitar = ultimoDia-maxDIA;
			
			var diaSeleccionadoFinal;
			if (diaSeleccionado<(ultimoDia-totalDiasQuitar))
				diaSeleccionadoFinal = diaSeleccionado;
			else
				diaSeleccionadoFinal=(ultimoDia-totalDiasQuitar);
			
				
			// 1) ELIMINAR TODOS LOS DATOS QUE HAY EN LA COMBO ACTUAL
			
			var optAux = document.createElement("OPTION");
			optAux.value = objDIA.options[0].value;
			optAux.text = objDIA.options[0].text;
			
			while (objDIA.options.length > 0)
			{
				for (var i=0; i<objDIA.options.length; i++)
				{
					objDIA.options[i] = null;
				}
			}
			
			// 2) VOLVEMOS A INSERTAR EL PRIMER ELEMENTO
			
			var opt = document.createElement("OPTION");
			opt.value = optAux.value;
			opt.text = optAux.text;
			
			if (opt.value == diaSeleccionadoFinal)
				opt.selected = true;
			
			if (NAVEGADOR == "NS")
				objDIA.appendChild(opt);
			else if (NAVEGADOR = "IE")	
				objDIA.add(opt);
			
			
			// 3) COPIAMOS LOS ELEMENTOS Y SELECCIONAMOS EL DIA CORRESPONDIENTE
			
			for (var j=1; j<=(ultimoDia-totalDiasQuitar); j++)
			{
				var opt = document.createElement("OPTION");
				opt.value = j;
				opt.text = j;
				
				if (j == diaSeleccionadoFinal)
					opt.selected = true;
				
				if (NAVEGADOR == "NS")
					objDIA.appendChild(opt);
				else if (NAVEGADOR = "IE")	
					objDIA.add(opt);
			}
		}
		
		else
		{
			
			// TENEMOS QUE METER DIAS, SEGUN LA DIFERENCIA ENTRE AMBOS
			var totalDiasMeter = maxDIA-ultimoDia;
			
			// 1) INSERTAMOS LOS NUEVOS ELEMENTOS (SE SUPONE QUE LA SELECCION SE MANTIENE)
			
			var maximoACTUALIZADO = (objDIA.options.length * 1);
			
			for (var j=0; j<totalDiasMeter; j++)
			{
				var opt = document.createElement("OPTION");
				opt.value = maximoACTUALIZADO+ j;
				opt.text = maximoACTUALIZADO+ j;
				
				if (NAVEGADOR == "NS")
					objDIA.appendChild(opt);
				else if (NAVEGADOR = "IE")	
					objDIA.add(opt);
			}
		}
	}
	
	//OBTENEMOS EL VALOR FINAL
	valorDIA =  objDIA.options[objDIA.selectedIndex].value;
	valorMES =  objMES.options[objMES.selectedIndex].value;
	valorANIO = objANIO.options[objANIO.selectedIndex].value;
	
	if (valorDIA != "-1" && valorMES != "-1" && valorANIO!="-1")
	{
		if (valorDIA*1<10)
			valorDIA="0"+valorDIA;
		if (valorMES*1<10)
			valorMES="0"+valorMES;
		
		document.getElementById("fechanacimiento").value=valorDIA+"/"+valorMES+"/"+valorANIO;
		
		//ANALIZAMOS SI LA FECHA OBTENIDA ES VERDADERA
		var fechaACTUALIZADA = document.getElementById("fechanacimiento").value;
		//alert (fechaACTUALIZADA);
		document.getElementById("fechanacimientoresultado").value=isNaN(fechaACTUALIZADA);
	}
	else
	{
		document.getElementById("fechanacimientoresultado").value="false";
	}
	
	//alert(document.getElementById("fechanacimientoresultado").value);
		
}

// Get Days In Month
function getDIM(m)
{
	var d=31;
	if(m==2)
		d=28;
	else if(m==4||m==6||m==9||m==11) 
		d=30;
	return d;
}

// Get Days In Month
function getDIMCompleto(m,yr)
{
	var d=31;
	if(m==2)
	{
		//d=((yr/4)==Math.floor(yr/4))? 29:28;
		if((yr/4)==Math.floor(yr/4))
		{
			if((yr/400)==Math.floor(yr/400))
				d=29;
			else
			{
				if((yr/100)==Math.floor(yr/100))
					d=28;
				else
					d=29;
			}
		}
		else
			d=28;
	}		
	else if(m==4||m==6||m==9||m==11) 
		d=30;
	return d;
}

function compruebaFechaTitulacion()
{
	var objINICIO = document.getElementById("titulacioninicio");
	var objFIN = document.getElementById("titulacionfin");
	
	var valorINICIO =  objINICIO.options[objINICIO.selectedIndex].value;
	var valorFIN =  objFIN.options[objFIN.selectedIndex].value;
	
	valorINICIO = valorINICIO*1;
	valorFIN = valorFIN*1;
	
	if (valorFIN=="" || valorFIN>=valorINICIO)
		document.getElementById("fechatitulacionresultado").value="true";
	else
		document.getElementById("fechatitulacionresultado").value="false";
		
	//alert(document.getElementById("fechatitulacionresultado").value);	
		
}

function cambioDisponibilidad()
{
	var valor;
	var radio = document.getElementsByName("disponibilidadViajar");
	for (var z=0; z<radio.length; z++)
	{
		if (radio[z].checked == true)
		{
			valor = radio[z].value;
			break;
		}
	}
	
	if (valor == "S")
	{
		if (NAVEGADOR == "NS")
			document.getElementById("bloqueDisponibilidad").style.visibility='visible';
		else if (NAVEGADOR = "IE")
			document.getElementById("bloqueDisponibilidad").style.display='block';
	}	
	else if (valor == "N")
	{
		if (NAVEGADOR == "NS")
			document.getElementById("bloqueDisponibilidad").style.visibility='collapse';
		else if (NAVEGADOR = "IE")
			document.getElementById("bloqueDisponibilidad").style.display='none';
	}	
		
	combrobacionValidezDisponibilidad();	
	
}

function combrobacionValidezDisponibilidad()
{
	var valor;
	var radio = document.getElementsByName("disponibilidadViajar");
	for (var z=0; z<radio.length; z++)
	{
		if (radio[z].checked == true)
		{
			valor = radio[z].value;
			break;
		}
	}
	
	if (valor == "N")
	{
		document.getElementById("disponibilidadvalida").value = "true";
		document.getElementById("disponibilidad").value = "";
	}
	else if (valor == "S")
	{
		var disponibilidadNac = document.getElementById("disponibilidadNac").checked;
		var disponibilidadInter = document.getElementById("disponibilidadInter").checked;
		
		if (disponibilidadNac == false && disponibilidadInter == false)
		{
			document.getElementById("disponibilidadvalida").value = "false";
			document.getElementById("disponibilidad").value = "";
		}
		else
		{
			document.getElementById("disponibilidadvalida").value = "true";
			
			if (disponibilidadNac == true && disponibilidadInter == true)
				document.getElementById("disponibilidad").value = "TODO";
			else
				if (disponibilidadNac == true)
					document.getElementById("disponibilidad").value = "NAC";
				else
					document.getElementById("disponibilidad").value = "INT";
		}
		
	}
	
	//alert(document.getElementById("disponibilidadvalida").value);
	//alert(document.getElementById("disponibilidad").value);
	
}

function cambioSolicitud()
{
	var objSOLICITUD = document.getElementById("solicitud");
	var valorSOLICITUD =  objSOLICITUD.options[objSOLICITUD.selectedIndex].value;
	
	if (valorSOLICITUD == '1')
	{
		if (NAVEGADOR == "NS")
		{
			document.getElementById("bloqueHorario").style.visibility='visible';
			document.getElementById("bloqueTipoJornada").style.visibility='visible';
			
			document.getElementById("bloqueRangoSalarial").style.visibility='collapse';
		}
		else if (NAVEGADOR = "IE")
		{
			document.getElementById("bloqueHorario").style.display='block';
			document.getElementById("bloqueTipoJornada").style.display='block';
			
			document.getElementById("bloqueRangoSalarial").style.display='none';
		}
	}
	else if (valorSOLICITUD == '2')
	{
		if (NAVEGADOR == "NS")
		{
			document.getElementById("bloqueHorario").style.visibility='collapse';
			document.getElementById("bloqueTipoJornada").style.visibility='collapse';
			
			document.getElementById("bloqueRangoSalarial").style.visibility='visible';
		}
		else if (NAVEGADOR = "IE")
		{
			document.getElementById("bloqueHorario").style.display='none';
			document.getElementById("bloqueTipoJornada").style.display='none';
			
			document.getElementById("bloqueRangoSalarial").style.display='block';
		}
	}
}

function cambioConocido()
{
	var valor;
	var radio = document.getElementsByName("algunconocido");
	for (var z=0; z<radio.length; z++)
	{
		if (radio[z].checked == true)
		{
			valor = radio[z].value;
			break;
		}
	}
	
	if (valor == "S")
	{
		if (NAVEGADOR == "NS")
			document.getElementById("bloqueDatosConocido").style.visibility='visible';
		else if (NAVEGADOR = "IE")
			document.getElementById("bloqueDatosConocido").style.display='block';
	}	
	else if (valor == "N")
	{
		if (NAVEGADOR == "NS")
			document.getElementById("bloqueDatosConocido").style.visibility='collapse';
		else if (NAVEGADOR = "IE")
			document.getElementById("bloqueDatosConocido").style.display='none';
	}
}

function cambioTitulacion()
{
	// 1) IDENTIFICAMOS CUAL ES LA TITULACION SELECCIONADA
	
	var objTITULACION = document.getElementById("titulacion");
	var objESPECIALIDAD = document.getElementById("especialidad");
	var objESPECIALIDADAUX = document.getElementById("especialidadAux");
	
	var valorTITULACION =  objTITULACION.options[objTITULACION.selectedIndex].value;
	
	if (valorTITULACION > 0)
	{
		// 2) BUSCAMOS SI DICHA TITULACIÓN TIENE ESPECIALIDADES ASOCIADAS
		
		var valorOpcionAuxiliar;
		var datos = new Array();
		var tieneEspecialidad = false;
		
		for (var i=0; i<objESPECIALIDADAUX.options.length; i++)
		{
			valorOpcionAuxiliar = objESPECIALIDADAUX.options[i];
			datos = valorOpcionAuxiliar.value.split("~");
			if (datos[0]==valorTITULACION)
			{
				tieneEspecialidad = true;
				break;
			}
		}
		
		if(tieneEspecialidad)
		{
			// 3) SI TIENES ACTUALIAMOS LA COMBO y SINO MOSTRAMOS MENSAJE DE QUE NO TIENE ELEMENTOS
			
				// 3.1) BORRAMOS TODOS ELEMENTOS ACTUALES QUE CONTIENE LA COMBO DE ESPECIALIDAD
					
				while (objESPECIALIDAD.options.length > 0)
				{
					for (var i=0; i<objESPECIALIDAD.options.length; i++)
					{
						objESPECIALIDAD.options[i] = null;
					}
				}
			
				// 3.2) CARGAMOS EL MENSAJE DE QUE SELECCIONE UNA OPCION
				
				var opt = document.createElement("OPTION");
				opt.value = "0";
				opt.text = "- "+seleccioneopcion+" -";
				
				if (NAVEGADOR == "NS")
					objESPECIALIDAD.appendChild(opt);
				else if (NAVEGADOR = "IE")	
					objESPECIALIDAD.add(opt);
			
				// 3.3) CARGAMOS LOS ELEMENTOS
			
				for (var i=0; i<objESPECIALIDADAUX.options.length; i++)
				{
					valorOpcionAuxiliar = objESPECIALIDADAUX.options[i];
					datos = valorOpcionAuxiliar.value.split("~");
					if (datos[0]==valorTITULACION)
					{
						var opt = document.createElement("OPTION");
						opt.value = valorOpcionAuxiliar.value;
						opt.text = valorOpcionAuxiliar.text
						
						if (NAVEGADOR == "NS")
							objESPECIALIDAD.appendChild(opt);
						else if (NAVEGADOR = "IE")	
							objESPECIALIDAD.add(opt);
					}
				}
			
		}
		else
		{
			// 1.1) BORRAMOS TODOS ELEMENTOS ACTUALES QUE CONTIENE LA COMBO DE ESPECIALIDAD
				
			while (objESPECIALIDAD.options.length > 0)
			{
				for (var i=0; i<objESPECIALIDAD.options.length; i++)
				{
					objESPECIALIDAD.options[i] = null;
				}
			}
				
			// 1.2) CARGAMOS EL MENSAJE DE QUE NO HAY ELEMENTOS
			
			var opt = document.createElement("OPTION");
			opt.value = "-1";
			opt.text = nohayelementos;
			
			if (NAVEGADOR == "NS")
				objESPECIALIDAD.appendChild(opt);
			else if (NAVEGADOR = "IE")	
				objESPECIALIDAD.add(opt);
		}
			
	}
	else
	{
		// 1.1) BORRAMOS TODOS ELEMENTOS ACTUALES QUE CONTIENE LA COMBO DE ESPECIALIDAD
				
		while (objESPECIALIDAD.options.length > 0)
		{
			for (var i=0; i<objESPECIALIDAD.options.length; i++)
			{
				objESPECIALIDAD.options[i] = null;
			}
		}
			
		// 1.2) CARGAMOS EL MENSAJE DE QUE NO HAY ELEMENTOS
		
		var opt = document.createElement("OPTION");
		opt.value = "-1";
		opt.text = nohayelementos;
		
		if (NAVEGADOR == "NS")
			objESPECIALIDAD.appendChild(opt);
		else if (NAVEGADOR = "IE")	
			objESPECIALIDAD.add(opt);
	}	
}

function compruebaAreasSeleccionada(area)
{
	// 1) LO PRIMERO ES IDENTIFICAR EL NÚMERO DE ELEMENTOS TIPO AREA QUE TENEMOS
	
	var totalareas = 0;
	var elementosINPUT=document.getElementsByTagName("input");
  	
  	for (var i=0; i<elementosINPUT.length; i++)
  	{	
  		if (document.getElementsByTagName("input")[i].type == "checkbox")
  		{
	  		var nombre = document.getElementsByTagName("input")[i].name;
	  		
			var auxiliar = nombre.substring(0,5);
			
			if (auxiliar == "area_")
				totalareas = totalareas +1
		}			
  	}
  	
  	totalareas = totalareas*1;
  	
  	// 2) SI TENEMOS MAS DE 3 ELEMENTOS DEBEMOS COMPROBAMOS QUE SOLO SEAN SELECCIONADOS 3
  	if (totalareas > 3)
  	{
  		checkeado="";
  		totalcheckeado=0;
  		var datos = new Array();
  		
  		for (var i=0; i<elementosINPUT.length; i++)
	  	{	
	  		if (document.getElementsByTagName("input")[i].type == "checkbox")
	  		{
		  		var nombre = document.getElementsByTagName("input")[i].name;
		  		
				var auxiliar = nombre.substring(0,5);
				
				if (auxiliar == "area_")
				{
					if(document.getElementsByTagName("input")[i].checked == true)
					{
						totalcheckeado = totalcheckeado+1;
						
						if (totalcheckeado > 3)
						{
							if (area.checked == true)
								area.checked = false;
							
							alert (maximasareasseleccionada);
						}
						else
						{
							datos = nombre.split("area_");
							checkeado=checkeado+datos[1]+";";
						}	
					}
				}	
			}			
	  	}
  		
  		document.getElementById("areasseleccionadas").value=checkeado;
  	
  	}
  	// 3) SI TENEMOS MENOS DE 3 ELEMENTOS ACTUALIZAMOS CUALES SON LA AREAS SELECCIONADAS
  	else
  	{
  		checkeado="";
  		var datos = new Array();
  		
  		for (var i=0; i<elementosINPUT.length; i++)
	  	{	
	  		if (document.getElementsByTagName("input")[i].type == "checkbox")
	  		{
		  		var nombre = document.getElementsByTagName("input")[i].name;
		  		
				var auxiliar = nombre.substring(0,5);
				
				if (auxiliar == "area_")
				{
					if(document.getElementsByTagName("input")[i].checked == true)
					{
						datos = nombre.split("area_");
						checkeado=checkeado+datos[1]+";";
					}
				}	
			}			
	  	}
  		
  		document.getElementById("areasseleccionadas").value=checkeado;
  	}
	
	//alert(document.getElementById("areasseleccionadas").value);
	
}


function ofertasSeleccionadas()
{
	// 1) LO PRIMERO ES IDENTIFICAR EL NÚMERO DE ELEMENTOS TIPO OFERTA QUE TENEMOS
	
	var totalofertas = 0;
	var elementosINPUT=document.getElementsByTagName("input");
  	
  	for (var i=0; i<elementosINPUT.length; i++)
  	{	
  		if (document.getElementsByTagName("input")[i].type == "checkbox")
  		{
	  		var nombre = document.getElementsByTagName("input")[i].name;
	  		
			var auxiliar = nombre.substring(0,7);
			
			if (auxiliar == "oferta_")
				totalofertas = totalofertas +1
		}			
  	}
  	
  	totalofertas = totalofertas*1;
  	
  	// 2) SI EXISTEN OFERTAS DEBEMOS RECOGER SUS ID
  	if (totalofertas > 0)
  	{
  		checkeado="";
  		totalcheckeado=0;
  		var datos = new Array();
  		
  		for (var i=0; i<elementosINPUT.length; i++)
	  	{	
	  		if (document.getElementsByTagName("input")[i].type == "checkbox")
	  		{
		  		var nombre = document.getElementsByTagName("input")[i].name;
		  		
				var auxiliar = nombre.substring(0,7);
				
				if (auxiliar == "oferta_")
				{
					if(document.getElementsByTagName("input")[i].checked == true)
					{
						datos = nombre.split("oferta_");
						checkeado=checkeado+datos[1]+";";	
					}
				}	
			}			
	  	}
  		
  		document.getElementById("ofertasseleccionadas").value=checkeado;
  	}
  	
  	// alert(document.getElementById("ofertasseleccionadas").value);
}



function validarNewCurriculum()
{
	var f = document.getElementById("formcv");
	
	// COMPROBAMAOS SI HAN ADJUNTADO UN FICHERO y DE SER ASI CUAL ES SU EXTENSION
	var curriculum = rtrim(ltrim(document.getElementById("curriculum").value));
	
	if (curriculum!="")
	{
		document.getElementById("hayfichero").value = "si";
		
		var ruta=new Array();
		var extension="";
		ruta = curriculum.split(".");
		extension=ruta[ruta.length-1];
		
		document.getElementById("extensionfichero").value = extension;
	}
	else
		document.getElementById("hayfichero").value = "no";
	
	
	// RECOGEMOS LOS VALORES DE LAS OFERTAS SELECCIONADAS
	ofertasSeleccionadas();
	
	
	// COMPROBACIONES DEL FORMULARIO
	
	// 1) NOMBRE
	var nombre = rtrim(ltrim(document.getElementById("nombre").value));
	
	// 2) APELLIDO 1
	var apellido1 = rtrim(ltrim(document.getElementById("apellido1").value));
	
	// 3) APELLIDO 2
	var apellido2 = rtrim(ltrim(document.getElementById("apellido2").value));
	
	// 4) FECHA NACIMIENTO
	var fechanacimientoresultado = document.getElementById("fechanacimientoresultado").value;
	
	// 5) DIRECCION
	var direccion = rtrim(ltrim(document.getElementById("direccion").value));
	
	// 6) TELEFONO
	var telefono = rtrim(ltrim(document.getElementById("telefono").value));
	
	// 7) EMAIL
	var email = rtrim(ltrim(document.getElementById("email").value));
	
	// 8) PROVINCIA
	var provincia = rtrim(ltrim(document.getElementById("provincia").value));
	
	// 9) PAIS
	var pais = rtrim(ltrim(document.getElementById("pais").value));
	
	// 10) NACIONALIDAD
	var nacionalidad = rtrim(ltrim(document.getElementById("nacionalidad").value));
	
	// 11) TITULACION
	var objTITULACION = document.getElementById("titulacion");	
	var valorTITULACION =  objTITULACION.options[objTITULACION.selectedIndex].value;
	
	// 12) FECHAS TITULACIÓN 
	var fechatitulacionresultado= document.getElementById("fechatitulacionresultado").value;
	
	// 13) SELECCIÓN DISPONIBILIDAD
	combrobacionValidezDisponibilidad();
	var disponibilidadvalida = document.getElementById("disponibilidadvalida").value;
	
	// 14) SELECCIÓN MOVILIDAD
	combrobacionValidezMovilidad();
	var movilidadvalida = document.getElementById("movilidadvalida").value;
	
	// 15) TIPO DE SOLICITUD SELECCIONADA
	var objSOLICITUD = document.getElementById("solicitud");
	var valorSOLICITUD =  objSOLICITUD.options[objSOLICITUD.selectedIndex].value;
	
	// 16) RANGO SALARIAL
	var objRANGOSALARIAL = document.getElementById("rangosalarial");
	var valorRANGOSALARIAL =  objRANGOSALARIAL.options[objRANGOSALARIAL.selectedIndex].value;
	
	// 17) SELECCION CONOCIDO
	var conocido;
	var radio = document.getElementsByName("algunconocido");
	for (var z=0; z<radio.length; z++)
	{
		if (radio[z].checked == true)
		{
			conocido = radio[z].value;
			break;
		}
	}
	
	// 18) NOMBRE CONOCIDO
	var datosconocido = rtrim(ltrim(document.getElementById("datosconocido").value));
	
	if (nombre!="")
	{
		if (apellido1!="")
		{
			//if (apellido2!="")
			//{
				if (fechanacimientoresultado=="true")
				{
					if (direccion!="")
					{
						if (telefono!="")
						{
							if (!esCorreoValido(f.email))
							{
								if (provincia!="")
								{
									if (pais!="")
									{
										if (nacionalidad!="")
										{
											if (valorTITULACION > 0)
											{
												if (fechatitulacionresultado=="true")
												{
													if (disponibilidadvalida=="true")
													{
														if (movilidadvalida=="true")
														{
															if (valorSOLICITUD == '2')
															{
																if (valorRANGOSALARIAL > 0)
																{
																	if (conocido == "S")
																	{
																		if (datosconocido!="")
																		{
																			if (extensionOK (extension))
																			{
																				if (document.getElementById("aceptarLPD").checked == true)
																				{
																					transformarTextArea();
																					f.submit();
																				}
																				else
																				{
																					alert(introducirLPD);
																				}
																			}
																			else
																			{
																				alert (ficheroExtensionIncorrecta);
																			}
																		}
																		else
																		{
																			document.getElementById("datosconocido").focus();
																			alert(introducirNombreConocido);
																		}
																	}
																	else
																	{
																		if (extensionOK (extension))
																		{
																			if (document.getElementById("aceptarLPD").checked == true)
																			{
																				transformarTextArea();
																				f.submit();
																			}
																			else
																			{
																				alert(introducirLPD);
																			}
																		}
																		else
																		{
																			alert (ficheroExtensionIncorrecta);
																		}
																	}	
																}
																else
																{
																	alert(introducirRangoSalarial);
																}
															}
															else
															{
																if (conocido == "S")
																{
																	if (datosconocido!="")
																	{
																		if (extensionOK (extension))
																		{
																			if (document.getElementById("aceptarLPD").checked == true)
																			{
																				transformarTextArea();
																				f.submit();
																			}
																			else
																			{
																				alert(introducirLPD);
																			}
																		}
																		else
																		{
																			alert (ficheroExtensionIncorrecta);
																		}
																	}
																	else
																	{
																		document.getElementById("datosconocido").focus();
																		alert(introducirNombreConocido);
																	}
																}
																else
																{
																	if (extensionOK (extension))
																	{
																		if (document.getElementById("aceptarLPD").checked == true)
																		{
																			transformarTextArea();
																			f.submit();
																		}
																		else
																		{
																			alert(introducirLPD);
																		}
																	}
																	else
																	{
																		alert (ficheroExtensionIncorrecta);
																	}
																}	
															}
														}
														else
														{
															alert(introducirTipoMovilidad);
														}
													}
													else
													{
														alert(introducirTipoDisponibilidad);
													}
												}
												else
												{
													alert(introducirPeriodoTitulacion);
												}
											}
											else
											{
												alert(introducirTitulacion);
											}
										}
										else
										{
											document.getElementById("nacionalidad").focus();
											alert(introducirNacionalidad);
										}
									}
									else
									{
										document.getElementById("pais").focus();
										alert(introducirPais);
									}
								}
								else
								{
									document.getElementById("provincia").focus();
									alert(introducirProvincia);
								}
							}
							else
							{
								document.getElementById("email").focus();
								alert(introducirEmail);
							} 
						}
						else
						{
							document.getElementById("telefono").focus();
							alert(introducirTelefono);
						}
					}
					else
					{
						document.getElementById("direccion").focus();
						alert(introducirDireccion);
					}
				}
				else
				{
					alert(introducirFechaNacimiento);
				}
			//}
			//else
			//{
			//	document.getElementById("apellido2").focus();
			//	alert(introducirApellido2);
			//}
		}
		else
		{
			document.getElementById("apellido1").focus();
			alert(introducirApellido1);
		}
	}
	else
	{
		document.getElementById("nombre").focus();
		alert(introducirNombre);
	}
}

function cancelarNewCurriculum()
{
	var f = document.formcv;
	f.reset();
	valoresIniciales();
}

function verDetalleOferta (id,idioma)
{
		var strCaracteristica = "top=0, left=0, width=470, height=450, scrollbars=yes, toolbar=no, menubar=no, location=no, directories=no, modal=yes";
		modal=window.open("/ibding/selecciona.do?op=detofertacv&id="+id+"&idioma="+idioma,"ventanaDetalleOferta",strCaracteristica);
}

function cambioMovilidad()
{
	var valor;
	var radio = document.getElementsByName("movilidadGeografica");
	for (var z=0; z<radio.length; z++)
	{
		if (radio[z].checked == true)
		{
			valor = radio[z].value;
			break;
		}
	}
	
	if (valor == "S")
	{
		if (NAVEGADOR == "NS")
			document.getElementById("bloqueMovilidad").style.visibility='visible';
		else if (NAVEGADOR = "IE")
			document.getElementById("bloqueMovilidad").style.display='block';
	}	
	else if (valor == "N")
	{
		if (NAVEGADOR == "NS")
			document.getElementById("bloqueMovilidad").style.visibility='collapse';
		else if (NAVEGADOR = "IE")
			document.getElementById("bloqueMovilidad").style.display='none';
	}	
		
	combrobacionValidezMovilidad();	
	
}

function combrobacionValidezMovilidad()
{
	var valor;
	var radio = document.getElementsByName("movilidadGeografica");
	for (var z=0; z<radio.length; z++)
	{
		if (radio[z].checked == true)
		{
			valor = radio[z].value;
			break;
		}
	}
	
	if (valor == "N")
	{
		document.getElementById("movilidadvalida").value = "true";
		document.getElementById("movilidad").value = "";
	}
	else if (valor == "S")
	{
		var movilidadNac = document.getElementById("movilidadNac").checked;
		var movilidadInter = document.getElementById("movilidadInter").checked;
		
		if (movilidadNac == false && movilidadInter == false)
		{
			document.getElementById("movilidadvalida").value = "false";
			document.getElementById("movilidad").value = "";
		}
		else
		{
			document.getElementById("movilidadvalida").value = "true";
			
			if (movilidadNac == true && movilidadInter == true)
				document.getElementById("movilidad").value = "TODO";
			else
				if (movilidadNac == true)
					document.getElementById("movilidad").value = "NAC";
				else
					document.getElementById("movilidad").value = "INT";
		}
		
	}
}

function compruebaOfertasSeleccionada(oferta)
{
	// 1) LO PRIMERO ES IDENTIFICAR EL NÚMERO DE ELEMENTOS TIPO OFERTA QUE TENEMOS
	
	var totalofertas = 0;
	var elementosINPUT=document.getElementsByTagName("input");
  	
  	for (var i=0; i<elementosINPUT.length; i++)
  	{	
  		if (document.getElementsByTagName("input")[i].type == "checkbox")
  		{
	  		var nombre = document.getElementsByTagName("input")[i].name;
	  		
			var auxiliar = nombre.substring(0,7);
			
			if (auxiliar == "oferta_")
				totalofertas = totalofertas +1
		}			
  	}
  	
  	totalofertas = totalofertas*1;
  	
  	// 2) SI TENEMOS MAS DE 5 ELEMENTOS DEBEMOS COMPROBAMOS QUE SOLO SEAN SELECCIONADOS 5
  	if (totalofertas > 5)
  	{
  		checkeado="";
  		totalcheckeado=0;
  		var datos = new Array();
  		
  		for (var i=0; i<elementosINPUT.length; i++)
	  	{	
	  		if (document.getElementsByTagName("input")[i].type == "checkbox")
	  		{
		  		var nombre = document.getElementsByTagName("input")[i].name;
		  		
				var auxiliar = nombre.substring(0,7);
				
				if (auxiliar == "oferta_")
				{
					if(document.getElementsByTagName("input")[i].checked == true)
					{
						totalcheckeado = totalcheckeado+1;
						
						if (totalcheckeado > 5)
						{
							if (oferta.checked == true)
								oferta.checked = false;
							
							alert (maximasofertasseleccionada);
						}
						else
						{
							datos = nombre.split("oferta_");
							checkeado=checkeado+datos[1]+";";
						}	
					}
				}	
			}			
	  	}
  		
  		document.getElementById("ofertasseleccionadas").value=checkeado;
  	
  	}
  	// 3) SI TENEMOS MENOS DE 5 ELEMENTOS ACTUALIZAMOS CUALES SON LA AREAS SELECCIONADAS
  	else
  	{
  		checkeado="";
  		var datos = new Array();
  		
  		for (var i=0; i<elementosINPUT.length; i++)
	  	{	
	  		if (document.getElementsByTagName("input")[i].type == "checkbox")
	  		{
		  		var nombre = document.getElementsByTagName("input")[i].name;
		  		
				var auxiliar = nombre.substring(0,7);
				
				if (auxiliar == "oferta_")
				{
					if(document.getElementsByTagName("input")[i].checked == true)
					{
						datos = nombre.split("oferta_");
						checkeado=checkeado+datos[1]+";";
					}
				}	
			}			
	  	}
  		
  		document.getElementById("ofertasseleccionadas").value=checkeado;
  	}
	
	//alert(document.getElementById("areasseleccionadas").value);
	
}

/*
Nombre:
	extensionOK
Descripcion:
	Comprueba que la cadena recibida (extensión del fichero a subir) está
	entre las extensiones válidas para el CV.
*/
function extensionOK (str)
{
	var extensionesPermitidas = new Array ('PDF', 'DOC', 'DOCX');
	
	if (str != null && str.length > 0)
	{
		for (i = 0; i < extensionesPermitidas.length && extensionesPermitidas[i] != str.toUpperCase(); i++){}
	}
	
	return (i < extensionesPermitidas.length);
}

/************************************************************************************
Nombre:
	rtrim
Parámetros:
Autor:
	Iberinco
Fecha:
Descripción:
	Elimina los espacios en blanco de una cadena por la derecha.
Modificaciones:

**************************************************************************************/	
function rtrim(str)
{
	str=str + ""  // evitar error si no se pasa nada	
	while (str.substring(str.length-1,str.length) == ' '|| str.substring(str.length-1,str.length)=='\r' || 
		  str.substring(str.length-1,str.length)=='\f' || str.substring(str.length-1,str.length)=='\n' || 
		  str.substring(str.length-1,str.length)=='\t')
	{
		str = str.substring(0,str.length-1);
	}
	return str;
}

/************************************************************************************
Nombre:
	ltrim
Parámetros:
Autor:
	Iberinco
Fecha:
Descripción:
	Elimina los espacios en blanco de una cadena por la izquierda.
Modificaciones:

**************************************************************************************/	
function ltrim(str)
{
	str = "" + str  // evitar error si no se pasa nada

	while(str.substring(0,1)==' ' || str.substring(0,1)=='\r' || 
		  str.substring(0,1)=='\f' || str.substring(0,1)=='\n' || 
		  str.substring(0,1)=='\t') {
		str = str.substring(1, str.length);		
	} 	
	return str;
}

function validar(e) {
  return !(e.keyCode==86 && e.ctrlKey)
}

function compruebaTextarea (textArea) {
	var elem = document.getElementById(textArea.id);
	if (elem.value.replace(/(\r\n)|(\n)/g, "<br>").length > maxLongTextArea) {
		alert (campoDemasiadoLargo);
		setTimeout("document.getElementById('"+textArea.id+"').focus()",1);
	} /*else {
		elem.value = elem.value.replace(/(\r\n)|(\n)/g, "<br>");
	}*/
}

function transformarTextArea ()
{
	var textAreas = document.getElementsByTagName("textarea");
	for (i = 0; i < textAreas.length; i++)
	{
		textAreas[i].value = textAreas[i].value.replace(/(\r\n)|(\n)/g, "<br>");
	}
}
