var profileServiceURL = document.location.protocol + '//' + document.location.host + '/WebService/Profile.asmx/';
var profileServiceCommunicationMethod = 'post';
var profileServiceContentType = 'application/x-www-form-urlencoded';

function GetSavePreferencesRequest(url, requestArguments, preferences) {

    var request = 'url=' + url
                + '&requestArguments=' + encodeURIComponent(requestArguments)
                + '&preferences=' + encodeURIComponent(preferences);

    return request;
}

function SavePreferences(url, requestArguments, preferences, onSuccess, onFail) {

    var postBody = GetSavePreferencesRequest(url, requestArguments, preferences);

    var request = new Ajax.Request(profileServiceURL + 'SavePreferences', {
        method: profileServiceCommunicationMethod,
        postBody: postBody,
        contentType: profileServiceContentType,
        onSuccess: onSuccess,
        onFailure: onFail
    });
}

function GetRecoverPasswordRequest(url, requestArguments, userName) {

    var request = 'url=' + url
                + '&requestArguments=' + encodeURIComponent(requestArguments)
                + '&userName=' + encodeURIComponent(userName);

    return request;                
}

function RecoverPassword(url, requestArguments, userName, onSuccess, onFail) {

    var postBody = GetRecoverPasswordRequest(url, requestArguments, userName);

    var request = new Ajax.Request(profileServiceURL + 'RecoverPassword', {
        method: profileServiceCommunicationMethod,
        postBody: postBody,
        contentType: profileServiceContentType,
        onSuccess: onSuccess,
        onFailure: onFail
    });
}

function GetRecoverUsernameRequest(url, requestArguments, email) {

    var request = 'url=' + url
                + '&requestArguments=' + encodeURIComponent(requestArguments)
                + '&email=' + encodeURIComponent(email);

    return request;
}

function RecoverUsername(url, requestArguments, email, onSuccess, onFail) {

    var postBody = GetRecoverUsernameRequest(url, requestArguments, email);

    var request = new Ajax.Request(profileServiceURL + 'RecoverUsername', {
        method: profileServiceCommunicationMethod,
        postBody: postBody,
        contentType: profileServiceContentType,
        onSuccess: onSuccess,
        onFailure: onFail
    });
}

function SaveReferAFriend(url, requestArguments, firstname, lastname, email, onSuccess, onFail) {
    var postBody = GetSaveReferAFriendRequest(url, requestArguments, firstname, lastname, email);
    
    var request = new Ajax.Request(profileServiceURL + 'SaveReferAFriend', {
        method: profileServiceCommunicationMethod,
        postBody: postBody,
        contentType: profileServiceContentType,
        onSuccess: onSuccess,
        onFailure: onFail
    });
    
}

function GetSaveReferAFriendRequest(url, requestArguments, firstname, lastname, email) {

    var request = 'url=' + url
                + '&requestArguments=' + encodeURIComponent(requestArguments)
                + '&firstname=' + encodeURIComponent(firstname)
                + '&lastname=' + encodeURIComponent(lastname)
                + '&email=' + encodeURIComponent(email);

    return request;
}

function GetReferAFriendList(url, requestArguments, onSuccess, onFail) {

    var postBody = GetReferAFriendListRequest(url, requestArguments);

    var request = new Ajax.Request(profileServiceURL + 'GetReferAFriendList', {
        method: profileServiceCommunicationMethod,
        postBody: postBody,
        contentType: profileServiceContentType,
        onSuccess: onSuccess,
        onFailure: onFail    
    });
}

function GetReferAFriendListRequest(url, requestArguments) {

    var request = 'url=' + url
                + '&requestArguments=' + encodeURIComponent(requestArguments);

    return request;
}
