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

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

window.addEvent('domready', function() {

	var loginform = new Fx.Slide('loginform');
	var el = $('myElement');
	//el.fade.bind(el, [0]).delay(0);
	
	$("myElement").setStyle("display", "none");
	$('ajax_loading').setStyle('display','none');
	
	$('login').addEvent('submit', function(e) {

		// Prevents the default submit event from loading a new page.
		e.stop();

		// Show the spinning indicator when pressing the submit button...
		//el.fade(1);
		$("myElement").setStyle("display", "none");
		$('login_response').setStyle('display','none');
		$('ajax_loading').setStyle('display','block');

		// Hide the submit button while processing...
		//$('submit').setStyle('display','none');
		
		// Set the options of the form's Request handler.
		// ("this" refers to the $('login') element).
		
		this.set('send', { onComplete: function(response) {
			
			$('ajax_loading').setStyle('display','none');

			var response = response;
			var response2 = response.substr(0,2);
			var page = response.substr(3,response.length);
			
			function goToUrl(page) {
				window.location.href = "/" + page;
				//setTimeout('window.location.href = "/" + page;',4000);
			}
			
			if (response2 == 'OK')
			{
			     	 $('loginform').set('html', '<div id="logged_in">Logging in ... Please wait. <br />' +
			      	 '<img align="absmiddle" src="/images/loader-bar.gif" /></div>');
			      	
			 	loginform.slideOut();
			 	
			 	goToUrl(page);
			 	
				//setTimeout('goToUrl(page)',4000);
			}
			
			else if (response == 'FP-OK!') {
			      $('loginform').set('html', '<div class="green"><b>Success!</b><br/><br/>&raquo; Instructions for changing your password have been E-mailed to the address you specified.<br/></div>');
			}
			
			else
			{ 
			
			  $("myElement").setStyle("display", "block");
			  $('login_response').setStyle('display','block');
			  $('login_response').set('html', response);
			  
			  //el.fade(1);
			  
			  // Show the login button
			  $('submit').setStyle('display','block');
			  
			  //e.stop();
			  //el.fade.bind(el, [0]).delay(5000);
			  //$("myElement").setStyle("display", "none");

			}
		}});

		// Send the form.
		this.send();
	});
	
});