/*
   global.js
   ----------------------------
   Funzioni di utilita' comuni.
*/


/* Imposta il messaggio della status bar */
function setStatusBar(msg) {
  window.status = msg;
  return true;
}


/* Resetta il messaggio della status bar */
function resetStatusBar() {
  window.status = "";
  return true;
}

/*
   Controllo semantico.
   Verifica che una stringa rappresenti un intero positivo [0-9]+.
   Ritorna true se il valore e' numerico, false altrimenti.
*/
function isPositiveInteger(value,
                           zeroAdmitted) {
   if (value.search(/^\d+$/) == -1)
      return false;

   if (!zeroAdmitted && Number(value) == 0)
      return false;

   return true;
}

/* Funzione per switch locale */
function changeLocale(localeId) {
	var ROOT = "/html/";
	var currentLocation = location.pathname;
	var sid= currentLocation.indexOf(ROOT);
	var newLocation = currentLocation.substr(0, sid + ROOT.length)
									+ localeId
									+ currentLocation.substring(sid + ROOT.length + localeId.length)
	location.href = newLocation;
}

/*
  Formatta una data secondo il formato DD/MM/YYYY.
*/
function formatDateAsDDMMYYYY(date) {
   /* Se data non specificata si ritorna */
   if (date == null)
      return date;

   /* Suddivisione campi data */
   var fields = new Array();
   fields[0] = new String(date.getDate());
   fields[1] = new String(date.getMonth() + 1);
   fields[2] = new String(date.getFullYear());

   /* Normalizzazione giorno */
   if (fields[0].length == 1)
      fields[0] = "0" + fields[0];

   /* Normalizzazione mese */
   if (fields[1].length == 1)
      fields[1] = "0" + fields[1];

   /* Merge campi */
   return fields.join("/");
}