$(document).ready(function(){
  var acc      = '<img src="./imagens/icones/accept.png" alt="" />';
  var imgLoad  = '<img src="./imagens/icones/loading6.gif" alt="" />';
  var imgKey   = '<img src="./imagens/icones/l.png" alt="" />';
  var imgNo    = '<img src="./imagens/icones/exclamation.png" alt="" />';
  $('#login-box').resizable();
  $('#lembrar').click(function(){
    $('#FrmAuthentic').hide(300);
    $('#Box-Lembrete').show(300);
  });

  $('#hideLembrete').click(function(){
    $('#FrmAuthentic').show(300);
    $('#Box-Lembrete').hide(300);
  });

  $('#btnLembrar').click(function(){
  	   $('#btnLembrar').val('Processando ..');
       var serial    = $.trim($('#SerialLembrete').val());
       var numsecure = $.trim($('#numsecure').val());
       if(serial!=''){
         if(numsecure!=''){
           $.post('inc/cc.ajax.white.php?action=lembrar', {Serie: serial, imgSecure: numsecure}, function(data){
           var d = data.split('|');
            if(d[0]== 'Y'){
              if(d[1]){
                  $('#box_lembrete_form').html('Lembrete de senha enviada para o e-mail: '+d[1]+', obrigado. ');
              }else{
                alert(data);
              }
             }else{
               alert(data);
               location.href = 'Clientes.php?Action=lembrete';
             }
           });
          }else{
            alert('Digite o número de segurança');
            $('#numsecure').focus();
          }
         }else{
            alert('Digite seu número de serie.');
            $('#SerialLembrete').focus();
         }
  });


  $('#FrmAuthentic').submit(function(){

      var nSerie = $.trim($('#nSerie').val());
      var sSerie = $.trim($('#sSerie').val());

      if( (nSerie!='') && (sSerie!='') ){
        if((nSerie.length != 6) && (sSerie.length != 6) ){
           alert('Verifique os dados');
        }else{
           $('#LoginErro').hide(500);
           $('#login-box').slideUp(200);//after('<div id="imgLoad"><br />'+imgLoad+' carregando ..</div>');
           $('.super').html(imgLoad+' <u>Carregando ...</u>');
           $.post('inc/cc.ajax.Authentic.php',{NumeroDeSerie: nSerie , SenhaDaSerie: sSerie},function(data){
             $('.super').html(imgKey+' <u>Central do Cliente</u>');
             $('#login-box').slideDown(500);
              if(data == 'N'){
                  $('#LoginErro').html(imgNo+' Seu serial e senha não correspondem. Digite novamente').show(300);
              }else if(data == 'ERROR'){
                  $('#LoginErro').html(imgNo+'O serviço está momentâneamente indisponível. Tente novamente').show(300);
             }
            else{
              if(data == 'Y'){
                $('#FrmAuthentic').html(acc+' Usuário autenticado, aguarde estamos te redirecionando...');
                $('#title-login').html('Aguarde ...');
                location.href = 'Cliente-Key-Authentic.php';
               }else{
                  alert('O Sistema não obteve resposta do servidor.');
                  location.href = 'Clientes.php';
               }

             }
          });
        }
      }
    return false;
  });
});
