/* REFERALS [ show link back to ] */

/* : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : set variables
- examples:
	var theDomain --> [ http://alias.discovery.com ]
	var theLocalPath --> [ /root/dir/dir/page.html ]
	var theLocalSearch --> [ ?name=value&name=value.... ]
*/
var theDomain = window.location.hostname.toLowerCase();
var theLocalPath = window.location.pathname;
var theLocalSearch = window.location.search;

var networkAlias = new Array(["animal","apl","n=200"],["dsc","dsc","n=400"],["health","dhc","n=300"],["tlc","tlc","n=500"],["travel","trv","n=600"],["home","hom","n=UNKNOWN"],["science","sci","n=UNKNOWN"],["times","dtc","n=UNKNOWN"],["military","mil","n=UNKNOWN"],["fittv","fit","n=UNKNOWN"],["dhd","dhd","n=UNKNOWN"],["enespanol","esp","n=UNKNOWN"],["www","www","n=100"],["kids","kid","n=UNKNOWN"],["highspeed","high","n=UNKNOWN"],["dev-01","dhc","n-300"]);
var myDiscoAlias = new Array(["my.animal","apl"],["my.dsc","dsc"],["my.health","dhc"],["my.tlc","tlc"],["my.travel","trv"],["my.home","hom"],["my.science","sci"],["my.times","dtc"],["my.military","mil"],["my.fittv","fit"],["my.dhd","dhd"],["my.enespanol","esp"],["my.discovery","dsc"],["my.kids","kid"],["my.highspeed","high"],["dev-01","dhc"]);

var targetPosition = "default";
var localPage = 0;


/* : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : functions [ test ]
- read:
	the domain for test :: [ (!= -1) is (true) ]
*/
/* infopop */
if ((theDomain.indexOf(".infopop.net") != -1) || (theDomain.indexOf(".groupee.net") != -1)) { targetPosition = "infopop"; }

/* cheetahmail */
if (theDomain.indexOf(".cheetahmail.com") != -1) {
	targetPosition = "cheetahmail";
	for (cb = 0; cb < networkAlias.length; cb++) {
		if (theLocalSearch.indexOf(networkAlias[cb][2]) != -1) { break; }
	}
}

/* d.com domain [ all ] */
if (theDomain.indexOf(".discovery.com") != -1) {
	targetPosition = "default";
	for (ma = 0; ma < networkAlias.length; ma++) {
		if (theDomain.indexOf("community.") != -1) { targetPosition = "infopop"; break; }
		if (theDomain.indexOf(networkAlias[ma][0]) != -1) { break; }
	}
}

/* d.com domain [ my ] */
if (theDomain.indexOf("my") != -1) {
	targetPosition = "default";
	for (ma = 0; ma < myDiscoAlias.length; ma++) {
		if (theDomain.indexOf(myDiscoAlias[ma][0]) != -1) { break; }
	}
}

/* d.com domain [ poll ] */
if (theDomain.indexOf("poll.discovery.com") != -1) {
	targetPosition = "polls";
	for (po = 0; po < networkAlias.length; po++) {
		if (theLocalSearch.indexOf(networkAlias[po][1]) != -1) { break; }
	}
}

/* d.com domain [ search ] */
if (theDomain.indexOf("search.discovery.com") != -1) {
	targetPosition = "search";
	for (sa = 0; sa < networkAlias.length; sa++) {
		if (theLocalSearch.indexOf(networkAlias[sa][1]) != -1) { break; }
	}
}

/* d.com domain [ kids ] */
if (theDomain.indexOf("kids.discovery.com") != -1) { targetPosition = "kids"; }


/* apl specific [  Pets911  ] */
if (theDomain.indexOf("pets911.com") != -1) { targetPosition = "thirdParty"; localPage = 0; }

/* trv specific [ away, oanda, wow, onetravel ] */
if (theDomain.indexOf("adventure.discovery.com") != -1) { targetPosition = "thirdParty"; localPage = 4; }
if (theDomain.indexOf("oanda.com") != -1) { targetPosition = "thirdParty"; localPage = 4; }
if ((theDomain.indexOf("whatsontheplanet.com") != -1) || (theDomain.indexOf("travelevents.discovery.com") != -1)) { targetPosition = "thirdParty"; localPage = 4; }
if (theDomain.indexOf("onetravel.com") != -1) { targetPosition = "thirdParty"; localPage = 4; }
if (theDomain.indexOf("seeamerica.org") != -1) { targetPosition = "thirdParty"; localPage = 4; }
if (theDomain.indexOf("igougo.com") != -1) { targetPosition = "thirdParty"; localPage = 4; }

/* dhc specific [ nbc, centerwatch, foodfit, healthgrade, in2nutrition, nexcura, queendom, ediets, wishoo ] */
if (theDomain.indexOf("bodychallenge.") != -1) { targetPosition = "thirdParty"; localPage = 2; }
if (theDomain.indexOf("ediets.") != -1) { targetPosition = "thirdParty"; localPage = 2; }
if (theDomain.indexOf("wishoo.") != -1) { targetPosition = "thirdParty"; localPage = 2; }
if (theDomain.indexOf("centerwatch.com") != -1) { targetPosition = "thirdParty"; localPage = 2; }
if (theDomain.indexOf("foodfit.com") != -1) { targetPosition = "thirdParty"; localPage = 2; }
if (theDomain.indexOf("happyneuron.com") != -1) { targetPosition = "thirdParty"; localPage = 2; }
if (theDomain.indexOf("healthgrades.com") != -1) { targetPosition = "thirdParty"; localPage = 2; }
if (theDomain.indexOf("nexcura.com") != -1) { targetPosition = "thirdParty"; localPage = 2; }
if (theDomain.indexOf("queendom.com") != -1) { targetPosition = "thirdParty"; localPage = 2; }

/* esp specific [ kaleidoscope ] */
if (theDomain.indexOf("channelfinder.net") != -1) { targetPosition = "thirdParty"; localPage = 11; }

/* other specific */
if (theDomain.indexOf("dev-01.") != -1) { targetPosition = "thirdParty"; localPage = 2; }


/* : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : functions [ case ]
- output: document.write(<a ...><img ... /></a>);
*/
function dcomDocWrite (btPosition, track, local) {
	if (track && !local) { document.write("<a onclick=\"trackLink('" + networkAlias[btPosition][1] + ",tophat/dcomhome_button');\" href=\"http://www.discovery.com\" target=\"_top\"><img name=\"dcomoff\" src=\"http://" + networkAlias[btPosition][0] + ".discovery.com/common/sgallery/" + networkAlias[btPosition][1] + "/tophat810/dcomoff.gif\" width=\"165\" height=\"20\" border=\"0\" alt=\"discovery.com home\" /></a>"); }
	else if (track && local) { document.write("<a onclick=\"trackLink('" + networkAlias[btPosition][1] + ",tophat/dcomhome_button');\" href=\"http://www.discovery.com\" target=\"_top\"><img src=\"/common/sgallery/" + networkAlias[btPosition][1] + "/tophat810/dcomoff.gif\" width=\"165\" height=\"20\" border=\"0\" alt=\"discovery.com home\" /></a>"); }
	else { document.write("<a href=\"http://www.discovery.com\" target=\"_top\"><img src=\"http://" + networkAlias[btPosition][0] + ".discovery.com/common/sgallery/" + networkAlias[btPosition][1] + "/tophat810/dcomoff.gif\" width=\"165\" height=\"20\" border=\"0\" alt=\"discovery.com home\" /></a>"); }
}

switch (targetPosition) {
	case "infopop" :
		/*	var netURLString --> [ /utilities/js/forums.js ] in <head> --> [ http://alias.discovery.com ]
			var netAbbr --> [ /utilities/js/forums.js ] in <head> --> [ dsc ]	*/
		document.write("<a onclick=\"trackLink('" + netAbbr + ",tophat/dcomhome_button');\" href=\"http://www.discovery.com\" target=\"_top\"><img src=\"" + netURLString + "/common/sgallery/" + netAbbr + "/tophat810/dcomoff.gif\" width=\"165\" height=\"20\" border=\"0\" alt=\"discovery.com home\" /></a>");
		break;
		
	case "kids" :
		document.write("<a onclick=\"trackLink('kid,tophat/dcomhome_button');\" href=\"http://kids.discovery.com/utilities/jumppage.html?url=http://www.discovery.com\" target=\"_top\"><img src=\"http://kids.discovery.com/common/sgallery/kid/tophat810/dcomoff.gif\" width=\"165\" height=\"20\" border=\"0\" alt=\"discovery.com home\" /></a>");
		break;
	
	case "cheetahmail" : dcomDocWrite(cb, true, false); break;
	case "polls" : dcomDocWrite(po, true, false); break;	
	case "search" : dcomDocWrite(sa, true, false); break;
	case "thirdParty" : dcomDocWrite(localPage, false, false); break;
	
	default :  dcomDocWrite(ma, true, true); break;
}


/* END REFERALS */
