function setSourcepopup(dest){
ID="TDWsite"; //default
URLArg = parent.location.search;
CkID="";
UrlID="";

//do cookie also
	CkID = GetCookie('Banner');
	if (!CkID)
	{
	sourceID = GetCookie('Referrer');
	if (sourceID) {
		CkID=setID(sourceID); // setID is set in each html page or may be undefined
	}
	}
	if (URLArg)  {  // if there's a search argument in URL check it too
		UrlID=sourceParm(URLArg);
	}

if (!UrlID && CkID) {ID=CkID;} //if no URL ID, use cookie ID
if (UrlID && !CkID) {ID=UrlID;} //if no cookie ID, use URL ID
if (UrlID && CkID) {ID=UrlID}; //if both URL ID and cookie ID, use URL ID

if (ID) {

		dest = dest + "?source=" + ID;
}

window.open (dest);

return true;
} // end setSource
function setSource(dest){
ID="TDWsite"; //default
URLArg = parent.location.search;
CkID="";
UrlID="";

//do cookie also
	CkID = GetCookie('Banner');
	if (!CkID)
	{
	sourceID = GetCookie('Referrer');
	if (sourceID) {
		CkID=setID(sourceID); // setID is set in each html page or may be undefined
	}
	}
	if (URLArg)  {  // if there's a search argument in URL check it too
		if(URLArg.indexOf("source=") != -1) {
			UrlID=sourceParm(URLArg);
		}
	}

if (!UrlID && CkID) {ID=CkID;} //if no URL ID, use cookie ID
if (UrlID && !CkID) {ID=UrlID;} //if no cookie ID, use URL ID
if (UrlID && CkID) {ID=UrlID}; //if both URL ID and cookie ID, use URL ID

if (ID) {

		window.location.href = dest + "?source=" + ID;
}else{
		window.location.href = dest;
}

return true;
} // end setSource
function setID(refURL) {
ID="TDWsite"; //default
var goldURL = document.location.href;
	if ( goldURL.indexOf("Channel") != -1) {
		ID = "gold";
	}else {
			if ( refURL.indexOf("tdcanadatrust.com") != -1 ) {
						ID = "TDCTsite";
	}else {
			if ( refURL.indexOf("www.tdwaterhouse.ca/") != -1 ) {
				ID = "TDWSite";

	}else {
				ID = "TDWsite";
				}
	}
	if (refURL.indexOf("easyweb.tdcanadatrust.com") != -1 ) { ID="WBS"; return ID;}
	if (refURL.indexOf("toronto.com") != -1 ) {ID="TOR";return ID;}
	if (refURL.indexOf("www.sympatico.ca") != -1 ) {ID="SYM";return ID;}
	if (refURL.indexOf("www.canada.com") != -1 ) {ID="CAN";return ID;}
	if (refURL.indexOf("www.fundlibrary.com") != -1 ) {ID="FND";return ID;}
	if (refURL.indexOf("www.quicken.ca") != -1 ) {ID="QUI";return ID;}
	if (refURL.indexOf("//www/V3/ads") != -1 ) {ID="HOM";return ID;}
	if (refURL.indexOf("uwo") != -1 ) {ID="UWO";return ID;}
	if (refURL.indexOf("utoronto") != -1 ) {ID="UTORONTO";return ID;}
	if (refURL.indexOf("yorku") != -1 ) {ID="YORKU";return ID;}
	if (refURL.indexOf("carletonu") != -1 ) {ID="CARLETONU";return ID;}
	if (refURL.indexOf("hrpao") != -1 ) {ID="HRPAO";return ID;}
	if (refURL.indexOf("queensu") != -1 ) {ID="QUEENSU";return ID;}
	if (refURL.indexOf("uvictoria") != -1 ) {ID="UVICTORIA";return ID;}
	if (refURL.indexOf("uwindsor") != -1 ) {ID="UWINDSOR";return ID;}
	if (refURL.indexOf("canoe") != -1 ) {ID="MON";return ID;}   //Canoe Money
	if (refURL.indexOf("Money") != -1 ) {ID="MON";return ID;}
	if (refURL.indexOf("investorrally") != -1 ) { ID="RAL"; return ID;}
	if (refURL.indexOf("moneyin/waterhouse/") != -1 ) { ID="MIC"; return ID;}
// external banner campaign tracking
	if (refURL.indexOf("/easyweb5/showmemore/all_investments.jsp") != -1 ) { ID="EBUSDEV1"; return ID;}
	if (refURL.indexOf("EBUSDEV1") != -1 ) { ID="EBUSDEV1"; return ID;}
	if (refURL.indexOf("EBUSDEV2") != -1 ) { ID="EBUSDEV2"; return ID;}
	if (refURL.indexOf("EBUSDEV3") != -1 ) { ID="EBUSDEV3"; return ID;}
	if (refURL.indexOf("EBUSDEV4") != -1 ) { ID="EBUSDEV4"; return ID;}
	if (refURL.indexOf("EBUSDEV5") != -1 ) { ID="EBUSDEV5"; return ID;}
	if (refURL.indexOf("EBUSDEV6") != -1 ) { ID="EBUSDEV6"; return ID;}
	}
//if cookie value carried source=3577:WB3577xx type value, use that but chg to 3 char value

	if (refURL.indexOf("WB3577") != -1) {
		WBsource=refURL.slice(refURL.indexOf("3577:WB3577"));
		if (WBsource.indexOf("WB357703") != -1 ) {ID="TCD";return ID;}
	}
return ID;
} // end setID