//<!---------------------------------+
//  Developed by Roshan Bhattarai 
//  Visit http://roshanbh.com.np for this script and more.
//  This notice MUST stay intact for legal use
// --------------------------------->

//function user_availability () {
//var _username = document.registrazione.username;

/*if ((_username.value.length<6) || (_username.value==null)) {
     alert("- Lo username deve essere lungo almeno 6 caratteri\n");
		 return;
    }*/

$(document).ready(function()
{
	$("#username").blur(function()
	{ 
		if ((document.registrazione.username.value.length<6) || (document.registrazione.username.value==null)) {
			$("#msgbox").removeClass().addClass('messagebox').text('Lo username deve essere lungo almeno 6 caratteri').fadeIn(1000);
		 return;
    }
		
		//remove all the class add the messagebox classes and start fading
		$("#msgbox").removeClass().addClass('messagebox').text('Checking...').fadeIn(1000);
		//check the username exists or not from ajax
		$.post("/files/user_availability.php",{ username:$(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('Username non disponibile').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('Username disponibile').addClass('messageboxok').fadeTo(900,1);	
			});
		  }
				
        });
 
	});
});
//}
