function help(id) {
    $.ajax({
        type: "POST",
        url: "/WebService/ContextualHelp.asmx/HelloWorld",
        data: "{}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {
        var html = $('#' + id).html();
            
            if (msg != null) {
                var terms = msg.d.toString().split(";");

                for (var i = 0; i < terms.length; i++) {
                    var term = terms[i].split(":");

                    for (var k = 0; k < term.length; k++) {
                        var keyword = term[0];
                        var display = term[1];
//                        html = html.replace(" " + keyword + " ", '<a class="contextualHelpLink" href="javascript:showContextualHelp(\'' + display + '\');"> ' + keyword + ' </a>');
//                        html = html.replace(" " + keyword + ". ", '<a class="contextualHelpLink" href="javascript:showContextualHelp(\'' + display + '\');"> ' + keyword + '. </a>');
//                        html = html.replace(" " + keyword + "? ", '<a class="contextualHelpLink" href="javascript:showContextualHelp(\'' + display + '\');"> ' + keyword + '? </a>');
//                        html = html.replace(" " + keyword + "! ", '<a class="contextualHelpLink" href="javascript:showContextualHelp(\'' + display + '\');"> ' + keyword + '! </a>');
                    }
                }

                // set html
                $('#' + id).html(html);
            }
        } 
    });
}


//Keeps track of Mouse Position for Contextual Help Popup
var mouseX;
var mouseY;

jQuery(document).ready(function() {
    $().click(function(e) {
        mouseX = e.pageX;
        mouseY = e.pageY;
    });
})

function showContextualHelp(display) {
    //Dynamically creates contextual content element
    //remove contextual help if it already exists
    if ($("#contextElement").length > 0) {
        $("#contextElement").remove();
    }
    $("<div id=\"contextElement\" class=\"contextualContainer\" onClick=\"hideContextualHelp();\"><img src=\"/App_Themes/FastSigns_AU/images/contextBox_top.png\" width=\"214\" height=\"13\"/><div class=\"contextualContent\">" + display + "</div><img src=\"/App_Themes/FastSigns_AU/images/contextBox_btm.png\" width=\"214\" height=\"25\" /></div>").appendTo("body");
    document.getElementById("contextElement").style.position = "absolute";
    document.getElementById("contextElement").style.top = mouseY - $("#contextElement").height() + "px";
    document.getElementById("contextElement").style.left = mouseX - 107 + "px";
}

function hideContextualHelp() {
    $("#contextElement").remove();
}

