salvavalori = new Array(32)	

function VaiAllaPagina( sPageIndex ) {

	var oFrm = MM_findObj('frmInvia');
	if (oFrm){
		oFrm.PaginaCorrente.value=sPageIndex;
		oFrm.submit();
		}
}

function CambiaCommissione ( val ) {
	var tbl1 = MM_findObj( 'tblComposizione' ); 
	var tbl2 = MM_findObj( 'tblVerbali' ); 
	
	if (val==1)
			{
		tbl1.style.display = "";
		tbl2.style.display = "none";
			}
	else
			{
		tbl1.style.display = "none";
		tbl2.style.display = "";
			}
}

function TipoRicerca ( Tipo ){
	  
  frmInvia.PaginaCorrente.value=1;
  frmInvia.action='page.asp?Speciale=Ricerca&Tipo=' + Tipo;
  frmInvia.submit();
	}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

function MM_findObj(n, d) { //v4.01
  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);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_jumpMenuGo(selName,targ,restore){ //v3.0
  var selObj = MM_findObj(selName); if (selObj) MM_jumpMenu(targ,selObj,restore);
}

function MM_validateForm() { //v3.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (val!=''+num) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}
function selezionatutto() {

 i = 0
 if (document.getElementById("frmCalendario").tutto.checked)
   for (var i = 0; i < document.getElementById("frmCalendario").giorno.length; i++) {
    salvavalori[i] = document.getElementById("frmCalendario").giorno[i].checked
    document.getElementById("frmCalendario").giorno[i].checked = true;
       }
 else
       {
   for (var i = 0; i < document.getElementById("frmCalendario").giorno.length; i++)
     document.getElementById("frmCalendario").giorno[i].checked = salvavalori[i]
       }

 return false;
}

function controllagiorno() {

 ok = false;

   for (var i = 0; i < document.getElementById("frmCalendario").giorno.length; i++)
     if (document.getElementById("frmCalendario").giorno[i].checked)
        ok = true;

 document.valore = ok
 if (!ok)
   alert("Per effettuare la ricerca occorre selezionare almeno un giorno del mese.");

 return false;
}

function VaiOffset( i ) {

  document.getElementById("frmGiorni").elements['OffSet'].value = Number(document.getElementById("frmGiorni").elements['OffSet'].value) + Number(i)
  document.getElementById("frmGiorni").submit()
}

function controllaradio(obj)
{
ncheck = obj.length;
for (i=0; i<ncheck;i++)
{
    if (obj[i].checked)	
		{
        return obj[i].value;
       break;
	   }
}
}

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_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_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_validateFormComplete() { //v3.0
  var checkstr = "0123456789";
  var i,p,q,nm,test,num,min,max,errors='',lbl,args=MM_validateFormComplete.arguments;
  for (i=0; i<(args.length-2); i+=3) 
  { 
  	test=args[i+2]; 
  	lbl=args[i+1];
	val=MM_findObj(args[i]);
	o=MM_findObj(args[i]); 
    if (val) 
	{ 
	  nm=val.name;
	  if (lbl == '') { lbl = nm; } 
	  if (val.type)
	  {
		  if ((val.type == 'text')||(val.type == 'password')||(val.type == 'textarea'))
		  {		  	
			  if ((val=val.value)!="") 
			  {
				if (test.indexOf('isEmail')!=-1) 
				{ 
				  p=val.indexOf('@');
				  if (p<1 || p==(val.length-1)) errors+='- '+lbl+' deve contenere un\'indirizzo e-mail valido.\n';
				}
				if ((test.indexOf('isNum')!=-1)||(test.indexOf('inRange')!=-1)) 
				{ 
					num = parseFloat(val);
					if (val!=''+num) errors+='- '+lbl+' deve contenere un numero.\n';
					if (test.indexOf('inRange') != -1) 
					{ 
					  p=test.indexOf(':');
					  min=test.substring(8,p); max=test.substring(p+1);
					  if (num<min || max<num) errors+='- '+lbl+' deve contenere un numero tra '+min+' e '+max+'.\n';
					}
				}
				if (test.indexOf('isDate')!=-1) 
				{ 
				  errors+=IsDate(o,lbl);
				}		
				if (test.indexOf('isCF')!=-1) 
				{ 
				  errors+=IsCodiceFiscale(val,lbl);
				}				
				if (test.indexOf('isPI')!=-1) 
				{ 
				  errors+=IsPartitaIva(val,lbl);
				}				
				if (test.indexOf('isTelefono')!=-1)
				{
					nerr = 0;
					for (j = 0; j < val.length; j++) {
 						if (checkstr.indexOf(val.substr(j,1)) < 0) 
 						{
							nerr += 1;
 						}
					}
					if (nerr > 0)	errors+='- '+lbl+' deve essere inserito senza separatori tra i numeri';				
				}
			  }
			  else if (test.charAt(0) == 'R') errors += '- '+lbl+' č richiesto.\n';
			  if (test.indexOf('Confirm')!=-1)
			  {
				  confval = MM_findObj('Conf'+nm);
				  if (confval)
				  {
					if ((val)!=(confval.value))	errors+='- '+lbl+' e Conferma '+lbl+' devono contenere valori uguali.\n';		
				  }
			  }		  
		  }
		  if ((val.type == 'select-one' || val.type == 'select-multiple')&&(test.charAt(0) == 'R'))
		  {
				if ( val.options(val.selectedIndex).value == '' ) 
				{
					errors += '- '+lbl+' č richiesto.\n';
				}	
		  }
		  if ((val.type == 'radio' || val.type == 'checkbox')&&(test.charAt(0) == 'R'))
		  {
		  	if (! val.checked )	errors += '- '+lbl+' č richiesto.\n';
		  }
	  }
	  else
	  {
		  nitem = val.length;
		  if (nitem) 
		  {
			nm = val[0].name;
			tipo = val[0].type;
			checked = false;
			if (lbl == '') { lbl = nm; }			
 		    if ((tipo == 'radio' || tipo == 'checkbox')&&(test.charAt(0) == 'R'))
		    {
				for( j=0; j < nitem; j++ )
				{
					if ( val[j].checked )	checked = true;
			    }
				if( !checked ) errors += '- '+lbl+' č richiesto.\n';
			}  	
		  }
	  }
	}	
  }

  oInformativa = MM_findObj('rInformativa');
  if (oInformativa)
		{
	if (controllaradio(oInformativa)=='0')	errors += '- devi prima accettare l\'informativa.\n';
		}	
		
  if (errors) alert('Si sono verificati i seguenti errori:\n'+errors);
  document.MM_returnValue = (errors == '');
}


function IsCodiceFiscale(val, lbl) 
{
  	var error = '';
  	var cf = val;
  	var controllo = new RegExp("([a-zA-Z]{6}[0-9]{2}[a-zA-Z]{1}[0-9]{2}[a-zA-Z]{1}[0-9]{3}[a-zA-Z]{1})");
   	if(!controllo.test(cf)) error += '- ' + lbl + ' deve essere un codice fiscale corretto!\n';
	return error;
}

function IsPartitaIva(val, lbl) 
{
  	var checkstr = "0123456789";
  	var error = '';
	var bError = false;
	var n = val.length;
	if (n != 11)	{ bError = true; }
  	for (i = 0; i < val.length; i++) {
 		if (checkstr.indexOf(val.substr(i,1)) < 0) 
		{
 	     		bError = true;
 		}
  	}
   	if(bError) error += '- ' + lbl + ' deve essere una partita iva corretta!\n';
	return error;
}

function IsDate(o, lbl)
{
  var checkstr = "0123456789";
  var DateValue = o.value;
  var DateTemp = "";
  var separatore = "/";
  var day;
  var month;
  var year;
  var errmsg = '';
  var leap = 0;
  var i;
  for (i = 0; i < DateValue.length; i++) {
 	if (checkstr.indexOf(DateValue.substr(i,1)) >= 0) {
 	     DateTemp = DateTemp + DateValue.substr(i,1);
 	}
  }
  DateValue = DateTemp;
  if (DateValue.length != 8) { errmsg += '- ' + lbl + ' deve essere nel formato gg/mm/aaaa\n'; }
  year = DateValue.substr(4,4);
  if (year == 0) { errmsg += '- L\'anno in ' + lbl + ' deve essere di quattro cifre\n'; }
  month = DateValue.substr(2,2);
  if ((month < 1) || (month > 12)) { errmsg += '- Il mese in ' + lbl + ' deve essere compreso tra 1 e 12\n'; }
  day = DateValue.substr(0,2);
  if ((day < 1) || (day > 31)) { errmsg += '- Il giorno in ' + lbl + ' deve essere compreso tra 1 e 31\n'; }
  if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)) { leap = 1; }
  if ((month == 2) && (leap == 1) && (day > 29)) { errmsg += '- In ' + lbl + ' il giorno non puņ essere maggiore di 29\n'; }
  if ((month == 2) && (leap != 1) && (day > 28)) { errmsg += '- In ' + lbl + ' il giorno non puņ essere maggiore di 28\n'; }
  if ((day > 31) && ((month == "01") || (month == "03") || (month == "05") || (month == "07") || (month == "08") || (month == "10") || (month == "12"))) { errmsg += '- In ' + lbl + ' il giorno non puņ essere maggiore di 31\n'; }
  if ((day > 30) && ((month == "04") || (month == "06") || (month == "09") || (month == "11"))) { errmsg += '- In ' + lbl + ' il giorno non puņ essere maggiore di 30\n'; }
  if (errmsg == '') { o.value = day + '/' + month + '/' + year; }
  return errmsg;
}

function showHide() {
	if (arguments.length>0) {
		for (i=0;i<arguments.length;i++) {
			idRow=arguments[i];
			var newClass = "";
			var rowNode = document.getElementById(idRow);
			var imgId = document.getElementById(idRow + "img");
			if(rowNode.className=="hide") {
				newClass = "view"; //class4Show;
			} else {
				newClass = "hide";
			}
			rowNode.className = newClass;
		}
	}
}
					
function showHideSecond() {
	if (arguments.length>0) {
		for (i=0;i<arguments.length;i++) {
			idRow=arguments[i];
			var newClass = "";
			var rowNode = document.getElementById(idRow);
			var imgId = document.getElementById(idRow + "img");
			rowNode.className="hide";
		}
	}
}					

function IndiciPagine ( Pagina, num ){
  var NPagina = 0
  var Nnum = 0
  NPagina = Pagina;
  Nnum = num;
  frmInvia.PaginaCorrente.value= NPagina + Nnum ;
  frmInvia.submit();
	}

/***************/
/* per schede urp */
function GetDivVal(thediv)
{    
var retval = "";
    if (document.getElementById(thediv)!=null && document.getElementById(thediv)!="undefined")
    {
        retval = document.getElementById(thediv).innerHTML; 
    }
    return retval;
}


/* per schede urp */
function GetDivVal(thediv)
{    
    var retval = "";
    if (document.getElementById(thediv)!=null && document.getElementById(thediv)!="undefined")
    {
        retval = document.getElementById(thediv).innerHTML; 
    }
    return retval;
}

function doPrintURP()
{ 
    var disp_setting="toolbar=no,location=no,directories=no,menubar=no,scrollbars=yes,width=800,height=600,resizable=yes"; 
    var prn_width = 600;
    var arrdiv = new Array("div_testa_prn","div_destinatari","div_requisiti","div_modalita","div_presdom","div_approfondimenti","div_tempi","div_rilascio","div_rinnovo","div_leggiart");
    var content_value = "";
    for (i=0;i<arrdiv.length;i++)
    {
        content_value += "<tr><td>" + GetDivVal(arrdiv[i]) + "</td></tr>"; 
    }

    var arrdiv2 = new Array("div_mattino","div_pomeriggio","div_sabato","div_tel","div_fax","div_indirizzo","div_email_prn","div_links_prn");
    var content_value2 = "";
    for (i=0;i<arrdiv2.length;i++)
    {
        content_value2 += GetDivVal(arrdiv2[i]); 
    }

    var docprint=window.open("","",disp_setting); 	  
    docprint.document.open(); 
    docprint.document.write('<html><head>'); 
    docprint.document.write('<link rel="stylesheet" href="stili.css" type="text/css">'); 
    docprint.document.write('</head><body style="background-image:url(img/home/void.gif)">'); //onLoad="self.print();"
    docprint.document.write('<table width="' + prn_width + '" border="0" cellspacing="0" cellpadding="8"><tr><td valign="top">');
    docprint.document.write(content_value);          
    docprint.document.write('</td></tr></table>');
    docprint.document.write('<table width="' + prn_width + '" border="0" cellspacing="0" cellpadding="8"><tr><td valign="top">');
    docprint.document.write('<table width="100%" border="0" cellspacing="2" cellpadding="0"><tr><td valign="top">');
    docprint.document.write('<img src="img/internopagina/schedapratica.gif ">');          
    docprint.document.write(content_value2);          
    docprint.document.write('</td></tr></table>');
    docprint.document.write('</td></tr></table>');
    docprint.document.write('<table width="' + prn_width + '" border="0" cellspacing="0" cellpadding="8"><tr><td valign="top">');
    docprint.document.write('<br><br><input type="button" value="Stampa" onClick="self.print();" style="border:1px solid #000000; background-color:#FFFFFF; color:#000000"><br><br>');
    docprint.document.write('</td></tr></table>');
    docprint.document.write('</body></html>'); 
    docprint.document.close(); 
    docprint.focus(); 
    //docprint.close(); 
}

/* funzione per login usato nelle Aree protette gestire dall'informatica della Ppovincia  */
function doLogin() {
 df = document.getElementById("theform");
 if (df.user.value!="" && df.pwd.value!="") {
  df.act.value="login";
  df.submit();
 } else {
  alert('Compilare correttamente la form!');
 }
}

/* Quick Calendario  */
function QuickCalCMese(PrSet,UlSet,MesPic,AnnoPic,frmform)
{    
	var oFrm = MM_findObj(frmform);
	if (oFrm){	
		oFrm.PrimoSett.value=PrSet;
		oFrm.UltimoSett.value=UlSet;
		oFrm.MesePiccolo.value=MesPic;
		oFrm.AnnoPiccolo.value=AnnoPic;
/*		document.getElementById(oFrm).submit();*/
		oFrm.submit();
	}
}

function QuickCal(PrSet,UlSet,Set,frmform)
{    
	var oFrm = MM_findObj(frmform);
	if (oFrm){
		oFrm.PrimoSett.value=PrSet;
		oFrm.UltimoSett.value=UlSet;
		oFrm.Sett.value=Set;
		/*document.getElementById(oFrm).submit();	*/	
		oFrm.submit();
	}
}

/*usato nella newsletter creata dal Serv. informatico della Prov. MO*/
function invalid() 
{
	if (document.getElementById("email").T3.value.length < 6) {
		alert("Inserire l'indirizzo email!");
		return false;
	 }
	 
	 return true;
}
		
function invia(id) 
{
	if (invalid()) {
		if ((id==0 && confirm('Procedere con la cancellazione dalla newsletter?')) || (id==1)) {
			document.getElementById("email").azione.value=id;
			document.getElementById("email").submit();
		}
	}
}

/* - usato dell'applicazione PIAP */
	function paginatore(loc) {
			location.href=loc;
	}

/**/