





 
	




/* wx-a21-plugthis-2_0.js expireTime 120 */

/*	Ads 2.1 plug in include JS on the page
*	Jang Choe/Daniel Wetteroth/Casey Dement
*   USE http://closure-compiler.appspot.com/home to minimize. Use "simple" settings 
*/


// Interim for Contextual Ads
var wxDateArray = wx.config.page.serverdate.split("/");
var wxTimeArray = wx.config.page.servertime.split(":");

if(wx.config.page.pageId == 62287) {
	document.write("<scri"+"pt src='http://j.imwx.com/v."+wxDateArray[0]+wxDateArray[1]+wxDateArray[2]+"."+wxTimeArray[0]+"/common/ads/contextuallinks/providerHomepage.js'></scri"+"pt>");
} else if(wx.config.page.pageId == 62288) {
	document.write("<scri"+"pt src='http://j.imwx.com/v."+wxDateArray[0]+wxDateArray[1]+wxDateArray[2]+"."+wxTimeArray[0]+"/common/ads/contextuallinks/providerOverview.js'></scri"+"pt>");
}else if(wx.config.page.pageId ==  62735 ) {
	document.write("<scri"+"pt src='http://j.imwx.com/v."+wxDateArray[0]+wxDateArray[1]+wxDateArray[2]+"."+wxTimeArray[0]+"/common/ads/contextuallinks/provider_fiveday.js'></scri"+"pt>");
}else if(wx.config.page.pageId == 62381 ) {
	document.write("<scri"+"pt src='http://j.imwx.com/v."+wxDateArray[0]+wxDateArray[1]+wxDateArray[2]+"."+wxTimeArray[0]+"/common/ads/contextuallinks/provider_interactivemaps.js'></scri"+"pt>");
}else if(wx.config.page.pageId ==  59506) {
	document.write("<scri"+"pt src='http://j.imwx.com/v."+wxDateArray[0]+wxDateArray[1]+wxDateArray[2]+"."+wxTimeArray[0]+"/common/ads/contextuallinks/provider_sixtenday.js'></scri"+"pt>");
}else if(wx.config.page.pageId == 59974) {
	document.write("<scri"+"pt src='http://j.imwx.com/v."+wxDateArray[0]+wxDateArray[1]+wxDateArray[2]+"."+wxTimeArray[0]+"/common/ads/contextuallinks/provider_classicmaps.js'></scri"+"pt>");
}else if(wx.config.page.pageId == 60010) {
	document.write("<scri"+"pt src='http://j.imwx.com/v."+wxDateArray[0]+wxDateArray[1]+wxDateArray[2]+"."+wxTimeArray[0]+"/common/ads/contextuallinks/provider_text.js'></scri"+"pt>");
}else if(wx.config.page.pageId == 60161) {
	document.write("<scri"+"pt src='http://j.imwx.com/v."+wxDateArray[0]+wxDateArray[1]+wxDateArray[2]+"."+wxTimeArray[0]+"/common/ads/contextuallinks/provider_tenday.js'></scri"+"pt>");
}else if(wx.config.page.pageId == 61898) {
	document.write("<scri"+"pt src='http://j.imwx.com/v."+wxDateArray[0]+wxDateArray[1]+wxDateArray[2]+"."+wxTimeArray[0]+"/common/ads/contextuallinks/provider_video.js'></scri"+"pt>");
}
// End Interim


(function() {
    var query = new Object;
    function parse(){var pat_query=new RegExp('^[^\\?]+\\?(.*)$');if(!pat_query.test(location))return false;var array=pat_query.exec(location);query.QUERY_STRING=array[1];var params=query.QUERY_STRING.split(/&/);for(var i=0;i<params.length;i++){var keys=params[i].split(/=/);query[keys[0]]=unescape(keys[1]);}}
    function param(key){if(key==null){alert("param() function has been used incorrectly.\nUSAGE: param(key)");return false;}
    return query[key];}
    parse();

    //RMID
    A21.onParseConfig.subscribe(function(type, arg, me) {
        var rmid = YAHOO.util.Cookie.get('RMID');
	var rmidExpires = new Date("December 31, 2025");
        if (!rmid) {
            // we'll need to fix this before 2/7/2106 when timestamps roll over to 9 digits!
            rmid = (Math.round(Math.random() * 0xffffffff)).toString(16) + (Math.floor(new Date().getTime() / 1000)).toString(16);
            while (rmid.length < 16) rmid = '0' + rmid;
        }
        YAHOO.util.Cookie.set('RMID', rmid, {
            path:'/',
            domain:'weather.com',
            expires: rmidExpires
        });
        wx.config.user.rmid = rmid;
    });

    //ASI
    A21.onParseConfig.subscribe(function(type, arg, me) {
        var asiCookie = YAHOO.util.Cookie.get("rsi_segs");
        var segments, asiArray, asi = [];
        var i, len;

        if (asiCookie) {
            segments = asiCookie.split('|');
            len = segments.length;

            if (len > 0) {
                for (i = 0; i < len; i++) {
                    asiArray = segments[i].split('_');
                    asi.push(asiArray[1]);
                }
                wx.config.user.asi = asi;
            }
        }
    });

    //cobrand
    A21.onParseConfig.subscribe(function(type, arg, me) {
        if (!wx.config.user.cobrand) {
            wx.config.user.cobrand = YAHOO.util.Cookie.get('partner') || 'nl';
        }
        wx.config.ad.keywords.push('cobr=' + wx.config.user.cobrand);
        //wx.config.ad.keywords.push('!c=' + wx.config.user.cobrand);
    });

    //ENV
    A21.onParseConfig.subscribe(function(type, arg, me) {
      

        if (wx.config.page.env) {
            var segments  = wx.config.page.env.split(':');
            var env = segments[1];

            if (env) {
            	 wx.config.ad.keywords.push('env=' + env);
             
            }
        }
    });
	
	
    //locid
    A21.onParseConfig.subscribe(function(type, arg, me) {
        var expires = new Date("December 31, 2025");
        if(wx.config.loc.locid && wx.config.loc.locid !="") {
            var loc;
            if(wx.config.loc.locid.indexOf("$") >= 0) {
                loc = wx.config.loc.locid.replace("$",":");
                YAHOO.util.Cookie.set("LocID", loc, {
                        path: '/',
                        domain: '.weather.com',
                        expires: expires
                });
            } else {
                YAHOO.util.Cookie.set("LocID", wx.config.loc.locid, {
                    path: '/',
                    domain: '.weather.com',
                    expires: expires
                });
            }
            
        } else if(wx.config.loc.zip && wx.config.loc.zip != "") {
            YAHOO.util.Cookie.set("LocID", wx.config.loc.zip, {
                path: '/',
                domain: '.weather.com',
                expires: expires
            });
        }
        var loc = YAHOO.util.Cookie.get('LocID');
        if (loc) {
            wx.config.user.loc = loc.replace('$1','');
	    wx.config.loc.locid = loc.replace(':','$');
	    wx.config.user.loc = loc.replace('$',':');

        } else {
            wx.config.user.loc = '';
        }

        wx.config.ad.keywords.push('loc=' + (wx.config.loc.locid ||  'nl'));
    });

    //CS
    A21.onParseConfig.subscribe(function(type, arg, me) {
        var cs = param('attrib');

        if (typeof(cs)=='undefined'){
            cs = param('epc');
        }

        var cskey='';
        if (typeof(cs) != 'undefined') {
            cs = cs.toLowerCase();
            if (cs == 'wxar' || cs=='bw' || cs=='bx' || cs=='by') {
                cskey="cs=nascar";
            } else if (cs == "bi") {
                cskey="cs=nfl"
            } else if (cs == "be") {
                cskey="cs=mlb!c=mlb";
            } else if (cs == "bz") {
                cskey="cs=cftbl";
            }

            wx.config.ad.keywords.push(cskey);
        }
				
    });

    //Provider
   /* A21.onParseConfig.subscribe(function(type, arg, me) {
        if (!provider) { var provider = ''; }
        var ctxp = provider || 'nl';
        wx.config.ad.keywords.push('ctxp=' + ctxp);
    });*/


    //Geo-Political Regions
    A21.onParseConfig.subscribe(function(type, arg, me) {
        function addGPR(gpr, keyword) {
            if (gpr.length > 0) {
                wx.config.ad.keywords.push(keyword);
            }
        }
        var gpr;

        if (wx && wx.config && wx.config.loc) {
            gpr = wx.config.loc.gpr;
            if (gpr instanceof Array) {
                addGPR(gpr, 'intl=' + gpr.join(';intl='));
            } else if (typeof gpr === 'string') {
                addGPR(gpr, 'intl=' + gpr);
            }
        }
    });


    //UserPrefs
    A21.onParseConfig.subscribe(function(type, arg, me) {
        var getCID = function(str) { return str.split('|')[33]; };
        var cid;

        wx.config.user.claritas = YAHOO.util.Cookie.get('UserPreferences', getCID) || '';
        cid = wx.config.user.claritas || 'nl';
        wx.config.ad.keywords.push('cid=' + cid);
    });


    // Forecast entry
    A21.onParseConfig.subscribe(function(type, arg, me) {
            if (wx && wx.config && wx.config.page) {
            	if (wx.config.page.fromStr && 
            		(wx.config.page.fromStr == "searchbox_typeahead" 
            			|| wx.config.page.fromStr == "hdr_localsearch"
            			|| wx.config.page.fromStr == "enhsearch"
            			|| wx.config.page.fromStr == "enhsearch_didyoumean" 
            			|| wx.config.page.fromStr == "enhsearch_drilldown" 
            			|| wx.config.page.fromStr == "hdr_trptsearch"
            			|| wx.config.page.fromStr == "hdr_recentsearch")) {
            		if(wx.config.page.locType == "4") {
            			wx.config.ad.keywords.push('ent=zip');
            		} else if(wx.config.page.locType == "1") {
                		wx.config.ad.keywords.push('ent=city');
            		}
            	}	
            }
            
    });

    //view
    A21.onParseConfig.subscribe(function(type, arg, me) {
        var vw = YAHOO.util.Cookie.get('fv') || 'nl';
        wx.config.ad.keywords.push('vw=' + vw);
    });


        
    //Provider
    A21.onParseConfig.subscribe(function(type, arg, me) {
	// Needed for contextual ads interim solution.
	if( wx.config.page.pageId != 62288 && wx.config.page.pageId != 62735 && wx.config.page.pageId != 62381 
		&& wx.config.page.pageId != 59506 && wx.config.page.pageId != 59974 && wx.config.page.pageId != 60010 
		&& wx.config.page.pageId != 60161 && wx.config.page.pageId != 61898) {      
		if (!provider) { var provider = ''; }
        	var ctxp = provider || 'nl';
        	wx.config.ad.keywords.push('ctxp=' + ctxp);
	}
    });

    //Severe
    A21.onParseConfig.subscribe(function(type, arg, me) {
            var dcoptFound = false;

            function removeDcopt(keywords) {
                var i, len = keywords.length;
                var returnArray = [];
                //alert("Debug1");
                for (i = 0; i < len; i++) {
                    if (keywords[i] != 'dcopt=ist' && keywords[i] != 'sev=nl') {
                        returnArray.push(keywords[i]);
                    } else {
                        dcoptFound = true;
                    }
                }
                return returnArray;
            }
            
            var getAddi = function(str) { return str.split('|')[16]; };
            var addi = YAHOO.util.Cookie.get('UserPreferences', getAddi) || '';
           if(addi!="") {
			//	wx.config.ad.keywords.push(wx.config.user.decl);  ****** Taken out per BZ 34655
                //var addis = addi.split(";");
                //for(i=0; i<addis.length; i++) {
                   //wx.config.ad.keywords.push(addis[i]);
                //}
            
           if(typeof gnSiteMode != "undefined") { 
                if((gnSiteMode=="severe" || gnSiteMode=="alert")) {
                    if(wx.config.ad.zone && (wx.config.ad.zone.indexOf('base/home')>=0 || wx.config.ad.zone.indexOf('vert/news')>=0)) {
                        wx.config.ad.sev = "severe";
                        wx.config.wx.severe="true";
                        var position;
                        var adPositions;
                        
                    
                        if (wx && wx.config && wx.config.page) {
                            adPositions = wx.config.ad.positions;
                            for (position in adPositions) {
                                if (adPositions.hasOwnProperty(position)) {
                                    wx.config.ad.positions[position].keywords = removeDcopt(adPositions[position].keywords);
                                    var tempke = wx.config.ad.keywords.toString();
                                    if(tempke.indexOf('!c=oob')<0) {
                                        wx.config.ad.positions[position].keywords.push('!c=oob');
                                    }
                                }
                            }
                        }
                    }
		  }
                } else if(wx.config.page && wx.config.page.localseveremod=="localseveremode" || wx.config.page.severe == "true") {  //Local severe treatment.
                        
                        wx.config.ad.sev = "severe";
                    
                        var position;
                        var adPositions;
                        
                    
                        if (wx && wx.config && wx.config.page) {
                            adPositions = wx.config.ad.positions;
                            for (position in adPositions) {
                                if (adPositions.hasOwnProperty(position)) {
                                    wx.config.ad.positions[position].keywords = removeDcopt(adPositions[position].keywords);
                                    var tempke = wx.config.ad.keywords.toString();
                                    if(tempke.indexOf('!c=oob')<0) {
                                        //alert("adding oob - Daniel Debug, do not log a BZ");
                                        wx.config.ad.positions[position].keywords.push('!c=oob');
                                    }
                            }
                        }
                    }
                } else if(wx.config.wx && wx.config.wx.severe !="" && wx.config.wx.severe != "nl") {
                        
                        wx.config.ad.sev = "severe";
                    
                        var position;
                        var adPositions;
                        
                    
                        if (wx && wx.config && wx.config.ad) {
                            adPositions = wx.config.ad.positions;
                            for (position in adPositions) {
                                if (adPositions.hasOwnProperty(position)) {
                                    wx.config.ad.positions[position].keywords = removeDcopt(adPositions[position].keywords);
                                    var tempke = wx.config.ad.keywords.toString();
                                    if(tempke.indexOf('!c=oob')<0) {
                                        //alert("adding oob - Daniel Debug, do not log a BZ");
                                        wx.config.ad.positions[position].keywords.push('!c=oob');
                                    }
                            }
                        }
                    }
                } else {
			if (wx.config.user.cobrand) {
				wx.config.ad.keywords.push('!c=' + wx.config.user.cobrand);
			}
	     }

	 } else if((wx.config.page && (wx.config.page.localseveremod=="localseveremode" || wx.config.page.severe == "true")) || (wx.config.wx && wx.config.wx.severe !="" && wx.config.wx.severe != "nl")) {
		 wx.config.ad.sev = "severe";
                    
                        var position;
                        var adPositions;
                        
                    
                        if (wx && wx.config && wx.config.page) {
                            adPositions = wx.config.ad.positions;
                            for (position in adPositions) {
                                if (adPositions.hasOwnProperty(position)) {
                                    wx.config.ad.positions[position].keywords = removeDcopt(adPositions[position].keywords);
                                    var tempke = wx.config.ad.keywords.toString();
                                    if(tempke.indexOf('!c=oob')<0) {
                                        //alert("adding oob - Daniel Debug, do not log a BZ");
                                        wx.config.ad.positions[position].keywords.push('!c=oob');
                                    }
                            }
                        }
                    }

	}
        });
    

	
    
    //Declaration Passed:
    A21.onParseConfig.subscribe(function(type, arg, me) {
        if (wx.config.user) {
        	//wx.config.ad.keywords.push(wx.config.user.declar);
        	if(wx.config.page && wx.config.page.pageId=='62288') {
	        	var apps = wx.config.user.apps;
	        	for(i=0;i<apps.length;i++) {
	        		var whatTo = getDeclarationDFP(apps[i]);
	        		wx.config.ad.keywords.push(whatTo);
	        	}
			}
        }
    });
    


    
    //Pollen
    A21.onParseConfig.subscribe(function(type, arg, me) {
        if (!pagemetadata) { var pagemetadata = {}; }

        if(pagemetadata && pagemetadata.wx && pagemetadata.wx.pollen) {
            if(pagemetadata.wx.pollen>=4) {
                wx.config.wx.pollen = "hi";
                wx.config.ad.keywords.push('plln=' + 'hi');
            } else if(pagemetadata.wx.pollen==2 || pagemetadata.wx.pollen==3) {
                wx.config.wx.pollen = "me";
                wx.config.ad.keywords.push('plln=' + 'me');
            } else if(pagemetadata.wx.pollen==0 || pagemetadata.wx.pollen==1) {
                wx.config.wx.pollen = "lo";
                wx.config.ad.keywords.push('plln=' + 'lo');
            }
        }
    });

    //Snow
    A21.onParseConfig.subscribe(function(type, arg, me) {

        if(wx.config && wx.config.wx && wx.config.wx.snw) {
	        wx.config.ad.keywords.push('snw=' + wx.config.wx.snw);
        }
        if(wx.config && wx.config.wx && wx.config.wx.fsnw) {
	        wx.config.ad.keywords.push('fsnw=' + wx.config.wx.fsnw);
        }
    });

    //Barometric Trend
    A21.onParseConfig.subscribe(function(type, arg, me) {

        if(wx.config && wx.config.wx && wx.config.wx.baroTendency) {
	        wx.config.ad.keywords.push('baro=' + wx.config.wx.baroTendency);
        }
    });
        
    // Scattershots
    A21.onParseConfig.subscribe(function(type, arg, me) {
        var tScat = wx.config.page.scatter;
        count = 0;
        for (scat in tScat) {
             if( count<50) {
                wx.config.ad.keywords.push('zcs='+ tScat[scat]);
             }
             count++;
        }
        
    });

   A21.onAdStart.subscribe(printDebug("DFPdebug"));
   A21.onFinish.subscribe(printDebug("DeveloperDebug"));

    function printDebug(param) {
        return function(type, arg, me) {
            var adVariables = arg[0].adVariables;
            var posName     = arg[0].position;
            var position    = arg[0].Positions[posName];

            var loader = new YAHOO.util.YUILoader({
 
                require: ["history"],
                loadOptional: true,
 
                onSuccess: function() {
                    var paramCheck  = YAHOO.util.History.getQueryStringParameter(param, location.href);
                    
                    if (paramCheck == 'true') {
                        getPosReqDetails(posName, position);
                    }
                },
             
                timeout: 10000,
             
                combine: true
            });
             
            loader.insert();


            function getPosReqDetails(posName, position, style) {
                var i, keywords, keyValue;
                var divStart = '<div style="margin: 0; background: white; color: black; font-family: sans-serif; padding: 5px; border: 1px solid gray; font-size: 12px;" id="%id%">';
                var debug = document.createElement('div');
                
                if (!position.keywords) {
                    return;
                }
                if (style) {
                    for (i in style) {
                        if (style.hasOwnProperty(i)) {
                            debug.style[i] = style[i];
                        }
                    }
                }
                
                debug.innerHTML = '<div style="padding: 5px; border: 1px solid gray; color: black; font-family: sans-serif; background-color: yellow; font-weight: bold;">' + posName + '</div>';
                debug.innerHTML += divStart.replace(/%id%/, posName + '_d_html') + "html: <strong>" + position.bodyHTML + "</strong></div>";
                debug.innerHTML += divStart.replace(/%id%/, posName + '_d_position') + "position: <strong>" + posName + "</strong></div>";
                debug.innerHTML += divStart.replace(/%id%/, posName + '_d_pageId') + "pageId: <strong>" + wx.config.page.pageId + "</strong></div>";
                debug.innerHTML += divStart.replace(/%id%/, posName + '_d_url') + "url: <strong>" + A21.getDFPUrl(posName) + "</strong></div>";
                debug.innerHTML += divStart.replace(/%id%/, posName + '_d_zone') + "zone: <strong>" + adVariables.zone + "</strong></div>";
                debug.innerHTML += divStart.replace(/%id%/, posName + '_d_site') + "site: <strong>" + adVariables.site + "</strong></div>";
                debug.innerHTML += divStart.replace(/%id%/, posName + '_d_sizes') + "sizes: <strong>" + position.sizes[0] + "</strong></div>";
                debug.innerHTML += divStart.replace(/%id%/, posName + '_d_u') + "u: <strong>" + position.u + "</strong></div>";
                debug.innerHTML += divStart.replace(/%id%/, posName + '_d_tiles') + "tiles: <strong>" + position.tile + "</strong></div>";
                keywords = position.keywords.split(';');
                
                for (i=0; i < keywords.length; i++) {
                    keyValue = keywords[i].split('=');
                    if (keyValue[0]) {
                        debug.innerHTML += divStart.replace(/%id%/, posName + '_d_' + keyValue[0]) + keyValue[0] + ': <strong>' + keyValue[1] + '</strong></div>';
                    }
                }
                document.getElementsByTagName('body')[0].appendChild(debug);
            }

        }
    }
})();




