﻿$(document).ready(function() {
	setupSearchForm();

	$("#SearchResults").hide();
	$("#Loading")
			.hide()
			.ajaxStart(function() { $(this).show(); })
			.ajaxStop(function() { $(this).hide(); });
	$("#Instructions_Link")
		.click(function() { $("#Instructions_Text").slideToggle("slow"); })
		.hover(function() { $(this).css("cursor", "pointer"); }, function() { $(this).css("cursor", "default"); });

	$("#Location").validate({
		errorPlacement: function(error, element) {
			error.appendTo(
					element.parent().parent().children(".Label").children("label")
				);
		},
		rules: {
			/*PostalCode: {
				required: true,
				digits: true,
				minLength: 5
			}*/
		},
		messages: {
			/*PostalCode: "Required"*/
		},
		submitHandler: function(form) {
			search();
		}
	});
	
	if (($("#PostalCode").val() != "") || ($("#City").val() != "")) {
		search();
	}
});

function hasStateProvince() {
	return true;
}

function search() {
	//$("#Instructions_Text").slideUp("slow");
	$("#SearchFrm").slideUp("slow");
	$("#SearchBtn").slideDown("slow");
	$.get("/Search/Events.asp", {
			Radius: $("#Radius").val(),
			Street: $("#Street").val(),
			City: $("#City").val(),
			State: $("#State").val(),
			PostalCode: $("#PostalCode").val(), 
			Country: $("#Country").val()
		},
		function(data) {
			$("#SearchResults").html("<div id='Results'></div>").slideDown("slow");
			$("#Results").append(data);
		}
	);
}