/***********************
* -----------------------
* Author: fhays
* Description: Javascript library for various data points on websense.com
* -----------------------
*/
var jws = (function() {
    // constructor
    function utility(baseUrl) {
        this.baseUrl = 'https://www.websense.com';
        if (baseUrl != null && typeof (baseUrl) != 'undefined')
            this.baseUrl = baseUrl;
    }

    // public instance methods
    utility.prototype.getVisitor = function(callback) {
        var ajaxBase = this.baseUrl;
        doAjax("GetVisitor", ajaxBase, callback);
    }
    
    utility.prototype.logout = function(callback) {
        var ajaxBase = this.baseUrl;
        doAjax("Logout", ajaxBase, callback);
    }

    // private methods
    function doAjax(methodName, ajaxBase, successCallback) {
        $.ajax({
            url: ajaxBase + "/controls/WebDataServiceJsonp.asmx/" + methodName,
            dataType: "jsonp",
			contentType: "",
            success: function(msg) {
                if (successCallback != null)
                    successCallback(msg.d);
            }
        });
    }

    return {
        utility: utility,

        // finds commented out code in a form and re-inserts into the dom without comments.
        removeFormComments: function (className) {
            $(function () {
                $("form." + className).contents().each(function () {
                    if (this.nodeType == 8) {
                        $(this).parent().prepend(this.nodeValue);
                        $(this).remove();
                    }
                });
            });
        }
    }
})();
