
$.fn.copyTo = function(to) {
    var to = $(to);
    for ( var i = 1; i < arguments.length; i++ )
        to.set( arguments[i], this.get(0)[ arguments[i] ] );
    return this;
};

new function() {
		$('.form input').css({backgroundColor:"#FFFFFF"});
		$('.form input').focus(function(){
			$(this).css({backgroundColor:"#FF0"});
		});
		$('.form input').blur(function(){
			$(this).css({backgroundColor:"#FFFFFF"});
		});
       // $.fn.validate = validate() {};
		var valCount = 0;
    $.fn.validate = {
        init: function(o) {
          if(o.name == 'fname') { this.fname(o) };
					if(o.name == 'lname') { this.lname(o) };
					if(o.name == 'address') { this.address(o) };
					if(o.name == 'city') { this.city(o) };
					if(o.name == 'state') { this.state(o) };
					if(o.name == 'zip') { this.zip(o) };
          if(o.name == 'email') { this.email(o) };
        },
        fname: function(o) {
          var fname = /[(\*\(\)\[\]\+\.\,\/\?\:\;\"\`\~\\#\$\%\^\&\<\>)+]/;
           if (!o.value.match(fname) && o.value.length >= 3){
						 var zFname = true;
						 return zFname;
             doSuccess(o);
            } else {
             doError(o,'name must contain 3 or more alphanumeric characters');
            };
        },
				lname: function(o) {
          var lname = /[(\*\(\)\[\]\+\.\,\/\?\:\;\"\`\~\\#\$\%\^\&\<\>)+]/;
           if (!o.value.match(lname) && o.value.length >= 3){
             doSuccess(o);
            } else {
             doError(o,'name must contain 3 or more alphanumeric characters');
            };
        },
				address: function(o) {
          var address = /[(\*\(\)\[\]\+\,\/\?\:\;\"\`\~\\#\$\%\^\&\<\>)+]/;
           if (!o.value.match(address) && o.value.length >= 5){
             doSuccess(o);
            } else {
             doError(o,'address must contain 5 or more alphanumeric characters');
            };
        },
				city: function(o) {
          var city = /[(\*\(\)\[\]\+\,\/\?\:\;\"\`\~\\#\$\%\^\&\<\>)+]/;
           if (!o.value.match(city) && o.value.length >= 3){
             doSuccess(o);
            } else {
             doError(o,'city must contain 3 or more alphanumeric characters');
            };
        },
				state: function(o) {
           if (o.value.length == 2){
             doSuccess(o);
            } else {
             doError(o,'you must select a state');
            };
        },
				zip: function(o) {
          var zip = /[a-zA-Z_\(\*\(\)\[\]\+\.\,\/\?\:\;\"\`\~\\#\$\%\^\&\<\>)+]/;
           if (!o.value.match(zip) && o.value.length == 5){
             doSuccess(o);
            } else {
             doError(o,'zip code must contain 5 numeric characters');
            };
        },
        email: function(o) {
          var email  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
           if (o.value.match(email)) {
              doSuccess(o);
            } else {
              doError(o,'not a valid email');
            };
        },
				
     };

     function doSuccess(o) {
              $('#' + o.id + '_img').html('<img src="/images/accept.gif" border="0" style="float:left;" />');
              $('#' + o.id + '_li').removeClass("error");
              $('#' + o.id + '_msg').html("");
              $('#' + o.id + '_li').addClass("success");
							valCount++;
							return valCount;
     }

     function doError(o,m) {
              $('#' + o.id + '_img').html('<img src="/images/exclamation.gif" border="0" style="float:left;" />');
              $('#' + o.id + '_li').addClass("error");
              $('#' + o.id + '_msg').html(m);
              $('#' + o.id + '_li').removeClass("success");
     }

     //private helper, validates each type after check
     /*function doValidate(o) {
        	$('#' + o.id + '_img').html('<img src="/images/loading.gif" border="0" style="float:left;" />');
        	$.post('ajax.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/loading.gif" border="0" style="float:left;" />');
	if ($(this).get(0).val() == $(m.match).val()) {
          $('#' + this.get(0).id + '_img').html('<img src="images/accept.gif" border="0" style="float:left;" />');
          $(m.error).removeClass("error");
          $(m.error).addClass("success");
          $('#' + this.get(0).id + '_msg').html("");
        } else {
          $('#' + this.get(0).id + '_img').html('<img src="images/exclamation.gif" border="0" style="float:left;" />');
          $(m.error).addClass("error");
          $(m.error).removeClass("success");
          $('#' + this.get(0).id + '_msg').html("The passwords don't match, please try again");
        };
};
*/
$(document).ready(function()
{

$("//[@class=validated]/input,select").blur(function() {
          $(this).validate.init(this);
  }); 

/*
  $("#confirmpass").blur(function() {
          $(this).match({match: '#password', error: '#confirmpass_li'});
  });
*/
/*
  $("#password").keyup(function() {
          $(this).copyTo("#password_copy","value");
  });
*/

  // This Used To Be HOVER, But I.E. Didnt Like It
  //$(".form li").hover(function(){$(this).addClass("selected");},function(){$(this).removeClass("selected");});
/*  $(".form input").mouseover(function() {
          $(this).addClass("selected");
  });
  $(".form input").mouseout(function() {
          $(this).removeClass("selected");
  });*/
});