/* begin library.js */

var print= 0;
var spec= 0;
var syn= 0;
var associate= "textexcavatio-20";

function writeCopy()
{
	var copy= "";
	var today= new Date();
	var date= today.getFullYear();

	copy += '<p class= \"center\"><span class= \"caption\">Copyright &copy; ';
	copy += date + ', ';
	copy += '<span class= \"logo\">TextExcavation<\/span>.<\/span><\/p>';

	if (document.all)
	{
		document.all.copyright.innerHTML= copy;
	}

	else if (document.getElementById)
	{
		document.getElementById('copyright').innerHTML= copy;
	}
}

function writeHeader(pagename, pagekind)
{
	var name= pagename;
	var kind= pagekind;

	var h= fillHeader();

	if (document.all)
	{
		document.all.header.innerHTML= h;
	}

	else if (document.getElementById)
	{
		document.getElementById('header').innerHTML= h;
	}
}

function fillHeader()
{
	var h= "";

	h += '<p class= \"linkboard\">';
	h += '| <a href= \"texts.html\">Texts</a>. ';
	h += '| <a href= \"excavations.html\">Excavations</a>. ';
	h += '| <a href= \"tools.html\">Tools</a>. ';
	h += '| <a href= \"links.html\">Links</a>. |<br\/>';
	h += '| <a href= \"feedback.html\">Offer feedback<\/a>. ';
	h += '| <a href= \"errata.html\">Report errata<\/a>. ';
	h += '| <a href= \"booklist.html\">Browse booklist<\/a>. ';
	h += '| <a href= \"pagecustomizer.html\" onclick= \"window.open';
	h += '(\'pagecustomizer.html\', \'pagecustomizer\', ';
	h += '\'copyhistory=0,directories=0,location=0,menubar=0,resizable=1,'
	h += 'scrollbars=1,status=0,toolbar=0\'); return false\">';
	h += 'Customize page<\/a>. ';
	h += '| <a href= \"knowyourtext/index.html\" target= \"_blank\">Pop window<\/a>. ';
	h += '| <a href= \"index.html\">Visit index<\/a>. |';
	h += '<\/p>';

	return h;
}

function setFont(fon, clas)
{
	var allPageTags= new Array();

	if (document.all)
	{
		allPageTags= document.all;
	}

	else if (document.getElementsByTagName)
	{
		allPageTags= document.getElementsByTagName("*");
	}

	for (var i=0; i<allPageTags.length; i++)
	{
		if (allPageTags[i].className == clas)
		{
			allPageTags[i].style.fontFamily= fon;
		}
	}

	if (clas == 'hebrew')
	{
		for (var i=0; i<allPageTags.length; i++)
		{
			if ((allPageTags[i].className == 'hebrewheader') ||
			(allPageTags[i].className == 'hebrewdisplay') ||
			(allPageTags[i].className == 'hebrewfooter') ||
			(allPageTags[i].className == 'hebrewreg') ||
			(allPageTags[i].className == 'aramaic'))
			{
				allPageTags[i].style.fontFamily= fon;
			}
		}
	}

	if (clas == 'greek')
	{
		for (var i=0; i<allPageTags.length; i++)
		{
			if ((allPageTags[i].className == 'greekheader') ||
			(allPageTags[i].className == 'greekdisplay') ||
			(allPageTags[i].className == 'greekfooter') ||
			(allPageTags[i].className == 'greekreg'))
			{
				allPageTags[i].style.fontFamily= fon;
			}
		}
	}

	if (clas == 'coptic')
	{
		for (var i=0; i<allPageTags.length; i++)
		{
			if ((allPageTags[i].className == 'copticheader') ||
			(allPageTags[i].className == 'copticdisplay') ||
			(allPageTags[i].className == 'copticreg') ||
			(allPageTags[i].className == 'copticfooter'))
			{
				allPageTags[i].style.fontFamily= fon;
			}
		}
	}

	if (clas == 'papy')
	{
		for (var i=0; i<allPageTags.length; i++)
		{
			if (allPageTags[i].className == 'papy')
			{
				allPageTags[i].style.fontFamily= fon;
			}
		}
	}

	if (clas == 'latin')
	{
		for (var i=0; i<allPageTags.length; i++)
		{
			if ((allPageTags[i].className == 'latinheader') ||
			(allPageTags[i].className == 'latindisplay') ||
			(allPageTags[i].className == 'latinfooter') ||
			(allPageTags[i].className == 'latinreg') ||
			(allPageTags[i].className == 'european') ||
			(allPageTags[i].className == 'europeandisplay') ||
			(allPageTags[i].className == 'customdisplay') ||
			(allPageTags[i].className == 'manuscript') ||
			(allPageTags[i].className == 'manuscriptdisplay') ||
			(allPageTags[i].className == 'latinfooter'))
			{
				allPageTags[i].style.fontFamily= fon;
			}
		}
	}

	/* if (clas == 'english')
	{
		if (document.all)
		{
			document.all.tags('body')[0].style.fontFamily= fon;
		}

		else if (document.getElementsByTagName)
		{
			document.getElementsByTagName('body')[0].style.fontFamily= fon;
		}

		for (var i=0; i<allPageTags.length; i++)
		{
			if ((allPageTags[i].className == 'ref') ||
			(allPageTags[i].className == 'ascii') ||
			(allPageTags[i].className == 'default'))
			{
				allPageTags[i].style.fontFamily= fon;
			}
		}
	} */
}

function setCookie (cName, cValue)
{
	var exdate= new Date();

	exdate.setDate(exdate.getDate() + 365);
	document.cookie= cName + '=' + escape(cValue) + ';expires=' + exdate;
}

function deleteCookie(name, path, domain)
{
	if (getCookie(name))
	{
		document.cookie= name + "=" +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		"; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}

function getCookie(cName)
{
	if (document.cookie.length > 0)
	{
		start= document.cookie.indexOf(cName + '=')

		if ( start != -1 )
		{ 
			start= start + cName.length + 1;
			end= document.cookie.indexOf(";", start);

			if (end == -1) end= document.cookie.length;

			return (unescape(document.cookie.substring(start, end)));
		}
	}

	return (null);
}

function setUpInterfacePage()
{
	setUpFonts();
}

function setUpFonts()
{
	if (en= getCookie('englishfont'))
	{
		setFont(en, 'english');
	}

	if (pa= getCookie('papyrusfont'))
	{
		setFont(pa, 'papy');
	}

	if (hb= getCookie('hebrewfont'))
	{
		setFont(hb, 'hebrew');
	}

	if (gk= getCookie('greekfont'))
	{
		setFont(gk, 'greek');
	}

	if (cp= getCookie('copticfont'))
	{
		setFont(cp, 'coptic');
	}

	if (lt= getCookie('latinfont'))
	{
		setFont(lt, 'latin');
	}
}

function writeFooter()
{
	setUpFonts();

	/* prevents pages from being framed */
	eliminateFrames();

	writeFoot();
}

function writeFreeFooter()
{
	/* prevents pages from being framed */
	eliminateFrames();

	writeFoot();
}

function writeFoot()
{
	var f= "";
	var today= new Date();
	var date= today.getFullYear();

	if (navigator.appName == "Microsoft Internet Explorer")
	{
		f += '<p class= \"center\"><span class= \"caption\">TextExcavation ';
		f += date + ', ';
		f += '<a href= \"index.html\" style= \"text-decoration: none\">';
		f += '<code style= \"color: #ff0033\">www.textexcavation.com</code>.';
		f += '<\/a><br\/>Author and designer: Ben C. Smith.<br\/>';
		f += 'File last modified ' + document.lastModified + '.<\/span><\/p>';
	}

	else
	{
		f += '<p class= \"center\"><span class= \"caption\">TextExcavation ';
		f += date + '.<br\/>Ben C. Smith, author and designer.<br\/>';
		f += 'File last modified ' + document.lastModified + '.<\/span><\/p>';
	}

	if (document.all)
	{
		document.all.footer.innerHTML= f;
	}

	else if (document.getElementById)
	{
		document.getElementById('footer').innerHTML= f;
	}
}

function writeEmail()
{
	var e= '';

	e += '<a href= ';
	e += '\"mailto:ben';
	e += '@textexcavation.';
	e += 'com\" onmouseover= \"writeStatus(\'Email: ben@';
	e += 'textexcavation.com.\'); ';
	e += 'return true\" onmouseout= \"writeStatus(\'\'); return true\">Ben C. Smith</a>';

	return e;
}

function writeEmailAddress()
{
	var e= '';

	e += '<a href= ';
	e += '\"mailto:ben';
	e += '@textexcavation.';
	e += 'com\" onmouseover= \"writeStatus(\'Email: ben@';
	e += 'textexcavation.com.\'); ';
	e += 'return true\" onmouseout= \"writeStatus(\'\'); return true\">';
	e += 'ben@textexcavation.com</a>';

	return e;
}

function writeIndexHeaderAndFooter()
{
	writeIndexHeader();
	writeIndexFooter();
}

function hoverOverHR()
{
	writeStatus('Change this page to black and white for printing or viewing purposes.');
	return true;
}

function unHoverOverHR()
{
	writeStatus('');
	return true;
}

function eliminateFrames()
{
	if (top.location !== self.location)
	{
		top.location.replace(self.location);
	}
}

function writeStatus(message)
{
	window.status= message;
}

function setActiveStyleSheet(title)
{
	var i, a, main;

	for (i=0; (a=document.getElementsByTagName("link")[i]); i++)
	{
		if ((a.getAttribute("rel").indexOf("style") !== -1) && (a.getAttribute("title")))
		{
			a.disabled= true;

			if (a.getAttribute("title") == title)
			{
				a.disabled= false;
			}
		}
	}
}

function setSheet()
{
	if (print == 0)
	{
		setActiveStyleSheet('print');
		writePrintFooter();
		print= 1;
	}

	else
	{
		setActiveStyleSheet('styles');
		writeFooter();
		print= 0;
	}
}

function setSpecSheet()
{
	if (spec == 0)
	{
		setActiveStyleSheet('print');
		writePrintFooter();
		spec= 1;
	}

	else if (spec == 1)
	{
		setActiveStyleSheet('spec');
		writePrintFooter();
		spec= 2;
	}

	else
	{
		setActiveStyleSheet('styles');
		writeFooter();
		spec= 0;
	}
}

function setFourColorSheet()
{
	if (print == 0)
	{
		setActiveStyleSheet('blankprint');
		writePrintFooter();
		print= 1;
	}

	else
	{
		setActiveStyleSheet('carlson4');
		writeFooter();
		print= 0;
	}
}

function bookMark(x, y)
{
	var bm= "";
	var address= x;
	var name= y;

	bm += '| <a href= ';
	bm += '\"javascript:window.external.AddFavorite';
	bm += '(\'' + address + '\',';
	bm += '\'' + name + '\')">Bookmark</a>. ';

	if (document.all)
	{
		document.all.bookmark.innerHTML= bm;
	}

	else if (document.getElementById)
	{
		document.getElementById('bookmark').innerHTML= bm;
	}
}

function writePrintFooter()
{
	/* prevents pages from being framed */
	eliminateFrames();

	var p= "";

	if (navigator.appName == "Microsoft Internet Explorer")
	{
		p += '<p class= \"center\"><span class= \"caption\" id= \"printfooter\">';
		p += 'TextExcavation 2009, <a href= \"index.html\" ';
		p += 'style= \"text-decoration: none\">';
		p += '<code>www.textexcavation.com<\/code><\/a>.<br\/>';
		p += 'Author and designer: Ben C. Smith.<br\/>';
		p += 'File last modified ' + document.lastModified + '.<\/span><\/p>';
	}

	else
	{
		p += '<p class= \"center\"><span class= \"caption\">Text';
		p += 'Excavation 2009.<br\/>Ben C. Smith, author and designer.<br\/>';
		p += 'File last modified ' + document.lastModified + '.<\/span><\/p>';
	}

	if (document.all)
	{
		document.all.footer.innerHTML= p;
	}

	else if (document.getElementById)
	{
		document.getElementById('footer').innerHTML= p;
	}
}

function getSelectValue(formname, selectname)
{
	var dropDownMenu = document[formname][selectname];
	var selectedItem = dropDownMenu.selectedIndex;
	return dropDownMenu.options[selectedItem].value;
}

function getCheckValue(formname, checkname)
{
	var check= document[formname][checkname];
	var val= "";

	if (check.checked)
	{
		val= "yes";
	}

	else
	{
		val= "no";
	}

	return val;
}

function getOptValue(formname, optname)
{
	var radioButtons = document[formname][optname];
	for (x=0; x<radioButtons.length; x++)
	{
		if (radioButtons[x].checked)
		{
			return radioButtons[x].value;
		}
	}
}

function copyText(field)
{
	var tempVal= eval("document." + field);
	tempVal.focus();
	tempVal.select();
	textRange= tempVal.createTextRange();
	textRange.execCommand("Copy");
}

function clearText(textArea)
{
	textArea.value= "";
	var disp= "";

	disp += '<p class= \"center\"><span';
	disp += ' class= \"display\" style= \"text-align: center\"><span class= \"english\">';
	disp += 'Text will be';
	disp += ' displayed in this box for preview.<\/span><\/span><\/p>';

	if (document.all)
	{
		document.all.display.innerHTML= disp;
	}

	else if (document.getElementById)
	{
		document.getElementById('display').innerHTML= disp;
	}
}

function clearScript(textArea)
{
	textArea.value= "";
	var disp= "";

	disp += '<p class= \"center\"><span';
	disp += ' class= \"display\" style= \"text-align: center\"><span class= \"english\">';
	disp += 'Display box.<\/span><\/span><\/p>';

	if (document.all)
	{
		document.all.display.innerHTML= disp;
	}

	else if (document.getElementById)
	{
		document.getElementById('display').innerHTML= disp;
	}
}

function executeScript()
{
	eval(document.scriptform.script.value);
}

function clearDisplay()
{
	if (document.all)
	{
		document.all.display.innerHTML= "";
	}

	else if (document.getElementById)
	{
		document.getElementById('display').innerHTML= "";
	}
}

function displayCode()
{
	var cod= document.codeform.code.value;

	if (document.all)
	{
		document.all.display.innerHTML= cod;
	}

	else if (document.getElementById)
	{
		document.getElementById('display').innerHTML= cod;
	}
}

function nothing()
{
	// nothing happens
}

function writeIndividualAmazonLink(linktext, id)
{
	var link= "";

	link += '<a class= \"moderntitle\" ';
	link += 'href= \"http:\/\/www.amazon.com\/exec\/obidos\/ASIN\/';
	link += id + '\/';
	link += associate + '\" ';
	link += 'target= \"_blank\" onmouseout= \"writeStatus(\'\'); return true\" ';
	link += 'onmouseover= \"writeStatus(\'Buy it from Amazon.\'); return true\">';
	link += linktext;
	link += '<\/a>';

	return link;
}

function writeQuickAmazonLink(linktext, id)
{
	var link= "";

	link += '<a class= \"moderntitle\" ';
	link += 'href= \"http:\/\/buybox.amazon.com\/exec\/obidos\/redirect?tag=';
	link += associate;
	link += '&link_code=qcb&creative=23424&camp=2025&path=\/dt\/assoc\/tg\/aa\/xml';
	link += '\/assoc\/-\/';
	link += id + '\/';
	link += associate;
	link += '\/ref%3Dac_bb5_\" onmouseout= \"writeStatus(\'\'); return true\" ';
	link += 'onmouseover= \"writeStatus(\'Buy it from Amazon with Quick-Click.\'); return';
	link += ' true\" ';
	link += 'onclick= \"openAmazonWindow(\'http:\/\/buybox.amazon.com\/exec\/obidos\/';
	link += 'redirect?tag=';
	link += associate;
	link += '&link_code=qcb&creative=23424&camp=2025&path=\/dt\/assoc\/tg\/aa\/xml';
	link += '\/assoc\/-\/';
	link += id + '\/';
	link += associate;
	link += '\/ref%3Dac_bb5_\'); return false\">';
	link += linktext;
	link += '<\/a>';

	return link;
}

function writeIndividualAmazonImageLink(image, id)
{
	var link= "";

	link += '<a href= \"http:\/\/www.amazon.com\/exec\/obidos\/ASIN\/';
	link += id + '\/';
	link += associate + '\" ';
	link += 'target= \"_blank\" onmouseout= \"writeStatus(\'\'); return true\" ';
	link += 'onmouseover= \"writeStatus(\'Buy it from Amazon.\'); return true\">';
	link += '<img src= \"images\/' + image + '\" alt= \"Buy it from Amazon.\" ';
	link += 'border= \"0\" style= \"margin-bottom: 2px\"\/>';
	link += '<\/a>';

	return link;
}

function writeQuickAmazonImageLink(image, id)
{
	var link= "";

	link += '<a href= \"http:\/\/buybox.amazon.com\/exec\/obidos\/redirect?tag=';
	link += associate;
	link += '&link_code=qcb&creative=23424&camp=2025&path=\/dt\/assoc\/tg\/aa\/xml';
	link += '\/assoc\/-\/';
	link += id + '\/';
	link += associate;
	link += '\/ref%3Dac_bb5_\" onmouseout= \"writeStatus(\'\'); return true\" ';
	link += 'onmouseover= \"writeStatus(\'Buy it from Amazon with Quick-Click.\'); return';
	link += ' true\" ';
	link += 'onclick= \"openAmazonWindow(\'http:\/\/buybox.amazon.com\/exec\/obidos\/';
	link += 'redirect?tag=';
	link += associate;
	link += '&link_code=qcb&creative=23424&camp=2025&path=\/dt\/assoc\/tg\/aa\/xml';
	link += '\/assoc\/-\/';
	link += id + '\/';
	link += associate;
	link += '\/ref%3Dac_bb5_\'); return false\">';
	link += '<img src= \"images\/' + image + '\" ';
	link += 'alt= \"Buy it from Amazon with Quick-Click.\" ';
	link += 'border= \"0\" style= \"margin-bottom: 2px\"\/>';
	link += '<\/a>';

	return link;
}

function writeIndividualBookLink(linktext, id)
{
	var link= writeIndividualAmazonLink(linktext, id);
	document.write(link);
}

function writeQuickBookLink(linktext, id)
{
	var link= writeQuickAmazonLink(linktext, id);
	document.write(link);
}

function writeIndividualBookImageLink(image, id)
{
	var link= writeIndividualAmazonImageLink(image, id);
	document.write(link);
}

function writeQuickBookImageLink(image, id)
{
	var link= writeQuickAmazonImageLink(image, id);
	document.write(link);
}

/* put in HTML: <script language= "javascript"
type= "text/javascript"><!--
writeComboBookLink(image, linktext, id, floatpos); //--></script> */

function writeComboBookLink(image, linktext, id, floatpos)
{
	var floatBox= "";

	floatBox += '<div class= \"caption\" style= \"width: 15%; margin: 0px; ';
	floatBox += 'padding: 0px; clear: ' + floatpos + '; float: ' + floatpos + '\" ';
	floatBox += 'border= \"0\">';
	floatBox += writeQuickAmazonImageLink(image, id) + '<br\/>';
	floatBox += writeIndividualAmazonLink(linktext, id) + '<span style= ';
	floatBox += '\"color: #000000\"></span><br\/>&#160;<\/div>';

	/* floatBox += '<table class= \"grid\" style= \"width: 65px; margin: 0px; padding: 0px;';
	floatBox += 'float: ' + floatpos + '\" border= \"0\"><tr class= \"grid\">';
	floatBox += '<td class= \"caption\">';
	floatBox += writeQuickAmazonImageLink(image, id) + '<br\/>';
	floatBox += writeIndividualAmazonLink(linktext, id) + '<\/td><\/tr><\/table>'; */

	document.write(floatBox);
}

function openAmazonWindow(ref)
{
	var amazonwin= window.open(ref,"amazonwindow",
	"location=yes,scrollbars=yes,width=380,height=450,screenX=10,screenY=10,top=10,left=10");
	amazonwin.focus();
}

/* end library.js */