

	/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// CONFIGURACIÓN
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	var js_output = "alert";
	var js_msg_url = "";
	var js_msg_path = null;
	
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// ESTABLECE: SALIDA DE TEXTO MEDIANTE LA URL DE MENSAJE O MEDIANTE UNA ALERTA JS
	//
	// output				Método de salida							S				alert | msg (Alerta JS ó mensaje por URL)
	// msg_path			Objeto Window, Frame, IFrame			O
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	function setOutput (output, msg_path) {
		if (output == "msg") {
			js_output = output;
			js_msg_path = msg_path;
		}
	}
	
	
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// ESTABLECE: COLOR #FF0000 (CSS) EN EL ELEMENTO INDICADO Y LE APLICA EL FOCO
	//
	// element			Objeto InputText							O
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	var js_oColor ="";
	var js_oBgColor = "";
	var js_firstMark = true;
	function mark (element) {
		if (js_firstMark) {
			js_oColor = element.style.color;
			js_oBgColor = element.style.backgroundColor;
			js_firstMark= false;
		}
		element.style.color = "#ffffff";
		element.style.backgroundColor = "#ff0000";
		element.focus ();
	}
	
	
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// REESTABLECE: COLOR ORIGINAL (CSS) DEL ELEMENTO INDICADO Y LE RETIRA EL FOCO
	//
	// element			Objeto InputText							O
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	function unmark (element) {
		element.style.color = js_oColor;
		element.style.backgroundColor = js_oBgColor;
		element.blur ();
	}
	
	
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// MUESTRA: MENSAJE DE RESPUESTA A TRAVÉS DEL CANAL CONFIGURADO
	//
	// sentence			Respuesta a mostrar						S
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	function answer (sentence) {
		if (js_output == "msg") {
			js_msg_path.location = js_msg_url + sentence;
		} else {
			if (sentence != "") alert (sentence);
		}
	}
	
	
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// IMPIDE: CAMPOS NECESARIOS VACÍOS
	//
	// element			Objeto InputText							O
	// description		Descripción del campo						S
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	function checkBlank (element, description) {
		if (element.value == "") {
			mark (element);
			answer (description + ": Campo necesario");
			return (true);
		} else {
			unmark (element);
			answer ("");
			return (false);
		}
	}
	
	
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// IMPIDE: CAMPOS NUMÉRICOS CON VALORES INCORRECTOS O QUE NO CUMPLAN LOS LÍMITES ESTABLECIDOS
	//
	// element			Objeto InputText							O
	// description		Descripción del campo						S
	// count_int			Cantidad de enteros						i
	// count_dec			Cantidad de decimales					i
	// mini					Límite mínimo								i, d				Opcional
	// maxi				Límite máximo								i, d				Opcional
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	function checkNumber (element, description, count_int, count_dec, mini, maxi) {
		
		var number = "" + element.value;
		var msg = "";
		var minimum = Number.NEGATIVE_INFINITY;
		var maximum = Number.POSITIVE_INFINITY;
		var error = false;
		
		if ((mini != "inf") && (typeof (mini) != "undefined")) minimum = mini;
		if ((maxi != "inf") && (typeof (maxi) != "undefined")) maximum = maxi;
	
		if (isNaN (number)) {																																				// Si no es numérico
			error = true;
		} else {
		
			// SI HA DE SER ENTERO
			if (count_dec == 0) {	
				if (number.indexOf (".") != -1) error = true;																											// Si posee parte decimal
				if (number.length > count_int) error = true;																												// Si el número supera el límite de cifras
				
			// SI HA DE SER DECIMAL
			} else {
				if (number.indexOf (".") == 0) error = true;																												// Si no existe parte entera
				if (number.indexOf ("-.") == 0) error = true;																											// Si no existe parte entera negativa
				if (number.indexOf (".") != -1) {
					if (number.substring (0, number.indexOf (".")).length > count_int) error = true;															// Si la parte entera supera el límite de cifras
				} else {
					if (number.length > count_int) error = true;																											// Si la parte entera supera el límite de cifras
				}
				if ((number.indexOf (".") != -1) && (number.substring (number.indexOf (".") + 1).length > count_dec)) error = true;				// Si la parte decimal supera el límite de cifras
			}
	
			if (parseFloat (number) < minimum) error = true;																											// Si el número se encuentra por debajo del mínimo
			if (parseFloat (number) > maximum) error = true;																										// Si el número se encuentra por debajo del máximo
		
		}
	
	
		if (error) {
			msg = description + ": Campo numérico"
			if (minimum >= 0) msg += " positivo";
			if (maximum <= 0) msg += " negativo";
			msg += " de " + count_int + " entero(s)";
			if (count_dec > 0) msg += " y " + count_dec + " decimal(es)";
			msg += " máximo";
			if ((minimum != Number.NEGATIVE_INFINITY) && (minimum != 0)) msg += ", mayor o igual que " + (minimum + "").replace (".", ",");
			if ((maximum != Number.POSITIVE_INFINITY) && (maximum != 0)) msg += ", menor o igual que " + (maximum + "").replace (".", ",");
			
			mark (element);
			answer (msg);
			return (true);
			
		} else {
			unmark (element);
			answer ("");
			return (false);
		}
	
	}
	
	
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// IMPIDE: CAMPOS DE IDENTIFICACIÓN CON VALORES SENSIBLES A ERROR
	//
	// element			Objeto InputText							O
	// description		Descripción del campo						S
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	function checkIdWord (element, description) {
		
		var word = element.value;
		var chars = new Array ("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "-", "_");
		var passed = 0;
		var error = false;

		for (var i = 0; i < word.length; i++) {
			for (var j = 0; j < chars.length; j++) {
				if (word.charAt (i) == chars [j] || word.charAt (i) == chars [j].toUpperCase () ) {
					passed++;
					break;
				}
			}
		}
		
		if (passed != word.length) {
			mark (element);
			answer (description + ": Sólo puede contener caracteres alfanuméricos (sin tildes, diéresis, apóstrofes o cedillas) y guiones medios y bajos");
			return (true);
		} else {
			unmark (element);
			answer ("");
			return (false);
		}

	}
	
	
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// IMPIDE: DIRECCIONES DE EMAIL CON CARACTERES O FORMATO INCORRECTO
	//
	// element			Objeto InputText							O
	// description		Descripción del campo						S
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	function checkEmail (element, description) {
		
		var email = element.value;
		var chars = new Array ("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", ".", "-", "_", "@");
		
		// EVITA VERIFICAR CAMPOS VACÍOS
		/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		if (email.length == 0) {
			unmark (element);
			answer ("");
			return (false);
		}
		
		
		// 1 - CARACTERES INVÁLIDOS
		/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		
		var passed = 0;
		for (var i = 0; i < email.length; i++) {
			for (var j = 0; j < chars.length; j++) {
				if (email.charAt (i) == chars [j] || email.charAt (i) == chars [j].toUpperCase () ) {
					passed++;
					break;
				}
			}
		}
		
		if (passed != email.length) {
			mark (element);
			answer (description + ": Sólo puede contener caracteres alfanuméricos (sin tildes, diéresis, apóstrofes o cedillas) y guiones medios y bajos");
			return (true);
		}
		
		// 2 - NÚMERO DE ARROBAS
		/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		if (email.indexOf ("@") == -1 || email.indexOf ("@") != email.lastIndexOf ("@")) {
			mark (element);
			answer (description + ": Debe de contener una arroba");
			return (true);
		}
		
		// 3 - ARROBA O PUNTO EN COMIENZO O FINAL
		/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		if (email.charAt (0) == "." || email.charAt (0) == "@" || email.charAt (email.length - 1) == "." || email.charAt (email.length - 1) == "@") {
			mark (element);
			answer (description + ": No ha de contener ni arrobas ni puntos al comienzo o al final");
			return (true);
		}

		// 4 - EXISTENCIA DE ARROBA ADYACENTE A PUNTO
		/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		if (email.charAt (email.indexOf ("@") - 1) == "." || email.charAt (email.indexOf ("@") + 1) == ".") {
			mark (element);
			answer (description + ": No ha de contener arrobas adyacentes a puntos");
			return (true);
		}
		
		// CORRECTO
		/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		unmark (element);
		answer ("");
		return (false);

	}
	
	
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// IMPIDE: TIEMPOS CON CARACTERES O FORMATO INCORRECTO
	//
	// element			Objeto InputText						O
	// description		Descripción del campo					S
	// separator			Separador de cifras					S		no | any | [separador] (Ninguno, cualquiera, sólo el indicado)
	// _12hour			Sistema PM/AM de 12 horas			b		true | false
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	function checkTime (element, description, separator, _12hour) {

		if (_12hour != true) _12hour = false;
				
		var time = element.value;
		if (separator != "no") time = time.substring (0, 2) + "" + time.substring (3, 5) + "" + time.substring (6, 8);	
		
		// EVITA VERIFICAR CAMPOS VACÍOS
		/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		if (time.length == 0) {
			unmark (element);
			answer ("");
			return (false);
		}
		
		// 1 - FORMATO INCORRECTO / CARACTERES INVÁLIDOS
		/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		if (time.length != 6 || isNaN (time)) {
			mark (element);
			if (separator == "no") {
				answer (description + ": Sólo puede contener caracteres numéricos, con el formato \"hhmmss\" (sin separadores)");
			} else if (separator == "any") {
				answer (description + ": Sólo puede contener caracteres numéricos, con el formato \"hh[]mm[]ss\" siendo \"[]\" el separador deseado");
			} else {
				answer (description + ": Sólo puede contener caracteres numéricos, con el formato \"hh" + separator + "mm" + separator + "ss\"");
			}
			return (true);
		}
		
		// 2 - SEPARADOR INCORRECTO ( SI SE HA INDICADO ALGUNO)
		/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		if ( (separator != "no" && separator != "any") && (element.value.charAt (2) != separator || element.value.charAt (5) != separator) ) {
			mark (element);
			answer (description + ": Sólo puede contener caracteres numéricos, con el formato \"hh" + separator + "mm" + separator + "ss\"");
			return (true);
		}

		// 3 - RANGO DE TIEMPO INCORRECTO
		/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		if (_12hour) {
			if (parseInt (time.substring (0, 2), 10) < 1 || parseInt (time.substring (0, 2), 10) > 12) {
				mark (element);
				answer (description + ": Sólo puede contener horas dentro del rango 01 hasta 12");
				return (true);
			}
		} else {
			if (parseInt (time.substring (0, 2), 10) < 0 || parseInt (time.substring (0, 2), 10) > 23) {
				mark (element);
				answer (description + ": Sólo puede contener horas dentro del rango 00 hasta 23");
				return (true);
			}
		}

		if (parseInt (time.substring (2, 4), 10) < 0 || parseInt (time.substring (2, 4), 10) > 59) {
			mark (element);
			answer (description + ": Sólo puede contener minutos dentro del rango 00 hasta 59");
			return (true);
		}
		
		if (parseInt (time.substring (4, 6), 10) < 0 || parseInt (time.substring (4, 6), 10) > 59) {
			mark (element);
			answer (description + ": Sólo puede contener segundos dentro del rango 00 hasta 59");
			return (true);
		}

		
		// CORRECTO
		/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		unmark (element);
		answer ("");
		return (false);

	}
	
	
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// IMPIDE: FECHAS CON CARACTERES O FORMATO INCORRECTO
	//
	// element			Objeto InputText						O
	// description		Descripción del campo					S
	// separator			Separador de cifras					S		no | any | [separador] (Ninguno, cualquiera, sólo el indicado)
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	function checkDate (element, description, separator) {
				
		var date = element.value;
		if (separator != "no") date = date.substring (0, 4) + "" + date.substring (5, 7) + "" + date.substring (8, 10);

		// EVITA VERIFICAR CAMPOS VACÍOS
		/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		if (date.length == 0) {
			unmark (element);
			answer ("");
			return (false);
		}
		
		// 1 - FORMATO INCORRECTO / CARACTERES INVÁLIDOS
		/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		if (date.length != 8 || isNaN (date)) {
			mark (element);
			if (separator == "no") {
				answer (description + ": Sólo puede contener caracteres numéricos, con el formato \"aaaammdd\" (sin separadores)");
			} else if (separator == "any") {
				answer (description + ": Sólo puede contener caracteres numéricos, con el formato \"aaaa[]mm[]dd\" siendo \"[]\" el separador deseado");
			} else {
				answer (description + ": Sólo puede contener caracteres numéricos, con el formato \"aaaa" + separator + "mm" + separator + "dd\"");
			}
			return (true);
		}
		
		// 2 - SEPARADOR INCORRECTO ( SI SE HA INDICADO ALGUNO)
		/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		if ( (separator != "no" && separator != "any") && (element.value.charAt (4) != separator || element.value.charAt (7) != separator) ) {
			mark (element);
			answer (description + ": Sólo puede contener caracteres numéricos, con el formato \"aaaa" + separator + "mm" + separator + "dd\"");
			return (true);
		}

		// 3 - RANGO DE TIEMPO INCORRECTO
		/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		switch (date.substring (4, 6)) {
			case "01":
			case "03":
			case "05":
			case "07":
			case "08":
			case "10":
			case "12":
				if (date.substring (6, 8) > 31) {
					mark (element);
					answer (description + ": Ese mes sólo puede contener días dentro del rango 01 hasta 31");
					return (true);
				}
			break;
			
			case "04":
			case "06":
			case "09":
			case "11":
				if (date.substring (6, 8) > 30) {
					mark (element);
					answer (description + ": Ese mes sólo puede contener días dentro del rango 01 hasta 30");
					return (true);
				}
			break;
			
			case "02":
				if ((date.substring (0, 4) % 4 == 0) && (date.substring (0, 4) % 100 != 0)){
					if (date.substring (6, 8) > 29) {
						mark (element);
						answer (description + ": Ese mes sólo puede contener días dentro del rango 01 hasta 29");
						return (true);
					}
					return "Fecha: A la fecha indicada no le corresponden más de 29 días."
				} else {
					if (date.substring (0, 4) % 400 == 0) {
						if (date.substring (6, 8) > 29) {
							mark (element);
							answer (description + ": Ese mes sólo puede contener días dentro del rango 01 hasta 29");
							return (true);
						}
					} else {
						if (date.substring (6, 8) > 28) {
							mark (element);
							answer (description + ": Ese mes sólo puede contener días dentro del rango 01 hasta 28");
							return (true);
						}
					}
				}
			break;
			
			default:
				mark (element);
				answer (description + ": Sólo puede contener meses dentro del rango 01 hasta 12");
				return (true);
			break;
		}

		
		// CORRECTO
		/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		unmark (element);
		answer ("");
		return (false);

	}
	
	
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// COMPARA: VALORES NUMÉRICOS (ENTEROS, DECIMALES, HORAS HHMMSS, FECHAS AAAAMMDD)
	//
	// element1			Objeto InputText 1				O
	// description1		Descripción del campo	 1			S
	// element2			Objeto InputText 2				O
	// description2		Descripción del campo	 2			S
	// type				Tipo de dato							S		Sólo si son tiempos/fechas con separador: h | D (Tiempo, fecha)
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	function compareNumerical (element1, description1, element2, description2, type) {		
		
		var num1 = "" + element1.value;
		var num2 = "" + element2.value;
		
		if (type == "h") {
			num1 = num1.substring (0, 2) + "" + num1.substring (3, 5) + "" + num1.substring (6, 8);
			num2 = num2.substring (0, 2) + "" + num2.substring (3, 5) + "" + num2.substring (6, 8);
		} else if (type == "D") {
			num1 = num1.substring (0, 4) + "" + num1.substring (5, 7) + "" + num1.substring (8, 10);
			num2 = num2.substring (0, 4) + "" + num2.substring (5, 7) + "" + num2.substring (8, 10);
		}

		// EVITA VERIFICAR CAMPOS VACÍOS
		/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		if (num1.length == 0 || num2.length == 0) {
			unmark (element);
			answer ("");
			return (false);
		}
		
		// 1 - COMPARACIÓN
		/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		if (parseFloat (num1, 10) >= parseFloat (num2, 10)) {
			mark (element2);
			answer (description2 + ": Ha de ser mayor que el valor del campo \"" + description1 + "\"");
			return (true);
		}
		
		// CORRECTO
		/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		unmark (element2);
		answer ("");
		return (false);
	
	}
	
	
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// CARGA: VALOR POR DEFECTO DE UN CAMPO
	//
	// element			Objeto InputText					O
	// description		Descripción del campo				S
	// type				Tipo de datos especial			S		i | d | h | H | D (Entero, decimal, tiempo 24h, tiempo 12h, fecha)
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	function fillDefault (element, type, separator) {
		
		if (element.value.length == 0) {
			if (type == "i") {
				element.value = "0";
			} else if (type == "d") {
				element.value = "0.0";
			} else if (type == "h") {
				element.value = "00" + separator + "00" + separator + "00";
			} else if (type == "H") {
				element.value = "12" + separator + "00" + separator + "00";
			} else if (type == "D") {
				element.value = "2005" + separator + "01" + separator + "01";
			}
		}
		
	}
	
	
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// COMPARA: EL CÓDIGO DEL EVENTO DE TECLA PULSADA CON EL CÓDIGO NUMÉRICO DESEADO
	//
	// code				Código numérico que activa la función			i
	// e				Objeto Event										O			En IE puede ser null
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	function checkKey (code, e) {
		// Netscape y otros
		if (! document.all) {
			if (e.which == code) return (true);
		// Internet Explorer
		} else {
			if (event.keyCode == code) return (true);
		}
		return (false);
		
	}