$(document).ready(function() {
		
	$("form").ajaxStart(function(){
		$(".loading").fadeIn("fast");
		$(".output").html("<img src='/images/loading.gif' />Processing...");

	});
	
	$("form").ajaxStop(function(){
		$(".loading").fadeOut("fast");
	});
						   
						   
    $('.loginLink').click(function() { 
        $.blockUI({ message: $('#loginPanel') }); 
    });
	
	
	$('.forgotPass').click(function() { 
		$.unblockUI();								
        $.blockUI({ message: $('#passPanel') }); 
    });
	
	$('.registerLink').click(function() { 
		$.unblockUI();								
        $.blockUI({ message: $('#registerPanel') }); 
    });
	
	$('.sendLink').click(function() { 
		$.unblockUI();								
        $.blockUI({ message: $('#sendPanel') }); 
    });
	
	$('.close').click(function(){
		$.unblockUI();
		//setTimeout('window.location.reload()',500);
	});

	var optionsLogin = { 
        target:	'.output',   // target element(s) to be updated with server response 
       	url:  	'/ajax/connexion/check_connexion.php',       // override for form's 'action' attribute 
        type:   'post',        // 'get' or 'post', override for form's 'method' attribute 
		success: showResponse
    };
	
	var optionsPass = { 
        target:	'.output',   // target element(s) to be updated with server response 
       	url:  	'/ajax/connexion/check_connexion.php',       // override for form's 'action' attribute 
        type:   'post',        // 'get' or 'post', override for form's 'method' attribute 
		success: showResponse
    };
	
	var optionsRegister = { 
        target:	'.output',   // target element(s) to be updated with server response 
       	url:  	'/ajax/registration/registration.php',       // override for form's 'action' attribute 
        type:   'post',        // 'get' or 'post', override for form's 'method' attribute 
		success: showResponse
    };
	
	var optionsSend = { 
        target:	'.output',   // target element(s) to be updated with server response 
       	url:  	'/ajax/send_friend/send_friend.php',       // override for form's 'action' attribute 
        type:   'post',        // 'get' or 'post', override for form's 'method' attribute 
		success: showResponse
    };
	
    // bind form using 'ajaxForm' 
    $('#loginForm').ajaxForm(optionsLogin);
	$('#passForm').ajaxForm(optionsPass);
	$('#registerForm').ajaxForm(optionsRegister);
	$('#sendFriend').ajaxForm(optionsSend);
}); 

function showResponse(responseText, statusText)  {
	if(responseText == 'logged')
	{
		$.blockUI({ message: '<div class="no_error">You are logged</div>'});
		setTimeout($.unblockUI, 2000); 
		 //<a href="/customer/download_trial.php"><strong>Request a trial</strong></a>'
		 //"<a href='/customer/' class='customer'>Your account</a> <a href='/planningforce/logout.php' class='customer'>Logout</a>"
		$("#top_menu").html("<a href='/customer/' class='customer'>Your account</a> <a href='/planningforce/logout.php' class='customer'>Logout</a> <a href='/customer/download_trial.php'><strong>Request a trial</strong></a>");
		$("#sd").hide();
		return true;
		//setTimeout('window.location.reload()',2000);	
	}
	if(responseText == 'registered')
	{
		$.blockUI({ message: '<div class="no_error">You are registered</div>'});
		setTimeout($.unblockUI, 2000); 
		setTimeout('window.location.reload()',3000);	
	}
}