function $(obj){
  return document.getElementById(obj);
}

function validaNome(strNome) {
  strNome = strNome.value;
  var blnNomeValido = true;
  var space = String.fromCharCode(32);
  var arrCaracteresInvalidos = new Array('"', '!', '@', '#', '$', '%', 'Â¨', '&', '*', '(', ')', '_', '-', '+', '=', 'Â§', 'Â´', '`', '{', 'Âª', '[', '~','^', '|', '\\', '<', ',', '>', '.', ':', ';', '?', '/', 'Â°', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0','  ',';');
  if ((strNome != '') && (strNome.length > 3)) {
   blnNomeValido = true;
   for (x = 0; x < arrCaracteresInvalidos.length; x++ ) {
    for (y = 0; y < strNome.length; y++) {
     if (strNome.charAt(y) == arrCaracteresInvalidos[x]) {
      blnNomeValido = false;
     }
    }
  }
  for (z = 0; z < strNome.length; z++) {
    if (z != strNome.length) {
     if ((strNome.charAt(z - 1) == space) && (strNome.charAt(z + 1) == space)) {
      blnNomeValido = false;
     }
    }
  }
   if (strNome.charAt(strNome.length - 2) == space) {
    blnNomeValido = false;
   }
  } else {
   blnNomeValido = false;
  }
  return blnNomeValido;
}

function ajax(){

        try{
                xmlhttp = new XMLHttpRequest();
        }

        catch (ee){

            try{
                        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
            }

            catch (e){

                        try{
                                xmlhttp = new ActiveXObject("Msxml.XMLHTTP");
                        }

                        catch (E){
                            xmlhttp = false;
                        }

        }

        }

        return xmlhttp;

}
/*
function enviaEmail () {

        var contatoNome     = document.getElementById("contatoNome").value;
        var contatoCidade   = document.getElementById("contatoCidade").value;
        var contatoPais     = document.getElementById("contatoPais").value;
        var contatoDDI      = document.getElementById("contatoDDI").value;
        var contatoDDD      = document.getElementById("contatoDDD").value;
        var contatoNumero   = document.getElementById("contatoNumero").value;
        var contatoEmail    = document.getElementById("contatoEmail").value;
        var contatoMensagem = document.getElementById("contatoMensagem").value;
        var strQuery        = "contatoNome="+contatoNome+"&contatoCidade="+contatoCidade+"&contatoPais="+contatoPais+"&contatoDDI="+contatoDDI+"&contatoDDD="+contatoDDD+"&contatoNumero="+contatoNumero+"&contatoEmail="+contatoEmail+"&contatoMensagem="+contatoMensagem;
        var strURL          = "ajax.php";

        xmlhttp.open("POST", strURL, true);

        xmlhttp.onreadystatechange=function() {
                if ( xmlhttp.readyState==4 ){
                        alertar('Contato','Sua mensagem foi enviada com sucesso!','Ok,false');
                        limparForm("formContato");
                }
        }
        xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
        xmlhttp.send(strQuery);
}
*/

function atualizarCorrigirDados() {

        var dado_cadastral_cep              = document.getElementById("dado_cadastral_cep").value;
        var dado_cadastral_endereco         = document.getElementById("dado_cadastral_endereco").value;
        var dado_cadastral_bairro           = document.getElementById("dado_cadastral_bairro").value;
        var dado_cadastral_municipio        = document.getElementById("dado_cadastral_municipio").value;
        var dado_cadastral_estado           = document.getElementById("dado_cadastral_estado").value;
        var dado_cadastral_ddd_fone         = document.getElementById("dado_cadastral_ddd_fone").value;
        var dado_cadastral_telefone         = document.getElementById("dado_cadastral_telefone").value;
        var dado_cadastral_ddd_cel          = document.getElementById("dado_cadastral_ddd_cel").value;
        var dado_cadastral_celular          = document.getElementById("dado_cadastral_celular").value;
        var dado_cadastral_ddd_fone_contato = document.getElementById("dado_cadastral_ddd_fone_contato").value;
        var dado_cadastral_telefone_contato = document.getElementById("dado_cadastral_telefone_contato").value;
        var dado_cadastral_email            = document.getElementById("dado_cadastral_email").value;
        var dado_cadastral_banco            = document.getElementById("dado_cadastral_banco").value;
        var dado_cadastral_agencia          = document.getElementById("dado_cadastral_agencia").value;
        var dado_cadastral_conta_corrente   = document.getElementById("dado_cadastral_conta_corrente").value;


        var formName  = "formCBDadosCadastrais";
        var strQuery  = "dado_cadastral_cep="+dado_cadastral_cep+"&dado_cadastral_endereco="+dado_cadastral_endereco+"&dado_cadastral_bairro="+dado_cadastral_bairro+"&dado_cadastral_municipio="+dado_cadastral_municipio+"&dado_cadastral_estado="+dado_cadastral_estado+"&dado_cadastral_ddd_fone="+dado_cadastral_ddd_fone+"&dado_cadastral_telefone="+dado_cadastral_telefone+"&dado_cadastral_ddd_cel="+dado_cadastral_ddd_cel+"&dado_cadastral_celular="+dado_cadastral_celular+"&dado_cadastral_email="+dado_cadastral_email+"&dado_cadastral_banco="+dado_cadastral_banco+"&dado_cadastral_agencia="+dado_cadastral_agencia+"&dado_cadastral_conta_corrente="+dado_cadastral_conta_corrente+"&dado_cadastral_ddd_fone_contato="+dado_cadastral_ddd_fone_contato+"&dado_cadastral_telefone_contato="+dado_cadastral_telefone_contato+"&formName="+formName;
        var strURL    = "../../inc/ajax.php";

        xmlhttp.open("POST", strURL, true);

        xmlhttp.onreadystatechange = function() {
                if ( xmlhttp.readyState == 4 ) {
                        alertar('Atualização Cadastral',xmlhttp.responseText,'Ok,false');
                        limparForm("formCBDadosCadastrais");
                }
        };
        xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
        xmlhttp.send(strQuery);

}


function CCAtualizarCorrigir() {

        var atualizarCorrigirEmail      = document.getElementById("atualizarCorrigirEmail").value;
        var atualizarCorrigirCep        = document.getElementById("atualizarCorrigirCep").value;
        var atualizarCorrigirEndereco   = document.getElementById("atualizarCorrigirEndereco").value;
        var atualizarCorrigirBairro     = document.getElementById("atualizarCorrigirBairro").value;
        var atualizarCorrigirMunicipio  = document.getElementById("atualizarCorrigirMunicipio").value;
        var atualizarCorrigirEstado     = document.getElementById("atualizarCorrigirEstado").value;
        var atualizarCorrigirDDD1       = document.getElementById("atualizarCorrigirDDD1").value;
        var atualizarCorrigirTelefone   = document.getElementById("atualizarCorrigirTelefone").value;
        var atualizarCorrigirDDDFax     = document.getElementById("atualizarCorrigirDDDFax").value;
        var atualizarCorrigirFax        = document.getElementById("atualizarCorrigirFax").value;
        var atualizarCorrigirDDDCel     = document.getElementById("atualizarCorrigirDDDCel").value;
        var atualizarCorrigirCel        = document.getElementById("atualizarCorrigirCel").value;
        var atualizarCorrigirBanco      = document.getElementById("atualizarCorrigirBanco").value;
        var atualizarCorrigirAgencia    = document.getElementById("atualizarCorrigirAgencia").value;
        var atualizarCorrigirConta      = document.getElementById("atualizarCorrigirConta").value;

        var formName  = "formCCAtualizarCorrigir";
        var strQuery  = "atualizarCorrigirEmail="+atualizarCorrigirEmail+"&atualizarCorrigirCep="+atualizarCorrigirCep+"&atualizarCorrigirEndereco="+atualizarCorrigirEndereco+"&atualizarCorrigirBairro="+atualizarCorrigirBairro+"&atualizarCorrigirMunicipio="+atualizarCorrigirMunicipio+"&atualizarCorrigirEstado="+atualizarCorrigirEstado+"&atualizarCorrigirDDD1="+atualizarCorrigirDDD1+"&atualizarCorrigirTelefone="+atualizarCorrigirTelefone+"&atualizarCorrigirDDDFax="+atualizarCorrigirDDDFax+"&atualizarCorrigirFax="+atualizarCorrigirFax+"&atualizarCorrigirDDDCel="+atualizarCorrigirDDDCel+"&atualizarCorrigirCel="+atualizarCorrigirCel+"&atualizarCorrigirBanco="+atualizarCorrigirBanco+"&atualizarCorrigirAgencia="+atualizarCorrigirAgencia+"&atualizarCorrigirConta="+atualizarCorrigirConta+"&formName="+formName;
        var strURL    = "../../inc/ajax.php";

        xmlhttp.open("POST", strURL, true);

        xmlhttp.onreadystatechange = function() {
                if ( xmlhttp.readyState == 4 ) {
                        
                        alertar('Atualização Cadastral',xmlhttp.responseText,'Ok,false');
                        limparForm(formName);
                }
        };
        xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
        xmlhttp.send(strQuery);
}


function CBFaleConosco() {

        var nome      = document.getElementById("nome").value;
        var red       = document.getElementById("red").value;
        var municipio = document.getElementById("municipio").value;
        var email     = document.getElementById("email").value;
        var ddd       = document.getElementById("ddd").value;
        var telefone  = document.getElementById("telefone").value;
        var mensagem  = document.getElementById("mensagem").value;


        var formName  = "formCBFaleConosco";
        var strQuery  = "nome="+nome+"&red="+red+"&municipio="+municipio+"&email="+email+"&ddd="+ddd+"&telefone="+telefone+"&mensagem="+mensagem+"&formName="+formName;
        var strURL    = "../../inc/ajax.php";

        xmlhttp.open("POST", strURL, true);

        xmlhttp.onreadystatechange = function() {
                if ( xmlhttp.readyState == 4 ){
                        
                        alertar('Fale Conosco',xmlhttp.responseText,'Ok,false');
                        limparForm(formName);
                }
        };
        xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
        xmlhttp.send(strQuery);

}

function CCFaleConosco() {

        var convenio     = document.getElementById("convenio").value;
        var razao_social = document.getElementById("razao_social").value;
        var nome         = document.getElementById("nome").value;
        var cidade       = document.getElementById("cidade").value;
        var email        = document.getElementById("email").value;
        var ddd          = document.getElementById("ddd").value;
        var telefone     = document.getElementById("telefone").value;
        var mensagem     = document.getElementById("mensagem").value;

        var formName  = "formCCFaleConosco";
        var strQuery  = "convenio="+convenio+"&razao_social="+razao_social+"&nome="+nome+"&cidade="+cidade+"&email="+email+"&ddd="+ddd+"&telefone="+telefone+"&mensagem="+mensagem+"&formName="+formName;
        var strURL    = "../../inc/ajax.php";

        xmlhttp.open("POST", strURL, true);

        xmlhttp.onreadystatechange = function() {
                if ( xmlhttp.readyState == 4 ){
                        alertar('Fale Conosco',xmlhttp.responseText,'Ok,false');
                        limparForm(formName);
                }
        };
        xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
        xmlhttp.send(strQuery);

}


function mudarPlano() {
/*
        var empresa      = document.getElementById("empresa").value;
        var red          = document.getElementById("red").value;
        var seq          = document.getElementById("seq").value;
        var beneficiario = document.getElementById("beneficiario").value;
        var telefone     = document.getElementById("telefone").value;
        var email        = document.getElementById("email").value;*/
        var plano        = document.getElementById("plano").value;


        var formName  = "formMudarPlano";
//      var strQuery  = "empresa="+empresa+"&red="+red+"&seq="+seq+"&beneficiario="+beneficiario+"&telefone="+telefone+"&email="+email+"&plano="+plano+"&formName="+formName;
        var strQuery  = "plano="+plano+"&formName="+formName;
        var strURL    = "../../inc/ajax.php";

        xmlhttp.open("POST", strURL, true);

        xmlhttp.onreadystatechange=function() {
                if ( xmlhttp.readyState==4 ){
                        
                        alertar('Mudar Plano de Saúde',xmlhttp.responseText,'Ok,false');
                        limparForm(formName);
                }
        };
        xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
        xmlhttp.send(strQuery);

}


function incluirDependente() {
/*
        var empresa      = document.getElementById("empresa").value;
        var red          = document.getElementById("red").value;
        var seq          = document.getElementById("seq").value;
        var beneficiario = document.getElementById("beneficiario").value;
        var telefone     = document.getElementById("telefone").value;
        var email        = document.getElementById("email").value;
*/

        var formName  = "formIncluirDependente";
//      var strQuery  = "empresa="+empresa+"&red="+red+"&seq="+seq+"&beneficiario="+beneficiario+"&telefone="+telefone+"&email="+email+"&formName="+formName;
        var strQuery  = "formName="+formName;
        var strURL    = "../../inc/ajax.php";

        xmlhttp.open("POST", strURL, true);

        xmlhttp.onreadystatechange=function() {
                if ( xmlhttp.readyState==4 ){
                        
                        alertar('Inclusão de Dependente',xmlhttp.responseText,'Ok,false');
                        limparForm(formName);
                }
        };
        xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
        xmlhttp.send(strQuery);

}


function extravioCartao() {

        var formName          = "formExtravioCartao";
        var objForm           = document.getElementById(formName);        
        var strQuery          = "formName="+formName+"&";
        var strURL            = "../../inc/ajax.php";

        var seq               = objForm.seq;
        var red               = objForm.red;
        var extravio_atestado = document.getElementById("extravio_atestado");
        

        if ( seq.type == undefined ) {
                for ( i = 0; i < seq.length; i++ ) {
                        if ( seq[i].checked == true ) {
                                strQuery += seq[i].name+"="+seq[i].value+"&";
                                strQuery += red[i].name+"="+red[i].value+"&";
                        }
                }
        }
        else {
                if ( seq.checked == true ) {
                        strQuery += seq.name+"="+seq.value+"&";
                        strQuery += red.name+"="+red.value+"&";
                }
        }


        if ( extravio_atestado.checked == true ) {
                strQuery += extravio_atestado.name+"=S" ;
        } 
        else {
                strQuery += extravio_atestado.name+"=N" ;
        }


        xmlhttp.open("POST", strURL, true);

        xmlhttp.onreadystatechange=function() {
                if ( xmlhttp.readyState==4 ) {
                        
                        alertar('Extravio, perda ou roubo de cartão',xmlhttp.responseText,'Ok,false');
                        limparForm(formName);
                }
        };
        xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
        xmlhttp.send(strQuery);
}


function localidadesPS(plano_codigo) {

        document.getElementById("municipio_codigo").options.length     = 1;
        document.getElementById("especialidade_codigo").options.length = 1;

        var strQuery  = "plano_codigo="+plano_codigo;
        var strURL    = "../../xml/localidades.php";

        xmlhttp.open("POST", strURL, true);

        xmlhttp.onreadystatechange=function() {
                if ( xmlhttp.readyState == 1 ) {
                        document.getElementById("municipio_opcao").innerHTML = "Carregando...";
                }
                if ( xmlhttp.readyState == 4 ){

                        var objXml         = xmlhttp.responseXML;
                        var arrLocalidades = objXml.getElementsByTagName("localidade");

                        if ( arrLocalidades.length > 0 ) {

                                for ( i = 0 ; i < arrLocalidades.length ; i++ ) {

                                        var item   = arrLocalidades[i];
                                        var codigo = item.getElementsByTagName("codigo")[0].firstChild.nodeValue;
                                        var nome   = item.getElementsByTagName("nome")[0].firstChild.nodeValue;
                                        
                                        var novo   = document.createElement("option");
                                        novo.setAttribute("id", "opcoes");
                                        novo.value = codigo;
                                        novo.text  = nome;

                                        document.getElementById("municipio_codigo").options.add(novo);
                                }
                        }
                        document.getElementById("municipio_opcao").innerHTML = "Localidades";
                }
        };
        xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
        xmlhttp.send(strQuery);
}


function especialidadesPS(municipio_codigo, plano_codigo) {

        document.getElementById("especialidade_codigo").options.length = 1;

        var objForm = document.getElementById("formRedeConveniados");
        var planos  = objForm.pCodigo;

        if ( planos.length ) {  

                for ( i = 0; i < planos.length; i++ ) {
                        if ( planos[i].checked == true ) {
                                plano_codigo = planos[i].value;
                        }
                }
        }
        else {
        
                if ( planos.checked == true ) {
                        plano_codigo = planos.value;
                }
        }

        var strQuery = "municipio_codigo="+municipio_codigo+"&plano_codigo="+plano_codigo;
        var strURL   = "../../xml/especialidades.php";


        xmlhttp.open("POST", strURL, true);

        xmlhttp.onreadystatechange=function() {
                if ( xmlhttp.readyState == 1 ) {
                        document.getElementById("especialidade_opcao").innerHTML = "Carregando...";
                }
                if ( xmlhttp.readyState == 4 ) {

                        var objXml            = xmlhttp.responseXML;
                        var arrEspecialidades = objXml.getElementsByTagName("especialidade");
                        
                        if ( arrEspecialidades.length > 0 ) {

                                for ( i = 0 ; i < arrEspecialidades.length ; i++ ) {

                                        var item      = arrEspecialidades[i];
                                        var codigo    = item.getElementsByTagName("codigo")[0].firstChild.nodeValue;
                                        var descricao = item.getElementsByTagName("descricao")[0].firstChild.nodeValue;
                                        
                                        var novo      = document.createElement("option");
                                        novo.setAttribute("id", "opcoes");
                                        novo.value    = codigo;
                                        novo.text     = descricao;

                                        document.getElementById("especialidade_codigo").options.add(novo);
                                }
                                document.getElementById("especialidade_opcao").innerHTML = "Todas Especialidades";
                        }
                        else {
                                document.getElementById("especialidade_opcao").innerHTML = "Escolha outra localidade";
                        }
                }
        };
        xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
        xmlhttp.send(strQuery);
}


function CBCadastre() {

        var usuario_empresa = document.getElementById("usuario_empresa").value;
        var usuario_red     = document.getElementById("usuario_red").value;
        var usuario_seq     = document.getElementById("usuario_seq").value;
        var usuario_cpf     = document.getElementById("usuario_cpf").value;


        var formName  = "formCBCadastre";
        var strQuery  = "usuario_empresa="+usuario_empresa+"&usuario_red="+usuario_red+"&usuario_seq="+usuario_seq+"&usuario_cpf="+usuario_cpf+"&formName="+formName;
        var strURL    = "../../inc/ajax.php";

        xmlhttp.open("POST", strURL, true);

        xmlhttp.onreadystatechange = function() {
                if ( xmlhttp.readyState == 4 ) {
                        
                        alertar('Cadastre seu login',xmlhttp.responseText,'Ok,false');
                        limparForm(formName);
                }
        };
        xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
        xmlhttp.send(strQuery);

}


function CCCadastre() {

        var usuario_convenio = document.getElementById("usuario_convenio").value;
        var usuario_cgc      = document.getElementById("usuario_cgc").value;
        var usuario_senha_1  = document.getElementById("usuario_senha_1").value;
        var usuario_senha_2  = document.getElementById("usuario_senha_2").value;

        if ( usuario_senha_1.length < 6 || usuario_senha_1.length > 8 ) {
                alertar('Cadastre seu login','Senha deve ser de 6 a 8 digitos.','Ok,false');
        } else if ( usuario_senha_1 != usuario_senha_2 ) {
                alertar('Cadastre seu login','Senhas não conferem.','Ok,false');
        } else {
                var formName  = "formCCCadastre";
                var strQuery  = "usuario_convenio="+usuario_convenio+"&usuario_cgc="+usuario_cgc+"&usuario_senha="+usuario_senha_1+"&formName="+formName;
                var strURL    = "../../inc/ajax.php";

                xmlhttp.open("POST", strURL, true);

                xmlhttp.onreadystatechange = function() {
                        if ( xmlhttp.readyState == 4 ) {
                                
                                alertar('Cadastre seu login',xmlhttp.responseText,'Ok,false');
                                limparForm(formName);
                        }
                };
                xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
                xmlhttp.send(strQuery);
        }
}


function inclusaoExclusaoEndereco() {
        
        var inclusaoExclusaoRazaoSocial = document.getElementById("inclusaoExclusaoRazaoSocial").value;
        var inclusaoExclusaoEmail       = document.getElementById("inclusaoExclusaoEmail").value;
        var inclusaoExclusaoCep         = document.getElementById("inclusaoExclusaoCep").value;
        var inclusaoExclusaoEndereco    = document.getElementById("inclusaoExclusaoEndereco").value;
        var inclusaoExclusaoBairro      = document.getElementById("inclusaoExclusaoBairro").value;
        var inclusaoExclusaoMunicipio   = document.getElementById("inclusaoExclusaoMunicipio").value;
        var inclusaoExclusaoEstado      = document.getElementById("inclusaoExclusaoEstado").value;
        var inclusaoExclusaoDDD1        = document.getElementById("inclusaoExclusaoDDD1").value;
        var inclusaoExclusaoTelefone    = document.getElementById("inclusaoExclusaoTelefone").value;
        var inclusaoExclusaoDDDFax      = document.getElementById("inclusaoExclusaoDDDFax").value;
        var inclusaoExclusaoFax         = document.getElementById("inclusaoExclusaoFax").value;
        var inclusaoExclusaoBanco       = document.getElementById("inclusaoExclusaoBanco").value;
        var inclusaoExclusaoAgencia     = document.getElementById("inclusaoExclusaoAgencia").value;
        var inclusaoExclusaoConta       = document.getElementById("inclusaoExclusaoConta").value;
        var inclusaoExclusaoDiaHora     = document.getElementById("inclusaoExclusaoDiaHora").value;
        var inclusao                    = document.getElementById("inclusao");
        var exclusao                    = document.getElementById("exclusao");

        var inclusaoExclusao            = ( inclusao.checked == true ) ? inclusao.value : exclusao.value;
        
        
        var formName  = "inclusaoExclusaoEndereco";
        var strQuery  = "inclusaoExclusaoRazaoSocial="+inclusaoExclusaoRazaoSocial+"&inclusaoExclusaoEmail="+inclusaoExclusaoEmail+"&inclusaoExclusaoCep="+inclusaoExclusaoCep+"&inclusaoExclusaoEndereco="+inclusaoExclusaoEndereco+"&inclusaoExclusaoBairro="+inclusaoExclusaoBairro+"&inclusaoExclusaoMunicipio="+inclusaoExclusaoMunicipio+"&inclusaoExclusaoEstado="+inclusaoExclusaoEstado+"&inclusaoExclusaoDDD1="+inclusaoExclusaoDDD1+"&inclusaoExclusaoTelefone="+inclusaoExclusaoTelefone+"&inclusaoExclusaoDDDFax="+inclusaoExclusaoDDDFax+"&inclusaoExclusaoFax="+inclusaoExclusaoFax+"&inclusaoExclusaoBanco="+inclusaoExclusaoBanco+"&inclusaoExclusaoAgencia="+inclusaoExclusaoAgencia+"&inclusaoExclusaoConta="+inclusaoExclusaoConta+"&inclusaoExclusaoDiaHora="+inclusaoExclusaoDiaHora+"&inclusaoExclusao="+inclusaoExclusao+"&formName="+formName;
        var strURL    = "../../inc/ajax.php";

        xmlhttp.open("POST", strURL, true);

        xmlhttp.onreadystatechange=function() {
                if ( xmlhttp.readyState==4 ){
                        
                        alertar('Inclusão ou Exclusão de Endereço',xmlhttp.responseText,'Ok,false');
                        limparForm(formName);
                }
        };
        xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
        xmlhttp.send(strQuery);
}


function inclusaoExclusaoServico() {
        
        var inclusaoExclusaoRazaoSocial          = document.getElementById("inclusaoExclusaoRazaoSocial").value;
        var inclusaoExclusaoServicoEspecialidade = document.getElementById("inclusaoExclusaoServicoEspecialidade").value;
        var inclusaoExclusaoServicoOutra         = document.getElementById("inclusaoExclusaoServicoOutra").value;
        var inclusaoExclusaoServicoObservacao    = document.getElementById("inclusaoExclusaoServicoObservacao").value;
        var inclusao                             = document.getElementById("inclusao");
        var exclusao                             = document.getElementById("exclusao");

        var inclusaoExclusao                     = ( inclusao.checked == true ) ? inclusao.value : exclusao.value;
        
        
        var formName  = "formInclusaoExclusaoServico";
        var strQuery  = "inclusaoExclusaoRazaoSocial="+inclusaoExclusaoRazaoSocial+"&inclusaoExclusaoServicoEspecialidade="+inclusaoExclusaoServicoEspecialidade+"&inclusaoExclusaoServicoOutra="+inclusaoExclusaoServicoOutra+"&inclusaoExclusaoServicoObservacao="+inclusaoExclusaoServicoObservacao+"&inclusaoExclusao="+inclusaoExclusao+"&formName="+formName;
        var strURL    = "../../inc/ajax.php";

        xmlhttp.open("POST", strURL, true);

        xmlhttp.onreadystatechange = function() {
                if ( xmlhttp.readyState == 4 ) {
                        
                        alertar('Inclusão ou Exclusão de Serviço',xmlhttp.responseText,'Ok,false');
                        limparForm(formName);
                }
        };
        xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
        xmlhttp.send(strQuery);
}

function CBAlterarSenha() {

        var strCPF          = document.getElementById("ben_cpf"      ).value;
        var strSenha        = document.getElementById("senha"        ).value;
        var strNovaSenha    = document.getElementById("nova_senha"   ).value;
        var strRepetirSenha = document.getElementById("repetir_senha").value;
        
        if ( strNovaSenha == strRepetirSenha && strNovaSenha != "" && strRepetirSenha != "" ) {

                if ( ( strNovaSenha.length < 7 ) ) {
                        var formName  = "formCBAlterarSenha";
                        var strQuery  = "senha="+strSenha+"&novaSenha="+strNovaSenha+"&repetirSenha="+strRepetirSenha+"&ben_cpf="+strCPF+"&formName="+formName;
                        var strURL    = "../../inc/ajax.php";
        
                        xmlhttp.open("POST", strURL, true);
        
                        xmlhttp.onreadystatechange = function() {
                                if ( xmlhttp.readyState == 4 ) {
        
                                        alertar('Alteração de senha',xmlhttp.responseText,'Ok,false');
                                        limparForm(formName);
                                }
                        };
                        xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
                        xmlhttp.send(strQuery);
                }
                else {
                        alertar('Alteração de senha','A senha deve ter no máximo 6 caracteres!','Ok,false');
                }
        }
        else {
                alertar('Alteração de senha','Senhas não combinam!','Ok,false');
        }
}

function CCAlterarSenha() {

        var strSenha        = document.getElementById("senha").value;
        var strNovaSenha    = document.getElementById("nova_senha").value;
        var strRepetirSenha = document.getElementById("repetir_senha").value;

        if ( strNovaSenha == strRepetirSenha && strNovaSenha != "" && strRepetirSenha != "" ) {

                if ( ( strNovaSenha.length < 7 ) ) {
                        
                        var formName  = "formCCAlterarSenha";
                        var strQuery  = "senha="+strSenha+"&novaSenha="+strNovaSenha+"&repetirSenha="+strRepetirSenha+"&formName="+formName;
                        var strURL    = "../../inc/ajax.php";
        
                        xmlhttp.open("POST", strURL, true);
        
                        xmlhttp.onreadystatechange = function() {
                                if ( xmlhttp.readyState == 4 ) {
        
                                        alertar('Alteração de senha',xmlhttp.responseText,'Ok,false');
                                        limparForm(formName);
                                }
                        };
                        xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
                        xmlhttp.send(strQuery);
                }
                else {
                        alertar('Alteração de senha','A senha deve ter no máximo 6 caracteres!','Ok,false');
                }
        }
        else {
                alertar('Alteração de senha','Senhas não combinam!','Ok,false');
        }
}

function esqueceuSenha() {

        var strCanalCB  = document.getElementById("esqueciSenhaCB");
        var strCanalCC  = document.getElementById("esqueciSenhaCC");
        var bEmpCodigo  = document.getElementById("empcodigoB").value;
        var bRed        = document.getElementById("redB").value;
        var bSeq        = document.getElementById("seqB").value;
        var bCPF        = document.getElementById("cpfB").value;
        var bEmail      = document.getElementById("emailB").value;
        var cConvenio   = document.getElementById("convenioC").value;
        var cCgcCpf     = document.getElementById("cgc_cpfC").value;
        var cEmail      = document.getElementById("emailC").value;
        var formName    = "formEsqueceuSenha";
        var strURL      = "../../inc/ajax.php";
        
        var strMensagem = "Para cadastrar um e-mail, faça contato com a nossa<br> Central de Atendimento do Beneficiário:<br> Fone: 0800512202 ou pelo Fale Conosco";


        if ( strCanalCB.checked == false && strCanalCC.checked == false) {
                alertar('Esqueceu senha','Selecione o tipo de canal.','Ok,false');
        }
        else {
                if (strCanalCB.checked) {
                        if ( (bEmpCodigo == "" && bRed == "" && bSeq == "" && bCPF == "") || (bEmpCodigo == "Emp." && bRed == "RE/d" && bSeq == "seq." && bCPF == "CPF") ) {
                                alertar('Esqueceu senha','Preencha corretamente os campos','Ok,false');
                        }
                        else {
                                if ( (bEmail == "") || (bEmail == "E-mail") ) {
                                        alertar('Esqueceu senha',strMensagem,'Ok,false');
                                }
                                else {
                                        var strQuery  = "strCanal=B&bEmpCodigo="+bEmpCodigo+"&bRed="+bRed+"&bSeq="+bSeq+"&bCpf="+bCPF+"&bEmail="+bEmail+"&formName="+formName;
                                }
                        }
                }
                if (strCanalCC.checked) {
                        if ( (cConvenio == "" && cCgcCpf == "") || (cConvenio == "Nº do Convênio" && cCgcCpf == "CGC/CPF") ) {
                                alertar('Esqueceu senha','Preencha corretamente os campos','Ok,false');                         
                        }
                        else {
                                if ( (cEmail == "") || (cEmail == "E-mail") ) {
                                        alertar('Esqueceu senha',strMensagem,'Ok,false');
                                }
                                else {
                                        var strQuery  = "strCanal=C&cConvenio="+cConvenio+"&cCgcCpf="+cCgcCpf+"&cEmail="+cEmail+"&formName="+formName;
                                }
                        }
                }

                if (strQuery) {
                        xmlhttp.open("POST", strURL, true);
                        xmlhttp.onreadystatechange = function() {
                                if ( xmlhttp.readyState == 4 ) {
                                        alertar('Esqueceu senha',xmlhttp.responseText,'Ok,false');
                                        limparForm(formName);
                                }
                        };
                        xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
                        xmlhttp.send(strQuery);
                }

        }
}

function verificaAcesso ( tipoPerfil, strLink ) {
        var formName  = "verificaAcesso";
        var strURL    = "../../inc/ajax.php";
        var strQuery  = "tipoPerfil="+tipoPerfil+"&strLink="+strLink+"&formName="+formName;

        xmlhttp.open("POST", strURL, true);
        xmlhttp.onreadystatechange = function() {
                if ( xmlhttp.readyState == 4 ) {
                        if ( xmlhttp.responseText != "" ) {
                                alertar('Login',xmlhttp.responseText,'Ok,false');
                        } else {
                                window.location = strLink;
                        }
                }
        };
        xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
        xmlhttp.send(strQuery);
}


function verificaAcessoTiss() {

        var formName  = "verificaAcessoTiss";
        var strURL    = "../../inc/ajax.php";
        var strQuery  = "formName="+formName;

        xmlhttp.open("POST", strURL, true);
        xmlhttp.onreadystatechange = function() {
                if ( xmlhttp.readyState == 4 ) {
                        if ( xmlhttp.responseText != "" ) {
                                alertar('TISS - SENERGISUL',xmlhttp.responseText,'Ok,false');
                        }
                        else {
                                window.open('../../../tiss/content/home/index.php', '', 'width=770,scrollbars=yes,resizable=yes,toolbar=no,location=yes');
                        }
                }
        };
        xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
        xmlhttp.send(strQuery);
}


function logar () {
        var formName   = "FormLogin";
        var tipoPerfil = document.getElementById("acessoDiretoSelect").value;
        var strURL     = "../../inc/ajax.php";
        var strQuery   = "formName="+formName+"&tipoPerfil="+tipoPerfil;

        switch (tipoPerfil) {
                default: alertar('Login','Selecione um perfil','Ok,false');
                case "cb":
                        var bEmpCodigo = document.getElementById("beneficiarioEmpCodigo").value;
                        var bSeq       = document.getElementById("beneficiarioSeq").value;
                        var bRed       = document.getElementById("beneficiarioRed").value;
                        var bSenha     = document.getElementById("beneficiarioSenha").value;

                        if (bEmpCodigo == "Emp." || bSeq == "seq." || bRed == "RE/d" || bSenha == "senha" ) {
                                alertar('Login','Preencha os campos corretamente.','Ok,false');
                        } else {
                                strQuery = "formName="+formName+"&tipoPerfil="+tipoPerfil+"&bEmpCodigo="+bEmpCodigo+"&bSeq="+bSeq+"&bRed="+bRed+"&bSenha="+bSenha;
                        }

                break;

                case "cc":
                        var cConvenio = document.getElementById("conveniadoConvenio").value;
                        var cCPF      = document.getElementById("conveniadoCPF").value;
                        var cSenha        = document.getElementById("conveniadoSenha").value;
                        if ( cConvenio == "Nº do Convênio" || cCPF == "CPF" || cSenha == "senha" ) {
                                alertar('Login','Preencha os campos corretamente.','Ok,false');
                        } else {
                                strQuery = "formName="+formName+"&tipoPerfil="+tipoPerfil+"&cConvenio="+cConvenio+"&cCPF="+cCPF+"&cSenha="+cSenha;
                        }
                break;

        }

        if ( strQuery != "" ) {
                xmlhttp.open("POST", strURL, true);
                xmlhttp.onreadystatechange = function() {
                        if ( xmlhttp.readyState == 4 ) {

                                if (xmlhttp.responseText.substr(0,3) == "Olá") {
                                    var acessoDiretoSair                               = document.getElementById("acessoDiretoSair");
                                    acessoDiretoSair.style.display                     = 'block';
                                    acessoDiretoSair.innerHTML                         = xmlhttp.responseText;
                                    document.getElementById('FormLogin').style.display = 'none';
								}
								else if (xmlhttp.responseText.substr(0,3) == "olá") {
                                    var acessoDiretoSair                               = document.getElementById("acessoDiretoSair");
                                    acessoDiretoSair.style.display                     = 'block';
                                    acessoDiretoSair.innerHTML                         = xmlhttp.responseText;
                                    document.getElementById('FormLogin').style.display = 'none';

                                    document.getElementById('desbloqueio').style.display = 'block'; //Exibe POPUP de desbloqueio de cartao
                                }
                                else if (xmlhttp.responseText != "") {

                                        if (xmlhttp.responseText == "cb_incluir_dados") {
                                                document.location = "../cb_cadastre/incluir_dados.php";
                                        }
                                        else if (xmlhttp.responseText == "cc_incluir_dados") {
                                                document.location = "../cc_cadastre/incluir_dados.php";
                                        }
                                        else {
                                                alertar('Login',xmlhttp.responseText,'Ok,false');
                                        }
                                }
                        }
                };
                xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
                xmlhttp.send(strQuery);
        }
}


function AvisoLido (aviso_id) {
        if ( aviso_id != "" ) {
                var strURL    = "../../xml/avisos.php?aviso_id="+aviso_id;

                xmlhttp.open("GET", strURL, true);

                xmlhttp.onreadystatechange = function() {
                        if ( xmlhttp.readyState == 4 ){
                                if ( isNaN ( xmlhttp.responseText ) == false ) {
                                        document.getElementById(aviso_id).style.display = "none";
                                }
                        }
                }
                xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
                xmlhttp.send(null);
        }
}


function carregaDependentes() {

        var strURL = "dependentes.php";

        xmlhttp.open("GET", strURL, true);
        
        xmlhttp.onreadystatechange = function() {
                if ( xmlhttp.readyState == 4 ) {
                        document.getElementById("dependentes").innerHTML = xmlhttp.responseText;
                }
        }
        xmlhttp.send(null);
}


function incluirDados() {

        var tipo_perfil          = document.getElementById("tipo_perfil").value;
        var inserir_email        = document.getElementById("inserir_email").value;


        if ( tipo_perfil == "cb" ) {
                
                var inserir_ddd_contato  = document.getElementById("inserir_ddd_contato").value;
                var inserir_fone_contato = document.getElementById("inserir_fone_contato").value;

                var formName = "formCBIncluirDados";
                var strQuery = "inserir_email="+inserir_email+"&inserir_ddd_contato="+inserir_ddd_contato+"&inserir_fone_contato="+inserir_fone_contato+"&formName="+formName;
        }
        else {
                var formName = "formCCIncluirDados";
                var strQuery = "inserir_email="+inserir_email+"&formName="+formName;
        }
        
        var strURL    = "../../inc/ajax.php";

        xmlhttp.open("POST", strURL, true);
        xmlhttp.onreadystatechange = function() {
                if ( xmlhttp.readyState == 4 ) {

                        if ( xmlhttp.responseText != "" ) {
                                alertar('Seus Dados Cadastrais',xmlhttp.responseText,'Ok,false');
                        }
                }
        };
        xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
        xmlhttp.send(strQuery);
}


function consultarAndamento() {

        var strDataPagamento_1 = document.getElementById("data_pagamento_1").value;
        var strDataPagamento_2 = document.getElementById("data_pagamento_2").value;


        var strURL   = "reembolso.php";
        var strQuery = "data_pagamento_1="+strDataPagamento_1+"&data_pagamento_2="+strDataPagamento_2;

        xmlhttp.open("POST", strURL, true);
        xmlhttp.onreadystatechange = function() {

                if ( xmlhttp.readyState == 1 ) {
                        document.getElementById("reembolso").innerHTML = "Carregando dados...";
                }

                if ( xmlhttp.readyState == 4 ) {
                        document.getElementById("reembolso").innerHTML = xmlhttp.responseText;
                }
        };
        xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
        xmlhttp.send(strQuery);
}


function totalDebito(blnMarcado, intValorDebito) {
        
        var intValorTotal = document.getElementById("valor_total").value;
        var strURL        = "valor_debito.php";
        var strQuery      = "marcado="+blnMarcado+"&valor_debito="+intValorDebito+"&valor_total="+intValorTotal;

        xmlhttp.open("POST", strURL, true);
        xmlhttp.onreadystatechange = function() {

                if ( xmlhttp.readyState == 4 ) {
                        document.getElementById("valor_debito").value = xmlhttp.responseText;
                }
        };
        xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
        xmlhttp.send(strQuery);
}


function desbloquearCartao() {

	var objForm       = document.getElementById("formDesbloquear");
	var intEmpCodigo  = objForm.empresa_codigo.value;
	var intRed        = objForm.red.value;
	var intSeq        = objForm.seq.value;

	var intBnfSeq     = objForm.bnf_seq;
	var strBnfNome    = objForm.bnf_nome;
	var intCpf        = objForm.bnf_cpf;
	var intRg         = objForm.bnf_rg; 
	var strBnfNomeMae = objForm.bnf_nome_mae;

	var strQuery      = "empresa_codigo="+intEmpCodigo+"&red="+intRed+"&seq="+intSeq+"&";
	var strURL        = "desbloquear.php";
	var strErro       = "";

        
	if ( intBnfSeq.type == undefined ) {
					
		for ( i = 0; i < intBnfSeq.length; i++ ) {
				
			if ( strBnfNomeMae[i].value == "" ) {
				strErro = "O campo nome da mãe deverá ser preenchido.";
				break;
			}
			strBnfNomeMae[i].style.borderColor = '';
			strBnfNomeMae[i].style.border='1px solid #4C6075';

			intRg[0].style.borderColor = '';
			intRg[0].style.border='1px solid #4C6075';
			
			if ( ( intRg[0].value == "" ) || ( intRg[0].value == "0" ) || ( isNaN(intRg[0].value) ) ) {
				strErro = "O campo rg do titular está em formato inválido.";
				intRg[0].style.border = '1px solid red';
				break;
			}

			if (validaNome(strBnfNomeMae[i]) == false) {
				strErro = "O campo nome da mãe está em formato inválido.";
				strBnfNomeMae[i].style.border = '1px solid red';
				break;
			}
			else {
				strQuery += intBnfSeq[i].name+"="+intBnfSeq[i].value+"&";
				strQuery += strBnfNome[i].name+"="+strBnfNome[i].value+"&";
				strQuery += intCpf[i].name+"="+intCpf[i].value+"&";
				strQuery += intRg[i].name+"="+intRg[i].value+"&";
				strQuery += strBnfNomeMae[i].name+"="+strBnfNomeMae[i].value+"&";
			}
		}
	}
	else {
		strBnfNomeMae.style.borderColor = '';
		strBnfNomeMae.style.border='1px solid #4C6075';
		
		intRg.style.borderColor = '';
		intRg.style.border='1px solid #4C6075';
		
		if ( ( intRg.value == "" ) || ( intRg.value == "0" ) || ( isNaN(intRg.value) ) ) {
			strErro = "O campo rg do titular está em formato inválido.";
			intRg.style.border = '1px solid red';
		}
		else if (validaNome(strBnfNomeMae) == false) {
			strErro = "O campo nome da mãe está em formato inválido.";
			strBnfNomeMae.style.border = '1px solid red';
		}
		else {
			strQuery += intBnfSeq.name+"="+intBnfSeq.value+"&";
			strQuery += strBnfNome.name+"="+strBnfNome.value+"&";
			strQuery += intCpf.name+"="+intCpf.value+"&";
			strQuery += intRg.name+"="+intRg.value+"&";
			strQuery += strBnfNomeMae.name+"="+strBnfNomeMae.value+"&";
		}
	}


	if ( strErro == "" ) {

		xmlhttp.open("POST", strURL, true);
		xmlhttp.onreadystatechange = function() {
			if ( xmlhttp.readyState == 4 ) {
				alertar('Desbloqueio de Cartão', xmlhttp.responseText, 'Ok,false');
			}
		};
		xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
		xmlhttp.send(strQuery);
	}
	else {
		alertar('Desbloqueio de Cartão', strErro, 'Ok,false');
	}
}


ajax();