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' );
 	}
}

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 temaChange(index){
	
	eval("templateChange('"+index+"')");
	document.getElementById("stile").value = index;
      
        document.sceltastile.submit();
}
