
function preselectValues(timer, country, city, hotel)
{
	if (dsCities1.getDataWasLoaded() && dsCities2.getDataWasLoaded() && dsCities3.getDataWasLoaded())
	{
/*				if(dsCities1.getDataWasLoaded()){alert('loaded1');}
		if(dsCities2.getDataWasLoaded()){alert('loaded2');}
		if(dsCities3.getDataWasLoaded()){alert('loaded3');}
*/		window.clearInterval(timer);
		updateSearchList(country, city, hotel);

	}

}

function getIndex(list, value)
{
	var list = document.getElementById(list);

	for (var i=0; i<list.options.length; i++)
	{
    	if (list.options[i].value == value)
    	{
			return i;
    	}
    }

	return -1;
}

function updateSearchList(country, city, hotel)
{
	if (country != -1)
	{
	    dsCities2.setXPath("countries/country[@id=" + country + "]/city");

	    
		$('countrylist').selectedIndex = getIndex('countrylist', country);
	    $('citylist').selectedIndex	 = 0;
	    $('search_hotel_string').value = '';
	}

	if (city != -1)
	{
		var countryList = document.getElementById('countrylist');
	    $('citylist').selectedIndex	 = getIndex('citylist', city);
	}
	
	if (hotel != -1)
	{
	    $('search_hotel_string').value = hotel;
	}

	if($('countrylist').selectedIndex > 0)
	{
		var xPathOptions1 = "[@id=" + $('countrylist').options[$('countrylist').selectedIndex].value + "]";
	}	
	else
	{
		var xPathOptions1 = "";
	}
	if($('citylist').selectedIndex > 0)
	{
		var xPathOptions2 = "[@id=" + $('citylist').options[$('citylist').selectedIndex].value + "]";
		
	}
	else
	{
		var xPathOptions2 = "";
	}
	var newXpath = "countries/country" + xPathOptions1 + "/city" + xPathOptions2 + "/hotel";
		
	dsCities3.setXPath(newXpath, { distinctOnLoad: true });
	dsCities3.loadData();
	
}

function updateSearchListContextRight(country, city, hotel)
{
	/*if (country != -1)
	{
	    dsCities2.setXPath("countries/country[@id=" + country + "]/city");
	    dsCities3.setXPath("countries/country[@id=" + country + "]/city[1]/hotel");
	
	    document.getElementById('countrylist_con').selectedIndex = getIndex('countrylist_con', country);
	    document.getElementById('citylist_con').selectedIndex	 = 0;
	    document.getElementById('hotellist_con').selectedIndex	 = 0;
	}

	if (city != -1)
	{
		var countryList = document.getElementById('countrylist_con');
	    dsCities3.setXPath("countries/country[@id=" + countryList.options[countryList.selectedIndex].value + "]/city[@id=" + city + "]/hotel");

	    document.getElementById('citylist_con').selectedIndex	 = getIndex('citylist_con', city);
	    document.getElementById('hotellist_con').selectedIndex	 = 0;
	}
	
	if (hotel != -1)
	{
	    document.getElementById('hotellist_con').selectedIndex	 = getIndex('hotellist_con', hotel);
	}*/
	if (country != -1)
	{
	    dsCities2.setXPath("countries/country[@id=" + country + "]/city");

	    
		$('countrylist_con').selectedIndex = getIndex('countrylist', country);
	    $('citylist_con').selectedIndex	 = 0;
	    $('search_hotel_string').value = '';
	}

	if (city != -1)
	{
		var countryList = document.getElementById('countrylist_con');
	    $('citylist_con').selectedIndex	 = getIndex('citylist', city);
	}
	
	if (hotel != -1)
	{
	    $('search_hotel_string_con').value = hotel;
	}

	if($('countrylist_con').selectedIndex > 0)
	{
		var xPathOptions1 = "[@id=" + $('countrylist_con').options[$('countrylist_con').selectedIndex].value + "]";
	}	
	else
	{
		var xPathOptions1 = "";
	}
	if($('citylist_con').selectedIndex > 0)
	{
		var xPathOptions2 = "[@id=" + $('citylist_con').options[$('citylist_con').selectedIndex].value + "]";
	}
	else
	{
		var xPathOptions2 = "";
	}
	var newXpath = "countries/country" + xPathOptions1 + "/city" + xPathOptions2 + "/hotel";
		
	dsCities3.setXPath(newXpath, { distinctOnLoad: true });
	dsCities3.loadData();
}


function updateSearchListEmail(country, city, hotel)
{
	if (country != -1)
	{
	    dsCities2.setXPath("countries/country[@id=" + country + "]/city");

	    
		$('countrylist').selectedIndex = getIndex('countrylist', country);
	    $('citylist').selectedIndex	 = 0;
	    $('search_hotel_string').value = '';
	}

	if (city != -1)
	{
		var countryList = document.getElementById('countrylist');
	    $('citylist').selectedIndex	 = getIndex('citylist', city);
	}
	
	if (hotel != -1)
	{
	    $('search_hotel_string').value = hotel;
	}

	if($('countrylist').selectedIndex > 0)
	{
		var xPathOptions1 = "[@id=" + $('countrylist').options[$('countrylist').selectedIndex].value + "]";
	}	
	else
	{
		var xPathOptions1 = "";
	}
	if($('citylist').selectedIndex > 0)
	{
		var xPathOptions2 = "[@id=" + $('citylist').options[$('citylist').selectedIndex].value + "]";
		
	}
	else
	{
		var xPathOptions2 = "";
	}
	var newXpath = "countries/country" + xPathOptions1 + "/city" + xPathOptions2 + "/hotel";
		
	dsCities3.setXPath(newXpath, { distinctOnLoad: true });
	dsCities3.loadData();
	
}

