function SoloNumeros(Nombre)
{
var checkOK = "0123456789";
var checkStr = Nombre.value;
var allValid = true;
for (i = 0;  i < Nombre.length;i++){
ch = Nombre.charAt(i);
for (j = 0;  j < checkOK.length;j++)
if (ch == checkOK.charAt(j)) break;
if (j == checkOK.length) { allValid = false;  break;}}
if (!allValid) return (false);
return (true);
}


function SoloLetras(Nombre)
{
var checkOK = "ABDCEFGHIJKLRMNÑOPQRSTUVWXYZabcdefghijklmnñopqrstuvwxyzáéíóúÁÉÍÓÚ- ";
var checkStr = Nombre.value;
var allValid = true;
for (i = 0;  i < Nombre.length;i++){
ch = Nombre.charAt(i);
for (j = 0;  j < checkOK.length;j++)
if (ch == checkOK.charAt(j)) break;
if (j == checkOK.length) { allValid = false;  break;}}
if (!allValid) return (false);
return (true);
}


function RevisaRUT(RUT) 
{
var ceros = "0000000000000";
var checkOK = "0123456789--Kk";
var checkStr = RUT.value;
var allValid = true;
var txtlargo = 0;
var txtprincip = "1234567890123";
var txtdigitover = "x";
var txtrut = "1234567890123-5";
txtlargo = RUT.length;
if (txtlargo<3) return(false);
if (txtlargo>15) return(false);
txtprincip = RUT.substr(0,txtlargo-2);
txtdigitover = RUT.substr(txtlargo-1,1);
txtdigitover.toUpperCase();
for (i = 0;  i < RUT.length;  i++) {
ch = RUT.charAt(i);
for (j = 0;  j < checkOK.length;  j++)
if (ch == checkOK.charAt(j)) break;
if (j == checkOK.length) { allValid = false;  break;}}
if (!allValid) return (false);
txtrut = ceros.substr(0,txtrut.length-txtlargo) + RUT;
var  Suma = 0
var  Aux = "8765432765432"
var digitos = "123456789K0"
for ( i=0 ; i<13 ; i++)  {
Suma = Suma + Number(txtrut.substr(i,1)) * Number(Aux.substr(i,1));}
Dig = digitos.substr(11 - (Suma % 11) - 1, 1)
if (Dig != txtdigitover.toUpperCase()) return (false);
return (true);
}


function RevisaFecha(Fecha, FechaMin, FechaMax) {
numdia = 0;
nummes = 0;
numano = 0;
mindia = 0;
minmes = 0;
minano = 0;
maxdia = 0;
maxmes = 0;
maxano = 0;
res = true;
if (Fecha.length!=10)  return (false);
numdia = Fecha.substr(0,2);
nummes = Fecha.substr(3,2);
numano = Fecha.substr(6,4);
mindia = FechaMin.substr(0,2);
minmes = FechaMin.substr(3,2);
minano = FechaMin.substr(6,4);
maxdia = FechaMax.substr(0,2);
maxmes = FechaMax.substr(3,2);
maxano = FechaMax.substr(6,4);
if( (numdia<1) || (numdia>31) ) return (false);
if( (nummes<1) || (nummes>12) ) return (false);
if (nummes == 1) { if (numdia>31) return (false); }
if (nummes == 2) { if (numdia>29) return (false); }
if (nummes == 3) { if (numdia>31) return (false); }
if (nummes == 4) { if (numdia>30) return (false); }
if (nummes == 5) { if (numdia>31) return (false); }
if (nummes == 6) { if (numdia>30) return (false); }
if (nummes == 7) { if (numdia>31) return (false); }
if (nummes == 8) { if (numdia>31) return (false); }
if (nummes == 9) { if (numdia>30) return (false); }
if (nummes == 10) { if (numdia>31) return (false); }
if (nummes == 11) { if (numdia>30) return (false); }
if (nummes == 12) { if (numdia>31) return (false); }
if (nummes == 2) { if ((numdia==29) && (numano%4)!=0)  return (false); }
if( minano>numano ) return (false);
if( numano == minano ) {
if( minmes>nummes ) return (false);
if( (nummes==minmes) && (mindia>numdia) ) return (false);}
if( numano>maxano ) return (false);
if( numano == maxano ) {
if( nummes>maxmes ) return (false);
if( (nummes==maxmes) && (numdia>maxdia) ) return (false);
}return (true);}


function RevisaHora(Hora)
{
var checkOK = "0123456789:";
var checkStr = Hora.value;
var allValid = true;
hora = Hora.substr(0,2);
dospuntos = Hora.substr(2,1);
minutos = Hora.substr(3,2);
if(hora<1||hora>23)
return (false);
if(dospuntos!=":"||minutos>59)
return (false);   
for (i = 0;  i < Hora.length;i++){
ch = Hora.charAt(i);
for (j = 0;  j < checkOK.length;j++)
if (ch == checkOK.charAt(j)) break;
if (j == checkOK.length) { allValid = false;  break;}}
if (!allValid) return (false);
return (true);
}

function RevisaEmail(Email)
{   var goodEmail = Email.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
if (!goodEmail)
	return false;

return true;
}


/**
 * This array is used to remember mark status of rows in browse mode
 */
var marked_row = new Array;
/**
 * Sets/unsets the pointer and marker in browse mode
 *
 * @param   object    the table row
 * @param   integer  the row number
 * @param   string    the action calling this script (over, out or click)
 * @param   string    the default background color
 * @param   string    the color to use for mouseover
 * @param   string    the color to use for marking a row
 *
 * @return  boolean  whether pointer is set or not
 */
function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
    var theCells = null;

    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    // 3.2 ... with other browsers
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    } // end 3

    // 3.3 ... Opera changes colors set via HTML to rgb(r,g,b) format so fix it
    if (currentColor.indexOf("rgb") >= 0)
    {
        var rgbStr = currentColor.slice(currentColor.indexOf('(') + 1,
                                     currentColor.indexOf(')'));
        var rgbValues = rgbStr.split(",");
        currentColor = "#";
        var hexChars = "0123456789ABCDEF";
        for (var i = 0; i < 3; i++)
        {
            var v = rgbValues[i].valueOf();
            currentColor += hexChars.charAt(v/16) + hexChars.charAt(v%16);
        }
    }

    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == ''
        || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor              = thePointerColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
            // Garvin: deactivated onclick marking of the checkbox because it's also executed
            // when an action (like edit/delete) on a single item is performed. Then the checkbox
            // would get deactived, even though we need it activated. Maybe there is a way
            // to detect if the row was clicked, and not an item therein...
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = true;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
             && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
        if (theAction == 'out') {
            newColor              = theDefaultColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = true;
        }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor              = (thePointerColor != '')
                                  ? thePointerColor
                                  : theDefaultColor;
            marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
                                  ? true
                                  : null;
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = false;
        }
    } // end 4

    // 5. Sets the new color...
    if (newColor) {
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    } // end 5

    return true;
} // end of the 'setPointer()' function


/**
 * Checks/unchecks all rows
 *
 * @param   string   the form name
 * @param   boolean  whether to check or to uncheck the element
 * @param   string   basename of the element
 * @param   integer  min element count
 * @param   integer  max element count
 *
 * @return  boolean  always true
 */
// modified 2004-05-08 by Michael Keck <mail_at_michaelkeck_dot_de>
// - set the other checkboxes (if available) too
function setCheckboxesRange(the_form, do_check, basename, min, max)
{
	if(document.forms[the_form].CheckAll.checked==true){ do_check=true;}else{ do_check=false;}
	for (var i = min; i < max; i++) {
        if (typeof(document.forms[the_form].elements[basename + i]) != 'undefined') {
            document.forms[the_form].elements[basename + i].checked = do_check;
        }
        if (typeof(document.forms[the_form].elements[basename + i + 'r']) != 'undefined') {
            document.forms[the_form].elements[basename + i + 'r'].checked = do_check;
        }
    }

    return true;
} // end of the 'setCheckboxesRange()' function

