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

jQuery(document).ready(function()
{
	jQuery("#frmLog").submit(function()
	{
		//remove all the class add the messagebox classes and start fading
		//jQuery("#msgbox").removeClass().addClass('messagebox').text('Validando...').fadeIn(1000);
		//jQuery.facebox('Validando...');
		//check the username exists or not from ajax
		var u_name = jQuery('#username').val();
		jQuery.post("js/ajax_login.php",{ user_name:jQuery('#username').val(),password:jQuery('#password').val(),rand:Math.random() } ,function(data)
        {
		  if(data=='si') //if correct login detail
		  {
			  //jQuery.facebox('Conectando...');
			  	 //redirect to secure page
				 //document.location='index1.php';
				 //jQuery.facebox('Datos cargados');
				 jQuery("#conectate").hide(300, function () {
				 jQuery("#bienvenido").show(300, function () {
				 jQuery("#conectateTitle").html(u_name).fadeTo(200,1);
													 });
			  });
			  
			 
		  }
		  else 
		  {
		  	
			  //add message and change the class of the box and start fading
			  jQuery.facebox('<h2 style=padding:15px;text-align:center;>&iexcl;Nombre de usuario y/o contrase&ntilde;a incorrectos!</h2>');
				
          }
				
        });
 		return false; //not to post the  form physically
	});
	
	//now call the ajax also focus move from 
	/*jQuery("#password").blur(function()
	{
		jQuery("#frmLog").trigger('submit');
	});*/
});
