new function() {
       // $.fn.validate = validate() {};
    $.fn.validate = {
        init: function(o) {
          if(o.name == 'memberUserName') { this.username(o) };
		  if(o.name == 'memberEmail') { this.email(o) };
		  if(o.name == 'memberPostalCode') { this.postalCode(o) };
		  if(o.name == 'memberBirthday') { this.date(o) };
        },
        username: function(o) {
          var user = /[(\*\(\)\[\]\+\.\,\/\?\:\;\'\"\`\~\\#\$\%\^\&\<\>)+]/;
           if (!o.value.match(user)) {
             doValidate(o);
            } else {
             doError(o,'No special characters allowed');
            };
        },
        email: function(o) {
          var email  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
           if (o.value.match(email)) {
              doValidate(o);
            } else {
              doError(o,'Not a valid email');
            };
        },
		postalCode: function(o) {
			var postalCode = /[(\*\(\)\[\]\+\.\,\/\?\:\;\'\"\`\~\\#\$\%\^\&\<\>)+]/;
			if (!o.value.match(postalCode)) {
             doPostalValidate(o);
            } else {
             doError(o,'No special characters allowed');
            };
		},
        date: function(o) {
           doValidate(o);
        }
     };

     function doPostalValidate(o) {
			$('#' + o.id + '_img').html('<img src="images/webDev/loading.gif" border="0" style="float:left;" />');
			country = $('#memberCountry').val();
			if(country == "United States" || country == "Canada") {
				$.post('includes/webDevPostalCodeAJAX.php', { id: o.id, whattodo: 'memberPostalCode', zip: o.value, country: country }, function(json) {
                  	eval("var args = " + json);
                    if (args.success == true)
                  	{
                  	  doPostalSuccess(args.city, args.state);
                  	}
                });
			}
     }

     function doPostalSuccess(city, state) {
			  $('#memberState').attr("value", state);
			  $('#memberCity').attr("value", city);		  
     }

     function doSuccess(o) {
              $('#' + o.id + '_img').html('<img src="images/webDev/accept.gif" border="0" style="float:left;" />');
			  $('#' + o.id + '_validated').attr("value", "true");
              $('#' + o.id + '_msg').html("");
     }

     function doError(o,m) {
              $('#' + o.id + '_img').html('<img src="images/webDev/exclamation.gif" border="0" style="float:left;" />');
			  $('#' + o.id + '_validated').attr("value", "false");
              $('#' + o.id + '_msg').html(m);
     }
     //private helper, validates each type after check
     function doValidate(o) {
        	$('#' + o.id + '_img').html('<img src="images/webDev/loading.gif" border="0" style="float:left;" />');
        	$.post('includes/webDevUniqueUserNameAJAX.php', { id: o.id, value: o.value }, function(json) {
                  	eval("var args = " + json);
                        if (args.success == true)
                  	{
                  	  doSuccess(args);
                  	}
                  	else
                  	{
                          doError(args,args.msg);
                  	}
                  });
    };

};
$.fn.match = function(m) {
	$('#' + this.get(0).id + '_img').html('<img src="images/webDev/loading.gif" border="0" style="float:left;" />');
	if ($(this).val() == $(m.match).val()) {
          $('#' + this.get(0).id + '_img').html('<img src="images/webDev/accept.gif" border="0" style="float:left;" />');
          $('#' + this.get(0).id + '_msg').html("");
        } else {
          $('#' + this.get(0).id + '_img').html('<img src="images/webDev/exclamation.gif" border="0" style="float:left;" />');
          $('#' + this.get(0).id + '_msg').html("The passwords don't match, please try again");
        };
};
	
$(document).ready(function()
{

   $('#memberUserName').ready(function() {
		if ($('#memberUserName').val() != "") {
			o = this;
			o.id = 'memberUserName';
			o.name = 'memberUserName';
			o.value = $('#memberUserName').val();
			$(o).validate.init(o);	
		}
	});
	
	$('#memberBirthday').ready(function() {
		if ($('#memberBirthday').val() != "") {
			o = this;
			o.id = 'memberBirthday';
			o.name = 'memberBirthday';
			o.value = $('#memberBirthday').val();
			$(o).validate.init(o);
		}
	});
   
   $('#memberEmail').ready(function() {
		if ($('#memberEmail').val() != "") {
			o = this;
			o.id = 'memberEmail';
			o.name = 'memberEmail';
			o.value = $('#memberEmail').val();
			$(o).validate.init(o);	
		}
	});

  $("[@class=validated]:input").blur(function() {
          $(this).validate.init(this);
  });

});
