var CadastroDownloadsClass = new Class({ options: { script: 'php/ajax_downloads.php' }, initialize: function(options) { this.setOptions(options); this.login = ''; this.flg_cadastro_disponivel = 'S'; this.dadosCliente = {}; if(this.login == 'true'){ this.oper = 'alterar'; } else { this.oper = 'incluir'; } this.imprimeFormulario(this.login, this.dadosCliente); // ajusta top e left this.cadastroDownload = $('cadastro_download'); if(this.cadastroDownload) { var display = $(document.body).getSize(); var top = (display.size.y - 410) / 2; top = top + 'px'; var left = (display.size.x - 350) / 2; left = left + 'px'; this.cadastroDownload.style.left = left; this.cadastroDownload.style.top = top; // adiciona eventos nos botões if($('btnCadastroDownloadFechar')) $('btnCadastroDownloadFechar').addEvent('click', this.fecharJanela); if($('btnCadastroDownloadLogarFechar')) $('btnCadastroDownloadLogarFechar').addEvent('click', this.fecharJanela); if($('btnCadastroDownloadLogarSenha')) $('btnCadastroDownloadLogarSenha').addEvent('click', this.fecharJanela); // botão logar if($('btnCadastroDownloadLogar')) $('btnCadastroDownloadLogar').addEvent('click', this.efetuaLogin.bind(this)); // botão salvar if($('btnCadastroDownloadSalvar')) $('btnCadastroDownloadSalvar').addEvent('click', this.salvar.bind(this)); // nova senha if($('btnCadastroDownloadSenha')) $('btnCadastroDownloadSenha').addEvent('click', this.novaSenha.bind(this)); // link esqueci senha if($('esqueciSenha')) $('esqueciSenha').addEvent('click', function(){this.abrirJanela('senha'); }.bind(this)); // novo cadastro var t1 = $('novoCadastro'); if($('novoCadastro')){ $('novoCadastro').addEvent('click', function(){ if(this.flg_cadastro_disponivel == 'S') this.abrirJanela('formulario'); else alert('O cadastro não está disponível neste momento.'); }.bind(this)); } } // controla comportamento do link de download this.menuDownload = $('menu').getElement('li[class=download]').getFirst('a'); // se não estiver logado if(this.login == '') { if(location.href.indexOf('download.html') != -1) { location.href = 'index.html'; } // remove link this.menuDownload.href = '#'; // abre janela de login this.menuDownload.addEvent('click', function(){this.abrirJanela('login');}.bind(this)); } else { this.menuDownload.href = 'download.html'; } }, imprimeFormulario: function(login, dadosCliente) { var containerCadastro = $('containerCadastro'); if(containerCadastro) { var html = ''; html = '
'; html+= '
'; html+= '
'; html+= '
Downloads
'; html+= '
'; // login html+= '
'; html+= '
Login
'; html+= '
Senha
'; html+= ''; html+= '
'; html+= '
'; // lembrar senha html+= '
'; html+= '
Informe o e-mail utilizado no cadastro para receber uma nova senha.
'; html+= '
E-mail
'; html+= '

'; html+= '
'; // formulário html+= '
'; html+= '
Cadastre-se e possua acesso ao conteúdo exclusívo do website da Telwave.
'; html+= '

Requisitos mínimos para cadastro:

'; html+= '
    '; html+= '
  • Ser um revendedor Telwave
  • '; html+= '
  • Estar ativo no Sistema
  • '; html+= '
  • Ter efetuado compras nos últimos 90 dias
  • '; html+= '

    Caso não se enquadre nestes quesitos, favor entrar em contato com nossos consultores pelo Telefone:(31) 3469-5400

    '; html+= '
    '; html+= '
    Nome
    '; html+= '
    CPF
    '; html+= '
    CNPJ
    '; html+= '
    E-mail
    '; html+= '
    Website
    '; html+= '
    Endereço
    '; html+= '
    Número
    '; html+= '
    Complemento
    '; html+= '
    CEP
    '; html+= '
    Cidade
    '; html+= '
    Bairro
    '; html+= '
    '; html+= '
    Estado
    '; html+= ''; html+= '
    '; html+= '
    Login
    '; html+= '
    Senha
    '; html+= '
    Confirmar Senha
    '; html+= '
    '; html+= '
    '; html+= '
    '; $('containerCadastro').innerHTML = html; // link para meu cadastro var cadastrese = $('cadastrese'); if(cadastrese && login == 'true' && !$('meu_cadastro')) { var div = new Element('div', {"id" : "meu_cadastro"}); for(var campo in dadosCliente) { if($(campo)) $(campo).value = dadosCliente[campo]; } div.addEvent('click', function(){this.abrirJanela('formulario');}.bind(this)); cadastrese.adopt(div, 'top'); } } }, efetuaLogin: function() { var login = $('cl_login').value; var senha = $('cl_senha').value; if(!login || login == '' || !senha || senha == '') { alert('Informe seu login e senha.'); return; } else { show_hide_processando("Processando"); new Ajax(this.options.script, { method: 'post', data: {oper:'login', login: login, senha: senha}, onSuccess: function(obj_text) { show_hide_processando(); eval('var obj = ' + obj_text + ';'); if(obj) { if(obj.tipo_retorno == 'sucesso') { this.menuDownload.href = 'download.html'; location.href = 'download.html'; } else alert(obj.mensagem); } else { alert('O servidor não respondeu. Por favor tente novamente mais tarde.'); } obj = null; }.bind(this), onFailure: function() { show_hide_processando(); alert('O servidor não respondeu. Por favor tente novamente mais tarde.'); } }).request(); } }, salvar: function() { var erro = ''; var dados = {}; dados.oper = this.oper; dados.id = $('uid').value; dados.nome = $('unome').value; dados.cpf = $('ucpf').value; dados.ucnpj = $('ucnpj').value; dados.email = $('uemail').value; dados.site = $('usite').value; dados.logradouro = $('ulogradouro').value; dados.numero = $('unumero').value; dados.complemento = $('ucomplemento').value; dados.cep = $('ucep').value; dados.cidade = $('ucidade').value; dados.bairro = $('ubairro').value; dados.estado = $('uestado').value; dados.usuario = $('clogin').value; dados.senha = $('csenha').value; dados.confirma_senha = $('confirma_senha').value; // Validações if(dados.nome == '') erro += "- Informe o nome.\n"; if (dados.email == '') erro += "- Informe o e-mail.\n"; else { var padrao = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/; if(! padrao.test(dados.email)) erro += "- E-mail inválido.\n"; } if(dados.usuario == '') erro += "- Informe o usuario do cliente.\n"; else if(dados.usuario.indexOf(' ') != -1) erro += "- O usuario do não pode conter espaços.\n"; if(id == 0 && dados.senha == '') erro += "- Informe a senha.\n"; if(dados.senha != '' && dados.senha != dados.confirma_senha) erro += "- Senha e confirmação devem ser iguais.\n"; if(erro == '') { show_hide_processando("Processando"); new Ajax(this.options.script, { method: 'post', data: dados, onSuccess: function(obj_text) { show_hide_processando(); eval('var obj = ' + obj_text + ';'); if(obj) { if(obj.tipo_retorno == 'sucesso') { alert('Salvo com sucesso'); $('uid').value = obj.id; this.login = 'true'; this.oper = 'alterar'; location.href = 'download.html'; } else alert(obj.mensagem); } else { alert('O servidor não respondeu. Por favor tente novamente mais tarde.'); } obj = null; }.bind(this), onFailure: function() { show_hide_processando(); alert('O servidor não respondeu. Por favor tente novamente mais tarde.'); } }).request(); } else { alert("O(s) seguinte(s) problema(s) foram encontrado(s):\n" + erro); } }, novaSenha: function() { var erro = ''; var email = $('cl_email').value; // Validações if (email == '') erro += "- Informe o e-mail.\n"; else { var padrao = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/; if(! padrao.test(email)) erro += "- E-mail inválido.\n"; } if(erro == '') { show_hide_processando("Processando"); new Ajax(this.options.script, { method: 'post', data: {oper:'nova_senha', email:email}, onSuccess: function(obj_text) { show_hide_processando(); eval('var obj = ' + obj_text + ';'); if(obj) { if(obj.tipo_retorno == 'sucesso') { alert('Uma nova senha foi enviada para seu e-mail.'); } else alert(obj.mensagem); } else { alert('O servidor não respondeu. Por favor tente novamente mais tarde.'); } obj = null; }.bind(this), onFailure: function() { show_hide_processando(); alert('O servidor não respondeu. Por favor tente novamente mais tarde.'); } }).request(); } else { alert("O(s) seguinte(s) problema(s) foram encontrado(s):\n" + erro); } }, // fecha janela de cadastro fecharJanela: function() { $('cadastro_download').style.display = 'none'; }, // abre janela de cadastro abrirJanela: function(janela) { $('cadastro_download').style.display = 'block'; // login if(!janela || janela == 'login') { $('formulario').style.display = 'none'; $('camposNovaSenha').style.display = 'none'; $('camposLogin').style.display = 'block'; $('cadastro_download').style.height = '200px'; } // nova senha else if(janela == 'senha') { $('camposNovaSenha').style.display = 'block'; $('camposLogin').style.display = 'none'; $('formulario').style.display = 'none'; $('cadastro_download').style.height = '200px'; } // formulario cadastro else if(this.flg_cadastro_disponivel = 'S'){ $('camposLogin').style.display = 'none'; $('camposNovaSenha').style.display = 'none'; $('formulario').style.display = 'block'; $('cadastro_download').style.height = '350px'; $('cadastro_download').style.overflow = 'scroll'; } else if(this.flg_cadastro_disponivel = 'S'){ alert('A Telwave não está aceitando novos cadastros no momento. Contamos com sua compriensão.'); } } }); CadastroDownloadsClass.implement(new Options, new Events); function ObjectToQueryString(obj) { var QueryString = ''; for(var prop in obj) { if(QueryString == '') QueryString += prop + '=' + obj[prop]; else QueryString += '&' + prop + '=' + obj[prop]; } return QueryString; }