var req;

function loadXMLDocPagina(url, pagina, cod)
{
    req = null;
    // Procura por um objeto nativo (Mozilla/Safari)
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChangePagina;
        req.open("GET", url+'?pagina='+pagina+'&cod='+cod, true);
        req.send(null);
    // Procura por uma versao ActiveX (IE)
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqChangePagina;
            req.open("GET", url+'?pagina='+pagina+'&cod='+cod, true);
            req.send();
        }
    }
}

function processReqChangePagina()
{
    // apenas quando o estado for "completado"
    if (req.readyState == 4) {
        // apenas se o servidor retornar "OK"
        if (req.status == 200) {
            // procura pela div id="atualiza" e insere o conteudo
            // retornado nela, como texto HTML
            document.getElementById('idPrincipal').innerHTML = req.responseText;
        } else {
            alert("Houve um problema ao obter os dados:\n" + req.statusText);
        }
    }
}

function Pagina(pagina, cod)
{
    loadXMLDocPagina('atualizapagina.php', pagina, cod);
}

function loadXMLDocPeloMundo(url, inic, pag)
{
    req = null;
    // Procura por um objeto nativo (Mozilla/Safari)
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChangePagina;
        req.open("GET", url+'?pagina=pelomundo&inic='+inic+'&pag='+pag, true);
        req.send(null);
    // Procura por uma versao ActiveX (IE)
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqChangePagina;
            req.open("GET", url+'?pagina=pelomundo&inic='+inic+'&pag='+pag, true);
            req.send();
        }
    }
}

function PeloMundo(inic, pag)
{
    loadXMLDocPeloMundo('atualizapagina.php', inic, pag);
}

function loadXMLDocFoto(url, dir, foto)
{
    req = null;
    // Procura por um objeto nativo (Mozilla/Safari)
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChangePagina;
        req.open("GET", url+'?pagina=fotopelomundo&dir='+dir+'&foto='+foto, true);
        req.send(null);
    // Procura por uma versao ActiveX (IE)
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqChangePagina;
            req.open("GET", url+'?pagina=foto&dir='+dir+'&foto='+foto, true);
            req.send();
        }
    }
}

function Foto(dir, foto)
{
    loadXMLDocFoto('atualizapagina.php', dir, foto);
}

function loadXMLDocEmail(url, pNome, pEmail, pAssunto, pMensagem, pCidade)
{
    req = null;
    // Procura por um objeto nativo (Mozilla/Safari)
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChangePagina;
        req.open("GET", url+'?nome='+pNome+'&email='+pEmail+'&assunto='+pAssunto+'&mensagem='+pMensagem+'&cidade='+pCidade, true);
        req.send(null);
    // Procura por uma versao ActiveX (IE)
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqChangePagina;
            req.open("GET", url+'?nome='+pNome+'&email='+pEmail+'&assunto='+pAssunto+'&mensagem='+pMensagem+'&cidade='+pCidade, true);
            req.send();
        }
    }
}

function Envia_Email(pNome, pEmail, pAssunto, pMensagem, pCidade)
{
    loadXMLDocEmail('atualiza_email.php', pNome, pEmail, pAssunto, pMensagem, pCidade);
}

function loadXMLDocEmp(url, pTipo)
{
    req = null;
    // Procura por um objeto nativo (Mozilla/Safari)
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChangeEmp;
        req.open("GET", url+'?&tipo='+pTipo, true);
        req.send(null);
    // Procura por uma versao ActiveX (IE)
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqChangeEmp;
            req.open("GET", url+'?&tipo='+pTipo, true);
            req.send();
        }
    }
}

function processReqChangeEmp()
{
    // apenas quando o estado for "completado"
    if (req.readyState == 4) {
        // apenas se o servidor retornar "OK"
        if (req.status == 200) {
            // procura pela div id="atualiza" e insere o conteudo
            // retornado nela, como texto HTML
            document.getElementById('idHistorico').innerHTML = req.responseText;
        } else {
            alert("Houve um problema ao obter os dados:\n" + req.statusText);
        }
    }
}

function Dados_Empresa(pTipo)
{
    loadXMLDocEmp('atualiza_empresa.php', pTipo);
}

function MudaFoto(gFoto, gLegenda) {
  document.myPicture.src= 'galeria/' + gFoto;
  document.getElementById('idLegenda').innerHTML = "&nbsp;&nbsp;&nbsp;&nbsp;"+gLegenda;
}


