//==================================================================

//------------------------------------------------------------------  IMPOSTAZIONE MOUSE DX

function Disabilita(){
	if(event.button==2)
		alert("FUNZIONE DISABILITATA")
		}
//------------------------------------------------------------------  DATA E TIMER

//------------------------------- DATA STANDARD

//--- IN mSEC
function DataMs(d){
	var D=new Date(d)
	return D.getTime()
		}
		
//--- DATA E ORA	
function Data(d){
	if(isNaN(d))
		var D=new Date(d)
	else	{
		var D=new Date()
        	D.setTime(d)
        		}
	var g=D.getDate()<10? '0'+D.getDate(): D.getDate()
	var m=(D.getMonth()+1)<10? '0'+(D.getMonth()+1): (D.getMonth()+1)
	var a=D.getYear()+''; a=a.substring(2,a.length)
	var data=g+'/'+m+'/'+a
       
	var ora= D.getHours()<10? '0'+D.getHours(): D.getHours() 
	var min= D.getMinutes()<10? '0'+D.getMinutes(): D.getMinutes() 
	var sec=D.getSeconds()<10? '0'+D.getSeconds(): D.getSeconds()

	var ora=ora+':'+min//+':'+sec
	return (data+' '+ora)   
		}
		
//--- SOLO DATA		
function DataCorta(d){
	var data=Data(d).substring(0,Data(d).indexOf(' '))
	return data
		}
		
//------------------------------- TIMER

//---- PERCHE' SIA EFFICACE E DISCRIMINI IL NUMERO DI TENTATIVI E' NECESSARIO CHE LA CONDIZIONE DI VERITA' NELLA FUNZIONE DA RITARDARE 
	// GENERI UN ERRORE FINCHE' NON VIENE SODDISFATTA. ES:
	// if(azione.length<1) cazzullo()	(METODO INESISTENTE PER FARGLI GENERARE UN ERRORE E FAR RITENTARE IL TIMER)

function Timer(sec,tentativi,funzione){		// --- L'ARGOMENTO FUNZIONE DEVE ESSERE PASSATO COME STRINGA! SEC=INT TENTATIVI=INT
	for(var i=0; i<tentativi; i++){
		try{eval(funzione); var esito=true; break}
		catch(error){
			var data1=DataMs(Date()), data2=0
			data1=(data1*1)+(sec*1000)
			while((data2*1)<data1){
				data2=DataMs(Date())
					}
			var esito=false
				}
			}
	return esito
		}


//==================================================================

//------------------------------------------------------------------ FRAMESET

//------------------------------- GENERA IL FRAMESET

function Frameset(index,pag){
	if(top==window)
		pag!=null?location.replace(index+'#'+pag):location.replace(index)
		}  
			
//------------------------------- APRI IL FRAME SU LOCATION.HASH 
//--- RESTITUISCE UN ARRAY DI N.LINKS
function ApriFrame(){
	if(top.location.hash!=''){ 
		var clic=new Array()
		clic=top.location.hash.substring(1).split(',')
		var nClic= clic.length
		for(var i=0; i<nClic; i++)
       			document.links[clic[i]].onclick()
       			}
 	       	}

//------------------------------- ACCENDE IL GRASSETTO SUL MENU DEL FRAME
function Link(id){
	for(var i=0; i<document.links.length; i++)
		document.links[i].style.fontWeight="normal"
	if(id!=null)
		parent.document.getElementById(id).style.fontWeight="bold"
		}
		
//==================================================================

//------------------------------------------------------------------ STRINGHE

//------------------------------- CODIFICA TESTO
//--- TOGLI SPAZI
function TogliSpazi(testo){
	var testo2=new String()
	testo2=testo.replace(/\s+/g,"")
	return testo2
		}
		
//--- CONVERTI CAPORIGA			
function ConvertiCaporiga(testo){
	testo=testo.replace(/\n/g,'<br>')			
	return testo
		}		
					
//--- DISATTIVA HTML
function DisattivaHTML(testo){
	testo=testo.replace(/</g,'&lt;')
	testo=testo.replace(/>/g,'&gt;')
	return testo
		}
		
//--- RIMETTI HTML
function RimettiHTML(testo){
	testo=testo.replace(/&lt;br&gt;/g,'<br>')
	return testo
			}
			
//--- CONVERTI IN MAIUSCOLO
function Maiuscolo(testo){
	testo=testo.toUpperCase(); 
	return testo
			}
			
//--- CONVERTI IN MINUSCOLO
function Minuscolo(testo){
	testo=testo.toLowerCase(); 
	return testo
			}
			
//------------------------------- CODIFICA INPUT
function CodificaInput(testo){
	testo=new String(testo)
	testo=testo.replace(/'/g,"´")
	testo=escape(testo)
	return testo
		}
		
//------------------------------- DECODIFICA OUTPUT

function DecodificaOutputHTML(testo){
	testo=unescape(testo)
	testo=ConvertiCaporiga(testo)	
	testo=DisattivaHTML(testo)
	return testo
		}				

//------------------------------- CODIFICA PREZZO   

//--- PREZZO ITALIANO
function PrezzoItaliano(prezzo){      
	prezzo=prezzo+'';   
	if(prezzo.lastIndexOf('.')!=-1){
		if(prezzo.lastIndexOf('.')==(prezzo.length-2))
			prezzo=prezzo+'0'
				}
        else 
	 	prezzo=prezzo+'.00'
	return prezzo.replace('.',',')
		}  
		  
//--- PREZZO INGLESE
function PrezzoInglese(prezzo){
	prezzo=prezzo+'';   
	if(prezzo.indexOf(',',prezzo.length-2)>-1)
		prezzo=prezzo+'0'; 
	else if(prezzo.indexOf(',',prezzo.length-3)<0)
		prezzo=prezzo+',00';
		
	prezzo=prezzo.replace(/,/,'.')+''	
       	return prezzo
      		}

//------------------------------- CODIFICA QUERYSTRING

//--- MIO URLENCODE
function UrlEncode(testo){
	testo=escape(testo)
	testo=testo.replace(/\+/g,'plusplus')
	return testo
		}

//--- MIO HTMLENCODE
function HtmlEncode(testo){
	testo=unescape(testo)
	testo=testo.replace(/&amp;/g,String.fromCharCode(38))
	testo=testo.replace(/plusplus/g,String.fromCharCode(43))
	return testo
		}					

//==================================================================

//------------------------------------------------------------------ ARRAY		
//------------------------------- ORDINA ARRAY DI ARRAY NUMERICI
//--- L'ARGOMENTO "ORDINE" E' OPZIONALE. VALORE PREVISTO="crescente". SE OMESSO L'ARRAY E' DECRESCENTE PER DEFAULT
function Ordina(arrayA,elemento,ordine){
	var arrayB=new Array(arrayA[0])
	for(var i=1; i<arrayA.length; i++){
		arrayB[i]=arrayA[i]
		if(arrayB[i][elemento]>arrayA[0][elemento]){
			arrayB[0]=arrayB[i]
			arrayB[i]=arrayA[0]
			arrayA[0]=arrayA[i]
			arrayA[i]=arrayB[i]
			i=1
				}
		if(arrayB[i][elemento]>arrayA[i-1][elemento]){
			arrayB[i-1]=arrayB[i]
			arrayB[i]=arrayA[i-1]
			arrayA[i-1]=arrayA[i]
			arrayA[i]=arrayB[i]
			i=1
				}
			}
	return ordine=='crescente'? arrayB.reverse(): arrayB
		}	
		
//------------------------------- NON DUPLICARE ELEMENTI DI ARRAY 

function NonDuplicar(arrayA){
	var arrayB=new Array(1), m=0
	for(var i=0; i<arrayA.length; i++){
		for(var n=0; n<arrayB.length; n++)	
			if(arrayA[i]+''==arrayB[n]+'') break
		if(n==arrayB.length)
			arrayB[m++]=arrayA[i]
			}
	return arrayB
		}

		
//------------------------------- SOSTITUISCI FUNZIONE SPLICE

function Splice(arrayA,elemento){
	var arrayB=new Array()
	for(var i=0,n=0; i<arrayA.length;i++)
		if(i!=elemento){
			arrayB[n]=arrayA[i]
			n++
				}
	return arrayB
		}		
		
//==================================================================

//------------------------------------------------------------------ FORM

//------------------------------- SELECT BOX

function NumeriSelect(selectBox,min,max){
	var n=0
	for(var i=min; i<max; i++){
		var opt=new Option(i,i,false,false)
		selectBox.options[n++]=opt
			}
		}

//------------------------------- CONTROLLO
//--- SE QUALCHE PIATTAFORMA NON SUPPORTA L' APPLET DI CODIFICA DELLA EMAIL, IO SCAVALLO IL BUG METTENDO UN TRY - CATCH
	// SULLA FUNZIONE CODIFICA(). LA MAIL NON VIENE CODIFICATA E VIENE PASSATA ALLA PAGINA ASP SUCCESSIVA DOVE LA FUNZIONE
	// "AGGIUNGIRECORD()" PREVEDE CHE SE TROVA IL CARATTERE @ NON PROCEDE ALLA DECODIFICA DELLA EMAIL.

function ControllaForm(ogg){
	var emailExists=false
	for(var i=0; i<ogg.length; i++){
		if((ogg[i].value=='') && (ogg[i].title!="facoltativo"))break
		if(ogg[i].title!="facoltativo"){
			if(ogg[i].name.toUpperCase()=='EMAIL' &&(ogg[i].value.indexOf('@')<0 || ogg[i].value.indexOf('.')<0 || ogg[i].value.length<8)){
				alert("Email non corretta.")
				return false
					}
				}	
		if(ogg[i].name.toUpperCase()=='EMAIL'){
			ogg[i].value=''+ogg[i].value.toLowerCase()
			var emailExists=true
					}			
			}
	var verifica=i<ogg.length-1?false:true  
	if(!verifica)alert('Compilazione incompleta! ('+ ogg[i].name+')')
	else	ControllaCaratteriForm(ogg)

	if(verifica&&emailExists){
		try{
		stringaCriptata=document.applets[0].DammiDato(document.forms[0].email.value)+''	//CODIFICA EMAIL
			}
		catch(error){
			return verifica
				}
		for(var i=0; i<1000000; i++){}
			
		if(stringaCriptata.length<1)
			return verifica
		else	{
			document.forms[0].email.value=stringaCriptata
				}
			}
	return verifica			
		}	
		
function ControllaCaratteriForm(ogg){
	for(var i=0; i<ogg.length; i++){
		if(ogg[i].type.indexOf('select')<0)
			ogg[i].value=CodificaInput(ogg[i].value)
			}
		}
		
function RipristinaCaratteriForm(ogg){
	for(var i=0; i<ogg.length; i++){
		if(ogg[i].type.indexOf('select')<0)
			ogg[i].value=unescape(ogg[i].value)
			}
		}
		
function ControllaMaiuscoloForm(form){	
	for(var n=0; n<form.length; n++)
		form[n].value=form[n].name=='email'?form[n].value.toLowerCase():form[n].value.toUpperCase()
		}
		
//------------------------------- CRIPTA		
function Codifica(ogg){
	stringaCriptata=document.applets[0].DammiDato(ogg)+''
	return stringaCriptata
		}	


//==================================================================

//------------------------------------------------------------------ LAYOUT

//------------------------------- POPUP    
function Apri(URL,nome,w,h,sta,scr,rsz){
	var l=(screen.availWidth-w)/2
	var t=(screen.availHeight-h)/2
	if(nome=='')nome='pop'
	popUp=open(URL,nome,'left='+l+',top='+t+',width='+w+',height='+h+',menubar=0,toolbar=0,status='+sta+',scrollbars='+scr+',resizable='+rsz)
		}

//------------------------------- CREDITS		
function Credits(){
	l=document.all?layer:document.getElementById('layer')
	l.style.visibility='visible'
	document.onclick=Chiudi  
	try{
		parent.frames[1].document.onclick=Chiudi
		parent.frames[1].frames[0].document.onclick=Chiudi 
			}
	catch(error){}
		}  
function Chiudi(){l.style.visibility='hidden'}      


//------------------------------- TESTO BLINK
n=0	
function TestoBlink(){
	var ogg=document.getElementsByTagName('span')
	n++
	if(n==ogg.length){ogg[n-1].style.color='008822'; n=0; ogg[n].style.color='00cc33'}
	else {ogg[n].style.color='00cc33'; ogg[n-1].style.color='008822'}
	window.setTimeout('TestoBlink()',100)
		}


//------------------------------- CONTROLLA DIMENSIONI IMG

function LimitaImg(maxW, maxH){
	for(var i=0; i<document.images.length; i++){
		var w=document.images[i].width
		var h=document.images[i].height     
		
		if(w>maxW){        
			var hw=(h/w); 
			w=maxW
			h=maxH*hw 
				}   
	      		if(h>maxH){      
			var wh=(w/h)
			h=maxH
			w=maxW*wh
				}                                             
		document.images[i].height=h; document.images[i].width=w; 
			}
		}

//------------------------------- CERCA IMG SU ERRORE DI ESTENSIONE
//--- LA FUNZIONE E' CHIAMATA DA onerror. FILE=THIS
//--- SU ERRORE SOSTITUISCE .GIF CON .JPG O VICEVERSA; 

function CercaImg(percorsoFile, spazioImg){
	eval(spazioImg).onerror=function(){
		var stringaFile=unescape(percorsoFile)
		var percorso=stringaFile.substring(0,stringaFile.lastIndexOf('.'))  
		var estensione=stringaFile.slice(stringaFile.lastIndexOf('.'))=='.gif'? '.jpg': '.gif' 
		eval(spazioImg).src=unescape(percorso)+estensione
			}
		}
		
//------------------------------- FADE IMG, TESTO E AUDIO
//--- CREARE img1 e img2 SU UNO STESSO LAYER CON POSIZIONAMENTO ASSOLUTO
//--- CREARE UN ARRAY testo[0,1,2...] E titolo[0,1,2...] DA RUOTARE CON LE IMMAGINI. testo[0]=" ", titolo[0]=" "
//--- LA LUNGHEZZA DELLE STRINGHE NELL'ARRAY TESTO DIVISO IL COEFFICIENTE DETERMINA LA VELOCITA' DI ROTAZIONE (testo[n].length/coeff=V)
//--- CREARE I TAG EMBED (autostart=false)
//--- CHIAMARE LE IMMAGINI DA RUOTARE CON NUMERI PROGRESSIVI, PARTENDO DA 1
//--- CREARE OGGETTO: fade= new FadeConstructor(numImg, cartellaImg, estensioneImg, tempo)
//--- ISTANZIARE IL PRELOAD IMG: fade.Preload()
//--- ISTANZIARE LO SLIDER: fade.Slide()

//--- COSTRUTTORE
function FadeConstructor(numImg, cartellaImg, estensioneImg, coeff){
	this.numImg= numImg
	this.cartellaImg= cartellaImg
	this.estensione= estensioneImg
	this.coeff=coeff
	this.Preload=Preload
	this.Slide=Slide
		}
		
//--- PRELOAD IMG
function Preload(){
	var im=new Array()
	for(var i=0; i<fade.numImg; i++){
		im[i]=new Image(); 
		im[i].src=fade.cartella+'/'+i+'.'+fade.estensione
			}
		}	

//--- AUDIO			
function Audio(){
	if(parent.parent.audio)
		try{frames[0].document.embeds[n-1].Play()}
		catch(error){}
    		}

//--- SLIDER 						
function Slide(){
	if(i>(testi[n-1].length/fade.coeff)){
		if(n==(fade.numImg+1)){
			try{parent.oggettoSuccessivo.onclick()}
			catch(error){}
			n++
				}
		else{
			n++
			Fade(); Audio();
			i=0; 
				}
			}
	else	i++
	if(n<(fade.numImg+2)) 
		slide=setTimeout('Slide()',100)
		}    

//--- FADE IMG E TXT		
var opacity1=100, opacity2=0, opacity3=100			
function Fade(){
	document.getElementById('img1').src=n<(fade.numImg-1)? "img/0.jpg": "img/"+fade.cartellaImg+"/"+(n-2)+".jpg"
	document.getElementById('img2').src=n>(fade.numImg)? "img/"+fade.cartellaImg+"/"+(fade.numImg)+".jpg": "img/"+fade.cartellaImg+"/"+(n-1)+".jpg"
	
	opacity1=(opacity1-4)
	opacity2=100-opacity1
       	opacity3= opacity1<50? (opacity3+16): (opacity3-16)
       		       			
       	if(opacity1<50){
       		parent.document.getElementById('titolo').innerHTML=titoli[n-1]
		parent.document.getElementById('didascalia').innerHTML=ConvertiCaporiga(testi[n-1])	
		}		
	var img1=document.getElementById('img1'), img2=document.getElementById('img2'), didascalia=parent.document.getElementById('didascalia'), titolo=parent.document.getElementById('titolo')
	img1.style.opacity = (opacity1 / 100); img2.style.opacity = (opacity2 / 100) 	//--- W3c
    	img1.style.MozOpacity = (opacity1 / 100); img2.style.MozOpacity = (opacity2 / 100) //--- Mozilla/NN
    	img1.style.KhtmlOpacity = (opacity1 / 100); img2.style.KhtmlOpacity = (opacity2 / 100) //--- Safari
    	img1.style.filter = "alpha(opacity="+opacity1+")"; img2.style.filter= "alpha(opacity="+opacity2+")" //--- IE
 	didascalia.style.opacity = (opacity3 / 100); //--- W3c
    	didascalia.style.MozOpacity = (opacity3 / 100); //--- Mozilla/NN
    	didascalia.style.KhtmlOpacity = (opacity3 / 100); //--- Safari
    	didascalia.style.filter = "alpha(opacity="+opacity3+")" //--- IE
 	titolo.style.opacity = (opacity3 / 100); //--- W3c
    	titolo.style.MozOpacity = (opacity3 / 100); //--- Mozilla/NN
    	titolo.style.KhtmlOpacity = (opacity3 / 100); //--- Safari
    	titolo.style.filter = "alpha(opacity="+opacity3+")" //--- IE    	    	
	if(opacity1>0) setTimeout('Fade()',50)
	else	opacity1=100
		}	

//--- AUDIO PLAY - STOP		
function PlayStop(oggetto){    
        if(oggetto.value=="FAI UNA PAUSA"){
       		clearTimeout(slide)
       		oggetto.value="RIPRENDI"
       		try{
       			parent.parent.audio? frames[0].document.embeds[n-1].Pause(): false
       				}
       		catch(error){
       			parent.parent.audio? frames[0].document.embeds[n-1].Stop(): false
       				}
       			}
       	else	{
		fade.Slide()
       		oggetto.value="FAI UNA PAUSA" 
       		parent.parent.audio? frames[0].document.embeds[n-1].Play(): false
       			}   
		}

//==================================================================

//------------------------------------------------------------------ XML CLIENT
//------------------------------- CONNETTI XML    (SOLO IE)

function OggXML(){
	var oggXML = new ActiveXObject("Microsoft.XMLDOM");
       	oggXML.async=false; //Enforce download of XML file first. IE only.
     	oggXML.load(paginaXML)
     	return oggXML
		}

//------------------------------- LEGGI XML  
//--- ESTRAE UN ARRAY DI TAG CHE SODDISFANO UN ATTRIBUTO	  
	  		
function EstraiXML1(nomeAttributo,valoreAttributo){ 
       	var oggXML=OggXML()
     	var tags=new Array(); tags=oggXML.documentElement.childNodes
     	var estratto=new Object(); estratto.titoli=new Array(); estratto.sottotitoli=new Array(); estratto.testi=new Array()   
	for(var i=0, n=0; i<tags.length; i++){
		if(tags[i].getAttribute(nomeAttributo)==valoreAttributo){
		       estratto.titoli[n]=tags[i].getAttribute('titolo')
		       estratto.sottotitoli[n]=tags[i].getAttribute('sottotitolo')
		       estratto.testi[n]=tags[i].getAttribute('testo')
			n++
				}
			}       
  	return estratto
		}  
//--- ESTRAE UN ARRAY DI TAG CHE SODDISFANO LIVELLO E SOTTOLIVELLO	  
	  		
function EstraiXML(livello,sottolivello){ 
       	var oggXML=OggXML()
     	var tags=new Array(); tags=oggXML.documentElement.childNodes
     	var estratto=new Object(); estratto.titoli=new Array(); estratto.sottotitoli=new Array(); estratto.testi=new Array()   
	for(var i=0, n=0; i<tags.length; i++){
		if(tags[i].getAttribute('livello')==livello&&tags[i].getAttribute('sottolivello')==sottolivello){
		       estratto.titoli[n]=tags[i].getAttribute('titolo')
		       estratto.sottotitoli[n]=tags[i].getAttribute('sottotitolo')
		       estratto.testi[n]=tags[i].getAttribute('testo')
			n++
				}
			}       
  	return estratto
		}


//------------------------------- SALVA XML (solo I.Explorer)

function DatiXML(){
	var estraiXML=new Object, campi=new Array(), valori=new Array(), attributi=new Array(); estraiXML.campi=new Array(); estraiXML.valori=new Array()
	var oggXML = new ActiveXObject("Microsoft.XMLDOM");
	oggXML.async=false; //Enforce download of XML file first. IE only.
	oggXML.load(paginaXML)
	var campi=new Array(), valori=new Array(), attributi=new Array()
	if(oggXML.documentElement==null){
		alert("La pagina non esiste.")
		campi[0]=""; valori[0]=""
				}
	else if(oggXML.documentElement.childNodes==null){
		alert("Non esistono record da estrarre.")	
		campi[0]=""; valori[0]=""
				}
	else{
		for(var i=0; i<oggXML.documentElement.childNodes.length; i++){
			attributi[i]=new Array(); campi[i]=new Array(); valori[i]=new Array()
			attributi[i]=oggXML.documentElement.childNodes[i].attributes	
			
			for(var n=0; n<attributi[i].length; n++){
		 		campi[0][n]=attributi[i][n].name
				valori[i][n]=attributi[i][n].value
					}
	  			}
			}
		estraiXML.campi=campi
		estraiXML.valori=valori
		return estraiXML
		}
		
function CreaPaginaXML(){
	var oggXML = new ActiveXObject("Microsoft.XMLDOM");
	var documento=oggXML.createElement('db')
	var header=oggXML.createProcessingInstruction('xml', 'version="1.0"')
	oggXML.appendChild(header)
	oggXML.appendChild(documento)
	oggXML.save("pagina.xml")
		}
		
function ScriviPaginaXML(){
	var oggXML = new ActiveXObject("Microsoft.XMLDOM");
		oggXML.async=false; //Enforce download of XML file first. IE only.
		oggXML.load(paginaXML)
	if(oggXML.documentElement==null)
		CreaPaginaXML()
	for(var i=0; i<document.forms[0].length-1; i++){
		attributi.nome[i]=document.forms[0][i].name
		attributi.valore[i]=document.forms[0][i].value
			}
	if(CercaDatoXML(oggXML.documentElement,attributi.nome[0],attributi.valore[0]))
		alert("Record già presente sul database ("+ attributi.nome[0]+": "+attributi.valore[0]+").")
	else	{
	var nodo=oggXML.createElement("record")
	oggXML.documentElement.appendChild(nodo)
	for(var i=0; i<attributi.nome.length; i++)
		nodo.setAttribute(attributi.nome[i], attributi.valore[i])
	oggXML.save(paginaXML)
			}
		}
		
function ModificaTagXML(nomeChiavePrimaria, valoreChiavePrimaria){
	var oggXML = new ActiveXObject("Microsoft.XMLDOM");
		oggXML.async=false; //Enforce download of XML file first. IE only.
		oggXML.load(paginaXML)
	for(var i=0; i<document.forms[0].length-1; i++){
		attributi.nome[i]=document.forms[0][i].name
		attributi.valore[i]=document.forms[0][i].value
			}
	for(var i=0; i<oggXML.documentElement.childNodes.length; i++){
		if(oggXML.documentElement.childNodes[i].getAttribute(nomeChiavePrimaria)==valoreChiavePrimaria){
			for(var n=0; n<oggXML.documentElement.childNodes[i].attributes.length; n++)
				oggXML.documentElement.childNodes[i].attributes[n].value=attributi.valore[n]
				}
			}
	oggXML.save(paginaXML)
		}

function EliminaTagXML(nomeChiavePrimaria, valoreChiavePrimaria){
	var oggXML = new ActiveXObject("Microsoft.XMLDOM");
		oggXML.async=false; //Enforce download of XML file first. IE only.
		oggXML.load(paginaXML)
	for(var i=0; i<oggXML.documentElement.childNodes.length; i++){
		if(oggXML.documentElement.childNodes[i].getAttribute(nomeChiavePrimaria)==valoreChiavePrimaria)
			oggXML.documentElement.removeChild(oggXML.documentElement.childNodes[i])
			}
	oggXML.save(paginaXML)
		}
		
						
//---- TROVA IL VALORE DI UN ATTRIBUTO IN TUTTI I TAG

function CercaDatoXML(root,nomeAttributo,valore){
	for(var n=0; n<root.childNodes.length; n++){
		if(root.childNodes[n].getAttribute(nomeAttributo)==valore){
			var gotcha=true; break
				}
		else var gotcha=false
			}
	return gotcha
		}

//==================================================================

//------------------------------------------------------------------ FILE SYSTEM OBJECT CLIENT

//------------------------------- LEGGI INFO  
  		
function ListaDriver(){
	var fs = new ActiveXObject("Scripting.FileSystemObject");
   	var enu= new Enumerator(fs.drives), listaDrv=new Array()
	for(var i=0;!enu.atEnd();enu.moveNext()) 
		listaDrv[i++] = enu.item()
	return listaDrv     
		}

//------------------------------- SCRIVI FILE

function CreaFile(percorso,testo){
	var fs = new ActiveXObject("Scripting.FileSystemObject");
	if(fs.fileExists(percorso)){ 
		if(confirm("File esistente. Sovrascrivo?")){
			fs.DeleteFile(percorso)
			var ogg=fs.OpenTextFile(percorso,2,true)
				}
			}
	else	{
		var ogg=fs.OpenTextFile(percorso,2,true)
		ogg.write(testo)
			}
		}
		
function CreaFolder(percorso){
	var fs = new ActiveXObject("Scripting.FileSystemObject");      
	if(!fs.folderExists(percorso))
       		fs.CreateFolder(percorso)
		}  
		
function EliminaFolder(percorso){
	var fs = new ActiveXObject("Scripting.FileSystemObject"); 
	fs.DeleteFolder(percorso)
		}     
		
function EliminaFile(percorso){ 
	var fs = new ActiveXObject("Scripting.FileSystemObject"); 
	fs.DeleteFile(percorso)
		}       
		
//------------------------------- RINOMINA FOLDER
function RinominaFolder(percorso,arrivo){ 
	var fs= new ActiveXObject("Scripting.FileSystemObject"); 
	var nome=fs.getBaseName(arrivo)
       	try{
       		fs.CopyFolder(percorso,arrivo,true)
       		fs.deleteFolder(percorso)   
       			}
       	catch(error){
       	      	fs.CreateFolder(arrivo)
       			}
		}    
					
//------------------------------- COPIA FILE
function CopiaFile(partenza,arrivo){  
	var fs= new ActiveXObject("Scripting.FileSystemObject"); 
	var nome=fs.getBaseName(arrivo)
	fs.CopyFile(partenza,arrivo,true)
		}
						
//------------------------------- ELENCO FILE/FOLDERS IN CARTELLA (estensione fac.)

function ListaItem(percorso,tipo,estensione){              
	var fs = new ActiveXObject("Scripting.FileSystemObject");               
	var trovaCartella= fs.GetFolder(percorso)             
                                                               
	var enu= new Enumerator(trovaCartella.files), listaFiles=new Array(), listaFilesXML=new Array(), n=0
	for(var i=0;!enu.atEnd();enu.moveNext(),i++) 
		listaFiles[i]=enu.item().name
	if(estensione!=null){
		for(var i=0; i<listaFiles.length; i++) {
			if(listaFiles[i].lastIndexOf("xml")>-1){
				listaFilesXML[n]=listaFiles[i]
				n++
					}
				}
		listaFiles=listaFilesXML
			}
	listaFiles=listaFiles.sort()
	var enu= new Enumerator(trovaCartella.subFolders), listaFolders=new Array()
	for(var i=0;!enu.atEnd();enu.moveNext(),i++)
		listaFolders[i]=enu.item().name
	listaFolders=listaFolders.sort()	
	trovaCartella=null
	delete fs
	switch(tipo){
		case 'files': 	tipo=listaFiles; break
		case 'folders': 	tipo=listaFolders; break
		default: 		tipo=listaFolders.concat(listaFiles)
				} 			
	return tipo
			}																