//FUNZIONE PER LA DISABILITAZIONE DEL TASTO DESTRO

function Trim(stringa){    while (stringa.substring(0,1) == ' '){        stringa = stringa.substring(1, stringa.length);    }    while (stringa.substring(stringa.length-1, stringa.length) == ' '){        stringa = stringa.substring(0,stringa.length-1);    }    return stringa;}

var messaggio_tasto_destro="";
window.status="..: :..";


function click(e) {
  /*
  if (document.all) {
    if (event.button == 2) {
      alert(messaggio_tasto_destro);
      return false;
    }
    }
  if (document.layers) {
    if (e.which == 3) {
      alert(messaggio_tasto_destro);
      return false;
    }*/
  //}

}

if (document.layers) {
document.captureEvents(Event.MOUSEDOWN);
}

document.onmousedown=click;
//FUNZIONE PER L'ISTANZIAMENTO DELLE FINESTRE DI POPUP
function popup_window(contenuto,larghezza,altezza) {
     window.open(contenuto,"","top=130,left=240,status=no,menubar=no,scrollbars=no,resizable=no,width=" + larghezza + ",height=" + altezza);
     return false;

}



//FUNZIONE PER IL CONTEGGIO DELLE PAROLE INSERITE IN UNA TEXTAREA



function textCounter(field, countfield, maxlimit) {
  if (field.value.length > maxlimit)
    field.value = field.value.substring(0, maxlimit);
  else
    countfield.value = maxlimit - field.value.length;
}

//FUNZIONE PER LA CONFERMA DEL NUMERO AUTORI INSERITO
function conferma_numero_autori(){
    var n_autori=document.cambia_numero_autori.numero_autori.value;
    if (n_autori>1){
        var conferma_autori=confirm('Hai scelto di inserire '+n_autori+' autori. Confermi?');
    }
    else {
        var conferma_autori=confirm('Hai scelto di inserire '+n_autori+' autore. Confermi?');
    }
    if (conferma_autori == true)
    {
        window.location='../manutenzione/eliminazione/elimina_db.asp?cod_documento=<?php=$cod_documento%>';
    }
    else
    {
        return false;
    }
}

//FUNZIONE PER L'INCREMENTO DEL NUMERO DI AUTORI

function incrementa_autori(){
    window.document.cambia_numero_autori.numero_autori.value = parseInt(window.document.cambia_numero_autori.numero_autori.value)+1;
    window.document.cambia_numero_autori.ok.focus();
    return true;
}

//FUNZIONE PER IL DECREMENTO DEL NUMERO DI AUTORI

function decrementa_autori(){

    if (parseInt(window.document.cambia_numero_autori.numero_autori.value)>1){
        window.document.cambia_numero_autori.numero_autori.value = parseInt(window.document.cambia_numero_autori.numero_autori.value)-1;
        window.document.cambia_numero_autori.ok.focus();
        return true;
    }
    else window.document.cambia_numero_autori.ok.focus();
}



function VerificaCampoNumerico(field, fine_messaggio){
    var controllo = null;
    var command;
    controllo = field.value;
    if(controllo == ""){
        controllo = 0;
        field.value = "";
    }
    if ( isNaN(controllo) ){
        alert("INSERIRE UN VALORE NUMERICO PER "+fine_messaggio);
        command = field.style.background = '#FF0000';
        command = field.value = "";         
        command = field.select();
        eval(command); 
        command = field.focus();
        eval(command);

        return false;
    }
    return true;
}
function controlloCampoValuta(field, fine_messaggio){
  var controllo = null;
  var command;
  controllo = field.value;
  if(controllo == ""){
      controllo = 0;
    field.value = "0.00";
  }
  if ( isNaN(controllo) ){
    alert("INSERIRE UN VALORE NUMERICO PER "+fine_messaggio);
    command = field.style.background = '#FF0000';
    command = field.value = "0.00";     
    command = field.select();
    eval(command); 
    command = field.focus();
    eval(command);

    return false;
  }
  return true;
}

function seleziona(oggetto){
    oggetto.select();
}

function maskKeyPressSegno(objEvent, oggetto) {
    //var reValidChars=/[0-9][,-,]{1}[0-9]/;
    var reValidChars=/[0-9.-]/;
    var iKeyCode, strKey;
    iKeyCode = objEvent.keyCode;
    strKey = String.fromCharCode(iKeyCode);

    if (!reValidChars.test(strKey)
       || oggetto.value.length > oggetto.size) {
        return false;
    }
}
function maskKeyPress(objEvent, oggetto) {
    //var reValidChars=/[0-9][,-,]{1}[0-9]/;
    var v = parseFloat(objEvent.keyCode);
       
       if(v == 0){
           v =   parseFloat(objEvent.charCode);
       }

       if( isNaN(v) ){
          
          return false;

       }else{
           
          if(  v ==8  || v == 37  || v == 39  ||v == 46  || ( v >= 48 && v <= 57)  ){
          return true;
          }else{
          return false;
          }
       }
}

function mettizero(obj_ ,default_valore){
    if ( trim( obj_.value) == '')
         obj_.value = default_valore;
}

function maskKeyPressNoPoint(objEvent ,ogtipo){
       var v = parseFloat(objEvent.keyCode);
       
       if(v == 0){
           v =   parseFloat(objEvent.charCode);
       }

       if( isNaN(v) ){
          
          return false;

       }else{
          if(  v ==8  || v == 37  || v == 39   || ( v >= 48 && v <= 57)  ){
          return true;
          }else{
          return false;
          }
       }
  }


function myOpenCommessa( urlInd , field, tipo){
      var myurl1 =  urlInd + '?daCodiceNumerico=' + field.value + "&tipo="+tipo ;
    this.windowHandle = window.open(
            myurl1,
            'popup',
            'toolbar=no,'  +
            'location=no,' +
            'directories=no,' +
            'status=yes,' +
            'menubar=no,' +
            'scrollbars=yes,' +
            'resizable=no,' +
            'width=' + 550 + ',' +
            'height=' + 500
            );
    if (!windowHandle.opener){
      windowHandle.opener = self;
    }

}

function eseguiLaSelect( urlInd , field, filedtxt, tipo){
      var myurl1 =  urlInd + '?daCodiceNumerico=' + field.value + "&lettere="+filedtxt.value+"&tipo="+tipo ;
    
    this.windowHandle = window.open(
            myurl1,
            'finestraInvisibile',
            'toolbar=no,'  +
            'location=no,' +
            'directories=no,' +
            'status=no,' +
            'menubar=no,' +
            'scrollbars=no,' +
            'resizable=no,' +
            'width=' + 1 + ',' +
            'height=' + 1
            );        
    if (!windowHandle.opener){
      windowHandle.opener = self;
    }

}



function azzeraCampo(oggetto){
   if(isNaN(oggetto.value) | oggetto.value==""){
      oggetto.value="0";
   }

}

function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}


function expandCollapse() {            
    for (var i=0; i<expandCollapse.arguments.length; i++) {
      var element = document.getElementById(expandCollapse.arguments[i]);
      element.style.display = (element.style.display == "none") ? "block" : "none";
    }
}


function checkEmail(input)
{
   var ok=false;
   var i=0;
   var charToSearch = '@';
   for (i=0; (i<input.length) && (ok==false); i++) 
	{
		chr = input.charAt(i);
		if ( chr == charToSearch ) 
		     if( charToSearch == '@') 
		         charToSearch = '.';
		     else
		         ok=true;
	}
	
   return(ok);
}