// AJAX
function getHTTPObject_ANT() // comentado, 
{
    var xmlhttp;
    if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
        try {
            xmlhttp = new XMLHttpRequest();
        } catch (e) {
            xmlhttp = false;
        }
    }

    return xmlhttp;
}


function getHTTPObject()
{
    var xmlhttp;
    try
    {
        xmlhttp = new XMLHttpRequest(); // XMLHttpRequest para browsers como: Firefox, Safari entre outros.
    }catch(ee){
        try
        {
            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); // Para o IE2 da MS
        }catch(e){
            try
            {
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); // Para o IE2 da MS
            }catch(E){
                xmlhttp = false;
            }
        }
    }
    return xmlhttp;
}
var http  = getHTTPObject(); // Criado objeto HTTP




// *******************************************************
// POPUP
// *******************************************************
IE2 = navigator.appName=="Microsoft Internet Explorer";
NS2 = navigator.appName=="Netscape";
bVer2 = parseInt(navigator.appVersion);

var newWin=null;

function Popup2(loc, name, width, height, resizable, scrollable, scrollbars, status) {
        var _params = "width="+width+",height="+height+",resizable="+resizable+",scrollable="+scrollable+",scrollbars="+scrollbars+",status="+status+"";

        if (bVer2 >= 4) {
                 _left = ( (screen.width-width) >>1 );
                 _top = ( (screen.height-height) >>1 );
        } else {
                 _left = ( (800-width) >>1 );
                 _top = ( (600-height) >>1 );
        }

        if (IE2)
                _params += ",top=" + _top + ",left=" + _left;
        else
                if (NS2)
                      _params += ",screenX=" + _left + ",screenY=" + _top;

        newWin = window.open(loc, name, _params);
        if ( newWin!=null && !(IE2 && bVer2<5) )
                newWin.focus(); // MSIE24 DOESN'T FOCUS WINDOWS
}

function _painel()
{
    janela = Popup2('_painel.php','Painel',800,600,0,0,0,0);
}


function _Carregando(valor) {
    if(valor == "on") {
        document.getElementById("salvar").value="Finalizando...";
        document.getElementById("salvar").disabled = true;
    } else {
        document.getElementById("salvar").value=" Finalizar ";
        document.getElementById("salvar").disabled = false;
    }
}


function _Carregando2(valor) {
    if(valor == "on") {
        document.getElementById("salvar").value="Alterando...";
        document.getElementById("salvar").disabled = true;
    } else {
        document.getElementById("salvar").value=" Alterar ";
        document.getElementById("salvar").disabled = false;
    }
}

// retorno da chamada
function AjaxDevolvePlano(http)
{
    if (http.readyState == 4) {
        if (http.status == 200) {
            results = http.responseText.split(";");
            if (http.responseText.length > 0) {
                
                if(results[0] == "[ok]") {
                    
                    alert('Cadastrado finalizado com sucesso!\n\nVerifque seu e-mail! :)!!!');
                    window.close();
                    window.close();
                    
                } else if(results[0] == "[erro]") {
                    
                    alert(results[1]);
                    
                    // removendo o carregando
                    setTimeout("_Carregando('off')", 550);
                }
            }
        }
    }
}

// chamada
function AjaxPlano()
{


    var nome                = document.getElementById("nome").value;
    var rg                  = document.getElementById("rg").value;
    var cpf                 = document.getElementById("cpf").value;
    var data_nascimento_dia = document.getElementById("data_nascimento_dia").value;
    var data_nascimento_mes = document.getElementById("data_nascimento_mes").value;
    var data_nascimento_ano = document.getElementById("data_nascimento_ano").value;
    var cep                 = document.getElementById("cep").value;
    var endereco            = document.getElementById("endereco").value;
    var numero              = document.getElementById("numero").value;
    var cidade              = document.getElementById("cidade").value;
    var uf                  = document.getElementById("uf").value;
    var msn                 = document.getElementById("msn").value;
    var email               = document.getElementById("email").value;
    var telefone            = document.getElementById("telefone").value;
    var celular             = document.getElementById("celular").value;
    //var login               = document.getElementById("login").value;
    var senha               = document.getElementById("senha").value;
   // var rcon                = document.getElementById("rcon").value;
   // var sistema             = document.getElementById("sistema").value;
    var banco               = document.getElementById("banco").value;
    var preco               = document.getElementById("preco").value;
    var indicacao               = document.getElementById("indicacao").value;
    var plano               = document.getElementById("plano").value;
   // var servidor            = document.getElementById("servidor").value;


    // validacao de campos
    if(nome                 == "") { document.getElementById("nome").focus();                 alert('Preencha o campo NOME!'); return false; }
    if(rg                   == "") { document.getElementById("rg").focus();                   alert('Preencha o campo RG!'); return false; }
    if(cpf                  == "") { document.getElementById("cpf").value;                    alert('Preencha o campo CPF!'); return false; }
    if(data_nascimento_dia  == "") { document.getElementById("data_nascimento_dia").focus();  alert('Preencha o campo DATA NASCIMENTO DIA!'); return false; }
    if(data_nascimento_mes  == "") { document.getElementById("data_nascimento_mes").focus();  alert('Preencha o campo DATA NASCIMENTO MES!'); return false; }
    if(data_nascimento_ano  == "") { document.getElementById("data_nascimento_ano").focus();  alert('Preencha o campo DATA NASCIMENTO ANO!'); return false; }
    if(cep                  == "") { document.getElementById("cep").focus();                  alert('Preencha o campo CEP!'); return false; }
    if(endereco             == "") { document.getElementById("endereco").focus();             alert('Preencha o campo ENDEREÇO!'); return false; }
    if(numero               == "") { document.getElementById("numero").focus();               alert('Preencha o campo NUMERO!'); return false; }
    if(cidade               == "") { document.getElementById("cidade").focus();               alert('Preencha o campo CIDADE!'); return false; }
    if(uf                   == "") { document.getElementById("uf").focus();                   alert('Preencha o campo UF!'); return false; }
    //if(msn                  == "") { document.getElementById("msn").focus();                  alert('Preencha o campo MSN!'); return false; }
    if(email                == "") { document.getElementById("email").focus();                alert('Preencha o campo EMAIL!'); return false; }
    if(telefone             == "") { document.getElementById("telefone").focus();             alert('Preencha o campo TELEFONE!'); return false; }
    //if(celular              == "") { document.getElementById("celular").focus();              alert('Preencha o campo CELULAR!'); return false; }
    //if(login                == "") { document.getElementById("login").focus();                alert('Preencha o campo LOGIN!'); return false; }
    if(senha                == "") { document.getElementById("senha").focus();                alert('Preencha o campo SENHA!'); return false; }
   // if(rcon                 == "") { document.getElementById("rcon").focus();                 alert('Preencha o campo RCON!'); return false; }
   // if(sistema              == "") { document.getElementById("sistema").focus();              alert('Preencha o campo SISTEMA!'); return false; }
    if(banco                == "") { document.getElementById("banco").focus();                alert('Preencha o campo BANCO!'); return false; }
    //if(servidor             == "") { document.getElementById("servidor").focus();               alert('Preencha o campo SERVIDOR!'); return false; }

    if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email))) 
    {
        alert("O E-mail digitado é inválido!!!\nVerifique se foi digitado o arroba @.");
        return false
    }

    var data_nascimento = data_nascimento_ano + "-" + data_nascimento_mes + "-" + data_nascimento_dia;

    _Carregando('on');

    http.open("GET", "_plano_finaliza.php?nome="+nome+"&rg="+rg+"&cpf="+cpf+"&data_nascimento="+data_nascimento+"&cep="+cep+"&endereco="+endereco+"&numero="+numero+"&cidade="+cidade+"&uf="+uf+"&msn="+msn+"&email="+email+"&telefone="+telefone+"&celular="+celular+"&senha="+senha+"&banco="+banco+"&plano="+plano+"&indicacao="+indicacao+"&preco="+preco, true);
//    window.open("_plano_finaliza.php?nome="+nome+"&rg="+rg+"&cpf="+cpf+"&data_nascimento="+data_nascimento+"&cep="+cep+"&endereco="+endereco+"&numero="+numero+"&cidade="+cidade+"&uf="+uf+"&msn="+msn+"&email="+email+"&telefone="+telefone+"&celular="+celular+"&senha="+senha+"&banco="+banco+"&plano="+plano);
    http.onreadystatechange = function () { AjaxDevolvePlano(http) ; } ;
    http.send(null);
}


// retorno da chamada
function AjaxDevolveAlteraDados(http)
{
    if (http.readyState == 4) {
        if (http.status == 200) {
            results = http.responseText.split(";");
            if (http.responseText.length > 0) {
                
                if(results[0] == "[ok]") {
                    
                    alert('Dados alterado com sucesso!!!');
                    _Carregando2('off');
                    sp2.showPanel('menu_p1'); 
                    
                } else if(results[0] == "[erro]") {
                    
                    alert(results[1]);
                    
                    // removendo o carregando
                    setTimeout("_Carregando2('off')", 550);
                }
            }
        }
    }
}

// chamada
function AjaxAlteraDados()
{
    var cep                 = document.getElementById("cep").value;
    var endereco            = document.getElementById("endereco").value;
    var numero              = document.getElementById("numero").value;
    var cidade              = document.getElementById("cidade").value;
    var uf                  = document.getElementById("uf").value;
    var msn                 = document.getElementById("msn").value;
    var email               = document.getElementById("email").value;
    var telefone            = document.getElementById("telefone").value;
    var celular             = document.getElementById("celular").value;
    var senha               = document.getElementById("senha").value; document.getElementById("senha").value = "";
    var banco               = document.getElementById("banco").value;


    // validacao de campos
    if(cep                  == "") { document.getElementById("cep").focus();                  alert('Preencha o campo CEP!'); return false; }
    if(endereco             == "") { document.getElementById("endereco").focus();             alert('Preencha o campo ENDEREÇO!'); return false; }
    if(numero               == "") { document.getElementById("numero").focus();               alert('Preencha o campo NUMERO!'); return false; }
    if(cidade               == "") { document.getElementById("cidade").focus();               alert('Preencha o campo CIDADE!'); return false; }
    if(uf                   == "") { document.getElementById("uf").focus();                   alert('Preencha o campo UF!'); return false; }
    if(email                == "") { document.getElementById("email").focus();                alert('Preencha o campo EMAIL!'); return false; }
    if(telefone             == "") { document.getElementById("telefone").focus();             alert('Preencha o campo TELEFONE!'); return false; }
    if(banco                == "") { document.getElementById("banco").focus();                alert('Preencha o campo BANCO!'); return false; }

    if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email))) 
    {
        alert("O E-mail digitado é inválido!!!\nVerifique se foi digitado o arroba @.");
        return false
    }

    _Carregando2('on');

    http.open("GET", "_painel_altera.php?cep="+cep+"&endereco="+endereco+"&numero="+numero+"&cidade="+cidade+"&uf="+uf+"&msn="+msn+"&email="+email+"&telefone="+telefone+"&celular="+celular+"&senha="+senha+"&banco="+banco, true);
   // window.open("_painel_altera.php?cep="+cep+"&endereco="+endereco+"&numero="+numero+"&cidade="+cidade+"&uf="+uf+"&msn="+msn+"&email="+email+"&telefone="+telefone+"&celular="+celular+"&senha="+senha+"&banco="+banco);
    http.onreadystatechange = function () { AjaxDevolveAlteraDados(http) ; } ;
    http.send(null);
}


// retorno da chamada
function AjaxDevolveLogin(http)
{
    if (http.readyState == 4) {
        if (http.status == 200) {
            results = http.responseText.split(";");
            if (http.responseText.length > 0) {
                
                if(results[0] == "[ok]") {
                    
                    document.getElementById("mxLogin").innerHTML = "Logado: "+results[1]+"&nbsp;&nbsp;[ <a href='#' onclick='javascript:_painel2();'> Abrir Painel</a> ]&nbsp;&nbsp;[ <a href='_sair2.php'> Sair</a> ]";
                    _painel();
                    
                } else if(results[0] == "[erro]") {
                    document.getElementById("email").value="";
                    document.getElementById("senha").value="";
                    alert(results[1]);
                }
            }
        }
    }
}

// chamada
function AjaxLogin()
{
    var email   = document.getElementById("email").value;
    var senha   = document.getElementById("senha").value;

    // validacao de campos
    if(email == "") { document.getElementById("email").focus(); alert('Preencha o campo EMAIL!'); return false; }
    if(senha == "") { document.getElementById("senha").focus(); alert('Preencha o campo SENHA!'); return false; }

    if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email))) 
    {
        alert("O E-mail digitado é inválido!!!\nVerifique se foi digitado o arroba @.");
        return false
    }
    http.open("GET", "_painel.php?email="+email+"&senha="+senha, true);
    //window.open("_painel.php?email="+email+"&senha="+senha);
    http.onreadystatechange = function () { AjaxDevolveLogin(http) ; } ;
    http.send(null);
}


// retorno da chamada
function AjaxDevolveContato(http)
{
    if (http.readyState == 4) {
        if (http.status == 200) {
            results = http.responseText.split(";");
            if (http.responseText.length > 0) {
                
                if(results[0] == "[ok]") {
                    
                    document.getElementById("contato_nome").value ="";
                    document.getElementById("contato_email").value ="";
                    document.getElementById("contato_assunto").value ="";
                    document.getElementById("contato_mensagem").value ="";

                    alert('Formulário enviado com sucesso!');
                    
                } else if(results[0] == "[erro]") {
                    alert(results[1]);
                }
            }
        }
    }
}

// chamada
function AjaxContato()
{
    var contato_nome        = document.getElementById("contato_nome").value;    
    var contato_email       = document.getElementById("contato_email").value;   
    var contato_assunto     = document.getElementById("contato_assunto").value; 
    var contato_mensagem    = document.getElementById("contato_mensagem").value;

    // validacao de campos
    if(contato_nome     == "") { document.getElementById("contato_nome").focus(); alert('Preencha o campo NOME!'); return false; }
    if(contato_email    == "") { document.getElementById("contato_email").focus(); alert('Preencha o campo EMAIL!'); return false; }
    if(contato_assunto  == "") { document.getElementById("contato_assunto").focus(); alert('Preencha o campo ASSUNTO!'); return false; }
    if(contato_mensagem == "") { document.getElementById("contato_mensagem").focus(); alert('Preencha o campo MENSAGEM!'); return false; }


    if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(contato_email))) 
    {
        alert("O E-mail digitado é inválido!!!\nVerifique se foi digitado o arroba @.");
        return false
    }
    http.open("GET", "_contato.php?contato_nome="+contato_nome+"&contato_email="+contato_email+"&contato_assunto="+contato_assunto+"&contato_mensagem="+contato_mensagem, true);
    //window.open("_contato.php?contato_nome="+contato_nome+"&contato_email="+contato_email+"&contato_assunto="+contato_assunto+"&contato_mensagem="+contato_mensagem);
    http.onreadystatechange = function () { AjaxDevolveContato(http) ; } ;
    http.send(null);
}
