var win_dim;

var nav,ie
if (navigator.appName == "Netscape")
	{
	win_dim="sė"
	}

	
function perche(){

		 dim_x=450
		 dim_y=320

	y_def = dim_y+50
	dim_x=dim_x+8
	
	var wi = (l-dim_x)/2;
	var he = (a-dim_y)/2;
	
	
	
	ran=Math.random()
	prov=((ran*10)%4)+1
	prog=parseInt(prov,10)
	
	
	w=window.open("aziende/perche_"+prog+".htm","aa","location=no,menubar=no,status=no,toolbar=no,scrollbars=no,width="+dim_x+",height="+y_def);
       w.focus();
       w.moveTo(wi,he)  
	
}

var newwin;


var l = screen.width;
var a = screen.height;

	function crea(variabile,dim_x,dim_y){
	
	
	
	
	y_def = dim_y+50
	dim_x=dim_x+8
	
	var wi = (l-dim_x)/2;
	var he = (a-dim_y)/2;
	
	
	w=window.open(variabile,"aa","location=no,menubar=no,status=no,toolbar=no,scrollbars=no,width="+dim_x+",height="+y_def);
       w.focus();
       w.moveTo(wi,he)        
		 w.document.writeln("<head>"+
        "<title>zoom</title>"+
"<style type='text/css'>"+

"a {font-family:verdana,arial;font-size:10px;color:#505050;text-decoration:none}"+

"a:hover {font-family:verdana,arial;font-size:10px;color:#ff0000;text-decoration:none}"+

"</style>"+
        "</head>"+

"<body bgcolor='#ffffff' marginwidth='0' marginheight='0' leftmargin='0' topmargin='0'>"+
"<table>"+
"<tr>"+
       "<td><img src='http://www.cassaedilepratese.it/grandi/"+variabile+".jpg' border='0'></td>"+
"</tr>"+
"<tr>"+
       "<td align='right'><br><a href='javascript:window.close()'>[x] close&nbsp;&nbsp;</a></td>"+
"</tr>"+
"</table>"+

"</body>");

w.document.close();


}






	function crea_cosa(variabile,dim_x,dim_y){
	
	
	
	
	y_def = dim_y+50
	dim_x=dim_x+8
	
	var wi = (l-dim_x)/2;
	var he = (a-dim_y)/2;
	
	
	f=window.open(variabile,"aa","location=no,menubar=no,status=no,toolbar=no,scrollbars=yes,width="+dim_x+",height="+y_def);
       f.focus();
      f.moveTo(wi,he)        


}






	function info(variabile,dim_x,dim_y){
	
	
	
	y_def = dim_y+50
	dim_x=dim_x+8
	
	var wi = (l-dim_x)/2;
	var he = (a-dim_y)/2;
	
	
	h=window.open("","aa","location=no,menubar=no,status=no,toolbar=no,scrollbars=no,width="+dim_x+",height="+y_def);
      h.focus();
       h.moveTo(wi,he)        
		 h.document.writeln("<head>"+
        "<title>Istruzioni</title>"+
"<style type='text/css'>"+

"a {font-family:verdana,arial;font-size:10px;color:#505050;text-decoration:none}"+

"a:hover {font-family:verdana,arial;font-size:10px;color:#ff0000;text-decoration:none}"+

".testo {COLOR: #000000; FONT-FAMILY: Arial, Helvetica, sans-serif; FONT-SIZE: 12px; TEXT-ALIGN: justify};"+

"</style>"+
        "</head>"+

"<body background='../images/sfondo_modulo.gif' marginwidth='0' marginheight='0' leftmargin='0' topmargin='0'>"+
"<br><br>"+
"<table width='80%' align='center'>"+
"<tr>"+
       "<td class='testo'><b>Istruzioni di compilazione</b></td>"+
"</tr>"+
"<tr>"+
"<tr>"+
       "<td class='testo'>"+variabile+"</td>"+
"</tr>"+
"<tr>"+
       "<td align='right'><br><a href='javascript:window.close()'>[x] close&nbsp;&nbsp;</a></td>"+
"</tr>"+
"</table>"+

"</body>");

h.document.close();


}
//#edf7fe



	function apri_modulo(variabile,dim_x,dim_y){
	
	if(win_dim=="sė"){dim_x=dim_x+100};
	
	var wi = (l-dim_x)/2;
	var he = (a-dim_y)/2;
	
	
	win=window.open(variabile,"dd","location=no,menubar=no,status=no,toolbar=no,scrollbars=yes,width="+dim_x+",height="+dim_y);
       win.focus();
       win.moveTo(wi,he)  
	

                }



       function creanews(variabile,pag,filepdf){
	var wi = (l-500)/2;
	var he = (a-500)/2;
        if (filepdf) {

          w=window.open("http://www.cassaedilepratese.it/giornalini/"+filepdf, "aa","location=no,menubar=yes,status=no,toolbar=yes,scrollbars=yes,resizable=yes");
          return;
        } else {

          w=window.open("http://www.cassaedilepratese.it/gestione/info.php3?codice="+variabile+"&pagout="+pag,"aa","location=no,menubar=no,status=no,toolbar=no,scrollbars=yes,width=500,height=400");
          w.moveTo(wi,he)        
        }
       w.focus();



}

function cercaveloce(pagina) {
    ind=document.form.categ.selectedIndex;
    document.form.DB_categoria1.value=document.form.categ.options[ind].value;
    document.form.pagout.value=pagina;
    document.form.comando.value="QuickSearch";
    document.form.submit();
}
function cerca1(categoria1,codice,pagina) {
    document.form.DB_categoria1.value=categoria1;
    document.form.DB_codice.value=codice;
    document.form.pagout.value=pagina;
    document.form.submit();
}
function cerca2(categoria1,categoria2,codice,pagina) {
    document.form.DB_categoria1.value=categoria1;
    document.form.DB_categoria2.value=categoria2;
    document.form.DB_codice.value=codice;
    document.form.pagout.value=pagina;
    document.form.submit();
}

function check_cf(cf) {
  if (cf.value.length ==  11) { 
    check_piva(cf) ;
    return;
  }
  var valore = parseInt(cf.value,10);
  codfis=cf.value.toUpperCase();
  var pari = new Array("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","0","1","2","3","4","5","6","7","8","9");
  var dispari=new Array ("B","A","K","P","L","C","Q","D","R","E","V","O","S","F","T","G","U","H","M","I","N","J","W","Z","Y","X","1","0","","","","2","","3","","4","","","","5","","6","","7","","8","","9");
  var controllo = new Array("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");
  if (cf.value.length ==  0) { 
     return;
  }
  if (cf.value.length !=  16) { 
     alert("Codice Fiscale non corretto. Non ci sono 16 caratteri!");
     cf.value="";
     cf.focus();
     return;
   } else {
     i = 1;
     tot=0;
     //pos dispari 
     while (i < 16)  {
      carat=codfis.charAt(i-1);
      trovato=0;
      index=0;
      while ( trovato != 1 || index > 50) {
//alert ("dispari["+index+"]="+dispari[index]);
         if (dispari[index] == carat ) {
            trovato=1;
            x=index % 26;
         } else {
           index++;
         }
      }
      if (trovato != 1 ) {
         alert("Codice Fiscale non corretto. Caratteri non legali.");
         cf.value="";
         cf.focus();
         return;
      }
      tot = tot+x;
      i = i + 2;
     }
     i = 2;
     //pos pari 
     while (i < 16)  {
      carat=codfis.charAt(i-1);
      trovato=0;
      index=0;
      while ( trovato != 1 || index > 40) {
         if (pari[index] == carat ) {
            trovato=1;
            x=index % 26;
         } else {
           index++;
         }
      }
      if (trovato != 1 ) {
         alert("Codice Fiscale non corretto. Caratteri non legali.");
         cf.value="";
         cf.focus();
         return;
      }
      tot = tot+x;
      i = i + 2;
     }
     resto=tot % 26;
     //il secicesimo carattere deve essere uguale a controllo[resto]
     if ( controllo[resto] != codfis.charAt(15) ){
         alert("Codice Fiscale non corretto.");
         cf.value="";
         cf.focus();
         return;
     }
     
  }
return;
}
function check_piva(piva) {

  //var result = 0 //FALSE;
  var valore = parseInt(piva.value,10);
  if (piva.value.length ==  0) { 
      return;
  }
  if ( isNaN(valore) ){
       piva.value="";
       alert("Partita iva non corretta");
       return;
  }
  if (piva.value.length !=  11) { 
     alert("Partita iva non corretta. Non ci sono 11 cifre.");
     piva.value="";
     return;
   } else {
     tot = 0;
     i = 1;
     //pos dispari 
     while (i < 11)  {
      //tot = tot + Mid(p_iva, i, 1); 
      tot = tot + parseInt(piva.value.charAt(i-1),10);
      i = i + 2;
     }
     i = 2;
     //* posizioni pari */
     while (i < 11)     {

          //* raddoppia ogni singola posizione pari... */
          //x = Mid(p_iva, i, 1) * 2;
          x = parseInt(piva.value.charAt(i - 1),10) * 2;
          ///**
          // * ...aggiunge x alla somma delle dispari
          // * Se x e' maggiore di 10, viene ridotta
          // * alla somma della parte delle decine e delle 
          // * unita' (es: 15 diventa 1+5)
          // *
          // */
          //devo mettere +1 e -1 dopo perche valori come .2 fanno casino con
          //parsint. IL problema e' che la divisione mi da .2 anziche' 0.2
          xin=(x / 10)+1;
          xin= parseInt(xin,10)-1 ; 
          tot = tot + xin + ( x % 10 );
      i = i + 2;
     }
     x = tot;
//alert(x);
//alert(parseInt(piva.value.charAt(10)));
     if ((x % 10 == 0) && (parseInt(piva.value.charAt(10)) == 0)) {
          return;
          //result = TRUE;
     } else  {
        if ( 10 - ( x % 10) == piva.value.charAt(10)) {
          return;
        } else {
          alert("Partita iva non corretta");
          piva.value="";
          return;
        }
     }
     alert("Partita iva non corretta");
     piva.value="";
     return;
  }
                      
 


}

