﻿function isCharKey(evt) {
    var charCode = (evt.which) ? evt.which : event.keyCode
    if (charCode > 31 && ((charCode >= 48 && charCode <= 57) || charCode == 46))
        return true;
    else
        return false;
}

var window_i = "";
function ShowModal(dwindow, dbackground) {
    document.getElementById(dwindow).style.display = 'block';
    document.getElementById(dbackground).style.display = 'block';
    window_i = dwindow;
    // call once to center everything
    OnWindowResize();
    if (window.attachEvent)
        window.attachEvent('onresize', OnWindowResize);
    else if (window.addEventListener)
        window.addEventListener('resize', OnWindowResize, false);
    else
        window.onresize = OnWindowResize;

    // we won't bother with using javascript in CSS to take care
    //   keeping the window centered
    if (document.all)
        document.documentElement.onscroll = OnWindowResize;
}

function OnWindowResize() {
    // we only need to move the dialog based on scroll position if
    //   we're using a browser that doesn't support position: fixed, like < IE 7
    var left = window.XMLHttpRequest == null ? document.documentElement.scrollLeft : 0;
    var top = window.XMLHttpRequest == null ? document.documentElement.scrollTop : 0;
    var div = document.getElementById(window_i);

    div.style.left = Math.max((left + (GetWindowWidth() - div.offsetWidth) / 2), 0) + 'px';
    div.style.top = Math.max((top + (GetWindowHeight() - div.offsetHeight) / 2), 0) + 'px';
}

function CloseModal(dwindow, dbackground) {
    document.getElementById(dwindow).style.display = 'none';
    document.getElementById(dbackground).style.display = 'none';

    if (window.detachEvent)
        window.detachEvent('onresize', OnWindowResize);
    else if (window.removeEventListener)
        window.removeEventListener('resize', OnWindowResize, false);
    else
        window.onresize = null;
}
function GetWindowWidth() {
    var width =
		document.documentElement && document.documentElement.clientWidth ||
		document.body && document.body.clientWidth ||
		document.body && document.body.parentNode && document.body.parentNode.clientWidth ||
		0;

    return width;
}

function GetWindowHeight() {
    var height =
		document.documentElement && document.documentElement.clientHeight ||
		document.body && document.body.clientHeight ||
  		document.body && document.body.parentNode && document.body.parentNode.clientHeight ||
  		0;

    return height;
}
