/*
      ___         ___                                       ___                       ___           ___      /  /\       /  /\         _____         _____         /  /\        ___          /__/|         /__/|    /  /|/_     /  /||\       /  /||\       /  /||\       /  /||\      /  /\        |  |||        |  |||   /  /|/ /\   /  /|/\|\     /  /|/\|_     /  /|/\|_     /  /|/\|\    /  /|/        |  |||        |  |||  /  /|/ /|/  /  /|/-/||\   /  /|/-/||\   /  /|/-/||\   /  /|/-/|/   /__/||\      __|  |||      __|  ||| /__/|/ /|/  /__/|/ /|/\|\ /__/|/ /|/\|| /__/|/ /|/\|| /__/|/ /|/___ \__\/\|\__  /__/\_|||____ /__/\_|||____ \  \|\/|/   \  \|\/|/__\/ \  \|\/|/-/|/ \  \|\/|/-/|/ \  \|\/|||||/    \  \|\/\ \  \|\/|||||/ \  \|\/|||||/  \  \||/     \  \||/       \  \||/ /|/   \  \||/ /|/   \  \||/----      \__\||/  \  \||/----   \  \||/----   \  \|\      \  \|\        \  \|\/|/     \  \|\/|/     \  \|\          /__/|/    \  \|\        \  \|\    \  \|\      \  \|\        \  \||/       \  \||/       \  \|\         \__\/      \  \|\        \  \|\     \__\/       \__\/         \__\/         \__\/         \__\/                     \__\/         \__\/

Copyright Fabbrikk - http://fabbrikk.com/ - Scandola Christian - http://twitter.com/fabbrikk
*/
$(document).ready(function() { 
    $('fieldset.textfield label').inFieldLabels();
    $('button.submit').click(function (e) {
		e.preventDefault();
		var $this = $(this);
		var address = $this.html();
		$this.attr('disabled','disabled');
		$this.addClass('disabled');
		$this.blur();
		$this.html('Sending...');
    	$this.closest('form').ajaxSubmit({
			cache: false,
			dataType: 'html',
			complete: function (xhr) {
					$this.removeClass('disabled good bad');
					switch(xhr.responseText)
					{
						case 'Thank you!':
							$this.html(xhr.responseText);
							$this.addClass('good');
							$this.prev('fieldset.textfield input').val('check your mail inbox');
						break;
						case 'Mail exist!':
						case 'Bad mail!':
						case 'Ooopppss!':
							$this.html(xhr.responseText);
							$this.addClass('bad').fadeTo(3000,1, function() {
								$(this).removeClass('good bad').html(address).removeAttr('disabled')
							});
						break;
						default:
							$this.html('ERROR!');
							$this.addClass('bad').fadeTo(3000,1, function() {
								$(this).removeClass('disabled good bad').html(address).removeAttr('disabled')
							});
						break;
					}
			},
			error: function (xhr) {
					$this.html('ERROR!');
					$this.addClass('bad').fadeTo(3000,1, function() {
						$(this).removeClass('disabled good bad').html(address).removeAttr('disabled')
					});
			}
		});
    });
});
