// JavaScript Document


function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);


function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}


function WindowOpen(theURL,winName,features) {
  window.open(theURL,winName,features);
}


function UP(file,nomecontrollo,nomefunzione) {
	//nomecontrollo è l'id del campo del form
	// 
	if (nomefunzione=="cancella"){
		document.getElementById(nomecontrollo).value = file;
	}
	if (nomefunzione=="immagine"){
		//document.forms[nomeform].img.value = file;
		window.opener.document.getElementById(nomecontrollo).value = file;
	}
	if  (nomefunzione=="documento"){
		window.opener.document.getElementById(nomecontrollo).value = file;
	}

}



function test() {
var f = document.form; 
if ((f.nome.value == "" ) || (f.nome.value.charAt(0) == " ")){
alert("Manca il tuo nome");
f.nome.focus();
return false;
}
if ((f.email.value == "" ) || (f.email.value.charAt(0) == " ")){
alert("Manca la tua email");
f.email.focus();
return false;
}
var re = new RegExp("^[!#$&'*+/-9=?A-Z^-~-]+(\\.[!#$&'*+/-9=?A-Z^-~-]+)*@[!#$&'*+/-9=?A-Z^-~-]+(\\.[!#$&'*+/-9=?A-Z^-~-]+)+$","");
if (!f.email.value.match(re)){
alert("Indirizzo email non corretto!")
f.email.select();
return false;
}
if ((f.testo.value == "") || (f.testo.value.charAt(0) == " ")){
alert("Dovresti scrivere qualcosa nel messaggio");
f.testo.focus();
return false;
}
document.form.submit();
}


function testmail2() { 
e = document.form.email.value; 
a = e.indexOf("@"); // posizione della chiocciola 
p = e.lastIndexOf("."); // posizione del punto 
if (a<3 || p<(a+4) || p>(e.length-3)) { 
alert("\n Devi inserire una e-mail valida"); 
return false; 
document.form.email.focus();
} 
} 


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;
		}
		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;
			}
		}
	}
	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;
}
//-->

