
function InitPage() {
	document.title = 'District 31 Toastmasters';
	LoadMenu();
	LoadPageBanner();
	LoadPageClosing();
	UnhidePage();
	DoHideAfter(document);
}

// Build the menu
var indentMenu=0;
function LoadMenu() {
	var strMenu = '';
	strMenu += '<ul id="jd_menu" class="jd_menu" style="border:none;">\n';
	strMenu += parsemenu(myMenu);
	strMenu+= '</ul>\n';
	var elemJdMenu = document.getElementById('theMenu');
	if (elemJdMenu) {
		//alert(strMenu);
		elemJdMenu.innerHTML = strMenu;
	}
	//alert(strMenu);
	$(function() {
		$('ul.jd_menu').jdMenu();
	});
}


// Recursive method to parse the menu JSON to create the
// HTML for the menu
function parsemenu(aMenu) {
	var str = '';
	var strIndent = ''; for (var i=0; i<indentMenu; i++) strIndent += ' ';
	if (aMenu.menu) {
		if (aMenu.name) {
			str += strIndent + '<li class="accessible">' + CreateMenuLink(aMenu) + '\n';
			str += strIndent + '<ul>\n';
			indentMenu += 2;
		}
		for (var i=0; i<aMenu.menu.length; i++) {
			str += parsemenu(aMenu.menu[i]);
		}
		if (aMenu.name) {
			indentMenu -= 2;
			str += strIndent + '</ul>\n';
			str += strIndent + '</li>\n';
		}
	}
	else {
		str += strIndent + '<li>' + CreateMenuLink(aMenu) + '</li>\n';
	}
	return str;
}

// Returns a link to a menu or menu item
function CreateMenuLink(aMenu) {
	var str = '<a ';
	if (aMenu.menu) str += 'class="accessible" ';
	if (aMenu.target) str += 'target="' + aMenu.target + '" ';
	if ( ! aMenu.href) aMenu.href='#';
	str += 'href="' + aMenu.href + '" ';
	str += '>';
	str += aMenu.name;
	if (aMenu.menu && indentMenu>0) str += '&nbsp;&nbsp;&raquo;';
	str += '</a>&nbsp;&nbsp;&nbsp;';
	return str;
}

function LoadPageBanner() {
	var elem = document.getElementById('theBanner');
	if (elem) {
		var str = '';
		str += '<a href="index.html" style="text-decoration:none;">';
		str += '<img src="images/CutainWideWords5.jpg" style="height:292px;width:943px;border:none;">';
		str += '</a>';
		elem.innerHTML = str;
	}
}

function LoadPageClosing() {
	var elem = document.getElementById('theClosing');
	if (elem) {
		var str = '';
		str += '<p>';
		str += 'The names "Toastmasters International," "Toastmasters" and the Toastmasters International emblem are trademarks ';
		str += 'protected in the United States,	Canada and other countries where Toastmasters Clubs exist. Unauthorized use is strictly prohibited.';
		str += '</p>';
		str += '<p>';
		str += 'The information on this web site is for the sole use of Toastmasters members, for Toastmasters business only. ';
		str += 'It is not to be used for solicitation or distribution of non-Toastmasters materials or information.';
		str += '</p>';
		str += '<p>';
		str += '<br>';
		str += 'Website Property managed by <a href="http://www.linkedin.com/in/goingclear" target="_blank" title="Paul J Scott">Paul J. Scott</a> of <a target="_blank" href="http://www.goingclear.com">http://www.goingclear.com</a>.';
		str += '</p>';
		elem.innerHTML = str;
	}
}


// Implements "hideafter" functionality.
// If you want part of a document to be hidden after a particular date, wrap that part
// in a div (or other HTML element) and give it a class name of "hideafter_yyyymmdd".
// The code below scans the document for HTML elements with matching class names, and
// hides them after the given date.
var hideafter_today;

function DoHideAfter(node) {
	if ( ! hideafter_today) {
		var hideafter_Date  = new Date();
		var hideafter_Year  = '' + hideafter_Date.getFullYear();
		var hideafter_Month = '' + (hideafter_Date.getMonth() + 1); if (hideafter_Month.length==1) hideafter_Month='0'+hideafter_Month;
		var hideafter_Date  = '' + hideafter_Date.getDate();        if (hideafter_Date.length==1)  hideafter_Date ='0'+hideafter_Date;
		hideafter_today= 'hideafter_' + hideafter_Year + hideafter_Month + hideafter_Date;
	}

	if ((node.className) && (node.className.indexOf('hideafter_') == 0) && (hideafter_today > node.className)) {
		node.className = 'hidethis';
	}
	else {
		for (var i=0; i<node.childNodes.length; i++) DoHideAfter(node.childNodes[i]);
	}
}

function UnhidePage() {
	var elemPage = document.getElementById('thePage');
	if (elemPage) {
		elemPage.style.visibility = 'visible';
	}
}

function ShowImage(strFilename, strCaption) {
	var arg = '?image=' + strFilename;
	if (strCaption) {
		arg += '&caption=' + strCaption;
	}

	window.open('show_image.php' + arg, 'picwin', 'directories=no,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no');
}



// Countdown clock.
// Taken from http://scripts.franciscocharrua.com/countdown-clock.php
        
function countdown(year, month, day, hour, minute, format)
{
    Today = new Date();
    Todays_Year = Today.getFullYear() ;//- 2000;
    Todays_Month = Today.getMonth();        
    
    //Convert both today's date and the target date into miliseconds.            
    Todays_Date = (new Date(Todays_Year, Todays_Month, Today.getDate(), 
                  Today.getHours(), Today.getMinutes(), Today.getSeconds())).getTime();                  
    Target_Date = (new Date(year, month - 1, day, hour, minute, 00)).getTime();        
    
    //Find their difference, and convert that into seconds.        
    Time_Left = Math.round((Target_Date - Todays_Date) / 1000);
    
    if(Time_Left < 0)
       Time_Left = 0;
    
    var str = '';
    switch(format)
    {
        case 0:
          //The simplest way to display the time left.
          str = Time_Left + ' seconds';
          break;
        case 1:
          //More datailed.
          days = Math.floor(Time_Left / (60 * 60 * 24));
          Time_Left %= (60 * 60 * 24);
          hours = Math.floor(Time_Left / (60 * 60));
          Time_Left %= (60 * 60);
          minutes = Math.floor(Time_Left / 60);
          Time_Left %= 60;
          seconds = Time_Left;
          
          dps = 's'; hps = 's'; mps = 's'; sps = 's';
          //ps is short for plural suffix.
          if(days == 1) dps ='';
          if(hours == 1) hps ='';
          if(minutes == 1) mps ='';
          if(seconds == 1) sps ='';
          
          str += days + ' day' + dps + ' ';
          str += hours + ' hour' + hps + ' ';
          str += minutes + ' minute' + mps + ' and ';
          str += seconds + ' second' + sps;
          break;
        default: 
          str = Time_Left + ' seconds';
    }
          
    return str;
}
    
    