﻿/* 
    3rd Party Integration File 
    Authored: 2009 05 28

    * Please add development notes here

    1.0 - Shared Methods
        Description: Shared methods
        1.1 - Issue. In order not to crash IE7-8, we must call the getScript method via a timeout.
            More research on this jQuery method is needed.

    2.0 - RSI Implementation 
        Description: This code is used to generate user information used for behavioral targeting.
            Our ad calls will make use of these values for ad taregting via the WNAdManager class.
    Point Release (6/12/2009)
    http://twiki.worldnow.com/twiki/bin/view/Intranet/AdOperationsRevenueScienceUpdate200904Point1
        2.1 - Issue. RSI spuratically calls the DM_onSegsAvailable method more than once.  To avoid dup kw values
            we are adding a check to ensure it is only called once.
        2.2 - Note. Backwards compatible with container D sites that do not have the wng_pageInfo class.
*/

/* Section 1.0 - Shared Methods ***************************************** */
/* ********************************************************************** */
function wnLoadJSFile(filename, cb, docWrite){

    cb = (typeof cb == 'function') ? cb : function(){};
    
    if ( docWrite ) {
        document.writeln('<scr'+'ipt type="text/javascript" src="'+filename+'"></scr'+'ipt>');
        window.setTimeout(cb,parseInt(docWrite));
    } else {
        window.setTimeout(function() {
            jQuery.getScript(filename, cb);  
        },1); /* 1.1 See notes section */
    }
    
}

/* Section 2.0 - RSI Implementation ************************************* */
/* ********************************************************************** */
var RSI_CSID = 'E05511';
var RSI_JS_URL = 'http://js.revsci.net/gateway/gw.js?csid=' + RSI_CSID;
var G_RSI_SEGMENTS = null;

function DM_onSegsAvailable(rsinetsegs, csid) { 

    /* 2.1 See notes section */
    this.loaded = ( this.loaded != 'undefined' && this.loaded ) ? true : false;

    if ( !this.loaded  ) {
        var rsi_csid_pattern = new RegExp(RSI_CSID,"i");
        if (rsi_csid_pattern.test(csid)) { 
            G_RSI_SEGMENTS = rsinetsegs;
        }  
    }

    this.loaded = true;

}

function wn_CallRSI() {

    var RSI_affName, RSI_adTag, RSI_contType, RSI_baseUrl = null;

    /* 2.2 See notes section */
    if ( typeof wng_pageInfo != 'undefined'  ) {
        RSI_affName = wng_pageInfo.affiliateName;
        RSI_adTag = wng_pageInfo.contentClassification;
        RSI_contType = wng_pageInfo.containerType;
        RSI_baseUrl = wng_pageInfo.baseUrl;
    } else {
        RSI_affName = g_AffName;
        RSI_adTag = g_AdTag;
        RSI_contType = g_ContType;
        RSI_baseUrl = g_BaseURL;  
    }

    try {
        E05511.DM_addEncToLoc ('affname',escape(RSI_affName)); 
        E05511.DM_addEncToLoc ('adtag',escape(RSI_adTag)); 
        E05511.DM_addEncToLoc ('conttype',escape(RSI_contType)); 
        E05511.DM_addEncToLoc ('baseurl',escape(RSI_baseUrl)); 
        E05511.DM_tag(); 
    } catch(e) {
        try {
            WNErrorHandle.addErrorMsg(e);
            WNErrorHandle.console(e);
        } catch(ee) {}
    }

}    

wnLoadJSFile(RSI_JS_URL, wn_CallRSI, 1);

/* End of Section 1.0 - RSI Implementation ************************************* */
/* ***************************************************************************** */