// JavaScript Document

var waiting;
var xmlHttp=createXmlHttpRequestObject();
var Nave=true;

function createXmlHttpRequestObject()
{
	var xmlHttp;
	if(window.ActiveXObject)
	{
		try
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp=false;
		}
	}
	else
	{
		try
		{
			xmlHttp=new XMLHttpRequest();
		}
		catch (e)
		{
			xmlHttp=false;
		}
	}
	if(!xmlHttp){
		alert("Impossibile creare l'oggetto XMLHttpRequest!");
		return null
	}
	else{
		return xmlHttp;
	}
}


function Vota()
{
	if(xmlHttp.readyState==4 || xmlHttp.readyState==0)
	{
		var f=document.getElementById("frmPoll");
		var p=document.getElementById("pol").value;
		var s=new String;
		
		for(x=0;x<f.elements.length;x++)
		{
			s+=(f.elements[x].type=="checkbox" || f.elements[x].type=="radio") &&f.elements[x].checked ?f.elements[x].name + "=" +encodeURI(f.elements[x].value)+"&":"";
		}
		s+="pol="+escape(encodeURI(p));
		xmlHttp.open("POST", "script/ele_pol.php", true);
		//Send the proper header information along with the request
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", s.length);
		xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.onreadystatechange=showresult;
		xmlHttp.send(s);
	}
}

function showresult()
{
	var l=document.getElementById("lPOLL");
	var r=document.getElementById("risultati");

	if(xmlHttp.readyState==4)
	{
		if(xmlHttp.status==200)
		{
			xmlResponse=xmlHttp.responseXML;
			Result=xmlResponse.documentElement;
			try
			{
				helloMessage=Result.firstChild.data;
				if(helloMessage.indexOf("rrore")>0)
				{
					l.innerHTML+="<center><span class='TitoloNews'><strong>"+helloMessage+"</strong></span></center>";//xmlResponse.toString();
				}
				else
				{
					l.innerHTML="<center><span class='TitoloNews'><strong>"+helloMessage+"</strong></span></center>";//xmlResponse.toString();
					document.getElementById("risultati").style.display="";
				}
			}
			catch(e)
			{
				l.innerHTML="Errore!"+e.toString();
			}
		}
		else
		{
			l.innerHTML="errore.."+ xmlHttp.statusText;
		}
	}
}

function Verifica_Disponibilita(lng)
{
	if(xmlHttp.readyState==4 || xmlHttp.readyState==0)
	{
		if(document.getElementById("person").value!=0)
		{
			var f=document.getElementById("frmData");
			var s=new String;
			
			for(x=0;x<f.elements.length;x++)
			{
				switch(f.elements[x].type)
				{
					case "select-one":
						s+=f.elements[x].name + "=" +f.elements[x].options[f.elements[x].selectedIndex].value+"&";
						break;
					case "text":
						s+=f.elements[x].name + "=" +f.elements[x].value+"&";
						break;
				}
			}
			s+="l="+lng;
		//alert("xml/checkAvail.php?"+s);
			xmlHttp.open("get", "xml/checkAvail.php?"+s, true);
		//Send the proper header information along with the request
			xmlHttp.onreadystatechange=Scrivi_Disponibilita;
			xmlHttp.send(s);
		}
		else
		{
			alert("Indicare il numero di persone!");
		}
	}
}

function Scrivi_Disponibilita()
{
	if(xmlHttp.readyState==4)
	{
		if(xmlHttp.status==200)
		{
			xmlResponse=xmlHttp.responseXML;
			var Result=xmlResponse.documentElement;
			try
			{
				document.getElementById("resultText").innerHTML=Result.firstChild.data;
			}
			catch(e)
			{
				alert("Errore:"+e);
			}
		}
	}
}


function Prezzi(stagione, e, sData, tipo, l)
{
	var p=parent.parent.document.getElementById("prezziTT");
	var s=parent.parent.document.getElementById("globalTT");	

//	s=document.getElementById("prezziTT");	
	if(xmlHttp.readyState==4 || xmlHttp.readyState==0)
	{
	//alert("xml/checkPrice.php?l="+l+"&d="+sData+"&t="+ tipo+"&s="+stagione);
		xmlHttp.open("get", "xml/checkPrice.php?l="+l+"&d="+sData+"&t="+ tipo+"&s="+stagione, false);
		xmlHttp.send(null);
		if(xmlHttp.readyState==4 && xmlHttp.status==200)
		{
			xmlResponse=xmlHttp.responseXML;
			var Result=xmlResponse.documentElement;
			try
			{
				var helloMessage=Result.firstChild.data?Result.firstChild.data:"";
				//s.style.left=e.clientX>280?"10px":"250px";
				p.innerHTML=helloMessage;
				s.style.display="block";	
			}
			catch(f)
			{
				alert("ERRORE!:"+f);
			}
		}
	}
}

function ChiudiPrezzi()
{
	document.getElementById("globalTT").style.display="none";
}

function Cambia_Menu(lingua)
{
	if(xmlHttp.readyState==4 || xmlHttp.readyState==0)
	{
		xmlHttp.open("GET", "xml/getMenu.php?l="+lingua, false);
		xmlHttp.send(null);
		MostraMenu();
	}
}

function MostraMenu()
{
	if(xmlHttp.readyState==4 && xmlHttp.status==200)
	{
		document.getElementById("general_top").innerHTML="";	
		var b="";
		var MENU=xmlHttp.responseXML.getElementsByTagName('menu');
		for(x=0;x<MENU.length;x++)
		{
			b+=MENU[x].firstChild.data;
		}
		document.getElementById("general_top").innerHTML=b;
	}
	else
	{
		alert(xmlHttp.statusText);
	}
}


function global_avail(sElement)
{
	if(xmlHttp.readyState==4 || xmlHttp.readyState==0)
	{
		xmlHttp.open("GET", "xml/gblavail.php?"+sElement, false);
		xmlHttp.send(null);
		if(xmlHttp.readyState==4 && xmlHttp.status==200)
		{
			var p=document.getElementById("prezziTT");
			var s=document.getElementById("globalTT");	
			xmlResponse=xmlHttp.responseXML;
			var Result=xmlResponse.documentElement;
			try
			{
				var helloMessage=Result.firstChild.data;
				p.innerHTML=helloMessage;
				s.style.display="block";	
			}
			catch(f)
			{
				alert(f);
			}
		}		
	}
}

function Mostra_Mail()
{
	var m=document.getElementById("frmNew");
	m.style.display=m.style.display!='block'?"block":"none";
}

function Credit_Card(l)
{
	var w=window.open("http://www.secureholiday.net/reservation.asp?nc=4299&lg="+l, "new");
	document.getElementById("globalTT").style.display="none";
	w.focus();
}

function MandaMail()
{
	 var f=document.getElementById("frmNew");
	if(xmlHttp.readyState==4 || xmlHttp.readyState==0)
	{
		var s=new String;
		for(x=0;x<f.elements.length;x++)
		{
			s+=(f.elements[x].type=="text" || f.elements[x].type=="hidden" || f.elements[x].type=="textarea")?f.elements[x].name + "=" +encodeURI(f.elements[x].value)+"&":"";
		}
		xmlHttp.open("POST", "script/re_gister.php", true);
//		alert("script/re_gister.php"+s);
		//Send the proper header information along with the request
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", s.length);
		xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.onreadystatechange=Scrivi_Disponibilita;
		xmlHttp.send(s);

	}
}

function EspandiPromo(idPromo)
{
	var p=document.getElementById(idPromo);
	p.style.display=p.style.display!="block"?"block":"none";
}