$(document).ready(function() {
	var al_success = 1;
	var al_failure = 0;

	$('.auth').submit(function() {
		msg = $(this).find('#message');
		id = $(this).attr('id');
		$(this).ajaxSubmit({
			success: 	function showResponse(responseText, statusText){
							msg.html('');
							responselines = responseText.split("\n");
							for(i = 1; i < responselines.length - 1; i++){
								msg.append(responselines[i] + "<br />").fadeIn('slow');
							}
							if (responselines[0] == al_success) {
								msg.removeClass('error');
								msg.addClass('success');
								
								if (id == 'loginForm') {
									param = $(document).getUrlParam('redirect_to');
									setTimeout(function(){
										window.location = (param == null ? 'javascript:window.location.reload()' : param);
									}, 3000)
								} else {
									//$('input[type=submit]', this).attr('disabled', 'disabled');
									//$('select', this).attr('disabled', 'disabled');
									//$('input[type=text]', this).attr('readonly', 'readonly');
									//$('textarea', this).attr('readonly', 'readonly');
								
									setTimeout(function(){
										$tabs = $('#authenticate').tabs();
										$tabs.tabs('select', 'authlogin');
									}, 3000)
								}
							}
							return false;
						},
			error: 		function (XMLHttpRequest, textStatus, errorThrown) {
							msg.html('An error occured!').fadeIn('slow');
							return false; 
						},
			resetForm: 	false,
			timeout:   	3000
		});
		
		return false; 
	});
	
	$("#registerForm").formwizard(
		{
			historyEnabled : false, 
			formPluginEnabled: false, 
			validationEnabled : true,
			back: '#back',
			next: '#next'
		}, {
			//validation settings
		}, {
			// form plugin settings
		}
	);
});
