	$(document).ready(function() {
	    $("#login_form").submit(function() {
	    	//remove all the class add the messagebox classes and start fading
	    	$("#msgbox").removeClass().addClass('messagebox').text('Validando...').fadeIn(1000);
	    	//check the username exists or not from ajax
	    	$.post("login.php?action=login",{ email:$('#email').val(), senha:$('#senha').val(), rand:Math.random() } , function(data) {
	    		if (data == '1') {
	    			$("#msgbox").fadeTo(200,0.1,function() {
	    				$(this).html('Redirecionando').addClass('messageboxok').fadeTo(900,1, function() {
	    					document.location = $('#path_www').text() + '/restrito/home.php';
	    				});
	    			});
	    		} else if (data == '2') {
	    			$("#msgbox").fadeTo(200,0.1,function() {
	    				$(this).html('Usuário bloqueado! Consulte o suporte.').addClass('messageboxerror').fadeTo(900,1);
	    			});
	    		} else if (data == '3') {
	    			$("#msgbox").fadeTo(200,0.1,function() {
	    				$(this).html('Sistema em manutenção. Tente mais tarde!').addClass('messageboxerror').fadeTo(900,1);
	    			});
	    		} else {
	    			$("#msgbox").fadeTo(200,0.1,function() {
	    				$(this).html('E-mail e/ou senha inválidos!').addClass('messageboxerror').fadeTo(900,1);
	    			});
	    		}
	    	});
	    	return false;
	    });
	    
	    $("#newaccount_form").submit(function() {
	    	//remove all the class add the messagebox classes and start fading
	    	$("#msgbox-newaccount").removeClass().addClass('messagebox').text('Validando...').fadeIn(1000);
	    	//check the username exists or not from ajax
	    	$.post($('#path_www').text() + "/cadastro.php?action=new_account",{ 
	    			chave:$('#new_chave').val(), email:$('#new_email').val(), senha:$('#new_senha').val(), nome:$('#new_nome').val(),
	    			fone:$('#new_fone').val(), emit_CNPJ:$('#new_emit_CNPJ').val(), dest_CNPJ:$('#new_dest_CNPJ').val(),
	    			rand:Math.random() } , function(data) {
	    		if (data == '1') {
	    			$('#newaccount_form').slideUp('slow');
	    			$('#bloco-aviso').html('Cadastro concluído, aguarde a aprovação. Redirecionando...').fadeTo(1100,1, function() {
    					document.location = $('#path_www').text() + '/restrito/home.php';
    				});
	    		} else {
	    			$("#msgbox-newaccount").fadeTo(200,0.1,function() {
	    				$(this).html(data).addClass('messageboxerror').fadeTo(900,1);
	    			});
	    		}
	    	});
	    	return false;
	    });
	    
	    $("#recuperarSenhaForm").submit(function() {
	    	//remove all the class add the messagebox classes and start fading
	    	$("#msgboxsenha").removeClass().addClass('messagebox').text('Validando...').fadeIn(1000);
	    	//check the username exists or not from ajax
	    	$.post($('#path_www').text() + "/cadastro.php?action=recuperarSenha",{ 
	    			email:$('#recSenhaEmail').val(), rand:Math.random() } , function(data) {
	    		if (data == '1') {
	    			//$('#newaccount_form').slideUp('slow');
	    			//$('#msgboxsenha').html('Verifique sua caixa postal.').fadeTo(30000,1, function() {
	    			$('#btn-senha').hide();
	    			$('#msgboxsenha').html('Senha enviada para seu e-mail.').fadeTo(30000,1, function() {
	    				$("#recuperarSenha").hide();
	    				$("#fazerLogin").show();
	    				$('#msgboxsenha').html('');
    				});
	    		} else {
	    			$("#msgboxsenha").fadeTo(200,0.1,function() {
	    				$(this).html(data).addClass('messageboxerror').fadeTo(900,1);
	    			});
	    		}
	    	});
	    	return false;
	    });
	});
	
