/* 10738 */
/*
*/

var mm_ri = String( Math.random() );
mm_ri = mm_ri.replace( /0\./g,'' );

var mm_protocol = location.protocol;
if ( mm_protocol != 'http:' && mm_protocol != 'https:' ){ mm_protocol = 'http:'; }

function contractEndDate(endDates) {
	var today = new Date();
	var twoWeeks = new Date();
	twoWeeks.setDate(twoWeeks.getDate() + 14);
	var month = new Date();
	month.setMonth(month.getMonth() + 1);
	var twoMonths = new Date();
	twoMonths.setMonth(twoMonths.getMonth() + 2);
	var threeMonths = new Date();
	threeMonths.setMonth(threeMonths.getMonth() + 3);
	for (var i = 0; i < endDates.length; i++) {
		var endDate = new Date(endDates[i]);
		if (endDate > today) {
			if (endDate < twoWeeks) {
				(new Image).src = "//pixel.mathtag.com/event/img?mt_id=635107&mt_adid=108074";
				(new Image).src = "//pixel.mathtag.com/event/img?mt_id=635106&mt_adid=108074";
				(new Image).src = "//pixel.mathtag.com/event/img?mt_id=635105&mt_adid=108074";
				(new Image).src = "//pixel.mathtag.com/event/img?mt_id=635104&mt_adid=108074";
			} else if (endDate < month) {
				(new Image).src = "//pixel.mathtag.com/event/img?mt_id=635107&mt_adid=108074";
				(new Image).src = "//pixel.mathtag.com/event/img?mt_id=635106&mt_adid=108074";
				(new Image).src = "//pixel.mathtag.com/event/img?mt_id=635105&mt_adid=108074";
			} else if (endDate < twoMonths) {
				(new Image).src = "//pixel.mathtag.com/event/img?mt_id=635107&mt_adid=108074";
				(new Image).src = "//pixel.mathtag.com/event/img?mt_id=635106&mt_adid=108074";
			} else if (endDate < threeMonths) {
				(new Image).src = "//pixel.mathtag.com/event/img?mt_id=635107&mt_adid=108074";
			}
		}
	}
}

jQuery( window ).load(function() {
	if (/^.+www.att.com\/shop\/wireless\/upgradephone.html/.test(location.href)) {
		var dates = document.body.innerHTML.match( /Ends [a-zA-Z]{3} \d{2}, \d{4}/g );
		contractEndDate(dates);

		var upgradeEligible = document.body.innerHTML.match( /Upgrade Eligible/g );
		if (upgradeEligible.length > 0) {
			(new Image).src = "//pixel.mathtag.com/event/img?mt_id=635108&mt_adid=108074";
		}

		var nextEligible = document.body.innerHTML.match( /eligible.+Next/g );
		if (nextEligible.length > 0) {
			(new Image).src = "//pixel.mathtag.com/event/img?mt_id=639032&mt_adid=108074";
		}
		
		var devices = document.body.innerHTML.match( />.+iPhone 4<|>.+iPhone 4S<|>.+iPhone 5<|>.+iPhone 5S<|>.+Samsung Galaxy S4</g );
		if (devices.length > 1) {
			(new Image).src = "//pixel.mathtag.com/event/img?mt_id=635114&mt_adid=108074";
		}
		for (var i = 0; i < devices.length; i++) {
			var device = devices[i].toLowerCase();
			if (device.indexOf("iphone 5s") > 0) {
				(new Image).src = "//pixel.mathtag.com/event/img?mt_id=635112&mt_adid=108074";
			} else if (device.indexOf("iphone 5") > 0) {
				(new Image).src = "//pixel.mathtag.com/event/img?mt_id=635111&mt_adid=108074";
			} else if (device.indexOf("iphone 4s") > 0) {
				(new Image).src = "//pixel.mathtag.com/event/img?mt_id=635110&mt_adid=108074";
			} else if (device.indexOf("iphone 4") > 0) {
				(new Image).src = "//pixel.mathtag.com/event/img?mt_id=635109&mt_adid=108074";
			} else if (device.indexOf("samsung galaxy s4") > 0) {
				(new Image).src = "//pixel.mathtag.com/event/img?mt_id=635113&mt_adid=108074";
			}
		}
	}

	if (/^.+www.att.com\/olam\/profile.olamexecute?actionEvent=redirectToUserInfo/.test(location.href)) {
		var endDate = [/[\s\S]+Contract end date[\s\S]+(\d{2}\/\d{2}\/\d{4})/.exec(document.body.innerHTML)[1]];
		contractEndDate(endDate);
	}

	if (/^.+www.att.com\/olam\/showWirelessDashboardAction.myworld/.test(location.href) || /^.+www.att.com\/olam\/showSLIDOverviewAction.myworld/.test(location.href) ) {
		var upgradesEligible = document.body.innerHTML.match( /You're eligible for an upgrade/g ) || [];
		if (upgradesEligible.length > 0) {
			(new Image).src = "//pixel.mathtag.com/event/img?mt_id=635108&mt_adid=108074";
		}

		var nearDataLimit = document.body.innerHTML.match( /You're nearing your data usage limit/g );
		if (nearDataLimit !== null) {
			(new Image).src = "//pixel.mathtag.com/event/img?mt_id=640732&mt_adid=108074";
		}

		if (/Mobile Share Value/.test(document.body.innerHTML) === false) {
			var numUsers = jQuery('.deviceBadge').each(function(index) {}).length;
			if (numUsers > 1) {
				(new Image).src = "//pixel.mathtag.com/event/img?mt_id=640735&mt_adid=108074";
			}
		}

		var deviceResults = [];
		if (/apple-iphone%204-100x110.jpg/.test(document.body.innerHTML)) {
			deviceResults.push("apple-iphone%204-100x110.jpg");
		}
		if (/apple-iphone%204s-100x110.jpg/.test(document.body.innerHTML)) {
			deviceResults.push("apple-iphone%204s-100x110.jpg");
		}
		if (/apple-iphone%205%20model%20a1428-100x110.jpg/.test(document.body.innerHTML)) {
			deviceResults.push("apple-iphone%205%20model%20a1428-100x110.jpg");
		}
		if (/apple-iphone%205s%20a1533-100x110.jpg/.test(document.body.innerHTML)) {
			deviceResults.push("apple-iphone%205s%20a1533-100x110.jpg");
		}
		if (/samsung-sgh-i337-100x110.jpg/.test(document.body.innerHTML)) {
			deviceResults.push("samsung-sgh-i337-100x110.jpg");
		}
		if (deviceResults.length > 0) {
			var deviceMap = {
				"apple-iphone%204-100x110.jpg": "635109",
				"apple-iphone%204s-100x110.jpg": "635110",
				"apple-iphone%205%20model%20a1428-100x110.jpg": "635111",
				"apple-iphone%205s%20a1533-100x110.jpg": "635112",
				"samsung-sgh-i337-100x110.jpg": "635113"
			};
			for (var i = 0; i < deviceResults.length; i++) {
				(new Image).src = "//pixel.mathtag.com/event/img?mt_id=" + deviceMap[deviceResults[i]] + "&mt_adid=108074";
			}
		}

		if (/Mobile Share Value/.test(document.body.innerHTML) === true) {
			var dataPlans = {
				"300MB": "640726",
				"1GB": "640727",
				"2GB": "640728",
				"4GB": "640729",
				"6GB": "640730",
				"10GB": "640731"
			};
			var totalData = /[\s\S]+Mobile Share Value.?(300MB|1GB|2GB|4GB|6GB|10GB|\d+GB|\d+MB)/.exec(document.body.innerHTML) || [];
			totalData = totalData[1];
			if (dataPlans[totalData] !== undefined) {
				(new Image).src = "//pixel.mathtag.com/event/img?mt_id=" + dataPlans[totalData] + "&mt_adid=108074";
			}

			var dataUsed = 0.0;
			jQuery('#sdgUsage span').each(function(index) { dataUsed = dataUsed + parseFloat(jQuery( this ).text().trim()); });
			var daysRemaining = parseFloat(/[\s\S]+class="days-left">(\d+)</.exec(document.body.innerHTML)[1]);
			if (dataUsed/parseFloat(totalData) > (30 - daysRemaining)/30) {
				(new Image).src = "//pixel.mathtag.com/event/img?mt_id=640732&mt_adid=108074";
			}
		}
	}
});


var sync_4815162342 = function()
{
this.urls = [
[0, "http://pixel.mathtag.com/misc/img?mop_seq=0:35&mt_cb=607856&mop_top="],
[3, "http://image2.pubmatic.com/AdServer/Pug?vcode=bz0yJnR5cGU9MSZjb2RlPTM2MiZ0bD00MzIwMA==&piggybackCookie=uid:8878553e-ef3a-4600-bfe6-ba0e5e594a41"],
[0, "http://pixel.mathtag.com/misc/img?mop_seq=1:35&mt_cb=904544&mop_top=3:1430259465|"],
[13, "http://ib.adnxs.com/getuid?http://sync.mathtag.com/sync/img?mt_exid=13&mt_mminit=1&mt_exuid=$UID"],
[0, "http://pixel.mathtag.com/misc/img?mop_seq=2:35&mt_cb=744991&mop_top=3:1430259465|13:1430259465|"],
[5, "http://us-u.openx.net/w/1.0/sd?id=536872786&val=8878553e-ef3a-4600-bfe6-ba0e5e594a41"],
[10, "http://ads.yahoo.com/pixel?id=2172018&t=2&piggyback=http%3A%2F%2Fads.yahoo.com%2Fcms%2Fv1%3Fesig%3D1~444de053567fa80a3054a1981c8febcf1176dd9d%26nwid%3D10000355603%26sigv%3D1"],
[15, "http://dsum.casalemedia.com/rum?cm_dsp_id=3&external_user_id=8878553e-ef3a-4600-bfe6-ba0e5e594a41"],
[11, "http://bh.contextweb.com/bh/rtset?do=add&pid=530739&ev=8878553e-ef3a-4600-bfe6-ba0e5e594a41"],
[29, "http://delivery.swid.switchads.com/adserver/info.php?action=STORE&info=MMTH:8878553e-ef3a-4600-bfe6-ba0e5e594a41"],
[17, "http://ce.lijit.com/merge?pid=3&3pid=8878553e-ef3a-4600-bfe6-ba0e5e594a41"],
[21, "http://ums.adtechus.com/mapuser?providerid=1005;userid=8878553e-ef3a-4600-bfe6-ba0e5e594a41"],
[25, "http://www.burstnet.com/user/2/bidder_id=77161&bidder_user_id=8878553e-ef3a-4600-bfe6-ba0e5e594a41"],
[0, "http://pixel.mathtag.com/misc/img?mop_seq=10:35&mt_cb=605057&mop_top=3:1430259465|13:1430259465|5:1430259465|10:1430259465|15:1430259465|11:1430259465|29:1430259465|17:1430259465|21:1430259465|25:1430259465|"],
[20, "http://dis.criteo.com/pump/match.aspx?c=2&uid=8878553e-ef3a-4600-bfe6-ba0e5e594a41"],
[42, "http://sync.go.sonobi.com/us.gif?nw=mediamath&nuid=8878553e-ef3a-4600-bfe6-ba0e5e594a41"],
[38, "http://s.kau.li/?did=21&uid=8878553e-ef3a-4600-bfe6-ba0e5e594a41"],
[31, "http://sync.adap.tv/sync?type=gif&key=mediamathinc&uid=8878553e-ef3a-4600-bfe6-ba0e5e594a41"],
[32, "http://pix.btrll.com/partner/353806.png"],
[30, "http://sync.search.spotxchange.com/partner?adv_id=6653&uid=8878553e-ef3a-4600-bfe6-ba0e5e594a41"],
[24, "http://cs.specificclick.net/sync/?bdid=3&fr=1"],
[16, "http://ad.360yield.com/match?publisher_dsp_id=5&external_user_id=8878553e-ef3a-4600-bfe6-ba0e5e594a41"],
[35, "http://y.one.impact-ad.jp/cs?d=70&uid=8878553e-ef3a-4600-bfe6-ba0e5e594a41&tg=2&et=30&r=no"],
[26, "http://ih.adscale.de/adscale-ih/tpui?tpid=39&tpuid=8878553e-ef3a-4600-bfe6-ba0e5e594a41&cburl=http%3A%2F%2Fcotads.adscale.de%2Fads%2Fpixel%2F1by1.png"],
[0, "http://pixel.mathtag.com/misc/img?mop_seq=20:35&mt_cb=258501&mop_top=3:1430259465|13:1430259465|5:1430259465|10:1430259465|15:1430259465|11:1430259465|29:1430259465|17:1430259465|21:1430259465|25:1430259465|20:1430259465|42:1430259465|38:1430259465|31:1430259465|32:1430259465|30:1430259465|24:1430259465|16:1430259465|35:1430259465|26:1430259465|"],
[39, "http://rtb-csync.smartadserver.com/redir/?partnerid=25&partneruserid=8878553e-ef3a-4600-bfe6-ba0e5e594a41"],
[37, "http://admaym.com/UserMatch.ashx?bidderid=45&bidderuid=8878553e-ef3a-4600-bfe6-ba0e5e594a41"],
[41, "http://sync.tidaltv.com/GenericUserSync.ashx?dpid=82NoRedirect"],
[10002, "http://tags.bluekai.com/site/2948?id=8878553e-ef3a-4600-bfe6-ba0e5e594a41"],
[10010, "http://tags.bluekai.com/site/4448?id=8878553e-ef3a-4600-bfe6-ba0e5e594a41"],
[10008, "http://loadm.exelator.com/load/?p=204&g=101&buid=8878553e-ef3a-4600-bfe6-ba0e5e594a41&j=0"],
[10011, "http://e.nexac.com/e/media_math_sync.xgi?na_exid=8878553e-ef3a-4600-bfe6-ba0e5e594a41"],
[10031, "http://beacon.krxd.net/usermatch.gif?partner=mediamath&_kdpid=8dd53e69-ae3f-4829-8f12-05cc5b57b288&mmuuid=8878553e-ef3a-4600-bfe6-ba0e5e594a41"],
[10017, "http://idsync.rlcdn.com/361087.gif?partner_uid=8878553e-ef3a-4600-bfe6-ba0e5e594a41"],
[10018, "http://p.acxiom-online.com/pixel/ddp?pid=3006&ord=1000&uid=8878553e-ef3a-4600-bfe6-ba0e5e594a41&ot=pixel&redir=http%3A%2F%2Fpixel.mathtag.com%2Fload%2Fimg%3Fmt_segld2%3D%23DATTRIBUTES%23%26mt_exid%3D10018%26mt_pi%3Dax%26mt_exuid%3D%23COOKIEID%23"],
[0, "http://pixel.mathtag.com/misc/img?mop_seq=30:35&mt_cb=679806&mop_top=3:1430259465|13:1430259465|5:1430259465|10:1430259465|15:1430259465|11:1430259465|29:1430259465|17:1430259465|21:1430259465|25:1430259465|20:1430259465|42:1430259465|38:1430259465|31:1430259465|32:1430259465|30:1430259465|24:1430259465|16:1430259465|35:1430259465|26:1430259465|39:1430259465|37:1430259465|41:1430259465|10002:1430259465|10010:1430259465|10008:1430259465|10011:1430259465|10031:1430259465|10017:1430259465|10018:1430259465|"],
[10009, "http://adadvisor.net/adscores/g.pixel?sid=9211132948&_mt=8878553e-ef3a-4600-bfe6-ba0e5e594a41"],
[10025, "http://su.addthis.com/red/usync?pid=11112&puid=8878553e-ef3a-4600-bfe6-ba0e5e594a41"],
[43, "https://analytics.twitter.com/i/adsct?p_user_id=8878553e-ef3a-4600-bfe6-ba0e5e594a41&p_id=13524"],
[10042, "http://global.ib-ibi.com/image.sbxx?go=247256&pid=310&xid=8878553e-ef3a-4600-bfe6-ba0e5e594a41"],
[10013, "http://d.agkn.com/pixel/2184/?sync=615&che=1234750395&uuid=8878553e-ef3a-4600-bfe6-ba0e5e594a41"],
[0, "http://pixel.mathtag.com/misc/img?mop_seq=35:35&mt_cb=507882&check=8878553e-ef3a-4600-bfe6-ba0e5e594a41&mop_top=3:1430259465|13:1430259465|5:1430259465|10:1430259465|15:1430259465|11:1430259465|29:1430259465|17:1430259465|21:1430259465|25:1430259465|20:1430259465|42:1430259465|38:1430259465|31:1430259465|32:1430259465|30:1430259465|24:1430259465|16:1430259465|35:1430259465|26:1430259465|39:1430259465|37:1430259465|41:1430259465|10002:1430259465|10010:1430259465|10008:1430259465|10011:1430259465|10031:1430259465|10017:1430259465|10018:1430259465|10009:1430259465|10025:1430259465|43:1430259465|10042:1430259465|10013:1430259465|"]
]

   this.progress = 0;

   var self = this;

   var tims = "";
   var errs = "";

   this.sync = function(i)
   {
       var e = document.createElement("img");

       var now = new Date();


       if (e.addEventListener)
       {
	   e.addEventListener('load', function() {
	       var temp = new Date().getTime() - now.getTime(); tims += self.urls[i][0]+':'+temp+"|";
	   });

	   e.addEventListener('error', function() {
	       var temp = new Date().getTime() - now.getTime(); errs += self.urls[i][0]+':'+temp+"|";
	   });
       }

       e.src = self.urls[i][1];
   }

   this.batch = function()
   {
      for (var i = self.progress; i < self.urls.length; ++i)
      {
	 self.sync(i);
      }
   }

   this.final = function()
   {
      var e = document.createElement("img");
      e.src = self.urls[self.urls.length-1][1]+"&final&timings="+tims+"&errors="+errs;
   }

   this.some = function(howmany)
   {
      var count = 0;
      for (var i = self.progress; i < self.urls.length && count < howmany; ++i)
      {
         self.sync(i);
	 self.progress++;
         count++;
      }
   }
}


var s_4815162342 = new sync_4815162342();
s_4815162342.some(1);
setTimeout('s_4815162342.some(2)', 1000);
setTimeout(s_4815162342.batch, 3000);
setTimeout(s_4815162342.final, 10000);

(function() {
    metric = function(url, wait)
    {
        setTimeout(function() {
            var e = document.createElement("img");
            e.src = url;
        }, wait);
    }

    var intervals = [0, 3, 5, 10, 15, 20, 40, 80];
    var inlen = intervals.length;
    for (var k = 0; k < inlen; ++k)
	this.metric("http://pixel.mathtag.com/misc/img?mm_bnc&linger="+k, intervals[k] * 1000);
})();

(function() {
    metric = function(url, wait)
    {
        setTimeout(function() {
                var e = document.createElement("img");
                e.src = url;
            }, wait);
    }

    var intervals = [0, 10];
    var inlen = intervals.length;
    for (var k = 0; k < inlen; ++k)
        this.metric("http://pixel.mathtag.com/misc/img?mm_bnc&bcdv="+k, intervals[k] * 1000);
})();

