//the object containing all information about the navigation menu
//this was done as an object so the names of the pages could easily
//be associated with the text within them and the child menus below
//DO NOT EDIT THIS OBJECT directly, even if you think you know what
//you are doing.  Instead, use the menu-editing script located in
//the cgi-bin directory called menuedit.pl.  Just load it in the
//browser and let it do the work, this ensures that it will always
//be able to read the menu since it relies on strict formatting
var menuList =	{
	business:	{	text:	"Business & Investment",

		why:	{	text:	"Why North Dumfries?",

			location:	{	text:	"Location",

				highway:	{	text:	"Highways"
					},
				airport:	{	text:	"Airports"
					},
				seaport:	{	text:	"Ports"
					}
				},
			people:	{	text:	"People"
				},
			technology:	{	text:	"Technology"
				},
			history:	{	text:	"History"
				}
			},
		available:	{	text:	"What's Available",

			land:	{	text:	"Real Estate"
				},
			services:	{	text:	"Services",

				hydro:	{	text:	"Hydro"
					},
				telecom:	{	text:	"Telecom"
					}
				},
			zoning:	{	text:	"Planning"
				}
			},
		region:	{	text:	"The Region",

			stats:	{	text:	"Statistics"
				}
			},
		resources:	{	text:	"Resources",

			business:	{	text:	"Business"
				},
			local:	{	text:	"Local Resources"
				}
			}
		},
	community:	{	text:	"Local Government",

		bylaws:	{	text:	"Bylaws & Policies",

			permits:	{	text:	"Building Permits"
				},
			taxes:	{	text:	"Property Taxes"
				},
			rates:	{	text:	"Tax Rates"
				},
			plans:	{	text:	"Planning"
				}
			},
		council:	{	text:	"Council",

			election:	{	text:	"Municipal Election"
				},
			mayor:	{	text:	"Mayor's Message"
				},
			contact:	{	text:	"Contact"
				},
			meeting:	{	text:	"2009 Meeting Schedule"
				},
			agenda:	{	text:	"Agendas",

				Feb2:	{	text:	"Feb. 2 2009"
					},
				Feb19:	{	text:	"Feb. 19 2009"
					}
				},
			minutes:	{	text:	"Minutes",

				Jan5:	{	text:	"Jan. 5 2009"
					},
				Jan19:	{	text:	"Jan.19 2009"
					},
				Jan26:	{	text:	"Jan. 26 2009"
					},
				Feb2:	{	text:	"Feb. 2 2009"
					},
				Feb19:	{	text:	"Feb. 19 2009"
					},
				Mar2:	{	text:	"Mar. 2 2009"
					},
				Mar9:	{	text:	"Mar. 9 2009"
					}
				}
			}
		},
	lifestyle:	{	text:	"Lifestyle",

		businesses:	{	text:	"Businesses"
			},
		churches:	{	text:	"Churches"
			},
		clubs:	{	text:	"Clubs"
			},
		libraries:	{	text:	"Libraries"
			},
		schools:	{	text:	"Schools"
			}
		},
	recreation:	{	text:	"Parks & Recreation"
		},
	services:	{	text:	"Township Services",

		fire:	{	text:	"Fire",

			faq:	{	text:	"FAQ"
				},
			pics:	{	text:	"Pictures"
				},
			survive:	{	text:	"Survive a Fire!"
				}
			},
		health:	{	text:	"Health Care",

			clinics:	{	text:	"Clinics"
				}
			},
		police:	{	text:	"Police"
			},
		transit:	{	text:	"Transportation",

			roads:	{	text:	"Roads"
				}
			},
		waste:	{	text:	"Waste Management",

			garbage:	{	text:	"Garbage"
				},
			hazard:	{	text:	"Hazardous"
				},
			recycling:	{	text:	"Recycling"
				}
			},
		water:	{	text:	"Water & Sewers",

			bylaws:	{	text:	"Bylaws"
				}
			}
		},
	lacac:	{	text:	"Heritage",

		tour:	{	text:	"Ayr Walking Tour"
			},
		tour2:	{	text:	"Roseville Walking Tour"
			},
		designated:	{	text:	"Designated Sites",

			icehouse:	{	text:	"Ice House"
				}
			}
		},
	staff:	{	text:	"Staff"
		},
	tourism:	{	text:	"Tourism & Attractions"
		},
	accomodations:	{	text:	"Accomodations"
		},
	attractions:	{	text:	"Attractions",

		area:	{	text:	"Surrounding Area"
			}
		},
	food:	{	text:	"Restaurants / Food"
		},
	history:	{	text:	"History"
		},
	:	{	text:			}
};

//information about the logo images for each section
//When the pages are modular as they are, the script needs to know
//what image to place at the top of the page.  This object tells it
//that, based on the directory in which the page sits.
var logoImages =	{	business:		"bandilogo.gif",
						community:		"cllogo.gif",
						tourism:		"talogo.gif",
						contact:		"contactlogo.gif",
						email:			"emaillogo.gif",
						map:			"maplogo.gif",
						maintenance:	"maintenancelogo.gif",
						feedback:		"logofeedback.gif",
						other:			"logomisc.gif",
						test:			"test.gif"
					};

var mapping = 0;

//output a printer-friendly version of the page in a separate window
function printerFriendly() {
	
	//add the "?printable" string to the end of the url,
	//indicating that the printable page should be displayed
	strurl = location.href + "?printable";

	//open a new window containing the ammended url
	printable = window.open(strurl);

	return 1;
}

//call the perl script to search the database.  this could have
//been done just with a target property within the form tag, but
//the window needs to be formatted to get rid of the various
//toolbars and location bar and to size the window appropriately
//which cannot be done with a target property
function FindIt() {
	var count;
	var name;
	var value;
	//set the location of the script
	var url= "../cgi-bin/read.pl?";
	
	//go through each element in the form and attach it to the end
	//of url as a search string.  use the name of the element as
	//the name, and the value as the value & format it appropriately
	for (count=0; count < document.forms[0].length-1; count++)
	{
		//read in the name of the element
		name = document.forms[0].elements[count].name;

		//since netscape does not read the value of select boxes
		//the same as ie, we need to do a test to see if netscape
		//is the browser.  if it is, use the harder method (which
		//does not work in IE), if not, go ahead and do it the easy 
		//way.  this is just one example of browser incompatability
		if(document.forms[0].elements[count].type == "select-one" && navigator.appName == "Netscape") {
			value = document.forms[0].elements[count].options[document.forms[0].elements[count].selectedIndex].value;
		} else {
			value = document.forms[0].elements[count].value;
		}

		//format the url string such that the perl script can parse it
		url = url + "&" + name + "=" + value;
	}

	//open the window with no toolbar, location bar, directories, or menubar
	//but leave in the status bar, scroll bars, and resizing
	//size the window to 600x300 and place it at (100,100)
	//open the search script into the window
	searchwin= window.open(url,"","toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=600,height=300,top=100,left=100");
}

//verify the form on the more info page
function verify() {

	//the email and a question needs to be in the form, so we 
	//check to see that it has a value before we send the form
	if (document.forms[0].elements['Email'] && document.forms[0].elements['Email'].value == "") {
		if (document.forms[0].elements['Phone'] && document.forms[0].elements['Phone'].value == "") {
			alert("Enter your contact information!");
			return false;
		} else if (!document.forms[0].elements['Phone']) {
			alert("Enter your email address!");
			return false;
		}
	} 
	if (document.forms[0].elements['Question'] && document.forms[0].elements['Question'].value == "") {
		alert("You need to ask a question!");
		return false;
	} 
	if (document.forms[0].elements['Purpose'] && document.forms[0].elements['Purpose'].value == "") {
		alert("You need to state a purpose!");
		return false;
	} 
	if (document.forms[0].elements['Facility'] && document.forms[0].elements['Facility'].value == "") {
		alert("Which facility do you want?");
		return false;
	} 
	if (document.forms[0].elements['Date'] && document.forms[0].elements['Date'].value == "") {
		alert("You need to specify a date!");
		return false;
	} 
	if (document.forms[0].elements['Time'] && document.forms[0].elements['Time'].value == "") {
		alert("You need to specify a time!");
		return false;
	} 
	if (document.forms[0].elements['Name'] && document.forms[0].elements['Name'].value == "") {
		alert("We need your name");
		return false;
	}
	
	//submit the form
	document.forms[0].submit();
	return true;
}

//makes the navigation menu based on the filename of the page
function makeMenu() {

	var written1;
	var written2;
	var written3;

	//parse the path and filename of the page to determine which
	//menu to display unless this is the site map
	page = location.pathname;
	page = page.toLowerCase();
	end = page.indexOf(".");
	if(end > 0) {
		page = page.slice(1,end);
	} else {
		page = page.slice(1,page.length);
	}
	temp = page.split('/');
	mainlevel = temp[0];
	if(temp.length > 1) {
		sublevels = temp[1].split('_');
	}

	//write the menu out, expanding it where it applies
	for (curr_item in menuList) {
		document.write("<A HREF=\"/" + curr_item + "/index.html\" CLASS=\"parent\">" + menuList[curr_item].text + "</A><BR>\n");
		if((curr_item != "text") && ((mapping) || (curr_item == mainlevel))) {
			for(curr_item1 in menuList[curr_item]) {
				if(curr_item1 != "text") {
					if(!written1) {
						document.writeln("<UL CLASS=\"menu\">");
						written1 = true;
					}
					document.writeln("<LI><A HREF=\"/" + curr_item + "/" + curr_item1 + ".html\" CLASS=\"child\">" + menuList[curr_item][curr_item1].text + "</A><BR>");
					if((mapping) || (curr_item1 == sublevels[0])) {
						for(curr_item2 in menuList[curr_item][curr_item1]) {
							if(curr_item2 != "text") {
								if(!written2) {
									document.writeln("<UL CLASS=\"menu\">");
									written2 = true;
								}
								document.writeln("<LI><A HREF=\"/" + curr_item + "/" + curr_item1 + "_" + curr_item2 + ".html\" CLASS=\"submenu\">" + menuList[curr_item][curr_item1][curr_item2].text + "</A><BR>");
								if((mapping) || (curr_item2 == sublevels[1])) {
									for(curr_item3 in menuList[curr_item][curr_item1][curr_item2]) {
										if(curr_item3 != "text") {
											if(!written3) {
												document.writeln("<UL CLASS=\"menu\">");
												written3 = true;
											}
											document.writeln("<LI><A HREF=\"/" + curr_item + "/" + curr_item1 + "_" + curr_item2 + "_" + curr_item3 + ".html\" CLASS=\"submenu\">" + menuList[curr_item][curr_item1][curr_item2][curr_item3].text + "</A><BR>");
										}
									}
									if(written3) {
										document.writeln("</UL>");
										written3 = false;
									}
								}
							}
						}
					}
					if(written2) {
						document.writeln("</UL>");
						written2 = false;
					}
				}
			}
			if(written1) {
				document.writeln("</UL>");
				written1 = false;
			}
		}
	}

	//YOU CAN MAKE ADJUSTMENTS TO THIS NEXT BLOCK, BUT ONLY IF YOU KNOW WHAT YOU ARE DOING
	//write out the rest of the menu items that do not fit with the
	//above naming conventions.
		document.writeln("<A HREF=\"/contact.html\" CLASS=\"parent\">Contact Info / Location</A><BR />");
		document.writeln("<A HREF=\"/email.html\" CLASS=\"parent\">Questions?</A><BR>");
		document.writeln("<A HREF=\"/map.html\" CLASS=\"parent\">Site Map</A><BR />");
	//DO NOT MAKE CHANGES BEYOND THIS POINT
}


//prints out the top of the page.  this ensures that pages are kept
//small and consistent and that nobody can screw things up or change
//little things around that would ruin the look.  if any changes
//need to be made to the layout or style of the page, this is where
//it will be done.  any formatting that is not in here, can be found
//in the styles.html file in css format....
//note: DO NOT MAKE CHANGES WITHOUT PERMISSION!
function startPage() {

	page = location.pathname;
	page = page.toLowerCase();
	end = page.indexOf(".");
	if(end > 0) {
		page = page.slice(1,end);
	} else {
		page = page.slice(1,page.length);
	}
	temp = page.split('/');
	mainlevel = temp[0];
	if(location.search == "?printable"){
		return 1;
	}

	document.writeln("<body marginheight=\"0\" marginwidth=\"0\">");
	document.writeln("<a name=\"Top\"></a>");

	document.writeln("<table ID=\"table1\" cellspacing=0 cellpadding=0 border=0>");
	document.writeln("<tr>");
	document.writeln("<td width=198 height=\"100\" valign=\"top\"><a href=\"/crest.html\"><img src=\"/images/crest.gif\" id=\"crest\" width=200 height=100 border=0></a></td>");
	if(logoImages[mainlevel]) {
		document.writeln("<td height=100 align=\"right\"><img src=\"/images/" + logoImages[mainlevel] + "\" id=\"title\" width=570 height=62 align=\"right\">");
	} else {
		document.writeln("<td height=100 align=\"right\"><img src=\"/images/" + logoImages["other"] + "\" id=\"title\" width=570 height=62 align=\"right\">");
	}
	document.writeln("<br clear=\"all\" align=\"right\" />");
	document.writeln("<a href=\"javascript:;\" onClick=\"printerFriendly()\" onmouseover=\"status='Get a printer-friendly version of this page'; return true;\"  onmouseout=\"status=defaultStatus; return true;\">Printable version</a> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;");
	document.writeln("</td>");
	document.writeln("</tr>");
	document.writeln("<tr>");

	document.write("<td width=198 id=\"left-cell\" height=\"");

    var agent = navigator.userAgent.toLowerCase();
    var ns = ((agent.indexOf('mozilla') != -1) && (agent.indexOf('spoofer') == -1) && (agent.indexOf('compatible') == -1) && (agent.indexOf('opera') == -1) && (agent.indexOf('webtv') == -1));
    var availheight;
    if (ns) {
       if ((parseInt(navigator.appVersion))==4)
          availheight=innerHeight-102;
       else
          availheight=innerHeight-100;
    } else if(document.body.clientHeight) {
       availheight=document.body.clientHeight-100;
    } else {
       availheight=500;
    }
    document.write(availheight);
	document.write("\">");

	makeMenu();
	document.write("<p id=\"update\">Last Updated: ");
	document.write(document.lastModified);
	document.writeln("</p>");
	document.writeln("</td>");
	document.writeln("<td id=\"rightcell\">");
}


//print out the last few lines of the page, ensuring that it is done
function endPage() {
	if(location.search == "?printable"){
		return 1;
	}
	document.writeln("</td>");
	document.writeln("</tr>");
	document.writeln("</table>");
}

//print out the site map, basically just the menu system expanded fully
function MapIt() {
	mapping = 1;
	makeMenu();
	mapping = 0;
}