var PrinterFriendly = false;

// ------------- FOR PICKING UP URL ARGUMENTS  -------------
function getArguments()
{
	var args = new Object();
	var query = location.search.substring(1);
	var pairs = query.split("&");
	for(var i = 0; i < pairs.length; i++)
	{
		var pos = pairs[i].indexOf("=");
		if(pos == -1)
		{
			continue;
		}
		var argname = pairs[i].substring(0, pos);
		var value = pairs[i].substring(pos+1);
		args[argname] = unescape(value);
	}
	return args;
}

function PickUpData()
{
	var arguments = getArguments();
	if(arguments.Printerfriendly)
	{
		PrinterFriendly = arguments.Printerfriendly;
	}
}

function PrintLastModified()
{
	var Datostring = document.lastModified;
	var Dag=Datostring.substr(3,2);
	var MaanedTemp=Datostring.substr(0,2);
	var Aar=Datostring.substr(6,4);
	var Maanednavne = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");

	if (MaanedTemp.substr(0,1) == 0)
	{
		MaanedTemp = MaanedTemp.substr(1,1);
	}

	if (Dag == "11" || Dag == "12" || Dag == "13")
	{
		var Denounce = "th";
	}
	else if (Dag.substr(1,1) == 1)
	{
		var Denounce = "st";
	}

	else if (Dag.substr(1,1) == 2)
	{
		var Denounce = "nd";
	}

	else if (Dag.substr(1,1) == 3)
	{
		var Denounce = "rd";
	}

	else
	{
		var Denounce = "th";
	}

	if (Dag.substr(0,1) == 0)
	{
		Dag = Dag.substr(1,1);
	}

	var MaanedInt = MaanedTemp-1;
	var Maaned = Maanednavne[(MaanedInt)];

	document.writeln(Maaned + " " + Dag + Denounce + ", " + Aar + ".");
}

// ------------- BEGIN PAGE -------------
function CreatePageHeader()
{
	if(!PrinterFriendly)
	{
		document.writeln('<LINK REL="stylesheet" HREF="includes/styles.css" TYPE="text/css">');

		document.writeln('<table border="0" class="filltable" cellpadding="0" cellspacing="0"><tr>');
		document.writeln('<td class="contents_left"></td>');
		document.writeln('<td valign="top" class="contents">');
		document.writeln('<table width="1000" border="0" cellspacing="0" cellpadding="0">');
		document.writeln('<tr>');
		document.writeln('<td colspan=3 class="topbar"><a href="index.htm"><img src="graphics/top_bar.png" width="1000" height="100" border="0"></a></td>');
		document.writeln('</tr><tr>');
		document.writeln('<td colspan=3 class="vertical_seperator"></td>');
		document.writeln('</tr><tr>');
		document.writeln('<td class="column_menu">');
		document.writeln('<script language="JavaScript" type="text/JavaScript">');
		document.writeln('	CreateMenu();');
		document.writeln('</script>');
		document.writeln('</td>');
		document.writeln('<td class="column_seperator"></td>');
		document.writeln('<td class="column_contents">');
	}
	else
	{
		document.writeln('<LINK REL="stylesheet" HREF="includes/styles_printerfriendly.css" TYPE="text/css">');

/*
		document.writeln('<style type="text/css">');
		document.writeln('body, table {font-family: "Times New Roman", Times, serif; font-size: 10pt; background-image: url(graphics/background_ocean.jpg); background-color: #FFFFFF;}');
		document.writeln('</style>');
*/
	}
}

// ------------- BEGIN PAGE -------------


function CreatePageFooter()
{
	if(!PrinterFriendly)
	{

		document.writeln('</td>');
		document.writeln('</tr>');
		document.writeln('</table>');

		document.writeln('<br><center class="footer">');
		document.writeln('<hr width="970" size="1" noshade><a href="contacts.htm">Contact</a> - <a href="disclaimer.htm">Disclaimer</a> - <a href="javascript:nothing();" onClick="OpenPrinterFriendly();">Print this page</a> - <a href="javascript:nothing();" onClick="ComposeEMail();">E-mail webmaster</a>');
		document.writeln('<br>Please seek the permission from the webmaster before reproducing any part of this page. Copying without permission is not allowed.');
		document.writeln('</center><br>');

		document.writeln('</td>');
		document.writeln('<td class="contents_right"></td>');
		document.writeln('</tr>');
		document.writeln('</table>');
	}
	else
	{
		window.print();
	}
}


// ------------- VARIABLES -------------

// Our main class for creating menu items
new MenuItem();
var contents = new Array();
var i =0;
var currentlevel1;
var currentlevel2;
var currentlevel3;


// ------------- FUNCTIONS -------------

// Class constructor of our menu item
function MenuItem(l1, l2, l3, tit, url)
{
	this.level1 = l1;
	this.level2 = l2;
	this.level3 = l3;
	this.title = tit;
	this.filename = url;
	return this;
}

// For creating the table of contents
function AddToContentList(lev1, lev2, lev3, titl, urlstring)
{
	var i = contents.length;
	contents[i] = new MenuItem(lev1, lev2, lev3, titl, urlstring);
}

// Isolates the filename from a path, both locally and/or on the Internet
function ExtractFileName(str)
{
	var originallength = str.length;
	var pos = 0;

	while(pos>-1)
	{
		pos = str.indexOf("\\");
		str  = str.substr(pos+1);
	}

	pos = 0;
	while(pos>-1)
	{
		pos = str.indexOf('/');
		str  = str.substr(pos+1);
	}

	if(str.length == originallength)
	{
		alert("No filename found");
	}

	return str;
}

// ------------- LIST OF CONTENTS -------------

AddToContentList(1, 0, 0, "Introduction", "introduction.htm");
	AddToContentList(1, 1, 0, "The Estonia disaster", "the_disaster.htm");
	AddToContentList(1, 2, 0, "What is this site about?", "why_this_site.htm");

AddToContentList(2, 0, 0, "News", "news.htm");
	AddToContentList(2, 1, 0, "Archive", "news_archive.htm");

AddToContentList(3, 0, 0, "Chronology until today", "chronology.htm");
	AddToContentList(3, 1, 0, "Timeline of the disaster", "timeline.htm");
	AddToContentList(3, 2, 0, "Development since 1994", "development.htm");

AddToContentList(4, 0, 0, "Facts and stats", "facts.htm");
	AddToContentList(4, 1, 0, "The survivors", "survivors.htm");
	AddToContentList(4, 2, 0, "The deceased", "deceased.htm");
	AddToContentList(4, 3, 0, "Crew list", "crew_list.htm");
	AddToContentList(4, 4, 0, "Rescue info", "rescue_info.htm");
	AddToContentList(4, 5, 0, "The distress radio traffic", "radio_traffic.htm");
	AddToContentList(4, 6, 0, "M/S Estonia", "ms_estonia.htm");

AddToContentList(5, 0, 0, "The official explanation", "official_explanation.htm");
	AddToContentList(5, 1, 0, "Goverment instructions on sep. 28", "goverment_instructions.htm");
	AddToContentList(5, 2, 0, "The JAIC - members", "jaic_members.htm");
	AddToContentList(5, 3, 0, "Cause announced prematurely", "cause_announcement.htm");
	AddToContentList(5, 4, 0, "JAIC work methods", "jaic_methods.htm");
	AddToContentList(5, 5, 0, "News without evidence", "news_without_evidence.htm");
	AddToContentList(5, 6, 0, "The Part report - only one cause", "part_report.htm");
	AddToContentList(5, 7, 0, "Falsified technical investigations", "falsified_investigations.htm");
	AddToContentList(5, 8, 0, "Writing a false report", "writing_falsely.htm");
	AddToContentList(5, 9, 0, "Changes in the JAIC", "changes_in_jaic_report.htm");
	AddToContentList(5, 10, 0, "The final report", "final_report.htm");
	AddToContentList(5, 11, 0, "Comments on final report", "comments_final_report.htm");

AddToContentList(6, 0, 0, "Disaster or crime?", "crime.htm");
	AddToContentList(6, 1, 0, "Rough sea doesn't sink a ship", "rough_sea.htm");
	AddToContentList(6, 2, 0, "The Felix Report", "felix_report.htm");
		AddToContentList(6, 2, 1, "The bridge gets a phonecall", "bridge_phonecall.htm");
		AddToContentList(6, 2, 2, "The damage control  begins", "damage_control.htm");
		AddToContentList(6, 2, 3, "Drugs and illegal materials", "drugs_and_materials.htm");
	AddToContentList(6, 3, 0, "The witnesses speak out", "witnesses_speak_out.htm");
		AddToContentList(6, 3, 1, "Strange sounds from the car deck", "sounds_from_car_deck.htm");
		AddToContentList(6, 3, 2, "An explosion?", "an_explosion.htm");
	AddToContentList(6, 4, 0, "Swedish customs was waiting", "customs.htm");
	AddToContentList(6, 5, 0, "Missing survivors", "missing_survivors.htm");
		AddToContentList(6, 5, 1, "Captain Avo Piht", "avo_piht.htm");
		AddToContentList(6, 5, 2, "Lembit Leiger", "lembit_leiger.htm");
		AddToContentList(6, 5, 3, "Hannely and Hannika Veide", "veide_sisters.htm");
		AddToContentList(6, 5, 4, "Tina Müür", "tina_muur.htm");
		AddToContentList(6, 5, 5, "The two ghost planes", "ghost_planes.htm");
	AddToContentList(6, 6, 0, "Rescuer asked to keep silent", "rescuers_quiet.htm");
	AddToContentList(6, 7, 0, "	The governments standing idle", "governments_standing_idle.htm");
	AddToContentList(6, 8, 0, "	Dive team targeting cabins", "specific_cabins.htm");
	AddToContentList(6, 9, 0, "Who was on the bridge?", "who_was_on_the_bridge.htm");
	AddToContentList(6, 10, 0, "Private diving operations", "private_diving.htm");
		AddToContentList(6, 10, 1, "Explosive charges on the hull", "explosive_charges.htm");
		AddToContentList(6, 10, 2, "Large hole in the ship", "large_hole.htm");
	AddToContentList(6, 11, 0, "The official report is impossible", "official_report_impossible.htm");

AddToContentList(7, 0, 0, "FAQ", "faq.htm");

AddToContentList(8, 0, 0, "Unanswered questions", "unanswered_questions.htm");

AddToContentList(9, 0, 0, "What really happened?", "what_really_happened.htm");

AddToContentList(10, 0, 0, "The bereaved unite", "bereaved.htm");
	AddToContentList(10, 1, 0, "The struggles of the relatives", "relatives.htm");
	AddToContentList(10, 2, 0, "ELA", "ela.htm");
	AddToContentList(10, 2, 0, "Other organisations", "organisations.htm");

AddToContentList(11, 0, 0, "What can YOU do?", "what_can_you_do.htm");

AddToContentList(12, 0, 0, "Documents", "documents.htm");

AddToContentList(13, 0, 0, "Media", "media.htm");
	AddToContentList(13, 1, 0, "Documents and articles", "media_documents.htm");
	AddToContentList(13, 2, 0, "Sounds", "media_sounds.htm");
	AddToContentList(13, 3, 0, "Pictures", "media_pictures.htm");
	AddToContentList(13, 4, 0, "Video", "media_video.htm");

AddToContentList(14, 0, 0, "Links", "links.htm");

AddToContentList(15, 0, 0, "Credits", "credits.htm");
	AddToContentList(15, 1, 0, "Sources", "sources.htm");
	AddToContentList(15, 2, 0, "Thanks to ...", "thanks.htm");

AddToContentList(16, 0, 0, "Contact", "contacts.htm");

AddToContentList(17, 0, 0, "Disclaimer", "disclaimer.htm");

// ------------- OTHER PREPARATIONS -------------

// For locating file name
// Filename is stored in "locationstring"
var locationtemp = new String(document.location);
var locationstring = ExtractFileName(locationtemp);

// ------------- WRITE MENU -------------

function CreateMenu()
{
	document.writeln('<table width="256" border="0" cellspacing="0" cellpadding="0">');
	document.writeln('<tr>');
	document.writeln('<td class="contents_top">Table of contents</td>');
	document.writeln('</tr>');

	// Locates the current page's position in the system and the hierarchy
	for(i = 0; i < contents.length; i++)
	{
		if(locationstring == contents[i].filename)
		{
			currentlevel1 = contents[i].level1;
			currentlevel2 = contents[i].level2;
			currentlevel3 = contents[i].level3;
			break;
		}
	}


	// Prints each menu item (or not!), depending on the system structure
	for(i = 0; i < contents.length; i++)
	{
//		alert(contents[i].level1 + ", " + contents[i].level2 + ", " + contents[i].level3 + ", " + contents[i].title + ", " + contents[i].level3);
		if(contents[i].level3 == 0)
		{
			if(contents[i].level2 == 0)
			{
				document.writeln('<tr>');
				if(currentlevel1 == contents[i].level1 && locationstring == contents[i].filename)
				{
//					document.writeln('<td class="contentsLevel1On"><a href="' + contents[i].filename + '">' + contents[i].title + '</a></td>');
					document.writeln('<td class="contentsLevel1On">' + contents[i].title + '</td>');
				}
				else
				{
					document.writeln('<td class="contentsLevel1Off"><a href="' + contents[i].filename + '">' + contents[i].title + '</a></td>');
				}
				document.writeln('</tr>');
			}
			else
			{
				if((currentlevel1 == contents[i].level1) && (currentlevel2 == contents[i].level2))
				{
					if(locationstring == contents[i].filename)
					{
						document.writeln('<tr>');
						document.writeln('<td class="contentsLevel2On">' + contents[i].title + '</td>');
//						document.writeln('<td class="contentsLevel2On"><a href="' + contents[i].filename + '">' + contents[i].title + '</a></td>');
						document.writeln('</tr>');
					}
					else
					{
						document.writeln('<tr>');
						document.writeln('<td class="contentsLevel2Off" ><a href="' + contents[i].filename + '">' + contents[i].title + '</a></td>');
						document.writeln('</tr>');
					}
				}
/*
				else if((currentlevel1 == contents[i].level1) && (currentlevel2 != contents[i].level2) && locationstring != contents[i].filename)
				{
					document.writeln('<tr>');
					document.writeln('<td class="contentsLevel2Off" ><a href="' + contents[i].filename + '">' + contents[i].title + '</a></td>');
					document.writeln('</tr>');
				}
*/
				else if((currentlevel1 == contents[i].level1) && (currentlevel2 != contents[i].level2))
				{
					document.writeln('<tr>');
					document.writeln('<td class="contentsLevel2Off" ><a href="' + contents[i].filename + '">' + contents[i].title + '</a></td>');
					document.writeln('</tr>');
				}
				else
				{
					continue;
				}
			}
		}
		else
		{
			if((currentlevel1 == contents[i].level1) && (currentlevel2 == contents[i].level2)  && (currentlevel3 == contents[i].level3) && locationstring == contents[i].filename)
			{
				document.writeln('<tr>');
//				document.writeln('<td class="contentsLevel3On"><a href="' + contents[i].filename + '">' + contents[i].title + '</a></td>');
				document.writeln('<td class="contentsLevel3On">' + contents[i].title + '</td>');
				document.writeln('</tr>');
			}
			else if((currentlevel1 == contents[i].level1) && (currentlevel2 == contents[i].level2)  && (currentlevel3 != contents[i].level3))
			{
				document.writeln('<tr>');
				document.writeln('<td class="contentsLevel3Off"><a href="' + contents[i].filename + '">' + contents[i].title + '</a></td>');
				document.writeln('</tr>');
			}
			else
			{
				continue;
			}
		}
	}
	document.writeln('<tr>');
	document.writeln('<td background="graphics/menu_bottom.jpg" height="6"><img src="graphics/transp.gif" width="14" height="14"></td>');
	document.writeln('</tr>');
	document.writeln('</table>');
}

// ------------- TEST AREA -------------


function ComposeEMail()
{
	var params="width=1, height=1, status=0, menubar=0, location=0, toolbar=0, directories=0, resizable=0, scrollbars=0";
	var EMailWindow = window.open("mailto:webmaster@estoniadisaster.com?subject=Estonia", "Email", params);
	if(EMailWindow)
	{
		EMailWindow.close();
	}
}

function OpenPrinterFriendly()
{
	var params="width=800, height=600, status=1, menubar=0, location=0, toolbar=0, directories=0, resizable=0, scrollbars=auto";
	var printerurl = document.location + "?Printerfriendly=true"
	var PrinterWindow = window.open(printerurl, "Print", params);
}

function nothing()
{
}

