<!--
/*       Copyright (C) Dynamica S.r.l. 2001-2002.

         Le informazioni, il formato e la sintassi di questo modulo
         sono  di proprieta' della  Dynamica S.r.l. che ne conserva
         tutti i diritti ai sensi della corrente normativa Italiana
         sul diritto d'autore.
         La  Dynamica  S.r.l.  non  si  fa carico  di  anomalie  da
         malfunzionamento dei propri programmi dovute a alterazioni
         e/o aggiunte apportate a questo file.

         The information in this file is provided for the exclusive use of
         the licensees of Dynamica s.r.l..  Such users have the
         right to use and  modify this code provided that it is used
         exclusively with Dynamica's products and for purposes authorized
         by the license agreement provided they include this notice and
         the associated copyright notice with any such product.
         The information in this file is provided "AS IS" without warranty.

         Dynamica S.r.l. Milano, 2001-2002.
*/

var demone_blocco = null;
var demone_status = null;
var demone_sound = null;

var dyna_exec_str = null;

var xmlHttp;

/* var GG_MESE=new Array(31,28,31,30,31,30,31,31,30,31,30,31); */
function isleap(year) {
   if (year > 1582) 
      return ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0);
   else {
      if (year < 0)                     /* L'anno 0 non esiste, */
         year++;                        /* la continuita' dei bisestili si. */
      return ((((year%4)+4)%4) == 0);
      }
   }

function stop_demoni() {
   if (demone_blocco != null)
      clearInterval(demone_blocco);
   if (demone_status != null)
      clearInterval(demone_status);
   }

function stampa_pagina() {
   var nav=brw();
   if (nav == "IE7" || nav == "IE6" || nav == "IE5") {
      var WebBrowser='<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
      document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
      WebBrowser1.ExecWB(6, 2);
      WebBrowser1.outerHTML = "";  
      }
   else
      self.print();
   }

function dyna_scanner(gsid,terminale,nomeform,nomemenu) {
   sele=document.forms[nomeform].elements[nomemenu];
   quale=sele[sele.selectedIndex].value;
   buf=proxy_js+'scanner.php?G_SID='+gsid+'&quale='+quale+'&terminale='+terminale;
   var w=window.open(buf,'DYNA_SCANNER','toolbar=no,menubar=no,scrollbars=yes,statusbar=no,height=10,width=10,setResizable=yes,dependent=yes');
   w.focus();
   }

/* individua il tipo di browser */
function brw(){ 
   if(document.all){
      if(navigator.appVersion.charAt(22)==7)
         var nav="IE7";
      else if(navigator.appVersion.charAt(22)==6)
         var nav="IE6";
      else
         var nav="IE5";
      }
   else{
      version=navigator.appVersion.charAt(0);
      var nav="N"+version;
      }
   return nav;
   }

/* definisce il metodo per raggiungere l'oggetto "document" */
function dcto(){ 
   switch(brw()){
    case "IE7":
    case "IE6":
    case "IE5":
      doc=document.all;
      break;
    case "N4":
    case "N5":
      doc=document;
      break;
     }
   }

/* definisce il percorso per raggiungere un "div" */
function myobjs(obj_name){
   dcto();
   switch(brw()){
    case "N5":
      return(doc.getElementById(obj_name).style);
      break;
    case "IE7":
    case "IE6":
    case "IE5":
      return(doc[obj_name].style);
      break;
    case "N4":
      return(doc[obj_name]);
      break;
      }
   }    

/* scrive dati in una form */
function store_dat(form_name, field_name, val, rval){
   fts=document.forms[form_name].elements[field_name];
   vts=(rval!="") ? read_dat(form_name, rval) : val;
   fts.value=vts;
   }

/* legge dati da una form */
function read_dat(form_name, field_name){
   ffr=document.forms[form_name].elements[field_name];
   return ffr.value;
   }

/* muove il div passato come parametro */
function move_obj(obj_name, x_pos, y_pos){
   var ogg=xbGetElementById(obj_name);
   var oggstyle=new xbStyle(ogg);
   ogg.moveTo(x_pos, y_pos);  
   }

/* definisce la chiamata esatta per controllare lo scrolling verticale del
   browser */
function scroll_y(){ 
   switch(navigator.family){
    case "ie4":
    case "ie3":
      return(document.body.scrollTop);
      break;
    case "nn4":
      return(window.pageYOffset);
      break;
    case "gecko":
      return(window.scrollY);
      break;
      }
   } 

/* "ripulisce" la stringa passata sostituendo i caratteri speciali con 
    codici esadecimali */
function url_encode(str){

   var retstr="";
   if(str.length == 0) 
      return retstr;
   for(var i=0;i < str.length;i++){
      switch(str.charAt(i)){
       case " ":
         retstr+="%20";
         break;
       case "&":
         retstr+="%26";
         break;
       case "=":
         retstr+="%3d";
         break;
       case ":":
         retstr+="%3a";
         break;
       case ";":
         retstr+="%3b";
         break;
       case "+":
         retstr+="%2b";
         break;
       case "/":
         retstr+="%2f";
         break;
       case "\n":
         retstr+="%0a";
         break;
       default:
         retstr+=str.charAt(i);
         }
      }
    return retstr;
   }    

/* popup generico */
function popup_generale(pagina) {
   var pup=window.open(pagina,'DYNA_GEN_UP','toolbar=no,menubar=no,scrollbars=yes,statusbar=no,height=10,width=10,setResizable=yes,dependent=yes');
   pup.focus();
   return true;
   }

/* popup generico */
function popup_fixed(pagina) {
   var pup=window.open(pagina,'DYNA_FIX_UP','toolbar=no,menubar=no,scrollbars=no,statusbar=no,height=10,width=10,setResizable=no,dependent=yes');
   pup.focus();
   return true;
   }

/* popup homepage */
function popup_home(pagina,x,y) {
   var pup=window.open(pagina,'DYNA_HOME_POP','toolbar=no,menubar=no,scrollbars=no,statusbar=no,height='+y+',width='+x+',setResizable=no,dependent=yes');
   pup.focus();
   return true;
   }

/* usato da minibrow */
function popup_sql(table,codi,desc,form,campo,filtro,gsid) {
   var pagina=proxy_js+"minibrow.php?J_table="+table+"&J_codi="+codi+"&J_desc="+desc+"&J_form="+form+"&J_field="+campo+"&J_filter="+filtro+"&G_SID="+gsid;
   var pup=window.open(pagina,'DYNA_POP_UP','toolbar=no,menubar=no,scrollbars=yes,statusbar=no,height=10,width=10,setResizable=yes,dependent=yes');
   pup.focus();
   return true;
   }

/* usato da minibrow2 */
function popup_search(table,form,campo,filtro,gsid) {
   var pagina=proxy_js+"minibrow2.php?J_table="+table+"&J_form="+form+"&J_field="+campo+"&J_filter="+filtro+"&G_SID="+gsid;
   var pup=window.open(pagina,'DYNA_POP_UP','toolbar=no,menubar=no,scrollbars=yes,statusbar=no,height=10,width=10,setResizable=yes,dependent=yes');
   pup.focus();
   return true;
   }

/* usato da unicode */
function popup_unicode(form,campo,nome,gsid) {
   var pagina=proxy_js+"unicode.php?J_form="+form+"&J_field="+campo+"&G_SID="+gsid+"&J_nome="+nome;
   var pup=window.open(pagina,'DYNA_UNICODE','toolbar=no,menubar=no,scrollbars=yes,statusbar=no,height=10,width=10,setResizable=yes,dependent=yes');
   pup.focus();
   return true;
   }

/* per bottoni bloccati */
function auto_submit(nome,myform) {
   document.forms[myform].elements['AREA_BOTTONI2'].name=nome;
   document.getElementById(myform).submit();
   }

function insert_areatext(nomeform,nomemenu,nomearea) {
   area=document.forms[nomeform].elements[nomearea];
   sele=document.forms[nomeform].elements[nomemenu];
   area.value=area.value+sele[sele.selectedIndex].value;
   }

/* toglie simbolo html per quote; funziona senza fare nulla... */
function special_quote(s) {
   return (s);
   }

var img_buffer = new Array();
var loop_roll = new Array();
var semaforo = new Array();

function img_load(filename) {
   var i = img_buffer.length;

   img_buffer[i] = new Image();
   img_buffer[i].src = filename;
   }

function preload() {
   for(var i=0; i < preload.arguments.length; i++)
      img_load(preload.arguments[i]);
   }

function rollloop(dove,offset,quante,indice,tempo) {
   semaforo[dove]=1;
   if (loop_roll[dove] == 1) {
      img_show(dove, img_buffer[indice+offset].src);
      indice = (indice + 1) % quante;
      var chiamata='rollloop("'+dove+'",'+offset+','+quante+','+indice+','+tempo+')';
      window.setTimeout(chiamata, tempo);
      }
   semaforo[dove]=0;
   }

function img_show(nome,filename) {
   document.images[nome].src = filename;
   }

function chiudi_roll(dove,come) {
   loop_roll[dove] = 0;
   while (semaforo[dove] == 1);
   img_show(dove,come);
   }

function blocca_bottoni() {
   var myobj=xbGetElementById('area_bottoni');
   var mystyle=new xbStyle(myobj);

   if(init_pos != scroll_y())
      mystyle.moveTo(init_posx,scroll_y()+start_pos);
   init_pos=scroll_y();
   if(demone_blocco != null){
      clearInterval(demone_blocco);
      demone_blocco=null;
      }
   demone_blocco = setInterval("blocca_bottoni()",400);
   }

function pulisci_url() {
   status_pos++;
   var scroller="";

   if (status_velox < 0)
      window.status = status_testo;
   else {      
      if (status_pos==status_len)
         status_pos=1-status_width;
      if (status_pos<0) {
         for (var i=1; i<=Math.abs(status_pos); i++) {
            scroller=scroller+" ";}
            scroller=scroller+status_testo.substring(0,status_width-i+1);
         }
      else
         scroller=scroller+status_testo.substring(status_pos,status_width+status_pos);
      window.status = scroller;
      }
   }

if (status_velox != 0) {
   if (status_velox < 0)
      demone_status=setInterval('pulisci_url()',-status_velox);
   else
      demone_status=setInterval('pulisci_url()',status_velox);
   }

function view_table(gsid) {
   // rendere generale read_data per le select
   nometable=document.getElementById('query_form').qualetable[document.getElementById('query_form').qualetable.selectedIndex].value;
   var pagina=proxy_js+"database.php?query="+2+"&G_SID="+gsid+"&table_name="+nometable;
   var pup=window.open(pagina,'DYNA_POP_'+nometable,
                       'toolbar=no,menubar=no,scrollbars=yes,statusbar=no,height=10,width=10,setResizable=yes,dependent=yes');
   pup.focus();
   return true;
   }

function selez_all(nomeform,campoctrl){
   lunghezza=(brw()!="IE6" && brw()!="IE7") ? document.forms[nomeform].elements.length : document.forms[nomeform].length;
   controllo=document.forms[nomeform].elements[campoctrl];
   if(controllo.value==1)
      stato=1;
   else 
      stato=0;
   for(i=0;i < lunghezza;i++)
        document.forms[nomeform].elements[i].checked=stato;
   if(stato)
     controllo.value=0;
   else
   controllo.value=1;
   }

function play_sound(giro,ind){
        
   if (giro!='')
      demone_sound=setInterval('play_sound("",0)',eval(giro)*1000);
   else {
      document.getElementById('frameSound').src=play_sound_url[ind];
      if (ind<eval(play_sound_time.length)-1) {
         clearInterval(demone_sound);
         demone_sound=null;
         newind=eval(ind)+1;
         demone_sound=setInterval('play_sound("","'+newind+'")',eval(play_sound_time[ind])*1000);
         }
      else {
         clearInterval(demone_sound);
         demone_sound=null;
         }
      }
   }

var hexcase = 0;  /* hex output format. 0 - lowercase; 1 - uppercase        */
var b64pad  = ""; /* base-64 pad character. "=" for strict RFC compliance   */
var chrsz   = 8;  /* bits per input character. 8 - ASCII; 16 - Unicode      */

/*
 * These are the functions you'll usually want to call
 * They take string arguments and return either hex or base-64 encoded strings
 */

function hex_md5(s){
   if (s.length == 32)
      return (s);
   return binl2hex(core_md5(str2binl(s), s.length * chrsz));
   }

function hex_md5_clean(s){
   return binl2hex(core_md5(str2binl(s), s.length * chrsz));
   }
function b64_md5(s){ return binl2b64(core_md5(str2binl(s), s.length * chrsz));}
function str_md5(s){ return binl2str(core_md5(str2binl(s), s.length * chrsz));}
function hex_hmac_md5(key, data) { return binl2hex(core_hmac_md5(key, data)); }
function b64_hmac_md5(key, data) { return binl2b64(core_hmac_md5(key, data)); }
function str_hmac_md5(key, data) { return binl2str(core_hmac_md5(key, data)); }

/*
 * Perform a simple self-test to see if the VM is working
 */
function md5_vm_test() {
  return hex_md5("abc") == "900150983cd24fb0d6963f7d28e17f72";
  }

/*
 * Calculate the MD5 of an array of little-endian words, and a bit length
 */
function core_md5(x, len) {
  /* append padding */
  x[len >> 5] |= 0x80 << ((len) % 32);
  x[(((len + 64) >>> 9) << 4) + 14] = len;

  var a =  1732584193;
  var b = -271733879;
  var c = -1732584194;
  var d =  271733878;

  for(var i = 0; i < x.length; i += 16) {
    var olda = a;
    var oldb = b;
    var oldc = c;
    var oldd = d;

    a = md5_ff(a, b, c, d, x[i+ 0], 7 , -680876936);
    d = md5_ff(d, a, b, c, x[i+ 1], 12, -389564586);
    c = md5_ff(c, d, a, b, x[i+ 2], 17,  606105819);
    b = md5_ff(b, c, d, a, x[i+ 3], 22, -1044525330);
    a = md5_ff(a, b, c, d, x[i+ 4], 7 , -176418897);
    d = md5_ff(d, a, b, c, x[i+ 5], 12,  1200080426);
    c = md5_ff(c, d, a, b, x[i+ 6], 17, -1473231341);
    b = md5_ff(b, c, d, a, x[i+ 7], 22, -45705983);
    a = md5_ff(a, b, c, d, x[i+ 8], 7 ,  1770035416);
    d = md5_ff(d, a, b, c, x[i+ 9], 12, -1958414417);
    c = md5_ff(c, d, a, b, x[i+10], 17, -42063);
    b = md5_ff(b, c, d, a, x[i+11], 22, -1990404162);
    a = md5_ff(a, b, c, d, x[i+12], 7 ,  1804603682);
    d = md5_ff(d, a, b, c, x[i+13], 12, -40341101);
    c = md5_ff(c, d, a, b, x[i+14], 17, -1502002290);
    b = md5_ff(b, c, d, a, x[i+15], 22,  1236535329);

    a = md5_gg(a, b, c, d, x[i+ 1], 5 , -165796510);
    d = md5_gg(d, a, b, c, x[i+ 6], 9 , -1069501632);
    c = md5_gg(c, d, a, b, x[i+11], 14,  643717713);
    b = md5_gg(b, c, d, a, x[i+ 0], 20, -373897302);
    a = md5_gg(a, b, c, d, x[i+ 5], 5 , -701558691);
    d = md5_gg(d, a, b, c, x[i+10], 9 ,  38016083);
    c = md5_gg(c, d, a, b, x[i+15], 14, -660478335);
    b = md5_gg(b, c, d, a, x[i+ 4], 20, -405537848);
    a = md5_gg(a, b, c, d, x[i+ 9], 5 ,  568446438);
    d = md5_gg(d, a, b, c, x[i+14], 9 , -1019803690);
    c = md5_gg(c, d, a, b, x[i+ 3], 14, -187363961);
    b = md5_gg(b, c, d, a, x[i+ 8], 20,  1163531501);
    a = md5_gg(a, b, c, d, x[i+13], 5 , -1444681467);
    d = md5_gg(d, a, b, c, x[i+ 2], 9 , -51403784);
    c = md5_gg(c, d, a, b, x[i+ 7], 14,  1735328473);
    b = md5_gg(b, c, d, a, x[i+12], 20, -1926607734);

    a = md5_hh(a, b, c, d, x[i+ 5], 4 , -378558);
    d = md5_hh(d, a, b, c, x[i+ 8], 11, -2022574463);
    c = md5_hh(c, d, a, b, x[i+11], 16,  1839030562);
    b = md5_hh(b, c, d, a, x[i+14], 23, -35309556);
    a = md5_hh(a, b, c, d, x[i+ 1], 4 , -1530992060);
    d = md5_hh(d, a, b, c, x[i+ 4], 11,  1272893353);
    c = md5_hh(c, d, a, b, x[i+ 7], 16, -155497632);
    b = md5_hh(b, c, d, a, x[i+10], 23, -1094730640);
    a = md5_hh(a, b, c, d, x[i+13], 4 ,  681279174);
    d = md5_hh(d, a, b, c, x[i+ 0], 11, -358537222);
    c = md5_hh(c, d, a, b, x[i+ 3], 16, -722521979);
    b = md5_hh(b, c, d, a, x[i+ 6], 23,  76029189);
    a = md5_hh(a, b, c, d, x[i+ 9], 4 , -640364487);
    d = md5_hh(d, a, b, c, x[i+12], 11, -421815835);
    c = md5_hh(c, d, a, b, x[i+15], 16,  530742520);
    b = md5_hh(b, c, d, a, x[i+ 2], 23, -995338651);

    a = md5_ii(a, b, c, d, x[i+ 0], 6 , -198630844);
    d = md5_ii(d, a, b, c, x[i+ 7], 10,  1126891415);
    c = md5_ii(c, d, a, b, x[i+14], 15, -1416354905);
    b = md5_ii(b, c, d, a, x[i+ 5], 21, -57434055);
    a = md5_ii(a, b, c, d, x[i+12], 6 ,  1700485571);
    d = md5_ii(d, a, b, c, x[i+ 3], 10, -1894986606);
    c = md5_ii(c, d, a, b, x[i+10], 15, -1051523);
    b = md5_ii(b, c, d, a, x[i+ 1], 21, -2054922799);
    a = md5_ii(a, b, c, d, x[i+ 8], 6 ,  1873313359);
    d = md5_ii(d, a, b, c, x[i+15], 10, -30611744);
    c = md5_ii(c, d, a, b, x[i+ 6], 15, -1560198380);
    b = md5_ii(b, c, d, a, x[i+13], 21,  1309151649);
    a = md5_ii(a, b, c, d, x[i+ 4], 6 , -145523070);
    d = md5_ii(d, a, b, c, x[i+11], 10, -1120210379);
    c = md5_ii(c, d, a, b, x[i+ 2], 15,  718787259);
    b = md5_ii(b, c, d, a, x[i+ 9], 21, -343485551);

    a = safe_add(a, olda);
    b = safe_add(b, oldb);
    c = safe_add(c, oldc);
    d = safe_add(d, oldd);
  }
  return Array(a, b, c, d);

}

/*
 * These functions implement the four basic operations the algorithm uses.
 */
function md5_cmn(q, a, b, x, s, t) {
  return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s),b);
}
function md5_ff(a, b, c, d, x, s, t) {
  return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t);
}
function md5_gg(a, b, c, d, x, s, t) {
  return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t);
}
function md5_hh(a, b, c, d, x, s, t) {
  return md5_cmn(b ^ c ^ d, a, b, x, s, t);
}
function md5_ii(a, b, c, d, x, s, t) {
  return md5_cmn(c ^ (b | (~d)), a, b, x, s, t);
}

/*
 * Calculate the HMAC-MD5, of a key and some data
 */
function core_hmac_md5(key, data) {
  var bkey = str2binl(key);
  if(bkey.length > 16) bkey = core_md5(bkey, key.length * chrsz);

  var ipad = Array(16), opad = Array(16);
  for(var i = 0; i < 16; i++)
  {
    ipad[i] = bkey[i] ^ 0x36363636;
    opad[i] = bkey[i] ^ 0x5C5C5C5C;
  }

  var hash = core_md5(ipad.concat(str2binl(data)), 512 + data.length * chrsz);
  return core_md5(opad.concat(hash), 512 + 128);
}

/*
 * Add integers, wrapping at 2^32. This uses 16-bit operations internally
 * to work around bugs in some JS interpreters.
 */
function safe_add(x, y) {
  var lsw = (x & 0xFFFF) + (y & 0xFFFF);
  var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
  return (msw << 16) | (lsw & 0xFFFF);
}

/*
 * Bitwise rotate a 32-bit number to the left.
 */
function bit_rol(num, cnt) {
  return (num << cnt) | (num >>> (32 - cnt));
}

/*
 * Convert a string to an array of little-endian words
 * If chrsz is ASCII, characters >255 have their hi-byte silently ignored.
 */
function str2binl(str) {
  var bin = Array();
  var mask = (1 << chrsz) - 1;
  for(var i = 0; i < str.length * chrsz; i += chrsz)
    bin[i>>5] |= (str.charCodeAt(i / chrsz) & mask) << (i%32);
  return bin;
}

/*
 * Convert an array of little-endian words to a string
 */
function binl2str(bin) {
  var str = "";
  var mask = (1 << chrsz) - 1;
  for(var i = 0; i < bin.length * 32; i += chrsz)
    str += String.fromCharCode((bin[i>>5] >>> (i % 32)) & mask);
  return str;
}

/*
 * Convert an array of little-endian words to a hex string.
 */
function binl2hex(binarray) {
  var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
  var str = "";
  for(var i = 0; i < binarray.length * 4; i++)
  {
    str += hex_tab.charAt((binarray[i>>2] >> ((i%4)*8+4)) & 0xF) +
           hex_tab.charAt((binarray[i>>2] >> ((i%4)*8  )) & 0xF);
  }
  return str;
}

/*
 * Convert an array of little-endian words to a base-64 string
 */
function binl2b64(binarray) {
  var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  var str = "";
  for(var i = 0; i < binarray.length * 4; i += 3)
  {
    var triplet = (((binarray[i   >> 2] >> 8 * ( i   %4)) & 0xFF) << 16)
                | (((binarray[i+1 >> 2] >> 8 * ((i+1)%4)) & 0xFF) << 8 )
                |  ((binarray[i+2 >> 2] >> 8 * ((i+2)%4)) & 0xFF);
    for(var j = 0; j < 4; j++)
    {
      if(i * 8 + j * 6 > binarray.length * 32) str += b64pad;
      else str += tab.charAt((triplet >> 6*(3-j)) & 0x3F);
    }
  }
  return str;
}

function encode_utf8(plaintext) {
   plaintext = plaintext.replace(/\r\n/g,"\n");
   var utftext = "";
   for(var n=0; n<plaintext.length; n++) {
      var c=plaintext.charCodeAt(n);
      /* caso 0-127 */
      if (c<128)
          utftext += String.fromCharCode(c);
      /* caso 127-2047 */
      else if((c>127) && (c<2048)) {
          utftext += String.fromCharCode((c>>6)|192);
          utftext += String.fromCharCode((c&63)|128);
          }
      /* caso 2048-65535 */
      else {
          utftext += String.fromCharCode((c>>12)|224);
          utftext += String.fromCharCode(((c>>6)&63)|128);
          utftext += String.fromCharCode((c&63)|128);
          }
      }
   return utftext;
   }

function decode_utf8(utftext) {
   var plaintext = "";
   var i=0;
   var c=c1=c2=0;

   while(i<utftext.length) {
      c = utftext.charCodeAt(i);
      if (c<128) {
         plaintext += String.fromCharCode(c);
         i++;
         }
      else if((c>191) && (c<224)) {
         c2 = utftext.charCodeAt(i+1);
         plaintext += String.fromCharCode(((c&31)<<6) | (c2&63));
         i+=2;
         }
      else {
         c2 = utftext.charCodeAt(i+1); c3 = utftext.charCodeAt(i+2);
         plaintext += String.fromCharCode(((c&15)<<12) | ((c2&63)<<6) | (c3&63));
         i+=3;
         }
      }
  return plaintext;
  }

function isleap(year){
   if (year > 1582) 
      return ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0);
   else {
      if (year < 0)                     /* L'anno 0 non esiste, */
         year++;                        /* la continuita' dei bisestili si. */
      return ((((year%4)+4)%4) == 0);
      }
   }

function xisdate(richiesta) {
   if(richiesta=='') return(1);
   var valore_inv=dec_format('@@/@@/@@@@',richiesta,1);
   if(valore_inv=='')
      return(0);
   else
      valore=enc_date(valore_inv);
   if(valore==-1)
        return(0);
   var ritorno=isdate(valore);
   return (ritorno);
   }

function isdate(valore){
   var len = valore.length; 
   if (len == 0 )
      return(1);
   if (len != 6 && len != 8)
      return(0);
   if (len == 6) {
      if(!isNaN(valore.substr(4,2)))
         var gg=eval(valore.substr(4,2));
      else
         return(0);
      if(!isNaN(valore.substr(2,2)))
         var mm=eval(valore.substr(2,2));
      else
          return(0);
      if(!isNaN(valore.substr(0,2)))
         var aa=valore.substr(0,2);
      else
         return(0);
      }
   else {
      if(!isNaN(valore.substr(6,2)))
         var gg=eval(valore.substr(6,2));
      else
         return(0);
      if(!isNaN(valore.substr(4,2)))
         var mm=eval(valore.substr(4,2));
      else
         return(0);
      if(!isNaN(valore.substr(0,4)))
         var aa=valore.substr(0,4); 
      else 
         return(0);
      }
   if(mm > 12 || mm < 1)
      return(0);
   switch(mm){
      case 4:
      case 6:
      case 9:
      case 11: var mgg=30;
               break;
      case 2:  var mgg=28;
               if (aa < 100) {
                  if (aa < 70)
                     aa += 1900;
                  else
                     aa += 2000;
                  }
               if (isleap(aa))
                  var mgg = 29;
               break;
      default: var mgg=31;
               break;
      }
   if (gg > mgg || gg < 1)
      return (0);
   return(1);
   }

function dec_format(format,valore,numeric) {
   var len = format.length;
   var lenv = valore.length;
   var str = '';
   var i;
   var j;

   if (numeric == 1) {
      for (i=len-1,j=lenv-1;i>=0 && j>=0;i--) {
         if (format.charAt(i) == '@') {
            str = valore.charAt(i)+str;
            j--;
            }
         }
      }
   else {
      for (i=0;i<len && i<lenv;i++) {
         if (format.charAt(i) == '@')
            str = str + valore.charAt(i);
         }
      }
   return (str);
}

/* codifica data: ritorna la data per postgres (ribaltata) */
function enc_date(valore) {
   var len=valore.length;

   if (len == 0)
      return ('');
   if (len == 8) {
      str=valore.charAt(4)+valore.charAt(5)+valore.charAt(6)+valore.charAt(7)+valore.charAt(2)+valore.charAt(3)+valore.charAt(0)+valore.charAt(1);
      }
   else if (len == 6) {
      str=valore.charAt(4)+valore.charAt(5)+valore.charAt(2)+valore.charAt(3)+valore.charAt(0)+valore.charAt(1);
      }
   else
      return (-1);
   return (str);
}

function GetXmlHttpObject(){ 
   var objXMLHttp=null;
   if (window.XMLHttpRequest){
      objXMLHttp=new XMLHttpRequest();
      }
   else if (window.ActiveXObject){
      /*objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }*/
      try {
         objXMLHttp=new ActiveXObject("Msml2.XMLHTTP");
         }
      catch(err1) {
         try {
            objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
            }
         catch(err2) {
            objXMLHttp=null;
            }
         }
      }
   return objXMLHttp;
   }

function url_random() {
   return ("&brw_unic_id="+parseInt(Math.random()*99999999));
   }

function showNewHelp(urlvar){
   if(document.getElementById('newhelp-state').value==0){
      xmlHttp=GetXmlHttpObject();
      if (xmlHttp==null){
         alert ("Browser does not support HTTP Request");
         return;
         }        
      var url=proxy_js+"showsch.php?"+urlvar;
      xmlHttp.onreadystatechange=HelpRequest;
      xmlHttp.open("GET",url,true);
      xmlHttp.send(null);
      }
   else {
      document.getElementById('newhelp').innerHTML="";      
      document.getElementById('newhelp-state').value=0;
      }
   }

function HelpRequest(){
   if(document.getElementById('newhelp-state').value==0){
      if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
         document.getElementById('newhelp').innerHTML=xmlHttp.responseText;
         document.getElementById('newhelp-state').value=1;
         }
      }
   }

function ord(c) {
   c = c . charAt (0);
   var i;
   for (i = 0; i < 256; ++ i) {
      var h = i . toString (16);
      if (h . length == 1)
         h = "0" + h;
      h = "%" + h;
      h = unescape (h);
      if (h == c)
         break;
      }
   return i;
   }

function iscodfis(p) {
   var tot=0;
   if (p == '')
      return (0);
   if (p.length != 16)
      return (0);
   p = new String(p);
   p=p.toUpperCase();
   if (p.charAt(9) == '0' && p.charAt(10) == '0')
      return (0);
   if (p.charAt(9) > '7')
      return (0);
   if (p.charAt(9) == '7' && p.charAt(10) > '1')
      return (0);
   for (i=0;i<16;i++) {
      vv=ord(p.charAt(i));
      switch (i) {
       case 6:
       case 7:
       case 9:
       case 10:
          if (vv < ord('0') || vv > ord('9'))
             return (0);
          break;
       case 12:
       case 13:
       case 14:
          /* problema omonimi */
          if ((vv < ord('0') || vv > ord('9')) && vv != ord('L') && vv != ord('M') && vv != ord('N') &&
              vv != ord('P') && vv != ord('Q') && vv != ord('R') && vv != ord('S') && vv != ord('T') &&
              vv != ord('U') && vv != ord('V'))
             return (0);
          break;
       default:
          if (vv < ord('A') || vv > ord('Z'))
             return (0);
          break;
         }
      }
   j=0;
   for (i=1;i<=8;i++) {
      vv=ord(p.charAt(j));
      tot += Funzdis(vv);
      j++;
      if (i<8) {
         vv=ord(p.charAt(j));
         tot += (( vv >= ord ('0') && vv <= ord ('9')) ? vv-ord('0') : vv-ord('A'));
         j++;
         }
      }
   vv=ord(p.charAt(j));
   if ((tot % 26) == (vv - ord('A')))
      return (1);
   return (0);
   }

function Funzdis(n) {
   dispari = new Array(1,0,5,7,9,13,15,17,19,21,2,4,18,20,11,3,6,8,12,14,16,10,22,25,24,23);
   if (n >= ord('0') && n <= ord ('9'))
      n += 17;
   return (dispari[n-65]);
   }

function dyna_sugg(pagina,parametri,campo) {
   var oSug = new SuggestionProvider();
   oSug.phpcallback(proxy_js+pagina,parametri+url_random());
   var oTextbox = new AutoSuggestControl(document.getElementById(campo), oSug);
   }

var close_tool_tip='';

function show_tool_tip(e,text,div_id) {
   if(document.all)
      e = event;
   var limite=130;
   if (e.clientY < limite) {
      var div_id2=div_id+'2';
      var obj = document.getElementById(div_id2);
      var span2=div_id+'2-content';
      var obj2 = document.getElementById(span2);
      close_tool_tip='2';
      }
   else {
      var obj = document.getElementById(div_id);
      var span2=div_id+'-content';
      var obj2 = document.getElementById(span2);
      close_tool_tip='';
      }
   obj2.innerHTML = text;
   obj.style.display = 'block';
   var st = Math.max(document.body.scrollTop,document.documentElement.scrollTop);
   var leftPos = e.clientX - 100;
   if(leftPos<0)
      leftPos = 0;
   obj.style.left = leftPos + 'px';
   if (e.clientY < limite)
      obj.style.top = e.clientY + 20 + st + 'px';
   else
      obj.style.top = e.clientY - obj.offsetHeight -1 + st + 'px';
   }	

function hide_tool_tip(div_id){
   var div_id2=div_id;
   if (close_tool_tip != '')
      div_id2=div_id+close_tool_tip;
   document.getElementById(div_id2).style.display = 'none';
   }

function show_orario(form,campo,len) {
   stamp=new Date();
   
   if (len == 6)
      val=sprintf("%02d:%02d:%02d",stamp.getHours(),stamp.getMinutes(),stamp.getSeconds());
   else
      val=sprintf("%02d:%02d",stamp.getHours(),stamp.getMinutes());
   document.forms[form].elements[campo].value=val;
   }

//-->

