$(function() {
	$('div#content form').submit(function() {
		var name = $('input#name');
		var email = $('input#email');
		var zip = $('input#zip');
		
		if (trim(name.val()) == '' || name.val() == 'NAME') {
			name.focus();
			alert('Enter a valid name.');
			return false;
			
		} else if (trim(email.val()) == '' || email.val() == 'EMAIL' || !valid_email(email.val())) {
			email.focus();
			alert('Enter a valid email.');
			return false;
			
		} else if (trim(zip.val()) == '' || zip.val() == 'ZIPCODE') {
			zip.focus();
			alert('Enter a valid zip code.');
			return false;
		}
	});
	
	$('input#name').focus(function() {
		if ($(this).val() == 'NAME') {
			$(this).css({ 'text-align': 'left', 'color': '#000000' });
			$(this).val('');
		}
	}).blur(function() {
		if ($(this).val() == '') {
			$(this).css({ 'text-align': 'center', 'color': '#757575' });
			$(this).val('NAME');
		}
	});
	
	$('input#email').focus(function() {
		if ($(this).val() == 'EMAIL') {
			$(this).css({ 'text-align': 'left', 'color': '#000000' });
			$(this).val('');
		}
	}).blur(function() {
		if ($(this).val() == '') {
			$(this).css({ 'text-align': 'center', 'color': '#757575' });
			$(this).val('EMAIL');
		}
	});
	
	$('input#zip').focus(function() {
		if ($(this).val() == 'ZIPCODE') {
			$(this).css({ 'text-align': 'left', 'color': '#000000' });
			$(this).val('');
		}
	}).blur(function() {
		if ($(this).val() == '') {
			$(this).css({ 'text-align': 'center', 'color': '#757575' });
			$(this).val('ZIPCODE');
		}
	});
});

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function valid_email(email) { 
	var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/ 
	return email.match(re); 
}