function calcCharLeft(Target, maxchar) {
    StrLen = Target.value.length;
    if (StrLen > maxchar ) {
        Target.value = Target.value.substring(0,maxchar);
        CharsLeft = 0;
        window.alert(fn_mess('JS_LUNG_ECCESSIVA') + (StrLen-maxchar) + fn_mess('JS_CARATT'));
    } else {
        CharsLeft = maxchar - StrLen;
    }
}



// 1-1-03
function ShowDiv(xvar) {
   var topic = eval('document.all.'+xvar);
   if (topic.className=='hide_class') { topic.className = 'reveal_class'; }
   else { topic.className = 'hide_class'; }
}
var wnd_main;
function fn_switch(nome_cookie) {
    x2= getcookie(nome_cookie);
    if (x2==0) y=1; else y=0;
    setcookie(nome_cookie,y);
}



function setcookie(name, value, expire) {
    document.cookie = name + '=' + escape(value)   + ((expire == null) ? '' : ('; expires=' + expire.toGMTString()));

    //document.write(value);
}

function getcookie(Name) {
   var search = Name + "="
   if (document.cookie.length > 0) { // if there are any cookies
      offset = document.cookie.indexOf(search)
      if (offset != -1) { // if cookie exists
         offset += search.length
         // set index of beginning of value
         end = document.cookie.indexOf(";", offset)
         // set index of end of cookie value
         if (end == -1)
            end = document.cookie.length
         return unescape(document.cookie.substring(offset, end))
      }
   }
}


/* ---------- non + usata -------- 5-2-03
function ControlloInput (xvar) {
   // controlla campi su nome form di default: 'prima'

   var ar1= new Array();

   for (var i=0; i<arguments.length; i++) {
      ar1[i]= arguments[i].value;
   }
   ar1[ar1.length]='prima';

   window.alert( ar1.join()); // chi ha inventato js è un genio;;;

   return ControlloInput2 (ar1);
}
*/


function ControlloInput2 (xvar) {
   // IL PRIMO GRUPPO <NOT NULL> GLI ALTRI <NUMERICI>, l'ultimo param è il nome della form

   re= fn_re2();

   gruppo1 = arguments[0].value;

   Nomeform = arguments[arguments.length-1];

   for (var i=1; i<arguments.length-1; i++) {

       StrLen = arguments[i].value.length;
       if (StrLen == 0 && i <= gruppo1) {
          window.alert(fn_mess('JS_CAMPO_NOT_NULL'));
          eval(Nomeform+'.'+arguments[i].name+'.focus()');
          return(false);
       }

       eval('strout = arguments[i].value'+ '.match(re)');

       if (strout == null && i> gruppo1)  {
           window.alert(fn_mess('JS_CAMPO_NUMERICO'));
           eval(Nomeform+'.'+arguments[i].name+'.focus()');
           return(false);
       }
   }
   return true;
}

function ControlloInput_nn (x) {
   if (x.value.length==0) { window.alert (fn_mess('JS_CAMPO_NOT_NULL')); x.focus(); return false; }
   else { return true; }
}


function param_nodo( xdescr, xnod, xprec, xcanc, xdescr_ingl) {
   if ( xcanc.value == 'del' )
      location='gest_albero.php?NODOPREC='+xprec+'&tipo=del2';
   if ( xcanc.value == 'ins' )
      if (ControlloInput_nn (xdescr) && ControlloInput_nn(xnod) ) {
         location='gest_albero.php?DESCRIZIONE='+xdescr.value+'&NODO='+xnod.value+'&NODOPREC='+xprec+'&tipo=ins2&DESCR_INGL='+xdescr_ingl.value;
         }
   if ( xcanc.value == 'mod' )
      location='gest_albero.php?NODOPREC='+xprec+'&tipo=mod2';
   return false;
}

function param_report (xnodo ) {
   location='scelta_report2.php?NODO='+xnodo;
   return false;
}

function param_all (x) {
   location=''+ x;
   return false; // 3-1-02; non serve?..
}

function fn_build_URL () {
   var y='';
   var b=false;
   for (var i=0; i< document.forms.length; i++) {
      if (document.forms(i).name=='form_5_1_03') b= true;
   }

   if (b) {
       for (var i=0; i< form_5_1_03.elements.length; i++) {
          y= y+'&'+ form_5_1_03.elements(i).name + '=' + form_5_1_03.elements(i).value;
       }
   }
   return y;
}

function fn_o1 (x,xwnd) {
 //window.open(x+ fn_build_URL(),xwnd,'toolbar=no,scrollbars=yes,resizable=yes');
 window.alert('This is a static demo page!');
 }

function fn_ou (x,xwnd) { window.open(x+ fn_build_URL(),'_new','width=10,height=10'); }

function fn_o2 (x) {
 //location.replace(''+ x+ fn_build_URL());
 window.alert('This is a static demo page!');
 }

function fn_o3 (x) { location=''+ x + fn_build_URL(); }

function fn_o1exc (x) {
   window.open(x+ fn_build_URL(),'wnd_excel','scrollbars=yes,resizable=yes');
}

function fn_o_l (xloc) {
  window.alert('This is a static demo page!');
}
