$().ready(function() {

	function log(event, data, formatted) {$("<li>").html( !data ? "No match!" : "Selected: " + formatted).appendTo("#result");}
	function formatItem(row) { return row[0] + " (<strong>id: " + row[1] + "</strong>)";}
	function formatResult(row) {return row[0].replace(/(<.+?>)/gi, '');}


	$("#takim").autocomplete("search.php", {
		width: 260,
		selectFirst: false
	});

	

	$("#takim").result(function(event, data, formatted) {
		if (data)
			$(this).parent().next().find("input").val(data[1]);
	});

$("#f1").keyup(function()
{
if (this.value.length>4) {
 //remove all the class add the messagebox classes and start fading
 $("#msgbox").removeClass().addClass('messagebox').text('Kullanici adi kontrol ediliyor').fadeIn("slow");
 //check the username exists or not from ajax
 $.post("api.user.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('Kullanici kayitli').addClass('messageboxerror').fadeTo(900,1);
   });
  }
  else
  {
   $("#msgbox").fadeTo(200,0.1,function()  //start fading the messagebox
   {
    //add message and change the class of the box and start fading
    $(this).html('Kullanici adi uygun').addClass('messageboxok').fadeTo(900,1);
   });
  }
 });
}
else {
	 $("#msgbox").removeClass().text('');
	}
});


});