/*releaseEvents removeEventListener  detachEvent*/	

	function setCookie(name, value, expires, path, domain, secure) {
	    document.cookie= name + "=" + escape(value) +
	        ((expires) ? "; expires=" + expires.toGMTString() : "") +
	        ((path) ? "; path=" + path : "") +
	        ((domain) ? "; domain=" + domain : "") +
	        ((secure) ? "; secure" : "");
	}

	function getCookie(name) {
	    var dc = document.cookie;
	    var prefix = name + "=";
	    var begin = dc.indexOf("; " + prefix);
	    if (begin == -1) {
	        begin = dc.indexOf(prefix);
	        if (begin != 0) return null;
	    } else {
	        begin += 2;
	    }
	    var end = document.cookie.indexOf(";", begin);
	    if (end == -1) {
	        end = dc.length;
	    }
	    return unescape(dc.substring(begin + prefix.length, end));
	}

	// Rende visibile la finestra
	function showoff(){
		obj = document.getElementById("promstay");
		if (obj)
		{
			obj.style.display = "block";
			doff();
		}
	}
	
	function cambiaofferta($id) {
		$idoffer = new Array();
		$idboffer = new Array();
		
		$off_count = parseInt(document.getElementById("trick").innerHTML);
		for ($key = 0; $key <= $off_count; $key++) {
			$idoffer[$key] = "offerta"+$key;
			$idboffer[$key] = "bo"+$key;
		}
		
		document.getElementById($idoffer[$id]).style.display = "block";
		if (!window.innerHeight){
			document.getElementById($idboffer[$id]).setAttribute("className", "current");
		}else{
			document.getElementById($idboffer[$id]).setAttribute("class", "current");
		}
		
		for ($key in $idoffer) {
			if ($key != $id) {
				document.getElementById($idoffer[$key]).style.display = "none";
				if (!window.innerHeight){
					document.getElementById($idboffer[$key]).setAttribute("className", "none");
				}else{
					document.getElementById($idboffer[$key]).setAttribute("class", "none");
				}
			}
		}
		doff();

	}
	
	// Riposiziona la finestra
	function doff() {
		obj = document.getElementById("promstay");
		if (window.innerHeight){
			obj.style.top = ((window.innerHeight - obj.clientHeight) + document.documentElement.scrollTop - 30) + "px";
		}else{
			obj.style.top = ((document.documentElement.clientHeight - obj.clientHeight) + document.documentElement.scrollTop - 50) + "px";
		}
		obj.style.left = ((document.documentElement.clientWidth / 2) - (obj.offsetWidth / 2))  + "px";
	}

	// riposiziona la finestra(ext) ed esegue l'attach degli eventi
	function initff() {
		if (document.getElementById("promstay"))
		{
			doff();
			window.onscroll		= doff;
			window.onresize		= doff;
		}
	}
	
	function setTime(){
		var futdate = new Date();
		var expdate = futdate.getTime();
		expdate += 180*1000 //expires in 1 hour(milliseconds) 
		futdate.setTime(expdate);
		return futdate;
	}
	
	// chiude la finestra
	function chiudi() {
		obj = document.getElementById("promstay");
		obj.style.display = "none";
		setCookie("stato", "false", setTime());
	}
	
	function showHideOffert(){
	$Off = true;
		if (!$Off)
		{
			obj = document.getElementById("promstay");
			if (obj.style.display == "none" || obj.style.display == ""){
				obj.style.display = "block";doff();
			}else{
				obj.style.display = "none";
			}
		}else{
			alert("Al momento non ci sono promozioni attive");
		}
	}
	
	// Richiama la funzione per l'attach dell'event e rende visibile la finestra dopo un secondo dalla fine del caricamento della pagina
	// Da utilizzare solo in onload
	function myInit() {
		if (window.init) {init();}
		
		if (document.getElementById("promstay")){
			initff();
			if (getCookie("stato") != "false"){
				setTimeout('showoff()', 1000);
			}
		}
	}
	
	// Se nella pagina esiste gia l'evento onload  lo sovrascrive. Tutte le pagine devono avere ad onload una sola funzione di nome itin !!
	window.onload = myInit;
	//if (!window.init) {window.onload = myInit; }
	