// Create spider proof email addresses
// Use this code in the body:
// <SCRIPT language=javascript>generateAntiSpiderEmail('user', 'domain', 'tld', 'display_text');</SCRIPT>
function generateAntiSpiderEmail(Username, DomainName, TLD, Text) {
	Address = Username + "&#64;" + DomainName + "." + TLD;

	if (!(Text)) {DisplayText = Address}
	else {DisplayText = Text};

	document.write("<a href=\"mailto:" + Address + "\">" + DisplayText + "</a>");
}

// Top NAV
// <SCRIPT language=javascript>ShowTopNav('Home');</SCRIPT>
ContainerID = 'MasterMenuContainer_ProgramsServices';
MenuOverD   = 'menu(ContainerID, 1);';
MenuOutD    = 'menu(ContainerID, 0)';

BaseURL = '/'

function ShowTopNav(NavPageName) {
	
	document.write('<table class="nav"><tr>');
	
	WriteNavCell('Home',BaseURL + 'index.html',NavPageName);
	WriteNavCell('Support',BaseURL + 'support.html',NavPageName);
	WriteNavCell('Programs<br>And Services',BaseURL + 'programs_services/index.html',NavPageName);
	WriteNavCell('Human<br>Resources',BaseURL + 'hr/index.html',NavPageName);
	WriteNavCell('Fundraising',BaseURL + 'fundraising.html',NavPageName);
	WriteNavCell('Wood<br>Products',BaseURL + 'php/wood_products',NavPageName);
	WriteNavCell('Contact Us',BaseURL + 'contact_us.html',NavPageName);
	
	document.write('</tr></table>');
	
	OMO_Color = '  ';
	
	MenuHTML
	= '<div id="MasterMenuContainer_ProgramsServices" class="MasterMenuContainer" onMouseOver="' + MenuOverD + '" onMouseOut="' + MenuOutD + '">'
	
	+ WriteSubMenu('Residential Services')
	+ WriteSubMenu('Opportunities Program')
	+ WriteSubMenu('Woodwork Department')
	+ WriteSubMenu('Product Sales')
	+ WriteSubMenu('Front Shop')
	+ WriteSubMenu('Service Shop')
	+ WriteSubMenu('E-Waste Collection')
	+ WriteSubMenu('The John Unger Seniors Centre')
	
	+ '</div>';
	
	document.write(MenuHTML);
}

function WriteNavCell(NavTest,LinkURL,NavPageName) {
	
	MenuOver = (LinkURL == BaseURL + 'programs_services/index.html')?MenuOverD:'';
	MenuOut  = (LinkURL == BaseURL + 'programs_services/index.html')?MenuOutD:'';
	
	if (NavPageName == NavTest) {
		document.write("<td onClick=\"" + CellLink(LinkURL) + "\" class=\"nav_hatched\" onMouseOver=\"" + MenuOver + "\" onMouseOut=\"" + MenuOut + "\">" + NavTest + "</td>")
	} else {
		document.write("<td onClick=\"" + CellLink(LinkURL) + "\" onMouseOver=\"this.style.color = '#F7D610'; " + MenuOver + "\" onMouseOut=\"this.style.color = '#FFFFFF'; " + MenuOut + "\">" + NavTest + "</a></td>")
	}
}

function WriteSubMenu(MenuItem) {
	return '<div class="SingleMenuItemContainer" onMouseOver="this.style.color = \'#F7D610\'" onMouseOut="this.style.color = \'#FFFFFF\'" ' +
	'onClick="' + CellLink(BaseURL + 'programs_services/' + MenuItem.replace(/ /g,'_').toLowerCase() + '.html') + '">' + MenuItem + '</div>';
}

function CellLink(LinkURL) {
	return "document.location.href = '" + LinkURL + "'";
}

// Menu function
function menu(ContainerID, Over) {
	document.getElementById(ContainerID).style.display = (Over)?'block':'none';
}

// Is this MSIE?
IsCrappyMicroshaftBrowser = navigator.appVersion.indexOf('MSIE') != -1;

// ASSIGNS A JAVASCRIPT EVENT TO A SPECIFIED OBJECT ACCORDING TO THE BROWSER
function setEvent(Obj, Event, Action) {

	// For IE, use attachEvent
	if (IsCrappyMicroshaftBrowser) {
		eval("Obj.attachEvent('" + Event.toLowerCase() + "', function() { " + Action + " });");
	}

	// For proper browsers, simply use setAttribute
	else
		Obj.setAttribute(Event, Action);
}


// Display/Hide Section info
function toggleInfo(InfoContainerID) {
	InfoContainerObj = document.getElementById(InfoContainerID);
	InfoContainerObj.style.display = (InfoContainerObj.style.display == 'none' || !InfoContainerObj.style.display)?'block':'none';
}


// Function to create image overlay
function enlargeImg(ImgSrc, ImgLabel) {

	with (document) {
		NewContainerDiv	= createElement('div');
		NewDisableDiv	= createElement('div');
		NewImg		= createElement('img');
		NewXImg		= createElement('img');
	}

	with (NewImg) {
		src		= ImgSrc;
		style.margin	= '15px';
		style.cursor	= 'pointer';
		style.display	= 'block';

		TmpLabel = ImgLabel + ' [click to close]';
		setAttribute('alt', TmpLabel);
		setAttribute('title', TmpLabel);
		setAttribute('id', 'MainImg');
	}

	with (NewXImg) {
		src = 'http://www.blueskyop.com/images/x.gif';

		style.position	= 'absolute';
		style.cursor	= 'pointer';
		
		if (IsCrappyMicroshaftBrowser)
			style.margin = '-30px 10px 0px ' + (NewImg.width-0) + 'px';
		else
			style.margin	= '-15px 10px 0px ' + (NewImg.width+15) + 'px';

		setAttribute('width', '30');
		setAttribute('height', '35');
		setAttribute('alt', 'close');
		setAttribute('title', 'close');
		setAttribute('id', 'XImg');
	}

	setEvent(NewImg, 'onClick', 'closeMainImg()');
	setEvent(NewXImg, 'onClick', 'closeMainImg()');

	if (NewImg.width == 0) {
		setTimeout('enlargeImg("' + ImgSrc + '", "' + ImgLabel + '")', 500);
		return;
	}

	setLeft = (Math.round(document.body.clientWidth / 2)*1)/1 - ((NewImg.width + 10) / 2);
	setLeft = (String(setLeft).lastIndexOf('.') != '-1')
		  ?String(setLeft).substr(0, String(setLeft).lastIndexOf('.')):String(setLeft) + 'px';

	setTop = String(document.body.scrollTop + 35) + 'px';

	with (NewContainerDiv) {
		setAttribute('id', 'MainImgContainer');

		style.position	= 'absolute';
		style.top	= setTop;
		style.left	= setLeft;
		style.zIndex	= '3';
		style.background= '#FFFFFF';
		
		if (IsCrappyMicroshaftBrowser)
			style.paddingTop= '15px';
	}

	with (NewDisableDiv.style) {
		top        = '0px';
		left       = '0px';
		width      = '100%';
		position   = 'absolute';
		height     = String(document.body.scrollHeight) + 'px';
		background = '#204052';
		zIndex     = '1';

		if (IsCrappyMicroshaftBrowser) {
			//toggleSelectMenuVisibility(true, 'hidden');
			filter = 'alpha(opacity=75)';
		}
		else {
			setProperty('-moz-opacity', '.75', '');
			setProperty('opacity', '.75', '');
		}
	}

	NewDisableDiv.setAttribute('id', 'DisableDiv');

	with (document.body) {
		appendChild(NewDisableDiv);
		appendChild(NewContainerDiv);
	}

	NewContainerDiv.appendChild(NewXImg);
	NewContainerDiv.appendChild(NewImg);
}


// Function to close overlay
function closeMainImg() {
	with (NewContainerDiv) {
		removeChild(document.getElementById('MainImg'));
		removeChild(document.getElementById('XImg'));
	}

	with (document.body) {
		removeChild(document.getElementById('DisableDiv'));
		removeChild(document.getElementById('MainImgContainer'));
	}
}

