function getXmlObject()
{
	var xmlhttp;
	if (window.XMLHttpRequest)
	{
		// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp = new XMLHttpRequest();
	}
	else if (window.ActiveXObject)
	{
		// code for IE6, IE5
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
		alert("Your browser does not support XMLHTTP!");
	}
	
	return xmlhttp;
}

function updateSearchRegionsDiv(country_name)
{
	xmlObj = getXmlObject();

	xmlObj.onreadystatechange = function()
	{
		if (xmlObj.readyState == 4)
		{
			document.getElementById("searchRegionDiv").innerHTML = xmlObj.responseText;
			document.getElementById("searchLocationDiv").innerHTML = '<label for="p_SearchLocation">Location<br  /></label><select id="p_SearchLocation" name="p_SearchLocation" onchange="updateSearchPropertiesDiv(this.options[this.selectedIndex].value)"><option value="0">All locations  </option></select><br />';
		}
	}
	
	var url = "/ajax/getRegions.php?country=" + country_name;

	
	xmlObj.open("GET", url, true);
	xmlObj.send(null);
	
	//document.location = "/luxury-hotels/" + country_name;
}

function updateSearchLocationsDiv(region_name, country_name)
{
	xmlObj = getXmlObject();

	xmlObj.onreadystatechange = function()
	{
		if (xmlObj.readyState == 4)
		{
			document.getElementById("searchLocationDiv").innerHTML = xmlObj.responseText;
		}
	}
	
	var url = "/ajax/getLocations.php?region=" + region_name;
	
	xmlObj.open("GET", url, true);
	xmlObj.send(null);
}

function updateSearchPropertiesDiv(location_name)
{
	xmlObj = getXmlObject();

	xmlObj.onreadystatechange = function()
	{
		if (xmlObj.readyState == 4)
		{
			document.getElementById("searchPropertyDiv").innerHTML = xmlObj.responseText;
		}
	}
	
	var url = "/ajax/getProperties.php?location=" + location_name;
	
	xmlObj.open("GET", url, true);
	xmlObj.send(null);
	//country_ref = document.getElementById("p_SearchCountry");
	//country_name = country_ref.options[country_ref.selectedIndex].value;
	
	//region_ref = document.getElementById("p_SearchRegion");
	//region_name = region_ref.options[region_ref.selectedIndex].value;
	//document.location = "/luxury-hotels/" + country_name + "/" + region_name + "/" + location_name;
}

function loadSearchResults()
{
	country_ref = document.getElementById("p_SearchCountry");
	country_name = country_ref.options[country_ref.selectedIndex].value;
	
	region_ref = document.getElementById("p_SearchRegion");
	region_name = region_ref.options[region_ref.selectedIndex].value;
	
	location_ref = document.getElementById("p_SearchLocation");
	location_name = region_ref.options[location_ref.selectedIndex].value;
	
	document.location = "/luxury-hotels/" + country_name + "/" + region_name + "/" + location_name;
}

function updateFormAction()
{

	country_ref = document.getElementById("p_SearchCountry");
	country_name = country_ref.options[country_ref.selectedIndex].value;
	
	region_ref = document.getElementById("p_SearchRegion");
	region_name = region_ref.options[region_ref.selectedIndex].value;
	
	location_ref = document.getElementById("p_SearchLocation");
	location_name = location_ref.options[location_ref.selectedIndex].value;
	
	property_ref = document.getElementById("p_SearchProperty");
	property_name = property_ref.value;
	
	var action = "/luxury-hotels/";
	
	if (country_name != 0 && region_name != 0 && location_name != 0)
		action += country_name + "/" + region_name + "/" + location_name;
	else if (country_name != 0 && region_name != 0)
		action += country_name + "/" + region_name;
	else if (country_name != 0)
		action += country_name;
	else action += "reservation-hotels";
	
	if (property_name != '' && property_name != 0) {
		action = "/luxury-hotels/reservation-hotels";
		country_ref.selectedIndex = 0;
		region_ref.selectedIndex = 0;
		location_ref.selectedIndex = 0;
	}
	
	document.forms[0].action = action;
	return true;

}

function updateSynxisCode(property_name)
{
	xmlObj = getXmlObject();

	xmlObj.onreadystatechange = function()
	{
		if (xmlObj.readyState == 4)
		{
			document.getElementById("Hotel").value = xmlObj.responseText;
		}
	}
	
	var url = "/ajax/getSynxisCode.php?property=" + property_name;
	
	xmlObj.open("GET", url, true);
	xmlObj.send(null);
}

function updateFormPage(page)
{
	updateFormAction();
	if (page != '0') {
		document.forms['search_form'].nav_page.value = page;
		$("#search_form").submit();
	}
}

function updateFormSortMethod(sort_method)
{
	updateFormAction();
	document.forms['search_form'].sort_method.value = sort_method;
	$("#search_form").submit();
}


$(document).ready(function() {
	change_tabs(1);
});

function change_tabs(id) {
	if (id != 1 && id != 2 && id != 3 && id != 4)
		id = 1;
	for (i=1; i <= 4; i++) {
		var buton = 'Tab'+i;
		if (i == id) {
			$("#"+buton).attr('class','tabOn');
			$("#hotel_description"+i).show();
		} else {
			$("#"+buton).attr('class','tabOff');
			$("#"+buton).attr('class','tabOff');
			$("#hotel_description"+i).hide();
		}
	}
}



