var Img = new Image();
Img.src = "imagens/ajax-load.gif";

var xmlhttp;
var container;
var mensagem;

function CarregarPagina(DIV, URL)
{
    container = DIV;

    xmlhttp = null;
    window.scrollTo(0, 0);
    document.getElementById(DIV).innerHTML = "<center><br /><br /><br /><br /><img src=\"imagens/ajax-load.gif\" /><br /><br /><span class=\"subtitulo\">Por favor, aguarde...</span><br />O conteúdo está sendo carregado.</center>";

    if (window.XMLHttpRequest)
        xmlhttp = new XMLHttpRequest();

    else if (window.ActiveXObject)
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

    if (xmlhttp != null)
    {		
        xmlhttp.onreadystatechange = Pagina;		
        xmlhttp.open("GET", URL, true);		
        xmlhttp.send(null);
    }
    else
        alert("Seu navegador não suporta Ajax.");
}

function Pagina()
{
    if (xmlhttp.readyState == 4)
    {
        if (xmlhttp.status == 200)
        {
            document.getElementById(container).innerHTML = xmlhttp.responseText;
            ExecutarScripts(document.getElementById(container));
        }
        else
            document.getElementById(container).innerHTML = "<span class=\"subtitulo\">ERRO NO SERVIDOR</span><br /><br /> Ocorreu um erro ao tentar receber os dados do servidor. <br />Contate o administrador do site para alertá-lo de que esta página não existe ou há um erro em seu conteúdo.<br /><b>Erro: </b>" + xmlhttp.status;
    }
}

function CarregarConteudo(URL, DefaultMessage)
{
    xmlhttp = null;
    mensagem = DefaultMessage;

    if (window.XMLHttpRequest)
        xmlhttp = new XMLHttpRequest();
    else if (window.ActiveXObject)
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

    if (xmlhttp != null)
    {
        xmlhttp.onreadystatechange = Conteudo;
        //xmlhttp.open("GET", URL, true);
        xmlhttp.send(null);
    }
    else
        alert("Seu navegador não suporta Ajax.");
}

function Conteudo()
{
    if (xmlhttp.readyState == 4)
    {
        if (xmlhttp.status == 200)
        {
            var msg = xmlhttp.responseText;

            if (msg != "")
            {
                alert(msg);
            }
            else
            {
                alert(mensagem);
                CarregarPagina("inicial.php");
            }
        }
        else
            alert("Erro: " + xmlhttp.status);
    }
}

function CarregarImagem(div, imagem, source)
{
    document.getElementById(div).innerHTML = "<img src=\"" + source + "\" />";
}

function ExecutarScripts(e)
{
    if (e.nodeType != 1)
        return;

    if (e.tagName.toLowerCase() == 'script')
    {
        eval(e.text);
    }
    else
    {
        var n = e.firstChild;
        while (n)
        {
            if (n.nodeType == 1)
                ExecutarScripts(n);
            n = n.nextSibling;
        }
    }
}



