/*
    2009-01-16  LQ  Created
*/

$(document).ready(function()
{
    $("#username").blur(function()
    {
        var thisDomain = document.domain;
        
        if(thisDomain == 'localhost')
        {
            var thisData = "http://"+thisDomain+"/prom/site/custom/prom/user_availability.php";
        }
        else
        {
            var thisData = "http://"+thisDomain+"/custom/prom/user_availability.php";
        }
        //remove all the class add the messagebox classes and start fading
        $("#msgbox").removeClass().addClass('messagebox').text('Checking...').fadeIn("slow");
        //check the username exists or not from ajax
        $.post(thisData,{ 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('This Username already exists').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('This Username is available to register').addClass('messageboxok').fadeTo(900,1);	
                });
            }
        });
    });
});