var emailPlaceholder = 'Your Email';

$(document).ready(function() {
	
	// Private Beta Request Input Box Manipulation:
	
	$('#email').focus(function() {
		if ($(this).val() === emailPlaceholder) {
			$(this).val('');
			$(this).css('color', '#776e62');
		}
	});
	$('#email').blur(function() {
		if ($(this).val() === '' || $(this).val() === emailPlaceholder) {
			$(this).val(emailPlaceholder);
			$(this).css('color', '#d6d0c7');
		}
	});
});

function verifyEmail(email) {
	if (email.match(/[a-z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/i)) {
		return true;
	} else {
		return false;
	}
}

function requestInvite() {
	var email = $('#email').val().toLowerCase();
	
	if (email.length <= 0 || email === emailPlaceholder) {
		$('#feedback').text('No Email Address was entered. Please enter your Email Address to register.');
	} else if (!verifyEmail(email)) {
		$('#feedback').text('Email address must be in the form "name@domain.com"');
	} else {
		$.get('invite.php', {email: email}, function(ret) {
			if (ret === 'success') {
				$('#feedback').html('Thank you for your interest.<br/>You will be notified when the Xen Private Beta starts.').delay(5000).fadeOut(1000, function() { $(this).html('').show(); });
			} else {
				$('#feedback').text(ret);
			}
		});
	}
	
	if ($('#feedback').text().length > 0) {
		$('#feedback').css('visibility', 'visible');
	}
}

