// Copyright 2003-5 The Cyber Hymnal

var backWord;
var homeWord;
var midiFile;
var nextPage;
var nextWord;
var prevPage;
var root;
var scoreWord;
var midiWord;

var tipBio							= "See biography (in English)"   
var tipMidi		 					= "Open MIDI file"
var tipScore	 					= "Open score file ("
var openQuote  					= "&ldquo;"
var closeQuote 					= "&rdquo;"
var translatorText					= null
var translatorUnknownText	= null

//------------------------------------------------
// PURPOSE Draw navigational arrows to home, previous & next pages
// ENTRY	Init() has been called

function arrows()
{
	if (nextPage != ' .htm')
	{
		document.write('<p class="navigation"><a href="' + prevPage + '"><img src="' + root + '/img/a/ar-left.gif" border="0" title=" ' + backWord + ' " width="30" height="30"></a> ')
		document.write('<a href="' + root + 'index.htm#lk"><img src="' + root + 'img/a/ar-toc.gif" border="0" title=" ' + homeWord + ' " width="30" height="30" /></a>')
		document.write(' <a href="' + nextPage + '"><img src="' + root + '/img/a/ar-right.gif" border="0" title=" ' + nextWord + ' " width="30" height="30"></a></p>')
	}
}
//------------------------------------------------ 
// PURPOSE		Draw link to a biography page 
// ENTRY			Init() has been called 
// ARGUMENTS	text  Link text to display 
//					file  Biography file page (without extension, which must be .htm) 

function bio(text, file, language) 
{ 
	document.write('<a')
	if (language != null)
		document.write(' lang=' + language)
	document.write(' hreflang="en" href="' + root + 'bio/' + file + '.htm" onMouseOver="return stat(\'' + tipBio + '\')" onMouseOut="return erase()" hreflang="en">' + text + '</a>') 
} 
//------------------------------------------------
// PURPOSE Draw end of the page
// ENTRY	Init() has been called

function end()
{
	arrows()
		document.write('<center><iframe src="http://nethymnal.org/js/ads2.htm" width=800 height=150 frameborder=0></iframe></center>'
	document.write('<p class="footer">' + document.lastModified + '</p>')
}
//------------------------------------------------
// PURPOSE Draw link to English translation

function english(file, linktext)
{
	if (argsOk(arguments.callee, true, false))
	  document.write('<a href="' + root + "htm/" + file + '.htm" + title="English" hreflang="en" target="_self">' + linktext + '</a>')
}
//------------------------------------------------
function init

// PURPOSE		Page initialization
(
	level		, 	// Number of levels below site root
	midi		, 	// MIDI file name (without extension, which must be .mid)
	prev		, 	// Previous page's URL (without extension, which must be .htm)
	next		, 	// Next page's URL (without extension, which must be .htm)
	back		,	// Translation of "Back"
	home		, 	// Translation of "Home"
	forward	,	// Translation of "Next",
	score		, 	// Translation of "Score"
	midiWd	,	// Translation of "MIDI"
	midiTip	,	// Translation of "Open MIDI file"
	scoreTip		// Translation of "Open score file (Noteworthy Composer format)"
)
{
  if (argsOk(arguments.callee, false, true))
	{
		backWord = back.length	> 0 ? back  : "Back"
		homeWord = home.length	> 0 ? home  : "Home"
		nextWord = forward.length > 0 ? forward : "Next"
		scoreWord = score.length  > 0 ? score  : "score"
		midiWord = (midiWd && midiWd.length > 0) ? midiWd : "MI&shy;DI"
		if (midiTip)
			tipMidi  = midiTip
		if (scoreTip)
				tipScore = scoreTip
	  root = "";
	  for (i = 0; i < level; ++i)
	  	root += "../";
		midiFile = root + "mid/" + midi + ".mid"
		prevPage = prev + ".htm"
		nextPage = next + ".htm"
		document.write('<link href="' + root + 'sty/tch-hymn.css" rel="stylesheet" type="text/css" />')
		document.write('<bgsound src="' + midiFile + '" loop="infinite">')
		delay = location.search.toString()
		if (delay != "")
		{
			delay = delay.substring(1, delay.length)
			document.write('<meta http-equiv="refresh" content="' + delay + ';url=' + nextPage + '?' + delay + '">')
		}
	}
}
//------------------------------------------------
function insertMusicLinks
(
	midi				,	// Full MIDI file name, including extension
	scoreBase		,	// Score file name, down from score directory (no extension)
	scoreExtension	,	// Extension of score file name (must be same as score directory name)
	scoreType			// Decscription of score file type
)
// PURPOSE	Insert insert links for a MIDI & a score file.
// ENTRY	Init() has been called
{
	if (argsOk(arguments.callee, true, false))
 	{
		score = root + scoreExtension + '/' + scoreBase + '.' + scoreExtension
		document.write(' (<a href="' + midi + '" onMouseOver="return stat(\'' + tipMidi + '\')" onMouseOut="return erase()">' + midiWord + '</a>,')
		document.write(' <a href="' + score + '" onMouseOver="return stat(\'' + tipScore + '\')" onMouseOut="return erase()">' + scoreWord + '</a>)')
	}
}
//------------------------------------------------
function lmn
(
	score	// Base name of score file, with path down from nwc directory (no extension, which must be "nwc")
)
// PURPOSE	Insert links for a page's main MIDI file & NoteWorthy Composer score file
// ENTRY	Init() has been called
{
	if (argsOk(arguments.callee, true, false))
		lmn2(midiFile, score)
}
//------------------------------------------------
function lmn2
(
	midi,	// Full path to MIDI file, or path down from MIDI directory. If not full path, should not have extension, which must be "mid".
	score	// Score file name, down from the "nwc" directory (no extension, which must be "nwc")
)
// PURPOSE	Insert links for a MIDI file & NoteWorthy Composer score file. This function is called from lmn(),
//			and is also used for "alternate tune" links on hymn pages.
{
	if (argsOk(arguments.callee, true, false))
	{
		if (midi.indexOf(root) == -1)								// If MIDI lacks full path
			midi = root + 'mid/' + midi + ".mid"					// Add it
		insertMusicLinks(midi, score, "nwc", "NoteWorthy Composer")
	}
}
//------------------------------------------------
function needTranslationTo(language)
{
	document.write('<p class="request" lang="en">If you can trans&shy;late the Eng&shy;lish parts of this page in&shy;to ' + language)
	mail()
     document.write('</p>')
}
//------------------------------------------------
function play()
{
// PURPOSE	Insert embedded MIDI object for browsers that need it, & insert autoplay HTML when appropriate.
// ENTRY	Init() has been called

	if (navigator.appName == "Netscape")
	{
		document.write('<embed src="' + midiFile + '" autostart="true" height="60" width="144" loop="true" repeat="true">')
	}
	if (location.search.toString() != "")
	{
		document.write('<p class="ap">AUTOPLAY</p>')
	}
}
//------------------------------------------------
function setTipBio(tip)

// PURPOSE	Set the hint for the biography link (overrides English default)
{
	tipBio = tip 
}
//------------------------------------------------
function setTipMidi(tip)

// PURPOSE	Set the hint for the MIDI file link (overrides English default)
{
	tipMidi = tip 
}
//------------------------------------------------
function setTipScore(tip)

// PURPOSE	Set the hint for the score file link (overrides English default)
{
	tipScore = tip 
}
//------------------------------------------------
function start
(
	title, 			// Page title
	quote, 		// Scripture quotation
	verse,		// Chapter & verse
	alternate	// Alternate title (optional)
)
{
	play()
	document.write("<h1>" + title + "</h1>")
	if (alternate != null)
		document.write("<h2>" + alternate + "</h2>")
	startx(quote, verse)
	document.write('<center><iframe src="http://nethymnal.org/js/ads1.htm" width=800 height=150 frameborder=0></iframe></center>')

}
//------------------------------------------------
function startx(quote, verse)
{
// PURPOSE		Draw the top of the page
// ENTRY	 		Init() has been called
// ARGUMENTS	quote Scripture quotation (optional)
//					verse Chapter & verse (required if quote is present)
	arrows()
	if (quote && quote.length != 0)
		document.write('<p align="center"><marquee width="90%">' + openQuote + quote + closeQuote + ' ' + verse + '</marquee></p>')
	document.write("<hr/>")
}
//------------------------------------------------
function translator(name, link)
{
// PURPOSE		Write text telling who did the translation from English.
// ENTRY	 		translatedBy is set
// ARGUMENTS	name			Translator's name
//					link			Path to biography page (may be null)
	
	if (translatedBy == null)
		alert(error + "'Translated by' text not set yet")
	else
	{
		document.write(' ' + translatedBy + ' ')
		if (link != null)
			document.write('<script>bio("' + name + '","' + link + '")</script>')
		else if (name != null)
			document.write(name)
	}
}
//------------------------------------------------
function translatorUnknown()
{
// PURPOSE		Write text saying the translator is uknown.
// ENTRY	 		translatorUnknown is set
	
	if (translatorUnknownText == null)
		alert(error + "The 'translatorUnknownText' variable has not been set")
	else
		document.write(" " + translatorUnknownText + ". ")
}
