var ok2Send = false;
var fname = false;
var lname = false;
var email = false;

function val_name(o) {
//	alert('name');
	var user = /[(\*\(\)\[\]\+\.\,\/\?\:\;\'\"\`\~\\#\$\%\^\&\<\>)+]/;
	if (!o.value.match(user)) {
	  doSuccess(o);
	  return true;
	} else {
	 doError(o,'There are no special characters allowed in this field');
	  return false;
	}
}
function val_email(o) {
//	alert('email');
	var email  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (o.value.match(email)) {
	  doSuccess(o);
	  return true;
	} else {
	  doError(o,'Please enter a valid email address.');
	  return false;
	}
}
function doSuccess(o) {
  $('#' + o.id + '_img').html('<img src="media/accept.gif" border="0" style="float:left;" />');
  $('#' + o.id + '_li').removeClass("error");
  $('#' + o.id + '_msg').html("");
  $('#' + o.id + '_li').addClass("success");
}

function doError(o,m) {
  $('#' + o.id + '_img').html('<img src="media/exclamation.gif" border="0" style="float:left;" />');
  $('#' + o.id + '_li').addClass("error");
  $('#' + o.id + '_msg').html('<span style="color: red;">'+m+'</span>');
  $('#' + o.id + '_li').removeClass("success");
}



$(document).ready(function() {   
 $("#first-name").focus(function() {
	if( this.value == this.defaultValue ) {
		this.value = "";
	}
}).blur(function() {
	if( !this.value.length ) {
		this.value = this.defaultValue;
	}
	else {
		fname = val_name(this);
	}
});
$("#last-name").focus(function() {
	$("this:parent").addClass("selected"); 
	if( this.value == this.defaultValue ) {
		this.value = "";
	}
}).blur(function() {
	if( !this.value.length ) {
		this.value = this.defaultValue;
	}
	else {
		lname = val_name(this);
	}
});
$("#email-address").focus(function() {
	if( this.value == this.defaultValue ) {
		this.value = "";
	}
}).blur(function() {
	if( !this.value.length ) {
		this.value = this.defaultValue;
	}
	else {
		email  = val_email(this);
	}
});
$("#comment").focus(function() {
	if( this.value == this.defaultValue ) {
		this.value = "";
	}
}).blur(function() {
	if( !this.value.length ) {
		this.value = this.defaultValue;
	}
});
$("#sign-up-form").bind("submit", function(e) {
	ok2send = (fname && lname && email);
	//alert(ok2Send + " -- " + event);
 	if(ok2send) {	
 		return true; 	
 	}
 	else { 
		alert('There are one or more issues with your form information.\n\nPlease correct any errors before resubmitting.');
 		return false; 
 	}
 });
  
  $(".form li").mouseover(function() {
          $(this).addClass("selected");
  });
  $(".form li").mouseout(function() {
          $(this).removeClass("selected");
  });
});