// JavaScript Document

jQuery.fn.wait = function(time, type) {
	time = time || 1000;
	type = type || "fx";
	return this.queue(type, function() {
		var self = this;
		setTimeout(function() {
			j(self).dequeue();
		}, time);
	});
};


j(function() {
	j("#username").blur(function() {
		j("#msgbox").removeClass().addClass('messagebox').text('Checking...').fadeIn("slow");
		j.post("user_availability.php",{ user:j(this).val() } ,function(data) {
		  if(data=='no') { //if username not avaiable
		  	j("#msgbox").fadeTo(200,0.1,function() {  //start fading the messagebox

			  j(this).html('This username already exists!').addClass('messageboxerror').fadeTo(900,1);
			});		
          }
		  else
		  {
		  	j("#msgbox").fadeTo(200,0.1,function() {  //start fading the messagebox 
			  //add message and change the class of the box and start fading
			  j(this).html('Username available to register!').addClass('messageboxok').fadeTo(900,1).wait(2000).fadeTo(900,0);
			});
		  }
				
        });
 
	});	
});
