$(document).ready(function() {
	var checkUser = function (username) {
		var username = $('#username').val();
		var serviceName  = $('input[name=service]:checked').val() 
		var myRand   = parseInt(Math.random()*99999999);
		//remove all the class add the messagebox classes and start fading
		$("#"+serviceName).html('<img src="images/loading.gif">').fadeIn("slow");		
		$.post(
			"php/checkUser.php",
			{user: username, service: serviceName, opID: myRand},
			function(data) {
				if(data) { //if username not avaiable
					$("#"+serviceName).html('<img src="images/loading.gif">').fadeOut("slow");
				  	$("#response").fadeTo(200,0.1,function() { //start fading the messagebox
						//add message and change the class of the box and start fading
			  			$(this).html(data).fadeTo(900,1);
					});		
          		}
			}			
		)
	}
	$("#checkUser").click(checkUser);
});