function setSource(dest){
URLArg = location.search

if (URLArg)  {  // if there's a search argument in URL check it first
	ID=sourceParm(URLArg);
}else{  //go cookie route
	sourceID = GetCookie('Referrer')
	if (sourceID) {
		ID=setID(sourceID); // setID is set in each html page or may be undefined
	}
}
if (ID) {
		window.location.href = dest + "?source=" + ID;
}else{
		window.location.href = dest;
}

return true;
} // end setSource

function setAndSource(dest){
URLArg = location.search

if (URLArg)  {  // if there's a search argument in URL check it first
	ID=sourceParm(URLArg);
}
if (ID) {
		window.location.href = dest + "&source=" + ID;
}else{
		window.location.href = dest;
}

return true;
} // end setAndSource


function setSourceTDins(dest, otherargs){
	ExtArg = false
	URLArg = location.search	
	if (URLArg)  {  // if there's a search argument in URL check it first
		ID=sourceParm(URLArg);
	}else if (otherargs){  //go cookie route
		ID = GetCookie('sourceins')
		if (ID){
			campaign =	GetCookie('campaign')
			province =  GetCookie('province')
			rating = GetCookie('rating')
			brand = GetCookie('brand')
			association = GetCookie('association')
			moreargs = (otherargs == "app") ? " " : "&" + otherargs		
			ExtArg = true;		
		}
		else {
			sourceID = GetCookie('Referrer')
			if (sourceID) {
				ID=setID(sourceID); // setID is set in each html page or may be undefined
			}
		}
	}
	if (ExtArg) {
	window.location.href = dest + "?source=" + ID + "&campaign=" + campaign + "&province=" + province + "&rating=" 
	+ rating + "&brand=" + brand + "&association=" + association  + moreargs;
	}else{
		window.location.href = dest + "?source=" + ID;
	}
	
	return true;
} // end setSourceTDins


function setID(refURL) {
var ID="3577:WB357701";
	if (refURL.indexOf("webbanking.tdaccess.com") != -1 ) { ID="3577:WB357726"; return ID;}
	if (refURL.indexOf("WB357703") != -1 ) {ID="3577:WB357703";return ID;}
	if (refURL.indexOf("toronto.com") != -1 ) {ID="3577:WB357707";return ID;}
	if (refURL.indexOf("canada.com") != -1 ) {ID="3577:WB357708";return ID;}
	if (refURL.indexOf("//www/v3/ads") != -1 ) {ID="3577:WB357709";return ID;}
	if (refURL.indexOf("quicken.ca") != -1 ) {ID="3577:WB357710";return ID;}
	if (refURL.indexOf("studentawards") != -1 ) {ID="3577:WB357712";}
	if (refURL.indexOf("asian") != -1 ) {ID="3577:WB357714";return ID;}
	if (refURL.indexOf("mls.ca") != -1 ) {ID="3577:WB357717";return ID;}
	if (refURL.indexOf("fundlibrary.com") != -1 ) {ID="3577:WB357718";return ID;}
	if (refURL.indexOf("sympatico.ca") != -1 ) {ID="3577:WB357719";return ID;}
	if (refURL.indexOf("/mortgages/greatrate.jsp") != -1 ) {ID="WB357741";return ID;}
	if (refURL.indexOf("/mortgages/deep_discount_mort.jsp") != -1 ) {ID="WB357749";return ID;}
	if (refURL.indexOf("/mortgages/cashback.jsp") != -1 ) {ID="WB357750";return ID;}
	if (refURL.indexOf("/easyweb5/showmemore") != -1 ) {ID="WB357729";return ID;}
	
return ID;
} // end setID
