/**
 * Ritorna TRUE se il campo passato come argomento non contiene alcun valore,
 * FALSE altrimenti.
 */
function isEmpty(aTextField) {
  if ((aTextField.value.length==0) || (aTextField.value==null)) {
    return true;
  } else { return false; }
}

/**
 * Ritorna TRUE se la stringa passata come argomento rappresenta un numero,
 * FALSE altrimenti.
 */
function isNumeric(sText) {
  var ValidChars = "0123456789.";
  var IsNumber=true;
  var Char;
  
  for (i = 0; i < sText.value.length && IsNumber == true; i++)  { 
    Char = sText.value.charAt(i); 
    if (ValidChars.indexOf(Char) == -1) {
      IsNumber = false;
    }
  }
  return IsNumber;
}

/**
 * Ritorna TRUE se la stringa passata come argomento rappresenta un
 * indirizzo email valido dal punto di vista semantico, FALSE altrimenti.
 */
function isValidEmail(string) {
  if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
    return true;
  else
    return false;
}

/**
 * Ritorna TRUE se la data passata come primo argomento è valida ed è nel
 * formato dd/mm/yyyy, dove dd rappresenta il giorno a due cifre, mm il mese
 * a due cifre, yyyy l'anno a quattro cifre, '/' il carattere di separazione
 * passato come secondo argomento, FALSE altrimenti.
 */ 
function isValidDate(str, sep) {
  if (str.length == 10) {
    if (str.substring(2,3) == sep && str.substring(5,6) == sep) {
      var date  = str.substring(0,2);
      var month = str.substring(3,5);
      var year  = str.substring(6,10);
      var test = new Date(year,month-1,date);

      if (year == (test.getYear()<1000 ? test.getYear()+1900 : test.getYear()) && (month-1 == test.getMonth()) && (date == test.getDate())) {
        return true;
      } else {
        return false;
      }
    } else {
      return false;
    }
  } else {
    return false;
  }
}

function timestampDate(data_iniziale){
  var arr1 = data_iniziale.split('-');

  var d1 = new Date(arr1[2],arr1[1]-1,arr1[0]);

  var r1 = d1.getTime();

  return r1;
}

/**
 * Ritorna TRUE se la lunghezza del contenuto del campo passato come primo argomento
 * supera la dimensione massima passata come secondo argomento, FALSE altrimenti.
 */
function maxLength(textField, maxVal) {
  if(textField.value.length > maxVal) {
      return true;
    } else { 
    return false; 
  } 
}