// ==================================================================================
// ALI Swahili web pages: javascript functions which are used on each page (not toc pages).
// ==================================================================================
// Hannes Hirzel, July, 26, 2002
//                August, 18, 2002
//                November, 2002
//                December, 2002
//                August, 2005
//
//
// Style sheets: the individual (non-toc) pages use either
// - kuokota/e-sc800x600.css  or
// - kuokota/e-sc1024x768.css
// ==================================================================================


// t = "appName:" + navigator.appName  +"\n" // Microsoft Internet Explorer
// t += "platform:" + navigator.platform.substring(0,3) +"\n"   // Mac
// t += "appVersion:" + navigator.appVersion
// document.write(t)
// appName:Microsoft Internet Explorer 
//  platform:Mac 
//  appVersion:4.0 (kompatibel; MSIE 5.0; Macintosh; I; PPC) 
function IEMac() {
// only used for morphological analysis feedback area as a workaround 
   if (!navigator.platform.substring(0,3) == "Mac") {return false}
   if (navigator.appVersion.indexOf('MSIE') > 0) {return true}
   return false
}
// ==================================================================================
// table of contents
// ==================================================================================

// global color definitions
// chooseSpecificStyleSheet
// faharasa functions  
// quoting functions
// eliminating dashs
// write active span tag (color change for Swahili words)
// highlighting (main pane and drawer pane)
// show and hide
// calculate page type
// writeTitlePane
// animation of sentences
//    aswWord
//    aswExample
// (basic.js)
// window size

// ==================================================================================
// Initialize:
// ==================================================================================


// calculate screen type
// alert('screen.width = ' + screen.width)

mediumScreen = (screen.width < 1024)
mediumScreen = true

chooseSpecificStyleSheet()
// includes choosing of  background; added October 2002


// ==================================================================================
// End Initialize
// ==================================================================================



// ==================================================================================
// Global color definitions
// ==================================================================================

// The two dashes at the beginning of a line mark comment,
// i.e. the browser does not try to interpret the text to the right of these
// dashes.

// aswHLC= '#FFFF33';     // HLC = highlight color
aswHLC= '#FFAD00';     // HLC = highlight color; now the same as the dialogue color

// aswBG = '#FFFFFF';     // BG  = background color  = white
aswBG = '#FDE9C7';     // BG  = background color  = yellow 


aswDialogueColor = '#FFAD00';   // dialogue, yellow
aswDialogueColorOMO = '#F4A400';   // yellow; OMO = on mouse over

aswGrammarColor  = '#EB3343'    // grammar, red
aswGrammarColorOMO  = '#D42131'    // grammar, red, on mouse over


// aswVocabColor    = '#C87724;    // brown


// Faharasa-Links: There are two variants; the latter one is the one
// which will be active. So you may exchange the variants just by copying
// the one you like after the other.


// Variant brown
aswFahLinkColorOnMouseOver = '#996600';  
aswFahLinkColorOnMouseOut = '#996600';

// Variant blue
// aswFahLinkColorOnMouseOver = '#0000FF'; // blue
// aswFahLinkColorOnMouseOut = '#808080';

var screenType 



function writeStyleSheetLink(aCSSname) {
linkRelPref = '<link rel="stylesheet" type="text/css" href="'
document.write(linkRelPref + aCSSname + '">\n'); 
}


function chooseSpecificStyleSheet() {

// adapt path for conc (zaidi)
// assign css file names
if (getMyFilename() == "Site-map.html") {
	// the special case - site map
	mediumCSS = 'sitemap-800x572.css'
	largeCSS =  'sitemap-1024x732.css'
	// largeCSS = mediumCSS
	}
else { 
	// for all other text pages
	mediumCSS = '../../kuokota/e-sc800x600.css'
	largeCSS =  '../../kuokota/e-sc1024x768.css'	
	}
if (mediumScreen)  { writeStyleSheetLink(mediumCSS);
                                 screenType = 'svga'}
   else                    {  writeStyleSheetLink(largeCSS)
                                 screenType = 'xvga'
    }
}


function writeStyleSheetLinkBg2(pathPrefix) {
if (mediumScreen)  { writeStyleSheetLink(pathPrefix + "e-sc800x600-bg2.css")}
   else                    {  writeStyleSheetLink(pathPrefix +  "e-sc1024x768-bg2.css")}
}


// ==================================================================================
// faharasa functions 
// ==================================================================================


var aswFahLink = ''

readFaharasaLinkColor()

function readFaharasaLinkColor() {
	if (aswFahLink != '') {return aswFahLink}
	else
	{aswFahLink = '#000000' // default value
	 c = document.cookie
	 c = c.toString()
	 if (c.length> 1) {
	   re = /faharasa(\w\w\w\w\w\w)/
	   if (re.test(c)) {aswFahLink = '#' + (c.match(re)[1])}
	  }
	 }	
}



function fa(myHTMLfnameWithoutExtension, myLinkText) {

// writes text, that changes color of text and opens faharasa window

	var a = '<span class="faharasaLink" onClick="faharasa('

	a += encloseInSingleQuote(myHTMLfnameWithoutExtension)

	if (myLinkText != null && myLinkText != '') {a += ', '+ encloseInSingleQuote(myLinkText)}
	else  {myLinkText = myHTMLfnameWithoutExtension}

	a += ');" '
	a += '>'
	a += coloredText(myLinkText, aswFahLink)
	a += '</span>'

	document.writeln(a)
}


function coloredText(aString,aColor) {
	a = '<span style=' + encloseInDoubleQuote('color: ' + aColor)
	a += '>' + aString + '</span>'
	return a
}


function faharasa(myHTMLfnameWithoutExtension, myTitle, myHeight) {
	var w;
	if (myTitle == '' || myTitle==null) {myTitle = myHTMLfnameWithoutExtension}
	var url;
	url = '../../faharasa/' + myHTMLfnameWithoutExtension +'.html';
	if (myHeight == null) {myHeight = 150}
	var windowFeatures;
	windowFeatures = "height=" + myHeight + ", width=270, left=120, top=200";
	windowFeatures += ", scrollbars=yes,resizable=yes";
	windowName = withOutHTMLTagsAndSpace(myTitle)
	// alert(windowFeatures)
	w=window.open(url,windowName,windowFeatures);
	w.moveTo(30,10)
}


function faharasaWide(myHTMLfnameWithoutExtension, myTitle, myHeight) {
	// open point: What does myTitle really mean?
	var w;
	if (myTitle == '') {myTitle = myHTMLfnameWithoutExtension}
	var pg;
	pg = '../../faharasa/' + myHTMLfnameWithoutExtension +'.html';
	var size;
	size = "height=" + myHeight + ", width=400, left=120, top=200";
	w=open(pg,withOutHTMLTagsAndSpace(myTitle),size);
}


function withOutHTMLTagsAndSpace(aString) {
	  res = aString.replace(' ','_')
	  re = /<\/?\w+>/gi
	  return res.replace(re,'')
}	



// ==============================================================




// ==================================================================================
// quoting functions 
// ==================================================================================


function encloseInSingleQuote(aValue) {
	return "'" + aValue + "'"
}


function encloseInDoubleQuote(aValue) {
	// synonymous function to encloseInSingleQuote	
return '"' + aValue + '"'
}



// ==================================================================================
//  Animation of Swahili sentences / words
// ==================================================================================

function eliminateDash(aString) {
	l = aString.length
	if (aString.substring(0,1) == '-') {result = aString.substring(1,l)}
	else {result = aString}
	l = result.length
	if (result.substring(l-1,l) == '-') {result = result.substring(0,l-1)}
	return result
}



function firstLetterUCase(aString) {
	return  (aString.substring(0,1)).toUpperCase() + aString.substring(1, aString.length)
}



function openingSpanTagWithDynColorChange(aColor, id) {
	var a = '<span '
	if (id != null) { a += ' id=' + encloseInDoubleQuote(id) + ' '}
	a += 'onMouseOver='
	a += encloseInDoubleQuote('this.style.color=' + encloseInSingleQuote(aColor))
	a += '>'
	return a
}



function encloseInSpanTagWithDynColorChange(aString, aColor, id) {
	if (aColor==null) {aColor = 'red'}
	if (aColor=='red') {aColor = '#EB3343'}    // red of grammar

	var a = openingSpanTagWithDynColorChange(aColor, id)
	a += aString
	a += '</span>'
return a
}



// ==================================================================================
//  highlight text elements
// ==================================================================================


function highlight(myID, myColor) {
	// alert(myID)
	if (document.getElementById(myID)) {	 
	document.getElementById(myID).style.backgroundColor = myColor}
	else {alert('Element ' + encloseInSingleQuote(myID) + ' is not defined. The highlighting command fails! Please either define the element or remove it from the highlighting list!')}
}


function aswColor(myID, myColor) { 
	document.getElementById(myID).style.color = myColor;
}

function setBgColor(obj, myColor) {
	obj.style.backgroundColor = myColor
}
	





function spanTagMPHighLight(aTextString, anId1, anId2, anId3, anId4, anId5, anId6, anId7, anId8, anId9, anId10, anId11, anId12) {
	// called by the web page author
	
	// highlights aTextString in the main pane (MP) and span area anId
	// this function may be shortened using the arguments array. However the readability in this version is maybe better.

	var anIdq = encloseInSingleQuote(anId1)

	if (anId2 != null) {var anIdq2 = ''; anIdq2 = encloseInSingleQuote(anId2)}
	if (anId3 != null) {var anIdq3 = ''; anIdq3 = encloseInSingleQuote(anId3)}
	if (anId4 != null) {var anIdq4 = ''; anIdq4 = encloseInSingleQuote(anId4)}
	if (anId5 != null) {var anIdq5 = ''; anIdq5 = encloseInSingleQuote(anId5)}
	if (anId6 != null) {var anIdq6 = ''; anIdq6 = encloseInSingleQuote(anId6)}
	if (anId7 != null) {var anIdq7 = ''; anIdq7 = encloseInSingleQuote(anId7)}
	if (anId8 != null) {var anIdq8 = ''; anIdq8 = encloseInSingleQuote(anId8)}
	if (anId9 != null) {var anIdq9 = ''; anIdq9 = encloseInSingleQuote(anId9)}
	if (anId10 != null) {var anIdq10 = ''; anIdq10 = encloseInSingleQuote(anId10)}
	if (anId11 != null) {var anIdq11 = ''; anIdq11 = encloseInSingleQuote(anId11)}
	if (anId12 != null) {var anIdq12 = ''; anIdq12 = encloseInSingleQuote(anId12)}

	var a = '<span onMouseOver="'
	// a += 'this.style.backgroundColor = aswHLC; '
	// a += 'this.style.backgroundColor = \'' + aswHLC +'\'; '
	a += 'this.style.backgroundColor = \'' + aswHLC +'\'; '
	// yyy a += 'setBgColor(this,' + aswHLC + '); '
	a += 'highlight(' + anIdq + ', aswHLC); '
	if (anId2 != null) {a += 'highlight(' + anIdq2 + ', aswHLC); '}
	if (anId3 != null) {a += 'highlight(' + anIdq3 + ', aswHLC); '}
	if (anId4 != null) {a += 'highlight(' + anIdq4 + ', aswHLC); '}
	if (anId5 != null) {a += 'highlight(' + anIdq5 + ', aswHLC); '}
	if (anId6 != null) {a += 'highlight(' + anIdq6 + ', aswHLC); '}
	if (anId7 != null) {a += 'highlight(' + anIdq7 + ', aswHLC); '}
	if (anId8 != null) {a += 'highlight(' + anIdq8 + ', aswHLC); '}
	if (anId9 != null) {a += 'highlight(' + anIdq9 + ', aswHLC); '}
	if (anId10 != null) {a += 'highlight(' + anIdq10 + ', aswHLC); '}
	if (anId11 != null) {a += 'highlight(' + anIdq11 + ', aswHLC); '}
	if (anId12 != null) {a += 'highlight(' + anIdq12 + ', aswHLC); '}

	a += 'this.style.cursor='
	a +=  encloseInSingleQuote('hand') +';" '
	a += ' onMouseOut="'
	a += 'this.style.backgroundColor = aswBG; '            // aswBG
	a += 'highlight(' + anIdq + ', aswBG); '
	if (anId2 != null) {a += 'highlight(' + anIdq2 + ', aswBG); '}
	if (anId3 != null) {a += 'highlight(' + anIdq3 + ', aswBG); '}
	if (anId4 != null) {a += 'highlight(' + anIdq4 + ', aswBG); '}
	if (anId5 != null) {a += 'highlight(' + anIdq5 + ', aswBG); '}
	if (anId6 != null) {a += 'highlight(' + anIdq6 + ', aswBG); '}
	if (anId7 != null) {a += 'highlight(' + anIdq7 + ', aswBG); '}
	if (anId8 != null) {a += 'highlight(' + anIdq8 + ', aswBG); '}
	if (anId9 != null) {a += 'highlight(' + anIdq9 + ', aswBG); '}
	if (anId10 != null) {a += 'highlight(' + anIdq10 + ', aswBG); '}
	if (anId11 != null) {a += 'highlight(' + anIdq11 + ', aswBG); '}
	if (anId12 != null) {a += 'highlight(' + anIdq12 + ', aswBG); '}

	a += 'this.style.cursor='
	a +=  encloseInSingleQuote('default') +';" '
	a += '>'
	a += aTextString
	a += '</span>'
	document.writeln(a)
	// alert(a)
}




// ==================================================================================
//   show / hide drawers
// ==================================================================================



function aswHideDrawer(drawerID) { 
	document.getElementById(drawerID).style.visibility = 'hidden';
}


function aswNoSpaceForDrawer(drawerID, drID2, drID3, drID4, drID5) { 
	e =document.getElementById(drawerID).style;
	e.display = 'none';
	e.visibility = 'hidden';
	if (!drID2 == null) {e = document.getElementById(drID2).style; e.display = 'none'; e.visibility = 'hidden'}
	if (!drID3 == null) {e = document.getElementById(drID3).style; e.display = 'none'; e.visibility = 'hidden'}
	if (!drID4 == null) {e = document.getElementById(drID4).style; e.display = 'none'; e.visibility = 'hidden'}
	if (!drID5 == null) {e = document.getElementById(drID5).style; e.display = 'none'; e.visibility = 'hidden'}
}



function aswShowDrawer(drawerID) { 
	document.getElementById(drawerID).style.display = 'block';
	document.getElementById(drawerID).style.visibility = 'visible';
}





// ==================================================================================
// calculate page type  attributes 
// ==================================================================================


 


function getMyFilename() {
	// file name without path, e.g. U03sar-eb01.html
	pieces = window.location.href;
	pieces = pieces.split('/');
	return pieces[pieces.length-1]
}


function getMyFilenameWithoutPageNo() {
	// e.g. U03-sar-eb
	var fname = getMyFilename()
	baseFileName = fname.split('.')[0]
	baseFileName = baseFileName.slice(0, baseFileName.length - 2)
	return baseFileName
}	


function getASWPageType() {
	// maz, sar, msa  (dialogue, grammar, vocabulary)
	var fname = getMyFilename();
	return fname.slice(3, 6)
}


function getASWUnitId() {
	// eg. U01, U02, U03 ...
	var fname = getMyFilename();
	return fname.slice(1, 3)
}


function getASWPageNo() {
	// eg. 01, 02, ...15
	var fname = getMyFilename();
	pieces = fname.split('.');
	n = pieces[0]
	l = n.length
	pageNo = n.slice(l-2,l)
	if (pageNo.slice(0,1) == '0') {pageNo = pageNo.slice(1,2)}
	return pageNo
}


function getASWPageIdent() {
	// eg.   sar-a3
	var fname = getMyFilename();
	pieces = fname.split('.');
	n = pieces[0]
	l = n.length
	pageNo = n.slice(l-2,l)
	letter = n.slice(l-3,l-2)
	type = n.slice(3,6);
	if (pageNo.slice(0,1) == '0') {pageNo = pageNo.slice(1,2)}
	return type + "-" + letter + pageNo
}




// ==================================================================================
// title pane
// ==================================================================================


function titlePrefix(aType) {
	// quotes are OK
	a =  '<div id="titleStringBox'
	a += aType
	a += '">'
	return(a)
}



function writeTitleHTMLCode(aTitlePaneType, aTitleString) {
    // aTitleString may be of the form 'Verb (kitenzi): part 2'
    // separate the English and the Swahili part
    
    temp =aTitleString.split('(');
    a1 = temp[0]
    swahili = temp[1]
     
    temp = swahili.split(')')
    swahili = temp[0]
    a3 = temp[1]
    
    aTitleString = a1 + a3 + "<br>" + '<span id="titleStringFontSwahili">' + swahili + "</span>"
    
    document.write(titlePrefix(aTitlePaneType) + aTitleString  + '</div>')
}





function putUnitNoDisplay() {
	unitNumberU = getASWUnitId()
	unitNumberDisplay = unitNumberU
	if (unitNumberU.substring(0,1) == '0' ) {unitNumberDisplay=unitNumberU.substring(1,2)}

	if ( (getMyFilename() != 'index.html') & (getMyFilename() != 'start.html')) {
	  a = '<div id=' + encloseInDoubleQuote('lblUnit') + ' align=center>UNIT<br>'  + unitNumberDisplay 
	  a += '<br><span class="pageno">' + getASWPageIdent() + '</span>'
	  a += '</div>'
	  document.write(a)
	}
}




function writeTitlePane(aValue) {
	// called by the web page author
	var ptype = getASWPageType().toUpperCase();
	if (ptype == 'SAR') {writeTitleHTMLCode('Grammar', aValue)}
	if (ptype == 'MAZ') {writeTitleHTMLCode('Dialogue', aValue)}
	if (ptype == 'MSA') {writeTitleHTMLCode('Vocab', aValue)}
	putUnitNoDisplay()
}




/* -------------------------------------- navigation Pane -------------------------------------------------- */

function openNavigationAidWindow()
{	var size; 
	var pg;
	pg = '../../kuokota/navigationaid.html'
	features = "height=500, width=300, left=120, top=50";
	// the new window will get it's own name
	wname = 'navigationaid'
	w=open(pg, wname, features);
	// make sure the name is assigned to the new window
	w.name = wname
	w.focus
}



function writeOutButtonCode(id, upURL) {
	b = '<div id=' 
	b += encloseInDoubleQuote(id) 
	b += ' onClick="javascript:window.location.href='
	b += encloseInSingleQuote(upURL)
	b += '; " '
	b += handCursorCode()
	b += '></div>'
	document.write(b)
}



function handCursorCode() {
	cd =  ' onMouseOver="'
	cd += 'this.style.cursor='
	cd +=  encloseInSingleQuote('hand') +';" '
	cd += ' onMouseOut="'
	cd += 'this.style.cursor='
	cd +=  encloseInSingleQuote('default') +';" '
 return(cd)
}


function writeOutButtonCodeWithImagePositioned(upURL, svgaImage, xvgaImage, top, left) {

	b = '<div ' 
	b += ' onClick="javascript:window.location.href='
	b += encloseInSingleQuote(upURL)
	b += '; " '
	b += handCursorCode()
	b += inLineStyleDefinitionPosition(top,left)  
	b += '><img  src="../../picha/'
	if (screenType == 'svga') { image = svgaImage} 
		else {image= xvgaImage}
	b += image
	b += '"></div>'
	document.write(b)
}


function inLineStyleDefinitionPosition(top, left) {


	a =  ' style="position: absolute; top: '
	a += adaptPixelCountForScreenSize(top) + 'px; ' 
	a += 'left: '
	a += adaptPixelCountForScreenSize(left) + 'px; '
	a += '"' 
	return a
}

function adaptPixelCountForScreenSize(aPixelCount) {
if (screenType == 'svga') { return Math.round(aPixelCount / 1.28) } 
		else {return aPixelCount}
	
}

function getDefaultUpURL(baseFileName) {
	return baseFileName.slice(0, 3) + '-toc.html'
}


function calcPageNumber(current, offset) {
	var p = eval(current + offset)
	p = '00' + p
	return p.slice(p.length -2, p.length)
}




function writeNavigationPane(prevURL, upURL, nextURL) {
	// called by the web page author

	// default value for upURL is Unitname + "-toc.html"
	// calculate default values if necessary

	baseFileName = getMyFilenameWithoutPageNo()
	pgNumber = getASWPageNo()

	if (upURL=='') {upURL = getDefaultUpURL(baseFileName)}
	if (nextURL=='') { nextURL = baseFileName + calcPageNumber(pgNumber, '+ 1') + '.html'}
	if (prevURL=='') { prevURL = baseFileName + calcPageNumber(pgNumber, '- 1') + '.html'}


	// write navigation buttons
	writeOutButtonCode('infoButton','../../kuokota/nav-index.html')
	writeOutButtonCode('homeButton', upURL)
	writeOutButtonCode('leftButton', prevURL)
	writeOutButtonCode('rightButton', nextURL);   
	
	// write out field for morphological analysis info of the word over which the mouse is.
	document.write('<div id="aswWordInfo">&nbsp;</div>')   

}


// -------------------------------------------------------------------------------------------------






/* ---------------- animation of sentences --------------------- */



// function analysisWindow(myText) {alert(myText)}
function analysisWindow(analysis) {
var w = null;
var p;
var s;
 s = "height=120, width=320, left=120, top=200";
//  w=open(null,'',s); // Martin Webb p. 255
    w=open('../../empty.html','',s); // Martin Webb p. 255
w.document.write('<html><head>')
w.document.write('<LINK href="../../kuokota/morph-analysis.css" rel=stylesheet type=text/css>')
w.document.write('<body>')
  w.document.writeln(analysis);
w.document.write('</body></html>')
 return false
}



// --------------------------------------------
// Object definition aswExample
// --------------------------------------------


// member functions


function aswExampleAsHTML() {
// displays whole sentence word by word.
	a = ''
	var i = 0
	for (i=0;i<this.words.length;i++) {
		a += (this.words[i]).asHTML() + ' ' }
	return a
}






function currentWord() {
	// this.words.length-1 is the index for the current word
	return this.words[(this.words.length)-1]
}

function addWord(aString) {
	this.words[this.words.length] = new aswWord(aString)
}


function addExampleInfo(aString) {
	this.info = aString
}

// constructor

function aswExample(myId) {
	function writeHTML() {
		document.write(this.asHTML())
        }
        
    this.id = myId
    this.words = new Array()
    this.addWord = addWord
    this.currentWord = currentWord
    this.addExampleInfo = addExampleInfo
    this.writeHTML = writeHTML
    this.asHTML = aswExampleAsHTML
}


// --------------------------------------------
// End of Object definition
// --------------------------------------------




// --------------------------------------------
// Object definition aswWord
// --------------------------------------------

// member functions
// asHTML(), writeHTML()
// aswWord(aString, gloss) (constructor)
// aswWordWithId(arg1, id1, arg2, id2)   (constructor)

function aswWordAsHTML() {
	a = ''
	if (this.morphemes.length > 0) {
	    a += infoFieldSpanTag('aswWordInfo', this.morphemesAsHTML())
            a += this.display() + '</span>'}
	else { a += this.display()}
	return a
}

function aswWordDisplay() {
	if (this.animationText == '') { return this.name}
	else { return this.animationText}
}


function aswWordWriteHTML() {
	document.write(this.asHTML())
}

function morphemesAsHTMLMonospace(obj) {
// return table with all morphemes belonging to the word
	strMorphs = ''
	strGlosses = ''
	for (j=0;j<obj.morphemes.length;j++) {
		
		m = obj.morphemes[j].morpheme
		gl = obj.morphemes[j].glossWithPS()
		m0 = m.length
		g0 = gl.length
		s = Math.abs(m0-g0) 
		if (m0 > g0) {
				// fill up gloss with spaces
				for (i=1; i <= s; i++) {
					gl += "&nbsp;"
				}
			}
		else if (m0 < g0) {
			// fill up morpheme with spaces
			for (i=1; i <= s; i++) {
				m += "&nbsp;"
			}
		}
		strMorphs += m + "&nbsp;"
		strGlosses += gl + "&nbsp;"
		}
	// alert(strMorphs + "\n" + strGlosses)
	a = "<span class=morphologicalAnalysisFixSpaceFont>"
	return (a + strMorphs + "<br>" + strGlosses + "</span>")
}function morphemesAsHTMLTable(obj) {
	//~ // added a parameter obj and replaced 'this' by 'obj'
	a = '<table class=infoTable><tr>'
	for (j=0;j<obj.morphemes.length;j++) {
		a +='<td class=infoTable>'
		a += (obj.morphemes[j]).morpheme + '</td>' }
	a += '</tr><tr>'
	for (j=0;j<obj.morphemes.length;j++) {
		a +='<td class=infoTable>'
		a += (obj.morphemes[j]).glossWithPS() + '</td>' }
	a += '</tr></table>'
	return a
}

function morphemesAsHTML() {
// return table with all morphemes belonging to the word
	if (IEMac()) {                         // (!IEMac()) for testing under Windows/Linux
		return morphemesAsHTMLMonospace(this)
		}
	else {
		return morphemesAsHTMLTable(this)
	}
}

function addMorpheme(aString, gloss, aDynColor, id) {
     
	 if (aDynColor == 'green') {aDynColor = '#AE5903'}           // light brown #C87724
	 this.addMorphemePS('', aString, gloss, aDynColor, id)
}




function addMorphemePS(ps, aString, gloss, aDynColor, id) {
	  this.morphemes[this.morphemes.length] = new aswMorpheme(aString, gloss, ps)
	  // In any case aString is stored a second time for the display
	  // either with or without animation.

	  aString = eliminateDash(aString)

	  if ((this.morphemes.length == 1) && (this.firstLetterUppercase == true)) {
		aString = firstLetterUCase(aString)
  }

	  if (aDynColor == null) {this.addAnimation(aString)}
	 else {this.addAnimation(encloseInSpanTagWithDynColorChange(aString, aDynColor, id))}
}



function addAnimation(aString) {
	this.animationText += aString
}





// constructor
function aswWord(aswName) {
    this.name = aswName
    this.animationText = ''
    this.firstLetterUppercase = false
    this.addAnimation = addAnimation
    this.morphemes = new Array()
    this.addMorpheme = addMorpheme
    this.addMorphemePS = addMorphemePS
    this.morphemesAsHTML = morphemesAsHTML
    this.writeHTML = aswWordWriteHTML
    this.display = aswWordDisplay  // helper function for asWordAsHTML
    this.asHTML = aswWordAsHTML
}



// --------------------------------------------
// End of Object definition aswWord
// --------------------------------------------




// --------------------------------------------
// Object definition aswMorpheme
// --------------------------------------------


function aswMorphemeAsHTML() {
	 return this.name
}


function aswGlossWithPS() {
	firstLetter = this.ps.substring(0,1)
	if (firstLetter == 'N') {
	  return this.gloss + '(' + this.ps + ')' }
	else 
	 {return this.gloss} 
}


function aswMorphemeWriteHTML() {
	document.write(this.asHTML())
}

// constructor

function aswMorpheme(aString, gloss, ps) {	
	    this.morpheme = aString
	    this.gloss = gloss	
	    this.glossWithPS = aswGlossWithPS
	    this.ps = ps
	    this.writeHTML = aswMorphemeWriteHTML
	    this.asHTML = aswMorphemeAsHTML
}



// -----------------------------------------------------------------------

function infoFieldSpanTag(infoFieldName, info) {
	// gives back a span tag with mouseOver function 
	// info for field infoFieldName
	var a = ''
	a += '<span onMouseOver='
	var b = "document.getElementById('"
	b += infoFieldName
	b += "').innerHTML="
	b += encloseInSingleQuote(info)
	a+=  encloseInDoubleQuote(b)   
	a+=  ' onMouseOut='
	b = "document.getElementById('"
	b += infoFieldName
	b += "').innerHTML=''"
	a+=  encloseInDoubleQuote(b)
	a+=  ' onClick='
	b = "analysisWindow('"
	b += info
	b += "')"
	a+=  encloseInDoubleQuote(b)
	a+=  '>'
	return a
}


// Aug 2005
// homeButton3 JS
function fn3MouseOver(elem) 
{ // document.getElementById("aswWordInfo").innerHTML = "mouseover button3"
this.getElementsByTagName('span')[0].style.display = 'block';
}

function fn3MouseOut(elem) 
{ // document.getElementById("aswWordInfo").innerHTML = "";
this.getElementsByTagName('span')[0].style.display = 'none';}

function initHomeButton3()
{
document.getElementById('homeButton3').onmouseover = fn3MouseOver;
document.getElementById('homeButton3').onmouseout = fn3MouseOut; 
}


// -------------------------------------------------------------
// copy from basic.js

function aswResizeWindow(s) { 
	switch (s) 
	{case 0: self.resizeTo(300,400);
		 document.body.style.backgroundColor = aswBG
	         break;
	 case 1: self.resizeTo(400,500);
	 	 document.body.style.backgroundColor = aswBG
	         break;
	 case 2: if (screen.height <= 600 | screen.width <= 800) {self.resizeTo(800,600)};	
	 	 e = document.getElementById('titlepane')
		 if (e != null) {} 
	 	 c = document.cookie
	 	 re = /bgColor(\w\w\w\w\w\w)/
	 	 c = c.toString()
	 	 if (re.test(c)) {aswBGnew = c.match(re)[1]}
	 	 else {aswBGnew = aswBG}
	 	 document.body.style.backgroundColor = aswBGnew
	 	 readFaharasaLinkColor()	 	 
                              if (document.getElementById('homeButton3') != null) { initHomeButton3()}
	         break;
	 default: self.resizeTo(300,500);
	}
	// make sure the window is named.
	self.name = 'unit'
}
// -----------------------------------------------------------------

// vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
// code part for gap fields
// var logg = 0;
// function logIt(evt)
// {
// 	logg++;
//	document.forms[1].log.value = logg + ': ' + evt + '\n' + document.forms[1].log.value;
// }


 function aswFieldBlr(tar, solution)
 {
	 
 	if (tar.value == solution)  {tar.parentNode.innerHTML = solution
// 				   logIt('correct')
		}
         else {
		if (tar.value != "") {}
//
// 		logIt('not correct')
 	      }
 }
 
 


function aswFieldBlr2(tar, solution1, solution2)
 {	
 	if (tar.value == solution1 )  {tar.parentNode.innerHTML = solution1
// 				   logIt('correct')
		}
	else if (tar.value == solution2)  {tar.parentNode.innerHTML = solution2
// 				   logIt('correct')
		}
         else {
		if (tar.value != "") {alert(this.feedback)}
//
// 		logIt('not correct')
 	      }
 }


// function clear(obj) {logIt('clear'); obj.value = ""}
// 
// function init() {
//  	logIt('init')
//  	document.forms[0].reset()
// }

function gap(t1,t2) {gapField(t1,t2)}

function gapString(aText) {
	a = '<span><INPUT TYPE=text '
	a += 'size= ' + aText.length
	a +='VALUE="" onBlur="aswFieldBlr(this, '
	a += "'" + aText + "'" 
	a += ')"></span>'
	return a
}


function gapString2(aText, anAlternative) {
	a = '<span><INPUT TYPE=text '
	a += 'size= ' + aText.length
	a +='VALUE="" onBlur="aswFieldBlr2(this, '
	a += "'" + aText + "', '" + anAlternative + "'"
	a += ')"></span>'
	return a
}

function gapField(aText, anAlternative) {
		                if (anAlternative == null) {
					document.write(gapString(aText)) 
					}
				else
				  {
				  document.write(gapString2(aText, anAlternative)) }
			        }

// nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn


function String_left(count) {
  return this.substring(0,count) 
}

String.prototype.left = String_left

