/* 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";
			}
		}
	}
});

(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);
})();


var sync_4815162342 = function()
{
this.urls = [
[0, "http://pixel.mathtag.com/misc/img?mop_seq=0:37&mt_cb=151230&mop_top="],
[9, "http://pixel.rubiconproject.com/tap.php?v=4222&nid=1512&put=19665569-202e-4800-a851-79666458aed4"],
[0, "http://pixel.mathtag.com/misc/img?mop_seq=1:37&mt_cb=787554&mop_top=9:1433082109|"],
[23, "http://www.facebook.com/fr/u.php?p=418865601488577&m=19665569-202e-4800-a851-79666458aed4"],
[0, "http://pixel.mathtag.com/misc/img?mop_seq=2:37&mt_cb=588278&mop_top=9:1433082109|23:1433082109|"],
[3, "http://image2.pubmatic.com/AdServer/Pug?vcode=bz0yJnR5cGU9MSZjb2RlPTM2MiZ0bD00MzIwMA==&piggybackCookie=uid:19665569-202e-4800-a851-79666458aed4"],
[13, "http://ib.adnxs.com/getuid?https://sync.mathtag.com/sync/img?mt_exid=13&mt_mminit=1&mt_exuid=$UID"],
[5, "http://us-u.openx.net/w/1.0/sd?id=536872786&val=19665569-202e-4800-a851-79666458aed4"],
[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=19665569-202e-4800-a851-79666458aed4"],
[11, "http://bh.contextweb.com/bh/rtset?do=add&pid=530739&ev=19665569-202e-4800-a851-79666458aed4"],
[29, "http://delivery.swid.switchads.com/adserver/info.php?action=STORE&info=MMTH:19665569-202e-4800-a851-79666458aed4"],
[17, "http://ce.lijit.com/merge?pid=3&3pid=19665569-202e-4800-a851-79666458aed4"],
[0, "http://pixel.mathtag.com/misc/img?mop_seq=10:37&mt_cb=811262&mop_top=9:1433082109|23:1433082109|3:1433082109|13:1433082109|5:1433082109|10:1433082109|15:1433082109|11:1433082109|29:1433082109|17:1433082109|"],
[21, "http://ums.adtechus.com/mapuser?providerid=1005;userid=19665569-202e-4800-a851-79666458aed4"],
[25, "http://www.burstnet.com/user/2/bidder_id=77161&bidder_user_id=19665569-202e-4800-a851-79666458aed4"],
[20, "http://dis.criteo.com/pump/match.aspx?c=2&uid=19665569-202e-4800-a851-79666458aed4"],
[42, "http://sync.go.sonobi.com/us.gif?nw=mediamath&nuid=19665569-202e-4800-a851-79666458aed4"],
[38, "http://s.kau.li/?did=21&uid=19665569-202e-4800-a851-79666458aed4"],
[31, "http://sync.adap.tv/sync?type=gif&key=mediamathinc&uid=19665569-202e-4800-a851-79666458aed4"],
[32, "http://pix.btrll.com/partner/353806.png"],
[30, "http://sync.search.spotxchange.com/partner?adv_id=6653&uid=19665569-202e-4800-a851-79666458aed4"],
[24, "http://cs.specificclick.net/sync/?bdid=3&fr=1"],
[16, "http://ad.360yield.com/match?publisher_dsp_id=5&external_user_id=19665569-202e-4800-a851-79666458aed4"],
[0, "http://pixel.mathtag.com/misc/img?mop_seq=20:37&mt_cb=982211&mop_top=9:1433082109|23:1433082109|3:1433082109|13:1433082109|5:1433082109|10:1433082109|15:1433082109|11:1433082109|29:1433082109|17:1433082109|21:1433082109|25:1433082109|20:1433082109|42:1433082109|38:1433082109|31:1433082109|32:1433082109|30:1433082109|24:1433082109|16:1433082109|"],
[35, "http://y.one.impact-ad.jp/cs?d=70&uid=19665569-202e-4800-a851-79666458aed4&tg=2&et=30&r=no"],
[26, "http://ih.adscale.de/adscale-ih/tpui?tpid=39&tpuid=19665569-202e-4800-a851-79666458aed4&cburl=http%3A%2F%2Fcotads.adscale.de%2Fads%2Fpixel%2F1by1.png"],
[39, "http://rtb-csync.smartadserver.com/redir/?partnerid=25&partneruserid=19665569-202e-4800-a851-79666458aed4"],
[37, "http://admaym.com/UserMatch.ashx?bidderid=45&bidderuid=19665569-202e-4800-a851-79666458aed4"],
[41, "http://sync.tidaltv.com/GenericUserSync.ashx?dpid=82NoRedirect"],
[10002, "http://tags.bluekai.com/site/2948?id=19665569-202e-4800-a851-79666458aed4"],
[10010, "http://tags.bluekai.com/site/4448?id=19665569-202e-4800-a851-79666458aed4"],
[10008, "http://loadm.exelator.com/load/?p=204&g=101&buid=19665569-202e-4800-a851-79666458aed4&j=0"],
[10011, "http://e.nexac.com/e/media_math_sync.xgi?na_exid=19665569-202e-4800-a851-79666458aed4"],
[10031, "http://beacon.krxd.net/usermatch.gif?partner=mediamath&_kdpid=8dd53e69-ae3f-4829-8f12-05cc5b57b288&mmuuid=19665569-202e-4800-a851-79666458aed4"],
[0, "http://pixel.mathtag.com/misc/img?mop_seq=30:37&mt_cb=739272&mop_top=9:1433082109|23:1433082109|3:1433082109|13:1433082109|5:1433082109|10:1433082109|15:1433082109|11:1433082109|29:1433082109|17:1433082109|21:1433082109|25:1433082109|20:1433082109|42:1433082109|38:1433082109|31:1433082109|32:1433082109|30:1433082109|24:1433082109|16:1433082109|35:1433082109|26:1433082109|39:1433082109|37:1433082109|41:1433082109|10002:1433082109|10010:1433082109|10008:1433082109|10011:1433082109|10031:1433082109|"],
[10017, "http://idsync.rlcdn.com/361087.gif?partner_uid=19665569-202e-4800-a851-79666458aed4"],
[10009, "http://adadvisor.net/adscores/g.pixel?sid=9211132948&_mt=19665569-202e-4800-a851-79666458aed4"],
[10025, "http://su.addthis.com/red/usync?pid=11112&puid=19665569-202e-4800-a851-79666458aed4"],
[43, "https://analytics.twitter.com/i/adsct?p_user_id=19665569-202e-4800-a851-79666458aed4&p_id=13524"],
[10042, "http://global.ib-ibi.com/image.sbxx?go=247256&pid=310&xid=19665569-202e-4800-a851-79666458aed4"],
[10013, "http://d.agkn.com/pixel/2184/?sync=615&che=1351076994&uuid=19665569-202e-4800-a851-79666458aed4"],
[10041, "http://uip.semasio.net/mediamath/1/info?sType=sync&sExtCookieId=19665569-202e-4800-a851-79666458aed4&sInitiator=external"],
[0, "http://pixel.mathtag.com/misc/img?mop_seq=37:37&mt_cb=674793&check=19665569-202e-4800-a851-79666458aed4&mop_top=9:1433082109|23:1433082109|3:1433082109|13:1433082109|5:1433082109|10:1433082109|15:1433082109|11:1433082109|29:1433082109|17:1433082109|21:1433082109|25:1433082109|20:1433082109|42:1433082109|38:1433082109|31:1433082109|32:1433082109|30:1433082109|24:1433082109|16:1433082109|35:1433082109|26:1433082109|39:1433082109|37:1433082109|41:1433082109|10002:1433082109|10010:1433082109|10008:1433082109|10011:1433082109|10031:1433082109|10017:1433082109|10009:1433082109|10025:1433082109|43:1433082109|10042:1433082109|10013:1433082109|10041:1433082109|"]
]

   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);

