// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
jQuery.noConflict();
jQuery(document).ready(function(){
	jQuery("#user_login").blur(function() {
	    //remove all the class add the messagebox classes and start fading
		jQuery("#msgbox").removeClass().addClass('messagebox').html("<img src='/images/ajax-loader.gif'></img>").fadeIn("slow");
	    //check the username exists or not from ajax
		jQuery.post("/checkuser",{ user_login:jQuery(this).val() } ,function(data) {
	    	if(data=='true') { //if username not avaiable
	    		jQuery("#msgbox").fadeTo(200,0.1,function() { //start fading the messagebox
	             //add message and change the class of the box and start fading
	    			jQuery(this).html("<font color='red'>มีชื่อนี้อยู่ในระบบแล้วค่ะ</font>").addClass('messageboxerror').fadeTo(900,1);
	           });
	        } else {
	        	jQuery("#msgbox").fadeTo(200,0.1,function() {  //start fading the messagebox
	        	   //add message and change the class of the box and start fading
	        		jQuery(this).html('ใช้งานชื่อนี้ได้ค่ะ').addClass('messageboxok').fadeTo(900,1);
	           });
	        }
	    });
	});
});


