﻿// JavaScript Document
function cambiaIframe() {
	
	//metodo per cambiare stile anche negli IFRAME
	var aDivs = window.parent.frames;
	var ind = aDivs.length ;
	
	if ( ( ind != null ) && ( ind > 0 ) ) {
		for ( var j=0 ; j < ( ind - 1 ) ; j++ ) {
			
			var nome = aDivs[j].name ;
			var ifrm = document.getElementById( nome );
			
			if ( ifrm != null ) {
				ifrm.src = document.getElementById( nome ).src ;
			}
		}
		
	}
	
}
function cambiafoglio( quale ){
 	
	//imposta un cookie con il numero del foglio di stile scelto
	setCookie( "cambiafoglio", quale );
	
	//rende attivo il foglio di stile corrispondente alla scelta effettuata	
	quale=quale-1;
	
	if(document.styleSheets){
	
		var c = document.styleSheets.length;
		
		for( var i = 0 ; i < ( c - 1 ) ; i++ ){
			
			if (document.styleSheets[i].href.indexOf('cambiafoglio') == -1) {
				if (document.styleSheets[i].href.indexOf('cambiacontrasto') == -1) {
					document.styleSheets[i].disabled=false;
				}
			} else if ( i != quale ) {
				document.styleSheets[i].disabled=true;
			} else {
				document.styleSheets[i].disabled=false;
			}
		
			document.styleSheets[3].disabled=true;
		
		}

	}
	
	//cambia stile anche negli IFRAME
	cambiaIframe();
	
}
function cambiaContrasto(quale){

	//imposta un cookie con il numero del foglio di stile scelto
	setCookie( "cambiacontrasto", quale );
	
	//rende attivo il foglio di stile corrispondente alla scelta effettuata	
	if( quale == "1" ){
	  document.styleSheets[12].disabled=false;
	  document.styleSheets[11].disabled=true;
	}
	if( quale == "2" ){
	  document.styleSheets[11].disabled=false;
	  document.styleSheets[12].disabled=true;
	}
	
	//cambia stile anche negli IFRAME
	cambiaIframe();
	
}

// legge il cookie precedentemente archiviato 
//(grazie a PPK: http://www.quirksmode.org/js/cookies.html)
function readCookie( name ) {
	
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	
	return null;
	
}
//al caricamento della pagina vede se c'è un cookie che memorizza la dimensione dei caratteri
function leggicookie() {
	
  var quale1 = parseInt( readCookie( 'cambiafoglio' ) );
  var quale2 = parseInt( readCookie( 'cambiacontrasto' ) );
  
  if ( quale1 ) { cambiafoglio( quale1 ); }
  if ( quale2 ) { cambiaContrasto( quale2 ); }
  
}
//
function setCookie( cookieName, cookieValue ) {

	scadenza = new Date();

	scadenza.setFullYear( scadenza.getFullYear() + 1 );
	
	document.cookie = cookieName + "=" + escape( cookieValue ) + "; expires=" + scadenza.toGMTString() + "; path=/" ;
	
	//alert( document.cookie )

}
onload = function(){ leggicookie(); }