﻿
//Calculates the width and height of the screen to show the modal.
function calculateViewPort() {
    // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight

    if (typeof window.innerWidth != 'undefined') {
        viewportwidth = window.innerWidth,
      viewportheight = window.innerHeight
    }

    // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)

    else if (typeof document.documentElement != 'undefined'
     && typeof document.documentElement.clientWidth !=
     'undefined' && document.documentElement.clientWidth != 0) {
        viewportwidth = document.documentElement.clientWidth,
       viewportheight = document.documentElement.clientHeight
    }

    // older versions of IE

    else {
        viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
       viewportheight = document.getElementsByTagName('body')[0].clientHeight
    }
}


function showModalBackground() {
    calculateViewPort();
    $('#modalBackground').css('width', viewportwidth + 'px');
    $('#modalBackground').css('height', viewportheight + 'px');
    $('#modalBackground').show();
}

function sendModalToBack(modal) {
    // number conversion for z-index to avoid possible concat error
    var zindex = Math.abs($('#modalBackground').css('z-index'));

    $(modal).css('z-index', zindex - 10);
    return false;
}

function bringModalToFront(modal) {
    // number conversion for z-index to avoid possible concat error
    var zindex = Math.abs($('#modalBackground').css('z-index'));

    document.getElementById(modal).style.zIndex = zindex + 1000;
    return false;
}

function closeModal(modal) {   
    sendModalToBack(modal);
    $(modal).hide();
    $('#modalBackground').hide();
    return false;
}
