﻿/*
 * This function is designed to make sure that a popup window (such as JQModal) won't extend outside the height of the users browser.
 */
function SafePositionPopup(strPopupID) 
{
    var intWinHeight = $(window).height();
    var intPopupTop = xTop(el(strPopupID));
    var intPopupHeight = $('#' + strPopupID).height();

    if (intWinHeight - intPopupTop < intPopupHeight) {
        if (intPopupHeight - (intWinHeight - intPopupTop) < intPopupTop) {
            var intNewTop = intPopupTop - (intPopupHeight - (intWinHeight - intPopupTop)) - ((intWinHeight - intPopupHeight) / 2);
            $('#' + strPopupID).css('top', intNewTop + 'px');
            $('#' + strPopupID).css('position', 'fixed');
        }
        else {
            $('#' + strPopupID).css('top', '40px');
            $('#' + strPopupID).css('position', 'absolute');
        }
    }
    else if($('#' + strPopupID).css('position') == 'absolute') {
        $('#' + strPopupID).css('top', '150px');
        $('#' + strPopupID).css('position', 'fixed');
        SafePositionPopup(strPopupID);
    }
}