var ord = Math.floor(Math.random()*100000000);
ad_debug=false
// DOUBLECLICK (DART) VARIABLES
var site="";
var zone="";
var passed_hash=""
var all_hash="";
var provider="";
var all_hash_set=false;
// END DOUBLECLICK (DART) VARIABLES

// GOOGLE VARIABLES -- DEFAULTS
var google_ad_client = "pub-7893828636899382";
var google_alternate_ad_url_template = "http://ad.doubleclick.net/adi/eons.google/google;sz=widthxheight;ord="+ord+"?";
var google_ad_width = 728;
var google_ad_height = 90;
var google_ad_format = "728x90_as"
var google_ad_type = "text";
var google_ad_channel ="8674095514";

var channel_map=new Array();
channel_map["love"]=			"9455188386";
channel_map["body"]=			"8674095514";
channel_map["bodyhealthology"]=	"4342072021";
channel_map["eons100"]=			"5864210607";
channel_map["fun"]=				"4328971621";
channel_map["funuclick"]=		"3213544646";
channel_map["funreal"]=			"3698226618";
channel_map["homepage"]=		"2259880777";
channel_map["jobs"]=			"6551633179";
channel_map["money"]=			"5669882036";
channel_map["obits"]=			"9590164840";

// END GOOGLE VARIABLES


function render_dart_js(site,zone,hash,size,ptile,ord)
{
    // for now, AMP doesn't support secure calls, so go right to doubleclick
    if (location.href.match(/^https/)) {
        server = "https://ad.doubleclick.net";
    } else {
        server = "http://a.collective-media.net";
    }

    if  (hash!="" && hash.match(/;$/)==null) // TRAC 5911, don't add ';' to empty hash
    {
        hash=hash+";";  // make sure the hash ends with a ;
    }
    var js = '<script src="' + server + '/adj/'+site+'/'+zone+';'+hash+'sz='+size+';tile='+ptile+';ord='+ord+'?" type="text/javascript"><\/script>';
    if (ad_debug==true)
    {
        alert(js);
    }
    document.write(js);
}


function render_google_adsense_js(channel,width,height)
{
	return render_google_js(channel,"as",width,height)
}

function alert_google_variables()
{
	var s= "google_ad_channel:\t"+google_ad_channel+"\n";
	s+= "google_ad_width:\t"+google_ad_width+"\n";
	s+= "google_ad_height:\t"+google_ad_height+"\n";
	s+= "google_ad_format:\t"+google_ad_format+"\n";
	s+= "google_alternate_ad_url_template:\t"+google_alternate_ad_url_template+"\n";
	alert(s);
}

function render_google_js(channel,format,width,height)
{
	if (channel.match(/^[0-9]+$/)==null) // if the channel is a name (not all numbers), look it up in the hash to get the right channel id
	{
		channel=channel_map[channel]
	}
	google_ad_channel=channel;
	google_ad_width=width;
	google_ad_height=height;
	google_ad_format = width+"x"+height+"_"+format;
	tmp=google_alternate_ad_url_template.replace(/width/,width);
	google_alternate_ad_url=tmp.replace(/height/,height);
	if (ad_debug==true)
	{
		alert_google_variables();
	}
    var protocol = 'http';
    if (location.href.match(/^https/)) {
        protocol = 'https';
    }
	var js = '<script src="' + protocol + '://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"><\/script>';
	document.write(js);	
}

function adjust_size(size)
{
       new_size=size;
       if (size=="120x60")
       {
               new_size="220x125";
       }
       return new_size;
}


function dart(_site,_zone,_hash,_provider,size,ptile)
{
	site=_site;
	zone=_zone;
	//site="usmf.cont.mainpage"
	//zone="mainpage"
	provider=_provider;
	if (site=="")
	{
		return;
	}
	// handle erroneous calls with no hash provided.
	if (_hash == null)
	{
		all_hash = "";
	}
	else
	{
		all_hash = _hash;
	}
//	if (all_hashset==false)
	{
		// only populate it once per page
		try
		{
			json = unescape(readCookie('prefs'));
			json = decodeBase64(json);
			//alert("json?:"+json);
			account=eval("("+json+")");
			var values=new Array(account.gender,account.age,account.country,account.zipcode,provider);
			var keys=new Array("g","a","country","zip","prov");
			for (var i=0;i<values.length;i++)
			{
				if (values[i]!=null && values[i]!="")
				{
					
					all_hash+=keys[i]+"="+values[i]+";";
				}
			}
		}
		catch (e)
		{
			//alert(e)
		}
	}
	size=adjust_size(size);
	render_dart_js(site,zone,all_hash,size,ptile,ord);
}

function dart1(site,zone,hash,provider,size) 
{
	passed_hash=hash;
	dart(site,zone,"dcopt=ist;"+hash,provider,size,1);
}

function dartN(_site,_zone,_hash,_provider,_size, _ptile) 
{
	if (_site==null || _site=="") {
		_site = site;
	}
	if (_zone==null || _zone=="") {
		_zone = zone;
	}
	if (_provider==null || _provider=="") {
		_provider  = provider;
	}
	if (_ptile==null || _ptile=="") {
		_ptile = 7;	// this was default for google_lb
	}
	dart(_site,_zone,_hash+passed_hash,_provider,_size,_ptile);
}

function dartBottom(_zone, ptile)
{
	if (_zone== null || _zone=="") {
		_zone = "bottom";	// default zone for bottom banner ad
	}
	dart(site,"bottom",passed_hash,provider,"728x90",ptile);
}

function dart2(size) 
{
	dart(site,zone,passed_hash,provider,size,2);
}

function dart3(size) 
{
	dart(site,zone,passed_hash,provider,size,3);
}

function dart4(size)
{
        dart(site,zone,passed_hash,provider,size,4);
}

function dart5(size)
{
        dart(site,zone,passed_hash,provider,size,5);
}

function dart6(size)
{
        dart(site,zone,passed_hash,provider,size,6);
}

function dart7(size)
{
        dart(site,zone,passed_hash,provider,size,7);
}

function dart10(size)
{
		dart(site,zone,"loc=1;"+passed_hash,provider,size,10)
}

function dart11(size)
{
		dart(site,zone,"loc=2;"+passed_hash,provider,size,11)
}

function dart12(size)
{
		dart(site,zone,"loc=3;"+passed_hash,provider,size,12)
}

function dart13(site,zone,hash,provider,size) 
{
		dart(site,zone,"loc=3;"+passed_hash,provider,size,12)
}


function eons_picks()
{
	document.write("<h3>Eons Picks</h3>");
	dart14("1x5");
	dart15("1x5");
	dart16("1x5");
}

function dart14(size) 
{
		dart(site,zone,"loc=1;"+passed_hash,provider,size,13);
}

function dart15(size) 
{
		dart(site,zone,"loc=2;"+passed_hash,provider,size,14);
}

function dart16(size) 
{
		dart(site,zone,"loc=3;"+passed_hash,provider,size,15);
}




/*
bodyhealthology= dartsite: "eons.body" dartzone: "bottomhealthology"

eons100: dartsite= "eons.eons100" dartzone: "bottom"

fun: dartsite= "eons.fun" dartzone: "bottom"

funuclick: dartsite= "eons.fun" dartzone: "bottomuclick"

funreal: dartsite= "eons.fun" dartzone: "bottomreal"
*/

function translate_google_channel_to_dart_zone(channel)
{
	zone="bottom"
    // jjn added this
	if (channel=="lifepath")
	{
		zone="lifepath_bottom";
        return zone;
	}
    // end jjn added
	if (channel.match(/^[0-9]+$/)==null) // if the channel is a name (not all numbers), look it up in the hash to get the right channel id
	{
		channel=channel_map[channel]
	}
	if (channel=="healthology")
	{
		zone="bottomhealthology"
	}
	if (channel=="funuclick")
	{
		zone="bottomuclick"
	}
	if (channel=="funreal")
	{
		zone="bottomreal"
	}
	return zone;
}

function google_mu(channel)
{
	zone=translate_google_channel_to_dart_zone(channel);
	dart(site,zone,passed_hash,provider,"300x250",6);
//	render_google_adsense_js(channel,300,250);
}

function google_lb(channel,hash)
{
	passed_hash=hash;
	zone=translate_google_channel_to_dart_zone(channel);
	dart(site,zone,passed_hash,provider,"728x90",7)
//	render_google_adsense_js(channel,728,90);
}



//		var js = '<script src="http://ad.doubleclick.net/adj/usmf.cont.mainpage/mainpage;dcopt=ist;pos=top;seg=v;src=;sz=728x90;ptile=1;ord=5?" type="text/javascript"><\/script>';
/*
var js = 
"<script>document.write \
	('<script language=\"JavaScript\" \
	type=\"text/javascript\" \
	src=\"http://ad.doubleclick.net/adj/usmf.cont.mainpage/mainpage;dcopt=ist;pos=top;seg=v;src=;sz=728x90;ptile=1;ord=' \
	+ Math.floor(Math.random()*100000000) +'?\"><\/script>');</script>";
*/





