// JavaScript Document
var checker=0;
var xmlhttp;
xmlhttp = null;

if(window.ActiveXObject){
	//alert("1");
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}else if(window.XMLHttpRequest){
	//alert("2");
	xmlhttp = new XMLHttpRequest();
}else{
	//alert("3");
	xmlhttp=new XMLHttpRequest();
}

function enlarge_img(prop_photo_id){
	//alert('hi');
	if(prop_photo_id != 0){
		var serverPage = "ajax/enlarge_image.php?prop_photo_id=" + prop_photo_id;
		xmlhttp.open("GET",serverPage);
		xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4 && xmlhttp.status==200){
				//alert(xmlhttp.responseText);
				var prop_photo_td = document.getElementById('prop_photo_td');
				prop_photo_td.innerHTML = xmlhttp.responseText;
			}
		}
		xmlhttp.send(null);
	}
}

function get_country(){
	//alert(xmlhttp);
	if(checker==0){
		var country = document.getElementById('country_id');
		country.options.length=0;
		country.options[0] = new Option('loading...',0);
		var serverPage = "ajax/get_country_search.php";
		xmlhttp.open("GET",serverPage);
		xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4 && xmlhttp.status==200){
				var country_td = document.getElementById('country_td');
				//var country_id = document.getElementById('country_id');	
				country_td.innerHTML = xmlhttp.responseText;
				checker=1;
			}
		}
		xmlhttp.send(null);
	}
}

function get_region(){
	//alert('hi');
	var country_id = document.getElementById('country_id').value;
	if(country_id != 0){
		var region = document.getElementById('region_id');
		region.options.length=0;
		region.options[0] = new Option('loading...',0);
		var serverPage = "ajax/get_region_search.php?country_id=" + country_id;
		xmlhttp.open("GET",serverPage);
		xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4 && xmlhttp.status==200){
				var region_td = document.getElementById('region_td');
				region_td.innerHTML = xmlhttp.responseText;
			}
		}
		xmlhttp.send(null);
	}
}

function get_location(){
	var region_id = document.getElementById('region_id').value;
	if(region_id != 0){
		var location = document.getElementById('location_id');
		location.options.length=0;
		location.options[0] = new Option('loading...',0);
		var serverPage = "ajax/get_location_search.php?region_id=" + region_id;
		xmlhttp.open("GET",serverPage);
		xmlhttp.onreadystatechange = function(){
			if(xmlhttp.readyState == 4 && xmlhttp.status==200){
				var location_td = document.getElementById('location_td');
				location_td.innerHTML = xmlhttp.responseText;
			}
		}
		xmlhttp.send(null);
	}
}

function checksearchinputs(){
	if(document.getElementById('country_id').value=="0"){
		alert("Please select a destination, region, walking area and accommodation type");
		return false;
	}else{
		if(document.getElementById('region_id').value=="0"){
			alert("Please select a region, walking area and accommodation type");
			return false;
		}else{
			/*if(document.getElementById('location_id').value=="0"){
				alert("Please select a walking area and accommodation type");
				return false;
			}else{*/
				if(document.getElementById('prop_type').value=="none"){
					alert("Please select accommodation type");
					return false;
				}
			//}
		}
	}
}

function mprop(prop_id){
	var serverPage = "ajax/get_mprop.php?prop_id=" + prop_id;
	//alert(serverPage);
	xmlhttp.open("GET",serverPage);
	xmlhttp.onreadystatechange = function(){
		if(xmlhttp.readyState == 4 && xmlhttp.status==200){
			//alert(xmlhttp.responseText);
			var mprop = document.getElementById('mprop');
			mprop.innerHTML = xmlhttp.responseText;
		}
	}
	xmlhttp.send(null);
}

function wprop(prop_id){
	var serverPage = "ajax/get_wprop.php?prop_id=" + prop_id;
	//alert(serverPage);
	xmlhttp.open("GET",serverPage);
	xmlhttp.onreadystatechange = function(){
		if(xmlhttp.readyState == 4 && xmlhttp.status==200){
			//alert(xmlhttp.responseText);
			var wprop = document.getElementById('wprop');
			wprop.innerHTML = xmlhttp.responseText;
		}
	}
	xmlhttp.send(null);
}

function getLatestProperty(){
	var serverPage = "ajax/get_latest_property.php";
	//alert(serverPage);
	xmlhttp.open("GET",serverPage);
	xmlhttp.onreadystatechange = function(){
		if(xmlhttp.readyState == 4 && xmlhttp.status==200){
			//alert(xmlhttp.responseText);
			var latestProperty = document.getElementById('latestProperty');
			latestProperty.innerHTML = xmlhttp.responseText;
			get_country();
		}
	}
	xmlhttp.send(null);	
}
