  



$(function () {
  $("#searchBlog").submit(function (event) {
    var text = $("#searchBlog input[name=text]").val();
    var site = $("#searchBlog input[name=site]").val();
    var action = $("#searchBlog ").attr("action");
    var searchUrl =
      window.location.protocol +
      "//" +
      window.location.host +
      "/" +
      action +
      "?text=" +
      text +
      "&site=" +
      site;
    window.location.href = searchUrl;
    event.preventDefault();
  });
});

$(document).ready(function () {

  $(".EnlargeButton").click(function (event) {
    event.preventDefault();
    $("#chartModal").modal("show", event);
  });

  $("body").on("click",".EnlargeButton",function (event) {
    event.preventDefault();
    $("#chartModal").modal("show", event);
  });


  $("#chartModal").on("show.bs.modal", function (event) {
    var img = $(event.relatedTarget.target).closest(".blogImage").find(".blogImagePopup")
    if (img.length == 0)
    {
      img = $(event.relatedTarget.currentTarget).parent().parent().find("img")
    }
    // Extract info from img attributes
    var imgSrc = img.attr("src");
    var imgAlt = img.attr("alt");
    var modal = $(this);
    modal.find(".modal-title").text(imgAlt);
    modal.find(".modal-body img").attr("src", imgSrc);
    modal.find(".modal-body img").attr("alt", imgAlt);
  });
});

$(function() {
	const isNumericInput = (event) => {
		const key = event.keyCode;
		return ((key >= 48 && key <= 57) || // Allow number line
			(key >= 96 && key <= 105) // Allow number pad
		);
	};

	const isModifierKey = (event) => {
		const key = event.keyCode;
		return (event.shiftKey === true || key === 35 || key === 36) || // Allow Shift, Home, End
			(key === 8 || key === 9 || key === 13 || key === 46) || // Allow Backspace, Tab, Enter, Delete
			(key > 36 && key < 41) || // Allow left, up, right, down
			(
				// Allow Ctrl/Command + A,C,V,X,Z
				(event.ctrlKey === true || event.metaKey === true) &&
				(key === 65 || key === 67 || key === 86 || key === 88 || key === 90)
			)
	};

	const enforceFormat = (event) => {
		// Input must be of a valid number format or a modifier key, and not longer than ten digits
		if(!isNumericInput(event) && !isModifierKey(event)){
			event.preventDefault();
		}
	};

	const formatToPhone = (event) => {
		if(isModifierKey(event)) {return;}

		const target = event.target;
		const input = event.target.value.replace(/\D/g,'').substring(0,10); // First ten digits of input only
		const areaCode = input.substring(0,3);
		const middle = input.substring(3,6);
		const last = input.substring(6,10);

		if(input.length > 6){target.value = `${areaCode}-${middle}-${last}`;}
		else if(input.length > 3){target.value = `${areaCode}-${middle}`;}
		else if(input.length > 0){target.value = `${areaCode}`;}
	};

	let inputElements = document.querySelectorAll('.phone-number-formatting');

	inputElements.forEach((item) => {
		item.addEventListener('keydown',enforceFormat);
		item.addEventListener('keyup',formatToPhone);
	});
});
 