// Ajax
var Loading = '<br /><div align="center"><img src="' + ROOT_DIR +'/gfx/icons/loader_1.gif" width="32" height="32" alt="A carregar" /><br /><br />A carregar informa&ccedil;&atilde;o, por favor aguarde uns momentos</div>';

var erro = '<div align="center"><img src="' + ROOT_DIR +'/gfx/icons/icon_aviso_azul.png" width="32" height="32" alt="Erro" /><br /><br />Ocurreu um erro enquanto tentavamos mostrar a informa&ccedil;&atilde;o.<br /><br />Por favor tente novamente mais tarde</div>';

function Carrega_Gmail(acao) {
    var Login = $('#login_email .meio #username_email').val();
    var Password = $('#login_email .meio #pw_email').val();
    $(function () {
        $.ajax({
            type: "POST",
            data: ({
                email: Login,
                pw: Password,
                ACC: acao
            }),
            url: ROOT_DIR + "/ajax/GMail.php",
            success: function (rsp) {
                if (rsp == "__ERRO1") {
                    $('#login_email .meio #check').html('<div align="center"><div align="center"><img src="' + ROOT_DIR + '/gfx/icons/icon_err.gif" alt="Erro" /><br />Têm de preencher todos os campos</div>');
                } else if (rsp == "__ERRO2") {
                    $('#login_email .meio #check').html('<div align="center"><div align="center"><img src="' + ROOT_DIR + '/gfx/icons/icon_err.gif" alt="Erro" /><br />Os dados inseridos estão incorrectos</div>');
                } else {
                    $('#login_email .meio').html(rsp);
                }
            },
            error: function (xhr, ajaxOptions, thrownError) {
                $('#login_email .meio').html(erro);
            }
        });

    });
}
function LogoutGMail() {
   $(function () {
        $.ajax({
            type: "POST",
            data: ({
                ACC: "Logout"
            }),
			success: function (rsp){
				location.reload(true);
			},
            url: ROOT_DIR + "/ajax/GMail.php",
            error: function (xhr, ajaxOptions, thrownError) {
                $('#login_email .meio').html(erro);
            }
        });

    });
}
function Login_GMail(acao) {
    if (acao == 2) {
        Carrega_Gmail(acao);
    } else {
        $('#GMail').click(function () {

            $('#login_email .meio #check').html('<div align="center"><img src="' + ROOT_DIR + '/gfx/icons/loader.gif" alt="A carregar..." />A verificar dados...</div>')
            Carrega_Gmail(0);
        });
    }
}

function Carregar_Tempo() {
    $('#Tempo #Tempo_Dados_Localidade').html(Loading);
    $(function () {
        $.ajax({
            type: "GET",
            url: ROOT_DIR + "/ajax/ajax_tempo.php",
            success: function (response) {
                $('#Tempo #Tempo_Dados_Localidade').html(response);
            },
            error: function (xhr, ajaxOptions, thrownError) {
                $('#Tempo #Tempo_Dados_Localidade').html(erro);
            }
        });

    });
}

function Ultimas_Blogs() {
    $("#ultimas_xoose_blogs_conteudo").html(Loading);
	
    $(function () {
        $.ajax({
            type: "POST",
            url: ROOT_DIR + "/ajax/geral_ajax.php",
            data: "_tarefa=RSS_Xoose_Blogs",
            success: function (response) {
                $('#ultimas_xoose_blogs_conteudo').html(response);
            },
            error: function (xhr, ajaxOptions, thrownError) {
                $('#ultimas_xoose_blogs_conteudo').html(erro);
            }

        });

    });
}

function Carrega_Bolsa() {
    $("#conteudo_bolsa").html(Loading);
    $(function () {
        $.ajax({
            type: "POST",
            url: ROOT_DIR + "/bolsa.php",
            success: function (response) {
                $('#conteudo_bolsa').html(response);
            },
            error: function (xhr, ajaxOptions, thrownError) {
                $('#conteudo_bolsa').html(erro);
            }

        });

    });

}

function Carrega_Tabs(ID) {
    $("#tabs #opcoes a").removeClass("selected");
    $('#tabs #opcoes #' + ID).addClass("selected")
    $("#tabs #conteudo").html(Loading);
    $(function () {
        $.ajax({
            type: "POST",
            url: ROOT_DIR + "/ajax/geral_ajax.php",
            data: "_tarefa=ler_rss&id=" + ID,
            success: function (response) {
                $('#tabs #conteudo').html(response);
            },
            error: function (xhr, ajaxOptions, thrownError) {
                $('#tabs #conteudo').html(erro);
            }

        });

    });
}

function aviso() {
    $("#loading").ajaxStart(function () {
        $(this).show();
    });
    $("#loading").ajaxStop(function () {
        $(this).hide();
    });
}