
<!--
// ---------------------------------------------------------------------- //
//                             RESUMEN                                    //
// ---------------------------------------------------------------------- //
// 
// El objetivo de las siguientes funciones en JavaScript es
// validar los ingresos del usuario en un formulario antes
// de que estos datos vayan al servidor.
//
// Se utiliza una función checkfield donde hace le llamado a las funciones
// de validación descritas seguidamente.
//
// Se utilizan unas funciones para la validación de entrada tipo monto:
//	- CheckAmount el cual llama a otras funciones para varias validaciones.
// También se utiliza una función:
//	- UpdateAmount donde actualiza la entrada para ser insertada en la tabla
//	  como un dato tipo string incluyendo los decimales
// Estas funciones son independientes de checkfield OJO!!
//
// Varias de ellas toman un parametro opcional E.O.K (eok) (emptyOK
// - true si se acepta que el valor este vacio, false si no
// se acepta). El valor por omision es el que indique la
// variable global defaultEmptyOK definida mas abajo.
//
// ---------------------------------------------------------------------- //
//                      SINTAXIS DE LAS FUNCIONES                         //
// ---------------------------------------------------------------------- //
//
// FUNCION PARA CHEQUEAR UN CAMPO DE INGRESO:
//
// checkField (theField, theFunction, [, s] [,eok])
//        verifica que el campo de ingreso theField cumpla con la
//        condicion indicada en la funcion theFunction (que puede ser
//        una de las descritas en "FUNCIONES DE VALIDACION" o cualquier
//        otra provista por el usuario). En caso contrario despliega el
//        string "s" (opcional, hay mensajes por default para las
//        funciones de validacion provistas aqui).
//
// FUNCIONES DE VALIDACION:
//
// isNumber (s [,eok])              s es entero o tiene punto decimal
// isAlphabetic (s [,eok])          s tiene solo letras
// isAlphanumeric (s [,eok])        s tiene solo letras y/o numeros
// isPhoneNumber (s [,eok])         s tiene solo numeros, (,),-
// isEmail (s [,eok])               s es una direccion de e-mail
// isFile(s [,eok])					s es una ruta de Archivo
//
// OTRAS IMPORTANTES: 
// isAmount(s)						s es un monto, numero con punto(s) y coma(s) dependiento del formato vzolano a o americano.	
// isTAX(s)							s es un código Arancelario/Acepta punto
// isText(s [,eok])					s es tiene solo letras, y/o numeros, y/o espacios en blanco
// isTextWithAll(s [,eok])			s es Text y los caracteres caracter "-./,#;"  
// isQuotationMark (s)				s contiene simple comilla

//
//
// FUNCIONES INTERNAS:
//
// isEmpty (s)						s es vacio
// isWhitespace (s)                 s es vacio o solo son espacios
// isLetter (c)                     c es una letra
// isDigit (c)                      c es un digito
// isLetterOrDigit (c)              c es letra o digito
// isNotLen(s,Len)					Verifica la longitud de s
// CountChars(s,char)				Cuenta el caracter "char" en la cadena s
//
// FUNCIONES PARA REFORMATEAR DATOS:
//
// stripCharsInBag (s, bag)			quita de s los caracteres en bag
// stripCharsNotInBag (s, bag)      quita de s los caracteres NO en bag
// stripWhitespace (s)              quita el espacio dentro de s
// stripInitialWhitespace (s)       quita el espacio al principio de s
//
// FUNCIONES PARA PREGUNTARLE AL USUARIO:
//
// statBar (s)                      pone s en la barra de estado
// warnEmpty (theField, s)          indica que theField esta vacio
// warnInvalid (theField, s)        indica que theField es invalido

// OTRAS IMPORTANTES: 
// warnNotLen (theField,Len,Dec,sLenEntera)     Notificar que el campo no tiene la longitud especifica
// warnNotDec(theField,Dec)						Notificar los números decimales incorrectos

// FUNCIONES PARA CAMPOS TIPO REAL Ejm. Montos
// No se utilizan en la función checkfield. Se llaman solas.
//
// Función para chequear un campo tipo Monto
//
//  checkAmount(theField,Dec,Len,emptyOK)
//			Parámetros:
//				theField: campo de entrada a chequear
//				Dec: número de decimales 
//				Len:  longitud del monto
//        Función que verifica la entrada correcta del Monto:
//			- Define el Símbolo Decimal utilizado (punto o coma)
//			- Valida las posiciones y las cantidades de las comas y los puntos
//			- Verifica los 3 dígitos entre el símbolo de agrupamiento de dígitos.
//			- Verifica el número de decimales
//
//  UpdateAmount(theField,Dec,Len)			
//		Elimina punto(s) y/o coma(s)  y rellena con ceros los decimales si falta(n)
//		Actualiza los valores colocándole los decimales de no existir y elimina
//		lo(s) punto(s) y la(s) coma(s) del objeto para almacenar estos como un
//		string.
//		Esta función se llama cuando ya se ha validado todas las entradas
//		para evitar que añada más decimales de los correctos cada vez que
//		se detenga por una validación de un campo erróneo.
//								
//isDecimalSymbol(s,NoDec)										Verifica el formato
//isVerifyDigits(theField,DigitGroupingSymbol,DecimalSymbol)	Verifica los 3 dígitos entre el símbolo de agrupamiento de dígitos
//isDecimal(s,n,DecimalSymbol)									s contien los decimales correctos(n)
//isAmountChars(s,n,DecimalSymbol)								Elimina puntos y la coma  y rellena con ceros los decimales si falta
//
// Otras FUNCIONES:

// checkLen (theField, Len,emptyOK)				Chequea que el objeto theField tenga la longitud Len.
// checkRange(theFieldLI, theFieldLS,emptyOK)	Chequea el Rango  de las dos entradas LI y LS.
//
// ---------------------------------------------------------------------- //
//                                VARIABLES                               //
// ---------------------------------------------------------------------- //

// Esta variable indica si está bien dejar las casillas
// en blanco como regla general
var defaultEmptyOK = false

// Esta variable indica si se debe verificar la presencia de comillas
// u otros símbolos extraños en un campo, por omisión no porque
// siempre crea problemas con las bases de datos o programas CGI
// Función asociada isNice
var checkNiceness = false;


// Esta variable indica si se debe verificar la presencia de simple comilla,
// por omisión no porque siempre crea problemas con las bases de datos o programas CGI
// Función asociada isQuatationMark
var checkQuotationMark = true;


// listas de caracteres
var digits = "0123456789";
var lowercaseLetters = "abcdefghijklmnopqrstuvwxyzáéíóúñü"
var uppercaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZÁÉÍÓÚÑ"
var whitespace = " \t\n\r";

// caracteres admitidos en nos de telefono
var phoneChars = "()-+#./";

//caracetres admitidos en Texto
var textAllChars = ".-/,#;:()+¿?";

//Caracteres admitidos en el Rif y en los Codigos
var dashChars = "-";

//Caracter . y para los montos
var dot = ".";
var comma = ",";
var numberChars =".,-"
//var numberCharsNew =".,-"

// Caracteres para archivos
var fileChars = ".:_-"
var fileCharsShow = "punto(.), dos puntos(:), backslash(\), (-)  y  (_)"
var Backslash = "\\"

// Caracteres para direccion URL
var UrlChars = ":/"

// ---------------------------------------------------------------------- //
//                     TEXTOS PARA LOS MENSAJES                           //
// ---------------------------------------------------------------------- //

// m abrevia "missing" (faltante)
var mMessage1 = "Error: no puede dejar "
var mMessage2 = " vacio"

// p abrevia "prompt"
var pPrompt = "Error: ";
var pAlphanumeric = "ingrese un texto que contenga solo letras y/o numeros";
var pAlphabetic   = "ingrese un texto que contenga solo letras";
var pInteger = "ingrese un numero entero";
var pNumber = "ingrese un numero";
var pPhoneNumber = "ingrese un número de teléfono";
var pEmail = "ingrese una dirección de correo electrónico válida";
var pNice = "no puede utilizar comillas aqui";
var pText = "ingrese un Texto válido";
var pFile = "ingrese un nombre de archivo válido."


// ---------------------------------------------------------------------- //
//                FUNCIONES PARA MANEJO DE ARREGLOS                       //
// ---------------------------------------------------------------------- //

// JavaScript 1.0 (Netscape 2.0) no tenia un constructor para arreglos,
// asi que ellos tenian que ser hechos a mano. Desde JavaScript 1.1 
// (Netscape 3.0) en adelante, las funciones de manejo de arreglos no
// son necesarias.

function makeArray(n) {
//*** BUG: If I put this line in, I get two error messages:
//(1) Window.length can't be set by assignment
//(2) daysInMonth has no property indexed by 4
//If I leave it out, the code works fine.
//   this.length = n;
   for (var i = 1; i <= n; i++) {
      this[i] = 0
   } 
   return this
}

// ---------------------------------------------------------------------- //
//                  CODIGO PARA FUNCIONES BASICAS                         //
// ---------------------------------------------------------------------- //

// s es vacio
function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}

// s es vacio o solo caracteres de espacio
function isWhitespace (s)
{   var i;
    if (isEmpty(s)) return true;
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        // si el caracter en que estoy no aparece en whitespace,
        // entonces retornar falso
        if (whitespace.indexOf(c) == -1) return false;
    }
    return true;
}

// Quita todos los caracteres bag que que estan en el string s.
function stripCharsInBag (s, bag)
{   var i;
    var returnString = "";

    // Buscar por el string, si el caracter no esta en "bag", 
    // agregarlo a returnString
    
    for (i = 0; i < s.length; i++)
    {   var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }

    return returnString;
}
// ---------------------------------------------------------------------- //
//						Funcion CaracterAscii			//
// ---------------------------------------------------------------------- //
function CaracterAscii (s,numberAscii)
{   var i;
    var returnString = "";

    // Buscar por el string, si el caracter no esta en "bag", 
    // agregarlo a returnString
    
    for (i = 0; i < s.length; i++)
    {   var c = s.charCodeAt(i);
        if (c != numberAscii) returnString += c;
    }

    return returnString;
}

// Lo contrario, quitar todos los caracteres que no estan en "bag" de "s"
function stripCharsNotInBag (s, bag)
{   var i;
    var returnString = "";
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (bag.indexOf(c) != -1) returnString += c;
    }

    return returnString;
}

// Quitar todos los espacios en blanco de un string
function stripWhitespace (s)
{   return stripCharsInBag (s, whitespace)
}


// Cuenta cuántos caracteres c existen en s
function CountChars(s,caracter)
{
var count=0;
	for (i = 0; i < s.length; i++)
	{   
	        var c = s.charAt(i);
			if (caracter.indexOf(c) !=  -1) count++;
	}
	return count;
}

// La rutina siguiente es para cubrir un bug en Netscape
// 2.0.2 - seria mejor usar indexOf, pero si se hace
// asi stripInitialWhitespace() no funcionaria

function charInString (c, s)
{   for (i = 0; i < s.length; i++)
    {   if (s.charAt(i) == c) return true;
    }
    return false
}

// Quita todos los espacios que antecedan al string
function stripInitialWhitespace (s)
{   var i = 0;
    while ((i < s.length) && charInString (s.charAt(i), whitespace))
       i++;
    return s.substring (i, s.length);
}

// c es una letra del alfabeto espanol
function isLetter (c)
{
    return( ( uppercaseLetters.indexOf( c ) != -1 ) ||
            ( lowercaseLetters.indexOf( c ) != -1 ) )
}

// c es un digito
function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}

// c es letra o digito
function isLetterOrDigit (c)
{   return (isLetter(c) || isDigit(c))
}

//s tiene la Longitud especifica
function isNotLen(s,Len)
{	if (s.length <= Len) return true;
	return false;
}

// ---------------------------------------------------------------------- //
//                          NUMEROS                                       //
// ---------------------------------------------------------------------- //

// s es un número entero 
function isNumber (s) 
{   var i;

    if (isEmpty(s)) 
       if (isNumber.arguments.length == 1) return defaultEmptyOK;
       else return (isNumber.arguments[1] == true);
       
    for (i = 0; i < s.length; i++)
         if (!isDigit(s.charAt(i)))  return false;
    return true;
}

// ---------------------------------------------------------------------- //
//                          COD ARANCEL                                   //
// ---------------------------------------------------------------------- //

// s es un codigo arancelario acepta punto.	
function isTAX(s)
{
	if (isNumber(stripCharsInBag(s,dot))) return true;
	return false;
}
// ---------------------------------------------------------------------- //
//                        STRINGS SIMPLES                                 //
// ---------------------------------------------------------------------- //

// s tiene solo letras
function isAlphabetic (s)
{   var i;

    if (isEmpty(s)) 
       if (isAlphabetic.arguments.length == 1) return defaultEmptyOK;
       else return (isAlphabetic.arguments[1] == true);
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is letter.
        var c = s.charAt(i);

        if (!isLetter(c))
        return false;
    }
    return true;
}

// s tiene solo letras y numeros
function isAlphanumeric (s)
{   var i;

    if (isEmpty(s)) 
       if (isAlphanumeric.arguments.length == 1) return defaultEmptyOK;
       else return (isAlphanumeric.arguments[1] == true);

    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (! (isLetter(c) || isDigit(c) ) )
        return false;
    }
    return true;
}

// s tiene solo letras,numeros y espacios en blanco
function isText (s)
{
    if (isEmpty(s)) 
       if (isText.arguments.length == 1) return defaultEmptyOK;
	   else return (isText.arguments[1] == true);
	return( isAlphanumeric( stripCharsInBag( s, whitespace ) ) );
}

//s es Text tiene letras, números, espacios en blanco, caracter "-","." o "/"

function isTextWithAll (s)
{   
	if (isEmpty(s)) 
       if (isTextWithAll.arguments.length == 1) return defaultEmptyOK;
       else return (isTextWithAll.arguments[1] == true);
       // si no se desea las dobles comillas sólo quite la sig. sentencia:
       // y coloque checkNice = false
       var modString = stripCharsInBag( s, "\"" );
       // igual con las simples comillas:
       //modString = stripCharsInBag( modString, "'" );
       //alert ('Mod:'+modString);
    return (isText(stripCharsInBag( modString, textAllChars )));
}

//s es RIF , tiene letras, números y/o el caracter "-"
function isTextWithDash (s)
{   
    if (isEmpty(s)) 
       if (isTextWithDash.arguments.length == 1) return defaultEmptyOK;
       else return (isTextWithDash.arguments[1] == true);
    return (isAlphanumeric(stripCharsInBag(s, dashChars )));
}

// ---------------------------------------------------------------------- //
//                           FILE			                              //
// ---------------------------------------------------------------------- //

function isFile(s)
{   
	var i;
	var String;
	if (isEmpty(s)) 
       if (isFile.arguments.length == 1) return defaultEmptyOK;
       else return (isFile.arguments[1] == true);
      
     modString = (stripCharsInBag( s,fileChars ));
     modString = (stripCharsInBag( modString,Backslash));
	return (isText(modString));
}

// ---------------------------------------------------------------------- //
//                           FONO o EMAIL                                 //
// ---------------------------------------------------------------------- //

// s es numero de telefono valido
function isPhoneNumber (s)
{   var modString;
    if (isEmpty(s)) 
       if (isPhoneNumber.arguments.length == 1) return defaultEmptyOK;
       else return (isPhoneNumber.arguments[1] == true);
    modString = stripCharsInBag( s, phoneChars );
    modString = stripCharsInBag( modString, whitespace )
    return (isNumber(modString));
}

// s es una direccion de correo válida
function isEmail (s)
{
    if (isEmpty(s)) 
       if (isEmail.arguments.length == 1) return defaultEmptyOK;
       else return (isEmail.arguments[1] == true);
    if (isWhitespace(s)) return false;
    var i = 1;
    var sLength = s.length;
    while ((i < sLength) && (s.charAt(i) != "@"))
    { i++
    }

    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;

    while ((i < sLength) && (s.charAt(i) != "."))
    { i++
    }

    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}

// ---------------------------------------------------------------------- //
//                               COMILLAS                                 //
// ---------------------------------------------------------------------- //
//s contiene simple deble comilla
function isNice(s)
{
        var i = 0;
        var sLength = s.length;
        var b = 1;
        while(i<sLength) {
				if ((s.charAt(i) == "\"")||(s.charAt(i) == "'" )) b = 0;
                i++;
        }
        return b;
}

// ---------------------------------------------------------------------- //
//                  Funcion isQuotatioMarks                               //
// ---------------------------------------------------------------------- //
//s contiene simple comilla
function isQuotationMark(s)
{
	var i = 0;
        var sLength = s.length;
        var b = 1;
        while(i<sLength) {
				if (s.charAt(i) == "'" ) b = 0;
                i++;
        }
        return b;
}

// ---------------------------------------------------------------------- //
//                  FUNCIONES PARA RECLAMARLE AL USUARIO                  //
// ---------------------------------------------------------------------- //

// pone el string s en la barra de estado
function statBar (s)
{   window.status = s
}


function warn(s)
{   alert(s);
    statBar(s);
    return false;
}

function warnFocus(theField,s)
{   theField.focus();
    return(warn(s));
}


// notificar que el campo theField es invalido
function warnSelect (theField, s)
{   
    theField.select();
    return (warnFocus(theField,s));
}
// notificar que el campo theField esta vacio
// es necesario la etiqueta cuando son muchos campo

function ComboVacio(theField)
{	
	return ((theField.options[theField.options.selectedIndex].value == '')||(theField.value==''));
	
}

function warnEmptyField (theField,Etiqueta)
{   
    mMessages = mMessage1+Etiqueta + mMessage2;
    alert(mMessages)
    statBar(mMessages)
    return false
}


// notificar que el campo theField esta vacio
// es necesario la etiqueta cuando son muchos campo
function warnEmpty (theField,Etiqueta)
{   
    theField.focus();
    mMessages = Etiqueta;
    alert(mMessages)
    statBar(mMessages)
    return false
}
// notificar que el campo theField es invalido
function warnInvalid (theField, s)
{   theField.focus();
    theField.select();
    alert(s);
    statBar(pPrompt + s);
    return false;
}

//Notificar que el campo no tiene la longitud especifica
function warnNotLen (theField,Len,Dec,sLenEntera)
{   
	var dif = sLenEntera - Len + Dec;
	theField.focus();
    theField.select();
    s = 'La longitud del Campo seleccionado debe ser de '+Len +' caracteres'+'\n'
    s = s +'incluyendo los '+Dec+ ' decimales, la parte entera excede por ' 
    s = s + dif+' caractere(s)';
    alert(s);
    statBar(pPrompt + s);
    return false;
}

//Notificar los números decimales correctos
function warnNotDec(theField,Dec)
{
	theField.focus();
    theField.select();
    s = 'Los decimales deben ser de '+Dec+ ' dígitos';
    alert(s);
    statBar(pPrompt + s);
    return false;
}


// ---------------------------------------------------------------------- //
//                   el corazon de todo: CHECKFIELD                       //
// ---------------------------------------------------------------------- //

function checkField (theField, theFunction, Etiqueta,emptyOK, s)
{   
    var msg;
    if (checkField.arguments.length < 4) emptyOK = defaultEmptyOK;
    if (checkField.arguments.length == 5) {
        msg = s;
    } else {
        if( theFunction == isAlphabetic ) msg = pAlphabetic;
        if( theFunction == isAlphanumeric ) msg = pAlphanumeric;
        if( theFunction == isNumber ) msg = pNumber;
        if( theFunction == isEmail ) msg = pEmail;
        if( theFunction == isPhoneNumber ) msg = pPhoneNumber;
        if( theFunction == isTextWithAll ) msg = pText;
        if( theFunction == isText ) msg = pText;
        if( theFunction == isTextWithDash ) msg = pAlphanumeric;
        if( theFunction == isAmount ) msg = pNumber;
        if( theFunction == isTAX ) msg = pNumber;
        if( theFunction == isFile ) msg = pFile;
     }
   
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;

    if ((emptyOK == false) && (isEmpty(theField.value))) 
        return warnEmpty(theField,Etiqueta);
    
    // Si no desea doble comilla elimine los siguientes comentario:
    /*if ( checkNiceness && !isNice(theField.value))
        return warnInvalid(theField, pNice);*/
        
    if ( checkQuotationMark && !isQuotationMark(theField.value))
        return warnInvalid(theField, pNice);

    
    if (theFunction(theField.value) == true) 
        return true;
    else
        return warnInvalid(theField,msg);


}

// ---------------------------------------------------------------------- //
//						FUNCIONES VARIAS								  //
//			Se llaman solas sin necesidad de CheckField                   //
// ---------------------------------------------------------------------- //


// ---------------------------------------------------------------------- //
//                           FILE			                              //
// ---------------------------------------------------------------------- //


// FILE FILE FILE SOLO
//Chequea que el objeto theField tenga la longitud especificada en Len.
function checkFile(theField,msgEmpty,emptyOK)
{
	var sLen = theField.value.length;
	var modString;
	s = theField.value;
	

	if (checkFile.arguments.length < 3) emptyOK = defaultEmptyOK;
	
	if ((emptyOK == true) && (isEmpty(theField.value))) return true;

    if ((emptyOK == false) && (isEmpty(theField.value)))
		 return warnEmpty(theField,msgEmpty);  
	 	
	//verifica que esté en el PC del cliente
	
	//La longitud menor a 8 , c:\a.ext 
	if (sLen<8)
		{//alert('entro');
		return warnInvalid(theField,'Archivo Inválido, indique la ruta válida.');
	}
		
	//if (theField.value.substr(1,1)!= ':')  
	//	return warnInvalid(theField,'Archivo Inválido, indique la ruta válida.');
		
	//if (theField.value.substr(2,1)!= Backslash)  
	//	return warnInvalid(theField,'Archivo Inválido, indique la ruta válida.');
		
	if ((theField.value.lastIndexOf(whitespace)) != -1)
		return warnInvalid(theField,'Archivo Inválido, espacio blanco.');
		
	//Valida si tiene más de un punto.
	if ((theField.value.lastIndexOf(dot)) == -1)
		return warnInvalid(theField,'Archivo Inválido, no tiene extensión de archivo.');
		
	//Valida si tiene más de un punto.
	//if ((CountChars(theField.value,dot)>1))
	//	return warnInvalid(theField,'Archivo Inválido.');

	pos = sLen - 4;
	var c = theField.value.substr(pos,1)
	
	if (c!=dot) 
	{
		return warnInvalid(theField,'Archivo Inválido, extensión incorrecta.');
		
	}
	return true;
}


// FILE FILE IMAGEN
//Chequea que el objeto theField tenga la longitud especificada en Len.
function checkFileImg(theField,msgEmpty,emptyOK)
{
	var sLen = theField.value.length;
	var aImg = new Array('jpg','JPG','gif','GIF','BMP','BMP');
	var modString;
	s = theField.value;
	

	//if (checkFileImg.arguments.length < 3) emptyOK = defaultEmptyOK;
	
	
	if ((emptyOK == true) && (isEmpty(theField.value))) return true;

    if ((emptyOK == false) && (isEmpty(theField.value))) 
        return warnEmpty(theField,msgEmpty);
	

	pos = sLen - 4;
	var c = theField.value.substr(pos,1)
	
	if (c==dot) 
	{
	
		ext = theField.value.substr(pos+1,sLen-1);
		if ((ext!='jpg') && (ext!='JPG') && (ext!='gif') && (ext!='GIF') && (ext!='BMP') && (ext!='BMP') && (ext!='SWF') && (ext!='swf') )
			return warnInvalid(theField,'Archivo de Imagen Inválido, no tiene la extensión correcta.');
		
		else
			return true;
		//else
		//{
		//	modString = (stripCharsInBag( s,fileChars ));
		//	modString = (stripCharsInBag( modString,Backslash));
		//	if (isText(modString))
		//		return true;
		//	else
		//	{
		//	msg = 'Archivo de Imagen Inválido, contiene caracteres no válidos.\n Caracteres válidos:\n'+fileCharsShow
		//		return warnInvalid(theField,msg);
		//	}
		//}
	}
	else
		return warnInvalid(theField,'Archivo de Imagen Inválido, no tiene la extensión correcta.');			

}




// FILE FILE PDF
//Chequea que el objeto theField tenga la longitud especificada en Len.
function checkFilePdf(theField,msgEmpty,emptyOK)
{
	var sLen = theField.value.length;
	var aDoc = new Array('pdf','PDF','doc','DOC','xls','XLS');
	var modString;
	s = theField.value;
	

	//if (checkFilePdf.arguments.length < 3) emptyOK = defaultEmptyOK;
	
	if ((emptyOK == true) && (isEmpty(theField.value))) return true;

    if ((emptyOK == false) && (isEmpty(theField.value))) 
        return warnEmpty(theField,msgEmpty);
	

	pos = sLen - 4;
	var c = theField.value.substr(pos,1)
	
	if (c==dot) 
	{
		ext = theField.value.substr(pos+1,sLen-1);
		if ((ext!='pdf') && (ext!='PDF')&& (ext!='doc') && (ext!='DOC') && (ext!='xls') && (ext!='XLS'))
			return warnInvalid(theField,'Archivo Inválido,no tiene la extensión correcta.');
		else
			return true;
		//{
		//	modString = (stripCharsInBag( s,fileChars ));
		//	modString = (stripCharsInBag( modString,Backslash));
		//	if (isText(modString))
		//		return true;
		//	else
		//	{
		//	msg = 'Archivo Inválido, contiene caracteres no válidos.\n Caracteres válidos:\n'+fileCharsShow
		//		return warnInvalid(theField,msg);
		//	}
		//}
	}
	else
		return warnInvalid(theField,'Archivo Inválido, punto incorrecto.');			

}

//Chequea que el objeto theField tenga la longitud especificada en Len.
function checkLen (theField, Len,emptyOK)
{
	var sLen = theField.value.length;

	if (checkLen.arguments.length < 3) emptyOK = defaultEmptyOK;
	
	if ((emptyOK == true) && (isEmpty(theField.value))) return true;
	
	if (parseInt(Len) < parseInt(sLen))
	   	return warnNotLen (theField,Len,sLen);

	return true;
}
// Chequea el Rango  de las dos entradas LI y LS.
function checkRange(theFieldLI, theFieldLS,emptyOK)
{
	if ((emptyOK == true) && (((isEmpty(theFieldLI.value)) || (isEmpty(theFieldLS.value))))) return true;

	if (parseFloat(theFieldLS.value)<parseFloat(theFieldLI.value))
	{	//alert('LS:'+parseFloat(theFieldLS.value));
		//alert('LS:'+parseFloat(theFieldLI.value));
		return warnInvalid(theFieldLS,'Rango Inválido');
	}
    return true;
}


// ---------------------------------------------------------------------- //
//              Funciones para campos de tipo real: MONTOS                //
// ---------------------------------------------------------------------- //
// 
//
//
//
	/*###############################################################################
	# Autor 					= ENIAC, C.A.				 						#
	# Programador				= Maybel Gil										#
	# Fecha de Creación 		= Marzo 2001										#	
	# Programador Modif.		= Maybel Gil										#
	# Fecha última Modif.		= 15/06/2001										#
	# Objetivo					= Funciones varias para campos tipo real			#
	#################################################################################*/


 //s contiene los decimales correctos
function isDecimal(s,n,DecimalSymbol)
{
	if ( s.indexOf(DecimalSymbol) != (s.length-1))
	{
		var Dec = s.substring(s.lastIndexOf(DecimalSymbol)+1,s.length);
		if (Dec.length >n) 
		return false;
	}
return true;
}

//Verifica los 3 dígitos entre el símbolo de agrupamiento de dígitos
function isVerifyDigits(theField,DigitGroupingSymbol,DecimalSymbol)
{
	var intNum = theField.value;
	if (intNum.indexOf(DecimalSymbol) != -1)
		intNum = theField.value.substring(0,theField.value.lastIndexOf(DecimalSymbol));
	
	while (intNum.indexOf(DigitGroupingSymbol) != -1)
	{
		var intLen = intNum.length;
		var intPos = intNum.lastIndexOf(DigitGroupingSymbol);
		Digits =  intLen - intPos-1;
		if (Digits != 3)
			return warnInvalid(theField,'Inválido el número de dígitos entre el símbolo de agrupamiento');
		intNum = intNum.substring(0,intPos);
	}
return true;
}

//Elimina puntos y la coma  y rellena con ceros los decimales si falta
function isAmountChars(s,n,DecimalSymbol)
{	
intNumber = -1;
Dec = "";
if (s.indexOf(DecimalSymbol) != -1) 
	{
		var intNumber = stripCharsInBag( s.substring(0,s.lastIndexOf(DecimalSymbol)), numberChars );
		
		if (s.indexOf(DecimalSymbol)== (s.length-1))
			for(i=0;i<n;i++)
				Dec+='0';
		else
			{
				var Dec = s.substring(s.lastIndexOf(DecimalSymbol)+1,s.length);
				if (Dec.length <n) 
					for(i=0;i<(n-Dec.length);i++)
						Dec+='0';
			}
		intNumber+=Dec;
	}
	else
	{
		intNumber = stripCharsInBag( s, numberChars );
		for(i=0;i<n;i++) 
			intNumber+='0';
	}
	return intNumber;
}

// s es un monto, numero con punto(s) y/o coma(s).	
function isAmount(s)
{
	if (isNumber(stripCharsInBag( s, numberChars ))) return true;
	return false;
}

// s es un monto, numero con punto(s) y/o coma(s) y número negativo.	
//function isAmountNeg(s)
//{
//	if (isNumber(stripCharsInBag( s, numberCharsNew ))) return true;
//	
//	return false;
//}


//Define el símbolo decimal utilizado
function isDecimalSymbol(s,NoDec)
{
var num = 0;
	for (i = (s.length-1); i >=0 ; i--)
		{
			var c = s.charAt(i);
			if ( c == "." ) 
			{	
				//alert ('numP'+num);
				if (num<=NoDec)
					return dot;
				else if (num>NoDec)
						if (num==3)
							if (s.lastIndexOf(dot)== 0)
								return dot;
							else
								return comma;
						else
							return dot;
			} else     
		    if ( c == "," )
			{
				//alert ('numC'+num);
				if (num<=NoDec)
					return comma;
				else
					if (num>NoDec)
						if (num==3)
							if (s.lastIndexOf(comma)== 0)
								return comma;
							else
								return dot;
						else
							return  comma;
			}else if (isDigit(c)) num++;
		}
}

//Funcion que chequea si es monto
function checkAmount(theField,Dec,Len,emptyOK)
{
	
	if (checkAmount.arguments.length < 4) emptyOK = defaultEmptyOK;
	
	if ((emptyOK == true) && (isEmpty(theField.value))) return true;

	//Validaciones de las posiciones y las cantidades de las comas y los puntos
	if ( (CountChars(theField.value,dot)>1) && (CountChars(theField.value,comma)>1))
		return warnInvalid(theField,'Monto inválido');
	if ( (CountChars(theField.value,dot) == 1) && (CountChars(theField.value,comma)>1))
		if ((theField.value.lastIndexOf(comma)) > (theField.value.lastIndexOf(dot)))
			return warnInvalid(theField,'Inválida posición del simbolo decimal')
		else
		{	
			return isVerifyDigits(theField,comma,dot);
			DecimalSymbol = dot;
		}
	if ( (CountChars(theField.value,comma) == 1) && (CountChars(theField.value,dot)>1))
		if ((theField.value.lastIndexOf(dot)) > (theField.value.lastIndexOf(comma)))
			return warnInvalid(theField,'Inválida posición del simbolo decimal');
		else 
		{	
			return isVerifyDigits(theField,dot,comma);
			DecimalSymbol = comma;
		}
	if ( (CountChars(theField.value,dot) == 0) && (CountChars(theField.value,comma)>1))
	{	
		return isVerifyDigits(theField,comma,dot);
		DecimalSymbol = dot;
	}
	if ( (CountChars(theField.value,comma) == 0) && (CountChars(theField.value,dot)>1))
	{	
		return isVerifyDigits(theField,dot,comma);
		DecimalSymbol = comma;
	}
	if ( (CountChars(theField.value,dot) == 0) && (CountChars(theField.value,comma)==1))
	{	
		DecimalSymbol = isDecimalSymbol(theField.value,Dec);
	}
	if ( (CountChars(theField.value,comma) == 0) && (CountChars(theField.value,dot)==1))
	{	
		DecimalSymbol = isDecimalSymbol(theField.value,Dec);
	}
	if ( (CountChars(theField.value,dot) == 1) && (CountChars(theField.value,comma)==1))
		if ((theField.value.lastIndexOf(dot)) > (theField.value.lastIndexOf(comma)))
			DecimalSymbol = dot
		else
			DecimalSymbol = comma;
	if ( (CountChars(theField.value,dot) == 0) && (CountChars(theField.value,comma)==0))
		DecimalSymbol = isDecimalSymbol(theField.value,Dec);
		
	//alert('simbolo Decimal es'+DecimalSymbol);
	
	if (theField.value.lastIndexOf(DecimalSymbol) != -1)
	{
		//Verifica la longitud de los decimales
		if (!isDecimal(theField.value,Dec,DecimalSymbol))
			return warnNotDec(theField,Dec);
		var intNumber = stripCharsInBag( theField.value.substring(0,theField.value.lastIndexOf(DecimalSymbol)), numberChars );
	}
	else
		intNumber = stripCharsInBag( theField.value, numberChars );
	LenEntera = Len - Dec;
	sLen = intNumber.length;
	//alert('Entera:'+intNumber);
	//Verifica la longitud del monto (parte entera) sumando decimales si existen o no
	if (sLen > LenEntera)
		return warnNotLen(theField,Len,Dec,sLen)
	
	return true;
}
//Actualiza los valores colocándole los decimales de no existir y elimina
//lo(s) punto(s) y la(s) coma(s) del objeto para almacenar estos como un
//string.
function UpdateAmount(theField,Dec,Len)
{
	if (theField.value!= '')
	{
		DecimalSymbol = isDecimalSymbol(theField.value,Dec);
		intNumber = isAmountChars(theField.value,Dec,DecimalSymbol)
		theField.value = intNumber;
	}
}
