


<?php 
$fgh = getFullPaymentSettings();


$dsbj = $fgh['result']['data'][0]['paymentGatewayoffon'];

foreach ($dsbj as $key => $dd) {
  if ($dd['source'] == 'WEBSITE') {
    $paymentSeverOn = $dd['isenable']; 
    $paymentSeverText = $dd['desc']; 
  }
}

$paymentSetting = @getPaymentGatewaySettings();



// print_r($paymentSetting);

// die();

?>

<!-- date picker -->
<script src="<?=base_url('assets/js/jquery-ui.min.js');?>"></script>
<!-- date picker -->
<script src="<?=base_url('assets/js/notify.js')?>"></script>
<script src="<?=base_url('assets/js/notify.min.js')?>"></script>
<script src="<?=base_url('assets/js/toast.js')?>"></script>

<a href="#" class="back-to-top d-flex align-items-center justify-content-center" style="background-color: #00522cb0 !important"><i class="bi bi-arrow-up-short"></i></a>


  <!-- Vendor JS Files -->
  <script src="<?=base_url('assets/vendor/aos/aos.js');?>"></script>
  <script src="<?=base_url('assets/vendor/bootstrap/js/bootstrap.bundle.min.js');?>"></script>
  <script src="<?=base_url('assets/vendor/glightbox/js/glightbox.min.js');?>"></script>
  <script src="<?=base_url('assets/vendor/swiper/swiper-bundle.min.js');?>"></script>

  <!-- Template Main JS File -->
  <script src="<?=base_url('assets/js/main.js');?>"></script>

  <script type="text/javascript">

    $('#tabs .nav-link2').on('click', function() {
      const activeTab = $('.nav-link2.active');

      if (activeTab.attr('tab-name') === 'Devotee') {
        $('#signupLink').hide();
      } else {
        $('#signupLink').show();
      }
    });

    var loader = new ldLoader({root: ".ldld.full"});
    if (window.performance && window.performance.navigation.type === window.performance.navigation.TYPE_BACK_FORWARD) {
      loader.on();
    }

    document.addEventListener("click", function(event) {
      if (event.target.matches(".navlink, .loader")) {
        loader.on();
      }
    });

    window.onload = function() {
      loader.off();
    };

    $(function(){
     $('#timepicker').mdtimepicker();
     $('.modal').modal({backdrop: 'static', keyboard: false});
   });
    $("#loginBtn").hide();




    function checkLoginStatus(serviceAmt='', serviceName='', service_Id='', serviceCategoryTypes='', serviceTypes='', dayTypes='', startDate='', startTime='') {

     loader.on();

     if(serviceAmt == 'OUTSIDE'){
      pageName= 'REQUEST-OUTSIDE';
    }else if(serviceAmt == 'APARAKARYA'){
      pageName= 'APARAKARYA';
    }else if(serviceAmt == 'REQUEST-FORM'){
      pageName= 'REQUEST-FORM';
    }else if(serviceAmt == 'PAY-LATER'){
      pageName = 'PAY-LATER';
    }else{
      pageName= '';

    }


    var amt = (serviceAmt / 1).toFixed(2);
    var serviceName = serviceName;
    var serviceId = service_Id;

    var serviceCategoryTypes = serviceCategoryTypes;
    var serviceTypes = serviceTypes;
    var dayTypes = dayTypes;
    var startDate = startDate;
    var startTime = startTime;



    if (serviceCategoryTypes == 'DONATIONS') {
      $("#dateTimeTable").css('display','none');
    }
    if($("#DonateToTemple").val() == 'DONATIONS'){ $("#DonateToTemple").val('') };

    if (serviceCategoryTypes == 'DONATIONS' && amt == 0.00) {
      $("#edittable").html('<input style="text-align: right;" type="number" class="form-control currency" id="serviceAmt" min="1.00" value="1.00" required/>');
    }else{

      $("#edittable").html('<h4 id="servicePrice">'+amt+'</h4><input type="hidden" name="" value="'+amt+'" id="serviceAmt">');
    }

    // event.preventDefault();
    $.ajax({
      url: "<?=base_url('check-login-status');?>",
      type: "POST",
      dataType: "json",
      success: function(data) 
      {
       loader.off();
       if(data == 0){
        $("#signupModal").modal("hide");
        $("#EventDetailsModal").modal("hide");
        $('#servicePrice').text('$'+amt);
        $('#serviceName').text(serviceName);

        if (serviceCategoryTypes == 'EVENTS') {

          $('#fullPackage').val('true');
        }


        $('#serviceId').val(serviceId);
        if (amt != 0.00) {
          $('#serviceAmt').val(amt);
        }
        openLoginModal(pageName);
        $('#serviceCategoryTypes').val(serviceCategoryTypes);
        $('#serviceTypes').val(serviceTypes);
        $('#dayTypes').val(dayTypes);
        $('#startDate').val(startDate);
        $('#serviceStartDate').val(startDate);
        $('#startTime').val(startTime);
        $('#timepicker').val(startTime);

      }else{

        if (pageName == 'REQUEST-FORM') {

          window.location.href="<?=base_url('services/serviceRequest');?>";
        }else if(pageName == 'REQUEST-OUTSIDE'){
          window.location.href="<?=base_url('services/request/outside-temple');?>";
        }
        else if(pageName == 'APARAKARYA'){
          window.location.href="<?=base_url('services/request/aparakarya');?>";
        }
        else if(pageName == 'PAY-LATER'){
          window.location.href="<?=base_url('services/payLater');?>";
        }

        if (serviceCategoryTypes == 'EVENTS') {

          $('#fullPackage').val('true');
        }


        $("#loginModal").modal("hide");
        $('#servicePrice').text('$'+amt);
        $('#serviceName').text(serviceName);
        $('#serviceId').val(serviceId);
        $('#serviceCategoryTypes').val(serviceCategoryTypes);
        $('#serviceTypes').val(serviceTypes);
        $('#dayTypes').val(dayTypes);
        $('#startDate').val(startDate);
        $("#serviceStartDate").val(startDate);
        $('#startTime').val(startTime);
        $("#timepicker").val(startTime);
        if (amt != 0.00) {
          $('#serviceAmt').val(amt);
        }

        $.ajax({
          url: "<?=base_url('Home/getServiceDetailsById');?>",
          type: "POST",
          data : {'serviceId' : serviceId},
          success: function(serviceDetails) 
          {
           loader.off();
           var details = JSON.parse(serviceDetails);

           if (serviceCategoryTypes == 'EVENTS') {

            $('#fullPackage').val('true');
          }

          if (serviceDetails != '') {
            $("#servicesDetails").html();

            if (details.startDate != '') {
              if ($("#serviceStartDate").val() != '') {
                $("#serviceStartDate").val('');
              }
              $("#serviceStartDate").val('');
              $("#serviceStartDate").val(details.startDate);
              $("#serviceStartDate").prop('readonly', true);
            }else{
             if ($("#serviceStartDate").val() != '') {
              $("#serviceStartDate").val('');
            }
            $("#serviceStartDate").val('');
            $("#serviceStartDate").val(details.startDate);
            $("#serviceStartDate").prop('readonly', false);
          }

          if (details.startTime != '') {

            if ($("#timepicker").val() != '') {
              $("#timepicker").val('');
            }

            $("#timepicker").val(details.startTime);
            $("#timepicker").prop('readonly', true);
            $("#timepicker").prop('disabled', true);


          }else{
           if ($("#timepicker").val() != '') {
            $("#timepicker").val('');
          }

          $("#timepicker").val(details.startTime);
          $("#timepicker").prop('readonly', false);
          $("#timepicker").prop('disabled', false);
        }


        $("#modaleventCloseBtn").click();
        $("#paymentModal").modal("show");
      }
    }             
  });



        if ($("#serviceCategoryTypes").val() == 'AWAY-TEMPLE') {
          $("#addressField").html('<p>Please Select Your Service Location:</p> <input type="radio" id="home" name="ServiceAddress" value="home" checked required>  <label for="home">Home</label><br> <input type="radio" id="other" name="ServiceAddress" value="other">  <label for="other">Other Location</label><br><textarea class="form-control my-3" placeholder="Enter Your Full address" id="Address" name="Address" style="display:none" required></textarea>');


          $('input:radio[name="ServiceAddress"]').change(function(){
            if($(this).val() == 'home'){
             $("#Address").css('display','none');
           }else{
            $("#Address").css('display','inline-flex');
          }
        });

        }
      }
    }             
  });
}


function subscribeNewsletterCheckLogin(){
 loader.on();

 // event.preventDefault();
 $.ajax({
  url: "<?=base_url('check-login-status');?>",
  type: "POST",
  dataType: "json",
  success: function(data) 
  {
   loader.off();
   if (data == 0) {
    openLoginModal('newsletter');
  }else{
    subscribeNewsletter();
  }

}
});
}

function subscribeNewsletter() {

 // event.preventDefault();

 loader.on();
 $.ajax({
  url: "<?=base_url('Home/subscribeNewsletter');?>",
  type: "POST",
  dataType: "json",
  success: function(data) 
  {
    // alert(data);
   loader.off();

   swal({
     html: true,
     title: data,
     type: "success",
     confirmButtonText: 'OK',
     confirmButtonColor: '#008080',
   },

   function(){
     if((location.href.match(/([^\/]*)\/*$/)[1]).indexOf('Payonline') != -1){
      window.location.href="<?=base_url('logout');?>"
    }
    else
    {
      window.location.reload(); 
    }

  });
 }
});

}

function openLoginModal(page = ''){


  var fromPage = page;
  $("#fromPage").val(page);
  $("form").get(0).reset();

  var emailotpntn = document.getElementById('emailotpntn');

  emailotpntn.disabled = false;
  emailotpntn.innerText = 'LOGIN';

  $('.signupBtnClose').click();
  $("#signupModal").modal("hide");
  $("#loginModal").modal("show");


  $(".vOtpBox").hide();
  $("#emailotpntn").show();
  $(".mobile_section").show();
  $(".email_section").show();
}

function openSignupModal(){
  $("form").get(0).reset();

  var signupBtn = document.getElementById('signupBtn');
  signupBtn.disabled = false;
  signupBtn.innerText = 'SIGN UP';
  $('.loginBtnClose').click();
  $("#loginModal").modal("hide");
  $("#signupModal").modal("show");
}

function startTimer() {

  resendButton.disabled = true;

  let timeLeft = 120;
  let minutes, seconds;

  timerMessage.style.display = "block";
  resendButton.style.display = "none";

  const countdown = setInterval(() => {
    minutes = Math.floor(timeLeft / 60);
    seconds = timeLeft % 60;
    timeCounter2.innerText = `${minutes}:${seconds.toString().padStart(2, "0")}`;

    timeLeft--;

    if (timeLeft === 0) {
      clearInterval(countdown);
      timerMessage.style.display = "none";
      resendButton.style.display = "block";
      resendButton.disabled = false;
    }
  }, 1000);
}

function sendEmailOtp(url){


  loader.on();
    //test
  var email = $('#loginEmail').val();
  var phoneval = $('#loginPhoneNumber').val();
  var phoneLength = $('#loginPhoneNumber').val().length;


  var signupPhoneNumber = $('#signupPhoneNumber').val();
  var cuntryCode =  $("#loginModal .iti__selected-flag").attr('title');
  cuntryCode     =   (cuntryCode.split(':')[1]).trim();
  $('#signupPhoneNumber').val(cuntryCode);


  const inputString = $("#loginModal .iti__selected-flag").attr("aria-activedescendant");
  $("#signupModal .iti__selected-flag").attr("aria-activedescendant", inputString);


  const flagTitle = $("#loginModal .iti__selected-flag").attr("title");
  $("#signupModal .iti__selected-flag").attr("title", flagTitle);


  const SignInflagClass = $("#loginModal .iti__flag").attr("class");

  const SignUpflagClass = $("#signupModal .iti__flag").attr("class");



  const SignUpclassesArray = SignUpflagClass.split(" ");
  const SignUpfirstClass = SignUpclassesArray.length > 0 ? SignUpclassesArray[1] : null;
  $("#signupModal .iti__flag").removeClass(SignUpfirstClass);


  const SignInclassesArray = SignInflagClass.split(" ");
  const SignInfirstClass = SignInclassesArray.length > 0 ? SignInclassesArray[1] : null;
  $("#signupModal .iti__flag").addClass(SignInfirstClass);





  if (email == "" && phoneLength < 12) {


    showToast(
    { 
      eleWrapper: '#login-error-flashmsg',
      msg: 'Please enter valid email or valid mobile number.',
      theme: 'warning',
      closeButton: false,
      autoClose: true,
      afterShow: function(){
        console.log('After show function');
      },
      afterClose: function(){
        console.log('After close function');
      }
    } 
    );
    loader.off();

  }else{
    $("#login-error-flashmsg").html("");

    if(email==""){
      // event.preventDefault();
      LoginUser('<?=base_url('signin');?>');
      loader.off();
    }else{

     var mailformat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
     if(email.match(mailformat))
     {
      var btn = document.getElementById('emailotpntn');
      btn.disabled =true;
      btn.innerText = 'SENDING';


      // event.preventDefault();
      var url = url;
      var email = $('#loginEmail').val();

      const activeLoginTab = $('.nav-link.active');
      const LoginTabName = activeLoginTab.attr('tab-name');

      $.ajax({
        url: url,
        type: "POST",
        dataType: "json",
        data : {'email' : email, 'LoginTabName' : LoginTabName},
        success: function(data) 
        {
         loader.off();


         if (data['statusCode'] == '1') {  

          $("#emailotpntn").hide();
          $(".mobile_section").hide();

          btn.disabled =true;
          btn.innerText = 'SENT';
          $('#otptoggle').css('display','inline-flex');
          var btn2 = document.getElementById('emailotpverifybtn');
          btn2.disabled =false;
          btn.disabled =true;


          $("#AdministratorTab").addClass('disabled');
          $("#devoteeTab").addClass('disabled');




          startTimer();


          $("#emailotp").focus();

          showToast(
          { 
            eleWrapper: '#login-success-flashmsg',
            msg: 'OTP send on this email id!',
            theme: 'success',
            closeButton: false,
            autoClose: true,
            afterShow: function(){
              console.log('After show function');
            },
            afterClose: function(){
              console.log('After close function');
            }
          } 
          );

          $(".mobile-section").hide();

        }else if (data['statusCode'] == '2') {
         btn.disabled =false;
         btn.innerText = 'LOGIN';

         showToast(
         { 
          eleWrapper: '#login-success-flashmsg',
          msg: 'Technical Error! Please Login With Phone Number or Contact Admin.',
          theme: 'error',
          closeButton: false,
          autoClose: true,
          afterShow: function(){
            console.log('After show function');
          },
          afterClose: function(){
            console.log('After close function');
          }
        } 
        );
       }else{


        if (LoginTabName == 'Management') {

          btn.disabled =false;
          btn.innerText = 'LOGIN';


          showToast(
          { 
            eleWrapper: '#login-error-flashmsg',
            msg: 'This email id is not registered please signup.',
            theme: 'error',
            closeButton: false,
            autoClose: true,
            afterShow: function(){
              console.log('After show function');
            },
            afterClose: function(){
              console.log('After close function');
            }
          } 
          );

        }else
        {

          showToast(
          { 
            eleWrapper: '#signup-error-flashmsg',
            msg: 'This email id is not registered please signup.',
            theme: 'error',
            closeButton: false,
            autoClose: true,
            afterShow: function(){
              console.log('After show function');
            },
            afterClose: function(){
              console.log('After close function');
            }
          } 
          );


          $("#loginModal").modal('hide');
          $("#signupModal").modal('show');

          $("#signupEmail").val(email);


        }
      }
    }             
  });

    }else{
     btn.disabled =false;
     btn.innerText = 'LOGIN';

     showToast(
     { 
      eleWrapper: '#login-error-flashmsg',
      msg: 'Please enter a valid email address.',
      theme: 'warning',
      closeButton: false,
      autoClose: true,
      afterShow: function(){
        console.log('After show function');
      },
      afterClose: function(){
        console.log('After close function');
      }
    } 
    );
     loader.off();
   }

 }
 loader.off();
}
}

function verifyEmailOtp(url){
 loader.on();
 var btn = document.getElementById('emailotpverifybtn');
 btn.disabled =true;
 btn.innerText = 'VERIFYING';


 // event.preventDefault();
 var url = url;
 var otp = $('#emailotp').val();

 if (otp == "") {
   $("#login-success-flashmsg").html("");

   showToast(
   { 
    eleWrapper: '#login-error-flashmsg',
    msg: 'Please enter 6 digit OTP!',
    theme: 'warning',
    closeButton: false,
    autoClose: true,
    afterShow: function(){
      console.log('After show function');
    },
    afterClose: function(){
      console.log('After close function');
    }
  } 
  );
   btn.disabled =false;
   btn.innerText = 'VERIFY';
   loader.off();

 }else{
   var email = $('#loginEmail').val();
   $.ajax({
    url: url,
    type: "POST",
    dataType: "json",
    data : {'otp' : otp,'email':email},
    success: function(data) 
    {
     loader.off();

     if (data['statusCode'] == 1) { 
      btn.disabled =true;
      btn.innerText = 'VERIFIED';
      if($("#includeSankalpamModal").val() == 'YES'){
        $("#loginModal").modal("hide");
      }
      PhoneLogin('<?=base_url('signin');?>');

    }else{
      $("#login-error-flashmsg").html("");
      $("#login-success-flashmsg").html("");


      showToast(
      { 
        eleWrapper: '#login-error-flashmsg',
        msg: data['message'],
        theme: 'warning',
        closeButton: false,
        autoClose: true,
        afterShow: function(){
          console.log('After show function');
        },
        afterClose: function(){
          console.log('After close function');
        }
      } 
      );
      btn.disabled =false;
      btn.innerText = 'VERIFY';
    }


  }             
});
 }
}




function LoginUser(url) {
 loader.on();
 var btn = document.getElementById('emailotpntn');
 btn.disabled = true;
 btn.innerText = 'PLEASE WAIT...';

 // event.preventDefault();
 var url = url;
 var email = $('#loginEmail').val();
 var phone = $('#loginPhoneNumber').val();

 var newphone = 0;
 var cuntryCode =  $("#loginModal .iti__selected-flag").attr('title');
 cuntryCode     =   (cuntryCode.split(':')[1]).trim();
 var value  =  phone.replace(cuntryCode, ''); 
 newphone   =  value; 


 const inputString = $("#loginModal .iti__selected-flag").attr("aria-activedescendant");
 $("#signupModal .iti__selected-flag").attr("aria-activedescendant", inputString);


 const flagTitle = $("#loginModal .iti__selected-flag").attr("title");
 $("#signupModal .iti__selected-flag").attr("title", flagTitle);


 const SignInflagClass = $("#loginModal .iti__flag").attr("class");

 const SignUpflagClass = $("#signupModal .iti__flag").attr("class");



 const SignUpclassesArray = SignUpflagClass.split(" ");
 const SignUpfirstClass = SignUpclassesArray.length > 0 ? SignUpclassesArray[1] : null;
 $("#signupModal .iti__flag").removeClass(SignUpfirstClass);


 const SignInclassesArray = SignInflagClass.split(" ");
 const SignInfirstClass = SignInclassesArray.length > 0 ? SignInclassesArray[1] : null;
 $("#signupModal .iti__flag").addClass(SignInfirstClass);









 const activeLoginTab = $('.nav-link.active');

 const LoginTabName = activeLoginTab.attr('tab-name');




 $.ajax({
  url: url,
  type: "POST",
  dataType: "json",
  data : {'email' : email,'phone':newphone, 'LoginTabName' : LoginTabName},
  success: function(data) 
  {
   loader.off();
   console.log(data);

   if (data.statusCode == 1) {
     btn.disabled =true;
     btn.innerText = 'SENT';

     if(phone!=""){
      submitPhoneNumberAuth();
      $("#emailotpntn").hide();
      $(".email_section").hide();
      $("#loginPhoneNumber").attr('disabled','disabled'); 
    }else{

     $('#otptoggle').css("display", "none");

     var btn2 = document.getElementById('emailotpverifybtn');
     btn2.disabled =false;
     btn.disabled =true;

       // alert('Login Successful.');
     $('.loginBtnClose').click();
     $("#loginModal").modal("hide");
     $("#paymentModal").modal("show");

   }

 }else{


  showToast(
  { 
    eleWrapper: '#signup-error-flashmsg',
    msg: 'This phone no. is not registerd please signup.',
    theme: 'error',
    closeButton: false,
    autoClose: true,
    afterShow: function(){
      console.log('After show function');
    },
    afterClose: function(){
      console.log('After close function');
    }
  } 
  );

  if((location.href.match(/([^\/]*)\/*$/)[1]).indexOf('Payonline') != -1){
    openBoxlog('signup');
    btn.disabled = false;
    btn.innerText = 'LOGIN';
  }
  else
  {


    if (LoginTabName == 'Management') {

      btn.disabled =false;
      btn.innerText = 'LOGIN';


      showToast(
      { 
        eleWrapper: '#login-error-flashmsg',
        msg: 'This phone no. is not registerd please signup.',
        theme: 'error',
        closeButton: false,
        autoClose: true,
        afterShow: function(){
          console.log('After show function');
        },
        afterClose: function(){
          console.log('After close function');
        }
      } 
      );

    }else{

      $("#signupEmail").val(email);
      $("#signupPhoneNumber").val(phone);    
      $("#loginModal").modal('hide');
      $("#signupModal").modal('show'); 

    }
  }
}



}             
});

}


//Phone Login

function PhoneLogin(url) {

    // event.preventDefault();
  loader.on();
  var url = url;
  var email = $('#loginEmail').val();
  var phone = $('#loginPhoneNumber').val();
  var newphone = 0;
  var cuntryCode =  $("#loginModal .iti__selected-flag").attr('title');
  cuntryCode =   (cuntryCode.split(':')[1]).trim();
  var value = phone.replace(cuntryCode, ''); 
  newphone =  value; 


  const inputString = $("#loginModal .iti__selected-flag").attr("aria-activedescendant");
  $("#signupModal .iti__selected-flag").attr("aria-activedescendant", inputString);


  const flagTitle = $("#loginModal .iti__selected-flag").attr("title");
  $("#signupModal .iti__selected-flag").attr("title", flagTitle);


  const SignInflagClass = $("#loginModal .iti__flag").attr("class");

  const SignUpflagClass = $("#signupModal .iti__flag").attr("class");



  const SignUpclassesArray = SignUpflagClass.split(" ");
  const SignUpfirstClass = SignUpclassesArray.length > 0 ? SignUpclassesArray[1] : null;
  $("#signupModal .iti__flag").removeClass(SignUpfirstClass);


  const SignInclassesArray = SignInflagClass.split(" ");
  const SignInfirstClass = SignInclassesArray.length > 0 ? SignInclassesArray[1] : null;
  $("#signupModal .iti__flag").addClass(SignInfirstClass);



  const activeLoginTab = $('.nav-link.active');
  const LoginTabName = activeLoginTab.attr('tab-name');
  console.log(LoginTabName);



  $.ajax({
    url: url,
    type: "POST",
    dataType: "json",
    data : {'email' : email,'phone':newphone,'sessionCreate':1, 'LoginTabName' : LoginTabName},
    success: function(data) 
    {
     loader.off();
     console.log(data);
     if(data.statusCode == 1) {
          // alert('Login Successful.');
      $(".dotlgbtn").text('MY ACCOUNT');

      if($('#serviceId').val())
      {
       $('.loginBtnClose').click();
       $("#loginModal").modal("hide");
       $("#paymentModal").modal("show");


     } else if($('#donateToTempleBtnBeforeLogin').val())
     {
       $('.loginBtnClose').click();
       $("#loginModal").modal("hide");
       $("#DonateToTemple").val('DONATIONS');
       $("#DonateToTemplePaymentModal").modal("show");

     }
     else
     {
       if ($("#fromPage").val() == 'newsletter') {
        $('.loginBtnClose').click();
        $("#loginModal").modal("hide");
        subscribeNewsletter();

      }
      else if ( $("#fromPage").val() == 'REQUEST-FORM' )
      {
        window.location.href = "<?=base_url('services/serviceRequest');?>";
      } else if ( $("#fromPage").val() == 'REQUEST-OUTSIDE' )
      {
        window.location.href = "<?=base_url('services/request/outside-temple');?>";
      }
      else if ( $("#fromPage").val() == 'APARAKARYA' )
      {
        window.location.href = "<?=base_url('services/request/aparakarya');?>";
      }
      else if($("#fromPage").val() == 'MAKE-PAYMENTS-FORM'){
        window.location.href = "<?=base_url('services/MakePayment');?>";
      }
      else if ( $("#fromPage").val() == 'events' )
      {
        window.location.href = "<?=base_url('events/checkout');?>";
      }
      else if ( $("#fromPage").val() == 'services' )
      {

        var includeSankalpam = $("#includeSankalpamModal").val();

        if (includeSankalpam == 'YES') {
          $("#loginModal").modal("hide");
          $("#susbc-form-btn").click();
        }else{
          window.location.href = "<?=base_url('checkout/service')?>";
        }
      }
      else if ( $("#fromPage").val() == 'paylaterServices' )
      {

        var includeSankalpam = $("#includeSankalpamModal").val();

        if (includeSankalpam == 'YES') {
          $("#loginModal").modal("hide");
          $("#susbc-form-btn").click();
        }else{
          window.location.href = "<?=base_url('paylater-services/checkout')?>";
        }
      }
      else if ( $("#fromPage").val() == 'donations' )
      {
        window.location.href = "<?=base_url('donations/checkout');?>";

      }else if ( $("#fromPage").val() == 'recurring-sponsorships' )
      {
        window.location.href = "<?=base_url('recurring-sponsor/checkout');?>";

      }else if ( $("#fromPage").val() == 'sponsorships' )
      {
        window.location.href = "<?=base_url('checkout/sponsorship');?>";
      }
      else if ( $("#fromPage").val() == 'view-cart' )
      {
        window.location.href = "<?=base_url('Services/ViewCart');?>";
      }else if ( $("#fromPage").val() == 'facilities' )
      {
       $("#loginModal").modal("hide");
       BookNow();
       
     }else if ( $("#fromPage").val() == 'pledge_form' )
      {
        submitRecurringForm();
      }else if($("#includeSankalpamModal").val() == 'YES'){
        $("#loginModal").modal("hide");
      }
      else{

       if (LoginTabName == 'Management') {

        window.location.href = "<?=base_url('managements/member-directory');?>";

      }else{

        window.location.href = "<?=base_url('Admin/Dashboard');?>";
      }
    }
  }
}else{
  $("#loginModal").modal('hide');
  $("#signupModal").modal('show');
  showToast(
  { 
    eleWrapper: '#signup-error-flashmsg',
    msg: 'This phone no. is not registerd please signup.',
    theme: 'error',
    closeButton: false,
    autoClose: true,
    afterShow: function(){
      console.log('After show function');
    },
    afterClose: function(){
      console.log('After close function');
    }
  } 
  );

}
}             
});

}



function SignupUser(url) {
 loader.on();

 var btn = document.getElementById('signupBtn');


   // event.preventDefault();


 var phone = $('#signupPhoneNumber').val();

 if (phone.length < 6) {

  showToast(
  { 
    eleWrapper: '#signup-error-flashmsg',
    msg: 'Please enter a valid phone number.',
    theme: 'warning',
    closeButton: false,
    autoClose: true,
    afterShow: function(){
      console.log('After show function');
    },
    afterClose: function(){
      console.log('After close function');
    }
  } 
  );

  $('#signupPhoneNumber').focus();
  loader.off();
  
}





btn.disabled = true;
btn.innerText = 'PLEASE WAIT...';

var url = url;
var fname = $('#fname').val();
var lname = $('#lname').val();
var email = $('#signupEmail').val();

var newphone = 0;
var cuntryCode =  $("#signupModal .iti__selected-flag").attr('title');
cuntryCode =   (cuntryCode.split(':')[1]).trim();
var value = phone.replace(cuntryCode, ''); 
newphone =  value; 

$.ajax({
  url: url,
  type: "POST",
  dataType: "json",
  data : {'fname':fname,'lname':lname,'email' : email,'phone':newphone, 'countryCode': cuntryCode},
  success: function(data) 
  {

   loader.off();

   console.log(data);

   var loginbtn = document.getElementById('loginBtn');
   var emailotpntn = document.getElementById('emailotpntn');

   const obj = JSON.parse(data);
   if (obj.message == '') {

    loginbtn.disabled = false;
    loginbtn.innerText = 'LOGIN';

    emailotpntn.disabled = false;
    emailotpntn.innerText = 'LOGIN';


    showToast(
    { 
      eleWrapper: '#login-success-flashmsg',
      msg: data,
      theme: 'success',
      closeButton: false,
      autoClose: true,
      afterShow: function(){
        console.log('After show function');
      },
      afterClose: function(){
        console.log('After close function');
      }
    } 
    );


    if((location.href.match(/([^\/]*)\/*$/)[1]).indexOf('Payonline') != -1){
      openBoxlog('login');
    }
    else
    {
      $('.signupBtnClose').click();
      $("#signupModal").modal("hide");
      $("#loginModal").modal("show");
    }



  }else{



    if (obj.message == 'success') {
      loginbtn.disabled = false;
      loginbtn.innerText = 'LOGIN';

      emailotpntn.disabled = false;
      emailotpntn.innerText = 'LOGIN';


      showToast(
      { 
        eleWrapper: '#login-success-flashmsg',
        msg: obj.message,
        theme: 'success',
        closeButton: false,
        autoClose: true,
        afterShow: function(){
          console.log('After show function');
        },
        afterClose: function(){
          console.log('After close function');
        }
      } 
      );


      if((location.href.match(/([^\/]*)\/*$/)[1]).indexOf('Payonline') != -1){
        openBoxlog('login');
      }
      else
      {
        $('.signupBtnClose').click();
        $("#signupModal").modal("hide");
        $("#loginModal").modal("show");
      }

      btn.disabled = false;
      btn.innerText = 'SIGN UP';
    }else{
      loginbtn.disabled = false;
      loginbtn.innerText = 'LOGIN';

      emailotpntn.disabled = false;
      emailotpntn.innerText = 'LOGIN';


      showToast(
      { 
        eleWrapper: '#signup-error-flashmsg',
        msg: obj.message,
        theme: 'error',
        closeButton: false,
        autoClose: true,
        afterShow: function(){
          console.log('After show function');
        },
        afterClose: function(){
          console.log('After close function');
        }
      } 
      );

      btn.disabled = false;
      btn.innerText = 'SIGN UP';
    }
  }
}    




});


return false;
}

</script>


<!-- Mobile OTP AUTH BY FIREBASE -->
<!-- Add the latest firebase dependecies from CDN -->
<script src="https://www.gstatic.com/firebasejs/6.3.3/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/6.3.3/firebase-auth.js"></script>


<script>
  var firebaseConfig = {
    apiKey: "AIzaSyAcxU5AvD6qtVG76xDCXaf2vzuPIX_DwMw",
    authDomain: "login-7aff9.firebaseapp.com",
    projectId: "login-7aff9",
    storageBucket: "login-7aff9.appspot.com",
    messagingSenderId: "981533541532",
    appId: "1:981533541532:web:9846cc5487bb8fead35959",
    measurementId: "G-57D5BT4B2F"
  };


  firebase.initializeApp(firebaseConfig);
  window.recaptchaVerifier = new firebase.auth.RecaptchaVerifier(
    "recaptcha-container",
    {
      size: "normal",
      callback: function(response) {
        submitPhoneNumberAuth();
      }
    }
    );

  function submitPhoneNumberAuth() {
   $("#AdministratorTab").addClass('disabled');
   $("#devoteeTab").addClass('disabled');

   var phoneNumber = document.getElementById("loginPhoneNumber").value;
   var appVerifier = window.recaptchaVerifier;
   firebase
   .auth()
   .signInWithPhoneNumber(phoneNumber, appVerifier)
   .then(function(confirmationResult) {
    window.confirmationResult = confirmationResult;

    if(confirmationResult.verificationId)
    {
        // $("#mobiletoggle").toggle();
      $("#mobiletoggle").css('display','inline-flex');
      $('#mobileotp').focus();
      $("#AdministratorTab").addClass('disabled');
      $("#devoteeTab").addClass('disabled');

      showToast(
      { 
        eleWrapper: '.otpsendmsg_number',
        msg: 'OTP has been sent on this mobile number.',
        theme: 'success',
        closeButton: false,
        autoClose: true,
        afterShow: function(){
          console.log('After show function');
        },
        afterClose: function(){
          console.log('After close function');
        }
      } 
      );

      // $(".otpsendmsg_number").html("OTP has been sent on this mobile number.");
      // setTimeout(function(){$(".otpsendmsg_number").text('');},6000);
      $("#recaptcha-container").remove();
    }


  })
   .catch(function(error) {
    console.log(error);
  });
 }

 function submitPhoneNumberAuthCode() {
  var btn = document.getElementById('mobileotpverifybtn');
  btn.disabled =true;
  btn.innerText = 'VERIFYING';


  var code = document.getElementById("mobileotp").value;
  if (code == "") {
   btn.disabled =false;
   btn.innerText = 'VERIFY';
   $(".otpsendmsg_number").html("");


   showToast(
   { 
    eleWrapper: '.otpsendmsg_number_error',
    msg: 'Please enter 6 digit OTP!',
    theme: 'warning',
    closeButton: false,
    autoClose: true,
    afterShow: function(){
      console.log('After show function');
    },
    afterClose: function(){
      console.log('After close function');
    }
  } 
  );


   // $(".otpsendmsg_number_error").html("Please enter 6 digit OTP!");
   // setTimeout(function(){$(".otpsendmsg_number_error").text('');},6000);

 }else{
  confirmationResult
  .confirm(code)
  .then(function(result) {
    var user = result.user;
      // console.log(user);

    PhoneLogin('<?=base_url('signin');?>');


      // console.log("USER LOGGED IN");

  })
  .catch(function(error) {
    alert('Invalid OTP/OTP Expired!!')
    var btn = document.getElementById('mobileotpverifybtn');
    btn.disabled =false;
    btn.innerText = 'VERIFY';
      // console.log(error);
  });

  firebase.auth().onAuthStateChanged(function(user) {
  });
}
}


</script>


<!-- Live Client Id -->

<?php 


if ($paymentSeverOn == 1 && $paymentSetting == 'PAYPAL') { ?> 
  <?php $paypalLiveClientId  = getclientInfoById()['data'][0]['paypalClientId']; ?>

  <script src="https://www.paypal.com/sdk/js?client-id=<?=$paypalLiveClientId?>&enable-funding=venmo&intent=capture" data-sdk-integration-source="integrationbuilder"></script>



  <script>



    const paypalButtonsComponent = paypal.Buttons({
      style: {
        shape: 'rect',
        color: 'gold',
        layout: 'vertical',
        label: 'paypal',

      },
// set up the transaction
      createOrder: (data, actions) => {



        if($("#DonateToTemple").val() == 'DONATIONS'){ 
          amt = $("#DonationAmt").val(); 
        }else{
         amt = $("#serviceAmt").val()
       }


       const createOrderPayload = {
        purchase_units: [
        {
          amount: {

            value:amt
          }
        }
        ]
      };





      return actions.order.create(createOrderPayload);
    },
   // finalize the transaction


    onApprove: (data, actions) => {
      const captureOrderHandler = (details) => {

       loader.on();
       const payerName = details.payer.name.given_name;
       var payer_firstname = details.payer.name.given_name;
       var payer_lastname = details.payer.name.surname;
       var orderid = details.id;
       var status = details.status;
       var email = details.payer.email_address;
       var transaction_id = details.purchase_units[0].payments.captures[0].id;
       var serviceAmount = details.purchase_units[0].amount.value;
       if ($('#fullPackage').val() == 'true') {
        var fullPackage = $('#fullPackage').val();
      }

      if($("#DonateToTemple").val() == 'DONATIONS'){ 
        var serviceName = $("#DonationName").text();
        var service_Id = $("#DonationId").val();
        var serviceCategoryTypes = $("#DonationCategoryTypes").val();
        var serviceTypes = $("#DonationTypes").val();
        var dayTypes = $("#DonationdayTypes").val();
        var startDate = $("#DonationstartDate").val();
        var startTime = $("#DonationstartTime").val();
      }
      else
      {
        var serviceName = $("#serviceName").text();
        var service_Id = $("#serviceId").val();
        var serviceCategoryTypes = $("#serviceCategoryTypes").val();
        var serviceTypes = $("#serviceTypes").val();
        var dayTypes = $("#dayTypes").val();



        var startDate = $("#serviceStartDate").val();
        var startTime = $("#timepicker").val();


        if ($("#Address").val() != '') {
          var Address = $("#Address").val();
        }else{
          var Address = "";
        }

      }





      $.ajax({
        url: "<?=base_url('add-service-cart');?>",
        type: "POST",
        dataType: "json",
        data : {
          'fname' : payer_firstname, 
          'lname': payer_lastname, 
          'fullPackage': fullPackage, 
          'orderid': orderid, 
          'status': status, 
          'email': email, 
          'services_Id': service_Id,
          'serviceAmount':serviceAmount, 
          'serviceName': serviceName,
          'transaction_id': transaction_id,
          'serviceCategoryTypes': serviceCategoryTypes,
          'serviceTypes': serviceTypes,
          'dayTypes': dayTypes,
          'startDate': startDate,
          'startTime': startTime,
          'qty': 1,
          'serviceAddress':Address
        },
        success: function(response) 
        {
         loader.off();
         console.log(response);

         if (response.statusCode == 1) {
           // console.log(response);
           $('.PaymentClosebtn').click();
           $("#paymentModal").modal("hide");


           if (serviceCategoryTypes == 'DONATIONS') {
            $("#DonateToTemplePaymentModal").modal("hide");

            swal({
              html: true,
              title: "Donation is processed successfully!",
              text: "<span style='font-weight: 600;margin:5px;padding:5px'>Token No:</span> "+response.data[0].invoiceNo,
              type: "success",
              confirmButtonText: 'OK',
              confirmButtonColor: '#008080',
                // timer:5000,
            },

            function(){
             if((location.href.match(/([^\/]*)\/*$/)[1]).indexOf('Payonline') != -1){
              window.location.href="<?=base_url('logout');?>"
            }
            else
            {
              window.location.reload(); 
            }

          });
          }else{
            swal({
              html: true,
              title: "Service Booking Confirmed!",
              text: "<span style='font-weight: 600;margin:5px;padding:5px'>Order No:</span> "+response.data[0].invoiceNo,
              type: "success",
              confirmButtonText: 'OK',
              confirmButtonColor: '#008080',
                // timer:5000,
            },

            function(){
             if((location.href.match(/([^\/]*)\/*$/)[1]).indexOf('Payonline') != -1){
              window.location.href="<?=base_url('logout');?>"
            }
            else
            {
              window.location.reload(); 
            }

          });
          }


        }else{
         $('.PaymentClosebtn').click();
         $("#paymentModal").modal("hide");
         swal({
          html: true,
          title: "Failed!",
          text: "<span>Transaction Failed!<span><br><span style='font-weight: 600;margin:5px;padding:5px'>Token No:</span> "+response.data[0].invoiceNo,
          type: "error",
          confirmButtonText: 'OK',
          confirmButtonColor: '#008080',
              // timer:5000,
        },
        function(){
          window.location.reload(); 
        });

       }

     }             
   });


      // Ajax Request End

    };

    return actions.order.capture().then(captureOrderHandler);
  },


  onError: (err) => {
    alert('Transaction Failed');

  }
});

paypalButtonsComponent
.render("#paypal-button-container")
.catch((err) => {
  console.log('PayPal Buttons failed to render');
});
</script>
<?php } ?>


<script>
  function nonEditCuntryCode(el)
  {
   var cuntryCode =  $("#loginModal .iti__selected-flag").attr('title');
// alert(cuntryCode);
   cuntryCode =   (cuntryCode.split(':')[1]).trim();

   if(el.value.length > cuntryCode.length)
   {
        var value = el.value.replace(cuntryCode, '');; //replace all $ with empty string
        el.value = cuntryCode + value;     
      }else
      {
        el.value = cuntryCode;     
      }
    }



    function nonEditCuntryCode1(el)
    {
     var cuntryCode =  $("#signupModal .iti__selected-flag").attr('title');
     cuntryCode =   (cuntryCode.split(':')[1]).trim();
     if(el.value.length > cuntryCode.length)
     {
        var value = el.value.replace(cuntryCode, '');; //replace all $ with empty string
        el.value = cuntryCode + value;     
      }else
      {
        el.value = cuntryCode;     
      }
    }


    function checkValue(str, max) {
      if (str.charAt(0) !== '0' || str == '00') {
        var num = parseInt(str);
        if (isNaN(num) || num <= 0 || num > max) num = 1;
        str = num > parseInt(max.toString().charAt(0)) && num.toString().length == 1 ? '0' + num : num.toString();
      };
      return str;
    };

    function date_reformat_mm(date) {
      date.addEventListener('input', function(e) {
        this.type = 'text';
        var input = this.value;
        if (/\D\/$/.test(input)) input = input.substr(0, input.length - 3);
        var values = input.split('/').map(function(v) {
          return v.replace(/\D/g, '')
        });
        if (values[0]) values[0] = checkValue(values[0], 12);
        if (values[1]) values[1] = checkValue(values[1], 31);
        var output = values.map(function(v, i) {
          return v.length == 2 && i < 2 ? v + '/' : v;
        });
        this.value = output.join('').substr(0, 14);
      });

    }



    function openBoxlog(type)
    {
      if(type=='signup')
      {
       $(".login-box-msg h4").text('SIGN UP');
       $("#loginModal").hide();
       $(".inLogin").hide();
       $("#signupModal").show();
       $(".inSignup").show();

     }else if(type=='login')
     {
      $(".login-box-msg h4").text('LOGIN IN');
      $("#signupModal").hide();
      $(".inSignup").hide();
      $("#loginModal").show();
      $(".inLogin").show();
    }
  }

/*----------------------------------*/

/*==================================================*/
/*==================Script For Currency Input (.00)=================*/
/*==================================================*/
  $(document).ready(function() {
    $.fn.currencyInput = function() {
      this.each(function() {
        var wrapper = $("<div class='currency-input' />");
        $(this).wrap(wrapper);
      // $(this).before("<span class='currency-symbol' style='padding:7px 13px'>$</span>");
        $(this).change(function() {
          var min = parseFloat($(this).attr("min"));
          var max = parseFloat($(this).attr("max"));
          var value = this.valueAsNumber;
          if(value < min)
            value = min;
          else if(value > max)
            value = max;
          $(this).val(value.toFixed(2)); 
        });
      });
    };



    $('input.currency').currencyInput();
  });



  function loginBy(type) { 


    if(type=='email'){ 
      var cuntryCode =  $("#loginModal .iti__selected-flag").attr('title');
      cuntryCode     =   (cuntryCode.split(':')[1]).trim();
      $("#loginPhoneNumber").val(cuntryCode);
    }else{
     $("#loginEmail").val(''); 
   } 



 }

 // $(".modalClbtn").click(function(){window.location.reload();});



 $(document).ready(function() {
  $('.eye-toggle').on('click', function() {
    var eyeIcon = $(this).find('i');
    if ($(this).attr("aria-expanded") == "true") {
      eyeIcon.removeClass('fa-eye-slash').addClass('fa-eye');
    } else if($(this).attr("aria-expanded") == "false") {
      eyeIcon.removeClass('fa-eye').addClass('fa-eye-slash');
    }
  });
});


 $(".amount-input").on({
  keyup: function() {
    var inputId = $(this).attr('id');
    var id = inputId.replace('anyAmtEvent', '');
    formatCurrency($(this), id);
  },
  blur: function() { 
    var inputId = $(this).attr('id');
    var id = inputId.replace('anyAmtEvent', '');
    formatCurrency($(this), id, "blur");
  }
});

 $(".amount-input-donations").on({
  keyup: function() {
    var inputId = $(this).attr('id');
    var id = inputId.replace('anyAmtDonation', '');
    formatCurrency($(this), id);
  },
  blur: function() { 
    var inputId = $(this).attr('id');
    var id = inputId.replace('anyAmtDonation', '');
    formatCurrency($(this), id, "blur");
  }
});



 function formatCurrency(input, id, blur) {
  var input_val = input.val();

  if (input_val === "") { return; }

  var original_len = input_val.length;
  var caret_pos = input.prop("selectionStart");

  if (input_val.indexOf(".") >= 0) {
    var decimal_pos = input_val.indexOf(".");
    var left_side = input_val.substring(0, decimal_pos);
    var right_side = input_val.substring(decimal_pos);

    left_side = left_side.replace(/\D/g, "");
    right_side = right_side.replace(/\D/g, "");

    if (blur === "blur") {
      right_side += "00";
    }

    right_side = right_side.substring(0, 2);

    input_val = left_side + "." + right_side;
  } else {
    input_val = input_val.replace(/\D/g, "");

    if (blur === "blur") {
      input_val += ".00";
    }
  }

  input.val(input_val);

  $("#checkbox_" + id).attr('data-price', input_val);

  var updated_len = input_val.length;
  caret_pos = updated_len - original_len + caret_pos;
  input[0].setSelectionRange(caret_pos, caret_pos);
}







function  ViewCartMobile(page){
  if ( $(".cart-count").text() > 0) {
    window.location.href = "<?=base_url()?>"+page+"/ViewCart";

  }else{
    swal({
      title: "Your cart is empty!",
      text: "Please add some items to your cart.",
      icon: "warning",
      confirmButtonText: 'OK',
      confirmButtonColor: '#005D4B',
    });


  }

}


</script>

<script type="text/javascript" src="<?=base_url('assets/js/intlTelInput2.js?1706723638591');?>"></script>

<script type="text/javascript">
  var baseUrl = "<?=base_url();?>";


  var countryData = window.intlTelInputGlobals.getCountryData(),
  login_input          = document.querySelector("#loginPhoneNumber"),
  signup_input = document.querySelector("#signupPhoneNumber"),
  addressDropdown = document.querySelector("#address-country");

  window.intlTelInput(login_input, {
    utilsScript: baseUrl + "assets/js/utils.js?1706723638591",
  });

  window.intlTelInput(signup_input, {
    utilsScript: baseUrl + "assets/js/utils.js?1706723638591",
  });


  for (var i = 0; i < countryData.length; i++) {
    var country = countryData[i];
    var optionNode = document.createElement("option");
    optionNode.value = country.iso2;
    var textNode = document.createTextNode(country.name);
    optionNode.appendChild(textNode);
    addressDropdown.appendChild(optionNode);
  }

  addressDropdown.value = iti.getSelectedCountryData().iso2;

// listen to the address dropdown for changes
  addressDropdown.addEventListener('change', function() {
    iti.setCountry(this.value);
  });


</script>

<!-- <script type="text/javascript" src="<?=base_url('assets/js/country_code.js');?>"></script>  -->
<!-- <script type="text/javascript" src="<?=base_url('assets/js/country_code2.js');?>"></script>  -->
<script type="text/javascript" src="<?=base_url('assets/js/time-picker.js');?>"></script> 

</body>

</html>