$(document).ready(function(){  
/*
 * 		Contact Form Validation
 */
	$('#contactform').submit(function() {
	
		// Disable the submit button
		$('#contactform input[type=submit]')
			.attr('value', 'Creating Account...')
			.attr('disabled', 'disabled');
		$('span#loader').html('<img src="/images/ajax-loader.gif" />');
	
		// AJAX POST request
		$.post(
			$(this).attr('action'),
			{
				email:$('#email').val(),
				domain_name:$('#domain_name').val(),
				no_spam:$('#no_spam').val()
			},
			function(errors) {
				// No errors
				if (errors == null) {
					pageTracker._trackPageview("/hosting/signup_success.html");
					$('#contactform')
						.hide()
						.html('<h3>Thank you</h3><p>Your account has been created. Please check your email!</p><p>To sign in, use the link in the menu above.</p>')
						.show();
				}
	
				// Errors
				else {
					// Re-enable the submit button
					$('#contactform input[type=submit]')
						.removeAttr('disabled')
						.attr('value', 'SIGN UP!');
					$('span#loader').html('');
	
					// Technical server problem, the email could not be sent
					if (errors.server != null) {
						alert(errors.server);
						return false;
					}
	
					// Empty the errorbox and reset the error alerts
					$('#contactform .errorbox').html('<ul></ul>').show();
					$('#contactform li').removeClass('alert');
	
					// Loop over the errors, mark the corresponding input fields,
					// and add the error messages to the errorbox.
					for (field in errors) {
						if (errors[field] != null) {
							$('#' + field).parent('li').addClass('alert');
							$('#contactform .errorbox ul').append('<li>' + errors[field] + '</li>');
						}
					}
				}
			},
			'json'
		);
	
		// Prevent non-AJAX form submission
		return false;
	});

	$('form#ticket_form').submit(function() {
		// Disable the submit button
		$('#ticket_form input[type=submit]')
			.attr('value', 'Sending Support Ticket...')
			.attr('disabled', 'disabled');
		$('span#loader').html('<img src="/images/ajax-loader.gif" />');

		$.post(
			$(this).attr('action'),
			{
				message:$('#message').val(),
				subject:$('#subject').val()
			},
			function(errors) {
				// No errors
				$('#ticket_form')
					.hide()
					.html('<h3>Thank you</h3><p>Your support request has been sent. We will reply to your request shortly.</p>')
					.show();
			});
		return false;
	});

});