/*
	This is the JavaScript file for the AJAX Suggest Tutorial

	You may use this code in your own projects as long as this 
	copyright is left	in place.  All code is provided AS-IS.
	This code is distributed in the hope that it will be useful,
 	but WITHOUT ANY WARRANTY; without even the implied warranty of
 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
	
	For the rest of the code visit http://www.DynamicAJAX.com
	
	Copyright 2006 Ryan Smith / 345 Technical / 345 Group.	

*/


function pausecomp(millis)
{
var date = new Date();
var curDate = null;
pausecomp(3000);
do { curDate = new Date(); }
while(curDate-date < millis);
} 

//Gets the browser specific XmlHttpRequest Object
function getXmlHttpRequestObject() {
	if (window.XMLHttpRequest) {
		return new XMLHttpRequest();
	} else if(window.ActiveXObject) {
		return new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		alert("Your Browser!\nIt's about time to upgrade don't you think?");
	}
}

//Our XmlHttpRequest object to get the auto suggest
var searchReq = getXmlHttpRequestObject();

//Called from keyup on the search textbox.
//Starts the AJAX request.
function verifDisp(hotel, num_c, arr, par, a, b)
{
	var stringa = "hotel="+hotel+"&nc=1&arr="+arr+"&par="+par;
	
	e = document.getElementById("boxdisp"+a+"-"+b);
   e.innerHTML = "<br><br><img src=\"img/loading.gif\"><br><br><br>";
	
	if (searchReq.readyState == 4 || searchReq.readyState == 0)
	{
		
		//searchReq.open("GET", 'searchSuggest.php?search=' + str, true);
		var valore=0;
		var valore1=0;
		var valore2=0;
		var valore3=0;
		var valore4=0;
		var valore5=0;
		var valore6=0;
		var num_stanze=0;
		var i = a;
		var j = b;
		//alert("numero stanze: "+i+"-"+j);
//		navpath = escape(document.getElementById("path").value);
//		stringa = stringa+"&path="+navpath;
		num_stanze = escape(document.getElementById("numc"+i).value);
		valore = escape(document.getElementById("nc"+i+"-"+j).value);
		stringa = stringa+"&nc1="+valore;
		valore1 = escape(document.getElementById("na"+i).value);
		stringa = stringa+"&na1="+valore1;
		//alert(document.getElementById("nb"+i).value+"\n"+document.getElementById("nb"+i));
		if((document.getElementById("nb"+i) != null) && (document.getElementById("nb"+i).value != 0))
		{
			valore2 = escape(document.getElementById("nb"+i).value);
			stringa = stringa+"&nb1="+valore2;
			valore3 = escape(document.getElementById("b1eb"+i).value);
			stringa = stringa+"&b1eb1="+valore3;
			//alert(document.getElementById("nb"+i));
			if(document.getElementById("nb"+i).value == 2)
			{
				valore4 = escape(document.getElementById("b2eb"+i).value);
				stringa = stringa+"&b2eb1="+valore4;
			}
		}
		valore5 = escape(document.getElementById("t"+i).value);
		stringa = stringa+"&t1="+valore5;

		searchReq.open("POST", 'verifDisp.php', true);
		//searchReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;charset=UTF-8');
		searchReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		searchReq.setRequestHeader('Charset', 'windows-1251');
		searchReq.onreadystatechange = function() 
		{
			
			if (searchReq.readyState == 4) 
			{
				e = document.getElementById("boxdisp"+i+"-"+j);
				e.innerHTML = searchReq.responseText;
			}
		};

	
		//alert(stringa);
		searchReq.send(stringa);
		//alert('?ricerca_titolo='+str+'&tipo_dato='+name);
	}		
}



