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

img2 = new Image(220, 19);  
img2.src="images/ajax-loader.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(){  

// 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: "Login",  // 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();  

 if(msg == 'true') // LOGIN OK?
 {  

LoadPage('customer.jsp','loginbox');
$.modal.impl.close();
document.body.scrollTop="410";
 }  
 else // ERROR?
 {  
 var login_response = msg;
 $('#login_response').html(login_response);
 }  
      
 });  
   
 }  
   
  });  
  
// -- End AJAX Call --

return false;

}); // end submit event

});

function LoadPage(page,usediv) {
    // Set up request varible
    try {xmlhttp = window.XMLHttpRequest?new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP");}  catch (e) { alert("Error: Could not load page.");}
    //Show page is loading
    document.getElementById(usediv).innerHTML = '<img src="loading.gif">';
    //scroll to top
    scroll(0,0);
    //send data
    xmlhttp.onreadystatechange = function(){
            //Check page is completed and there were no problems.
            if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)) {
                   //Write data returned to page
                   document.getElementById(usediv).innerHTML = xmlhttp.responseText;
            }
    };
    xmlhttp.open("GET", page);
    xmlhttp.send(null);
    //Stop any link loading normaly
    return false;
}
function ajaxlog(){
	var ucheck = document.getElementById("ajaxlogin").value;
	if (ucheck == "null") {
		$('#login_form').modal(); 
		return false;		
	}else {
		return true;
	}
}
