$(document).ready(function() {
	$("form.validate #email").focus(function() {
		if ($(this).val() == "Your email address") {$(this).val('');} 
		if ($(this).val() == "Invalid email.") {
			$(this).val(''); 
			$(this).attr('style',''); 
		} 
	});
	$("form.validate #email").blur(function() {
		if ($(this).val() == '') {
			$(this).val('Your email address'); 
		} 
	});
	$("form.validate #email").blur(function() {
		if ($("form.validate #email").val() == 'Invalid email.') {
			$("form.validate #email").val('Your email address');
			$("form.validate #email").attr('style','');
		} 
	});
	$("form.validate #zip").focus(function() {
		if ($(this).val() == "ZIP code") {$(this).val('');} 
		if ($(this).val() == "Invalid ZIP code.") {
			$(this).val(''); 
			$(this).attr('style',''); 
		} 
	});
	$("form.validate #zip").blur(function() {
		if ($(this).val() == '') {
			$(this).val('ZIP code'); 
		} 
	});
});

function valid_email(the_form) {
    var el = the_form.email;
    var val = el.value;
    var isValid = true;
    var Regex = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    if (!Regex.test(val)) {
      isValid = false;
    }
    if( !isValid ) { 
      el.value = 'Invalid email.';
      el.style.color = 'red';
    }
  return isValid;
}
function check_length(id,default_value,error_text,min) {
    var el = document.getElementById(id);
    var val = el.value;
    var isValid = true;
    if (val.length<=min || val==default_value || val==error_text) {
      isValid = false;
    }
    if( !isValid ) { 
      el.value = error_text;
      el.style.color = 'red';
    }
  return isValid;
}
function check_form(the_form) {
    var a = check_length('zip', 'ZIP code', 'Invalid ZIP code.', 0);
    var b = valid_email(the_form);
    return (a && b);
}
