﻿/*===   DISPLAY THE LOADING IMAGE AT THE CENTER OF THE SCREEN.  ===*/
function CenterElementOnScreen(element) {
    var scrollTop = document.body.scrollTop;
    var scrollLeft = document.body.scrollLeft;
    var viewPortHeight = document.body.clientHeight;
    var viewPortWidth = document.body.clientWidth;

    if (document.compatMode == "CSS1Compat") {
        viewPortHeight = document.documentElement.clientHeight;
        viewPortWidth = document.documentElement.clientWidth;
        scrollTop = document.documentElement.scrollTop;
        scrollLeft = document.documentElement.scrollLeft;
    }

    var offsetHeight = element.offsetHeight; offsetHeight = offsetHeight > 0 ? offsetHeight : 0;
    var offsetWidth = element.offsetWidth; offsetWidth = offsetWidth > 0 ? offsetWidth : 0;

    var topOffset = Math.ceil(viewPortHeight / 2 - offsetHeight / 2);
    var leftOffset = Math.ceil(viewPortWidth / 2 - offsetWidth / 2);

    var top = scrollTop + topOffset;
    var left = scrollLeft + leftOffset;

    element.style.top = top + "px";
    element.style.left = left + "px";
    //alert('Top: ' + element.style.top + ' - Left: ' + element.style.left);
}
function ShowDivLoadingImg() {
    var divLoading = document.getElementById('divLoadingImg');
    CenterElementOnScreen(divLoading);
    divLoading.style.display = 'block';

    var divLoadingBar = $("#divLoadingBar");
    divLoadingBar.css("display", "block");
    var expectedHeight = document.body.clientHeight; //  - 200;
    if (expectedHeight > 0)
        divLoadingBar.css("height", expectedHeight);
}
function HideDivLoadingImg() {
    $("#divLoadingImg").css("display", "none");
    $("#divLoadingBar").css("display", "none");
}
function collapseContainers() {
    $(".toggle-container").hide();
    $(".full-content").hide();
}
function mapToggleEvents() {
    $(".trigger").live('click', function() {
        $(this).toggleClass("active");
        $(this).parent().parent().find(".toggle-container").slideToggle("fast");
        return false;
    });

    $(".read-more").live('click', function() {
        $(this).parent().hide()
        $(this).parent().parent().find(".full-content").show();
    });

    $(".read-less").live('click', function() {
        $(this).parent().hide()
        $(this).parent().parent().find(".short-content").show();
    });
}
function mapTopicSlideTrap() {
    var hideDelay = 200;
    var hideTimer = null;
    $('.slide-trap').live('mouseover', function() {
        var container = $(this).parent().find("ul.slide-list");
        if (hideTimer)
            clearTimeout(hideTimer);

        $(".slide-list").fadeOut(0);
        container.slideDown(hideDelay).show();
    });

    $('.slide-trap').live('mouseout', function() {
        var container = $(this).parent().find(".slide-list");
        if (hideTimer)
            clearTimeout(hideTimer);
        hideTimer = setTimeout(function() {
            container.fadeOut(0);
        }, hideDelay);
    });

    $(".slide-list").live('mouseover', function() {
        if (hideTimer)
            clearTimeout(hideTimer);
    });

    $(".slide-list").live('mouseout', function() {
        if (hideTimer)
            clearTimeout(hideTimer);
        hideTimer = setTimeout(function() {
            $(".slide-list").fadeOut(0);
        }, hideDelay);
    });
}
function mapCommonEvents() {
    $(".trigger").live('click', function() {
        $(this).toggleClass("active");
        $(this).parent().parent().find(".toggle-container").slideToggle("fast");
        return false;
    });

    $(".read-more").live('click', function() {
        $(this).parent().hide()
        $(this).parent().parent().find(".full-content").show();
    });

    $(".read-less").live('click', function() {
        $(this).parent().hide()
        $(this).parent().parent().find(".short-content").show();
    });
}
function validateFCK(source, args) {
    var fckBody = FCKeditorAPI.GetInstance('<%=txtEditor.ClientID %>');
    args.IsValid = fckBody.GetXHTML(true) != "";
}
