// JavaScript Document

jQuery(document).ready(function() {
								
$("#client_login_button").fancybox({
	'scrolling'		: 'no',
	'titleShow'		: false,
	'onClosed'		: function() {
	    $("#login_error").hide();
	}
});

//Ref validation http://fancybox.net/blog
$("#client_login_form").bind("submit", function() {
	$("#login_error").hide();
	$("#login_error").html('');

	$.ajax({
		type		: "POST",
		cache	: false,
		url		: "/client-login",
		data		: $(this).serializeArray(),
		success: function(data)
		{
			//console.log('data: '+data);
			// successful login?
			if (data.slice(0, 7) == 'success')
			{
				if(data.slice(8, 22) == 'changepassword'){
					$(".password_change_container").css("display", 'block');
					$("#client_login_form").css("display", 'none');
				} else {
					location.reload();
				}
			}
			else
			{
				// show error in the fancy box popup
				$("#login_error").hide();
				$("#login_error").html(data);
				$("#login_error").fadeIn();
				//$.fancybox(data);
			}
		}
	});
	return false;
});


//Ref validation http://fancybox.net/blog
$("#client_update_form").bind("submit", function() {
	
	$("#update_error").hide();
	$("#update_error").html('');

	$.ajax({
		type		: "POST",
		cache	: false,
		url		: "/client-update-password",
		data		: $(this).serializeArray(),
		success: function(data)
		{
			// successful login?
			if (data.slice(0, 7) == 'success')
			{
				location.reload();
			}
			else
			{
				// show error in the fancy box popup
				$("#update_error").hide();
				$("#update_error").html(data);
				$("#update_error").fadeIn();
				//$.fancybox(data);
			}
		}
	});
	return false;
});




});
