// Preload Images
img1 = new Image(16, 16);  
img1.src="../propias/imagenes/loading.gif";

img2 = new Image(220, 19);  
img2.src="../propias/imagenes/loading.gif";

// When DOM is ready
$(document).ready(function(){
	// Launch MODAL BOX if the Login Link is clicked
	$("#login_link").click(function(){
		$('#login_form').modal();
	});
	
	// When the form is submitted
	$("#status > form").submit(function(){  
		$('#submit').hide();			// Hide 'Submit' Button
		$('#ajax_loading').show();		// Show Gif Spinning Rotator
		var str = $(this).serialize();  // 'this' refers to the current submitted form
		// -- Start AJAX Call --
		$.ajax({  
			type: "POST",
			url: "propias/inc/login.php",  // Send the login info to this page
			data: str,  
			success: function(msg){  
				$("#status").ajaxComplete(function(event, request, settings){  
					$('#submit').show();		// Show 'Submit' Button
					$('#ajax_loading').hide();  // Hide Gif Spinning Rotator
					if(msg == 'OK') { // LOGIN OK?
						var login_response = '<div id="logged_in">' +
							'<div style="width: 40px; float: left;">' +
							'<img style="margin: 10px 0px 10px 0px;" align="absmiddle" src="propias/imagenes/loading.gif">' +
							'</div>' +
							'<div style="margin: 10px 0px 0px 10px; float: right; width: 350px;">'+ 
							'Usted ha entrado correctamente en el sistema<br />Espere para ser llevado nuevamente a la página principal...' +
							'</div>' + 
							'</div>';  
						$('a.modalCloseImg').hide();  
						$('#simplemodal-container').css("width","500px");
						$('#simplemodal-container').css("height","120px");
						$(this).html(login_response); // Refers to 'status'
						setTimeout('go_to_private_page()', 3000); // After 3 seconds redirect the 
					} else {
						// ERROR?
						 var login_response = msg;
						 $('#login_response').html(login_response);
					}  
		  
				});  
			}  
	   
		});  
		// -- End AJAX Call --
		return false;
	}); // end submit event

});

function go_to_private_page() {
	window.location = 'private.php'; // Members Area
}