/*
* Sitewide JS functions go here
*/
$(document).ready( function() {

	// handles mailing list signup form using ajax
	$("#client_subscribe_form").bind("submit", function() {
		$("#client_subscribe_form").fadeOut('fast', function () {

			$("#client_subscribe_error").html('');

			$.ajax({
				type		: "POST",
				cache	: false,
				async	: false,
				url		: "/mailingLists/ajaxSignup",
				data		: $(this).serializeArray(),
				success: function(data)
				{
					//console.log('data: '+data);
					if (data.slice(0, 7) == 'success')
					{
						$("#client_subscribe_form").html('<br />Thanks - you have been successfully added to our Mailing List.<br /><br />');
					}
					else
					{
						// show error
						$("#client_subscribe_error").html(data);
						$("#client_subscribe_error").fadeIn();
					}
				}
			});
		});
		$("#client_subscribe_form").fadeIn();
		return false;	// stops form loading on new page
	});


	/*
	* Disables submit button and displays loading text
	* Useful when handling big file uploads etc so user doesn't click submit button more than once
	*/
/*	$(".toggle_loading").click( function (e)
	{
		var alt = $(this).attr('alt');
		if (!alt)
		{
			alt = 'Saving, please wait...';
		}

		$(this).hide();
		$(this).attr('value', alt);
		$(this).attr('disabled', 'true');
		$(this).fadeIn();

	});*/

});