// find page type
var queries=OAS_query.split('&'),page_type='';
for(var q=0;q<queries.length;q++){
	var query=queries[q].split('=');
	if(query[0]=='pagetype'){page_type=query[1];break;}
	}
if (page_type=='article_page'){
	var suffix='_article';
	}
	else if (page_type=='photo_gallery'){
	var suffix='_gallery';
	}
	else
	{
	var suffix='_other';
	}

//now find the section from oas: split the sitepage, then match the big list
var spsplit=OAS_sitepage.split('/');
if(spsplit.length>2) {var section=spsplit[1]+'_'+spsplit[2]}
else {var section=spsplit[1]}

// adjust a couple of names
if (section =='travel_NET') {section='travel_newengland'}
else if (spsplit[1]=='bostonworks') {spsplit[1]='jobs'}
else if (spsplit[2]=='redsox') {section='sports_baseball'}
else if (spsplit[2]=='patriots') {section='sports_football'}
else if (spsplit[2]=='celtics') {section='sports_basketball'}
else if (spsplit[2]=='bruins') {section='sports_hockey'}
else if (spsplit[2]=='hyperlocal') {section='yourtown'}
else if (spsplit[2]=='dining') {section='ae_restaurants'}
else if (spsplit[2]=='family') {section='lifestyle_moms'}
else if (spsplit[2]=='health') {section='news_health'}
else if (spsplit[1]=='yourlife') {section='lifestyle_'+spsplit[2];spsplit[1]='lifestyle';}
var validchannels = "news|news_local|news_globe|news_nation|news_health|news_science|news_world|news_politics|news_education|business|business_finance|business_technology|sports|sports_baseball|sports_football|sports_basketball|sports_hockey|sports_soccer|sports_college|sports_highschool|lifestyle|lifestyle_home|lifestyle_green|lifestyle_food|lifestyle_relationships|lifestyle_weddings|lifestyle_moms|lifestyle_fashion|lifestyle_photos|ae|ae_restaurants|ae_music|ae_movies|ae_celebrity|ae_tv|ae_books|ae_arts|thingstodo|travel|travel_newengland|travel_boston|travel_getaways|cars|cars_news|cars_research|jobs|realestate|realestate_news|yourtown|obituaries|weather";
var channel = validchannels.match(section);

//backup tries
if (channel==null) {channel = validchannels.match(spsplit[1])}
if (channel==null) {channel = 'other'}

var google_ad_channel=channel+suffix,google_hints='',ad_test='';
//odd cases
if (spsplit[2]=='bigpicture') {google_ad_channel = 'bigpicture';}
else if (spsplit[1]=='weather') {google_ad_channel = 'weather';}
else if (document.location.search.indexOf("comments=all")!=-1) {google_ad_channel +=", community_comments";}
else if (document.location.href.indexOf("forums.html")!=-1) {google_ad_channel ="community_forums";}
function google_ad_request_done(ads)
{
var s='';
if(ads.length==0)
	return;
//alert (ad_test);
if (ad_test=='nogray')
{s += '<!--[if IE 6]><style>#adSenseHeaderGrayN { height: 100%; clear: both; }</style><![endif]--><div id="adSenseContainerN"><div id="adSenseHeaderGrayN"><div class="adsByN">Ads by Google</div><div class="whatIsN"><a href="http://www.boston.com/help/linksqa_text/" onClick="window.open(\'\',\'popupad\',\'width=400,height=400,resizable=yes,scrollbars=yes,toolbar=no,location=no,menubar=no,status=no\')" target="popupad" class="et">what\'s this?</a></div></div><div id="adSenseActual">';
}
else if (ad_test=='reverse' || ad_test=='reverselinkcolor')
{
s += '<!--[if IE 6]><style>#adSenseHeaderGrayR { height: 100%; clear: both; }</style><![endif]--><div id="adSenseContainerR"><div id="adSenseHeaderGrayR"><div class="adsByR">Ads by Google</div><div class="whatIsR"><a href="http://www.boston.com/help/linksqa_text/" onClick="window.open(\'\',\'popupad\',\'width=400,height=400,resizable=yes,scrollbars=yes,toolbar=no,location=no,menubar=no,status=no\')" target="popupad" class="et">what\'s this?</a></div></div><div id="adSenseActualR">';
}
else
{
s += '<div id="adSenseContainer"><div id="adSenseHeaderGray"><div class="adsBy">Ads by Google</div><div class="whatIs"><a href="http://www.boston.com/help/linksqa_text/" onClick="window.open(\'\',\'popupad\',\'width=400,height=400,resizable=yes,scrollbars=yes,toolbar=no,location=no,menubar=no,status=no\')" target="popupad" class="et">what\'s this?</a></div></div><div id="adSenseActual">';
}

for(var i=0;i<ads.length;++i)
{
if (ad_test=='reverse')
	{
	s+='<div class="adWrapR" ><a id="aw0" class="adUrlR" target="_blank" href="'+ads[i].url+'"><b>'+ads[i].line1+'</b></a><br><div class="adBodyR" onClick="window.open(\'' + ads[i].url + '\',\'popupad\',\'\');">'+ads[i].line2+' '+ads[i].line3+'</div>'+'<a id="aw0" class="adUrlR" target="_blank" href="' + ads[i].url + '">' + ads[i].visible_url+'</a></div>';
	}
else if (ad_test=='reverselinkcolor')
	{
	s+='<div class="adWrapR" ><a id="aw0" class="adUrl" target="_blank" href="'+ads[i].url+'"><b>'+ads[i].line1+'</b></a><br><div class="adBody" onClick="window.open(\'' + ads[i].url + '\',\'popupad\',\'\');">'+ads[i].line2+' '+ads[i].line3+'</div>'+'<a id="aw0" class="adUrl" target="_blank" href="' + ads[i].url + '">' + ads[i].visible_url+'</a></div>';
	}
else
	{
	s+='<div class="adWrap" ><a id="aw0" class="adUrl" target="_blank" href="'+ads[i].url+'"><b>'+ads[i].line1+'</b></a><br><div class="adBody" onClick="window.open(\'' + ads[i].url + '\',\'popupad\',\'\');">'+ads[i].line2+' '+ads[i].line3+'</div>'+'<a id="aw0" class="adUrl" target="_blank" href="' + ads[i].url + '">' + ads[i].visible_url+'</a></div>';
	}	}
s+='</div></div>';
document.write(s);
return;
}
var google_ad_output='js',google_max_num_ads='3',google_ad_client='ca-boston_js',google_safe='high',google_ad_section='default';
//section-specific changes
switch(section){
case 'sports_baseball':google_hints='MLB Merchandise, Red Sox,-Yankees';break;
case 'weather':google_hints='Travel';break;
case 'lifestyle_moms':google_max_num_ads='4';break;
case 'lifestyle_food':google_hints='recipes';break;
case 'bigpicture':google_hints='photography';break;
case 'sports_highschool':google_max_num_ads='2';
case 'yourtown':google_hints=trustedTown + ', MA';
}
//start test
if ((google_ad_channel=='lifestyle_food_article') || (google_ad_channel=='news_local_article'))
	{if (Math.random() > .5)
		{google_ad_channel +=', test6';
		} else {
		google_ad_channel +=', test7';ad_test='food';
		}
	}
if (ad_test=='')
	{z = Math.random();
	if (z < .5)
		{ad_test='reverselinkcolor';google_ad_channel +=', test2';}
	else
		{google_ad_channel +=', test1';}
	}