var base_url;
var durataGiorniCookie=30;

//Workaround per l'inserimento dinamico di elementi in firefox
if( typeof HTMLElement!="undefined" && !HTMLElement.prototype.insertAdjacentElement ) {
	HTMLElement.prototype.insertAdjacentElement = function (where,parsedNode) { 
		switch (where){
		case 'beforeBegin':
			this.parentNode.insertBefore(parsedNode,this)
			break;
		case 'afterBegin':
			this.insertBefore(parsedNode,this.firstChild);
			break;
		case 'beforeEnd':
			this.appendChild(parsedNode);
			break;
		case 'afterEnd':
			if (this.nextSibling) this.parentNode.insertBefore(parsedNode,this.nextSibling);
			else this.parentNode.appendChild(parsedNode);
			break;
		}
	}

	HTMLElement.prototype.insertAdjacentHTML = function (where,htmlStr) {
		var r = this.ownerDocument.createRange();
		r.setStartBefore(this);
		var parsedHTML = r.createContextualFragment(htmlStr);
		this.insertAdjacentElement(where,parsedHTML)
	}


	HTMLElement.prototype.insertAdjacentText = function (where,txtStr) {
		var parsedText = document.createTextNode(txtStr)
		this.insertAdjacentElement(where,parsedText)
	}
}

function FontResizer(type){
	//type => small / large
	//textSize_small
	//textSize_large
	var css_base =  base_url+'css/styles_'+type+'.css';
	//alert(css_base);
	css = document.createElement('link');
	css.href = css_base;
	css.rel = 'stylesheet';
	css.type = 'text/css';
	css.id = 'CurrentFontSize';
	if(!document.getElementById('CurrentFontSize')){
		document.getElementsByTagName('head')[0].insertAdjacentElement('beforeEnd',css);
	}else{
		var cfs = document.getElementById('CurrentFontSize');
		cfs.href = css_base;
	}
	
}

function setCookieFontResizer(type){
	if(type != ''){
		setCookie('Grappa_FontSize',type);
	}
}

function getCookieFontResizer(){
	if (document.cookie.length > 0) {
		var source = new Array();
		source = document.cookie.split(';');
		for(i=0;i<source.length;i++){
			if(source[i].indexOf('Grappa_FontSize') == 0){
				var current_font_size = source[i].substr(source[i].indexOf("=")+1);
				FontResizer(current_font_size);
			}else if(source[i].charAt(0) == ' ' && source[i].indexOf(' Grappa_FontSize') == 0){
				var current_font_size = source[i].substr(source[i].indexOf("=")+1);
				FontResizer(current_font_size);
			}
		}
	}	
}

function setCookie(nomeCookie,valoreCookie){
	var dataOggi = new Date()
	var dataExpires = new Date()
	dataExpires.setTime(dataOggi.getTime() + 24 * durataGiorniCookie * 3600000);
	document.cookie = nomeCookie+'='+escape(valoreCookie)+''+'; path=/'+'; expires='+dataExpires.toGMTString();
}

