function validarCampo(campo, msgError, longitudMinima, longitudMaxima, funcion) {
	if (!longitudMinima  && longitudMinima != 0) {
		longitudMinima = 1
	}
	if (!longitudMaxima ) {
		longitudMaxima = Number.MAX_VALUE
	}
	var value = trim(campo.value)
	if (value.length < longitudMinima || value.length > longitudMaxima ||
		(funcion ? !eval("funcion(campo)") : false)) {
		appendErrorMessage(msgError)
		if (_campoError == null) {
			_campoError = campo;
		}
		return false;
	}
	return true;
}

function comprobarClave(campo1,campo2,msgError, funcion){
	var clave1 = trim(campo1.value);
	var clave2 = trim(campo2.value);
	if (!(clave1==clave2) || (funcion ? !eval("funcion(campo1)") : false)) {
		appendErrorMessage(msgError)
		if (_campoError == null) {
			_campoError = campo1;
		}
		return false;		
	}
	return true;
}

function isUrl(s, msgError){
	var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
	if(s.value!=""){
		if(regexp.test(s.value)){
			return true;
		}else{
			appendErrorMessage(msgError);
			if (_campoError == null){
				_campoError = s;
			}
			return false;
		}
	}else{
		return true;
	}
}




function validarLista(lista, msgError, indiceInicial, funcion) {
	if (!indiceInicial && indiceInicial != 0) {
		indiceInicial = 1;
	}
	if (lista.selectedIndex < indiceInicial ||
		(funcion ? !eval("funcion(lista)") : false)) {
		appendErrorMessage(msgError)
		if (_campoError == null) {
			_campoError = lista;
		}
		return false;
	}
	return true;
}

function validarSeleccion(campo, msgError, funcion) {
	if (!isChecked(campo) ||
			(funcion ? !eval("funcion(campo)") : false)) {
		appendErrorMessage(msgError)
		if (_campoError == null) {
			if (campo.length) {
				_campoError = campo[0]
			} else {
				_campoError = campo;
			}
		}
		return false;
	}
	return true;
}

function validarCampoOpcional(campo, msgError, longitudMinima, longitudMaxima, funcion) {
	if (trim(campo.value).length > 0) {
		return validarCampo(campo, msgError, longitudMinima, longitudMaxima, funcion)
	}
}

function validarFecha(dia, mes, ano, msgError, funcion) {
	if (!isIntRange(parseInt(dia.value, 10) + "", 1, 31)) {
        appendErrorMessage(msgError)
        if (_campoError == null) {
            _campoError = dia;
        }
        return false;
    }
	if (mes.type != "text") {
		if (mes.selectedIndex < 1) {
			appendErrorMessage(msgError)
			if (_campoError == null) {
				_campoError = mes;
			}
			return false;
		}
	} else {
        if (!isIntRange(parseInt(mes.value, 10) + "", 1, 12)) {
            appendErrorMessage(msgError)
            if (_campoError == null) {
                _campoError = mes;
            }
            return false;
        }
    }
	if (!isInt(ano.value)) {
        appendErrorMessage(msgError)
        if (_campoError == null) {
            _campoError = ano;
        }
        return false;
	}
	var valorMes = (mes.type == "text")
			? mes.value
			: mes.options[mes.selectedIndex].value;
    if (!isDateDMY(dia.value + "/" + valorMes + "/" + ano.value) ||
        (funcion ? !eval("funcion(dia, mes, ano)") : false)) {
        appendErrorMessage(msgError)
        if (_campoError == null) {
            _campoError = dia;
        }
        return false;
    }
    return true;
}


/*Valida una fecha que se encuentra en un solo campo. en formato DD/MM/YYYY*/
function validarFechaUnCampo(campo, msgError, funcion){
	var value = trim(campo.value)
	if (value.length == 0 || value.length > 10 ||
		!isDateDMY(value) ||
		(funcion ? !eval("funcion(campo)") : false)) {
		appendErrorMessage(msgError)
		if (_campoError == null) {
			_campoError = campo;
			
		}
		return false;
	}
	return true;
}




function validarFechaOpcional(dia, mes, ano, msgError, funcion) {
	var entroMes =  (mes.type == "text")
			? (trim(mes.value).length > 0)
			: (mes.selectedIndex > 0);
	if ((trim(dia.value).length > 0) || entroMes
			|| (trim(ano.value).length > 0)) {
		return validarFecha(dia, mes, ano, msgError, funcion)
	}
}


function validarRangoFechas2(dia1,mes1,ano1,dia2,mes2,ano2,msgError,funcion) {
	var valorMes1 = mes1;
	var valorMes2 =	mes2;
	var mensajeerror = msgError;
	/*var valorMes1 = (mes1.type == "text")
			? mes1.value
			: mes1.options[mes1.selectedIndex].value;*/
	/*var valorMes2 = (mes2.type == "text")
			? mes2.value
			: mes2.options[mes2.selectedIndex].value;*/
			
	var estado = compareDatesDMY(dia1.value + "/" + valorMes1 + "/" + ano1.value, dia2.value + "/" + valorMes2 + "/" + ano2.value);
	//alert (estado);
	if (estado > 0) {
		alert (mensajeerror);
		appendErrorMessage(mensajeerror);
		return false;
		if (_campoError == null) {
			_campoError = dia1;
		}
		//alert ("return false;")
		
	}
	return true;
}

function validarRangoFechas(fecha1,fecha2,msgError,funcion) {
	var firstDateArray; 
	var secondDateArray;
	firstDateArray = fecha1.split("/");
	secondDateArray = fecha2.split("/");
	var mensajeError = msgError;
	//alert ("mensajeError"+mensajeError);
	if (compareDatesDMY(firstDateArray[0] + "/" + firstDateArray[1] + "/" + firstDateArray[2], secondDateArray[0] + "/" + secondDateArray[1] + "/" + secondDateArray[2]) >= 0) {
		//alert (mensajeError);
		if (_campoError == null) {
			if(!fecha1.disabled){
				_campoError = fecha1;
			}else{
				_campoError = fecha2;
			}
		}
		if(mensajeError!=""){
			appendErrorMessage(mensajeError);
		}
		return false;
	}
	
	return true;
}


function validarEntero(campo, msgError, limiteInferior, limiteSuperior,funcion) {
	if (!limiteInferior && limiteInferior != 0) {
		limiteInferior = Number.NEGATIVE_INFINITY
		limiteSuperior = Number.MAX_VALUE
	}
	if (!isIntRange(campo.value, limiteInferior, limiteSuperior) ||
		(funcion ? !eval("funcion(campo)") : false)) {
		appendErrorMessage(msgError)
		if (_campoError == null) {
			_campoError = campo;
		}
		return false;
	}
	return true;
}

function validarEnteroOpcional(campo, msgError, limiteInferior, limiteSuperior, funcion) {
	if (trim(campo.value).length > 0) {
		return validarEntero(campo, msgError, limiteInferior, limiteSuperior, funcion)
	}
}


function validarFloat(campo, msgError, limiteInferior, limiteSuperior, funcion) {
	if (!limiteInferior && limiteInferior != 0) {
		limiteInferior = Number.NEGATIVE_INFINITY
		limiteSuperior = Number.MAX_VALUE
	}
	if (!isFloatRange(campo.value, limiteInferior, limiteSuperior) ||
		(funcion ? !eval("funcion(campo)") : false)) {
		appendErrorMessage(msgError)
		if (_campoError == null) {
			_campoError = campo;
		}
		return false;
	}
	return true;
}

function validarFloatOpcional(campo, msgError, limiteInferior, limiteSuperior, funcion) {
	if (trim(campo.value).length > 0) {
		return validarFloat(campo, msgError, limiteInferior, limiteSuperior, funcion)
	}
}

function validarEmail(campo, msgError) {
	if (!isEmail(campo.value)) {
		appendErrorMessage(msgError)
		if (_campoError == null) {
			_campoError = campo;
		}
		return false;
	}
	return true;
}


function validarEmailOpcional(campo, msgError) {
	if (trim(campo.value).length > 0) {
		return validarEmail(campo, msgError);
	}
}


var _mensajeAdvertencia = "Por favor verifique la siguiente información: \n\n";

function validarForma(forma) {
	
	_errores = ""
	_campoError = null;
	eval("hacerValidaciones_" + forma.name +"(forma)");
	if (_errores != "") {
		alert(_mensajeAdvertencia + _errores);
		_campoError.focus();
		return false;
	}
	return true;
}


function controlarLongitudTextArea(teclaPresionada, campo, maximaLongitud) {
	var longitud = campo.value.length;

	var valTecla = teclaPresionada.which ? parseInt(teclaPresionada.which, 10)
			: (teclaPresionada.keyCode ? parseInt(teclaPresionada.keyCode, 10)
			: null);

	if (valTecla != null) {
		if ((valTecla != 8) && (valTecla != 46)) {
			if (longitud > maximaLongitud-1) {
				return false;
			}
		}
	}
	return true;
}






/**
Estas funciones están probadas en browsers Netscape 4.x y Explorer 4.x.
*/
function rtrim(cadena) {
	cadena += "";
	for (var i = cadena.length -1; (i >= 0) && ((cadena.charAt(i) == ' ')); i--)
		;
	return cadena.substring(0, i+1);
}

function ltrim(cadena) {
	cadena += "";
	for (var i = 0; (i < cadena.length) && ((cadena.charAt(i) == ' ')); i++)
		;
	if (i == cadena.length) {
		return "";
	}
	return cadena.substring(i);
}

function trim(cadena) {
	return ltrim(rtrim(cadena));
}

/** Las siguientes funciones se utilizan para validar un número de punto flotante. */
var r1Float = new RegExp("(\,\,)|([0-9]{4}\,)|(^[0]{0,}\,)|([\,]+[0-9]{0,2}[\,$])|(\\..*[\\.\,])");
var r2Float = new RegExp("(((\\[?)[0-9]\\,[0-9]{3}(\\]?))|(^[0-9]*))(\\.[0-9]+)?$")

function isFloat(number) {
	number = trim(number);

	if (number.length == 0) {
		return false;
	}

	if (isNaN(parseFloat(number))) {
		return false;
	} else {
		return true;
	}
}


/*Esta funcion recibe un float y un rango y lo valida*/
function isFloatRange(number, min, max)  {
	if (!isFloat(number)) {
		return false;
	}
	var theValue = (number.split(",").join(""))*1;
	return theValue >= min && theValue <= max
}

var r1Int = new RegExp("(\,\,)|([0-9]{4}\,)|(^[0]{0,}\,)|([\,]+[0-9]{0,2}[\,$])");
var r2Int = new RegExp("((\\[?)[0-9]\\,[0-9]{3}(\\]?)$)|(^[0-9]+)$")

function isInt(number) {
	number = trim(number + "");
	return (!r1Int.test(number) && r2Int.test(number));
}

/*Esta funcion recibe un entero y un rango y lo valida*/
function isIntRange(number, min, max)  {
	if (!isInt(number)) {
		return false;
	}
	var theValue = (number.split(",").join(""))*1;
	return theValue >= min && theValue <= max
}


/*Esta funcion valida una hora y retorna falso o verdadero*/
/* Recibe el formato de HH:MM*/
function isTime(time)  {
	var HP
	time = trim(time)
	HP = time.split(":")
	if (HP.length != 2) {
		return false;
	}
	return(HP[0] < 24 && HP[0] >= 0 && HP[1] < 60 && HP[1] >= 0)
}


/*Esta funcion valida una fecha y retorna falso o verdadero*/
/* Recibe el formato de Dia/Mes/Ano*/
function isDateDMY(date)  {
	var FP
	date = trim(date)
	FP = date.split("/")
	if (FP.length != 3) {
		return false
	}
	return isSplitDateDMY(FP[0], FP[1], FP[2])
}


function isSplitDateDMY(day, month, year)  {
	if (!isInt(day) || !isInt(month) || !isInt(year)) {
		return false;
	}
	date = new Date(year, month-1, day)
	return ((date.getDate() == (day*1)) && ((date.getMonth()+1) == (month*1)) && (date.getFullYear() == (year*1)));
}


// Retorna si la fecha inferior efectivamente es inferior
// que la fecha superior. La fecha debe encontrarse en formato dd/mm/yyyy
// -1 a < b, 0 a == b, 1 a > b
function compareDatesDMY(a, b) {
	var firstDateArray, secondDateArray;
	firstDateArray = a.split("/");
	secondDateArray = b.split("/");
	aDate = new Date(firstDateArray[2], firstDateArray[1]-1, firstDateArray[0]);
	bDate = new Date(secondDateArray[2], secondDateArray[1]-1, secondDateArray[0]);
	if (aDate.getTime() < bDate.getTime()) {
		//alert ("-1");
		return -1;
	}
	if (aDate.getTime() == bDate.getTime()) {
		//alert ("0")
		return 0;
	}
	//alert ("1")
	return 1;
}

function isChecked(field, msgError) {
	if (!field) {
		return false;
	}
	if (field.length) {
		for (var i = 0; i < field.length; i++) {
			if (field[i].checked) {
				return true;
			}
		}
		appendErrorMessage(msgError)
		if (_campoError == null) {
			_campoError = field[0];
		}
		return false;
	}
	return field.checked;
}


/** Valida un email */
function isEmail(str) {
  var indexLT = str.indexOf('<');
  var indexGT = str.indexOf('>');
  var email = str;
  if (indexGT > indexLT && indexGT > -1 && indexLT > -1) {
	email = email.substring(indexLT+1, indexGT);
  }
  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
  return (!r1.test(email) && r2.test(email));
}

/** Estas son la validaciones en si de las formas */

var _campoError = null;
var _errores    = "";

function appendErrorMessage(msgError) {
	_errores += ((_errores != "") ? "\n":"") + "        " + msgError
}

/** Valida si la tecla que se presionó fue un Enter */

function checkEnter(event)
{        var NS4 = (document.layers) ? true : false;
   var code = 0;
   var result = true;
      if(NS4)
       code = event.which;
   else
       code = event.keyCode;
      if(code==13)
       result = false;
          return result;
}

function convertirAFormatoLatino(origen) {
	document.write(origen.replace(/\,/gi,'.'));
}

function validarFechaUnCampo(campo, msgError, funcion){
    var value = trim(campo.value)
    if (value.length == 0 || value.length > 10 ||
     !isDateDMY(value) ||
        (funcion ? !eval("funcion(campo)") : false)) {
        appendErrorMessage(msgError)
        if (_campoError == null) {
            _campoError = campo;
        }
        return false;
    }
    return true;
}

 function validarFiltroNoVacio(forma,campos,msgError) {
    arrayCampo = campos.split(",");
    noVacio=false;
    for(i=0; i<arrayCampo.length; i++) {
    	if(eval(forma+"."+arrayCampo[i]+".value!=''"))noVacio=true;
    }
	if (!noVacio) {
  	    _campoError = eval(forma+"."+arrayCampo[0]);
		appendErrorMessage(msgError);
		return false;
	}
	return true;

}

function validarSelectoresDiferentes(campo1,campo2,msgError) {
	if (campo1.options[campo1.selectedIndex].value == campo2.options[campo2.selectedIndex].value) {
		appendErrorMessage(msgError)
		if (_campoError == null) {
				_campoError = campo2;
		}
		return false;
	}else{
		return true;
	}
}

function validarExcluyentes(campo1,campo2,msgError) {
	if (campo1.value!="" && campo2.value!="") {
		appendErrorMessage(msgError)
		if (_campoError == null) {
				_campoError = campo2;
		}
		return false;
	}else{
		if (campo1.value == "" && campo2.value == ""){
			appendErrorMessage("Debe llenar uno de los dos campos (URL o Archivo)")
			if (_campoError == null) {
					_campoError = campo2;
			}
			return false;
		}else{
		 return true;
		}
		
	}
}


<!-- Begin
function check_date(field,msgError){
var checkstr = "0123456789";
var DateField = field;
var Datevalue = "";
var DateTemp = "";
var seperator = ".";
var day;
var month;
var year;
var leap = 0;
var err = 0;
var i;
   err = 0;
   DateValue = DateField;
   //alert(DateValue);
   /* Delete all chars except 0..9 */
   for (i = 0; i < DateValue.length; i++) {
	  if (checkstr.indexOf(DateValue.substr(i,1)) >= 0) {
	     DateTemp = DateTemp + DateValue.substr(i,1);
	  }
   }
   DateValue = DateTemp;
   /* Always change date to 8 digits - string*/
   /* if year is entered as 2-digit / always assume 20xx */
   if (DateValue.length == 6) {
      DateValue = DateValue.substr(0,4) + '20' + DateValue.substr(4,2); }
   if (DateValue.length != 8) {
      err = 19;}
   /* year is wrong if year = 0000 */
   year = DateValue.substr(4,4);
   if (year == 0) {
      err = 20;
   }
   /* Validation of month*/
   month = DateValue.substr(2,2);
   if ((month < 1) || (month > 12)) {
      err = 21;
   }
   /* Validation of day*/
   day = DateValue.substr(0,2);
   if (day < 1) {
     err = 22;
   }
   /* Validation leap-year / february / day */
   if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)) {
      leap = 1;
   }
   if ((month == 2) && (leap == 1) && (day > 29)) {
      err = 23;
   }
   if ((month == 2) && (leap != 1) && (day > 28)) {
      err = 24;
   }
   /* Validation of other months */
   if ((day > 31) && ((month == "01") || (month == "03") || (month == "05") || (month == "07") || (month == "08") || (month == "10") || (month == "12"))) {
      err = 25;
   }
   if ((day > 30) && ((month == "04") || (month == "06") || (month == "09") || (month == "11"))) {
      err = 26;
   }
   /* if 00 ist entered, no error, deleting the entry */
   if ((day == 0) && (month == 0) && (year == 00)) {
      err = 0; day = ""; month = ""; year = ""; seperator = "";
   }
   /* if no error, write the completed date to Input-Field (e.g. 13.12.2001) */
   if (err == 0) {
      DateField.value = day + seperator + month + seperator + year;
   }
   /* Error-message if err != 0 */
   else {
      appendErrorMessage(msgError)
      return false;

   }
}

function hacerSubmit(campo,msgError,msgErrorVac){
	str = campo.value;
  	var r1 = new RegExp('^[\"]{1}[a-zA-Z0-9\\á\\é\\í\\ó\\ú\\-\\.\\ \\+]{1}[a-zA-Z0-9\\á\\é\\í\\ó\\ú\\-\\.\\ \\+]+[\"]{1}$')
  	var r2 = new RegExp('^([\"]{1}[a-zA-Z0-9\\á\\é\\í\\ó\\ú\\-\\.\\ \\+]{1}[a-zA-Z0-9\\á\\é\\í\\ó\\ú\\-\\.\\ \\+]+[\"][\+]?)?[a-zA-Z0-9\\á\\é\\í\\ó\\ú\\-\\.\\ \\+]{1}[a-zA-Z0-9\\á\\é\\í\\ó\\ú\\-\\.\\ \\+]+$')
  	var r3 = new RegExp('^([a-zA-Z0-9\\á\\é\\í\\ó\\ú\\-\\.\\ \\+]{1}[a-zA-Z0-9\\á\\é\\í\\ó\\ú\\-\\.\\ \\+]+[\+]?)?[\"]{1}[a-zA-Z0-9\\á\\é\\í\\ó\\ú\\-\\.\\ \\+]{1}[a-zA-Z0-9\\á\\é\\í\\ó\\ú\\-\\.\\ \\+]+[\"]{1}$');

	if(campo.value != '') {
		if(r3.test(str) || r2.test(str)){
			return true;
		} else {
			appendErrorMessage(msgError)
			if (_campoError == null) {
				_campoError = campo;
			}
			return false;
		}
	} else {
		appendErrorMessage(msgErrorVac);
	}
}
//  End -->
