<script type="text/javascript">
  function validateFileType(){
    var fileName = document.getElementById("p_image").value;
    var idxDot = fileName.lastIndexOf(".") + 1;
    var extFile = fileName.substr(idxDot, fileName.length).toLowerCase();
    // alert(extFile);
    if (extFile=="jpg" || extFile=="jpeg" || extFile=="png')}}"){
        //TO DO
    }else{
        document.getElementById("p_image").value = null;
        alert("Only jpg/jpeg and png files are allowed!");
        
    }   
  }


  $('#select_box').change(function () {
    var select=$(this).find(':selected').val();        
    $(".hide").hide();
    $('#' + select).show();

  }).change();

  $("#p_image").change(function() {
    readURLphoto(this);
  });
  function readURLphoto(input) {
    if (input.files && input.files[0]) {
      var reader = new FileReader();
      
      reader.onload = function(e) {
        $('#s_photo').attr('src', e.target.result);

        $("#s_photo").css("display", "block");
      }
      reader.readAsDataURL(input.files[0]); // convert to base64 string
    }
  }
</script>

<script type="text/javascript">

 function readURLvideo(input) {

  if (input.files && input.files[0]) {
    var reader = new FileReader();

    reader.onload = function(e) {
      $('#videoPreview').attr('src', e.target.result);

      $("#videoPreview").css("display", "block");
    }

    reader.readAsDataURL(input.files[0]); // convert to base64 string
  }
}

  $("#p_video").change(function() {

    $('#savebtn').attr('disabled',true);
    var video = document.getElementById("videoPreview");
    readURLvideo(this);

    video.addEventListener("loadedmetadata", function(e) {

        var videoWidth = video.videoWidth;
        var videoHeight = video.videoHeight;

        const maxWidth1 = 3840;
        const maxHeight1 = 2160;
        const maxWidth = 3850;
        const maxHeight = 2160;

        if (
            videoWidth >= maxWidth1 &&
            videoHeight >= maxHeight1 &&
            videoWidth <= maxWidth &&
            videoHeight <= maxHeight
        ) {
            $('#videoValidfalse').html("");
            $('#videoValidtrue').html("Video Dimensions Valid");
            $('#videoContainer').show();
            $('#savebtn').attr('disabled',false);
        } else {
            $('#videoValidtrue').html("");
            $('#videoValidfalse').html("Video Dimensions Invalid");
            $('#p_video').val("");
            $('#videoPreview').attr("src", "");
            $('#videoContainer').hide();
            $('#savebtn').attr('disabled',false);
        }
    }, false);
});


function updateSpanDimensions() {
  var selectedValue = document.getElementById("pageSelect").value;
  var spanElements = document.querySelectorAll(".pageSpan");
  spanElements.forEach(function(spanElement) {
      spanElement.style.display = "none";
  });
  var selectedSpan = document.getElementById(selectedValue + "Span");
  if (selectedSpan) {
      selectedSpan.style.display = "block";
  }

  var selectedPage = $("#pageSelect").val();
  if (selectedPage === "home") {
      $("#select_box option[value='video']").show();
  } else {
      $("#select_box option[value='video']").hide();
  }            
}
</script>

<link href="https://cdn.jsdelivr.net/npm/summernote@0.8.18/dist/summernote-bs4.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/summernote@0.8.18/dist/summernote-bs4.min.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
      $('.summernote').summernote();
    });
</script>


