// JavaScript Document
var curr_z_index = 1;

function page_loaded() {

	$('#dateFrom').datepicker({
		numberOfMonths: 1,
		showButtonPanel: true,
		dateFormat: 'dd.mm.yy',
		firstDay: 1,
		showOtherMonths: true,
		minDate: 0,
		onSelect: function(dateText) {
			if (document.getElementById('dateTo').value == 0)
				document.getElementById('dateTo').value = dateText;
		}
	});
	
	$('#dateTo').datepicker({
		numberOfMonths: 1,
		showButtonPanel: true,
		dateFormat: 'dd.mm.yy',
		firstDay: 1,
		showOtherMonths: true,
		minDate: 0
	});
	$("#ui-datepicker-div").hide();
}



function checkApartments() 
{
	if (isEmpty("dateFrom") || isEmpty("dateTo") || isEmpty("persons"))
	{
		alert("Fill all Fields!");
		return;	
	}
	
	$("#bt_search").hide();
	$("#bt_search_progress").show();
	//prompt("1", "checkApartments.php?objectIds=" +  document.getElementById("allObjPipe").value + "&from=" +document.getElementById("dateFrom").value+ "&persons=" +document.getElementById("persons").value+ "&to=" +document.getElementById("dateTo").value)
	$.get("checkApartments.php?", { ts: Math.random()*Math.random(), objectIds: document.getElementById("allObjPipe").value, from:document.getElementById("dateFrom").value, to:document.getElementById("dateTo").value, persons:document.getElementById("persons").value}, function(data){
		
		if (data.indexOf("AA") == 0)
		{
			nO = data.replace("AA","");
			if (nO.length == 0)
			{	
				$("#bt_search").show();		
				$("#bt_search_progress").hide();
				alert("No Apartments available.");
				return;	
			}
			else
			{
				location.href = "apartments.php?o=" + nO + "&from=" + document.getElementById("dateFrom").value + "&to=" + document.getElementById("dateTo").value + "&persons=" + document.getElementById("persons").value;	
			}
		}
		else
		{
			$("#bt_search").show();		
			$("#bt_search_progress").hide();
			alert("Some Error occured. Please try again.");	
		}
	});
}

function isEmpty(obj)
{
	if (document.getElementById(obj) != null && document.getElementById(obj).value.length > 0)
        return false;
    return true;	
}

function changeLang_change() {
	nLang = document.getElementById("changeLang").value;
	nLocation = location.href.split("?")[0].split("#")[0] + urlparam + "lang=" + nLang;
	location.href = nLocation;
}
