// Preload Images
img1 = new Image(16, 16);  
img1.src="medias/images/authentification/spinner.gif";

img2 = new Image(220, 19);  
img2.src="medias/images/authentification/ajax-loader.gif";

// When DOM is ready
$(document).ready(function(){

// Launch MODAL BOX if the Login Link is clicked
$("#login").click(function(){
$('#login_formulaire').modal();
$('#identifiant').focus();
});

// When the form is submitted
$("#status > form").submit(function(){  

// Hide 'Submit' Button
$('#submit').hide();

// Show Gif Spinning Rotator
$('#ajax_loading').show();

// 'this' refers to the current submitted form  
var str = $(this).serialize();  

// -- Start AJAX Call --

$.ajax({  
    type: "POST",
    url: URL_AUTHENTIFICATION,  // Send the login info to this page
    data: str,
    success: function(msg){  
    
$("#status").ajaxComplete(function(event, request, settings){  
 
 // Show 'Submit' Button
$('#submit').show();

// Hide Gif Spinning Rotator
$('#ajax_loading').hide();  
var
  etat = msg.substr(0, 2),
  login_response = msg.substr(3);
 if(etat == 'OK') // LOGIN OK?
 {
  $('a.modalCloseImg').hide();  
  
  $('#simplemodal-container').css("width","500px");
  $('#simplemodal-container').css("height","120px");
   
   $(this).html(login_response); // Refers to 'status'
  
  // After 3 seconds redirect the 
  setTimeout('go_to_private_page()', 1500); 
 }  
 else // ERROR?
 {
   $('#login_response').html(login_response);
   $('#identifiant').val("");
   $('#mot_de_passe').val("");
   $('#identifiant').focus();
 }    
 });
 } 
  });  
  
// -- End AJAX Call --

return false;

}); // end submit event

});

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