/* Revised ORD version of old http://images.oprah.com/javascripts/ad_top_include.js */

function getadcookie(cookiename) {
	var cookiestring=""+document.cookie;
	var index1=cookiestring.indexOf(cookiename);
	if (index1==-1 || cookiename=="") return "";
	var index2=cookiestring.indexOf(';',index1);
	if (index2==-1) index2=cookiestring.length;
	return unescape(cookiestring.substring(index1+cookiename.length+1,index2));
}
profilecookie = (getadcookie("ADC"));

adtagcontent1 = 'dummyad1';
adtagcontent2 = 'dummyad2';
adtagcontent3 = 'dummyad3';
adtagcontent4 = 'dummyad4';

var metas = document.getElementsByTagName('META');
var i;
for (i = 0; i < metas.length; i++) {
	if (metas[i].getAttribute('NAME') == "adtag1")
	adtagcontent1 = metas[i].getAttribute('CONTENT');  
	else if (metas[i].getAttribute('NAME') == "adtag2")
	adtagcontent2 = metas[i].getAttribute('CONTENT');  
	else if (metas[i].getAttribute('NAME') == "adtag3")
	adtagcontent3 = metas[i].getAttribute('CONTENT');  
	else if (metas[i].getAttribute('NAME') == "adtag4")
	adtagcontent4 = metas[i].getAttribute('CONTENT');  
}
  
var kw='';
if (adtagcontent1 != null) {
	if (adtagcontent1.indexOf("&") > -1) {
		temp1 =adtagcontent1.split("&");
		for (i=0; i<temp1.length;i++) {
			kw=kw+"adkw="+temp1[i]+";";
		}
	}
	else
		kw=kw+"adkw="+adtagcontent1+";";
}
if (adtagcontent2 != null) {
	if (adtagcontent2.indexOf("&") > -1) {
		temp1 =adtagcontent2.split("&");
		for (i=0; i<temp1.length;i++) {
			kw=kw+"adkw="+temp1[i]+";";
		}
	}
	else
		kw=kw+"adkw="+adtagcontent2+";";
}
if (adtagcontent3 != null) {
	if (adtagcontent3.indexOf("&") > -1) {
		temp1 =adtagcontent3.split("&");
		for (i=0; i<temp1.length;i++) {
			kw=kw+"adkw="+temp1[i]+";";
		}
	}
	else
		kw=kw+"adkw="+adtagcontent3+";";
}
if (adtagcontent4 != null) {
	if (adtagcontent4.indexOf("&") > -1) {
		temp1 =adtagcontent4.split("&");
		for (i=0; i<temp1.length;i++) {
			kw=kw+"adkw="+temp1[i]+";";
		}
	}
	else
		kw=kw+"adkw="+adtagcontent4+";";
}

posarray=new Array(12);
for (i=0; i <12; i++)
posarray[i]=new  Array(2);
posarray[0][0]="Index"; 					posarray[0][1]="184x90";  // index page header ad
posarray[1][0]="Leaderboard"; 		posarray[1][1]="728x90";  // header banner ad, pre-HD full-page video companion
posarray[2][0]="Island"; 					posarray[2][1]="300x250"; // island ad
posarray[3][0]="Skyscraper"; 			posarray[3][1]="160x600"; // skyscraper/tower ad, pre-HD full-page video companion
posarray[4][0]="Package";					posarray[4][1]="104x66";  // sponsor ad in package header
posarray[5][0]="SponsorPageTool";	posarray[5][1]="100x35";  // sponsor ad in page tools on section banner
posarray[6][0]="SponsorFeatured";	posarray[6][1]="115x125"; // featured sponsor ad
posarray[7][0]="VideoCompanion";	posarray[7][1]="234x60";  // pre-HD inline video companion, post-HD inline and full-page video companion
posarray[8][0]="Leaderboard2"; 		posarray[8][1]="728x90";  // footer banner ad
posarray[9][0]="pop"; 						posarray[9][1]="728x90";  // banner ad in popup slideshows
posarray[10][0]="print";					posarray[10][1]="468x60"; // half-ad for printable pages
posarray[11][0]="Island2"; 				posarray[11][1]="300x250"; // island ad for middle of slideshows

//configuration
OAS_sitepage1 = location.pathname;
OAS_sitepage = 'www.oprah.com' + OAS_sitepage1;

//random numbers
OAS_rn = '001234567890';
OAS_rns = '1234567890';
OAS_rn = new String (Math.random()); 
OAS_rns = OAS_rn.substring (2, 11);

//DART_URL='http://ad.doubleclick.net/adj';
page='';
site='';
zone='';
tile=0;
getSite();

function getTILE() {
	tile=tile+1;
	return tile;
}

function isFirstCharNumber(s) { //Cant have number after / for zone
	var i;
	var c = s.charAt(0); // Check that current character is number
	if (((c < "0") || (c > "9"))) return false;
	return true; // All characters are numbers.
}
function getSite() {
	if ((OAS_sitepage1 == null)||(OAS_sitepage1 == "")){
	}
	else {
		//for testing, comment out for real
		//OAS_sitepage1 ="/test/test2/2007/index.jhtml";
		//OAS_sitepage1 = "/search.jsp?query=skype+video+calling&resultsPerPage=20&sortBy=Relevancy&filterType=&filterBy=&page=1&x=0&y=0";
		
/* sectarray = root level directories to remove from site path */		
sectarray=new Array(18);
for (i=0; i <18; i++)
sectarray[i]=new  Array(1);
sectarray[0][0]="package";
sectarray[1][0]="subpackage";
sectarray[2][0]="article";
sectarray[3][0]="slideshow";
sectarray[4][0]="recipe";
sectarray[5][0]="menu";
sectarray[6][0]="survey";
sectarray[7][0]="workbook";
sectarray[8][0]="contributor";
sectarray[9][0]="contributorblog";
sectarray[10][0]="topics";
sectarray[11][0]="subtopic";
sectarray[12][0]="dated";
sectarray[13][0]="magazine";
sectarray[14][0]="magazinetoc";
sectarray[15][0]="datedcontent";
sectarray[16][0]="entity";
sectarray[17][0]="editorialsweeps";
	
		page1= OAS_sitepage1.substring(1);
		//alert("page1 : " +page1);
		var temp =page1.split("/");
		for(i=0; i<18; i++){
					if (sectarray[i][0] == temp[0]){
					var skip = true;
					break;
					}
				}
		//alert(skip);
		//alert(temp.length);
			if (temp.length >= 4) {
					if (skip == true){
						site = 'o.'+temp[1];
						if (isFirstCharNumber(temp[2])){
									temp[2]='_'+temp[2];
									}
						if (isFirstCharNumber(temp[3])){
									temp[3]='_'+temp[3];
									}
						zone='/'+temp[2]+'/'+temp[3];
						}
					else if (temp[0] == 'ads'){
						site = 'o.ads';
						if (isFirstCharNumber(temp[1])){
									temp[1]='_'+temp[1];
									}
						if (isFirstCharNumber(temp[2])){
									temp[2]='_'+temp[2];
									}
						if (isFirstCharNumber(temp[3])){
									temp[3]='_'+temp[3];
									}
						if (temp[3].indexOf(".") > -1){
							var str=new String(temp[3]);
							temp[3]=str.substring(0,temp[3].indexOf("."));
							zone ='/'+temp[1]+'/'+temp[2]+'/'+temp[3];
							}
						else {
							zone='/'+temp[1]+'/'+temp[2];
							}
					}
					else if (temp[0] == 'comments'){
						site = 'o.'+temp[2];
						if (isFirstCharNumber(temp[2])){
									temp[2]='_'+temp[2];
									}
						if (isFirstCharNumber(temp[3])){
									temp[3]='_'+temp[3];
									}
						if (temp[4]){
							if (isFirstCharNumber(temp[4])){
										temp[4]='_'+temp[4];
										}
							if (temp[4].indexOf(".") > -1){
								var str=new String(temp[4]);
								temp[4]=str.substring(0,temp[4].indexOf("."));
								zone ='/'+temp[2]+'/'+temp[3]+'/'+temp[4];
								}
							}
						else {
							zone='/'+temp[2]+'/'+temp[3];
							}
					                }
					else {
						site ='o.'+temp[0];
						if (isFirstCharNumber(temp[1])){
									temp[1]='_'+temp[1];
									}
						if (isFirstCharNumber(temp[2])){
									temp[2]='_'+temp[2];
									}
						if (temp[2].indexOf(".") > -1){
							zone ='/'+temp[1];
							}
						else {
							zone='/'+temp[1]+'/'+temp[2];
							}
						}
					}
			else if (temp.length == 3) {
					if (skip == true) {
						if (isFirstCharNumber(temp[2])){
									temp[2]='_'+temp[2];
									}
						site ='o.'+temp[1]+'/'+temp[2];
						}
					else if (temp[0] == 'ads'){
						site = 'o.ads';
						if (isFirstCharNumber(temp[1])){
									temp[1]='_'+temp[1];
									}
						if (isFirstCharNumber(temp[2])){
									temp[2]='_'+temp[2];
									}
						if (temp[2].indexOf(".") > -1){
							var str=new String(temp[2]);
							temp[2]=str.substring(0,temp[2].indexOf("."));
							zone ='/'+temp[1]+'/'+temp[2];
							}
						else {
							zone='/'+temp[1];
							}
					}
					else if (temp[0] == 'comments'){
						site = 'o.'+temp[2];
						if (isFirstCharNumber(temp[2])){
									temp[2]='_'+temp[2];
									}
						if (isFirstCharNumber(temp[3])){
									temp[3]='_'+temp[3];
									}
						if (temp[3].indexOf(".") > -1){
							var str=new String(temp[3]);
							temp[3]=str.substring(0,temp[3].indexOf("."));
							zone ='/'+temp[2]+'/'+temp[3];
							}
						else {
							zone='/'+temp[2];
							}
					}
					
					else {
						site ='o.'+temp[0];
						if (isFirstCharNumber(temp[1])){
								temp[1]='_'+temp[1];
									}
						if (isFirstCharNumber(temp[2])){
									temp[2]='_'+temp[2];
									}
						if (temp[2].indexOf(".") > -1){
							zone ='/'+temp[1];
							}
						else {
							zone='/'+temp[1]+'/'+temp[2];
						}
					}
			}
			else if (temp.length == 2) {
					if (skip == true){
						if (isFirstCharNumber(temp[1])){
								temp[1]='_'+temp[1];
									}
						if (temp[1].indexOf(".") > -1){
							site ='o.'+temp[1].substring(0,temp[1].indexOf("."));
							}
						else {site ='o.'+temp[1];}
						}
					else if (temp[0] == 'ads'){
						site = 'o.ads';
						if (isFirstCharNumber(temp[1])){
									temp[1]='_'+temp[1];
									}
						if (temp[1].indexOf(".") > -1){
							var str=new String(temp[1]);
							temp[1]=str.substring(0,temp[1].indexOf("."));
							zone ='/'+temp[1];
							}
						else {
							
							}
					}
					else if (temp[0] == 'comments'){
						site = 'o.'+temp[2];
						if (isFirstCharNumber(temp[2])){
									temp[2]='_'+temp[2];
									}
						if (temp[2].indexOf(".") > -1){
							var str=new String(temp[2]);
							temp[2]=str.substring(0,temp[2].indexOf("."));
							zone ='/'+temp[2];
							}
						else {
							
							}
					}
					
					else {
						site ='o.'+temp[0];
						if (temp[0].indexOf(".") > -1){
							site ='o.'+temp[0].substring(0,temp[0].indexOf("."));
							}
						if (isFirstCharNumber(temp[1])){
									temp[1]='_'+temp[1];
									}
						if (temp[1].indexOf(".") > -1){
							zone='';
							}
						else {
							zone='/'+temp[1];
							}
						}
					}
			else {
					if (skip == true){ }
					else { 
						if (isFirstCharNumber(temp[0])){
								temp[0]='_'+temp[0];
									}
						if (temp[0].indexOf(".") > -1){
							site ='o.'+temp[0].substring(0,temp[0].indexOf("."));
							}
						else {site ='o.'+temp[0];}
					}
				}
			}
		if (zone == '') { }
		else
		site=site+zone;
		//alert("temp[0] : " +temp[0]);
		//alert("temp[1] : " +temp[1]);
		//alert("temp[2] : " +temp[2]);
		//alert("temp[3] : " +temp[3]);
		//alert("site : " +site);
		//alert("zone : " +zone);
		if (OAS_sitepage1.indexOf('.') != "-1") {
			page=OAS_sitepage1.substring(OAS_sitepage1.lastIndexOf('/')+1,OAS_sitepage1.length);
			ext=page.indexOf('.');
			page=page.substring(0,ext);
		}
		else {
			page = OAS_sitepage1.substring(OAS_sitepage1.indexOf(zone)+zone.length+1);
		}
		//alert("page : " +page);
	}

	var fullpath = new String(location);
	//alert(fullpath);
	//alert("page: " + page);
		if (page == "search") {
			searched= fullpath.substring(fullpath.indexOf("query=")+6,fullpath.indexOf("&"));
			//alert("searched: " + searched);
			searched = searched.toLowerCase();
			kw="kw="+searched+";" + kw;
		}
	
function OAS_NORMAL(pos) {
for(i=0; i<20; i++){
		if (posarray[i][0].indexOf(pos) != -1){
			size = posarray[i][1];
			break;
		}
	}
	if (pos == 'Index') {
		document.write('<scr' + 'ipt src="'+'http://ad.doubleclick.net/adj/o.index;'+kw+';tile='+getTILE()+';sz='+size+';ord='+OAS_rns+'?" type="text/javascript"><\/SCRIPT>');
	}
	else {
		document.write('<scr' + 'ipt src="'+'http://ad.doubleclick.net/adj/'+ site+';'+kw+';page='+page+';tile='+getTILE()+';sz='+size+';pos='+pos+';ord='+OAS_rns+'?" type="text/javascript"><\/script>');
	}
}

function OAS_AD(pos) {
	var homeadstatus=1;
	if (homeadstatus==1) {
		OAS_NORMAL(pos);
	}
}

findhostname=location.hostname;
function GetCookieWWW2(name) {
	var cname = name + "=";
	var dc = document.cookie;
	if (dc.length > 0) {
		begin = dc.indexOf(cname);
		if (begin != -1) {
			return "COOKIEFOUND";
		}
	}
	return "COOKIENOTFOUND";
}

function DelCookieWWW2 (name,path,domain) {
	if (GetCookieWWW2(name) == "COOKIEFOUND") {
		document.cookie = name + "=" +
		((path == null) ? "" : "; path=" + path) +
		((domain == null) ? "" : "; host=" + domain) +
		"; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}

function DelCookieWWW3 (name,path,domain) {
	if (GetCookieWWW2(name) == "COOKIEFOUND") {
		document.cookie = name + "=" +
		((path == null) ? "" : "; path=" + path) +
		((domain == null) ? "" : "; domain=" + domain) +
		"; expires=Thu, 01-Jan-08 00:00:01 GMT";
	}
}

if (findhostname=='www2.oprah.com') {
//DelCookieWWW2('DYN_USER_ID','/');
//DelCookieWWW2('DYN_USER_CONFIRM','/');
//DelCookieWWW3('DYN_USER_ID','/');
//DelCookieWWW3('DYN_USER_CONFIRM','/');
}

/* PNG Capture and Fix */
if (navigator.platform == "Win32" && navigator.appName == "Microsoft Internet Explorer" && window.attachEvent) {
document.writeln('<style type="text/css">#page_tools_ad img,#page_tools_ad2 img,#package_ad img,#minitwix_title img { visibility:hidden; } </style>');
	window.attachEvent("onload", fnLoadPngs);
}

function fnLoadPngs() {
	var rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, '');
	var itsAllGood = (rslt != null && Number(rslt[1]) >= 5.5);

	for (var i = document.images.length - 1, img = null; (img = document.images[i]); i--) {
		if (itsAllGood && img.src.match(/\.png$/i) != null) {
			var src = img.src;
			////alert("src : "+src);
			var div = document.createElement("DIV");
			div.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizing='scale')"
			div.style.width = img.width + "px";
			div.style.height = img.height + "px";
			img.replaceNode(div);
		}
		img.style.visibility = "visible";
	}
}
