
// AFFICHE LE PANNEAU DE LOGIN


window.addEvent('domready', function(){

	$('login').setStyle('height','auto');
	var mySlide = new Fx.Slide('login').hide(); 

    $('toggleLogin').addEvent('click', function(e){
		e = new Event(e);
window.scrollTo(0,0);
		//document.getElementById('reminder').style.display="none"; 
		mySlide.toggle();
		e.stop();
	});
    $('toggleLogin2').addEvent('click', function(e){
		e = new Event(e);

		//document.getElementById('reminder').style.display="none"; 
		mySlide.toggle();
		e.stop();
	});

    $('closeLogin').addEvent('click', function(e){
		e = new Event(e);
		mySlide.slideOut();
		e.stop();
	});

	

$('loginform').addEvent('submit', function(e) {
		e.stop();
		var log = $('loginmessage'); //.empty().addClass('ajax-loading'); // UTILE

		$('loginform').set('send', {onComplete: function(response) { 
			log.removeClass('ajax-loading');

				if(response=='COK') {
						var getUsername = new Request({
						method: 'get',
						url: 'ajax/login/getUsername.php',
						onComplete: function(usernameSessionValue) { 
							$('contentdivlogin').set('html','Bienvenue '+usernameSessionValue+' - <a href="deconnexion.html">Déconnexion</a>');
							var ancienHash = window.location.hash;
							unFocus.History.addHistory("#connexion");
							unFocus.History.addHistory(ancienHash);
						}
					}).send();
					mySlide.slideOut();
				//$('contentdivlogin').set('html','');
				//document.location.href="mon-compte.html";
				} 
				else if(response=='ROK') {

						var getUsername = new Request({
						method: 'get',
						url: 'ajax/login/getUsername.php',
						onComplete: function(usernameSessionValue) { 
							$('contentdivlogin').set('html','Bienvenue '+usernameSessionValue+' - <a href="deconnexion.html">Déconnexion</a>');
							var ancienHash = window.location.hash;
							unFocus.History.addHistory("#connexion");
							unFocus.History.addHistory(ancienHash);
						}
					}).send();
					mySlide.slideOut();
				//document.location.href="recherche-rapide-offres-de-travail.html";
				} 
				else {
				$('reminder').setStyle('display','');
				$('loginform_text1').set('tween', {duration: 500}); 
					$('loginform_text1').highlight('#ff0000','#1E1E1E')
				$('loginform_text2').set('tween', {duration: 500}); 
					$('loginform_text2').highlight('#ff0000','#1E1E1E')
				}

		}});

		$('loginform').send();
	});


});

