﻿ 

$(document).ready(function() {
    var div = $(".roundedcornr_wrap");

    $(".close", div).click(function() {
        closeModalWindow();
    });
   

    $(".btn_close", div).click(function() {
        closeModalWindow();
    });
});

function showHelpTopic(helpTopicId, element, offset_left, offset_top) {
    // check if the input is correct
    if (helpTopicId != null && element != null) {
        getHelpTopic(helpTopicId);

        var offset = element.offset();
        var parentOffset = element.parents(".content").offset();

        $(".roundedcornr_wrap").css(
        {
            left: offset.left - parentOffset.left + offset_left,
            top: offset.top - parentOffset.top + offset_top
        });
    }
}


function getHelpTopic(helpTopicId) {
    
    jQuery.ajax({
        url: "/Handlers/Generic.ashx",
        global: false,
        type: "GET",
        data: ({ action: "getHelpTopic", helpTopicId: helpTopicId }),
        success: function(helpTopic) {

            if (helpTopic == null || helpTopic == '') {
                helpTopic = 'Help topic cannot be found!';
            }
        displayHelpTopic(helpTopic);
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            alert(textStatus);
        }
    });
}


function displayHelpTopic(helpTopic) {
    var topics = helpTopic.split('^');
    var div = $(".roundedcornr_wrap");
    if ( topics != null && topics.length > 1 )
    {
        pageTracker._trackEvent('Help', 'View', topics[0]);
        $("#help_topic_description", div).html(topics[1]);
    }
    else
    {
        $("#help_topic_description", div).html(helpTopic);
    }
    div.fadeIn("fast");
}

 

function closeModalWindow() {
    $(".roundedcornr_wrap").fadeOut("fast");
    $("#modalBackgroundDiv").fadeOut("fast");
}
 
function addErrorMessage(errorMessage) {
    var div = $(".roundedcornr_wrap");
    $(".message", div).html(errorMessage.join("<br/>"));
}


 