﻿/// <reference path="jquery-1.3.2-vsdoc.js" />

function showOverlay() {
    //jQuery(document).ready(function() {
    var divTag = document.createElement("div");
    divTag.id = "overlayDiv";
    divTag.className = "overlayDiv";

    pageWidth = jQuery(document).width();
    pageHeight = jQuery(document).height();



    divTag.style.width = pageWidth + 'px';
    divTag.style.height = pageHeight + 'px';
    divTag.innerHTML = '&nbsp';
   // document.body.prependChild(divTag);

    $('.overlayDiv').width(pageWidth + 'px');
    $('.overlayDiv').height(pageHeight + 'px');
    $('.overlayDiv').show();
    //});
}

function hideOverlay() {
    $('.overlayDiv').hide();
}

function hideOverlayContent() {
    $('.overlayContent').hide();
}

function centerOverlayContent(idOverlayContent) {
    document.getElementById(idOverlayContent).style.display = "block";
    var div = document.getElementById(idOverlayContent);
    var w = parseInt(document.getElementById(idOverlayContent).offsetWidth);
    var h = parseInt(document.getElementById(idOverlayContent).offsetHeight);

    pageWidth = jQuery(window).width();
    pageHeight = jQuery(window).height();

    document.getElementById(idOverlayContent).style.top = (pageHeight - h) / 2 + "px";
    document.getElementById(idOverlayContent).style.left = (pageWidth - w) / 2 + "px";
}

function centerFixedOverlayContent(idOverlayContent, top) {
   	document.getElementById(idOverlayContent).style.display = "block";
   	var div = document.getElementById(idOverlayContent);
   	var w = parseInt(document.getElementById(idOverlayContent).offsetWidth);
   	var h = parseInt(document.getElementById(idOverlayContent).offsetHeight);

   	pageWidth = jQuery(window).width();
   	pageHeight = jQuery(window).height();

   	document.getElementById(idOverlayContent).style.top = top + "px";
   	document.getElementById(idOverlayContent).style.left = (pageWidth - w) / 2 + "px";
}

function showModalInline(clientId) {
    hideOverlay();
    document.getElementById(clientId).style.display = "block";
    showOverlay();
}

function showModalCentered(idOverlayContent) {
    //jQuery(document).ready(function() {
    hideOverlay();
    centerOverlayContent(idOverlayContent);
    showOverlay();
    //});
}

function showFixedModalCentered(idOverlayContent, top) {
	//jQuery(document).ready(function() {
	hideOverlay();
	centerFixedOverlayContent(idOverlayContent, top);
	showOverlay();
	//});
}

function hideModal() {
    //jQuery(document).ready(function() {
    hideOverlayContent();
    hideOverlay();
    //});
}

// PANEL LOADING ANIMATION
function onUpdating(divId) {
    if (divId != '' && divId != undefined) {
        $('#' + divId).addClass("Opacity");

        // make it visible
        $("#AjaxProgressPopUp").show();

        //  center of visible part of the gridview
        var x = $('#' + divId).offset().left + Math.round($('#' + divId).width() / 2) - Math.round($("#AjaxProgressPopUp").width() / 2);
        var y = $('#' + divId).offset().top + Math.round($('#' + divId).height() / 2) - Math.round($("#AjaxProgressPopUp").height() / 2);

        $("#LoadingOverlay").width($('#' + divId).width());
        $("#LoadingOverlay").height($('#' + divId).height());
        $("#LoadingOverlay").css({ top: $('#' + divId).offset().top + "px", left: $('#' + divId).offset().left + "px", display: "block" });

        var visibleHeight = 0;
        if ($(window).scrollTop() < $('#' + divId).offset().top) {
            visibleHeight = $(window).height() - $('#' + divId).offset().top + $(window).scrollTop();
            if (($('#' + divId).offset().top + $('#' + divId).height()) < ($(window).scrollTop() + $(window).height())) {
                visibleHeight = visibleHeight - ($(window).scrollTop() + $(window).height() - ($('#' + divId).offset().top + $('#' + divId).height()));
            }
            y = $('#' + divId).offset().top + Math.round(visibleHeight / 2);
        }
        else {
            if (($(window).scrollTop() + $(window).height()) > ($('#' + divId).offset().top + $('#' + divId).height())) {
                visibleHeight = $('#' + divId).offset().top + $('#' + divId).height() - $(window).scrollTop();
                y = $(window).scrollTop() + Math.round(visibleHeight / 2);
            }
            else {
                visibleHeight = $(window).height();
                y = $(window).scrollTop() + Math.round(visibleHeight / 2);
            }
        }

        //	set the progress element to this position
        $("#AjaxProgressPopUp").css({ top: y + "px", left: x + "px", display: "block" });
    }
}

function onUpdated(divId) {
    // get the update progress div

    if (divId != '' && divId != undefined) {
        $('#' + divId).removeClass("Opacity");
    }

    $(".Opacity").removeClass("Opacity");

    $("#LoadingOverlay").hide();

    $('#AjaxProgressPopUp').hide();
}
