// Preload Images
img1 = new Image(16, 16);  
img1.src="Resources/login/images/spinner.gif";

img2 = new Image(220, 19);  
img2.src="Resources/login/images/ajax-loader.gif";

// When DOM is ready

$(document).ready(function()
{
	// Muestra el Form si el Link de loguear se activa
	$("#login_link").click(function(){$('#login_form').modal();});
	// Cuando se presiona el boton de enviar
	$("#status > form").submit(function()
	{  
		// Oculta 'Submit' Button
		$('#submit').hide();
		// Muestra Gif Spinning Rotator
		$('#ajax_loading').show();
		// 'this' refers to the current submitted form  
		var str = $(this).serialize();  

// -- Empieza la Llamada de AJAX --
$.ajax({  
    type: "POST",
    url: "do-login.php",  // Send the login info to this page
    data: str,  
    success: function(msg){  
   		$("#status").ajaxComplete(function(event, request, settings){  
		// Muestra 'Submit' Button
		$('#submit').show();
		// Oculta Gif Spinning Rotator
		$('#ajax_loading').hide();  

 if(msg == 'OK') // LOGIN OK?
 {  
 	var login_response = '<div id="logged_in">' +
	 '<div style="width: 350px; float: left; margin-left: 70px;">' + 
	 '<div style="width: 40px; float: left;">' +
	 '<img style="margin: 10px 0px 10px 0px; float:left;" src="Resources/login/images/ajax-loader.gif">' +
	 '</div>' +
	 '<div style="margin: 10px 0px 0px 10px; width: 300px;" align="left">'+ 
	 "Conexi&oacute;n Exitosa! <br /> Espera mientras carga tu cuenta.......</div></div>"; 

	$('a.modalCloseImg').hide();  
	$('#simplemodal-container').css("width","500px");
	$('#simplemodal-container').css("height","120px");
 
 	$(this).html(login_response); // Imprime el 'status'

	// Despues de 3 Segundos redirecciona 
	setTimeout('go_to_private_page()', 3000); 
 }  
 else // LOGIN ERROR?
 {  
 	var login_response = msg;
 	$('#login_response').html(login_response);
 }  
      
});  
}  
});  
  
// -- Termina Llamada de AJAX --
return false;

}); // end submit event

});

function go_to_private_page()
{
	window.location = 'private.php'; // Si fue OK redirecciona
}
