	function objCheck(texto,tipo)
	{
		this.texto=texto;
		if (tipo) { this.tipo=tipo }
		else { this.tipo = "TEXT"; }
	}

	function checkForm2(formu,m_objetos) {	
		for (i=0; i<formu.elements.length; i++) {
			obj = m_objetos[formu.elements[i].name];
			if (obj) {
				if (obj.tipo == "TEXT")
				{
					if (formu.elements[i].value=="") {
						alert(obj.texto);
						formu.elements[i].focus();
						return false;
					}
				}
				if (obj.tipo == "CHECK")
				{
					if (formu.elements[i].checked=="") {
						alert(obj.texto);
						formu.elements[i].focus();
						return false;
					}
				}
				if (obj.tipo == "RADIO")
				{
					if (!checkRadios(formu.elements[i],obj.texto)) 
					{
						return false;
					}
				}
			}
		}
		return true;
	}


	function checkForm(formu) {	
		for (i=0; i<formu.elements.length; i++) {
			if (mensajes[formu.elements[i].name]) {
				if (trim(formu.elements[i].value)=="") {
					alert(mensajes[formu.elements[i].name]);
					formu.elements[i].focus();
					return false;
				}
			}
		}
		return true;
	}
	
	function esnum(formu) {	
		for (i=0; i<(formu.elements.length-2); i++) {
			
				if (!EsNumerico(formu.elements[i].value)) {
					alert("El campo debe de ser numérico");
					formu.elements[i].focus();
					return false;
				}
			
		}
		return true;
	}

	function checkMail(obj,mensaje) 
	{
		//ok = (obj.value.indexOf('@')>0)
		ok = isEmail(obj.value)
		if (!ok) { 
			obj.focus();
			alert(mensaje);
		}
		return ok;
	}
	
	function isEmail (s)
	{   
	   if (isEmpty(s)) 
       if (isEmail.arguments.length == 1) return defaultEmptyOK;
       else return (isEmail.arguments[1] == true);
   
	   // is s whitespace?
       if (isWhitespace(s)) return false;
    
       // there must be >= 1 character before @, so we
       // start looking at character position 1 
       // (i.e. second character)
       var i = 1;
       var sLength = s.length;

	   // look for @
       while ((i < sLength) && (s.charAt(i) != "@"))
	    { i++
    	}

       if ((i >= sLength) || (s.charAt(i) != "@")) return false;
   	   else i += 2;

       // look for .
       while ((i < sLength) && (s.charAt(i) != "."))
        { i++
    	}

       // there must be at least one character after the .
   	   if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
       else return true;
   		}

	function isEmpty(s)
	{   return ((s == null) || (s.length == 0))
	}

	var defaultEmptyOK = false
	
	// whitespace characters
	var whitespace = " \t\n\r";

	// Returns true if string s is empty or 
	// whitespace characters only.

	function isWhitespace (s)

	{   var i;

    	// Is s empty?
	    if (isEmpty(s)) return true;

    	// Search through string's characters one by one
	    // until we find a non-whitespace character.
	    // When we do, return false; if we don't, return true.

    	for (i = 0; i < s.length; i++)
	    {   
    	    // Check that current character isn't whitespace.
	        var c = s.charAt(i);

    	    if (whitespace.indexOf(c) == -1) return false;
	    }

    	// All characters are whitespace.
    return true;
	}
	
	function checkRadios(obj,mensaje) 
	{
		for (i=0; i<obj.length; i++)
		{
			if (obj[i].checked) { return true; }
		}
		obj[0].focus();
		alert(mensaje);
		return false;
	}


	function alargar(tira,len,letra)
	{	
		for (i=tira.length; i<len; i++) { tira+=letra; }
		tira = tira.replace(/\n/g,"");
		tira = tira.replace(/\r/g,"");
		return tira;
	}
	
	function getRadioValue(obj) 
	{
		for (i=0; i<obj.length; i++)
		{
			if (obj[i].checked) { return obj[i].value; }
		}
		return null;
	}	
	
	function CCCValido(bancoIn,sucursalIn,controlIn,cuentaIn) {

        peso= new Array (6,3,7,9,10,5,8,4,2,1);
        banco = bancoIn;
        sucursal = sucursalIn;
        control = controlIn;
        cuenta =cuentaIn;

        // verifica que ningun campo sea nulo:
        if ((banco.length==0 ) || (sucursal.length==0) || (control.length == 0) || (cuenta.length == 0)) return false;

        // verifica que todos los campos sean nuericos:
        if (!EsNumerico(banco) || !EsNumerico(sucursal) || !EsNumerico(control) || !EsNumerico(cuenta)) return false;

        // filtra la CCC 0 0 0 0:
        if (parseInt(bancoIn,10) == 0  &&  parseInt(sucursalIn,10) == 0 && parseInt(controlIn,10) == 0 && parseInt(cuentaIn,10) == 0 )
                return false;

        //--- Se calcula el digito de control para el par banco-sucursal

        suma=0;
        banco_sucursal=banco+sucursal;
        longitud_banco_sucursal = banco_sucursal.length;

        for(i=0; i<longitud_banco_sucursal; i++) {
                numero = banco_sucursal.charAt(longitud_banco_sucursal-i-1);
                suma = suma + parseInt(numero,10)*peso[i];
        }

        if ((suma % 11)!=0) {
                primer_digito = 11-(suma % 11);
        } else {
                primer_digito = 0;
        }

        //--- Se calcula el dígito de control para el número de cuenta
        suma=0;
        longitud_numero_cuenta = cuenta.length;

        for(i=0; i<longitud_numero_cuenta; i++) {
                numero = cuenta.charAt(longitud_numero_cuenta-i-1);
                suma = suma + parseInt(numero,10)*peso[i];
        }

        if ((suma % 11)!=0) {
                segundo_digito = 11-(suma % 11);
        } else {
                segundo_digito = 0;
        }

        //--- Se construyen los dígitos de control

				digitos_control=String(primer_digito).charAt(0)+String(segundo_digito).charAt(0);

        //--- Se comprueba si la cuenta es correcta
        return (digitos_control==control);

}

function EsNumerico (valor) {

        return !(isNaN(valor));
}


function padLeft(len,caracter,tira)
{
	for (i=tira.length; i<len; i++) { tira=caracter+tira; }
	return tira;
}

function padRight(len,caracter,tira)
{
	for (i=tira.length; i<len; i++) { tira+=caracter; }
	return tira;
}

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
}

var daysInMonth = makeArray(12);
daysInMonth[1] = 31;
daysInMonth[2] = 29;   // must programmatically check this
daysInMonth[3] = 31;
daysInMonth[4] = 30;
daysInMonth[5] = 31;
daysInMonth[6] = 30;
daysInMonth[7] = 31;
daysInMonth[8] = 31;
daysInMonth[9] = 30;
daysInMonth[10] = 31;
daysInMonth[11] = 30;
daysInMonth[12] = 31;

function isIntegerInRange (s, a, b)
{   if (isEmpty(s)) 
       if (isIntegerInRange.arguments.length == 1) return defaultEmptyOK;
       else return (isIntegerInRange.arguments[1] == true);

    // Catch non-integer strings to avoid creating a NaN below,
    // which isn't available on JavaScript 1.0 for Windows.
    if (!isInteger(s, false)) return false;

    // Now, explicitly change the type to integer via parseInt
    // so that the comparison code below will work both on 
    // JavaScript 1.2 (which typechecks in equality comparisons)
    // and JavaScript 1.1 and before (which doesn't).
    var num = parseInt (s,10);
    return ((num >= a) && (num <= b));
}

function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}

function isInteger (s)
{   var i;

    if (isEmpty(s)) 
       if (isInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isInteger.arguments[1] == true);

    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);

        if (!isDigit(c)) return false;
    }

    // All characters are numbers.
    return true;
}

function isSignedInteger (s)
{
	if (isEmpty(s)) 
       if (isSignedInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isSignedInteger.arguments[1] == true);

    else {
        var startPos = 0;
        var secondArg = defaultEmptyOK;

        if (isSignedInteger.arguments.length > 1)
            secondArg = isSignedInteger.arguments[1];		
        // skip leading + or -
        if ( (s.charAt(0) == "-") || (s.charAt(0) == "+") )
           startPos = 1;            
        return (isInteger(s.substring(startPos, s.length), secondArg))
    }
}

function isNonnegativeInteger (s)
{   var secondArg = defaultEmptyOK;

    if (isNonnegativeInteger.arguments.length > 1)
        secondArg = isNonnegativeInteger.arguments[1];

    // The next line is a bit byzantine.  What it means is:
    // a) s must be a signed integer, AND
    // b) one of the following must be true:
    //    i)  s is empty and we are supposed to return true for
    //        empty strings
    //    ii) this is a number >= 0

    return (isSignedInteger(s, secondArg)
         && ( (isEmpty(s) && secondArg)  || (parseInt (s,10) >= 0) ) );
}

function isYear (s)
{   
	if (isEmpty(s)) 
       if (isYear.arguments.length == 1) return defaultEmptyOK;
       else return (isYear.arguments[1] == true);
    if (!isNonnegativeInteger(s)) return false;
    return ((s.length == 2) || (s.length == 4));
}

function isMonth (s)
{   if (isEmpty(s)) 
       if (isMonth.arguments.length == 1) return defaultEmptyOK;
       else return (isMonth.arguments[1] == true);
    return isIntegerInRange (s, 01, 12);
}

function isDay (s)
{   if (isEmpty(s)) 
       if (isDay.arguments.length == 1) return defaultEmptyOK;
       else return (isDay.arguments[1] == true);   
    return isIntegerInRange (s, 01, 31);
}

function daysInFebruary (year)
{   // February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (  ((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0) ) ) ? 29 : 28 );
}

function isDate (year, month, day)
{   // catch invalid years (not 2- or 4-digit) and invalid months and days.
    // Explicitly change type to integer to make code work in both
    // JavaScript 1.1 and JavaScript 1.2.
	
    var intYear = parseInt(year,10);
    var intMonth = parseInt(month,10);
    var intDay = parseInt(day,10);

    if (! (isYear(year, false) && isMonth(month, false) && isDay(day, false))) return false;

    // catch invalid days, except for February
    if (intDay > daysInMonth[intMonth]) return false; 
    if ((intMonth == 2) && (intDay > daysInFebruary(intYear))) return false;

    return true;
}

function RTrim(s){
	// Quita los espacios en blanco del final de la cadena
	var j=0;
	
	// Busca el último caracter <> de un espacio
	for(var i=s.length-1; i>-1; i--)
		if(s.substring(i,i+1) != ' '){
			j=i;
			break;
		}
	return s.substring(0, j+1);
}

function LTrim(s){
	// Devuelve una cadena sin los espacios del principio
	var i=0;
	var j=0;
	
	// Busca el primer caracter <> de un espacio
	for(i=0; i<=s.length-1; i++)
		if(s.substring(i,i+1) != ' '){
			j=i;
			break;
		}
	return s.substring(j, s.length);
}

/*function trim(s){
	// Quita los espacios del principio y del final
	return LTrim(RTrim(s));
}*/

function trim ( inputStringTrim ) {
	var sTemp;
	inputStringTrim =  new String(inputStringTrim );
	fixedTrim = "";
	lastCh = " ";
	for (x=0; x < inputStringTrim.length; x++) {
	ch = inputStringTrim.charAt(x);
	if ((ch != " ") || (lastCh != " ")) { fixedTrim += ch; }
	lastCh = ch;
	}
	if (fixedTrim.charAt(fixedTrim.length - 1) == " ") {
	fixedTrim = fixedTrim.substring(0, fixedTrim.length - 1); }
	return fixedTrim
}

function checkMaxLength(object, maxLength)
{
	var str = object.value;
	
	if (trim(str).length > maxLength)
	{
		alert("Ha sobrepasado el límite máximo de " + maxLength  + " carácteres.");
		object.value = object.value.substring(0, maxLength);
		
		return false;
	}
	
	return true;
}
