$(document).ready(function () {
    $("#FirstName").focus(function() {if (this.value == 'first name') {this.value='';};});
    $("#FirstName").blur(function() {if (this.value == '') {this.value='first name';};});
    $("#LastName").focus(function() {if (this.value == 'last name') {this.value='';};});
    $("#LastName").blur(function() {if (this.value == '') {this.value='last name';};});
    $("#Address").focus(function() {if (this.value == 'you@yourdomain.com') {this.value='';};});
    $("#Address").blur(function() {if (this.value == '') {this.value='you@yourdomain.com';};});
    $("#form_subscribe").submit(function() {
    	var email = $("#Address").val();
    	var group = $("#Group").val();
		var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		var emailError = ((!(filter.test(email))) || (email=="you@yourdomain.com"));
		var groupError = (group=="");
    	if ((groupError) || (emailError)) {
    		if (emailError) {
    			if (!($("#Address").parent().next().hasClass("error"))) {
					$("#Address").parent().after($('<p class="error">Please enter a valid email address in the form <strong>you@yourdomain.com</strong></p>'));
					$("#Address").parent().children("label").addClass("error");
				}
				$("#Address").focus();
    		}
			if (groupError) {
   		 		if (!($("#Group").parent().next().hasClass("error"))) {
					$("#Group").parent().after($('<p class="error">Please choose your region</p>'));
					$("#Group").parent().children("label").addClass("error");
				}
				$("#Group").focus();
			}
			return false;
		}
		else {return true;}
    });
});
