
var smsErrorFecha = "La Fecha de Inicio introducida es mayor a la Fecha de Fin.Por favor verifique la hora";
var smsErrorFechaInicioEspacio = "A esa hora de inicio el espacio no puede ser reservado.Por favor verifique la hora";
var smsErrorFechaFinEspacio = "A esa hora de fin el espacio no puede ser reservado.Por favor verifique la hora";
var smsNIE = "NIE o NIF Incorrecto";
var smsNieNifDni = "DNI, NIF o NIE Incorrecto";
var smsCIF = "CIF Incorrecto";
var smsRequerido = "Por favor, rellene el campo NIE o el Pasaporte";
var smsNieNifDniRequerido = "Por favor, rellene el campo DNI/NIF/NIE o el Pasaporte";
var smsTelefono = "Por favor, rellene el campo Teléfono o el Móvil";

// Descripción: Funcion que traduce todos los campos del fomulario a 1 o 0 para
// realizar la llamada
// Autor: jgarjona
// Modificado "fecha" por "nombre": "descripción del cambio"
// Parámetros: campo que se desea poner en blanco
//
//
//CambiaTodosFiltros
function CambiaCamposFiltrado2Numero(formulario) {
	if (formulario !== null) {
		if (formulario.ec_f_activo !== null) {
			CambiaFiltro(formulario.ec_f_activo);
		}
		if (formulario.ec_f_publicada !== null) {
			CambiaFiltro(formulario.ec_f_publicada);
		}
		if (formulario.ec_f_publicado !== null) {
			CambiaFiltro(formulario.ec_f_publicado);
		}
		if (formulario.ec_f_alarma !== null) {
			CambiaFiltro(formulario.ec_f_alarma);
		}
	}
}



// Descripción: Funcion que traduce el campo de filtrado a 1 o 0
// Autor: jgarjona
// Modificado "fecha" por "nombre": "descripción del cambio"
// Parámetros: campo que se desea poner en blanco
//
//
function CambiaFiltro(campo) {
	var cad = campo.value.toUpperCase();
	if (cad == "SI") {
		campo.value = "1";
	} else {
		if (cad == "NO") {
			campo.value = "0";
		}
	}
}

//Descripcion: Muestra un mensaje de solicita una accion a realizar sobre la BD. Si el usuario
 //confirma la pregunta establece como action del formulaio[0] la uriAction y la ejecuta
 //@param String operacion=Indicar que tipo de operaciones se realizará sobre la BD (ej: crear,borrar, modificar...)
 //@param String objeto=Indicar de tipo de dato sobre el que se realizará la operacion (ej: "usuario")
 //@param String uriAction=Indicar el Action que deseamos que se ejecute si el usuario confirma
 //@param String destino=Indicar en qué sitio se modifica la acción (ej. "la Base de Datos")
 //@author bjestes
function objectEval(text) {
    // eval() breaks when we use it to get an object using the { a:42, b:'x' }
    // syntax because it thinks that { and } surround a block and not an object
    // So we wrap it in an array and extract the first element to get around
    // this.
    // This code is only needed for interpreting the parameter input fields,
    // so you can ignore this for normal use.
    // The regex = [start of line][whitespace]{[stuff]}[whitespace][end of line]
	text = text.replace(/\n/g, " ");
	text = text.replace(/\r/g, " ");
	if (text.match(/^\s*\{.*\}\s*$/)) {
		text = "[" + text + "][0]";
	}
	return eval(text);
}


//function rellenaLocalidades(data){
	//alert('data '+data);
//	DWRUtil.removeAllOptions("localidad", data);
//	DWRUtil.addOptions("localidad", data, "idLocalidad", "nombre");
//}


//Descripcion: Recogemos el formulario de parametros , cambiamos los valores de los campos
 //que nos interesen , el action y lo enviamos
 //@param String accion=Este parametro nos dice el action a invocar
 //@param String idElemento=Este parametro nos dice el id del elemento que se quiere editar
 //@author Borja Vega Lopez
function confirmarAccion(operacion, accion, idElemento) {
	var pregunta = "\xbfEst\xe1 seguro que desea " + operacion + "?";
	if (window.confirm(pregunta)) {
		var formularioParametros = document.getElementById("formParamExtreme");
		formularioParametros.action = accion;
		formularioParametros.idElemento.value = idElemento;
		formularioParametros.submit();
	}
}
function confirmarAccionInmigrante(operacion, accion, idElemento) {
	var pregunta = "\xbfEst\xe1 seguro que desea " + operacion + "?";
	if (window.confirm(pregunta)) {
		var formularioParametros = document.getElementById("formParamExtreme");
		formularioParametros.action = accion;
		formularioParametros.idElemento.value = idElemento;
		var valorIE = 0;
		if (document.getElementById("idInmigranteBase") != null) {
			valorIE = document.getElementById("idInmigranteBase").value;
			formularioParametros.idInmigranteBase.value = valorIE;
		}
		if (valorIE == 0) {
			var formIE = document.getElementById("formulario");
			if (formIE.idInmigranteBase != null) {
				valorIE = formIE.idInmigranteBase.value;
				formularioParametros.idInmigranteBase.value = valorIE;
			}
		}
		formularioParametros.submit();
	}
}
function accionListado(accion, idElemento) {
	var formularioParametros = document.getElementById("formParamExtreme");
	formularioParametros.action = accion;
	formularioParametros.idElemento.value = idElemento;
	formularioParametros.submit();
}
function accionListadoIDInmigrante(accion, idElemento) {
	var formularioParametros = document.getElementById("formParamExtreme");
	formularioParametros.action = accion;
	formularioParametros.idElemento.value = idElemento;
	var valorIE = 0;
	if (document.getElementById("idInmigranteBase") != null) {
		valorIE = document.getElementById("idInmigranteBase").value;
		formularioParametros.idInmigranteBase.value = valorIE;
	}
	if (valorIE == 0) {
		var formIE = document.getElementById("formulario");
		if (formIE.idInmigranteBase != null) {
			valorIE = formIE.idInmigranteBase.value;
			formularioParametros.idInmigranteBase.value = valorIE;
		}
	}
	formularioParametros.submit();
}
function accionListadoInmigrante(accion, idElemento) {
	var formularioParametros = document.getElementById("formParamExtreme");
	formularioParametros.action = accion;
	formularioParametros.idInmigranteBase.value = idElemento;
	formularioParametros.submit();
}



//Descripcion: Recogemos el formulario de parametros , cambiamos los valores de los campos
 //que nos interesen , el action y lo enviamos
 //@param String accion=Este parametro nos dice el action a invocar
 //@author Borja Vega Lopez
function resetExtreme(accion) {
	var formularioResetEstado = document.getElementById("formParamResetExtreme");
	formularioResetEstado.action = accion;
	formularioResetEstado.submit();
}

//Descripcion: Sobreescribe el div que contiene al extremecomponents
 //@param String table
 //@author Borja Vega Lopez
function showTableNode(table) {
	if (table == "La sesi\xf3n ha expirado") {
		var formularioParametros = document.getElementById("formParamExtreme");
		formularioParametros.action = "./Login.do";
		formularioParametros.mensajeSesion.value = "Ha caducado la sesi\xf3n , vuelva a loguearse";
		formularioParametros.submit();
	}
	if (table == "") {
		table = "No existen registros disponibles";
	}
	var obj = document.createElement("div");
	obj.innerHTML = table;
	var idTable = obj.getElementsByTagName("FORM")[0].id;
	var divExtreme = document.getElementById("tableDiv" + "_" + idTable);
	divExtreme.innerHTML = table;
}
function showTable(table) {
   
	if (table == "La sesi\xf3n ha expirado") {
		var formularioParametros = document.getElementById("formParamExtreme");
		formularioParametros.action = "./Login.do";
		formularioParametros.mensajeSesion.value = "Ha caducado la sesi\xf3n , vuelva a loguearse";
		formularioParametros.submit();
	}
	if (table == "") {
		table = "<div class='error'>No existen registros disponibles</div>";
	}
	var divExtreme = document.getElementById("tableDiv");
	divExtreme.innerHTML = table;
}

//Descripcion: Calcula los días entre 2 fechas.
// Si date1 es posterior o igual a date 2 devuelve 1, en caso contrario devuelve la diferencia + 1
//@param String date1,date2
function calculaDias(date1, date2) {
	var fecha1 = fechaInvertidaToCadena(date1);
	var fecha2 = fechaInvertidaToCadena(date2);
	if (fecha1 < fecha2) {
		date1 = date1.split("/");
		date2 = date2.split("/");
		if (date2 != "") {
			var sDate = new Date(date1[2] + "/" + date1[1] + "/" + date1[0]);
			var eDate = new Date(date2[2] + "/" + date2[1] + "/" + date2[0]);
			var daysApart = Math.abs(Math.round((sDate - eDate) / 86400000));
			document.getElementById("num_dias").value = daysApart + 1;
		}
	} else {
		document.getElementById("num_dias").value = 1;
	}
}

//Descripcion: Calcula los días laborables entre 2 fechas (festivos no se tienen en cuenta).
//@param String fromdd,todd
function calculaDiasLaborables(fromdd, todd) {
	var date;
	var datestr = "";
	var ahora = new Date();
	var hoy = ahora.getDate();
	
	//hacemos esta comprobación para el caso en que se seleccione primero fechaFin quedando fechaInicio vacio
	if (fromdd == "") {
		fromdd = todd;
	}
	date1 = fromdd.split("/");
	date2 = todd.split("/");
	var fromdd = new Date(date1[2] + "/" + date1[1] + "/" + date1[0]);
	var todd = new Date(date2[2] + "/" + date2[1] + "/" + date2[0]);
	var dia = fromdd.getDate();
	//para que no pueda elegir un dia menor a la fecha actual
	if (fromdd < ahora) {
		fromdd = ahora;
	}
	if (todd < ahora) {
		todd = ahora;
		fromdd = ahora;
	}
	if (todd < fromdd) {
		todd = fromdd;
	}
	var currentDayOfWeek = fromdd.getDay();
	var fromMonth = fromdd.getMonth();
	var toMonth = todd.getMonth();
	var totalNoOfDays = 0;
	var fromNoDays;
	var noOfDaysLeftInFromMonth;
	var toNoDays;
	var noOfDaysLeftInToMonth;
	if (((toMonth - fromMonth) == 1) && (fromdd.getYear() == todd.getYear())) {
		fromNoDays = returnNoOfDaysInMonth(fromdd.getMonth(), fromdd.getYear());
		noOfDaysLeftInFromMonth = fromNoDays - fromdd.getDate();
		toNoDays = returnNoOfDaysInMonth(todd.getMonth(), todd.getYear());
		noOfDaysLeftInToMonth = todd.getDate();
		totalNoOfDays = noOfDaysLeftInFromMonth + noOfDaysLeftInToMonth;
	} else {
		if (((toMonth - fromMonth) == 0) && (fromdd.getYear() == todd.getYear())) {
			totalNoOfDays = todd.getDate() - fromdd.getDate();
		} else {
			if (fromdd.getYear() == todd.getYear()) {
				fromNoDays = returnNoOfDaysInMonth(fromdd.getMonth(), fromdd.getYear());
				noOfDaysLeftInFromMonth = fromNoDays - fromdd.getDate();
				totalNoOfDays = totalNoOfDays + noOfDaysLeftInFromMonth;
				checkFromMonth = fromMonth + 1;
				for (; checkFromMonth < toMonth; checkFromMonth++) {
					noOfDaysInCurrentMonth = returnNoOfDaysInMonth(checkFromMonth, fromdd.getYear());
					totalNoOfDays = totalNoOfDays + noOfDaysInCurrentMonth;
				}
				toNoDays = returnNoOfDaysInMonth(todd.getMonth(), todd.getYear());
				totalNoOfDays = totalNoOfDays + todd.getDate();
			}
		}
	}
	++totalNoOfDays;
	var noOfWorkingDays = 0;
	date = fromdd.getDate();
	for (i = 0; i < totalNoOfDays; i++) {
		if (currentDayOfWeek > 0 && currentDayOfWeek < 6) {
			if (totalNoOfDays - i != 1) {
				datestr = datestr + date + ", ";
			} else {
				datestr = datestr + date;
			}
			noOfWorkingDays++;
			currentDayOfWeek++;
		} else {
			if (currentDayOfWeek == 0) {
				currentDayOfWeek++;
			} else {
				if (currentDayOfWeek == 6) {
					currentDayOfWeek = 0;
				}
			}
		}
		if (((fromMonth == 0) || (fromMonth == 2) || (fromMonth == 4) || (fromMonth == 6) || (fromMonth == 7) || (fromMonth == 9) || (fromMonth == 11)) && (date < 31)) {
			date++;
		} else {
			if (((fromMonth == 3) || (fromMonth == 5) || (fromMonth == 8) || (fromMonth == 10)) && (date < 30)) {
				date++;
			} else {
				if (((fromdd.Year % 4) == 0) && (fromMonth == 2) && (date < 29)) {
					date++;
				} else {
					if (((fromdd.Year % 4) != 0) && (fromMonth == 2) && (date < 28)) {
						date++;
					} else {
						date = 1;
						fromMonth++;
					}
				}
			}
		}
	}
	document.getElementById("num_dias").value = noOfWorkingDays;
}
function returnNoOfDaysInMonth(month, year) {
	var totalNoOfDays;
	if ((month == 0) || (month == 2) || (month == 4) || (month == 6) || (month == 7) || (month == 9) || (month == 11)) {
		totalNoOfDays = 31;
	} else {
		if ((month == 3) || (month == 5) || (month == 8) || (month == 10)) {
			totalNoOfDays = 30;
		} else {
			if (((year % 4) == 0) && (month == 1)) {
				totalNoOfDays = 28;
			} else {
				if (((year % 4) != 0) && (month == 1)) {
					totalNoOfDays = 29;
				}
			}
		}
	}
	return totalNoOfDays;
}


// Funcion que comprueba y valida 2 campos passwords
function comprobarPasswords(nombre_pass1, nombre_pass2) {
	var p1 = document.getElementById(nombre_pass1).value;
	var p2 = document.getElementById(nombre_pass2).value;
	var espacios = true;
	var cont = 0;
	 
		// Este bucle recorre la cadena para comprobar
	    // que no todo son espacios
	while (espacios && (cont < p1.length)) {
		if (p1.charAt(cont) != " ") {
			espacios = false;
		}
		cont++;
	}
	if (espacios) {
		alert("La contrase\xf1a no puede ser todo espacios en blanco");
		return false;
	}
	if (p1 != p2) {
		alert("Los passwords deben de coincidir");
		return false;
	}
	return true;
}

// Funcion diseniada para validar la existencia/validacion de un determinado
// desplegable, el id de dicho despl. es el campo1, el campo2 representa el
// nombre que se desea que aparezca en el mensaje de validacion (nombre del desplegable)
// Tiene en cuenta la accion del boton 'cancel'
// Si se pulsa dicho boton(cancel), no realiza ninguna operacion, y devuelve true
function comprobarCampoBotonCancel(campo1, campo2) {
	if (bCancel == false) {
		var idmun = document.getElementById(campo1).value;
		if (idmun == 0) {
			alert("El campo " + campo2 + " debe rellenarse");
			return false;
		} else {
			return true;
		}
	}
}

// Funcion que comprueba y valida 2 campos passwords
// Tiene en cuenta la accion del boton 'cancel'
// Si se pulsa dicho boton(cancel), no realiza ninguna operacion, y devuelve true
function comprobarPasswordsBotonCancel(nombre_pass1, nombre_pass2) {
	if (bCancel == false) {
		var p1 = document.getElementById(nombre_pass1).value;
		var p2 = document.getElementById(nombre_pass2).value;
		var espacios = true;
		var cont = 0;
		 
			// Este bucle recorre la cadena para comprobar
		    // que no todo son espacios
		while (espacios && (cont < p1.length)) {
			if (p1.charAt(cont) != " ") {
				espacios = false;
			}
			cont++;
		}
		if ((espacios)&&(cont != 0)) {
			alert("La contrase\xf1a no puede ser todo espacios en blanco");
			return false;
		}
		if (p1 != p2) {
			alert("Los passwords deben coincidir");
			return false;
		}
		return true;
	} else {
		return true;
	}
}


// Chequea los campos usuario y password del formulario de login
function checkFields(login, password, captcha) {
	var missinginfo = "";
	var falta = "";
	if (login === "") {
		missinginfo += "\n     -  Login";
	} else {
		if (login.length < 4) {
			missinginfo += "\nEl login ha de contener m\xednimo 4 caracteres";
		}
	}
	if (password === "") {
		missinginfo += "\n     -  Password";
	} else {
		if (password.length < 4) {
			missinginfo += "\nEl password ha de contener m\xednimo 4 caracteres";
		}
	}
	if (captcha === "") {
		missinginfo += "\n     -  Captcha";
	} else {
		if (captcha.length < 6) {
			missinginfo += "\nEl captcha ha de contener 6 caracteres";
		}
	}
	if (missinginfo !== "") {
		if ((login === "") || (password === "")) {
			falta = "Le ha faltado introducir los siguientes datos:\n";
		}
		missinginfo = falta + missinginfo;
		this.alert(missinginfo);
		return false;
	} else {
		return true;
	}
}

//Descripcion: Marca o desmarca checkbox segun si esta pulsado o no
 //@param check ,cantidad, nameCheckbox
 //@author Borja Vega Lopez
function marcarTodos(check, cantidad, nameCheckbox, numCombo1, numCombo2) {
	var elemento;
	if (!check.checked) {
		for (i = 0; i < cantidad; i++) {
			elemento = document.getElementById(nameCheckbox + i);
			elemento.checked = false;
		}
		checkCombo(numCombo1);
		checkCombo(numCombo2);
	} else {
		for (i = 0; i < cantidad; i++) {
			elemento = document.getElementById(nameCheckbox + i);
			elemento.checked = true;
		}
		checkCombo(numCombo1);
		checkCombo(numCombo2);
	}
	
	var indice;
	for(indice=0;indice<=cantidad;indice++){
		
	
		var div=document.getElementById(indice);
		
		if(div!=null){

			if (check.checked){
				div.style.display='block';
			}else{
				div.style.display='none';
			}
		}
	}
}

//Funciones relacionadas con la herramienta calendar
//Autor : Borja Vega Lopez
//Descripcion: utilidades para comprobacion y manipulacion de fechas

 // funcion que invierte una fecha y la convierte en una cadena.
// 01/10/2007 -> 20071001
function fechaInvertidaToCadena(fecha) {
	var resultado = fecha.substr(6, 4);
	resultado += fecha.substr(3, 2);
	resultado += fecha.substr(0, 2);
	return resultado;
}
// funcion que comprueba si la fecha de inicio es menor o igual que la fecha
// de fin.
function nomenor(cal) {
				// fechaIni almacena la fecha de inicio.
	var fechaInicio = document.getElementById("f_date_ini");
				// fechaFin almacena la fecha de fin 
	var fechaFin = document.getElementById("f_date_fin");
	
	
	// time es la fecha capturada del calendar desde donde se llama a esta
	// funcion
	var time = cal.date.getTime();
	var fecha1 = fechaInvertidaToCadena(fechaInicio.value);
	var fecha2 = fechaInvertidaToCadena(fechaFin.value);
	var hoy = new Date();
	var fechaActual = hoy.print("%d/%m/%Y");
	var fechaActualString = fechaInvertidaToCadena(fechaActual);
	if (fecha1 < fechaActualString) {
		//La fecha de inicio sera la actual
		fechaInicio.value = hoy.print("%d/%m/%Y");
		time = hoy.getTime();
	}
				
				// si el campo por el que entro en fechaFin
	if (fechaFin == cal.params.inputField) {
					// compruebo que el primer dia no sea mayor o igual que el ultimo
					// dia, y si el primer dia esta vacio.
		if (fecha1 >= fecha2) {
		
			
			//Si la fecha de fin seleccionada es menor o igual a la actual
			if (fecha2 <= fechaActualString) {
			
				//La fecha de inicio sera la actual
				fechaInicio.value = hoy.print("%d/%m/%Y");
				
				//La fecha de fin sera la actual mas un dia
				hoy.setTime(hoy.getTime() + (24 * 60 * 60 * 1000) * 30); // añadimos 30 días
				fechaFin.value = hoy.print("%d/%m/%Y");
			} else {
				// le quito un dia para que siga manteniendo la diferencia.
				fechaInicio.value = new Date(time - Date.DAY).print("%d/%m/%Y");
			}
		}
	} else {
					// compruebo que el primer dia no sea mayor o igual que el ultimo dia.
		if (fecha1 >= fecha2) {
						// le sumo un dia para que siga manteniendo la diferencia.
			fechaFin.value = new Date(time + (Date.DAY * 30)).print("%d/%m/%Y");
		}
	}
}
function validaFechasContrataciones(cal) {
				// fechaPre almacena la fecha de presentación.
	var fechaPre = document.getElementById("f_date_presentacion");
				// fechaWeb almacena la fecha de presentación vía web 
	var fechaWeb = document.getElementById("f_date_web");
				// fechaEje almacena la fecha de ejecución
	var fechaEje = document.getElementById("f_date_ejecucion");
	
	// time es la fecha capturada del calendar desde donde se llama a esta
	// funcion
	var time = cal.date.getTime();
	var fecha1 = fechaInvertidaToCadena(fechaPre.value);
	var fecha2 = fechaInvertidaToCadena(fechaWeb.value);
	var fecha3 = fechaInvertidaToCadena(fechaEje.value);
	var hoy = new Date();
	var fechaActual = hoy.print("%d/%m/%Y");
	var fechaActualString = fechaInvertidaToCadena(fechaActual);

		//Si entra por fecha Presentacion 
	if (fechaPre == cal.params.inputField) {
		//Valida q la fecha no se menor q la fecha actual
		if (fecha1 < fechaActualString) {
			alert("No puede seleccionar una fecha menor a la fecha actual");
		//La fecha de inicio sera la actual
			fechaPre.value = hoy.print("%d/%m/%Y");
			time = hoy.getTime();
		}
		if (fechaWeb != null && fechaWeb != "") {
			if (fecha2 < fecha1) {
				alert("La fecha de Presentacion Web no puede ser menor a la fecha de Presentaci\xf3n");
				fechaWeb.value = fechaPre.value;
			}
		}
		if (fechaEje != null && fechaWeb != null) {
			if (fecha3 < fecha2) {
				alert("La fecha de Ejecuci\xf3n no puede ser menor a la fechas de Presentaci\xf3n");
				fechaEje.value = fechaWeb.value;
			}
		}
	}			
				// si entra por fecha Presentacion Web
	if (fechaWeb == cal.params.inputField) {
					// compruebo que no sea menor q la fecha actual
		if (fecha2 < fechaActualString) {
			alert("No puede seleccionar una fecha menor a la fecha actual");
			//La fecha Web sera la actual
			fechaWeb.value = hoy.print("%d/%m/%Y");
		}
		if (fecha2 < fecha1) {
			alert("La fecha de Presentaci\xf3n Web no puede ser menor a la fecha de Presentaci\xf3n");
			fechaWeb.value = fechaPre.value;
		}
	}
	if (fechaEje == cal.params.inputField) {
					// compruebo que no sea menor q la fecha actual
		if (fecha3 < fechaActualString) {
			alert("No puede seleccionar una fecha menor a la fecha actual");
			//La fecha Web sera la actual
			fechaEje.value = hoy.print("%d/%m/%Y");
		}
		if (fecha3 < fecha2) {
			alert("La fecha de Ejecuci\xf3n no puede ser menor a las fechas de Presentaci\xf3n");
			fechaEje.value = fechaWeb.value;
		}
	}
} 



// funcion que comprueba si la fecha de inicio es menor o igual que la fecha
// de fin.
function nomenorDatosProfesionales(cal) {
				// fechaIni almacena la fecha de inicio.
	var fechaInicio = document.getElementById("f_date_inicio");
				// fechaFin almacena la fecha de fin 
	var fechaFin = document.getElementById("f_date_final");
	
	// time es la fecha capturada del calendar desde donde se llama a esta
	// funcion
	var time = cal.date.getTime();
	var fecha1 = fechaInvertidaToCadena(fechaInicio.value);
	var fecha2 = fechaInvertidaToCadena(fechaFin.value);
	var hoy = new Date();
	var fechaActual = hoy.print("%d/%m/%Y");
	var fechaActualString = fechaInvertidaToCadena(fechaActual);
	if (fecha1 < fechaActualString) {
		//La fecha de inicio sera la actual
		fechaInicio.value = hoy.print("%d/%m/%Y");
		time = hoy.getTime();
	}
				
				// si el campo por el que entro en fechaFin
	if (fechaFin == cal.params.inputField) {
					// compruebo que el primer dia no sea mayor o igual que el ultimo
					// dia, y si el primer dia esta vacio.
		if (fecha1 >= fecha2) {
		
			
			//Si la fecha de fin seleccionada es menor o igual a la actual
			if (fecha2 <= fechaActualString) {
			
				//La fecha de inicio sera la actual
				fechaInicio.value = hoy.print("%d/%m/%Y");
				
				//La fecha de fin sera la actual mas un dia
				hoy.setTime(hoy.getTime() + (24 * 60 * 60 * 1000) * 30); // añadimos 30 días
				fechaFin.value = hoy.print("%d/%m/%Y");
			} else {
				// le quito un dia para que siga manteniendo la diferencia.
				fechaInicio.value = new Date(time - Date.DAY).print("%d/%m/%Y");
			}
		}
	} else {
					// compruebo que el primer dia no sea mayor o igual que el ultimo dia.
		if (fecha1 >= fecha2) {
						// le sumo un dia para que siga manteniendo la diferencia.
			fechaFin.value = new Date(time + (Date.DAY * 30)).print("%d/%m/%Y");
		}
	}
}

// funcion que comprueba si la fecha de inicio es menor que la fecha
// de fin, en este caso se permiten que sean iguales para el caso de solicitar 1 dia de asuntos propios
function nomenorAP(cal) {
				// fechaIni almacena la fecha de inicio.
	var fechaInicio = document.getElementById("f_date_ini");
				// fechaFin almacena la fecha de fin 
	var fechaFin = document.getElementById("f_date_fin");
	
	// time es la fecha capturada del calendar desde donde se llama a esta
	// funcion
	var time = cal.date.getTime();
	var fecha1 = fechaInvertidaToCadena(fechaInicio.value);
	var fecha2 = fechaInvertidaToCadena(fechaFin.value);
	var hoy = new Date();
	var fechaActual = hoy.print("%d/%m/%Y");
	var fechaActualString = fechaInvertidaToCadena(fechaActual);
	if (fecha1 < fechaActualString) {
		//La fecha de inicio sera la actual
		fechaInicio.value = hoy.print("%d/%m/%Y");
		time = hoy.getTime();
	}
				
	// si el campo por el que entro en fechaFin
	if (fechaFin == cal.params.inputField) {
					// compruebo que el primer dia no sea mayor o igual que el ultimo
					// dia, y si el primer dia esta vacio.
		if (fecha1 == "") {
			fechaInicio.value = fechaFin.value;
			fecha1 = fecha2;
		}
		if (fecha1 >= fecha2) {
			//Si la fecha de fin seleccionada es menor o igual a la actual
			if (fecha2 <= fechaActualString) {
			
				//La fecha de inicio y la de fin seran la actual
				fechaInicio.value = hoy.print("%d/%m/%Y");
				fechaFin.value = hoy.print("%d/%m/%Y");
			} else {
				// le quito un dia para que siga manteniendo la diferencia.
				//fechaInicio.value = new Date(time).print("%d/%m/%Y");
				fechaInicio.value = fechaFin.value;
			}
		}
	} else {
			// compruebo que el primer dia no sea mayor o igual que el ultimo dia.
		if (fecha1 >= fecha2) {
			fechaFin.value = new Date(time).print("%d/%m/%Y");
		}
	}
}

//funcion que comprueba si la fecha de inicio es menor que la fecha
//de fin, en este caso se permiten que sean iguales
function nomenorFechaInicioFechaFin(cal) {
	// fechaIni almacena la fecha de inicio.
	var fechaInicio = document.getElementById("fechaInicioInformeAlbergue");
	// fechaFin almacena la fecha de fin 
	var fechaFin = document.getElementById("fechaFinInformeAlbergue");
	
	// time es la fecha capturada del calendar desde donde se llama a esta
	// funcion
	var time = cal.date.getTime();
	var fecha1 = fechaInvertidaToCadena(fechaInicio.value);
	var fecha2 = fechaInvertidaToCadena(fechaFin.value);
	
	//si entramos por fecha Inicio
	if (fechaInicio == cal.params.inputField) {
		if(fecha1 != "" && fecha2 != ""){
			if(fecha1 > fecha2){
				alert("La Fecha de Inicio no puede ser mayor que la Fecha de Fin");
				fechaInicio.value ="";
			}
		}
	}else{
	//si entramos por fecha fin
		if(fecha1 != "" && fecha2 != ""){
			if(fecha1 > fecha2){
				alert("La Fecha de Fin no puede ser menor que la Fecha de Inicio");
				fechaFin.value ="";
			}
		}
	}
	
}
//funcion que comprueba si la fecha de inicio es menor que la fecha
//de fin, en este caso se permiten que sean iguales
function nomenorFechaInicioFechaFinAuditoria(cal) {
	// fechaIni almacena la fecha de inicio.
	var fechaInicio = document.getElementById("f_date_ini");
	// fechaFin almacena la fecha de fin 
	var fechaFin = document.getElementById("f_date_fin");
	
	// time es la fecha capturada del calendar desde donde se llama a esta
	// funcion
	var time = cal.date.getTime();
	var fecha1 = fechaInvertidaToCadena(fechaInicio.value);
	var fecha2 = fechaInvertidaToCadena(fechaFin.value);
	
	//si entramos por fecha Inicio
	if (fechaInicio == cal.params.inputField) {
		if(fecha1 != "" && fecha2 != ""){
			if(fecha1 > fecha2){
				alert("La Fecha Desde no puede ser mayor que la Fecha Hasta");
				fechaInicio.value ="";
			}
		}
	}else{
	//si entramos por fecha fin
		if(fecha1 != "" && fecha2 != ""){
			if(fecha1 > fecha2){
				alert("La Fecha Hasta no puede ser menor que la Fecha Desde");
				fechaFin.value ="";
			}
		}
	}
	
}


//funcion que comprueba si la fecha de inicio es menor que la fecha
//de fin, en este caso se permiten que sean iguales
function nomenorFechaInicioFechaFinReservas(cal) {
	// fechaIni almacena la fecha de inicio.
	var fechaInicio = document.getElementById("fechaInicioString");
	// fechaFin almacena la fecha de fin 
	var fechaFin = document.getElementById("fechaFinString");
	
	// time es la fecha capturada del calendar desde donde se llama a esta
	// funcion
	var time = cal.date.getTime();
	var fecha1 = fechaInvertidaToCadena(fechaInicio.value);
	var fecha2 = fechaInvertidaToCadena(fechaFin.value);
	
	//si entramos por fecha Inicio
	if (fechaInicio == cal.params.inputField) {
		if(fecha1 != "" && fecha2 != ""){
			if(fecha1 > fecha2){
				alert("La Fecha de Inicio no puede ser mayor que la Fecha de Fin");
				fechaInicio.value ="";
			}
		}
	}else{
	//si entramos por fecha fin
		if(fecha1 != "" && fecha2 != ""){
			if(fecha1 > fecha2){
				alert("La Fecha de Fin no puede ser menor que la Fecha de Inicio");
				fechaFin.value ="";
			}
		}
	}
	
}

// funcion que comprueba cuando inserto la fecha de baja si es menor que la fecha
// de alta, se permiten que sean iguales 
function nomenorDatosEmpleo(cal) {
				// fechaIni almacena la fecha de inicio.
	var fechaInicio = document.getElementById("fechaInicioExp");
				// fechaFin almacena la fecha de fin 
	var fechaFin = document.getElementById("fechaFinExp");
	
	// time es la fecha capturada del calendar desde donde se llama a esta
	// funcion
	var time = cal.date.getTime();
	var fecha1 = fechaInvertidaToCadena(fechaInicio.value);
	var fecha2 = fechaInvertidaToCadena(fechaFin.value);
	var hoy = new Date();
	var fechaActual = hoy.print("%d/%m/%Y");
	var fechaActualString = fechaInvertidaToCadena(fechaActual);
		
	if (fecha1 > fechaActualString) {
		fechaInicio.value = hoy.print("%d/%m/%Y");
	}
	
	if ((fecha2 != "") && (fecha1 > fecha2)) {
		fechaFin.value = fechaInicio.value;
//		alert("La fecha de alta no puede ser posterior a la fecha de baja");
	}
}
// funcion que comprueba cuando inserto la fecha de baja si es menor que la fecha
// de alta, se permiten que sean iguales 
function nomenorAlbergue(cal) {
				// fechaIni almacena la fecha de inicio.
	var fechaInicio = document.getElementById("f_date_ini");
				// fechaFin almacena la fecha de fin 
	var fechaFin = document.getElementById("f_date_fin");
	
	// time es la fecha capturada del calendar desde donde se llama a esta
	// funcion
	var time = cal.date.getTime();
	var fecha1 = fechaInvertidaToCadena(fechaInicio.value);
	var fecha2 = fechaInvertidaToCadena(fechaFin.value);
	var hoy = new Date();
	var fechaActual = hoy.print("%d/%m/%Y");
	var fechaActualString = fechaInvertidaToCadena(fechaActual);
	if ((fecha2 != "") && (fecha1 > fecha2)) {
		fechaFin.value = fechaInicio.value;
//		alert("La fecha de alta no puede ser posterior a la fecha de baja");
	}
}
// Para Datos Generales
function nomenorHoy(cal) {
   
   //Obtenemos la fecha que introducimos
	var fecha = document.getElementById('fechaNacimiento');
	var fechaString = fechaInvertidaToCadena(fecha.value);
		
	//Obtenemos la fecha actual
	var hoy = new Date();
	var fechaActual = hoy.print("%d/%m/%Y");
	var fechaActualString = fechaInvertidaToCadena(fechaActual);
	if (fechaString > fechaActualString) {
		fecha.value = hoy.print("%d/%m/%Y");
		alert("La fecha no puede ser posterior a la fecha de hoy");
	}
}

//Para Datos Generales
function nomenorHoyRegistro(cal) {
   
   //Obtenemos la fecha que introducimos
	var fecha = document.getElementById('fechaRegistroString');
	var fechaString = fechaInvertidaToCadena(fecha.value);
		
	//Obtenemos la fecha actual
	var hoy = new Date();
	var fechaActual = hoy.print("%d/%m/%Y");
	var fechaActualString = fechaInvertidaToCadena(fechaActual);
	if (fechaString > fechaActualString) {
		fecha.value = hoy.print("%d/%m/%Y");
		alert("La fecha no puede ser posterior a la fecha de hoy");
	}
}

function mayorIgualHoyCita(cal) {
   
   //Obtenemos la fecha que introducimos
   
	var fecha = document.getElementById('strFechaCita');
	var fechaString = fechaInvertidaToCadena(fecha.value);
		
	//Obtenemos la fecha actual
	var hoy = new Date();
	var fechaActual = hoy.print("%d/%m/%Y");
	var fechaActualString = fechaInvertidaToCadena(fechaActual);
	if (fechaString < fechaActualString) {
		fecha.value = hoy.print("%d/%m/%Y");
		alert("La fecha de la cita no puede ser inferior fecha de hoy");
	}
}

function calendarFechaActual(cal) {

	//Obtenemos la fecha que introducimos
	var fecha = document.getElementById("f_date_c");
	var fechaString = fechaInvertidaToCadena(fecha.value);
		
	//Obtenemos la fecha actual
	var hoy = new Date();
	var fechaActual = hoy.print("%d/%m/%Y");
	var fechaActualString = fechaInvertidaToCadena(fechaActual);
	if (fechaString < fechaActualString) {
		fecha.value = hoy.print("%d/%m/%Y");
	}
}
function validarExtensionFichero(idFile, extensionesPermitidas) {
	var result = false;
	var file = document.getElementById(idFile);
	if (file.value != "") {
		var valorFile = file.value;
		var extension = (valorFile.substring(valorFile.lastIndexOf("."))).toLowerCase();
		var cont = 0;
		while (cont < extensionesPermitidas.length && result != true) {
			var extensionPermitida = "." + extensionesPermitidas[cont];
			if (extension == extensionPermitida) {
				result = true;
			}
			cont++;
		}
	} else {
		result = true;
	}
	if (result == false) {
		alert("Error, la extensi\xf3n del fichero adjunto debe ser .doc,.pdf \xf3 .xls");
	}
	return result;
}
function validaDateFields(hhinicio, hhfin, mminicio, mmfin, hhInicioEspacio, hhFinEspacio) {
  
   // Compruebo que no sea el cancelar
	if (bCancel) {
		return true;
	}
	var finicio = document.getElementById("f_date_ini");
	var ffin = document.getElementById("f_date_fin");
	var hhini = document.getElementById(hhinicio);
	var hhfin = document.getElementById(hhfin);
	var mmini = document.getElementById(mminicio);
	var mmfin = document.getElementById(mmfin);
	if (hhini.value < hhInicioEspacio) {
		alert(smsErrorFechaInicioEspacio);
		return false;
	}
	if (hhfin.value > hhFinEspacio) {
		alert(smsErrorFechaFinEspacio);
		return false;
	}
	if (mmini.value == "") {
		mmini.value = "00";
	}
	if (mmfin.value == "") {
		mmfin.value = "00";
	}
	var fechai = new Date(finicio.value + " " + hhini.value + ":" + mmini.value);
	var fechaf = new Date(ffin.value + " " + hhfin.value + ":" + mmfin.value);
	if (fechai > fechaf) {
		alert(smsErrorFecha);
		return false;
	}
	return true;
}
function checkCombo(numCombo) {
	var combo = document.getElementById("combo" + numCombo);
	if (combo != null) {
		var check = document.getElementById("checkbox" + numCombo);
		if (check.checked == true) {
			combo.disabled = false;
		} else {
			combo.disabled = true;
		}
	}
}



function RedireccionamientoFotoInmigrantes(campoAction) {
	var campoEntero = "./" + campoAction;
	var formularioParametros = document.getElementById("formulario");
	formularioParametros.action = campoEntero;
	formularioParametros.submit();
}

function RedireccionamientoFoto(campoAction, pestania){
		
		document.getElementById('pestaniaActiva').value = pestania;
		var campoEntero = "./" + campoAction + "ExpedienteFront.do";
		var formularioParametros = document.getElementById("formulario");
		formularioParametros.action = campoEntero+'?mostrarFoto';
		formularioParametros.submit();
}
	
function validatePlazas() {
	var numPlazas = document.getElementById("numeroPlazas");
	var plazasDisp = document.getElementById("plazasDisponibles");
	valor1 = parseInt(numPlazas.value);
	valor2 = parseInt(plazasDisp.value);
	if (bCancel) {
		return true;
	}
	if (valor2 > valor1) {
		alert("El n\xfamero de plazas disponibles no puede ser mayor al n\xfamero de plazas");
		return false;
	}
}

//función que muestra un campo oculto para insertar texto cuando seleccionemos Otros como opción de Tipo de Consulta
function mostrarDatosOtros(campo) {
	var obj = document.getElementById(campo);
	var tamanio = obj.options.length;
	var opcionSeleccionada=obj.options[obj.selectedIndex].text;

	if(opcionSeleccionada== 'Especificar Otros'){
		document.getElementById("otrosEspecificarCampo").style.display = "";
		document.getElementById("habilitacionCampoOtros").value = "true";
	} else {
		document.getElementById("otrosEspecificarCampo").style.display = "none";
		document.getElementById("habilitacionCampoOtros").value = "false";
		document.getElementById("otrosEspecificarCampo").value = "";
	}
}

 // Validar NIF
function isValidNif(dni) {
	if (dni == null) {
		return false;
	}
	if (dni.length != 9) {
		return false;
	}
	var numero = dni.substr(0, dni.length - 1);
	var let = (dni.substr(dni.length - 1, 1)).toUpperCase();
	numero = numero % 23;
	var letra = "TRWAGMYFPDXBNJZSQVHLCKET";
	letra = letra.substring(numero, numero + 1);
	if (letra != let) {
		return false;
	}
	return true;
}
// Validar NIE
function isValidNie(nie) {
	
	var temp = nie.toUpperCase();
	var cadenadni = "TRWAGMYFPDXBNJZSQVHLCKE";
	//comprobacion de NIEs
	//tipo XYZ
	if (/^[XYZ]{1}/.test(temp)) {
		pos = str_replace(["X", "Y", "Z"], ["0", "1", "2"], temp).substring(0, 8) % 23;
		if (temp.charAt(8) == cadenadni.substring(pos, pos + 1)) {
			return true;
		}
	}
	
	if (/^[0-9]{8}[A-Z]{1}$/.test(temp)) {
		var posicion = temp.substring(8, 0) % 23;
		var letra = cadenadni.charAt(posicion);
		var letradni = temp.charAt(8);
		if (letra == letradni) {
			return true;
		}
	}
	return false;
}

function str_replace(search, replace, subject) {
	var f = search, r = replace, s = subject;
	var ra = r instanceof Array, sa = s instanceof Array, f = [].concat(f), r = [].concat(r), i = (s = [].concat(s)).length;
	while (j = 0, i--) {
		if (s[i]) {
			while (s[i] = s[i].split(f[j]).join(ra ? r[j] || "" : r[0]), ++j in f) {
			}
		}
	}
	return sa ? s : s[0];
}

function validarNieNifDni() {
	
    // Compruebo que no sea el cancelar
	if (bCancel) {
		return true;
	}
	
	//recojo los datos del nie y el pasaporte
	var nieNifDni = document.getElementById("nie");
	var pasaporte = document.getElementById("pasaporte");
	
	//comprobamos que alguno de los dos campos esté relleno
	//nie
	if ((nieNifDni == null) && (pasaporte == null)) {
		alert(smsNieNifDniRequerido);
		return false;
	}
	//pasaporte
	if ((nieNifDni != null && nieNifDni.value == "") && (pasaporte != null && pasaporte.value == "")) {
		alert(smsNieNifDniRequerido);
		return false;
	}
	//si el campo nie está relleno, entonces vamos comprobando que documento es
	if(nieNifDni != null && nieNifDni.value != ""){
		if(nieNifDni.value.length == 8){
			//si la longitud de la cadena es = 8 y son numeros quiere decir que se trata de un DNI por lo que deberemos de permitir la validacion
			if (/^[0-9]{8}$/.test(nieNifDni.value)) {
				return true;
			}else{
				alert(smsNieNifDni);
				return false;
			}
			
		}else if(nieNifDni.value.length == 9){
			//se trata de un NIE o un NIF, comprobamos cuál es
			if (/^[XYZ]{1}[0-9]{7}[A-Z]{1}$/.test(nieNifDni.value.toUpperCase())) {
				//es un nie, ahora comprobamos que sea correcto, es decir que la letra corresponda
				if(comprobarNIE(nieNifDni.value)){
					return true;
				}else{
					alert(smsNieNifDni);
					return false;
				}
			}else if(/^[0-9]{8}[A-Z]{1}$/.test(nieNifDni.value.toUpperCase())){
				//es un nif, ahora comprobamos que sea correcto, es decir que la letra corresponda
				if(comprobarNIF(nieNifDni.value)){
					return true;
				}else{
					alert(smsNieNifDni);
					return false;
				}
			}else{
				alert(smsNieNifDni);
				return false;
			}
			
			
		}else{
			alert(smsNieNifDni); 
			return false;
		}
	}
	
}

// Validar NIF
function comprobarNIF(nif) {
	
	var numero = nif.substr(0, nif.length - 1);
	var let = (nif.substr(nif.length - 1, 1)).toUpperCase();
	numero = numero % 23;
	var letra = "TRWAGMYFPDXBNJZSQVHLCKET";
	letra = letra.substring(numero, numero + 1);
	if (letra != let) {
		return false;
	}
	return true;
}
// Validar NIE
function comprobarNIE(nie) {
	
	var temp = nie.toUpperCase();
	var cadenadni = "TRWAGMYFPDXBNJZSQVHLCKE";
	pos = str_replace(["X", "Y", "Z"], ["0", "1", "2"], temp).substring(0, 8) % 23;
	if (temp.charAt(8) == cadenadni.substring(pos, pos + 1)) {
		return true;
	}
	return false;
}






function validateNIE() {
	      // Compruebo que no sea el cancelar
	if (bCancel) {
		return true;
	}
	var nie = document.getElementById("nie");
	var pasaporte = document.getElementById("pasaporte");
	if ((nie == null) && (pasaporte == null)) {
		alert(smsRequerido);
		return false;
	}
	if ((nie != null && nie.value == "") && (pasaporte != null && pasaporte.value == "")) {
		alert(smsRequerido);
		return false;
	}
	//añado '&& nie.value != ""' para el caso en que no meta nie y si pasaporte
	if (nie != null && (!isValidNie(nie.value) && nie.value != ""))  {
		alert(smsNIE);
		return false;
	}
	return true;
}

//Validar Telefono o Movil
function validateTelefono() {
    // Compruebo que no sea el cancelar
if (bCancel) {
	return true;
}
var telefono = document.getElementById("telefono");
var movil = document.getElementById("movil");
if ((telefono == null) && (movil == null)) {
	alert(smsTelefono);
	return false;
}
if ((movil != null && movil.value == "") && (telefono != null && telefono.value == "")) {
	alert(smsTelefono);
	return false;
}
return true;
}

// Validar CIF
function isValidCif(abc) {
	if (bCancel) {
		return true;
	}
	if (abc == null) {
	    alert(smsCIF);
		return false;
	}
	var par = 0;
	var non = 0;
	var letras = "ABCDEFGHKLMNPQS";
	var let = abc.charAt(0);
	if (abc.length != 9) {
		alert(smsCIF);
		return false;
	}
	if (letras.indexOf(let.toUpperCase()) == -1) {
		alert(smsCIF);
		return false;
	}
	for (zz = 2; zz < 8; zz += 2) {
		par = par + parseInt(abc.charAt(zz));
	}
	for (zz = 1; zz < 9; zz += 2) {
		nn = 2 * parseInt(abc.charAt(zz));
		if (nn > 9) {
			nn = 1 + (nn - 10);
		}
		non = non + nn;
	}
	var parcial = par + non;
	var control = (10 - (parcial % 10));
	if (control == 10) {
		control = 0;
	}
	if (control != abc.charAt(8)) {
	    alert(smsCIF);
		return false;
	}
	return true;
}

// Validar CIF
function nifValido(idElemento) {
	var nif=document.getElementById(idElemento).value;
	if (bCancel) {
		return true;
	}
	if (nif == null) {
	    alert(smsCIF);
		return false;
	}
	var par = 0;
	var non = 0;
	var letras = "ABCDEFGHKLMNPQS";
	var let = nif.charAt(0);
	if (nif.length != 9) {
		alert(smsCIF);
		return false;
	}
	if (letras.indexOf(let.toUpperCase()) == -1) {
		alert(smsCIF);
		return false;
	}
	for (zz = 2; zz < 8; zz += 2) {
		par = par + parseInt(nif.charAt(zz));
	}
	for (zz = 1; zz < 9; zz += 2) {
		nn = 2 * parseInt(nif.charAt(zz));
		if (nn > 9) {
			nn = 1 + (nn - 10);
		}
		non = non + nn;
	}
	var parcial = par + non;
	var control = (10 - (parcial % 10));
	if (control == 10) {
		control = 0;
	}
	if (control != nif.charAt(8)) {
	    alert(smsCIF);
		return false;
	}
	return true;
}

function carnetAlberguista() {
		var formulario = document.getElementById("formParamExtreme");
		formulario.action = './CrearCarnetAlberguista.do';
		formulario.submit();
}

function mostrarFoto() {
		var formulario = document.getElementById("formParamExtreme");
		formulario.action = './MuestraFotoInmigrante.do';
		formulario.submit();
}

function despliegaPermisosHijo(check){

	var li=document.getElementById(check);
	var padresCheck=li.childNodes;
	
	var checkBoxPadre;

	for (var i = 0; i < padresCheck.length; i++){
		if(padresCheck[i].tagName=='INPUT'){
			checkBoxPadre=padresCheck[i];
		}
		if(padresCheck[i].tagName=='UL'){	
			var checkPadre=padresCheck[i];
			var hijos=checkPadre.childNodes;
			for (var e = 0; e < hijos.length; e++){
				
				if(hijos[e].tagName=='LI'){
					
					var listaHijos=hijos[e].childNodes;
					for (var a = 0; a < listaHijos.length; a++){
						if(listaHijos[a].tagName=='INPUT'){
							var checkHijo=listaHijos[a];
							if(checkBoxPadre.checked){
								checkHijo.checked = true;
							}else{
								checkHijo.checked = false;
							}			
						}
					}		
				}
			}	
		}
	}
}


//Para borrar la cookie que hace persistente el estado del menu lateral
function delCookie() { 
	createCookie('treemenu1',"",-1); 
}

function delCookie2() { 
	createCookie('treemenu2',"",-1); 
}


function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function ocultarMostrarElementos(idElemento){
	var elemento=document.getElementById(idElemento);
	if(elemento.style.display=='none'){
		elemento.style.display='block';
	}else{
		elemento.style.display='none';
	}
}

// Función para validar el fck editor
// @author Borja Vega Lopez
// Parametros : idCampo,nombreCampo,minCaracteres,masCaracteres
// Descripcion : idCampo es el id que tenemos asignado al fckeditor en nuestra jsp
// nombreCampo es el nombre del campo en si , solo es para el mensaje alert que mostramos por pantalla
// minCaracteres es el minimo de caracteres a validar
// maxCaracteres es el maximo de caracteres a validar
function validarFckEditor(idCampo, nombreCampo, minCaracteres, maxCaracteres) {
 if (bCancel!=true) {
	 fckEditor1val = FCKeditorAPI.__Instances[idCampo].GetHTML();
	 while (fckEditor1val.search(/<p>&nbsp;<\/p>/) != -1) {
	  fckEditor1val = fckEditor1val.replace(/<p>&nbsp;<\/p>/, "");
	 }
	 while (fckEditor1val.search(/&nbsp;/) != -1) {
	  fckEditor1val = fckEditor1val.replace(/&nbsp;/, "");
	 }
	 while (fckEditor1val.search(/<p>/) != -1) {
	  fckEditor1val = fckEditor1val.replace(/<p>/, "");
	 }
	 while (fckEditor1val.search(/<\/p>/) != -1) {
	  fckEditor1val = fckEditor1val.replace(/<\/p>/, "");
	 }
	 num_caracteres = fckEditor1val.length;
	 if (fckEditor1val == "") {
	  alert("El campo Introduzca el Contenido debe rellenarse");
	  return false;
	 } else {
	  if (num_caracteres < minCaracteres) {
	   alert("El campo Introduzca el Contenido debe tener como m\xednimo " + minCaracteres + " caracteres");
	   return false;
	  } else {
	   if (num_caracteres > maxCaracteres) {
	    alert("El campo Introduzca el Contenido debe tener como m\xe1ximo " + maxCaracteres + " caracteres");
	    return false;
	   } else {
	    return true;
	   }
	  }
	 }
  }
 

}
