// JavaScript Document
var urlSito=location.host;
//-- funzione rollover
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_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_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_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];}
}

// MOSTRA - NASCONDI (Split)
function Attiva(Menu) {
objMenu=document.getElementById(Menu);

if (objMenu.style.display == "none") 
{
	objMenu.style.display = "block";
	
}
else 
{
	objMenu.style.display = "none";
	
}
} 




// setta il colore sulle righe * ie 6
function color(val)
{
function sfHover() {
	if(!document.getElementById(val))
    {
        return;
    }
	var sfEls = document.getElementById(val).getElementsByTagName("a");
	for (var i=0; i<sfEls.length; i++) { 
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
			
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}

browsername=navigator.appName;

if (browsername.indexOf("Microsoft")!=-1) {

if (navigator.appVersion.indexOf("6.0")!=-1)
	{
			sfHover(val);
			
	}
}

}


//-- funzioni per ajax
// funzione per assegnare un oggetto XMLHttpRequest
		function assegnaXMLHttpRequest() {
			var
				XHR = null,
				browserUtente = navigator.userAgent.toUpperCase();
			if(typeof(XMLHttpRequest) === "function" || typeof(XMLHttpRequest) === "object")
				XHR = new XMLHttpRequest();
			else if(window.ActiveXObject && browserUtente.indexOf("MSIE 4") < 0) {
				if(browserUtente.indexOf("MSIE 5") < 0)
					XHR = new ActiveXObject("Msxml2.XMLHTTP");
				else
					XHR = new ActiveXObject("Microsoft.XMLHTTP");
			}
			return XHR;
		};

 
var http_request = false;
function makeRequest(val,page,id) {
		
        var postvar=val;//mainSelection.options[mainSelection.selectedIndex].value

	 if(id!="1")
		{
		document.getElementById("col_cent").innerHTML ='<div align="center"><img src="immagini/loader.gif" vspace="30"  ></div>';
		}
			else
			     {
				   document.getElementById("box_link_art").innerHTML ='<div align="center"><img src="immagini/loader.gif" vspace="30"  ></div>';
				 }
				 
		http_request = false;
        if (window.XMLHttpRequest) { // Mozilla, Safari,...
            http_request = new XMLHttpRequest();
            if (http_request.overrideMimeType) {
                //http_request.overrideMimeType('text/xml');
                // See note below about this line
            }
        } else if (window.ActiveXObject) { // IE
            try {
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    http_request = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }

        if (!http_request) {
            alert('Giving up :( Cannot create an XMLHTTP instance');
            return false;
        }
        http_request.onreadystatechange = function(){
		scrivi(postvar,id);
	 
	}
    
	var pg=page+".php";
	
	 
	http_request.open("POST", ""+pg, true);
	http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    http_request.send(postvar);

    }

//-- stampa risultato
function scrivi(postvar,id)
{
	     
	
	switch(id)
	 {
	   case 1 :  div="col_cent";
	   break;
	   case 2 : div="box_link_art";
	   break;
	   case 3 :   div="dispense";
	   break;
	   default :   div="dispense";
	 }
	  alert(div);
	
	
			if (http_request.readyState == 4) 
			{
           
						if (http_request.status == 200) 
						{
							alert(http_request.responseText);
							document.getElementById("dispense").innerHTML = http_request.responseText; 
						
						}
						
						else {
							document.getElementById(''+div).innerHTML ='<div align="center"><br>Problemi di connessione riprovare grazie.</b></div>';
					
						}
         
		 	
			}


    }


//-- funzioni per aggiornamento select.
function azzera(val)
{
var subSelection=document.getElementById(val)
for (var i = subSelection.length - 1; i >= 0; i--) 
subSelection.remove(i); 

var NewOpt = document.createElement('option'); 
	NewOpt.value = ""; 
	NewOpt.text = "-"; 
	try{ 
	subSelection.add(NewOpt, null); //Metodo Standard, non funziona con IE 
	}catch(e){ 
	subSelection.add(NewOpt); // Funziona solo con IE 
	} 
}

function updateSubSelection(XMLResult,select2){
if (http_request.readyState == 4) 
			{
              
						if (http_request.status == 200) 
						{
							
							//Gestisco il documento XML ricevuto e popolo la seconda SELECT 
								var sub_categoria = http_request.responseXML.getElementsByTagName(select2); 
								//Recupero la seconda SELECT 
								var subSelection = document.getElementById(select2); 
								//Scorro gli elementi  
								//alert(http_request.responseText.getElementsByTagName(select2))
								for (var i = 1; i < sub_categoria.length; i++){ 
								//Recupero i vari elementi singoli 
								var item = sub_categoria[i]; 
								//Creo il nuovo elemento OPTION da aggiungere nella seconda SELECT 
								var NewOpt = document.createElement('option'); 
								NewOpt.value = item.getAttribute("value"); 
								NewOpt.text = item.firstChild.nodeValue; 
								//Popolo la seconda SELECT 
								try{ 
								subSelection.add(NewOpt, null); //Metodo Standard, non funziona con IE 
								}catch(e){ 
								subSelection.add(NewOpt); // Funziona solo con IE 
								} 
								} 
						
						}
						
						else {
							alert('Problemi di connessione riprovare grazie.');
					
						}
         
		 	
			}	


}


//-- CREO LA SELECT 
function populateSubSelection(select1,select2,val)
{
        //var postvar=val;//mainSelection.options[mainSelection.selectedIndex].value
		var mainSelection = document.getElementById(select1); 
		var postvar="choice="+mainSelection.options[mainSelection.selectedIndex].value+"&op="+val;
		//Recupero la seconda SELECT 
		var subSelection = document.getElementById(select2); 
		//Svuoto la secondo SELECT 
		for (var i = subSelection.length - 1; i >= 0; i--) 
		subSelection.remove(i); 
		//document.getElementById("col_cent").innerHTML ='<div align="center"><img src="immagini/loader.gif" vspace="30"  ></div>';
		
		http_request = false;
        if (window.XMLHttpRequest) { // Mozilla, Safari,...
            http_request = new XMLHttpRequest();
            if (http_request.overrideMimeType) {
                //http_request.overrideMimeType('text/xml');
                // See note below about this line
            }
        } else if (window.ActiveXObject) { // IE
            try {
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    http_request = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }

        if (!http_request) {
            alert('Giving up :( Cannot create an XMLHTTP instance');
            return false;
        }
        http_request.onreadystatechange = function(){
		updateSubSelection(postvar,select2);
	 
	}
    
	var pg="http://www.aerarium.eu/includes/comune_ajax_fh.php";
	
	http_request.open("POST", ""+pg, true);
	http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    http_request.send(postvar);

    }

function ckNum(campo)
{
var data = document.getElementById(campo).value;

if(data !="")
   {
			if (isNaN(data)) {
						   alert("Sono ammessi solo numeri");
						   document.getElementById(campo).select(); 
						   };
   }
}

//-- privato - azienda
function PrAz()
{
	var tipo=  document.getElementById("tipo_ut1").checked ;
	
	if(tipo == true)
	{
	  val=1;
	}
	 else 
	     {
		   val=2;
		 }

if(val == "2") // azienda

   {	
		  document.getElementById("denominazione").disabled=false;
		  document.getElementById("iva").disabled=false; 
		  document.getElementById("iva").style.background="#FFFFFF";
		  document.getElementById("denominazione").style.background="#FFFFFF";
		 
   }
     else 
	 		{
			  
			  document.getElementById("denominazione").disabled=true;
		 	  document.getElementById("iva").disabled=true;
		      document.getElementById("denominazione").value="";
		 	  document.getElementById("iva").value="";			 
		      document.getElementById("iva").style.background="#CCCCCC";
		      document.getElementById("denominazione").style.background="#CCCCCC";						 
			
			}
}
/*-------------VERIFICA QUIZ ------------------*/
function verifica(){
/*ccollect=new Array()
var inc=0
var alltags=document.all? document.all : document.getElementsByTagName("*")
for (i=0; i<alltags.length; i++){
if (alltags[i].className==classname)
alltags[i].className="true";
}*/

var vere=document.getElementById("true").value;		
var array_vere=vere.split(",");
var risp=document.getElementsByTagName("input");
//-- controllo se sono tutti ckekked
var num='0';
for (i=0; i<risp.length; i++)
 {
   if(risp[i].type== 'radio')
		  {
		      				
			if(risp[i].checked == true)
			   {
			     num++;
				
			   }
		  }
 }


if(num!=array_vere.length)
{
	 alert('Selezionare tutte le risposte.');
	 return;
}
//- controllo risposte
var Rvere='0';

for (i=0; i<risp.length; i++)
	{
		if(risp[i].type== 'radio')
		  {
			 var id=risp[i].value;	
			  //- controllo se è una risp esatta
			  if(risp[i].checked == true)
			   {
			      if( arrayIndexOf(array_vere, risp[i].value)!='-1')
				    {
					  Rvere++;
					}
			   }
			  if( arrayIndexOf(array_vere, id)!='-1')
			   {
				   document.getElementById(id).className="true";
				      
			   }
			    else 
						{
									 
			 				document.getElementById(id).style.color="#999999";	
						}
			 
		  }
		
	}
var tot=array_vere.length;
var totFalse=tot-Rvere;

document.getElementById("result").innerHTML ='<div class="box_risp"><div class="head">Risultato Quiz </div><div class="tab_risp"><table width="100%" border="0"><tr><td width="33%" height="23"><div align="center"><img src="skin/img/corrette_70x12.gif" width="70" height="12" alt="corrette" /></div></td><td width="34%"><div align="center"><img src="skin/img/errate_51x12.gif" width="51" height="12" alt="errate" /></div></td><td width="33%"><div align="center"><img src="skin/img/tot_50x12.gif" width="50" height="12" alt="totali" /></div></td></tr><tr><td><div align="center"><img src="skin/img/spunta_12x12.gif" width="12" height="12" alt="true" /> '+Rvere+'</div></td><td><div align="center"><img src="skin/img/ics_12x10.gif" width="12" height="10" alt="false" /> '+totFalse+'</div></td><td><div align="center">'+tot+'</div></td></tr></table></div></div>';
window.scrollTo(0,0);

document.getElementById("pul_sk").innerHTML ='<input name="Nuovo test" type="button" value="Nuovo test" onclick="window.location.reload()"/> <input name="stampa" type="button" value="Stampa" onclick="stampa();"/>';
}

function arrayIndexOf(array, search) {
        var indice; //contatore
        for (indice in array) {
                if (array[indice] == search)
                        return indice;
        } 
        return -1;
}
/* LISTA DISPENSE */
function disp(post)
{
var alfabeto=new Array('a','b','c','d','e','f','g','h','i','l','m','n','o','p','q','r','s','t','u','v','z')
 for(var i='0'; i<='20'; i++)
	{
     var lettera=alfabeto[i];
	 objMenu=document.getElementById(lettera);
	 if(post==alfabeto[i])
        {
			if(objMenu) 
			objMenu.style.display="block";
		}
			else
				 {
					    
						if(objMenu) 
								{
									objMenu.style.display="none";
								}
				  }
	}
}
/*-------------STAMPA SKEDE ----------------*/
//-- stampa popup 
function leggi()
{
var cont=opener.document.getElementById("stampa_q").innerHTML;
document.getElementById("cn_int").innerHTML = cont;
}
//-- stampa apre popup
function stampa()
{
window.open('stampa.php','Stampa','scrollbars=1,resizable=0,width=700,height=400');
}