function requestAjaxService(className, methodName, handler, usePost, useSsl, onSuccess, onFailure) {

    var url;
    var parameterIndex;
    var postBody;

    if (useSsl && (document.location.hostname != "localhost"))
        url = "https://" + document.location.hostname + "/" + handler;
    else
        url = handler;

    parameterIndex = 0;

    if (usePost) {

        postBody = "<bd><c>" + htmlEncode(className) + "</c><m>" + htmlEncode(methodName) + "</m>";

        for (var i = 7; i < arguments.length; i++) {

            if ((typeof(arguments[i].value) == "object") && arguments[i].value.length) {

                for (var j = 0; j < arguments[i].value.length; j++) {
                    postBody += "<p" + parameterIndex + ">" + htmlEncode(arguments[i].type + ":" + arguments[i].value[j]) + "</p" + parameterIndex + ">";
                }

            } else {
                postBody += "<p" + parameterIndex + ">" + htmlEncode(arguments[i].type + ":" + arguments[i].value) + "</p" + parameterIndex + ">";
            }
            
            parameterIndex++;
        }

        postBody += "</bd>";

        new Ajax.Request(url, { method: "post", onSuccess: onSuccess, onFailure: onFailure, postBody: postBody});        
    } else {
    
        url += "?c=" + encodeURIComponent(className) + "&m=" + encodeURIComponent(methodName);
    
        // The server-side functions parameters will vary in number and so they will be passed after the onFailure parameter
        //
        for (var i = 7; i < arguments.length; i++) {
    
            if ((typeof(arguments[i].value) == "object") && arguments[i].value.length) {
    
                for (var j = 0; j < arguments[i].value.length; j++) {
                    url += "&p" + parameterIndex + "=" + encodeURIComponent(arguments[i].type + ":" + arguments[i].value[j]);
                }
    
            } else {
                url += "&p" + parameterIndex + "=" + encodeURIComponent(arguments[i].type + ":" + arguments[i].value);
            }
    
            parameterIndex++;
        }
    
        new Ajax.Request(url, { method: "get", onSuccess: onSuccess, onFailure: onFailure });
    }
}

function htmlEncode(s) {    
    return s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/=/g, "&#61;").replace(/\"/g, "&quote;");
}

function showResponseAlert(request) {
    alert(request.responseText);
}

window.AuthoringGetImagesHandler = new AuthoringGetImagesHandler();

function AuthoringGetImagesHandler() {
    this.GetImageUris = function(p0, f1, f2) { requestAjaxService("AuthoringGetImagesHandler", "GetImageUris", "AuthoringGetImages.ashx", true, false, f1, f2, { type: "String", value: p0 }); }
}

window.RecommendationsHandler = new RecommendationsHandler();

function RecommendationsHandler() {
this.RecordMarkAsReadAndUnread = function(p0, p1, f1, f2) { requestAjaxService("RecommendationsHandler", "RecordMarkAsReadAndUnread", "ajaxservice.ashx", true, false, f1, f2, { type: "String[]", value: p0 }, { type: "String[]", value: p1 }); }
this.RenderTopicSearchResults = function(p0, f1, f2) { requestAjaxService("RecommendationsHandler", "RenderTopicSearchResults", "ajaxservice.ashx", true, false, f1, f2, { type: "String", value: p0 }); }
this.Subscribe = function(p0, p1, f1, f2) { requestAjaxService("RecommendationsHandler", "Subscribe", "ajaxservice.ashx", true, false, f1, f2, { type: "String", value: p0 }, { type: "Boolean", value: p1 }); }
this.Unsubscribe = function(p0, p1, f1, f2) { requestAjaxService("RecommendationsHandler", "Unsubscribe", "ajaxservice.ashx", true, false, f1, f2, { type: "String", value: p0 }, { type: "Boolean", value: p1 }); }
}

window.RegistrationHandler = new RegistrationHandler();

function RegistrationHandler() {
this.RenderRegistrationLoginDialog = function(p0, f1, f2) { requestAjaxService("RegistrationHandler", "RenderRegistrationLoginDialog", "ajaxservice.ashx", false, false, f1, f2, { type: "String", value: p0 }); }
this.CheckUserName = function(p0, f1, f2) { requestAjaxService("RegistrationHandler", "CheckUserName", "ajaxservice.ashx", false, false, f1, f2, { type: "String", value: p0 }); }
}

window.DotHandler = new DotHandler();

function DotHandler() {
this.PublishDot = function(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, f1, f2) { requestAjaxService("DotHandler", "PublishDot", "ajaxservice.ashx", true, false, f1, f2, { type: "String", value: p0 }, { type: "String", value: p1 }, { type: "String", value: p2 }, { type: "String", value: p3 }, { type: "Int32", value: p4 }, { type: "String", value: p5 }, { type: "String", value: p6 }, { type: "String", value: p7 }, { type: "String", value: p8 }, { type: "Int32", value: p9 }, { type: "Int32", value: p10 }); }
this.VoteUrl = function(p0, p1, f1, f2) { requestAjaxService("DotHandler", "VoteUrl", "ajaxservice.ashx", true, false, f1, f2, { type: "String", value: p0 }, { type: "VoteReason", value: p1 }); }
}

