ACM = {};
ACM.init = function() {
if (!Cookie.isEnabled) return;
var V = ACM_Vehicles, P = ACM_Profile;
if (location.search.indexOf('ACMPreview') != -1) {
var vName = location.search.substring(location.search.indexOf('ACMPreview')+11);
if (vName.indexOf('&') > -1) vName = vName.substring(0,vName.indexOf('&'));
var v = V[vName];
if (v) {
this.writeJSTag(v);
this.viewable = [ vName ];
v.preview = true;
return;
} else alert('ACM Preview:\n\n Vehicle not defined in preferences.');
}
this.cookie = new Cookie('ACM2',Time.yr,'/','.babycenter.com');
this.counter = 0;
this.viewable = new Array();
if (this.cookie.isExpired('s_',P.sessionTimeout))
this.newSession = true;
for (var n in V) {
var v = V[n];
v.sCounter = (v.cap) ? 0 : -1;
if (this.newSession) {
if (v.freq > 0) this.cookie.remove(n,true);
this.cookie.remove('s_'+n,true);
} else if (this.cookie.get('s_'+n) && v.sCounter > -1) {
v.sCounter = parseInt(this.cookie.get('s_'+n).value);
if (v.sCounter >= v.cap) v.freq = 0;
}
if (v.freq > 0) {
var skipped = (this.cookie.get(n))
? parseInt(this.cookie.get(n).value)
: false;
if (skipped && skipped <= v.freq) {
this.cookie.set(n,++skipped,true);
v.freq = 0;
}
} else if (typeof(v.freq) == 'string'
&& !this.cookie.isExpired(n,v.freq)) {
v.freq = 0;
}
}
var i = 0;
while (P['g'+(++i)]) {
var gId = 'g'+i;
var g = P[gId];
var gsCounter = (g.cap) ? 0 : -1;
if (this.newSession) {
this.cookie.remove('s_'+i,true);
this.cookie.remove(gId,true);
} else if (this.cookie.get('s_'+gId) && gsCounter > -1) {
gsCounter = parseInt(this.cookie.get('s_'+gId).value);
}
if (g.frequency > 0) {
var skipped = (this.cookie.get(gId))
? parseInt(this.cookie.get(gId).value)
: false;
if (skipped && skipped <= g.frequency) {
this.cookie.set(gId,++skipped,true);
g.frequency = 0;
}
} else if (typeof(g.frequency) == 'string'
&& !this.cookie.isExpired(gId,g.frequency)) {
g.frequency = 0;
}
if (g.frequency == 0) continue;
var gCounter = 0;
var j = 1;
while (g['v'+j]) {
var v = {freq:0}, n = g['v'+(j++)];
if (gsCounter > -1 && gsCounter >= g.cap) break;
if (g.frequency < 0 && gCounter >= Math.abs(g.frequency)) break;
if (g.frequency > 0 && gCounter > 0) break;
if (typeof(g.frequency) == 'string' && gCounter > 0) break;
if (this.counter >= P.pageCap) break;
if (typeof(n) == 'object') {
var k = 0, probability = 1, rndName;
while (n[k]) {
if (V[n[k]] && V[n[k]].freq && (Math.random() < 1/probability++)) {
rndName = n[k];
v = V[rndName];
}
k++;
}
n = rndName;
} else {
v = V[n];
}
v.groupID = gId;
if (v.freq == 0) continue;
if ((v.type == 'inline') && document.layers)
continue;
if (v.type == 'inline' && (document.getElementById && !document.getElementById(n)))
continue;
if (v.block) {
this.block(v.block);
v.block = '';
}
if (g.block) {
this.block(g.block);
delete(g.block);
}
if (v.type == 'popunder') this.popunderFlag = true;
this.writeJSTag(v);
this.viewable[this.viewable.length] = n;
gCounter++;  this.counter++;
if (gsCounter > -1) gsCounter++;
}
}
}
ACM.display = function(index) {
if (!Cookie.isEnabled) return;
var V = ACM_Vehicles, P = ACM_Profile;
if (!index && index != 0) index = 0;
if (!this.viewable || !this.viewable[index]) {
if (this.cookie) this.cookie.set('s_',1);
this.unload();
return;
}
var n = this.viewable[index];
var v = V[n];
if (!v.loaded) {
if (v.preview) {
alert('ACM Preview:\n\nVehicle not targeted or not loaded due to network delay');
return;
}
v.delay = (v.delay) ? v.delay+1 : 1;
if (v.delay > 3) this.display(++index);
else setTimeout('ACM.display('+index+')',500);
return;
}
if (v.freq == 0 && !v.preview) {
this.display(++index);
return;
} else if (v.block) {
this.block(v.block);
v.block = '';
}
if (v.type == 'inline' && v.html) {
var cr = (n=='rhuInline') ? '&nbsp;<br>' : '';
if (document.getElementById)
document.getElementById(n).innerHTML = cr+v.html;
}
if (v.events) {
if (this.popunderFlag && (v.type == 'popup')) setTimeout('eval(ACM_Vehicles["'+n+'"].events)',1000);
else eval(v.events);
}
if (v.preview) return;
if (v.TEC && v.TESC) {
var iSrc = '/di/trans.gif?_tp_EC='+v.TEC
+'&_tp_ESC='+v.TESC
+'&_tp_EFN=page&_tp_EFV='+escape(location.href)
+'&t='+Math.round(Math.random()*10000000);
v.tImg = new Image();
v.tImg.src = iSrc;
}
var gID = v.groupID;
this.cookie.set(n,1,true);
if (P[gID].frequency > 0) this.cookie.set(gID,1,true);
if (v.cap) {
if (this.newSession || !this.cookie.get('s_'+n)) {
this.cookie.set('s_'+n,1,true);
} else {
this.cookie.set('s_'+n,++v.sCounter,true);
}
}
if (P[gID].cap) {
if (this.newSession || !this.cookie.get('s_'+gID)) {
this.cookie.set('s_'+gID,1,true);
} else {
var gsCounter = parseInt(this.cookie.get('s_'+gID).value);
this.cookie.set('s_'+gID,++gsCounter,true);
}
}
this.display(++index);
}
ACM.block = function() {
if (!Cookie.isEnabled) return;
var P = ACM_Profile, V = ACM_Vehicles;
var  bArray;
if (!arguments.length)  bArray = ['ALL'];
else if (typeof(arguments[0]) == 'object') bArray = arguments[0];
else  bArray = arguments;
for (var i = 0; i < bArray.length; i++) {
var b = bArray[i];
if (typeof(b) == 'string') {
for (var n in V) {
if (b == n || V[n].type == b || b == 'ALL') V[n].freq = 0;
}
} else if (P['g'+b]) {
var sArray = new Array(), j = 0, g = 'g'+b;
while (P[g]['v'+(++j)]) {
var n = P[g]['v'+j];
if (typeof(n) == 'string')
sArray[sArray.length] = n;
else
sArray = sArray.concat(n)
}
this.block(sArray);
}
}
}
var cpm = { block : function() { ACM.block(); } }
ACM.blockFromCreative = function(n) {
if (arguments.length < 2) return;
var arr = new Array();
for (var i = 1; i < arguments.length; i++)
arr[(i-1)] = arguments[i];
if (ACM_Vehicles[n]) {
ACM_Vehicles[n].block = arr;
}
}
ACM.pBlock = function(key) {
if (window.ACM_PBlock && ACM_PBlock[key])
this.block(ACM_PBlock[key]);
}
ACM.writeJSTag = function(v) {
var adTag, rnd = Math.round(Math.random()*10000000);
this.ord = (this.ord) ? this.ord : rnd;
this.tile = (ACM_Types[v.type]==1100)?4:(ACM_Types[v.type]==1150)?6:(ACM_Types[v.type]==1200)?5:(ACM_Types[v.type]==1300)?3:'';
if (v.local || ACM_Debug) adTag = '/js/acm/'+ACM_Types[v.type]+'x'+v.id+'.js?rnd='+rnd;
else {
adTag =  'http://ad.doubleclick.net/adj/'+this.site+'/';
adTag += (this.page) ? this.page : '';
adTag += ';area=';
adTag += (this.area) ? this.area : '.';
adTag += ';sz='+ACM_Types[v.type]+'x'+v.id;
adTag += (this.tile) ? ';tile='+this.tile : 'noTile:'+this.tile;
adTag += ';ord='+this.ord+'?';
}
document.write('<script language="javascript" src="'+adTag+'"><\/script>');
}
ACM.setHTML = function(v,h) {
if (ACM_Vehicles[v])
ACM_Vehicles[v].html = h;
}
ACM.setEvent = function(v,e) {
if (ACM_Vehicles[v])
ACM_Vehicles[v].events = e;
}
ACM.setUnloadEvent = function(e) {
if (this.unloadEvents)
this.unloadEvents = this.unloadEvents[this.unloadEvents.length] = e;
else
this.unloadEvents = [e];
}
ACM.setLoadedFlag = function(v) {
if (ACM_Vehicles[v])
ACM_Vehicles[v].loaded = true;
}
ACM.setEmptyAd = function(v) {
if (ACM_Vehicles[v])
ACM_Vehicles[v].freq = 0;
}
ACM.setParam = function(n,v) {
if (!n || !v || !Cookie.isEnabled) return;
this[n] = v;
}
ACM.setTrackerCode = function(v,c,s) {
if (ACM_Vehicles[v]) {
ACM_Vehicles[v].TEC = c;
ACM_Vehicles[v].TESC = s;
}
}
ACM.setNSSize = function() { return; }
ACM.setNSDiv  = function() { return; }
ACM.debug = function() {
var V = ACM_Vehicles, P = ACM_Profile;
var html = '<pre>';
html += '<b>Vehicle Settings</b>\n\n';
for (var k in V) {
html += k+': ( ';
for (var p in V[k]) { html += (p != 'html') ? p+'='+V[k][p]+' ' : ''; }
html += ')\n';
}
html += '\n<b>Group Settings</b>\n\n';
html += 'Page Cap: '+P.pageCap+'\n';
html += 'Session Timeout: '+P.sessionTimeout+'\n';
var i = 0;
while (P['g'+(++i)]) {
var g = P['g'+i], j = 0;
html += 'Group '+i+' (frequency = '+g.frequency+') =';
while (g['v'+(++j)]) {
var v = g['v'+j];
html += '\n &nbsp; &nbsp;'+j+' - ';
html += (typeof(v) == 'object') ? '['+v+']' : v;
}
html += '\n';
}
html += '\n<b>Validated on this Page</b>\n\n';
for (var i = 0; i < this.viewable.length; i++) html += (i+1)+') '+this.viewable[i]+'\n';
html += '\n<b>Cookie</b>\n\n';
html += this.cookie;
html += '</pre>';
var w = new ChildWindow({ html:html, width:600, height:600, scrollbars:true });
}
ACM.unload = function() {
var e = this.unloadEvents;
if (e) {
for (var i = 0; i < e.length; e++){
eval(e[i]);
}
}
}