// Call the Barclays Offer Handler to get the html for the offer to show on the content page.
// The success function will insert the html into the supplied element.
// <created by="Jay Green" date="02/09/2011"/>
function GetBarclaysOfferHtml(ctrlRef, notLoggedInCtrlRef, channel) {
    try {
        var url = "/shared/barclayscontenthandler.ashx";
        var data = { "Channel": channel, "Name": dmData.name, "Miles": dmData.miles, "Status": dmData.status, "ReturnURL": window.location.href };
        $.ajax({ type: 'GET',
            url: url,
            data: data,
            dataType: 'json',
            success: function(result) {
            if (result != null) {

                if (result.CampaignKey != null && jQuery.trim(result.CampaignKey.toString()) > 1 && result.OfferAvailable != null && result.OfferAvailable) {
                    s_omniture.channel = "CONTENT";
                    s_omniture.prop8 = s_omniture.eVar33 = result.CampaignKey + OmnitureChannel(channel);

                    var s_code = s_omniture.t();
                    if (s_code) document.write(s_code)
                }
                    if (result.IsLoggedIn) {
                        ctrlRef.html(result.Markup);
                    }
                    else {
                        notLoggedInCtrlRef.html(result.Markup);
                    }
                }
            },
            error: function(jqXHR, textStatus, errorThrown) {
                //alert(jqXHR.statusText);
            }
        });
    }
    catch (e) {
        //alert(e);
    }
}


function GetTemplateName() {
    var sPath = window.location.pathname;
    var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
    var sPage = sPage.substring(0, sPage.lastIndexOf('.'));

    var sPart = sPath.substring(0,sPath.lastIndexOf('/'));
    var sFolder = sPart.substring(sPart.lastIndexOf('/') + 1);
        
    var sTemplate = sFolder + '_' + sPage;
        
    return sTemplate;
}


function OmnitureChannel(channel) {
    var postfix = "";
    switch (channel) {
        case "DMHomePage": postfix = "-dmhome";
            break;
        case "PreferredBenefits": postfix = "-prefben"
            break;
        case "Promotion": postfix = "-promo";
            break;
        default:
            postfix = "-" + channel.toString().toLowerCase();
            break;
    }
    return postfix;
}

 

