function LiveSearchList(strReq, listaDiv)
{
	m_listaDiv = listaDiv;
	m_strReq = strReq; 
	if(typeof(m_tim)!='undefined'){ 
		clearTimeout(m_tim);
	}
	m_tim = setTimeout(StartRequest, 200); 
}

function StartRequest()
{
	var objXmlHttp = new XMLHttp();
	objXmlHttp.SendAsync(m_strReq, callBackLiveSearchList, null, null);
}

function callBackLiveSearchList(xmlHttp)
{
	var xmldoc = xmlHttp.responseXML;
	var stream = xmldoc.getElementsByTagName('response')[0].firstChild.nodeValue; 
	
	var item = document.getElementById(m_listaDiv);
	item.innerHTML = stream;
	item.style.display = 'block';
	item.style.border = "1px";
	/*Tolgo il loading all'interno dell'input text per la ricerca (eliminando le classi css)*/
	$('#nomeCity').removeClass("loading");
}

function NumCamereChanged(numCamere)
{ 
	for(var k=1; k<=3; k++){ 
		if (k <= numCamere){
			ShowDiv('camera'+k+'Div');
		}else{
			HideDiv('camera'+k+'Div');
		}
	}   
}

function NumAdultiChanged(numAdulti, numCamera)
{
	var item = document.getElementById('selectNumBambini' + numCamera + 'Div');  
	var limit = 2;
	if (numAdulti > 2){
		limit = 4 - numAdulti;
	}
	var output = "<select name=\"numChild" + numCamera + "\" id=\"numChild" + numCamera + "\" style='width:34px' onChange=\"NumBambiniChanged(this.value, " + numCamera + ")\">";
	for(var k=0; k<=limit; k++){
		output += "<option value=\"" + k + "\">" + k + "</option>";
	}
	output += "</select>";  
	if (item != null){    
		item.innerHTML = output;
		NumBambiniChanged("0", numCamera);
	}
}

function NumBambiniChanged(numBambini, numCamera)
{ 
	var item = document.getElementById('numRooms');    
	for(var k=1; k<=9; k++){ 
		if (k <= numBambini){      
			ShowDiv('Child' + numCamera + k + 'Div');
		} else {      
			HideDiv('Child' + numCamera + k + 'Div');
		}
	}   
}

function CheckRoomConfig(numRooms, numAdulti1, numChild1, Room1_numChild1, Room1_numChild2, numAdulti2, numChild2, Room2_numChild1, Room2_numChild2, numAdulti3, numChild3, Room3_numChild1, Room3_numChild2)
{
	if( numRooms > 0){
		document.getElementById('numRooms').selectedIndex = numRooms - 1;
		document.getElementById('numAdulti1').selectedIndex = numAdulti1 - 1;
		if(numChild1 >= 1){      
			document.getElementById('numChild1').selectedIndex = numChild1;      
			document.getElementById('Room1_numChild1').selectedIndex = Room1_numChild1;
			ShowDiv('Child1Div');
			ShowDiv('Child11Div');
			if(numChild1 == 2){              
				document.getElementById('Room1_numChild2').selectedIndex = Room1_numChild2;        
				ShowDiv('Child12Div');
			}
		} 

		if(numAdulti2 > 0){   
			ShowDiv('camera2Div');   
			document.getElementById('numAdulti2').selectedIndex = numAdulti2 - 1;
			if(numChild2 >= 1){      
				document.getElementById('numChild2').selectedIndex = numChild2;      
				document.getElementById('Room2_numChild1').selectedIndex = Room2_numChild1;
				ShowDiv('Child2Div');
				ShowDiv('Child21Div');
				if(numChild2 == 2){              
					document.getElementById('Room2_numChild2').selectedIndex = Room2_numChild2;        
					ShowDiv('Child22Div');
				}
			}
		} 

		if(numAdulti3 > 0){   
			ShowDiv('camera3Div');   
			document.getElementById('numAdulti3').selectedIndex = numAdulti3 - 1;
			if(numChild3 >= 1){      
				document.getElementById('numChild3').selectedIndex = numChild3;      
				document.getElementById('Room3_numChild1').selectedIndex = Room3_numChild1;
				ShowDiv('Child3Div');
				ShowDiv('Child31Div');
				if(numChild3 == 2){              
					document.getElementById('Room3_numChild2').selectedIndex = Room3_numChild2;        
					ShowDiv('Child32Div');
				}
			}
		}    
	}
}

function HideDiv(divID){
	var item = document.getElementById(divID);
	if (item) {
		item.style.display = 'none';
	}
}

function ShowDiv(divID){
	var item = document.getElementById(divID);
	if (item) {
		item.style.display = 'block';
	}
}

function GetConfig()
{  
	var numRooms = document.getElementById('numRooms').value;
	var str = "&numRooms=" + numRooms;
	for(var k=1; k<=numRooms; k++){
		var item = document.getElementById('numAdulti'+k);
		if(item != null){
			str += "&" + item.id + "=" + item.value;
			item = document.getElementById('numChild'+k);
			if(item != null){
				str += "&" + item.id + "=" + item.value;
				var numChilds = item.value;
				for(var i=1; i<=numChilds; i++){
					item = document.getElementById('Room'+k+'_numChild'+i); 
					if(item != null){
						str += "&" + item.id + "=" + item.value;
					}
				}
			}
		}
	}
	return str;
}