
// whitespace characters
var whitespace = " \t\n\r";
var defaultEmptyOK = false;

function Vacio(s)
{
    //return ((s == null) || (s.length == 0))
    return (s==null || (s.length == 0))
}

function Fecha(dateStr)
{
// Checks for the following valid date formats:
// MM/DD/YY   MM/DD/YYYY   MM-DD-YY   MM-DD-YYYY
// Also separates date into month, day, and year variables

var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;

// To require a 4 digit year entry, use this line instead:
// var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;

var matchArray = dateStr.match(datePat); // is the format ok?
if (matchArray == null) {
return false;
}
month = matchArray[3]; // parse date into variables
day = matchArray[1];
year = matchArray[4];
if (month < 1 || month > 12) { // check month range
alert("El mes debe estar entre 1 y 12.");
return false;
}
if (day < 1 || day > 31) {
alert("El día debe estar entre 1 y 31.");
return false;
}
if ((month==4 || month==6 || month==9 || month==11) && day==31) {
alert("El mes "+month+" no tiene 31 dias!")
return false
}
if (month == 2) { // check for february 29th
var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
if (day>29 || (day==29 && !isleap)) {
alert("Febrero de " + year + " no tiene " + day + " dias!");
return false;
   }
}
return true;  // date is valid
}


/****************************************************************/

// Returns true if string s is empty or 
// whitespace characters only.

function EnBlanco(s)

{   var i;
    //if (s==null) return true;
    if (s=="") return true;
    // Is s empty?
    if (Vacio(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 esFichero()
/*  Devuelve true si el Fichero tiene la extensión que se pasa como parámetro
     Devuelve false en cualquier otro caso */
{
    var cadena,res,extensiones,i;

    extensiones = esFichero.arguments;
    cadena = extensiones[0];
    cadena = cadena.toUpperCase();
    res = false;
    for (i=1;i < extensiones.length; i++)
    {
        if (cadena.indexOf("."+ extensiones[i]) != -1 )
        {
            res = true;
        }
    }
    return (res);
}

function EsURL(s)

{   var i;
     if (s=="") return true;
    // Is s empty?
    if (Vacio(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.

    //La dirección URL debe contener la cadena http://
    if(s.indexOf("http://") == -1) return false;

    //La dirección URL debe comenzar con la cadena http://
    if(s.indexOf("http://") !=0) return false;

    // All characters are whitespace.
    return true;
}

//Comprueba si la cadena pasada se corresponde con una dirección válida de correo electrónico
function Email(s)
{
    if (Vacio(s))
       if (Email.arguments.length == 1) return defaultEmptyOK;
       else return (Email.arguments[1] == true);

    // is s whitespace?
    if (EnBlanco(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 testHTML(strTexto)
{
  var badStuff=new Array("IFRAME","SCRIPT","LAYER","ILAYER","OBJECT","APPLET","EMBED","FORM","INPUT","BUTTON","TEXTAREA"),hasStuff=new Array(),i=0
  for (i=0;i<badStuff.length;i++)
  {
    if (strTexto.toUpperCase().lastIndexOf(badStuff[i])>0)
    {
      hasStuff[hasStuff.length]=badStuff[i];
    }
  }
  var str=""
  if (hasStuff.length>0) {
    str="* Por favor elimine las siguientes etiquetas HTML y vuelva a darle a enviar:"
    for (i=0;i<hasStuff.length;i++)
       str+="\n - "+hasStuff[i]
  }
  return str
}


