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_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function previewImg(field){
  var imgURL = 'file:///' + field.value.replace(/\\/gi,'/').replace(/:/gi,'|').replace(/"/gi,'').replace(/^\//,'');
  document.icona.src = imgURL;
}

function previewImgCartello(field, prevField){
  var imgURL = 'file:///' + field.value.replace(/\\/gi,'/').replace(/:/gi,'|').replace(/"/gi,'').replace(/^\//,'');
  prevField.src = imgURL;
}

function controllaCodFisc(campo){
   caratteri= new Array ("0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z")
   pari= new Array (0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25)
   dispari=new Array (1,0,5,7,9,13,15,17,19,21,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)
   cod=campo.value.toLowerCase();
   check=true;
   if (cod.length!=16){
      check=false
      }
     else
      {
      lettere=cod.substr(0,6)+cod.substr(8,1)+cod.substr(11,1)+cod.substr(15);
      numeri=cod.substr(6,2)+cod.substr(9,2)+cod.substr(12,3);
      for (i=0;i<10;i++){
         if (lettere.charCodeAt(i)<97 || lettere.charCodeAt(i)>122){
            check=false;}
      }
      for (i=0;i<8;i++){
         if (numeri.charCodeAt(i)<48 || numeri.charCodeAt(i)>57){
            check=false;
         }
      }
     }
   //checksum del codice fiscale
   test=cod.substr(15,1);
   var somma=0
   for (i=0;i<16;i=i+2){ //dispari
       carattere=cod.substr(i,1)
       for (k=0;k<36;k++){
          if (carattere==caratteri[k]){
             somma=somma+dispari[k]
             break
          }
       }
    }
    for (i=1;i<15;i=i+2){ //pari
       carattere=cod.substr(i,1)
       for (k=0;k<36;k++){
          if (carattere==caratteri[k]){
             somma=somma+pari[k]
             break
          }
       }
    }
   resto=somma % 26;
   var lettera=String.fromCharCode(97+resto);
   if (test != lettera){
      check=false;
      }
/*   if (check==false){
      alert("Codice fiscale errato!")
      }
      else
      {
      alert("codice fiscale corretto!!")
      }*/
   return check;
}


 function controllaPIVA(pi)
{
	if( pi == '' )
		return '';
	if( pi.length != 11 )
		return "La lunghezza della partita IVA non \350\n" +
			"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 \350 valida:\n" +
			"il codice di controllo non corrisponde.\n";

	return '';
}


function changeDiv(oldDiv, newDiv){
  if (document.getElementById)
  {
  eval('document.getElementById("'+oldDiv+'").style.display="none";');
  eval('document.getElementById("'+newDiv+'").style.display="inline";');
  }
  else if (document.all)
  {
  eval('document.all["'+oldDiv+'"].style.display="none";');
  eval('document.all["'+newDiv+'"].style.display="inline";');
  }
  else if (document.layers)
  {
  eval('document.layers["'+oldDiv+'"].display="none";');
  eval('document.layers["'+newDiv+'"].display="inline";');
  }
}

function change(param){
  var azione,form;
  form = document.forms[0];
  azione = form.action + '?org.apache.struts.taglib.html.CANCEL=Annulla&change='+param;
  form.action = azione;
  form.submit();
}

function checkNum(e) {
  var whichCode = (e.which == null) ? e.keyCode : e.which;
	// whichCode=13 è il tasto Enter
  if (((whichCode>=48)&&(whichCode<=57))||(whichCode==8)||(whichCode==9)||(whichCode==13))
     {
     return true;
     }
  else
     return false;
}

function checkValuta(e) {
  var whichCode = (e.which == null) ? e.keyCode : e.which;
	// whichCode=13 è il tasto Enter
  if (((whichCode>=48)&&(whichCode<=57))||(whichCode==8)||(whichCode==9)||(whichCode==44)||(whichCode==46)||(whichCode==13))
     {
     return true;
     }
  else
     return false;
}

function checkValutaConSegno(e) {
  var whichCode = (e.which == null) ? e.keyCode : e.which;
	// whichCode=13 è il tasto Enter
  if (((whichCode>=48)&&(whichCode<=57))||(whichCode==8)||(whichCode==9)||(whichCode==44)||(whichCode==45)||(whichCode==46)||(whichCode==13))
     {
     return true;
     }
  else
     return false;
}

function checkValutaNoVirgola(e) {
  var whichCode = (e.which == null) ? e.keyCode : e.which;
	// whichCode=13 è il tasto Enter
  if (((whichCode>=48)&&(whichCode<=57))||(whichCode==8)||(whichCode==9)||(whichCode==46)||(whichCode==13))
     {
     return true;
     }
  else
     return false;
}

function checkPhone(e) {
  var whichCode = (e.which == null) ? e.keyCode : e.which;
	// whichCode=13 è il tasto Enter
  if (((whichCode>=48)&&(whichCode<=57))||(whichCode==8)||(whichCode==9)||(whichCode==43)||(whichCode==45)||(whichCode==46)||(whichCode==32)||(whichCode==13))
     {
     return true;
     }
  else
     return false;
}

function checkFax(e) {
  var whichCode = (e.which == null) ? e.keyCode : e.which;
	// whichCode=13 è il tasto Enter
  if (((whichCode>=48)&&(whichCode<=57))||(whichCode==8)||(whichCode==9)||(whichCode==43)||(whichCode==45)||(whichCode==46)||(whichCode==32)||(whichCode==13))
     {
     return true;
     }
  else
     return false;
}

function checkCodFisc(e) {
  var whichCode = (e.which == null) ? e.keyCode : e.which;
	// whichCode=13 è il tasto Enter
  if ((whichCode>=48 && whichCode<=57) || (whichCode >= 65 && whichCode < 91)||(whichCode==13))
  {
    return true;
  } else if (whichCode >= 97 && whichCode < 123)
  {
    //whichCode = whichCode - 32;
    e.which = e.which -32;
    e.keyCode = e.keyCode -32;
    return true;
  } else {
    return false;
  }
}

function handlePress(e) {
  var whichCode = (e.which == null) ? e.keyCode : e.which;
  if ((whichCode==13)||(whichCode==126)||(whichCode==92)||(whichCode==124)||(whichCode==34)||(whichCode==42)||(whichCode==60)||(whichCode==62))
     {
     return false;
     }
  else
     return true;
}

function isVuoto(s)
   {
   for(var i=0; i<s.length; i++)
	  {
	  var c=s.charAt(i);
	  if ((c != ' ') && (c != '\n') && (c != '\t'))
	     return false;
      }
   return true;
   }

