function SostituisciCaratteri(vObj){
	v=vObj;
	v=unescape(v);
	
	while(v.indexOf("\xff")>=0){
		v=v.replace ('\xff',' ');
	}
	return(v)

}
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) { //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_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 FieldCheck(obj)
{
	
	
	var strdata;
	
	//strdata=document.activeElement.value;
	strdata=obj.value
	//alert(strdata)
	//Controllo numero	
		
	
		var err=0
		var errorestr=''
		
	  	if (strdata.length != 10) 
		{
			err=1
			errorestr="Il formato della data non e' valido! Il formato corretto e' gg/mm/aaaa."
		}
	

		Giorno = strdata.substring(0, 2)	// Giorno ex d
		sepgm = strdata.substring(2, 3)	// '/'
		Mese = strdata.substring(3, 5)		// Mese ex B
		sepma = strdata.substring(5, 6)	// '/'
		Anno = strdata.substring(6, 10)		// Anno ex f
		
		
		//Controllo base
		if (Mese<1 || Mese>12) 
		{
			err=1
			errorestr="Il mese non e' valido"
		}
		
		if (sepgm != '/')
		{
			err=1
			errorestr="Il formato della data non e' valido! Il formato corretto e' gg/mm/aaaa."
		}
		
		
		if (Giorno<1 || Giorno>31)
		{
			err=1
			errorestr="Il giorno non e' valido!"
		}
		
		if (sepma != '/')
		{
			err=1
			errorestr="Il formato della data non e' valido! Il formato corretto e' gg/mm/aaaa."
		}
				
		if (Anno<0 || Anno>9999)
		{
			err=1
			errorestr="L'anno non e' valido!"
		}		
	
	
		// Controllo avanzato
		// Mesi di 30 giorni
		if (Mese==4 || Mese==6 || Mese==9 || Mese==11){
			if (Giorno>=31) 
			{
				err=1
				errorestr="Il mese non e' valido!"
			}
		}
		else
		{	
			// febbraio
			if (Mese==2){
	
				// febbraio
				var g=parseInt(Anno/4)
				if (isNaN(g)) {
					err=1
				}
				if (Giorno>29) err=1
					if (Giorno==29 && ((Anno/4)!=parseInt(Anno/4))) 
					{
						err=1
						errorestr="Il giorno non e' valido!"
					}
					else
					{
						if (Giorno>31) 
						{
							err=1
							errorestr="Il giorno non e' valido!"
						}
					}
			}			
		}
		if (err==1)
		{
			alert("ATTENZIONE - Errore - " + errorestr )
			document.activeElement.value='';
		
		}
			
		

		
}

function AllegaFile()
{
	
	document.CambioNews.action='upload.asp';
	alert(document.CambioNews.action)
	document.CambioNews.submit();
	
}


function countdown(){

	iniData= new Date(2000,11,31,23,59,59); // data inizio sequenza mesi-1 es. set=8
	oggi= new Date();
	//oggi.setHours(1,1,1,0) ;
	iniDataIt=iniData.getDate()+'-'+(iniData.getMonth()+1)+'-'+iniData.getFullYear()+' '+iniData.getHours()+':'+iniData.getMinutes()+':'+iniData.getSeconds();
	milDif=(iniData-oggi)
	giorni=parseInt(milDif/86400000);  
	milDif=milDif-(giorni*86400000); //millisecondi restanti talti i giorni
	ore=parseInt(milDif/3600000);
	milDif=milDif-(ore*3600000); //millisecondi restanti talti i giorni
	minuti=parseInt(milDif/60000);
	milDif=milDif-(minuti*60000); //millisecondi restanti talti i giorni
	secondi=parseInt(milDif/1000);
	milDif=milDif-(secondi*1000); //millisecondi restanti talti i giorni
	testo= giorni+' giorni, '+ore+' ore, '+minuti+' minuti,e '+secondi+' secondi';
	//alert(testo); //commentare
	//return testo

	if (document.layers){
alert (document.layers);
		document.layers.span1.document.write(testo);
		document.layers.span1.document.close();
	}else if (document.all){
alert (document.all);
		span1.innerHTML=testo;
	}
setTimeout("countdown()",1000);
}







function aprifinestra(URL)
{
	finestra=window.open(URL,"Nuova_Finestra","width=750,height=450,history=0,resizable,status=0,scrollbars=1,menubar=0,toolbar=1,titlebar=0");
	window.onfocus=function ChiudiFinestra(){finestra.close();};
}

function aprifinestraIndietro(URL)
{
	finestra=window.open(URL,"Nuova_Finestra","width=750,height=450,history=0,resizable,status=0,scrollbars=1,menubar=0,toolbar=1,titlebar=0");
	window.onfocus=function ChiudiFinestra(){finestra.close();};
}





function ModElim(Operazione,obj,campo,azione1,azione2,tipo)
{


	obj.action=azione1;
	obj.ModEl.value=Operazione;

	if (campo.options[campo.selectedIndex].value==0)
	{
		alert("selezionare " + tipo + "!");
		obj.ModEl.value='';
		obj.action=azione2;		
		return false;
	}	
	else
	{
		if (Operazione=="Elimina") 
		{
			if (!confirm("Si vuole procedere all'eliminazione?"))
				return false;	
			else
			{
				obj.submit();
				obj.ModEl.value='';
			}
		}
		else if (Operazione=="Modifica") 
		{
			if (!confirm("Si vuole procedere alla modifica?"))
				return false;	
			else
			{
				obj.submit();
				obj.ModEl.value='';
			}
		}
		else if (Operazione=="Archivia") 
		{
			if (!confirm("Si vuole procedere Con Archiviazione?"))
				return false;	
			else
			{
				obj.submit();
				obj.ModEl.value='';
			}
		}

	}

}

function new_window() {
	var url="http://www.adobe.com/products/acrobat/readstep2.html"
	//var finestra;
	//finestra=window.open(url,"Nuovo","width=600,height=500,history=no,resizable=yes,status=no,scrollbars=yes,menubar=no")
	window.open(url,"Nuovo","width=600,height=500,history=no,resizable=yes,status=no,scrollbars=yes,menubar=no")
	//finestra.resizeTo(600, 500);
	//finestra.moveTo((screen.width/2)-((screen.width-10)/2),(screen.height/2)-((screen.height-50)/2));
	//finestra.focus();
}
	
function Svuota(oggetto)
	{
		if  (oggetto=="File") 
		{
			if (document.CambioNews.immagine.value!="")
			{			
				document.CambioNews.svuotafile.value=document.CambioNews.immagine.value;
				document.CambioNews.immagine.value='';
			}
		}
		if (oggetto=="Filmato")
		{
			if (document.CambioNews.filmato.value!="")
			{
				document.CambioNews.svuotafilmato.value=document.CambioNews.filmato.value;
				document.CambioNews.filmato.value='';
			}
		}
		
	}

	
//*********FUNZIONI PER IL CONTROLLO DELLE DATE*****************

function CreaVettoreData(campo)
{
	stringa=campo.value;
	vettoredata=stringa.split("/");
	return(vettoredata);
}
function Controlla(vettoredata,prov)
{		
	if (stringa.length!=10)
	{
		alert("Il formato della data deve essere del tipo gg/mm/aaaa ");	
		prov.value="";
				
	}
	else
	{
		if ((stringa.substr(2,1)!="/") || (stringa.substr(5,1)!="/"))
		{
			alert("La data non è nel formato giusto (Usare come separatore /)");
			prov.value="";
		}
		else
		{
			if ((isNaN(vettoredata[0])==true)||(isNaN(vettoredata[1])==true)||(isNaN(vettoredata[2])==true))
			{
				alert("sono state introdotte lettere anzichè numeri!")
				prov.value="";
			}	
			else
			{	
				if (vettoredata[1]>12)	
				{
					alert("il mese non può essere maggiore di 12!")
					prov.value="";
				}
				if ((parseInt(vettoredata[1])==2)&&(CalcolaBisestile(vettoredata[2])=="si") && (vettoredata[0]>29))
				{
					alert("il giorno non può essere maggiore di 29!")
					prov.value="";
				}
				if ((parseInt(vettoredata[1])==2)&&(CalcolaBisestile(vettoredata[2])=="no") && (vettoredata[0]>28))
				{
					alert("il giorno non può essere maggiore di 28!")			
					prov.value="";
				}
				if (((parseInt(vettoredata[1])==4)||(parseInt(vettoredata[1])==6)||(parseInt(vettoredata[1])==9)||(parseInt(vettoredata[1])==11))&&(vettoredata[0]>30))
				{
					alert("il giorno non può essere maggiore di 30!")			
					prov.value="";
				}
				if ((parseInt(vettoredata[1])!=4)&&(parseInt(vettoredata[1])!=6)&&(parseInt(vettoredata[1])!=9)&&(parseInt(vettoredata[1])!=11)&&(parseInt(vettoredata[1])!=2) && (vettoredata[0] > 31))
				{
					alert("il giorno non può essere maggiore di 31!")			
					prov.value="";
				}
			}
		}
	}
}
function CalcolaBisestile(yeardata)
{
	if (((yeardata % 4 ==0) && (yeardata % 100 != 0))||(yeardata % 400 ==0))	
		return("si");
	else
		return("no");
}
/////////////////////////
function CampoIntero(obj,nome){
	var str
	str=obj.value;
	if(isNaN(str)) //isNaN= non è numerico
	{
		alert('Il campo '+ nome +' deve essere di tipo numerico!')
		obj.value=''
	}
	else{
		obj.value=str
	}
}
/////////////////
function templateChange(){
	//controllo browser
	if(!document.styleSheets){
		var ss = getAllSheets() //Opera
		
	}else{
		var ss = document.styleSheets; //Dom
	}
	
	// disabilita tutti i fogli di stile con un titolo 
	// tranne quello passato per argomento alla funzione
	for( var x = 0; x < ss.length; x++ ) {
		if( ss[x].title ) {			
			ss[x].disabled=true;			
			//document.getElementById("dt_12").style.visibility="hidden";
			//document.getElementById("dt_13").style.visibility="visible";
		}
		
		for( var y = 0; y < arguments.length; y++ ) {
			//controlla ogni titolo ...
			
			if(ss[x].title == arguments[y]){
				//e riabilita il foglio di stile se ha il titolo scelto
				ss[x].disabled=false;
				//document.getElementById("dt_12").style.visibility="visible";
				//document.getElementById("dt_13").style.visibility="hidden";					
			}		
		}
		
	}
	if( !ss.length ) { 
		alert( 'Il tuo browser non è abilitato a cambiare i fogli di stile CSS' );
	}
}

// ---------------------------------------------------------------------------------

// Funzione per Opera
function getAllSheets(){
	if( document.getElementsByTagName ) {
		var Lt = document.getElementsByTagName('LINK');
		var St = document.getElementsByTagName('STYLE');
	} else {
		// browser minori - restituisce array vuoto
		return []; 
	}
	//per tutti i tag link ...
	for( var x = 0, os = []; Lt[x]; x++ ) {
		//controlla l'attributo rel per vedere se contiene 'style'
		if( Lt[x].rel ) {
			var rel = Lt[x].rel;
		} else if( Lt[x].getAttribute ) {
			var rel = Lt[x].getAttribute('rel');
		} else {
			var rel = '';
		}
		if(typeof(rel)=='string'&&rel.toLowerCase().indexOf('style')+1){
			//riempe la variabile os con i stylesheets linkati
			os[os.length] = Lt[x];
		}
	}
	//include anche tutti i tags style e restituisce l'array
	for( var x = 0; St[x]; x++ ) {
		os[os.length] = St[x];
	}
	return os;
}

function AltaLeg_Def(c1,c2){
document.getElementById(c1).style.visibility="hidden";
document.getElementById(c2).style.visibility="visible";
}
	
