//RETURN FULL DATE (dayofweek, month day, year)
daynames = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
monthnames = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
function fulldate(mydate) {
	mydow = daynames[mydate.getDay()];
	myday = mydate.getDate();
	mymonth = monthnames[mydate.getMonth()];
	myyear = mydate.getFullYear();
	return mydow + ", " + mymonth + " " + myday + ", " + myyear;
	}

//SHOW DATE for home page
function showdate() {
	today = new Date();
	document.write("<p class='smallpurple'>" + fulldate(today) + "</p>");
	}
	
//MAKE POPUP MENU LAYER for layer/div called thismenu
function makemenu(thismenu,thishtml) {
	if (document.all) {
		if(CSAg.indexOf("MSIE 5.0") > 0 && CSAg.indexOf("Mac") > 0) {	
			//bug in IE5.0 for Mac requires the extra space
			document.all(thismenu).innerHTML = thishtml + " ";
			}
		else document.all(thismenu).innerHTML = thishtml;
		}
	else if (CSIsW3CDOM) document.getElementById(thismenu).innerHTML = thishtml;
	else {
		document.layers[thismenu].document.write( thishtml );
		document.layers[thismenu].document.close();
		}
	}

//ON LOAD INITIALIZE...
var showing = "";	//currently visible popup menu
var lit = "";		//currently lit menu-item button

function doInit2() {
	if (indexPage) doPreloads();		//once loaded, we're ok on subsequent pages
	if (thistopitem != 0) showtoplayer2("topnavat2",thistopitem);
	if (thismenuitem != "") showgetheadshi(thismenuitem);	//thismenuitem = A,B,C,D,RA,RB,RC or blank
	makemenu("divR",regionmenu() );
	if (!regionalPage) {
		makemenu("divA",getmenu("A") );
		makemenu("divB",getmenu("B") );
		makemenu("divC",getmenu("C") );
		makemenu("divD",getmenu("D") );
		}
	else {
		makemenu("divRA",getmenu("A") );
		makemenu("divRB",getmenu("B") );
		makemenu("divRC",getmenu("C") );
		}
	}

function doPreloads() {
	var preloads = new Array("images/regb_on.gif","images/getrule.gif","images/getb_on.gif","images/topnavon2.gif","images/topnavat2.gif","images/getheads_on.gif");
	var images = new Array();
	for (var i=0; i<preloads.length; i++) {
		images[i] = new Image;
		images[i].src = preloads[i];
		}
	}
	
	

function topshow2(i) {	//show the "topnavon" layer, clipped left & right for menu item i
	if (i != thistopitem) showtoplayer2("topnavon2",i);	//inactive on this top item
	}
	
function tophide2() {	//hide the "topnavon" layer
	CSSetStyleVis('topnavon2',0);
	}

function showtoplayer2(s,i) {	//show layer s, clipped left & right for menu item i
	switch (i) {
		case 1: pclose(); ClipLayer(s,114,187,0,34); break;
		case 2: pclose(); ClipLayer(s,190,279,0,34); break;
		case 3: {
			ClipLayer(s,282,363,0,34); 
			if (s == "topnavon2") popen("R");	//open the region popup
			break;
			}
		case 4: pclose(); ClipLayer(s,367,450,0,34); break;
		return false;
		}
	CSSetStyleVis(s,1);
	return true;
	}	

function ClipLayer (s,l,r,t,b) {	//clip style s at left, right,top,bottom
	clipRect = new CSRect(l,t,r-l,b-t);	//clip rect (left top width height)
	mySetLayerClip(s,clipRect);
	}

function popen(x) {	//open popup x=R,A,B,C,D (div); RA,RB,RC (region)
	pclose(); 	//hide menu popups
	bhide(lit);	//hide the current button
	if (x == "R") CSSetStyleVis('divR',1);
	else {
		if (!eval(x+"empty")) CSSetStyleVis('div'+x,1);	//if the menu exists
		showgetheads(x);
		}
	showing = x;
	var clearlayer =  (x == "R") ? "clearmast" : "cleardivs";
	CSSetStyleVis(clearlayer,1);	// show the clear floater to catch mouseouts
	}

function pclose() { 	//close popups
	bhide(lit);		//hide the current button
	CSSetStyleVis('divR',0); 
	if (regionalPage) {
		if (!RAempty) CSSetStyleVis('divRA',0); 
		if (!RBempty) CSSetStyleVis('divRB',0); 
		if (!RCempty) CSSetStyleVis('divRC',0);
		}
	else {
		if (!Aempty) CSSetStyleVis('divA',0); 
		if (!Bempty) CSSetStyleVis('divB',0); 
		if (!Cempty) CSSetStyleVis('divC',0); 
		if (!Dempty) CSSetStyleVis('divD',0); 
		}
	hidegetheads();
	tophide2();
	showing = "";
	CSSetStyleVis('clearmast',0);	// hide the clear floater that catches mouseouts
	CSSetStyleVis('cleardivs',0);	// hide the clear floater that catches mouseouts
	}
function showgetheadshi(x) {	//show get header highlight for x (A,B,C,D for div; RA,RB,RC for region)
//(that's the coloured underline under the menu you are in)
	switch (x) {
		case "A": ClipLayer('divheadshi',0,132,0,23); break;
		case "B": ClipLayer('divheadshi',132,264,0,23); break;
		case "C": ClipLayer('divheadshi',264,396,0,23); break;
		case "D": ClipLayer('divheadshi',396,528,0,23); break;
		case "RA": ClipLayer('divheadshi',0,176,0,23); break;
		case "RB": ClipLayer('divheadshi',176,352,0,23); break;
		case "RC": ClipLayer('divheadshi',352,528,0,23); break;
		default: return;
		}
	CSSetStyleVis('divheadshi',1);	// show the get menu head highlight
	}
function showgetheads(x) {	//show get header x (A,B,C,D for div; RA,RB,RC for region)
	switch (x) {
		case "A": ClipLayer('divheads',0,132,0,23); break;
		case "B": ClipLayer('divheads',132,264,0,23); break;
		case "C": ClipLayer('divheads',264,396,0,23); break;
		case "D": ClipLayer('divheads',396,528,0,23); break;
		case "RA": ClipLayer('divheads',0,176,0,23); break;
		case "RB": ClipLayer('divheads',176,352,0,23); break;
		case "RC": ClipLayer('divheads',352,528,0,23); break;
		default: return;
		}
	CSSetStyleVis('divheads',1);	// show the get menu heads
	}
function hidegetheads(x) {
	CSSetStyleVis('divheads',0);	// hide the get menu heads
	}
function bshow(x) {	//show button x
	bhide(lit); 	//hide the current button
	CSSetStyleVis(x,1);
	lit = x;
	}
function bhide(x) {	//hide button x
	if (x == "")  return;
	CSSetStyleVis(x,0);
	lit = "";
	}

//map routines
//basemap and mapshowing are global vars defined in the generated map script/html
//basemap is the page on which the map appears (0 for div, 1..6 for regions)
//mapshowing is the region with the mouseover that is hilited (1..6)
function mapareashow(i) {
	if(i == basemap) return;
	SetImgURL('mapbtm',imagesfolder + 'BCMap5btm_' + i + (basemap==0 ? '' : basemap + 'hi') + '.gif');
	if (i == 5) SetImgURL('maptop',imagesfolder + 'BCMap5top_5' + (basemap!=5 ? '' : 'hi') + '.gif');
	mapshowing = i;
	return;
	}
function mapareahide() {
	SetImgURL('mapbtm',imagesfolder + 'BCMap5btm_' + (basemap==0 ? '0' : basemap + 'hi') + '.gif');
	if (mapshowing == 5) SetImgURL('maptop',imagesfolder + 'BCMap5top_' + (basemap!=5 ? '0' : '5hi') + '.gif');
	mapshowing = 0;
	return;
	}

var showingname = new Array("donate","volunteer");
var donatepopcheck = 0;	//checked (= showing) popup item in array (starting from 0), default "donate"
var donatepopentry;		//checked item on entry to popup
var donatepophi;		//-1, 0, +1 for top, middle, bottom position
var closedonatepopTO;
var donateimages;
function donateOver() {
	donateimages = "images/";		//path to inside images folder
	donatepophi = donatepopcheck;		//start with checked item hilited on popup
	donatepopentry = donatepopcheck;	//checked item on entry to popup
	SetImgURL("donatepopimg",donateimages + "donatepopCK" + donatepopcheck + "HI" + donatepophi + ".gif");
	CSSetLayerYPos("donatepop",74-16*donatepopentry);
	CSSetStyleVis("donatepop",1);
	return true;
	}
function donatepopOver(id) {	// id=['0','n-1']
	clearTimeout(closedonatepopTO);
	if (donatepophi == id) return;	//we're still over the hilited popup item
	donatepophi = id;
	SetImgURL("donatepopimg",donateimages + "donatepopCK" + donatepopcheck + "HI" + donatepophi + ".gif");
	return true;
	}			
	
function donatepopOut(id) {
	closedonatepopTO = setTimeout("closedonatepop()",100);
	return true;
	}

function closedonatepop() {
	CSSetStyleVis("donatepop",0);
	SetImgURL("donate",donateimages + showingname[donatepopcheck] + ".gif");
	return true;
	}	

function donatepopClick(id) {	// id=['0','n-1']
	if (id == donatepopcheck) return;	//click was on the checked popup item
	donatepopcheck = id;
	donatepophi = id;
	SetImgURL("donatepopimg",donateimages + "donatepopCK" + donatepopcheck + "HI" + donatepophi + ".gif");
	return true;
	}
function donateGo() {	//link for "Donate" or "Volunteer"
	switch (donatepopcheck) {
		case 0:	
			location = "https://secure.cancer.ca/gifts/start.asp?/L=En&cid=0&src=1";
			break;
		case 1: 
			if (isPublicSite) location = backtoroot + "involved/volunteerapplication.html";
			else location = "page.asp?/involved/volunteerapplication";
			break;
		}
	return true;
	}
