

function GET($id){
	return 	document.getElementById($id);
}
function VAL($id){
	$el=GET($id);
	if($el.type=="text") return $el.value;
	if($el.type=="checkbox") return $el.checked;
	if($el.type=="textarea") return $el.value;
}

// OFFERTA ------------------------------------------------------------------------------------------------
$offerta_pos=0;
$offerta_loading='<li class="loading"><img src="images/loading.gif" /><span>caricamento..</span></li>';
$offerte_ul="";
$offerte_caricare=0;
function LoadNextOfferta(){
	if(!$offerte_caricare){
		$offerte_ul=GET("off_elenco").innerHTML;
		GET("off_elenco").innerHTML=$offerta_loading;
		GET("off_next").style.display="none";
		GET("off_back").style.display="none";
	
		var ajax = assegnaXMLHttpRequest();
		if(ajax) {
			percorso="http://www.legraziehotel.com/library/get_news.php?posizione="+$offerta_pos;
			//ajax.setRequestHeader('connection', 'close');
			ajax.open("POST", percorso, true);
			ajax.setRequestHeader("content-type", "text/html; charset=utf-8");
			dati='';
			ajax.onreadystatechange = function(){
				if(ajax.readyState === 4 && ajax.status == 200){
					if(ajax.responseText==""){
							$offerte_caricare=1;
							GET("off_elenco").innerHTML=$offerte_ul;
					} else {
						$sez=ajax.responseText.split("::");
						$offerta_pos=$sez[0];
						GET("off_elenco").innerHTML=$offerte_ul+$sez[1];
						$offerte_ul="";
					}						

					GET("off_next").style.display='';
					GET("off_back").style.display='';
					$(function() {
						$( "#news" ).accessNews({
							speed : "slow",
							slideBy : 1
						});
					});

				}
			}
			ajax.send(dati);
		}
	} else {
		$(function() {
			$( "#news" ).accessNews({
				speed : "slow",
				slideBy : 1
			});
		});	
	}
}

// COMMENTI ------------------------------------------------------------------------------------------------
$commentoid=0;
function LoadNextCommento(){
	$el=GET("diconodinoi");
	if($el){
		var ajax = assegnaXMLHttpRequest();
		if(ajax) {
			percorso="http://www.legraziehotel.com/library/get_commento.php?id="+$commentoid;
			//ajax.setRequestHeader('connection', 'close');
			ajax.open("POST", percorso, true);
			ajax.setRequestHeader("content-type", "text/html; charset=utf-8");
			dati='';
			ajax.onreadystatechange = function(){
				if(ajax.readyState === 4 && ajax.status == 200){
					$com=ajax.responseText.split("::");
					$commentoid=$com[0];
		
					$el1=GET("diconodinoi1");
					$el2=GET("author");
		
					$el.innerHTML='<p id="diconodinoi1">'+$com[2]+'</p><span id="author">'+$com[1]+'</span>';

					setOpacity($el1,0);
					setOpacity($el2,0);
					
					setTimeout("FadeIn()",1);
				}
			}
			ajax.send(dati);
		}
	}
}
//-------------------------------------------------------------------------------------------------------------

window.onload = function(){
	ajax=assegnaXMLHttpRequest();
	if(GET("diconodinoi")){
		LoadNextCommento();
	}
	if(GET("h_offerte")){
		LoadNextOfferta();
	}
}

function assegnaXMLHttpRequest() {
	var XHR = null, browserUtente = navigator.userAgent.toUpperCase();
	if(typeof(XMLHttpRequest) === "function" || typeof(XMLHttpRequest) === "object") XHR = new XMLHttpRequest();
	else if (window.ActiveXObject && browserUtente.indexOf("MSIE 4") < 0) {
		if(browserUtente.indexOf("MSIE 5") < 0) XHR = new ActiveXObject("Msxml2.XMLHTTP");
		else XHR = new ActiveXObject("Microsoft.XMLHTTP");
	}
	return XHR;
}

opacity=1;
function FadeOut(){
	if(opacity>0){
		$el=GET("diconodinoi1");
		$el2=GET("author");
		setOpacity($el,opacity-0.1);
		setOpacity($el2,opacity-0.1);
		$slide_out=setTimeout("FadeOut()",200);
	} else LoadNextCommento();
}
function FadeIn(){
	if(opacity<1){
		$el=GET("diconodinoi1");
		$el2=GET("author");
		setOpacity($el,opacity+0.1);
		setOpacity($el2,opacity+0.1);
		$slide_out=setTimeout("FadeIn()",100);
	} else setTimeout("FadeOut()",4000);
}


function setOpacity(el, fOp){
	if ( typeof el.style.MozOpacity!="undefined" ) el.style.MozOpacity = fOp-0.001;
	else if ( typeof el.style.opacity!="undefined" ) el.style.opacity = fOp;
	else if ( typeof el.style.KhtmlOpacity!="undefined" ) el.style.KhtmlOpacity = fOp;
	else if ( typeof el.style.filter!="undefined" ) el.style.filter = "Alpha(Opacity="+(fOp*100)+")";
	opacity=fOp;
}