// Costanti generali
  ico_ok = "../img/ico/ok.gif";
  ico_cancel = "../img/ico/cancel.gif";
  
  only_num = new Array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9');
  invalid_sql_inj = new Array('\'', '&', '!', '=', '\"', ';', '`', '*', '(', ')', '[', ']');
  invalid_email = new Array(' ', '!', '\"', '#', '$', '%', '&', '\'', '(', ')', '*', ',', ':', ';', '<', '=', '>', '?', '[', ']','\\', '`',  '{', '}', '|');
  
function checkDate2(year, month, day) {
}

function checkDate(value) {
  nDate = Date.parseDate(value, 'd/m/Y');
  if (nDate != null) {
    return new Date(nDate);
  }
  return null;
}

function checkDateTime(value) {
  if (value.indexOf(' ')==-1) {
	  nDate = Date.parseDate(value, 'd/m/Y');	
  }
  else nDate = Date.parseDate(value, "d/m/Y H.i");
  if (nDate != null) {
    return new Date(nDate);
  }
  return null;
}

function checkInvalidChars(value, invalidchars) {
  l_value = value.toLowerCase();
  for (var i=0; i<invalidchars.length; i++) {
   if (l_value.indexOf(invalidchars[i])>-1) return true;
  }
  return false;
}

function checkValidChars(value, validchars) {
  l_value = value.toLowerCase();
  for (var i=0; i<l_value.length; i++) {
   var is_valid = false;
   cur_char = l_value.charAt(i);
   for (var k=0; k<validchars.length; k++) { 
     is_valid = (cur_char==validchars[k]);
     if (is_valid) break;
   }
   if (!is_valid) return false;
  }
  return true;
}

function checkEmail(value){
  result = !checkInvalidChars(value, invalid_email);
  if (result) {
	posAt = value.indexOf('@');
	posDot = value.lastIndexOf('.');
	result = (posAt<(value.length-1)) && (posDot<(value.length-1)) && (posAt>0) && (posDot>0) && (posDot>posAt);
  }	  
  return result;	
}

function checkData_Login() {
 if (document.FormLogin) { 
  is_ok_username = ((document.FormLogin.username.value!='') && !(checkInvalidChars(document.FormLogin.username.value, invalid_sql_inj)));
  is_ok_passwd = ((document.FormLogin.passwd.value!='') && !(checkInvalidChars(document.FormLogin.passwd.value, invalid_sql_inj)));
  is_ok = is_ok_username && is_ok_passwd;
  
  if (is_ok_username) document.username_check.src = ico_ok; else document.username_check.src = ico_cancel;
  if (is_ok_passwd) document.passwd_check.src = ico_ok; else document.passwd_check.src = ico_cancel;
  
  document.FormLogin.Entra.disabled = (!is_ok); document.FormLogin.Entra.style.color = (is_ok ? "#102169" : "#d9d8d7");
 }
}  