function aprichiudi(item, op) {
            elem=document.getElementById(item);
            visibile=(elem.style.display!="none")
            prefisso=document.getElementById("menu" + item);
            if ((!(op) && visibile) || (op=="hide" && visibile)) {
                elem.style.display="none";
                prefisso.innerHTML="<img src=images/apri.gif width=13 border=0>";
            } else {
                if((!(op) && !(visibile)) || (op=="view" && !visibile)) {
                    elem.style.display="block";
                    prefisso.innerHTML="<img src=images/chiudi.gif width=13 border=0>";
                }
            }
}


function aprichiudi2(item) {
   elem=document.getElementById(item);
   visibile=(elem.style.display!="none")
   prefisso=document.getElementById(item);
   if (visibile) {
     elem.style.display="none";
   } else {
      elem.style.display="block";
   }
}

function cambiaCol(oggetto, evento, blur_color)
  {
   if(oggetto.name == 'link') {
        if(evento == 'onfocus') {
                oggetto.style.width = "30";
                oggetto.style.height = "30";
        } else {
                oggetto.style.width = "0";
                oggetto.style.height = "0";
        }
   } else {
       if(evento == 'onfocus') colore = "#ffAAAA";
       if(evento == 'onblur')
                if(oggetto.name == 'FORM_BUTTON') colore = '#C0C0C0';
                else colore = blur_color;
       if(oggetto.style) oggetto.style.backgroundColor = colore;
   }
  }
 
function enableObj(oggetto)
  {
        oggetto.disabled=false;
        oggetto.style.backgroundColor = "#FFFFFF";
  }

function disableObj(oggetto)
  {
    if(oggetto) {
        oggetto.style.backgroundColor = "#F4F4F4";
        //oggetto.style.borderColor = "#B0B0B0";
        oggetto.disabled=true;
    }
  }


function changeFocusOffset (InputObj, InputLen, offset) {
    if (InputObj.value.length == InputLen) {
        var i;
        for (i = 0; i < InputObj.form.length; i++)
            if (InputObj.form.elements[i].name == InputObj.name)
                break;
        i += offset;
        if (i < InputObj.form.length)
            InputObj.form.elements[i].focus();
    }
}

function CheckDate(data1, data2, str1, str2) {
    if(!eval('cal_'+str1).my_chk_date(data1)) {
	eval('document.forms[0].data_gg_'+str1).focus()
	return false;
    }
    if(!eval('cal_'+str2).my_chk_date(data2)) {
	eval('document.forms[0].data_gg_'+str2).focus()
	return false;
    }
    str_data = new String(data1)
    arr_str = str_data.split(' ')
    arr_date = arr_str[0].split('-')
    arr_time = arr_str[1].split(':')
    unix_data1 = new Date(arr_date[2],(arr_date[1]-1),arr_date[0],arr_time[0],arr_time[1])

    str_data = new String(data2)
    arr_str = str_data.split(' ')
    arr_date = arr_str[0].split('-')
    arr_time = arr_str[1].split(':')
    unix_data2 = new Date(arr_date[2],(arr_date[1]-1),arr_date[0],arr_time[0],arr_time[1])

    if(unix_data1 > unix_data2) {
	alert('La data di rientro deve essere maggiore di quella di uscita')
	return false;
    }
    return true;
}
function isPerc(Obj) {
    var Digit = "0123456789.";
    for(i=0;i<Obj.value.length;i++) {
        if(Digit.indexOf(Obj.value.charAt(i)) == -1) {
          alert("Campo:  "+Obj.name+"\n\nInserire un valore percentuale\n"); 
          Obj.value="";
          Obj.focus();
          return false
        }
    }
    return true;
}

function isN(Obj) {
    var Digit = "0123456789";
    for(i=0;i<Obj.value.length;i++) {
        if(Digit.indexOf(Obj.value.charAt(i)) == -1) {
          alert("Campo:  "+Obj.name+"\n\nInserire un valore numerico\n");
          Obj.value="";
          Obj.focus();
          return false
        }
    }
    return true;
}

function isNL(Obj, l) {
    var Digit = "0123456789";
    for(i=0;i<Obj.value.length;i++) {
        if(Digit.indexOf(Obj.value.charAt(i)) == -1) {
          alert("Campo:  "+Obj.name+"\n\nInserire un valore numerico\n"); 
          Obj.value="";
          Obj.focus();
          return false
        }
    }
    if(1*l > 0) {
	if(Obj.value.length != l) {
          alert("Campo:  "+Obj.name+"\n\nInserire un valore numerico di "+l+" cifre\n"); 
          Obj.focus();
          return false
	}
    }
    return true;
}

function isNneg(Obj) {
    var Digit = "0123456789";
    var Sign = "-";
    i = 0
    if(Sign.indexOf(Obj.value.charAt(0)) == 0) i = 1
    for(;i<Obj.value.length;i++) {
        if(Digit.indexOf(Obj.value.charAt(i)) == -1) {
          alert("Campo:  "+Obj.name+"\n\nInserire un valore percentuale (es.-20, 10)\n"); 
          Obj.value="";
          Obj.focus();
          return false
	}
    }
    return true;
}


function isEuro(Obj) {
    var Digit = ".0123456789";
    for(i=0;i<Obj.value.length;i++) {
        if(Digit.indexOf(Obj.value.charAt(i)) == -1) {
          alert("Campo:  "+Obj.name+"\n\nInserire un valore numerico (es. 123.55)\n"); 
          Obj.value="";
          Obj.focus();
          return false
        } else {
	    if(Digit.indexOf(Obj.value.charAt(i)) == 0) Digit = "0123456789";
	}
    }
    Obj.value = Math.round(Obj.value * 100) / 100
    return true;
}

function RoundEuro(num) {
    return Math.round(num * 100) / 100
}

function ChkNRange(Obj, Min, Max) {
    if(Max == 2100) {
    	if (Obj.value.length == 2) Obj.value = "20"+Obj.value
    	if (Obj.value.length == 1) Obj.value = "200"+Obj.value
	if(Min == 2002) Min = 2001
    }
    var num = parseInt(Obj.value)
    num = Obj.value * 1
    if (isN(Obj)) {
      if (num  < Min || num > Max) {
	if(Min == 2001) Min = 2002
        alert("Campo:  "+Obj.name+"\n\nInserire un valore numerico\ncompreso tra  "+Min+"  e  "+Max+"\n");
        Obj.value=Min;
      }
    }
}


function NoChg(tabella) {
  if(tabella) 
    alert('Operazione non consentita!\n\nPer modificare i dati accedi alla\n \'Gestione '+tabella+'\' dal menu principale.')
  else
    alert('Operazione non consentita!')
  return false;
}

