document.addEventListener('deviceready', onDeviceReady, false);

function onDeviceReady() {
    // Make sure the plugin is installed
    if (cordova.getAppVersion) {
        cordova.getAppVersion.getVersionNumber(function (version) {
            var float_version = parseFloat(version);

            // alert(float_version);

			$.ajax({
                type: 'post',
                url: 'https://transformationembassy.com/controller/api/app-version/',
                data: { version: float_version },
                crossDomain: true,
                success: function (data) {
                    var jsonData = JSON.parse(data);
    
                    for (var i = 0; i < jsonData.length; i++) {
                        var item = jsonData[i];

                        // alert(item.android_app_url);
    
                        if (item.android_app_url != '' && item.android_app_url != 0) {
                            // Show a non-closable dialog with a button
                            navigator.notification.alert(
                                "A new version is available!",
                                function () {
                                    // Redirect the user to the update URL
                                    cordova.InAppBrowser.open(item.android_app_url, '_system');
                                },
                                "Update Available",
                                "Update Now"
                            );
                            localStorage.setItem('update_avl', 'true');
                        }
                        else{

                        }
                    }
                }
            });
        });
    } else {
        console.error('cordova-plugin-app-version is not installed');
    }
}

$(document).ready(function() {
  // Show the splash screen for 3 seconds
   setTimeout(function(){
     $("#splash-screen").fadeOut("slow", function(){
         // Redirect to page2.html after fade out
         window.location.href = "login.html";
     });
 }, 3000); // 3000 milliseconds = 3 seconds
});

var navItems = document.querySelectorAll(".bottom-nav-item");

navItems.forEach(function(e, i) {
 e.addEventListener("click", function(e) {
   navItems.forEach(function(e2, i2) {
     e2.classList.remove("active");
   });
   this.classList.add("active");
 });
});

$(document).ready(function() {
 $(".chi-keyPad").click(function() {
     var value = $(this).data('id');

     if ($('.chimaKeyPadDisplay1').val()=='') {

       $('.chimaKeyPadDisplay1').val(value);

     }
     else if ($('.chimaKeyPadDisplay2').val()=='') {

       $('.chimaKeyPadDisplay2').val(value);

     }
     else if ($('.chimaKeyPadDisplay3').val()=='') {

       $('.chimaKeyPadDisplay3').val(value);

     }
     else if ($('.chimaKeyPadDisplay4').val()=='') {

       $('.chimaKeyPadDisplay4').val(value);

     }
     else {
     }

 });
});

$(document).ready(function() {
$(".chi-cleanPad").click(function() {
 
   
 if ($('.chimaKeyPadDisplay4').val()!='') {

   $('.chimaKeyPadDisplay4').val('');

 }
 else if ($('.chimaKeyPadDisplay3').val()!='') {

   $('.chimaKeyPadDisplay3').val('');

 }
 else if ($('.chimaKeyPadDisplay2').val()!='') {

   $('.chimaKeyPadDisplay2').val('');

 }
 else if ($('.chimaKeyPadDisplay1').val()!='') {

   $('.chimaKeyPadDisplay1').val('');

 }
 else {
 }

});
});

var minutes = 4;
var seconds = 38;

function updateCountdown() {
 $('#countdown').text(formatTime(minutes) + ':' + formatTime(seconds));

 seconds--;
 if (seconds < 0) {
     seconds = 59;
     minutes--;
     if (minutes < 0) {
        
         clearInterval(timer);
         $('#countdown').text('00:00');
        
     }
 }
}

function formatTime(time) {
 return time < 10 ? '0' + time : time;
}

var timer = setInterval(updateCountdown, 1000);





$(document).ready(function () {

  $("#upload-button").click(function () {

    
    $("#image-input").click(); 
  });

  


  




$("#image-input").change(function () {
   var input = this;
   if (input.files && input.files[0]) {
       var reader = new FileReader();

       reader.onload = function (e) {
           $("#profile-image").attr("src", e.target.result);
       };

       reader.readAsDataURL(input.files[0]);
   }
});
});

$(document).ready(function() {
// Initially hide all content except the first div
$('.tabContent div:not(:first)').hide();

// Hide the previous button initially
$('.previous').hide();

// Tab click event
$('.tabs li').click(function() {
 var tabId = $(this).data('id');

 // Show the next or previous buttons as appropriate
 $(this).is(':last-child') ? $('.next').hide() : $('.next').show();
 $(this).is(':first-child') ? $('.previous').hide() : $('.previous').show();

 // Scroll to the clicked tab
 var position = $(this).position();
 $('.tabs').animate({
     'scrollLeft': $('.tabs').scrollLeft() + position.left - 30
 }, 200);

 // Hide all content divs and show the selected one
 $('.tabContent div').hide();
 $('div.' + tabId).show();

 // Update the active class on the tabs
 $('.tabs li').removeClass('active');
 $(this).addClass('active');
});

// Next button click event
$('.next').click(function(e) {
 e.preventDefault();
 $('li.active').next('li').trigger('click');
});

// Previous button click event
$('.previous').click(function(e) {
 e.preventDefault();
 $('li.active').prev('li').trigger('click');
});
});




$(document).ready(function() {
            
                  
            
    // Select Child Jquery
    $('.selectBox').on("click",function(){
        $(this).parent().find('#checkBoxes').fadeToggle();
        $(this).parent().parent().siblings().find('#checkBoxes').fadeOut();
    });

    $('.selectBox').on("click",function(){
        $(this).parent().find('#checkBoxes-one').fadeToggle();
        $(this).parent().parent().siblings().find('#checkBoxes-one').fadeOut();
    });

    $('.pros_closeuser_cont').on("click",'', function(){
        $(".checkBoxes-one").css("display", "none");
    });

    prosload_check_box_content();
  
});





function  prosload_check_box_content()
{


  $(function () {
 
    //attatch click event to the checkbox, then, based on the checked checkboxes to add value to the tags input.
    $(".selectBox-cont input[type='checkbox']").each(function (index, item) {
        
    
        $(item).click(function () {


          
            var checkedvalue = [];
            var id = [];

            $(".selectBox-cont input[type='checkbox']:checked").each(function (index, ele) {
                checkedvalue.push($(ele).val());
                id.push($(ele).data('id'));
            })

            var result = checkedvalue.join(",");
            var result2 = id.join(",");
            
         
            $("#tagsinput").tagsinput('removeAll');
            $("#tagsinput").tagsinput('add', result);
            $("#tagsinput").data('id', result2);


  
        });
    });
    
    //trace the tag remove event, then, based on the tags to checked/unchecked the checkbox
    $("#tagsinput").on('itemRemoved', function () {
        var valarray = $("#tagsinput").val().split(",");
        $(".selectBox-cont input[type='checkbox']").each(function (index, item) {
            if (jQuery.inArray($(item).val(), valarray) != -1) {
                $(item).prop("checked", true);
            }
            else {
                $(item).prop("checked", false);
            }
        });
    });
  
    //get the selected tags.
    // $(".apply").click(function () {
    //     alert($(".tagsinput").data('id'));
    // });
  });

}

