﻿function isNumberKey(evt) {
  var charCode = (evt.which) ? evt.which : event.keyCode
  if (charCode > 31 && (charCode < 48 || charCode > 57))
    return false;

  return true;
}

function isNumberKey_dp(evt) {
  var charCode = (evt.which) ? evt.which : event.keyCode


  if (String.fromCharCode(charCode) == ".")
    return true;

  if (charCode > 31 && (charCode < 48 || charCode > 57))
    return false;

  return true;
}

// Malta js functions
// Generate Pop-up Div
function leavingWebsite(url, target) {
  if (!document.getElementById("popupDiv")) {
    window.scrollTo(0, 0);

    var strInnerHTML = "<table summary=\"popupHolder\">";
    strInnerHTML += "<tr>";
    strInnerHTML += "<td colspan=\"2\"><strong>NOTICE: You are currently leaving the Secure Government website for a 3rd Party one.</strong></td>";
    strInnerHTML += "</tr>";
    strInnerHTML += "<tr>";
    strInnerHTML += "<td><input type=\"button\" value=\"Continue\" onclick=\"leavingWebsite_Continue('" + url + "','" + target + "')\"/></td>";
    strInnerHTML += "<td><input type=\"button\" value=\"Cancel\" onclick=\"leavingWebsite_Cancel()\"/></td>";
    strInnerHTML += "</tr>";
    strInnerHTML += "</table>";

    var objPopupDiv = document.createElement("div");
    objPopupDiv.setAttribute("id", "popupDiv");
    objPopupDiv.style.width = "350px";
    objPopupDiv.style.height = "130px";
    objPopupDiv.innerHTML = strInnerHTML;
    document.body.appendChild(objPopupDiv);
    centerPopup();
    window.onresize = function () {
      centerPopup();
    }
  }
}

//Cancel Functionality
function leavingWebsite_Cancel() {
  objPopupDiv = document.getElementById("popupDiv");
  document.body.removeChild(objPopupDiv);
  window.onresize = function () {
    return false;
  }
}

//Continue Functionality
function leavingWebsite_Continue(url, target) {
  target = target.toLowerCase();
  if (target == "blank") {
    window.open(url);
  } else {
    eval(target + ".location='" + url + "'");
  }
  leavingWebsite_Cancel();
}

//Center Pop-up Div
function centerPopup() {
  objPopupDiv = document.getElementById("popupDiv");
  intWidth = parseInt(document.documentElement.clientWidth) - parseInt(objPopupDiv.style.width);
  intWidth = intWidth / 2;
  objPopupDiv.style.left = intWidth + "px";

  intHeight = parseInt(document.documentElement.clientHeight) - parseInt(objPopupDiv.style.height);
  intHeight = intHeight / 2;
  objPopupDiv.style.top = intHeight + "px";
}
 
