function confirm_deletion(dluLink){
      	if (confirm('Delete selected item ?')) { return true; };
	return false; 
}

function imageswap(name, imagesrc)  
{
   eval("document." + name + ".src = '" + imagesrc + "'");
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}


function gen(texts,links,t,tl)
{
  //var texts = new Array("","","")
  //var links = new Array("","","")
  //var t
  //var tl
  var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
  
  var map = InternetExplorer ? menu : document.embeds("menu");
	for (i=0;i<=t;i++)
	{
  	map.SetVariable('m' + (i+1), texts[i]);
  	map.SetVariable('l' + (i+1), links[i]);
	}
	map.SetVariable('nt', t);
	map.SetVariable('title', tl);
  
  	
}
  
function gens(texts,links,t,tl)
{
  //var texts = new Array("","","")
  //var links = new Array("","","")
  //var t
  //var tl
  var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
  
  var map = InternetExplorer ? menu : document.embeds("menu");
	for (i=0;i<=t;i++)
	{
  	map.SetVariable('ms' + (i+1), texts[i]);
  	map.SetVariable('ls' + (i+1), links[i]);
	}
	map.SetVariable('nts', t);
	map.SetVariable('titles', tl);
  
	
}

function SelDeselTutti(e,multi) {
  var sel;
  var id_multi;
  
  if (e.checked == false) {
     sel = 0;
  } else {
     sel = 1;
  }
  
  if (multi.length) {
    for (var i=0;i<multi.length;i++){
      if (sel == 1) {
         multi[i].checked = true;
      }else{
         multi[i].checked = false;
      }
    }
  }else{
    if (sel == 1){
        multi.checked = true;
    }else{
        multi.checked = false;
    }
  }

}

function controllaLink() {
   var valrma = document.getElementById('fld323').value;
   //alert('valore: '+valrma);
   if (valrma.length > 2) {  
     if (Number(valrma.substring(2,3))){
        if (valrma.length > 3) {
	  val = Number(valrma.substring(2,3));
	  //alert('anno: ' +val);
	  if (val <= 6) {
	     window.location.href='http://85.46.56.164/asus/ricerca.asp?RMA='+valrma;
	     return false;
	  }
	  return true;
	}else{
	  return true;
	}
      }else{
        if (valrma.substring(2,3) == 0) {
	  window.location.href='http://85.46.56.164/asus/ricerca.asp?RMA='+valrma;
	  return false;
        }else{
	  alert('Formato RMA non riconosciuto');
	  return false;
	}
      }
    }else{
       return false;
    }
}

function ControllaCF(cf)
{
    var validi, i, s, set1, set2, setpari, setdisp;
    if( cf == '' )  return '';
    cf = cf.toUpperCase();
    if( cf.length != 16 )
        return "La lunghezza del codice fiscale non ?"
        +"corretta: il codice fiscale dovrebbe essere lungo\n"
        +"esattamente 16 caratteri.\n";
    validi = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    for( i = 0; i < 16; i++ ){
        if( validi.indexOf( cf.charAt(i) ) == -1 )
            return "Il codice fiscale contiene un carattere non valido `" +
                cf.charAt(i) +
                "'.\nI caratteri validi sono le lettere e le cifre.\n";
    }
    set1 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    set2 = "ABCDEFGHIJABCDEFGHIJKLMNOPQRSTUVWXYZ";
    setpari = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    setdisp = "BAKPLCQDREVOSFTGUHMINJWZYX";
    s = 0;
    for( i = 1; i <= 13; i += 2 )
        s += setpari.indexOf( set2.charAt( set1.indexOf( cf.charAt(i) )));
    for( i = 0; i <= 14; i += 2 )
        s += setdisp.indexOf( set2.charAt( set1.indexOf( cf.charAt(i) )));
    if( s%26 != cf.charCodeAt(15)-'A'.charCodeAt(0) )
        return "Il codice fiscale non ?orretto:\n"+
            "il codice di controllo non corrisponde.\n";
    return "";
}

function ControllaPIVA(pi)
{
    if( pi == '' )  return '';
    if( pi.length != 11 )
        return "La lunghezza della partita IVA non ?" +
            "corretta: la partita IVA dovrebbe essere lunga\n" +
            "esattamente 11 caratteri.\n";
    validi = "0123456789";
    for( i = 0; i < 11; i++ ){
        if( validi.indexOf( pi.charAt(i) ) == -1 )
            return "La partita IVA contiene un carattere non valido `" +
                pi.charAt(i) + "'.\nI caratteri validi sono le cifre.\n";
    }
    s = 0;
    for( i = 0; i <= 9; i += 2 )
        s += pi.charCodeAt(i) - '0'.charCodeAt(0);
    for( i = 1; i <= 9; i += 2 ){
        c = 2*( pi.charCodeAt(i) - '0'.charCodeAt(0) );
        if( c > 9 )  c = c - 9;
        s += c;
    }
    if( ( 10 - s%10 )%10 != pi.charCodeAt(10) - '0'.charCodeAt(0) )
        return "La partita IVA non ?alida:\n" +
            "il codice di controllo non corrisponde.\n";
    return '';
}

function controllaPivaCf() {
   
   if (document.getElementById('fld442')) {
     document.getElementById('fld442').value = document.getElementById('fld442').value.toUpperCase();
     pivaCf = document.getElementById('fld442').value;
     if (pivaCf.length > 0) {
       if (Number(pivaCf)) {
         if (ControllaPIVA(pivaCf) != '') {
           alert("La partita IVA non valida:\n" +
                 "il codice di controllo non corrisponde.\n");
           return false;
         }
       } else {
         if (ControllaCF(pivaCf) != '') {
           alert("Il codice fiscale non corretto:\n"+
            "il codice di controllo non corrisponde.\n");
           return false;
         }
       }
     }
   }else if (document.getElementById('fld443')) {
     document.getElementById('fld443').value = document.getElementById('fld443').value.toUpperCase();
     pivaCf = document.getElementById('fld443').value;
     if (pivaCf.length > 0) {
       if (Number(pivaCf)) {
         if (ControllaPIVA(pivaCf) != '') {
           alert("La partita IVA non valida:\n" +
                 "il codice di controllo non corrisponde.\n");
           return false;
         }
       } else {
         if (ControllaCF(pivaCf) != '') {
           alert("Il codice fiscale non corretto:\n"+
            "il codice di controllo non corrisponde.\n");
           return false;
         }
       }
     }   
   }else if (document.getElementById('fld444')) {
     document.getElementById('fld444').value = document.getElementById('fld444').value.toUpperCase();
     pivaCf = document.getElementById('fld444').value;
     if (pivaCf.length > 0) {
       if (Number(pivaCf)) {
         if (ControllaPIVA(pivaCf) != '') {
           alert("La partita IVA non valida:\n" +
                 "il codice di controllo non corrisponde.\n");
           return false;
         }
       } else {
         if (ControllaCF(pivaCf) != '') {
           alert("Il codice fiscale non corretto:\n"+
            "il codice di controllo non corrisponde.\n");
           return false;
         }
       }
     }
   }
   
   if (document.getElementById('fld471')) {
       document.getElementById('fld471').value = document.getElementById('fld471').value.toUpperCase();
       pivaCf = document.getElementById('fld471').value;
       if (pivaCf.length > 0) {
          if (Number(pivaCf)) {
            if (ControllaPIVA(pivaCf) != '') {
              alert("La partita IVA non valida:\n" +
                    "il codice di controllo non corrisponde.\n");
              return false;
            }
          } else {
            if (ControllaCF(pivaCf) != '') {
              alert("Il codice fiscale non corretto:\n"+
               "il codice di controllo non corrisponde.\n");
              return false;
            }
          }
        }
    }  
      
    if (document.getElementById('fld460')) {
      if (document.getElementById('fld456_locale').value == '') {
         document.getElementById('fld460').value = '';
      }else{
         document.getElementById('fld460').value = '1';
      }
    }
        
    if (document.getElementById('fld496')) {
       if (document.getElementById('fld457_locale').value == '') {
          document.getElementById('fld496').value = '';
       }else{
          document.getElementById('fld496').value = '1';
       }
    }
    
    
    if (document.getElementById('fld473')) {
       if (document.getElementById('fld474_locale').value == '') {
          document.getElementById('fld473').value = '';
       }else{
          document.getElementById('fld473').value = '1';
       }
    }
    
    return true;
          
}

String.prototype.trim = function() {
     return(this.replace(/^\s+/,'').replace(/\s+$/,''));
}

function campiFuochi() {
    matricola = document.getElementById('fld7');
    ordine = document.getElementById('fld3');
    //cdl = document.getElementById('fld8');
    operazione = document.getElementById('fld4');

    if (matricola.value.trim() == '') {
        matricola.focus();
        matricola.value='';
        return false;
    }
    if (ordine.value.trim() == '') {
        ordine.focus();
        ordine.value='';
        return false;
    }
    //if (cdl.value.trim() == '') {
    //    cdl.focus();
    //    cdl.value='';
    //    return false;
    //}
    if (operazione.value.trim() == '') {
        operazione.focus();
        operazione.value='';
        return false;
    }
    return true;
}
function campiFuochiGRANDE() {
    matricola = document.getElementById('fld157');
    ordine = document.getElementById('fld158');
    //cdl = document.getElementById('fld161');
    operazione = document.getElementById('fld159');

    if (matricola.value.trim() == '') {
        matricola.focus();
        matricola.value='';
        return false;
    }
    if (ordine.value.trim() == '') {
        ordine.focus();
        ordine.value='';
        return false;
    }
    //if (cdl.value.trim() == '') {
    //    cdl.focus();
    //    cdl.value='';
    //    return false;
    //}
    if (operazione.value.trim() == '') {
        operazione.focus();
        operazione.value='';
        return false;
    }
    return true;
}

function campiFuochi22() {
    articolo = document.getElementById('fld130');
    qta = document.getElementById('fld131');

    if (articolo.value.trim() == '') {
        articolo.focus();
        articolo.value='';
        return false;
    }
    if (qta.value.trim() == '') {
        qta.focus();
        qta.value='';
        return false;
    }
    return true;
}

function campiFuochi12() {
    qtanc = document.getElementById('fld193');
    qta = document.getElementById('fld113');

    if (qtanc.value.trim() == '') {
        qtanc.focus();
        qtanc.value='';
        return false;
    }
    if (qta.value.trim() == '') {
        qta.focus();
        qta.value='';
        return false;
    }
    return true;
}

function campiFuochi28() {
    qta = document.getElementById('fld138');
    causale = document.getElementById('sfld7');

    if (qta.value.trim() == '') {
        qta.focus();
        qta.value='';
        return false;
    }
    if (causale.value.trim() == '') {
        causale.focus();
        causale.value='';
        return false;
    }
    return true;
}

function campiFuochi29() {
    qta = document.getElementById('fld143');
    causale = document.getElementById('sfld8');

    if (qta.value.trim() == '') {
        qta.focus();
        qta.value='';
        return false;
    }
    if (causale.value.trim() == '') {
        causale.focus();
        causale.value='';
        return false;
    }
    return true;
}

function campiFuochi33() {
    qtanc = document.getElementById('fld194');
    qta = document.getElementById('fld156');

    if (qtanc.value.trim() == '') {
        qtanc.focus();
        qtanc.value='';
        return false;
    }
    if (qta.value.trim() == '') {
        qta.focus();
        qta.value='';
        return false;
    }
    return true;
}

function campiFuochi38() {
    qta = document.getElementById('fld172');
    causale = document.getElementById('sfld4');

    if (qta.value.trim() == '') {
        qta.focus();
        qta.value='';
        return false;
    }
    if (causale.value.trim() == '') {
        causale.focus();
        causale.value='';
        return false;
    }
    return true;
}

function scrollit() {
	var campo;
	var idDiv;
	var valCampo;

	divs=document.getElementsByTagName("div");
	for (i=0;i<divs.length;i++) {
	  var nomeDiv = divs[i].id;
	  if (nomeDiv.substring(0,4) == 'scr_'){
	   idDiv = document.getElementById(nomeDiv);
	   campo=nomeDiv+'cur';
	       if (document.getElementById(campo)){
		   valCampo = document.getElementById(campo).value;
		      for (var I=1; I<=(valCampo-1)*20; I++){
			idDiv.scrollTop=I;
		      }
	       }
	   }
	}

}
	
function blendoff(idname) {document.getElementById(idname).style.display = 'none';}
function blendon(idname) {document.getElementById(idname).style.display = 'block';}

function swichtabs(wert) {
	if (wert=='1'){
	  document.getElementById('tablink1').className='tab1 tabactive';
	  document.getElementById('tablink2').className='tab2';
	}else if (wert=='2'){
	  document.getElementById('tablink1').className='tab1';
	  document.getElementById('tablink2').className='tab2 tabactive';
	}else if (wert=='3'){
	  document.getElementById('tablink3').className='tab1 tabactive';
	  document.getElementById('tablink4').className='tab2';
	}else if (wert=='4'){
	  document.getElementById('tablink3').className='tab1';
	  document.getElementById('tablink4').className='tab2 tabactive';
	}
}