$(document).ready(function()
{
	$("#username").blur(function()
	{
		//remove all the class add the messagebox classes and start fading
		$("#msgbox").removeClass().addClass('messagebox').text('Kontrol Ediliyor...').fadeIn("slow");
		//check the username exists or not from ajax
		$.post("uye_ismi_kontrol.php",{ user_name:$(this).val() } ,function(data)
        {

		  if(data=='no') //if username not avaiable
		  {
		  	$("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('<br>Bu kullanıcı adı kullanılıyor. Lütfen başka kullanıcı adı yazınız.').addClass('messageboxerror').fadeTo(900,1);
			});		
          }

		  if (data=='yes')
		  {
		  	$("#msgbox").fadeTo(200,0.1,function()  //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('Kullanıcı adı uygun').addClass('messageboxok').fadeTo(900,1);	
			});
		  }

		  if (data=='kisa_ad')
		  {
		  	$("#msgbox").fadeTo(200,0.1,function()  //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('kullanıcı adı 4 karakterden kısa olamaz!').addClass('messageboxerror').fadeTo(900,1);	
			});
		  }

		  if (data=='bos')
		  {
		  	$("#msgbox").fadeTo(200,0.1,function()  //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('kullanıcı adı yazınız').addClass('messageboxerror').fadeTo(900,1);	
			});
		  }
				
        });
 
	});
});
