// JavaScript Document

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;	
}