var controllarisposta=0;
var timerbusy=0;
function CleanBody(ID)
{
	if (ID!="dati_testata")
		Hide("dati_testata");
	if (ID!="dati_clienti")
		Hide("dati_clienti");
	if (ID!="registrazione")
		Hide("registrazione");
	if (ID!="display_list")
		Hide("display_list");
	if (ID!="display_large")
		Hide("display_large");
	if (ID!="menu_dx")
		Hide("menu_dx");
	if (ID!="menu_dx_centrale")
		Hide("menu_dx_centrale");
	if (ID!="corpocentrale")
		Hide("corpocentrale");
	if (ID!="testomenu")
		Hide("testomenu");
	if (ID!="pp")
		Hide("pp");	
	if (ID!="avvisi")
		Hide("avvisi");
	if (ID!="framecentrale")
		Hide("framecentrale");		
	if (ID!="notizie")
	{
		doc=document.getElementById("notizie");
		if (doc!=null && doc!=undefined)
		{ 
			StopNews();
			Hide("notizie");
		}
	}
	if (ID!="corpocentraleSX")
		Hide("corpocentraleSX");
	
//	StoppaScrollo();
	StoppaFader();
//	fermacubo();
	stoptimeout();
	PulisciRisposta();
}
function Loader(url,ID,pulisci,parms)
{
	StoppaFader();
	if (pulisci==true) CleanBody();
	var doc=document.getElementById(ID);
	if (doc!=null && doc!=undefined)
	{
		Mostra(ID);
		if (pulisci=='2') //aggiungo il contenuto dell'URL SOTTO a quel che c'è già
		{
			doc.innerHTML+=SynchPOSTRequestA(url, parms);
		}
		else if (pulisci=='3') //aggiungo il contenuto dell'URL SOPRA a quel che c'è già
		{
			var insidenow=doc.innerHTML;
	//		alert(insidenow);
			doc.innerHTML=SynchPOSTRequestA(url, parms);
			doc.innerHTML+=insidenow;
		}
		else //lo pulisco e ci metto il contenuto dell'URL
		{
			doc.innerHTML="";
			doc.innerHTML=SynchPOSTRequestA(url, parms);
		}	
	}
}
function LoaderJS(url,ID,pulisci)
{
	StoppaFader();
	if (pulisci==true) CleanBody();
	var doc=document.getElementById(ID);
	if (doc!=null && doc!=undefined)
	{
		doc.style.display="block";
		doc.style.visibility="visible";
		doc.style.zindex="100";
	}
	SynchPOSTRequestAll(url, "",ID);
}
function Hide(ID,nonsvuotare)
{
	var doc=document.getElementById(ID);
	prova=0;
	while ( ((doc==undefined) || !doc) && prova<1)
	{
		if (emb!="s" && emb!="S")
		  doc=parent.document.getElementById(ID);
		prova++;
	}
	if (doc && doc!=null && doc!=undefined && doc!="")
	{
		//doc.style.height=0;	
		if (ID=="framecentrale")
		{	
		//	alert("svoto framecentrale");
			doc.style.height=0;	
		}
		else 
		{
			if (!nonsvuotare)
			  doc.innerHTML=("");  
		}
		doc.style.display="inline";
		doc.style.visibility="hidden";
	}
}
function Svuota(ID)
{
	var doc=document.getElementById(ID);
	if (doc!=null && doc!=undefined)
	{
		doc.innerHTML=("");
		doc.style.display="inline";
	}
}
function Busy(timeout)
{
	StoppaFader();
	var scrolltop=document.documentElement.scrollTop ?
                         document.documentElement.scrollTop :
                         document.body.scrollTop;
	var scrollleft=document.documentElement.scrollLeft ?
                         document.documentElement.scrollLeft :
                         document.body.scrollLeft;
	var docu=document.getElementById("aspettame");
	document.body.style.cursor='wait';
	var h=0;	
	var w=0;
	if (navigator.appName=="Microsoft Internet Explorer")
	{
		h=document.body.offsetHeight-20;
		w=document.body.offsetWidth;
	}
	else
	{
		h=window.innerHeight;
		w=window.innerWidth;
	}
	if (docu!=null && docu!=undefined)
	{
		docu.style.position='absolute'  ;
		docu.style.left = w/2 + scrollleft -80; 
		docu.style.top = h/2 + scrolltop -40;
		docu.style.zIndex=999;
		docu.innerHTML="<img src='images/iv_stars.gif'  border=0>";
	//	alert("fatto");
	//	if (navigator.appName=="Microsoft Internet Explorer")
	//	{
	//		docu.style.height=document.body.offsetHeight;
	//	}
	//	else
	//	{
	//		docu.style.height=window.innerHeight;
	//	}
	//	if (TESTO)
	//	{
	//		docu.innerHTML=TESTO;
	//	}
		docu.style.display="block";
		docu.style.visibility="visible";
	}
	if (timeout && timeout!=undefined && timeout!=0)
	  timerbusy=setTimeout("UNBusy()",timeout);
}
function UNBusy()
{
	if (timerbusy);
	  clearTimeout(timerbusy);  
	StoppaFader();
	var docu=document.getElementById("aspettame");
	document.body.style.cursor='default';
	if (docu!=null && docu!=undefined)
	{
	//	docu.style.position='relative';
		docu.innerHTML="";
		docu.style.height=0;
		docu.style.left=0;
		docu.style.top=0;
		docu.style.display="inline";
		docu.style.visibility="hidden";
	}
}
function Mostra(ID)
{
	UNBusy();
	var doc=document.getElementById(ID);
	prova=0;
	while ((doc==undefined || doc==null) && prova<1)
	{
		if (emb!="s" && emb!="S")
		  doc=parent.document.getElementById(ID);
		prova++;
	}
	if (doc!=null && doc!=undefined)
	{
		doc.style.display="block";
		doc.style.visibility="visible";
		doc.style.zIndex="100";
		
	}
	if (ID!="framecentrale")
	{
	    Hide("framecentrale");
	}
}
function Lanciaconattesa(functio)
{
	Busy();
	window.setTimeout(functio, 10);
}
function PulisciRisposta()
{
	controllarisposta=0;
}
function Chiudi(ID)
{
	StoppaFader();  
	var dok2="";
	if (ID!=undefined && ID!='')
		dok2=document.getElementById(ID);
	else
		dok2=document.getElementById('display_list');
	prova=0;
	while ((dok2==undefined || dok2==null) && prova<1)
	{
		if (ID!=undefined && ID!='')
			dok2=document.getElementById(ID);
		else
			dok2=document.getElementById('display_list');
		prova++;
		Hide("framecentrale");
	}
	if (dok2!=null && dok2!=undefined)
	{
		if (ID!=undefined && ID!='')
			Hide(ID);
		else
		{
		  CaricaInizio();
		}
		//alert("SHOW");
	}
	//else alert("NON trovato");
}
function refreshpage()
{
  StoppaFader();
  window.location.reload();
}
function LanciaDemo(chi)
{
  if (chi==1 || chi=='1')
     window.open("loggato.php?ID=bbbbbb&user=operatore&pwd=demo1234","_new");
  else
    window.open("loggato.php?ID=bbbbbb&user=demo&pwd=demo1234","_new"); 
      
}
function LanciaDemoUlt()
{
  window.open("loggato.php?ID=ultragas","_new"); 
}
function LanciaAdmin()
{
   $.post("http://www.iv-srl.it/ivhomepagetest/index.php/admin/loginck",{
		username:"root",
		password:"root"
	      },function(data){  
		    window.open("http://www.iv-srl.it/ivhomepagetest/index.php/adminselection","_new");
			      }
	  );
}
