$.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 == 'langd1') { this.langd(o) };
    	 if(o.name == 'langd2') { this.langd(o) };
    	 if(o.name == 'langd3') { this.langd(o) };
    	 if(o.name == 'langd4') { this.langd(o) };
    	 if(o.name == 'langd5') { this.langd(o) };
    	 if(o.name == 'langd6') { this.langd(o) };
    	 if(o.name == 'langd7') { this.langd(o) };
    	 if(o.name == 'langd8') { this.langd(o) };
    	 if(o.name == 'langd9') { this.langd(o) };
    	 if(o.name == 'langd10') { this.langd(o) };
         if(o.name == 'antal1') { this.antal(o) };
         if(o.name == 'antal2') { this.antal(o) };
         if(o.name == 'antal3') { this.antal(o) };
         if(o.name == 'antal4') { this.antal(o) };
         if(o.name == 'antal5') { this.antal(o) };
         if(o.name == 'antal6') { this.antal(o) };
         if(o.name == 'antal7') { this.antal(o) };
         if(o.name == 'antal8') { this.antal(o) };
         if(o.name == 'antal9') { this.antal(o) };
         if(o.name == 'antal10') { this.antal(o) };

        },
        langd: function(o) {
         
           if (o.value <= 3200 && o.value > 1 ) {
              doSuccess(o);
            } else {
              doError(o,'');
            };
        },
        antal: function(o) {
        	 
            if (o.value > 0) {
              doSuccess(o);
            } else {
              doError(o);
            };
        }
     };

     function doSuccess(o) {
              $('#' + o.id + '_li').removeClass("error");
              $('#' + o.id + '_li').addClass("success");
     }

     function doError(o) {
              $('#' + o.id + '_li').addClass("error");
              $('#' + o.id + '_li').removeClass("success");
              document.getElementById("next").style.display="hidden";
     }
     //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").keyup(function() {
          $(this).validate.init(this);
  });
  

  $("#confirmpass").keyup(function() {
          $(this).match({match: '#password', error: '#confirmpass_li'});
  });


  $("#password").keyup(function() {
          $(this).copyTo("#password_copy","value");
  });
});
