// JavaScript Document
var continent_array =  new Array();
//
function addContinent(continentName) {
	var newContinent = new Continent(continentName);
	continent_array.push(newContinent);
}
// Declare Classes
function Continent(continentName) {
	this.name = continentName;
	this.countries = new Array();
	this.addCountry = addCountry;
	this.getTotalCountries = getTotalCountries;
	this.getCountry = getCountry;
	this.getContinentName = getContinentName;
}
//
function addCountry(countryName) {
	var newCountry = new Country(countryName);
	this.countries.push(newCountry);
}
//
function getTotalCountries() {
	return this.countries.length;
}
//
function getCountry(whichCountry) {
	return this.countries[whichCountry];
}
//
function getContinentName() {
	return this.name;
}
//
function Country(countryName) {
	this.name = countryName;
	this.chapters = new Array();
	//
	this.addChapter = addChapter;
	this.getChapter = getChapter;
	this.getTotalChapters = getTotalChapters;
	this.getCountryName = getCountryName
}
//
function getCountryName() {
	return this.name;
}
//
function addChapter(chapterName, chapterURL) {
	var newChapter = new Chapter(chapterName, chapterURL);
	this.chapters.push(newChapter);
}
//
function getChapter(chapterNumber) {
	return this.chapters[chapterNumber];
}
//
function getTotalChapters() {
	return this.chapters.length;
}
//
function Chapter(chapterName, chapterURL) {
	this.name = chapterName;
	this.url = chapterURL;
	//
	this.getChapterName = getChapterName;
	this.getChapterURL = getChapterURL;
}
//
function getChapterName() {
	return this.name;
}
//
function getChapterURL() {
	return this.url;
}
//
function listContinents() {
	// Populate Books list
	var counter;
	var path = window.document.links_form.select_continent;
	// Intialize
	path.options.length = 0;
	//
	// Populate
	for (counter=0; counter<continent_array.length; counter++) {
		path.options[counter] = new Option(continent_array[counter].getContinentName(), counter);
	}
	// end for
}
//
function continentSelected() {
	var continentPath = window.document.links_form.select_continent;
	var countryPath = window.document.links_form.select_country;
	var chapterPath = window.document.links_form.select_chapter;
	var viewPath = window.document.links_form.viewSite;
	//
	var totalCountries = continent_array[continentPath.selectedIndex].getTotalCountries();
	var counter;
	//
	// clear countries
	countryPath.options.length=0;
	// clear chapters
	chapterPath.options.length=0;
	// disable view button
	viewPath.disabled = true;
	//
	// Populate countries
	for (counter=0; counter<totalCountries; counter++) {
		countryPath.options[counter] = new Option(continent_array[continentPath.selectedIndex].getCountry(counter).getCountryName(), counter);
	}
	//
	countryPath.disabled = false;
}
//
function countrySelected() {
	var continentPath = window.document.links_form.select_continent;
	var countryPath = window.document.links_form.select_country;
	var chapterPath = window.document.links_form.select_chapter;
	var viewPath = window.document.links_form.viewSite;
	//
	var selectedContinent = continentPath.selectedIndex;
	var selectedCountry = countryPath.selectedIndex;
	var totalChapters = continent_array[selectedContinent].getCountry(selectedCountry).getTotalChapters();
	var counter;
	//
	// Clear chapter list
	chapterPath.options.length = 0;
	viewPath.disabled = true;
	//
	// Populate Chapters
	for (counter=0; counter<totalChapters; counter++) {
		chapterPath.options[counter] = new Option(continent_array[selectedContinent].getCountry(selectedCountry).getChapter(counter).getChapterName(), continent_array[selectedContinent].getCountry(selectedCountry).getChapter(counter).getChapterURL());
	}
	//
	chapterPath.disabled = false;
}
//
function chapterSelected() {
	//
	var viewPath = window.document.links_form.viewSite;
	viewPath.disabled = false;
}
//
function getSite() {
	var chapterPath = window.document.links_form.select_chapter;
	// Get url
	window.open("http://" + chapterPath.options[chapterPath.selectedIndex].value, "ubfSite");
}