/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

function openDialog( type , html ){
    $("#alert_body").html( html );

    $("#overlay").css('display','inline');
    centerDialog();
}

function closeDialog( ){
    $("#overlay").css('display','none');
}

function getWindowHeight() {
    var windowHeight = 0;
    if (typeof(window.innerHeight) == 'number') {
        windowHeight = window.innerHeight;
    }
    else {
        if (document.documentElement && document.documentElement.clientHeight) {
            windowHeight = document.documentElement.clientHeight;
        }
        else {
            if (document.body && document.body.clientHeight) {
                windowHeight = document.body.clientHeight;
            }
        }
    }
    return windowHeight;
}
function centerDialog() {
    if (document.getElementById) {
        var windowHeight = getWindowHeight();
        
        if (windowHeight > 0) {
            var contentElement = document.getElementById('alert');
            var contentHeight = contentElement.offsetHeight;
            
            if (windowHeight - contentHeight > 0) {
                contentElement.style.position = 'relative';

               
                var pos = (scrollTop() + (windowHeight / 2) - (contentHeight / 2));                
                contentElement.style.top = pos+'px';
               
            }
            else {
                contentElement.style.position = 'static';
            }
        }
    }
}

function scrollTop(){
    if(window.pageYOffset){
        return window.pageYOffset;
    }
    else {
        return  Math.max(document.body.scrollTop,document.documentElement.scrollTop);
    }
}

window.onscroll = function() {
    centerDialog();
}
window.onresize = function() {
    centerDialog();
}


