$.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() {
       // $.fn.validate = validate() {};
    $.fn.validate = {
        init: function(o) {
          	if(o.name == 'names') { this.names(o) };
			if(o.name == 'surname') { this.surname(o) };
          	if(o.name == 'email') { this.email(o) };
			if(o.name == 'myemail') { this.myemail(o) };
        },
        names: function(o) {
			if (o.value == "") {
				doError(o,'this field cannot be empty');
			} else {
				var user = /[(\*\(\)\[\]\+\.\,\/\?\:\;\'\"\`\~\\#\$\%\^\&\<\>)+]/;
				if (!o.value.match(user)) {
					doSuccess(o);
				} else {
					doError(o,'no special characters allowed');
				};
			};
        },
        surname: function(o) {
			if (o.value == "") {
				doError(o,'this field cannot be empty');
			} else {
				var user = /[(\*\(\)\[\]\+\.\,\/\?\:\;\'\"\`\~\\#\$\%\^\&\<\>)+]/;
				if (!o.value.match(user)) {
					doSuccess(o);
				} else {
					doError(o,'no special characters allowed');
				};
			};
        },
        email: function(o) {
			if (o.value == "") {
				doError(o,'this field cannot be empty');
			} else {
				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');
				};
			};
        },
		myemail: function(o) {
			if (o.value == "") {
				doError(o,'this field cannot be empty');
			} else {
				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 id="imgs" src="../images/accept.gif" border="0" style="float:right;" />');
              $('#' + o.id + '_li').removeClass("error");
              $('#' + o.id + '_msg').html("");
              $('#' + o.id + '_li').addClass("success");
     }

     function doError(o,m) {
              //$('#' + o.id + '_img').html('<img id="imgs" src="../images/exclamation.gif" border="0" style="float:right;" />');
              $('#' + o.id + '_li').addClass("error");
              $('#' + o.id + '_msg').html(m);
              $('#' + o.id + '_li').removeClass("success");
     }
};
$.fn.match = function(m) {
	//$('#' + this.get(0).id + '_img').html('<img id="imgs" src="../images/loading.gif" border="0" style="float:right;" />');
	if ($(this).get(0).val() == $(m.match).val()) {
          //$('#' + this.get(0).id + '_img').html('<img id="imgs" src="../images/accept.gif" border="0" style="float:right;" />');
          $(m.error).removeClass("error");
          $(m.error).addClass("success");
          $('#' + this.get(0).id + '_msg').html("");
        } else {
          //$('#' + this.get(0).id + '_img').html('<img id="imgs" src="../images/exclamation.gif" border="0" style="float:right;" />');
          $(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").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 li").mouseover(function() {
          $(this).addClass("selected");
  });
  $(".form li").mouseout(function() {
          $(this).removeClass("selected");
  });*/
});
