// Global settings for future AJAX calls
$(function(){
	$.ajaxSetup({
		type: "POST",
		dataType: "html",
		cache: false
	});
});


// This is a general function to submit a form using ajax.
function ajaxSubmitForm(f)
{
	$.ajax({
		url: "/includes/"+f+"-form.inc.php",
		data: $("#"+f+"form").serialize(),
		success: function(html){
			$("#"+f+"formcont").html(html);
		}
	});
	
	return false;
}

// update a cont
function updateCont(cont, id)
{
	$.ajax({
		url: "/includes/"+cont+".inc.php",
		data: ({cont: cont, id: id}),
		success: function(html){
			$("#"+cont+"cont").html(html);
		}
	});
	
	return false;
}

// search form functions
function updateCategories(location)
{
	$.ajax({
		url: "/includes/search-form-category.inc.php",
		data: ({location: location}),
		type: "GET",
		success: function(html){
			$("#category-cont").html(html);
			$("#type").attr("disabled", "disabled");
		}
	});
	
	return false;
}

function updateTypes(location, category, is_searchresults)
{
	$.ajax({
		url: "/includes/search-form-type.inc.php",
		data: ({location: location, category: category}),
		type: "GET",
		success: function(html){
			$("#type-cont").html(html);
		}
	});
	
	return false;
}

function checkForm() {
	if ($("#location").val() == "" || $("#category").val() == "") {
		alert("Please select a Location and Category to search.");
		
		return false;
	}
	
	/// build url
	url = "/" + $("#location").val() + "/" + $("#category").val() + "/";
	// add type if necessary
	if ($("#type").size() != 0 && $("#type").val() != "") url = url + $("#type").val() + "/";

	// redirect
	document.location = url;
	
	return false;
}
	
