﻿
// Retrieves the results from the web service.
function initHomePartnerModule(id, serviceUrl, contentName, urlRoot) {

    $.ajax({
        type: 'POST',
        url: serviceUrl + '/GetPartnerItem',
        data: '{\'ContentName\':' + '\'' + contentName + '\'}',
        contentType: 'application/json; charset=utf-8',
        dataType: 'json',
        success: function(result)
             {
                if (result.d != null)
                {
                    displayResults(id, result.d, urlRoot);
                }
             },
        failure: function(error)
             {
                //TODO: Do something
             }
    });
}

// Sets the retrieved results to the appropriate fields.
function displayResults(id, results, urlRoot) {
  
    var module = $('#' + id);
    
    if (module.length > 0) {
        module.find('.Title').html(results.Title);
        module.find('.Text').html(results.Text);
        module.find('.Image').append('<img src="' + results.ImageURL + '" alt="' + results.ImageLabel + '" />');
        module.find('.divMoreLink').find('a').attr('href', results.URL.replace('~/', urlRoot));
    }
}