//<!---------------------------------+
//  Developed by Roshan Bhattarai 
//  Visit http://roshanbh.com.np for this script and more.
//  This notice MUST stay intact for legal use
// --------------------------------->
$(document).ready(function()
{
	$("#username").blur(function()
	{
		//remove all the class add the messagebox classes and start fading
		$("#user_msgbox").removeClass().addClass('messagebox').text('Checking...').fadeIn("slow");
		//check the username exists or not from ajax
		$.post("/inc/xhr/user_availability.php",{ user_name:$(this).val() } ,function(data)
        {
		  if(data=='exists') //if username not avaiable
		  {
		  	$("#user_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 Already exists!').addClass('messageboxerror').fadeTo(900,1);
			  $("#KT_Insert1").attr("disabled", true);
			});		
          }
		  else if(data=='empty')
		  {
		  	$("#user_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 Required!').addClass('messageboxerror').fadeTo(900,1);	
			  $("#KT_Insert1").attr("disabled", true);
			});
		  }
		  else if(data=='yes')
		  {
		  	$("#user_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 available to register.').addClass('messageboxok').fadeTo(900,1);	
			  $("#KT_Insert1").attr("disabled", false);
			});
		  }
		  else
		  {
		  	$("#user_msgbox").fadeTo(200,0.1,function()  //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('Contact Administrator. Report "Username Check Error"').addClass('messageboxerror').fadeTo(900,1);	
			  $("#KT_Insert1").attr("disabled", true);
			});
		  }
				
        });
 
	});
	
	$("#username").focus(function()
	{
		$("#user_msgbox").removeClass();
		$("#user_msgbox").hide();
	});
	
	$("#email").blur(function()
	{
		//remove all the class add the messagebox classes and start fading
		$("#email_msgbox").removeClass().addClass('messagebox').text('Checking...').fadeIn("slow");
		//check the username exists or not from ajax
		$.post("/inc/xhr/referrer_email_check.php",{ email:$(this).val() } ,function(data)
        {
		  if(data=='no') //if username not avaiable
		  {
		  	$("#email_msgbox").fadeTo(200,0.1,function() //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('Valid Email Address Required').addClass('messageboxerror').fadeTo(900,1);
			  $("#KT_Insert1").attr("disabled", true);
			});		
          }
		  else if(data=='invalid')
		  {
		  	$("#email_msgbox").fadeTo(200,0.1,function()  //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('Email Domain does not exist! Please use a valid email address.').addClass('messageboxerror').fadeTo(900,1);	
			  $("#KT_Insert1").attr("disabled", true);
			});
		  }
		  else if(data=='exists')
		  {
		  	$("#email_msgbox").fadeTo(200,0.1,function()  //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('Email Already Exists!').addClass('messageboxerror').fadeTo(900,1);	
			  $("#KT_Insert1").attr("disabled", true);
			});
		  }
		  else if(data=='format')
		  {
		  	$("#email_msgbox").fadeTo(200,0.1,function()  //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('Bad Email Format or Domain!').addClass('messageboxerror').fadeTo(900,1);	
			  $("#KT_Insert1").attr("disabled", true);
			});
		  }
		  else if(data=='yes')
		  {
		  	$("#email_msgbox").fadeTo(200,0.1,function()  //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('Email available to register.').addClass('messageboxok').fadeTo(900,1);	
			  $("#KT_Insert1").attr("disabled", false);
			});
		  }
		  else
		  {
		  	$("#email_msgbox").fadeTo(200,0.1,function()  //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('Contact Administrator! Report "Email Check Error"').addClass('messageboxerror').fadeTo(900,1);	
			  $("#KT_Insert1").attr("disabled", true);
			});
		  }
			  
				
        });
 
	});
	
	$("#email").focus(function()
	{
		$("#email_msgbox").removeClass();
		$("#email_msgbox").hide();
	});
	
});
