// user accept cookies?
var dclkBanner = false;
var acceptsCookie = false;
if(document.cookie == '') {
    document.cookie = 'acceptsCookie=yes'; // Try set cookie
    if(document.cookie.indexOf('acceptsCookie=yes') != -1) {
	acceptsCookie = true;
	dclkBanner = true;
    } 
	} else { 
  acceptsCookie = true;
  dclkBanner = true; 
}

function setCookie (name, value, expires) {
if (acceptsCookie) {
	if (!expires) expires = new Date();
	document.cookie = name + "=" + value + "; expires=" + expires.toGMTString() +"; path=/";
    }
}

function readCookie(name) {
    if(document.cookie == '') { 
	return false; 
    } else { 
	var firstChar, lastChar;
	var gamCookie = document.cookie;
	name = name + '=';
	firstChar = gamCookie.indexOf(name);	
	if (firstChar != -1) {
	    firstChar += name.length;
	    lastChar = gamCookie.indexOf(';', firstChar); 
	    if(lastChar == -1) lastChar = gamCookie.length;
	    return unescape(gamCookie.substring(firstChar, lastChar));
	} else {return false;}
    }	
} 

function getValue(cookieName,name) {
	cookieValue=readCookie(cookieName)
	findString=name;
	if (cookieValue) {
		namePos=cookieValue.indexOf(findString,0);
		if (namePos==-1) {return false;}
		valueStart=(cookieValue.indexOf('&',namePos+1)+1);
		valueEnd=cookieValue.indexOf('&',valueStart+1);
		if (valueEnd==-1)  valueEnd=cookieValue.length;
		valueIs=cookieValue.substring(valueStart,valueEnd)
		if (namePos!=null) {return valueIs;}
	}
	else {return false;}
}


// rest month and day to adjust cookie launch
var MAXPOP = 1; // freq
if (sMAXPOP >= MAXPOP) {
MAXPOP=sMAXPOP;
}
var pdays = 1; // days to expire
var bannerName = 'site'; // name
var expdate = new Date();
expdate.setTime(expdate.getTime() +  (pdays * 12  *  60 * 60000));
// pdays * 12 hr * 60 min * 60 sec
var nHits = eval(readCookie(bannerName));
nHits += 1;
var wCookie=MAXPOP+1;
if (nHits <= MAXPOP || (nHits > 1 && nHits < wCookie)) setCookie(bannerName, nHits, expdate);
// disable AOL 
aol_checkjd='Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)';
if (aol_checkjd.indexOf("AOL") > 0) dclkBanner=false;
if (aol_checkjd.indexOf("WebTV") > -1 ) dclkBanner=false;

// dclkBanner over max
if (nHits > MAXPOP) {
	dclkBanner = false;
}

if (!showAd) {if (parent.showAd) {var showAd = parent.showAd;} else {var showAd=false;}}
if (!smode) {if (parent.smode) {var smode = parent.smode;} else {var smode="";}}

if ((smode==";comp=Ethical_Funds_Inc")||(smode==";comp=Fidelity_Investments_Canada_Ltd")||(smode==";comp=Capstone_Consultants_Ltd")||(smode==";comp=Saxon_Funds")){
showAd=true;
}

if ((smode==";p1=Ethical_Funds_Inc")||(smode==";p1=Fidelity_Investments_Canada_Ltd")||(smode==";p1=Capstone_Consultants_Ltd")||(smode==";p1=Saxon_Funds")){
showAd=true;
}


if (showAd) {
	dclkBanner=true;
}


//override
dclkBanner=true;

var houseList_GAM = new Array(
"https://customer.globeandmail.ca/circcsSubsBase.asp><globeandmailprint/468x60/banner2.gif><GAM_print><GAM_print>","http://magazine.globeinvestor.com/\"onclick=\"tradeByNumbersWin=window.open('http://magazine.globeinvestor.com','tradeByNumbersWin','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=720,height=508,left=15,top=10');return false;\"><globeinvestor/tbn_468x60_nc_2.gif><cibc><cibcDirect_tbn468_gam>","http://magazine.globeinvestor.com/\"onclick=\"tradeByNumbersWin=window.open('http://magazine.globeinvestor.com','tradeByNumbersWin','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=720,height=508,left=15,top=10');return false;\"><globeinvestor/tbn_468x60_nc_2.gif><cibc><cibcDirect_tbn468_gam>","http://www.globeadvisor.com><globeadvisor/garage_banner.gif><ga><ga_gam>","http://www.globetechnology.com/einsider/fragments/IBMsub.html><gam_house/468x60/e_insider_news_banner.gif><gtE><gtE_gam>");



function selectImg(){
	randNum = Math.floor(Math.random()*houseList_GAM.length) ;
	url = houseList_GAM.slice(randNum,randNum+1) ;
	left  = houseList_GAM.slice(0,randNum) ;
	right = houseList_GAM.slice(randNum+1) ;
	houseList_GAM = left.concat(right) ;
	return url ;
}
 
function placeRandom468x60Img(){
	if (dclkBanner)  {
		if (!ord) {var abc = Math.random() + "";	var ord = abc.substring(2,abc.length);}
		document.write('<scr'+'ipt language=\"javascript1.1\" src=\"http://ad.ca.doubleclick.net/adj/www.globefund.com/'+szone+';abr=!webtv;mode='+smode+';loc=hub;adpg='+sadpg+';arena='+sarena+';kw=;pos=banTop;sz=468x60;tile=1;ord='+ord+'?\">');
document.write('<\/scr'+'ipt>');
document.write('<img src="http://adcounter.theglobeandmail.com/servlet/AdletCounter?ad1=GF_'+sadpg+'_468x60" width="1" height="1" border="0">');
	} else {
		pick = 1 ;
		for (i=0 ; i <= pick-1 ; i++ ) {
			display = selectImg() ;
			house468Array     = /(.*)><(.*)><(.*)><(.*)>/g ;
			var urlVal  = display[0].replace(house468Array,"$1") ;
			var img   = display[0].replace(house468Array,"$2") ;
			var text  = display[0].replace(house468Array,"$3") ;
			var adCounter  = display[0].replace(house468Array,"$4") ;
		
			document.write('<a href="'+urlVal+'" target="_top"><img src="http://ads.globeandmail.com/images/'+img+'" width="468" height="60" border="0"></A><img src="http://adcounter.theglobeandmail.com/servlet/AdletCounter?ad1=HOUSE_'+adCounter+'_gf" width="1" height="1" border="0"><img src="http://adcounter.theglobeandmail.com/servlet/AdletCounter?ad1=GF_'+sadpg+'_468x60" width="1" height="1" border="0">'); 
 		}
	}
}
