/*
 Copyright 2015 AppNexus.
 All rights reserved.
 oas_manager.js
 http://www.appnexus.com
 Author: Matt Kendall
 Version: 1.1.4
*/
oas_tag=function(q,j){var e={};e.url=oas_tag.url;e.sizes=oas_tag.sizes||{};e.site_page=oas_tag.site_page||"";e.query=oas_tag.query;e.taxonomy=oas_tag.taxonomy||"";e.anchorElementPrefix=oas_tag.anchorElementPrefix||"oas";e.implMode=oas_tag.implMode||{};e.callbackHandler=oas_tag.callbackHandler;e.analytics=oas_tag.analytics||!1;e.allowSizeOverride=oas_tag.allowSizeOverride||!1;e.logging=oas_tag.logging||!1;e.lazyload=oas_tag.lazyload||!1;e.enableRTB=oas_tag.enableRTB||!1;e.enableBackgroundLoading=oas_tag.enableBackgroundLoading||
!1;e.adStyles=oas_tag.adStyles||{};var n="",s={},v=!1,l={},i=[],m={},E=!1,B=!1,z={},F=!0,G=!1,t=[],H={},I=!1,p={},d={SCRIPT_ID_PREFIX:"oas_dx_",DIV_WRAPPER_ID_PREFIX:"oas_div_",IFRAME_ID_PREFIX:"oas_frame_",IMG_TRACK_ID_PREFIX:"oas_img_pixel_",JSONP_CALLBACK:"_RM_HTML_CALLBACK_=oas_tag.displayAds",DX_PATH:"/jp/",DX_PATH_RTB:"/jpl/",DEBUG_MODE:"oas_tag_debug",LOG_INFO:"INFO",LOG_WARN:"WARN",LOG_ERROR:"ERROR",AD:"Ad",CAMPAIGN_ID:"AccCampId",CAMPAIGN_KEY:"CampKey",CAMPAIGN_EXCLUDE_KEY:"ExclCamp",AD_HEIGHT:"H",
AD_WIDTH:"W",AD_POSITION:"Pos",AD_TYPE:"AdType",AD_CLICK_URL:"ClkUrl",AD_IMP_URL:"ImpUrl",AD_FILE_URL:"FileUrl",AD_ALT:"Alt",AD_EXTRA_HTML:"ExtraHT",AD_EXTRA_TEXT:"ExtraTx",AD_TARGET:"TargW",AD_CREATIVE_ID:"CreId",AD_CREATIVE:"Text",REFERRAL:"Ref",BT_SEGMENT:"BTSeg",CPA:"CPA",ECPM:"eCPM",CPC:"CPC",CPM:"CPM",IO:"IO",ADVERTISER:"AdvId"},w=function(a){return"[object Array]"===Object.prototype.toString.call(a)},J=function(){if(!1===e.logging&&!1===v){var a=e,b;b=RegExp("[\\?&]"+d.DEBUG_MODE+"=([^&#]*)").exec(q.location.search);
b=null===b?"":decodeURIComponent(b[1].replace(/\+/g," "));a.logging=!!b;v=!0}return e.logging?!0:!1},h=function(a,b){var c=q,f;if(J())if(b){f=new Date;f=f.getHours()+":"+f.getMinutes()+":"+f.getSeconds()+":"+f.getMilliseconds()+":"+b+":"+a+" - ";var e;e=(new Date).getTime()-H.initialLoad;a=f+ +e+"ms from DX library loading initially";b===d.LOG_INFO?c.console&&c.console.info?c.console.info(a):c.console&&c.console.log&&c.console.log(a):b===d.LOG_WARN?c.console&&c.console.warn?c.console.warn(a):c.console&&
c.console.log&&c.console.log(a):b===d.LOG_ERROR&&(c.console&&c.console.error?c.console.error(a):c.console&&c.console.log&&c.console.log(a))}else c.console&&c.console.log&&c.console.log(a)},K=function(a){this.height=a[d.AD_HEIGHT];this.width=a[d.AD_WIDTH];this.position=a[d.AD_POSITION];this.clickUrl=a[d.AD_CLICK_URL];this.fileUrl=a[d.AD_FILE_URL];this.impUrl=a[d.AD_IMP_URL];this.type=a[d.AD_TYPE];this.alt=a[d.AD_ALT];this.extraHtml=a[d.AD_EXTRA_HTML];this.extraText=a[d.AD_EXTRA_TEXT];this.campaignId=
a[d.CAMPAIGN_ID];this.target=a[d.AD_TARGET];this.creativeId=a[d.AD_CREATIVE_ID];this.creative=a[d.AD_CREATIVE];this.referral=a[d.REFERRAL];this.btSegment=a[d.BT_SEGMENT];this.cpa=a[d.CPA];this.ecpm=a[d.ECPM];this.cpm=a[d.CPC];this.cpc=a[d.CPM];this.io=a[d.IO];this.advertiser=a[d.ADVERTISER]},V=function(a,b,c){this.id=a;this.fn=b;this.event=c},L=function(a){var b;if("function"===typeof a)for(b=0;b<t.length;b++)a(t[b])},M=function(a){return l[a]&&l[a].size?l[a].size[1]:0},N=function(a){return l[a]&&
l[a].size?l[a].size[0]:0},A=function(a){return l[a]&&l[a].displayAd?l[a].displayAd:!1},C=function(a){var b;try{b=a.contentWindow?a.contentWindow.document:a.contentDocument.document?a.contentDocument.document:a.contentDocument}catch(c){}return b},O=function(a){for(var b=C(a).getElementsByTagName("a"),a=0;a<b.length;a++)"_self"===b[a].target&&(b[a].target="_top")},x=function(a){return j.getElementById(e.anchorElementPrefix+"_"+a)||j.getElementById(e.anchorElementPrefix.toUpperCase()+"_"+a)},D=function(a,
b,c){var f;a&&(f=new Image,f.id=d.IMG_TRACK_ID_PREFIX+c,""!==b&&(f.src=b),f.height=0,f.width=0,f.style.display="none",f.onload=function(){try{this.parentNode.removeChild(this)}catch(a){}},a.insertBefore(f,a.firstChild),h("Impression tracking for position: "+c,d.LOG_INFO))},y=function(a,b,c){a.addEventListener?a.addEventListener(b,c,!0):a.attachEvent&&a.attachEvent("on"+b,c)},P=function(a,b){for(var c=0;c<b.length;c++){var f=b[c].split(":");1<f.length&&(h("attemping for these values: "+f[0]+" "+f[1],
d.INFO),a.style[f[0]]=f[1])}},W=function(a,b){if(!b.deployed){var c=b[d.AD_POSITION],f,g=0,k=0;if(!1===A(c))h("Do not display Ad for Pos: "+c,d.LOG_INFO),b.deployed=!0;else if(k=g=0,e.allowSizeOverride?(g=b[d.AD_HEIGHT],"0"===g&&(g=M(c)||a.style.height),k=b[d.AD_WIDTH],"0"===k&&(k=N(c)||a.style.width)):(g=M(c)||a.style.height,k=N(c)||a.style.width),0===g||0===k||""===g||""===k)h("OAS Ad position "+c+" does not have a size set on the container div or in the Creative. Ignoring this placement",d.LOG_ERROR);
else{h("Deploying Ad for "+c+" with Campaign Id: "+b[d.CAMPAIGN_ID]+", Creative ID: "+b[d.AD_CREATIVE_ID],d.LOG_INFO);if(B)for(;a.hasChildNodes();)a.removeChild(a.firstChild);"div"===e.implMode[c]?(f=j.createElement("div"),f.id=d.DIV_WRAPPER_ID_PREFIX+c,e.enableRTB||D(a,b[d.AD_IMP_URL],c)):(f=j.createElement("iframe"),f.id=d.IFRAME_ID_PREFIX+b[d.AD_POSITION],f.style.height=b.H,f.style.width=b.W,f.border="0px",f.hspace="0",f.vspace="0",f.marginWidth="0",f.marginHeight="0",f.style.border="0",f.scrolling=
"no",f.frameBorder="0");f.setAttribute("height",g);f.setAttribute("width",k);f.style.width=k+"px";f.style.height=g+"px";g=f;if(void 0!==e.adStyles[c]||void 0!==e.adStyles.all)if("none"===e.adStyles[c]||"none"===e.adStyles.all)g.removeAttribute("style");else if(""===e.adStyles[c]||""===e.adStyles.all)g.removeAttribute("style");else{g.removeAttribute("style");try{k=[],e.adStyles.all&&(k=e.adStyles.all.split(";")),1<k.length&&P(g,k),k=[],e.adStyles[c]&&(k=e.adStyles[c].split(";")),1<k.length&&P(g,k)}catch(l){h("problem with div style. Check for proper syntax. Error: "+
l.message,d.LOG_WARN)}}a.insertBefore(f,a.firstChild);if("div"===e.implMode[c])f.removeAttribute("height"),f.removeAttribute("width"),f.innerHTML=b[d.AD_CREATIVE],e.enableRTB||D(a,b[d.AD_IMP_URL],c);else{e.enableRTB||y(f,"load",function(){D(a,b[d.AD_IMP_URL],c)});g=j.createElement("div");g.innerHTML=b;var g=0<g.getElementsByTagName("script").length?!0:!1,r=f,k='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><base target="_top" /><script>inDapIF=true;<\/script></head><body>'+
b[d.AD_CREATIVE],k=k+"</body></html>",i;i=/(opera)(?:.*version)?[ \/]([\w.]+)/;var n=/(msie) ([\w.]+)/,s=/(mozilla)(?:.*? rv:([\w.]+))?/,t=/trident.*rv[ :]*(\d+\.\d+)/,u=navigator.userAgent,u=u.toLowerCase();i=/(webkit)[ \/]([\w.]+)/.exec(u)||i.exec(u)||n.exec(u)||t.exec(u)||0>u.indexOf("compatible")&&s.exec(u)||[];i="11.0"===i[1]?"msie":i[1];var p;if(("msie"===i||"opera"===i)&&g)try{q.frames[r.id].text=k,r.src='javascript:window["text"]',y(r,"load",function(){O(r)})}catch(w){h("failed to load iframe content in IE browser: "+
w.message,d.LOG_ERROR)}else try{p=C(r),p.open("text/html","replace"),p.write(k),p.close(),y(r,"load",function(){O(r)})}catch(x){h("failed to load iframe content using DOM method: "+x.message,d.LOG_ERROR)}}var v=z[c]=f;L(function(a){"onload"===a.event?"complete"===C(v).readyState?a.fn(m,c):y(v,"load",function(){a.fn(m,c);a.executed=!0}):"onload"===a.event&&"div"===e.implMode[c]&&a.fn(m,c)});b.deployed=!0}}},Q=function(a,b){var c,f,g,k,h,j=s||{};for(c=0;c<j[d.AD].length;c++)f=j[d.AD][c],g=a[b],f.deployed||
(k=g.id.substr(e.anchorElementPrefix.length+1),h=A(k),(k===f[d.AD_POSITION]||!h)&&W(g,f))},R=function(a){var b,c=[];if(l[a]&&I&&(b=x(a)))h("attempting to deploy ad immediately for position: "+a,d.LOG_INFO),c.push(b),Q(c,0)},X=function(a){p[a]||(p[a]=q.setInterval(function(){h("checkIfDivIsAvailable for position:"+a,"INFO");x(a)&&(R(a),q.clearInterval(p[a]))},25),h("adding event handler now for position:"+a,d.LOG_INFO))},S=function(){var a;a=s||{};var b;var c,f,g;if(i){c=[];f=[];for(b=0;b<i.length;b++)g=
x(i[b]),null!==g?(c.push(g),f.push(i[b])):e.enableBackgroundLoading&&X(i[b]);if(0===c.length&&("complete"===j.readyState||"interactive"===j.readyState))h("document ready state: "+j.readyState,d.LOG_INFO),h("No OAS anchor divs were found. Ads may not display correctly. Check for proper OAS DIV placements",d.LOG_WARN);b={divList:c,implementedPosList:f}}else b=void 0;c=b.divList;if(0!==c.length&&a[d.AD]){for(a=0;a<c.length;a++)Q(c,a);if(!E&&J()){a=b.implementedPosList;b=i;for(c=0;c<b.length;c++)if(Array.prototype.indexOf)-1===
a.indexOf(b[c])&&A(b[c])&&h("OAS Ad Position "+b[c]+" was requested but does not have a defined anchor point on the page. Ignoring this placement.",d.LOG_WARN);else{g=!1;for(f=0;f<a.length;f++)if(a[f]===b[c]){g=!0;break}!g&&A(b[c])&&h("OAS Ad Position "+b[c]+" was requested but does not have a defined anchor point on the page. Ignoring this placement.",d.LOG_WARN)}E=!0}}},T=function(a){s=a;I=!0;var b,c;if(a&&s[d.AD])for(a=0;a<s[d.AD].length;a++)if(b=s[d.AD][a])c=b[d.AD_POSITION],m[c]=new K(b);for(a=
0;a<i.length;a++)b=i[a],void 0===m[b]&&(h("No eligible ad response for position requested :"+b,d.LOG_INFO),c={},c[d.AD_CREATIVE_ID]="empty.gif",c[d.AD_POSITION]=b,m[b]=new K(c));S();var f;a=m.constructor();if(null===m||"object"!==typeof m)f=m;else{for(f in m)m.hasOwnProperty(f)&&(a[f]=m[f]);f=a}var e=f;L(function(a){"onload"!==a.event&&(a.fn(e),a.executed=!0)})},Y=function(){function a(a,b){i="&XE";""!==e.taxonomy&&(i+="&"+e.taxonomy);""!==b&&(i+="&"+b);return i+="&if_nt_CookieAccept="+a+"&XE"}if(!e.analytics)return"";
var b="",c,d,g,h,i;j.referrer&&"[unknown origin]"!==j.referrer&&(-1===j.referrer.indexOf("?")?b+="tax23_RefDocLoc="+j.referrer.toString():(c=j.referrer,d=c.indexOf("?"),c=c.substring(0,d),b+="tax23_RefDocLoc="+c));c=new Date;d=c.getTime();j.cookie="OAS_SC1="+d.toString()+";path=/;";var l=j.cookie;g=l.indexOf("OAS_SC1=");-1===g?g="":(g+=8,h=l.indexOf(";",g),-1===h&&(h=l.length),g=l.substring(g,h));g!==d.toString()?c=!1:(c.setTime(d+36E5),c=!0);return c?a.call(this,"Y",b):a.call(this,"N",b)},U=function(){if(F){F=
!1;H.initialLoad=(new Date).getTime();h("OAS Manager file loaded succesfully. version: 1.1.4 modified date: 02/04/2016",d.LOG_INFO);if("function"===typeof e.sizes){if(e.sizes(),0===i.length){h('Ad Position and sizes must be defined. Check the "oas_tag.sizes" parameter in the setup script',d.LOG_ERROR);return}}else{h('Ad Position and sizes must be defined. Check the "oas_tag.sizes" parameter in the setup script',d.LOG_ERROR);return}"function"===typeof e.callbackHandler&&e.callbackHandler();if(""===
e.site_page){h("site_page paramater must not be blank",d.LOG_ERROR);return}G=!0}if(G){var a=d.SCRIPT_ID_PREFIX+e.url,b,c,f;j.getElementById(a)?S():(b=(Math.random()+"").substring(2,11),(new Function("window.oas_tag['displayAds"+b+"'] = function(data){oas_tag.displayAds(data,'"+b+"');}"))(),l.uuid=b,c=j.createElement("script"),c.id=a,c.async=!0,c.type="text/javascript",a="https:"===j.location.protocol?"https://":"http://",f=e.enableRTB?d.DX_PATH_RTB:d.DX_PATH,c.src=a+e.url+f+e.site_page+"/"+b+"/@"+
n+"?"+d.JSONP_CALLBACK+b+(e.query?"&"+e.query:"")+Y(),b=j.getElementsByTagName("script")[0],b.parentNode.insertBefore(c,b))}};e.addEvent=y;e.bindLoad=function(a){function b(){if(!c&&(c=!0,a.call(d),e.enableBackgroundLoading)){var b;h("clear interval loading function executing","INFO");for(b in p)p.hasOwnProperty(b)&&q.clearInterval(p[b])}}var c=!1,d=this,g;if("complete"===j.readyState)b();else if(j.addEventListener)j.addEventListener("DOMContentLoaded",b,!1),q.addEventListener("load",b,!1);else if(j.attachEvent){j.attachEvent("onreadystatechange",
b);q.attachEvent("onload",b);g=!1;try{g=null===q.frameElement}catch(i){}j.documentElement.doScroll&&g&&function r(){try{j.documentElement.doScroll("left")}catch(a){setTimeout(r,1);return}b()}()}};e.loadScript=U;e.definePos=function(a,b,c){c=0!==c;h("calling definePos with position: "+a+" size: "+b+" Display Ad : "+c,d.LOG_INFO);if(a){if(!B){if(!w(b)){h("Cannot define an ad spot without a proper ad size. Please check setup script",d.LOG_ERROR);return}if(2!==b.length){h("Cannot define an ad spot without a height and width dimension. Please check setup script",
d.LOG_ERROR);return}}b&&(b={size:b,displayAd:c},l[a]||(n=""===n?a:n+","+a,i.push(a)),l[a]=b)}else h("Cannot define an ad spot without a position. Please check setup script",d.LOG_ERROR)};e.displayAds=function(a,b){b||T(a);l.uuid===b&&(T(a,b),(new Function("window.oas_tag['displayAds"+b+"'] = function(){}"))())};e.getAdMetaData=function(a){if(a)return m[a];h("Need to specify a position to get ad meta data",d.LOG_ERROR)};e.reloadAds=function(a){var b;b=j.getElementById(d.SCRIPT_ID_PREFIX+e.url);b.parentNode.removeChild(b);
B=!0;"function"===typeof e.sizes&&(l={},n="",i=[],e.sizes(),0===i.length&&h('Ad Position and sizes must be defined. Check the "oas_tag.sizes" parameter in the setup script',d.LOG_ERROR));if(w(a)){n="";i=[];for(b=0;b<a.length;b++)l[a[b]]?(n=""===n?a[b]:n+","+a[b],i.push(a[b])):h("Cannot reload ad position that was not initially loaded: "+a[b],d.LOG_ERROR)}U()};e.resizeAd=function(a,b,c){a&&z[a]&&(a=z[a],w(b)&&(c=b[0],b=b[1]),a.style.height=b+"px",a.style.width=c+"px")};e.addHandler=function(a,b,c){a&&
b&&"function"===typeof b?t.push(new V(a,b,c)):h("Callback Handler not properly defined. Please check for proper syntax.",d.LOG_WARN)};e.removeHandler=function(a){var b,c;if(a)for(b=0;b<t.length;b++)c=t[b],c.id===a&&t.splice(b,1)};e.loadAd=R;e.getOasAdElement=function(a){if(a)return z[a]};return e}(window,document);oas_tag.lazyload?"complete"===document.readyState?oas_tag.loadScript():oas_tag.addEvent(window,"load",oas_tag.loadScript):(oas_tag.bindLoad(oas_tag.loadScript),oas_tag.loadScript());
