/*************************************************************

	Logic for the Poetry Generator
	Javascript DOM version

	Poetry Generator
	Copyright (c) 1985-2004 c.e.
	by Jelks Cabaniss (mailto:jelks@jelks.nu)

	Full use of code granted
	as long as you (dis)credit the author.

**************************************************************/


/*************************************************************
	global variables & constants
**************************************************************/

var isDOM = (document.getElementById) ? true : false;
var isIE = (navigator.appVersion.lastIndexOf("MSIE") >= 0) ? true : false;
var isWin = (navigator.appVersion.lastIndexOf("Win") >= 0) ? true : false;
var isWinIE = ((isIE) && (isWin)) ? true : false;

if (isDOM) {
    var cmdSpew
    var cboTheme
    var cmdWords
    var cmdOptions
    var cmdAbout
    var theWords
    var theOptions
    var thePoem
    var poemTitle
    var poemBody
}

// Constants
var iTHEMES = 8				// number of themes
var iMAXCELLS = 55			// number of "cells" in cell array
var iMAXOPTS = 9			// max # of leadins and expletives
var iPOEMLINES = 9			// max # of lines in poem + title
var sPUNCTUATION = ",;:!?";		// punctuation marks
var sCOLORRAISED = "red";		// selected button text color
var sCOLOROVER = "magenta";		// mouseover button text color
var sCOLORFLAT = "captiontext";		// unselected button text color
var sBG = "url(../../images/uchu.gif)"	// background image or color

// simple variables initialized
var iThemeIndex = 0			// Which theme are we on
var iNumLines = 8			// Number of Lines per poem
var iNumVerses = 2			// Number of verses per Poem
var iUseLeadins = 1			// When[] subscript for "Oh how ...?" (SOMETIMES)
var iYeaOnLast = 1			// When[] subscript for "Yea, ..."  (SOMETIMES)
var iMaxExplete = 2			// Max Expletives per poem
var iExpleteWhere = 1			// Odd, EVEN, or any lines?
var iTransChoice = 1			// none, DISSOLVE, circle, random, cycle
var iTransKey = 0			// IE specific transition key
var oWhichButton		// which button is "on"
var sFocusWords	= "cell0"		// focus on which Words field
var sFocusOptions = "Leadin0"		// focus on which Options field

// simple variables calculated
var sPoem				// One string for whole sPoem
var sYeaLine				// Yea, the ... of the ... ...!
var iLinesPerVerse			// Number of lines in each verse
var iExpleteCtr				// Counter for Expletives
var iVerseCtr				// Number of verses
var iLineInVerse			// used to be a static local variable

// booleans initialized
var bIsRandom = false			// Picked the "Random" theme
var bIncludeTitle = true		// Should we include the title?
var bFirstTime = true			// Just started up?

// booleans calculated
var bExpleteAny				// Expletives allowed on ANY lines
var bExpleteEven			//   "	   "	   "	  EVEN "
var bExpleteOdd				//   "	   "	   "	  ODD  "
var bEvenLine				// Even or Odd line in verse?
var bYeaOK				// But can we use such a line?
var bUseTransition			// Dissolve from one Poem into another?
var bIsWindows				// Win platform?

// String arrays
var sPoemCells = new Array(iTHEMES)	// Array of all "words"
var sPoemExpletives= new Array(iTHEMES) // Array of all Expletives
var sPoemLeadins= new Array(iTHEMES)	// Array of all Lead Ins ("Oh how...")
var cell = new Array(iMAXCELLS)		// Array of "words" instance
var Explete = new Array(iMAXOPTS)	// Array of Expletives instance
var Leadin = new Array(iMAXOPTS)	// Array of Lead Ins instance
var sPoemLines = new Array(iPOEMLINES)	// The array to hold the sPoem lines
var sWhen = new Array("Never", "Sometimes", "When Possible")

// Boolean arrays
var bTaken = new Array(iMAXCELLS)	// for no duplicate words in sPoem
var bLeadinTaken = new Array(iMAXOPTS)	// for no duplicate Lead-ins
var bExpleteTaken= new Array(iMAXOPTS)	// for no duplicate Expletives


/*************************************************************
	main()
**************************************************************/

	startUp();
	doPoem();

/*************************************************************
	beginning of functions
**************************************************************/

function startUp() {
  if (isDOM) {
    cmdSpew = document.getElementById("cmdSpew");
    cboTheme = document.getElementById("cboTheme");
    cmdWords = document.getElementById("cmdWords");
    cmdOptions = document.getElementById("cmdOptions");
    cmdAbout = document.getElementById("cmdAbout");
    theWords = document.getElementById("theWords");
    theOptions = document.getElementById("theOptions");
  }
  oWhichButton = cmdSpew;
	document.body.style.backgroundImage = sBG;
	bUseTransition = isWinIE;
	for(var i = 0; i <= iTHEMES; i++)
		sPoemCells[i] = new Array(55);
	for(i = 0; i <= iTHEMES; i++)
		sPoemExpletives[i] = new Array(9);
	for(i = 0; i <= iTHEMES; i++)
		sPoemLeadins[i] = new Array(9);
	// initialize arrays & load first Theme
	initArrays();  // loads ALL the words
	loadTheme();
	document.body.onkeypress = processKey;
}

function processKey() {
	// do Poem on ENTER or 'S' when "Spew" is selected

  if (isIE) {
  	k = window.event.keyCode;
  	if (oWhichButton == cmdSpew) {
      if ("13 32 115 83".indexOf(k) != -1)	// CR, SPACE, 's', or 'S'
  			cmdSpew_onClick();
    }
  }
}

function loadTheme() {
	var i

	if (bIsRandom)
		iThemeIndex = getNum(0,6);  // random
	for(i = 0; i <= iMAXCELLS; i++)
		cell[i] = sPoemCells[iThemeIndex][i];
	for(i = 0; i <= iMAXOPTS; i++)
		Explete[i] = sPoemExpletives[iThemeIndex][i];
	for(i = 0; i <= iMAXOPTS; i++)
		Leadin[i] = sPoemLeadins[iThemeIndex][i];
}

function saveTheme() {
	var i

	for(i = 0; i <= 55; i++)
		sPoemCells[iThemeIndex][i] = cell[i];
	for(i = 0; i <= 9; i++)
		sPoemExpletives[iThemeIndex][i] = Explete[i];
	for(i = 0; i <= 9; i++)
		sPoemLeadins[iThemeIndex][i] = Leadin[i];
}


function doPoem() {
/*************************************************************
	Builds a whole Poem then displays it.
**************************************************************/

	var s, i
	var LineCtr
	var VerseChange
	var iLineInVerse

	if (bIsRandom)
		loadTheme();
	raiseButton(cmdSpew)
	flattenButtons(cmdWords, cmdOptions, cmdAbout);
	if (!bFirstTime) {
		theWords.style.display = "none";
		theOptions.style.display = "none";
	}
	// So you won't have repeating words:
	for(i = 0; i <= iMAXCELLS; i++)
		bTaken[i] = false;
	for(i = 0; i <= 9; i++) {
		bExpleteTaken[i] = false;
		bLeadinTaken[i] = false;
	}
	// Prepare for upcoming Poem
	iExpleteCtr = 0;
	iLineInVerse = 1;
	iLinesPerVerse = iNumLines / iNumVerses;
	bExpleteOdd = (iExpleteWhere == 0)
	bExpleteEven = (iExpleteWhere == 1)
	bExpleteAny = (iExpleteWhere == 2)
	sPoem = "";
	bYeaOK = false;
	sPoemLines[0] = " ";

	// Now build the Poem as an array of lines
	for (LineCtr = 1;  LineCtr <= iNumLines; LineCtr++)
		sPoemLines[LineCtr] = getLine(LineCtr);
	// Now join the lines into one string with "Verses"
	for (LineCtr = 1;  LineCtr <= iNumLines; LineCtr++) {
		sPoem += sPoemLines[LineCtr] + "<br />";
		if (LineCtr < iNumLines) {
			if (iLineInVerse == iLinesPerVerse) {
				iLineInVerse = 1;
				VerseChange = true;
			}
			else {
				iLineInVerse++;
				VerseChange = false;
			}
		}
		else {
			iLineInVerse = iNumVerses;
			VerseChange = false;
		}
		if (VerseChange)
			sPoem += "<br />";
	}
	s = getTitle(true)
	sPoemLines[0] = properCase(s)

	if (bFirstTime) {
	 	document.write("<div id=\"thePoem\">"
			+ "<table id=\"poemTable\"><tr><td id=\"poemArea\" "
			+ "onclick=\"cmdSpew_onClick()\" style=\"color: maroon; "
			+ "background: url(../../images/textura.gif) white\">"
			+ "<div id=\"poemTitle\">" + sPoemLines[0] + "</div>");
	 	document.write("<div id=\"poemBody\"><p>" + sPoem + "</p></div>"
			+ "</td></tr></table></div>");
		bFirstTime = false;
    if (isDOM) {
      thePoem = document.getElementById("thePoem");
      poemTitle = document.getElementById("poemTitle");
      poemBody = document.getElementById("poemBody");
    }
	}
	else {
		if (bIncludeTitle) {
			poemTitle.innerHTML = "<p>" + sPoemLines[0] + "</p>";
      poemTitle.style.display = "block";
    }
		else
			poemTitle.style.display = "none";
		poemBody.innerHTML = "<p>" + sPoem + "</p>";
	}
	loadTheme();
	bUseTransition = (isWinIE && iTransChoice > 0);
	if (bUseTransition && (thePoem.filters[0].Status == 0)) {
		thePoem.style.visibility = "hidden"
		thePoem.style.display = "block";
		switch(iTransChoice) {
			case 1: iTransKey = 12; break;	// they want dissolve
			case 2: iTransKey = 3; break;	// they want circle
			case 3: iTransKey = 23; break;	// they want random
			case 4: iTransKey++; 		// they want cycle
				if (iTransKey > 22)
					iTransKey = 0;
		}
		thePoem.filters[0].transition = iTransKey
		thePoem.filters[0].Apply()
		thePoem.style.visibility = "visible"
		thePoem.filters[0].Play()
	}
	else
		thePoem.style.display = "block";
/*************************************************************
	end function doPoem()
**************************************************************/
}

function getLine(LineCtr) {
/*************************************************************
	This function actually constructs a Poem line.
	It can also modify the punctuation of the previous line.
**************************************************************/

	var WholeLine
	var RandomInsert
	var Modifier
	var WholeLeadin
	var VerbPhrase
	var VerbSingular
	var FirstPart, LastPart
	var VerbPos, SpacePos
	var LeftChar, RightChar
	var WordOnly
	var IsRightPunct
	var LeadPossible
	var ChosenObject
	var L

	if (bYeaOK) 	// last line in Poem
		return(sYeaLine);

	if (LineCtr == 1)
		iLineInVerse = 1;
	else {
		iLineInVerse++;
		if (iLineInVerse > iLinesPerVerse)
			iLineInVerse = 1;
	}

	bEvenLine = (iLineInVerse % 2 == 0);

	if (iExpleteCtr < iMaxExplete && landedFaceUp()) {	// Expletive!
		if (bExpleteAny || (bExpleteEven && bEvenLine)
			|| (bExpleteOdd && !bEvenLine)) {
				iExpleteCtr++;
				return(getExpletive(true) + "!");
		}
	}

	if (landedFaceUp() && landedFaceUp() && landedFaceUp())
		// exclamation (like Title but with "!")
		return(getTitle(false));

	// OK, got rid of "Yea" lines and expletives, so
	// the following is going to be a "regular" line

	if (landedFaceUp() && landedFaceUp()) {
		// the blankety *OF* the blankety blank
		RandomInsert = "the " + getObject(true) + " of ";
		// means prime candidate for bYeaOK
		if (LineCtr == iNumLines - 1) {
			if (sWhen[iYeaOnLast] == "When possible")
				bYeaOK = true;
			else
			if (sWhen[iYeaOnLast] == "Sometimes" && landedFaceUp())
				bYeaOK = true;
		}
	}
	else	// *NO* blankety of the blankety blank
		RandomInsert = "";

	if (landedFaceUp() && landedFaceUp()) {	// Modifier is possessive
		Modifier = lowerCaseKeywords(getSubject(true));
		if (Modifier.indexOf("totally") == -1) {
			if (Modifier.substr(Modifier.length - 1) == "s")
				// if it already ends in "s", just add apostrophe
				Modifier += "'";
			else  // otherwise add apostrophe "s"
				Modifier += "'s";
			}
		// below is just for Valley Girls
		if (iThemeIndex == 7 && Modifier.indexOf("totally") > 0)
			Modifier = getAdjective(true);
	}
	else // Modifier is "adjective"
		Modifier = getAdjective(true);

	ChosenObject = getObject(true);

	// Save "Yea" for last line, if chosen in "Options" form
	if (bYeaOK)
		sYeaLine = "Yea, " + RandomInsert + Modifier + " "
			+ ChosenObject + "!";

	// OK, now build us our line
	VerbPhrase = getVerb(true);
	WholeLine = getSubject(true) + " " + VerbPhrase + " "
		+ RandomInsert + Modifier + " " + ChosenObject + ".";

	if (sWhen[iUseLeadins] == "Never") // if no Lead-ins, we are done
		return(WholeLine);

	if (sWhen[iUseLeadins] == "Sometimes" && landedFaceUp() && landedFaceUp())
		// "Sometimes" wasn't THIS time!
		return(WholeLine);

	if (sPoemLines[LineCtr - 1].substr(sPoemLines[LineCtr - 1].length - 1) == "!")
		// Previous line was expletive, so get out
		return(WholeLine);

	// So now, iUseLeadins must be "When possible"
	if (iLineInVerse != 1) {
		if (iLinesPerVerse % 2 == 0) 	// even # lines
			LeadPossible = bEvenLine;// if even line, OK
		else
			LeadPossible = true;	// odd # lines in verse
	}
	else	// Can't use lead-in on first line
			LeadPossible = false;

	if (!LeadPossible)  	// get out
		return(WholeLine);

	// We finally get to use Lead-ins like "And", "But", etc.
	WholeLeadin = getLeadin(true);

	// now see if the lead-in has sPUNCTUATION, and if so,
	// punctuate the line (and if necessary, the preceeding line)
	LeftChar = WholeLeadin.substr(0, 1);
	RightChar = WholeLeadin.substr(WholeLeadin.length - 1);
	IsRightPunct = false;
	if (sPUNCTUATION.indexOf(LeftChar) >= 0) {
		// punctuate (overwrite period on) preceeding line
		if (sPoemLines[LineCtr - 1].substr(sPoemLines[LineCtr - 1].length - 1) == ".") {
			L = LineCtr - 1;
			sPoemLines[L] = sPoemLines[L].substr(0, sPoemLines[L].length - 1);
			sPoemLines[L] += LeftChar;
		}
		// strip out the leading sPUNCTUATION of the Lead-in
		WordOnly = WholeLeadin.substr(1);
		if (sPUNCTUATION.indexOf(RightChar) >= 0) {
			// get ready to punctuate this line
			IsRightPunct = true;
			WordOnly = WordOnly.substr(0, WordOnly.length - 1);
		}
		WholeLine = WordOnly + " " + lowerCaseKeywords(WholeLine);
	}
	else
	if (sPUNCTUATION.indexOf(RightChar) >= 0) {
		// get READY to punctuate THIS line
		IsRightPunct = true;
		WordOnly = WholeLeadin.substr(0, WholeLeadin.length - 1);
		WholeLine = WordOnly + " " + lowerCaseKeywords(WholeLine);
	}
	else {	// no sPUNCTUATION
		WholeLine = WholeLeadin + " " + lowerCaseKeywords(WholeLine);
		WordOnly = "";  // just in case it's referenced by helperVerb()
	}

	if (IsRightPunct)
		// NOW punctuate line if Lead-in ends in sPUNCTUATION
		WholeLine = WholeLine.substr(0, WholeLine.length - 1) + RightChar;

	if (helperVerb(WordOnly)) {
		// Can, Will, Shall, Does, etc.
		VerbPos = WholeLine.indexOf(VerbPhrase)
		FirstPart = WholeLine.substr(0, VerbPos)
		// Now strip out the "s" of the VerbPhrase
		// to get a Singular Verb
		SpacePos = VerbPhrase.indexOf(" ")
		if (SpacePos == -1) {
			// no prepositions, so the Verb IS the VerbPhrase
			VerbSingular = VerbPhrase.substr(0, VerbPhrase.length - 1)
			LastPart = WholeLine.substr(VerbPos + VerbPhrase.length, WholeLine.length)
		}
		else { // must have preposition or adverb
			VerbSingular = VerbPhrase.substr(0, SpacePos - 1)
			LastPart = WholeLine.substr(VerbPos + SpacePos, WholeLine.length)
		}
		WholeLine = FirstPart + VerbSingular + LastPart;
	}

	// OK, here's your line -- now with a lead-in!
	return(WholeLine);
/*************************************************************
	end of function getLine()
**************************************************************/
}


/*************************************************************
	Now for the smaller functions ...
**************************************************************/

function raiseNow(x) {	// raise a button temporarily
	x.style.borderColor =
		"buttonhighlight buttonshadow buttonshadow buttonhighlight";
}

function raiseButton(x) {  // keep a button raised
	raiseNow(x);
	x.style.color = sCOLORRAISED;
	oWhichButton = x;
}

function flattenButtons(x, y, z) {
	x.style.borderColor = "buttonface";
	x.style.color = sCOLORFLAT;
	y.style.borderColor = "buttonface";
	y.style.color = sCOLORFLAT;
	z.style.borderColor = "buttonface";
	z.style.color = sCOLORFLAT;
}

function mOver(x) {
	if (oWhichButton != x)
		raiseNow(x);
	x.style.color = sCOLOROVER;
}

function mOut(x) {
	if (oWhichButton == x)
		x.style.color = sCOLORRAISED;
	else {
		x.style.borderColor = "buttonface";
		x.style.color = sCOLORFLAT;
	}
}

function getRandomCellNum(lower, upper, TakeIt) {
	var i

	if (TakeIt) {
		do
			i = getNum(lower, upper)
		while(bTaken[i]);
		bTaken[i] = true;
	}
	else
		i = getNum(lower, upper);
	return(i);
}

function getRandomOptsNum(which, TakeIt) {
	var i

	if (TakeIt) {
		if (which == "explete") {
			do
				i = getNum(0, 9)
			while (bExpleteTaken[i]);
			bExpleteTaken[i] = true;
		}
		else {
			do
				i = getNum(0, 9)
			while (bLeadinTaken[i]);
			bLeadinTaken[i] = true;
		}
	}
	else
		i = getNum(0, 9);
	return(i);
}

function getSubject(TakeIt) {
	var i = getRandomCellNum(0, 13, TakeIt);
	// some hard-coding here for the Valley Girl theme
	if (iThemeIndex == 7 && TakeIt &&
		landedFaceUp() && landedFaceUp() && landedFaceUp()) {
		return(cell[i] + " totally");
	}
	else
		return(cell[i]);
}

function getObject(TakeIt) {
	var i = getRandomCellNum(42, 55, TakeIt);
	return(cell[i]);
}

function getAdjective(TakeIt) {
	var i = getRandomCellNum(28, 41, TakeIt);
	return(cell[i]);
}

function getVerb(TakeIt) {
	var i = getRandomCellNum(14, 27, TakeIt);

	// here's a part that's, like, totally for Valley Girls
	if (iThemeIndex == 7 && cell[i].indexOf("like") == -1 &&
		landedFaceUp() && landedFaceUp() && landedFaceUp()) {
		return(cell[i] + ", like,");
	}
	else
		return(cell[i]);
}

function getLeadin(TakeIt) {
	var i = getRandomOptsNum("leadin", TakeIt)
	return(Leadin[i]);
}

function getExpletive(TakeIt) {
	var i = getRandomOptsNum("explete", TakeIt)
	return(Explete[i]);
}

function fillLeadIn(n) {
	return ( n == iUseLeadins ? " SELECTED>" : ">" )
}

function fillExpletiveWhere(n) {
	return ( n == iExpleteWhere ? " SELECTED>" : ">" )
}

function fillYea(n) {
	return (n == iYeaOnLast ? " SELECTED>" : ">" )
}

function fillMaxExpletives(n) {
	return (n == iMaxExplete ? " SELECTED>" : ">" )
}

function fillTrans(n) {
	return ( n == iTransChoice ? " SELECTED>" : ">" )
}

function fillNumLines(n) {
	var s=" ", sel=" selected";

	switch(n) {
		case 0: if (iNumVerses==2 && iNumLines==8) s = sel; break;
		case 1: if (iNumVerses==2 && iNumLines==6) s = sel; break;
		case 2: if (iNumVerses==2 && iNumLines==4) s = sel; break;
		case 3: if (iNumVerses==1 && iNumLines==4) s = sel; break;
		case 4: if (iNumVerses==1 && iNumLines==3) s = sel; break;
		case 5: if (iNumVerses==1 && iNumLines==2) s = sel; break;
		case 6: if (iNumVerses==1 && iNumLines==1) s = sel; break;
	}
	return (s + ">");
}

function cmdSpew_onClick() {
	if (thePoem.style.display != "block")
		saveTheme();
	doPoem();
}

function cboTheme_onChange() {
	saveTheme();
	iThemeIndex = cboTheme.selectedIndex;
	bIsRandom = (iThemeIndex == iTHEMES);
	loadTheme();
	doPoem();
}

function cmdWords_onClick() {
	thePoem.style.display = "none";
	theOptions.style.display = "none";
	showWords();
}

function cmdOptions_onClick() {
	thePoem.style.display = "none";
	theWords.style.display = "none";
	showOptions();
}

function makeVerseLines(n) {
	switch(n) {
		case 0: iNumVerses = 2; iNumLines = 8; 	break;
		case 1: iNumVerses = 2; iNumLines = 6; 	break;
		case 2: iNumVerses = 2; iNumLines = 4; 	break;
		case 3: iNumVerses = 1; iNumLines = 4; 	break;
		case 4: iNumVerses = 1; iNumLines = 3; 	break;
		case 5: iNumVerses = 1; iNumLines = 2; 	break;
		case 6: iNumVerses = 1; iNumLines = 1; 	break;
	}
}

function landedFaceUp() {
	 return getNum(0, 1);
}

function properCase(s) {
	var s1, s2 = "", i;

	for (i = 0; i < s.length; i++) {
		s1 = s.charAt(i)
		if (i > 0) {
			if (s.charAt(i-1) == " ")
				s1 = s1.toUpperCase();
		} else if (i == 0)
			s1 = s1.toUpperCase();
		s2 += s1;
	}
	return s2;
}

function cmdAbout_onClick() {
	raiseButton(cmdAbout)
	flattenButtons(cmdWords, cmdOptions, cmdSpew);
	var hWnd = window.open("about.html", null, "width=506,height=220,status=no");
}

function getNum(lower, upper) {
	return parseInt((upper - lower + 1) * Math.random() + lower)
}

function helperVerb(WhichWord) {
	var FirstPart

	var NotPos = WhichWord.indexOf(" not");
	(NotPos > 0) ? FirstPart = WhichWord.substr(0, NotPos) : FirstPart = WhichWord;
	switch(FirstPart) {
		case "Can":
		case "Will":
		case "Does":
		case "Should":
		case "May":
		case "Shall":
		case "Could":
		case "Might":
			return (true);
			break;
		default: return (false)
	}
}

function lowerCaseKeywords(s) {
	if (!s.indexOf("My ") || !s.indexOf("Your ") || !s.indexOf("The ") ||
	    !s.indexOf("A ") || !s.indexOf("An ") || !s.indexOf("His ") ||
	    !s.indexOf("Her ") )
			return( (s.substr(0, 1)).toLowerCase() + s.substr(1) );
	else
		return(s);
}

function getTitle(IsTitle) {
	var s1, s2

	if (landedFaceUp()) {
		s1 = getSubject(!IsTitle);
		(s1.substr(s1.length - 1) == "s") ? s1 = s1 + "'" : s1 = s1 + "'s";
	}
	else
		s1 = getAdjective(!IsTitle);
	if (IsTitle)
		return(s1 + " " + getObject(!IsTitle));
	else {
		s2 = (s1.substr(0, 1)).toUpperCase();
		s1 = s2 + s1.substr(1);
		return(s1 + " " + getObject(!IsTitle) + "!");
	}
}

function showOptions() {
	var i, r, c, s, sWords

	raiseButton(cmdOptions);
	flattenButtons(cmdWords, cmdSpew, cmdAbout);
	sWords = "<table style=\"margin:auto\"><tr><th><u>L</u>ead-ins</th><th>E<u>x</u>pletives</th>"
			+ "<th>Info</th><th>Options</th></tr>"
	var nTabIndex = 56;
	for(r = 0; r < 10; r++) {
		sWords += "<tr>";
		for(c = 0; c < 2; c++) {
			s = "<td>&nbsp;<input type=\"textbox\" size=\"17\" maxlength=\"22\" id="
			if (c == 0) {
				s += "\"Leadin" + r + "\" value=\"" + Leadin[r] + "\" onChange=\""
				+ "Leadin[" + r + "]=Leadin" + r + ".value\" ";
				if (r == 0)
					s += "accesskey=\"L\" ";
			}
			else {
				s += "\"Explete" + r + "\" value=\"" + Explete[r] + "\" onChange=\""
				+ "Explete[" + r + "]=Explete" + r + ".value\" ";
				if (r == 0)
					s += "accesskey=\"X\" ";
			}
			s += "tabindex=\"" + nTabIndex +
				"\" onfocus=\"sFocusOptions=this.id\">&nbsp;</td>"
			nTabIndex++;
			sWords += s;
		}
		if (r == 0) {
			sWords += "<td style=\"background:snow\" rowspan=\"10\">"
				+ "<div style=\"margin:1em;text-align:left\">"
				+ "Here is where you set <br />"
				+ "lead-ins, expletives, and<br />"
				+ "options. Lead-ins can<br />"
				+ "punctuate both previous<br />"
				+ "and current lines: a<br />"
				+ "leading comma means<br />"
				+ "the previous line may<br />"
				+ "end with a comma.<br /><br />"
				+ "Don't punctuate<br />"
				+ "Expletives since<br />"
				+ "the generator<br />"
				+ "will do it.<br />"
				+ "</div></td>"
			sWords += "<td rowspan=\"10\" style=\"background:lavenderblush\" "
				+ "align=\"right\" valign=\"top\">"
				+ "<div class=\"opts\"><br />"

			sWords += "<span style=\"color: blue\">"
				 + "<u>I</u>nclude Titles </span><input "
			if (bIncludeTitle)
				sWords += "checked='checked' ";
			sWords += "type=\"checkbox\" id=\"chkTitle\" accesskey=\"I\" onClick="
				+ "\"bIncludeTitle=this.checked\">&nbsp;<br /><br />"

			if (isWinIE) {
        			sWords += "Tra<u>n</u>sition effect "
        				+ "<select id=\"cboYea\" accesskey=\"N\" onChange="
        				+ "\"iTransChoice=this.selectedIndex\">"
        				+ "<option" + fillTrans(0) + "&nbsp;None"
        				+ "<option" + fillTrans(1) + "&nbsp;Dissolve"
        				+ "<option" + fillTrans(2) + "&nbsp;Circle"
        				+ "<option" + fillTrans(3) + "&nbsp;Random"
        				+ "<option" + fillTrans(4) + "&nbsp;Cycle"
        				+ "</select>&nbsp;<br />"
			}

			sWords += "<u>M</u>aximum of <select id=\"cboMaxExplete\" accesskey=\"M\" onChange="
				+ "\"iMaxExplete=this.selectedIndex\">"
				+ "<option" + fillMaxExpletives(0) + "&nbsp;&nbsp;0 expletives"
				+ "<option" + fillMaxExpletives(1) + "&nbsp;&nbsp;1 expletives"
				+ "<option" + fillMaxExpletives(2) + "&nbsp;&nbsp;2 expletives"
				+ "<option" + fillMaxExpletives(3) + "&nbsp;&nbsp;3 expletives"
				+ "<option" + fillMaxExpletives(4) + "&nbsp;&nbsp;4 expletives"
				+ "</select>&nbsp;<br />"

			sWords += "will appea<u>r</u> <select id=\"cboExpleteWhere\" accesskey=\"R\" onChange="
				+ "\"iExpleteWhere=this.selectedIndex\">"
				+ "<option" + fillExpletiveWhere(0) + "on odd lines"
				+ "<option" + fillExpletiveWhere(1) + "on even lines"
				+ "<option" + fillExpletiveWhere(2) + "on any lines"
				+ "</select>&nbsp;<br />"

			sWords += "&nbsp; <u>U</u>se Lead-ins "
				+ "<select id=\"cboUseLeadins\" accesskey=\"U\" onChange="
				+ "\"iUseLeadins=this.selectedIndex\">"
				+ "<option" + fillLeadIn(0) + "&nbsp;Never"
				+ "<option" + fillLeadIn(1) + "&nbsp;Sometimes"
				+ "<option" + fillLeadIn(2) + "&nbsp;When Possible"
				+ "</select>&nbsp;<br />"

			sWords += "\"<u>Y</u>ea\" last line "
				+ "<select id=\"cboYea\" accesskey=\"Y\" onChange="
				+ "\"iYeaOnLast=this.selectedIndex\">"
				+ "<option" + fillYea(0) + "&nbsp;Never"
				+ "<option" + fillYea(1) + "&nbsp;Sometimes"
				+ "<option" + fillYea(2) + "&nbsp;When Possible"
				+ "</select>&nbsp;<br />"

			if (!isWinIE)
				sWords += "<br /><hr size=\"1\"><br />"

            sWords += "<span ID=\"spewSig\">S<u>p</u>ew! </span>"
				+ "<select name=cboVerseLines accesskey=\"P\" onChange="
				+ "\"makeVerseLines(this.selectedIndex)\">"
				+ "<option" + fillNumLines(0) + "&nbsp;8 lines 2 verses"
				+ "<option" + fillNumLines(1) + "&nbsp;6 lines 2 verses"
				+ "<option" + fillNumLines(2) + "&nbsp;4 lines 2 verses"
				+ "<option" + fillNumLines(3) + "&nbsp;4 lines 1 verse"
				+ "<option" + fillNumLines(4) + "&nbsp;3 lines 1 verse"
				+ "<option" + fillNumLines(5) + "&nbsp;2 lines 1 verse"
				+ "<option" + fillNumLines(6) + "&nbsp;1 line 1 verse</select>"
				+ "&nbsp;<br /><br /><hr size=\"1\">"

			sWords += "</div><div class=\"sig1\">"
			sWords += "A Poetry Generator</div>"
				+ "<div class=\"sig2\">"
				+ "&copy; 1998 by "
				+ "<a href=\"mailto:jelks@jelks.nu\">"
				+ "Jelks Cabaniss</a>"
			sWords += "</div></td>"
		}
		sWords += "</tr>"
	}
	theOptions.innerHTML = sWords + "</table>"
	theOptions.style.display = "block"
  if (isDOM && !isIE)
    getOptionIDs();
 	eval(sFocusOptions + ".focus()");
}

function getOptionIDs() {
	var i, r, c, s, sE

	for(r = 0; r < 10; r++) {
		for(c = 0; c < 2; c++) {
			if (c == 0)
        s = "Leadin" + r;
			else
        s = "Explete" + r;
      sE = s + " = document.getElementById('" + s + "');";
      eval(sE);
		}
	}
}


function showWords() {
	var i, r, c, s, sWords

	raiseButton(cmdWords)
	flattenButtons(cmdSpew, cmdOptions, cmdAbout);
	sWords = "<table style=\"margin: auto\"><tr><th>S<u>u</u>bject</th><th>A<u>c</u>tion</th>"
		+" <th>Mo<u>d</u>ifier</th><th>O<u>b</u>jects</th><th>Info</th></tr>"
	i = 0;
	for(r = 0; r < 14; r++) {
		sWords += "<tr>";
		for(c = 0; c < 4; c++) {
			i = r + (c * 14);
			s = i + "\" value=\"" + cell[i] + "\" onChange="
				+ "\"cell[" + i + "]=cell" + i + ".value\" "
				+ "onfocus=\"sFocusWords=this.id\"";
			if (r == 0) {
				switch(c) {
					case 0: s += "accesskey=\"U\""; break;
					case 1: s += "accesskey=\"C\""; break;
					case 2: s += "accesskey=\"D\""; break;
					case 3: s += "accesskey=\"B\""; break;
				}
			}

			sWords += "<td>&nbsp;<input type=\"textbox\" size=\"17\" maxlength=\"22\" "
				+ "id=\"cell" + s + ">&nbsp;</td>"
		}
		if (r == 0) {
			sWords = sWords + "<td rowspan=\"14\" "
        + "style=\"vertical-align:top;background:snow;text-align:left\">"
				+ "<div style=\"margin: 0 1em;\"><br /><br />"
				+ "Here you edit the<br />"
				+ "words that go into<br />"
				+ "poems. When you<br />"
				+ "want to see a new<br />"
				+ "Poem, click <em>Spew!</em><br /><br />"
				+ "If you want to edit &nbsp;&nbsp;&nbsp;<br />"
				+ "expletives and<br />"
				+ "lead-ins, click the<br />"
				+ "<em>Options</em> button<br />"
				+ "above.<br /><br />"
				+ "To see a poem with<br />"
				+ "a new Theme, select<br />"
				+ "your theme from the<br />"
				+ "dropdown on the<br />"
				+ "toolbar above.<br /><br />";
			sWords += "</div></td>"
		}
		sWords += "</tr>"
	}
	theWords.innerHTML = sWords + "</table>"
	theWords.style.display = "block"
  if (!isIE)
    getWordIDs();
  eval(sFocusWords + ".focus()");
}

function getWordIDs() {
	var i, r, c, s, sE

	i = 0;
	for(r = 0; r < 14; r++) {
		for(c = 0; c < 4; c++) {
			i = r + (c * 14);
      s = "cell" + i;
      sE = s + " = document.getElementById('" + s + "');";
      eval(sE);
		}
	}
}


function initArrays() {
	sPoemCells[0] = 		//sweet
["The moon","The sun","A wet cave","The morning","A red rose","My love","The night",
"The desert","A wanderer","Heaven","The wind","Eternity","The ocean","The sunset",
"dances to","fiddles with","holds meetings on","aches for","bathes in",
"blows bubbles in","emanates","quivers in","ponders","lingers in","calls forth",
"shines like","weeps with","dwells on","inquisitive","virtuous","purple","frozen",
"steaming","refridgerated","barren","black","studious","luscious","velvet",
"well-deserved","fermented","reflective","ecstasy","knowledge","agony","water",
"volcanoes","dew drops","laughter","delight","abandonment","oysters",
"bananas","rapture","sorrow","outhouses"]
	sPoemLeadins[0] =
["Will?",",But",",While",",As",",And",
"Shall not?",",Thus","Oh, how!","Ah, but!","Might not?"]
	sPoemExpletives[0] =
["Hark","Alas","Listen","Oh, no","And yea",
"Stop","Help","Dang","Cool","Forget it"]

	sPoemCells[1] =		//weird
["The moon","The sun","A wet cave","The night","A red rose","My love","My sweetheart",
"The desert","A wanderer","Heaven","The wind","Eternity","The ocean","The sunset",
"throbs with","fiddles with","holds meetings on","aches for","bathes in",
"blows bubbles in","emanates","quivers in","embraces","gets addicted to","spews forth",
"shines like","erupts with","tastes like","virgin","voluptuous","purple","frozen",
"steaming","poodle","donkey","black","wanton","luscious","velvet","raw","fermented",
"horrible","ecstasy","lust","agony","doo doo","spit","dew drops","residue",
"delight","abandonment","oysters","bananas","rapture","madness","jello"]
	sPoemLeadins[1] =
["Will not?",",But",",While",",As",",And",
"Shall not?",",Thus","Oh, how!","Ah, but!","Can?"]
	sPoemExpletives[1] =
["Hark","Alas","Listen","Oh, no","And yea",
"Jump back","Shooo wee","Dang","Cool","Forget it"]

	sPoemCells[2] =		//sick
["Your cuticle","My assistant","A student nurse","The head surgeon","Hippocrates",
"The cardiac team","A paramedic","Dr. Kervorkian","An internist","The hospital",
"My left testicle","The insurance company","A stethoscope","The AMA","butchers",
"x-rays","does surgery on","diagnoses","vivisects","prescribes","sends a bill to",
"dismembers","amputates","suctions out","lances","cuts up on","euthanizes","barfs up",
"chronic","acute","prurient","suppurated","slippery","green","corrupt","swollen",
"rampant","luscious","soft","infested","infected","disease-ridden","pustules",
"diarrhea","pyorrhea","gonorrhea","acne vulgaris","arrythmia","smegma","trachiotomies",
"hangnails","boils","herpes simplex","malpractice","excreta","anesthetists"]
	sPoemLeadins[2] =
["Ah, how!",",But",",While",",As",",And",
"Will?","Thus","Should?","Ah, but!","Shall not?"]
	sPoemExpletives[2] =
["Hark","Alas","Listen","Oh, no","Ah, yes",
"Nurse","911","We're losing him","Scalpel","Quick"]

	sPoemCells[3] =		//Clinton
["Congress","Hillary","Bill Clinton","Monica Lewinsky","Social Security",
"Newt Gingrich","The Justice Department","Jesse Helms","Ken Starr","The Religious Right",
"Paula Jones","The NAACP","Rush Limbaugh","Saddam Hussein","wants to impeach",
"debates with","holds meetings on","aches for","bathes in","blows bubbles in",
"has affairs with","quivers in","responds with","serves subpoenas to","spews forth",
"gives speeches on","erupts with","tastes like","unconstitutional","voluptuous",
"purple","racist","Republican","poodle","donkey","black","severe","fundamentalist",
"Democratic","socialist","liberal","conservative","ecstasy","lust","agony",
"antitrust laws","tax cuts","trade embargos","health care","market economies",
"controversies","filibusters","bananas","rapture","affirmative action","jello"]
	sPoemLeadins[3] =
["Knowest thou how?",",But",",While",",As!",",And",
",But it's known that","Thus!","Oh, how!","Ah, but!","Can you believe?"]
	sPoemExpletives[3] =
["Hark","Alas","Listen","Oh, no","Ah, yes",
"My fellow Americans","Ah feel your pain","Dang","Cool","Forget it"]

	sPoemCells[4] =		//Bush
["Congress","George Bush","Colin Powell","Osama bin Laden","Rumsfeld",
"Al Qaeda","John Ashcroft","Dick Cheney","Richard Perle","Fox News",
"Paul Wolfowitz","The U.N.","Tony Blair","Saddam Hussein","commits suicide with",
"debates with","holds meetings on","aches for","bathes in","blows bubbles in",
"gets addicted to","quivers in","explodes into","drops bombs on","spews forth",
"gives speeches on","erupts with","tastes like","Pakistani","Wahabi",
"purple","Afghani","Republican","democratic","compassionate","Palestinian","Muslim",
"fundamentalist","Iraqi","Israeli","liberal","Baathist","ecstasy","lust","agony",
"WMDs","tax cuts","terrorism","health care","falsehoods",
"caves","neocons","bananas","rapture","freedom","outsourcing"]
	sPoemLeadins[4] =
["Knowest thou how?",",But",",While",",As!",",And",
",But it's known that","Thus!","Oh, how!","Ah, but!","Can you believe?"]
	sPoemExpletives[4] =
["Hark","Alas","Listen","Oh, no","Ah, yes",
"My fellow Americans","There he goes again","Dang","Cool","Forget it"]

	sPoemCells[5] =		//sixties
["The draft board","A pop festival","Woodstock","My guru","Eric Clapton","Jimi Hendrix",
"The Grateful Dead","Janis Joplin","John Lennon","A flower","The wind","Haight-Ashbury",
"Bob Dylan","Timothy Leary","throbs with","jams with","gives shotguns with",
"demonstrates about","skinnydips in","blows bubbles in","gets stoned with","quivers in",
"plays lead with","gets addicted to","sings about","tokes hard on","overdoses on",
"drops acid with","laid back","radical","purple","psychedelic","beautiful","free",
"wasted","multi-colored","velvet","luscious","soft","paisley","strung out","sparkling",
"quaaludes","waterbeds","agony","lava lamps","love-ins","blacklights","revolutions",
"bellbottoms","patterns","drug busts","bummers","flashbacks","madness","windowpane"]
	sPoemLeadins[5] =
["Can you dig how?",",But",",While","Will not?",",And",
"Shall not?","Will?","Oh, how!","Man, but!","Can you believe?"]
	sPoemExpletives[5] =
["Far out","In-a-gadda-da-vida","Listen","Oh, God","Ah, yes",
"What a trip","Man","Peace","Cool","Dig it, brother"]

	sPoemCells[6] =		//jim
["The moon","The sun","The blue bus","The morning","My cock","My love","The night",
"The desert","The stranger","Gloria","The music","Love Street","The ocean","Her thigh",
"dances to","fiddles with","lingers long on","aches for","bathes in","gets drunk in",
"emanates","quivers in","lives in","breaks on through","lights fires in","shines like",
"weeps with","dwells in","endless","glorious","purple","green","horrible","mysterious",
"dark","black","red","Indian","velvet","terrible","horse","Spanish","pleasures",
"knowledge","agony","fire","death","humor","laughter","delight","summers","latitudes",
"holes and caves","sadness","caravans","blood"]
	sPoemLeadins[6] =
["Will?","Old friend,!",",While",",As",",And",
"Shall not?",",Thus","How!","Ah, but!","Might not?"]
	sPoemExpletives[6] =
["Yeah, man","Let it roll","Listen","Touch me","Shut up",
"Wake up","Angels and sailors","C'mon baby","Yeahhhh","Dig it, man"]

	sPoemCells[7] = 	//valley
["My curling iron","My Porsche","Daddy's money","The galleria","The prom","My letter sweater",
"My homework","My training bra","My boyfriend","My curfew","Mommy","My earring","My retainer",
"My period","throbs with","french kisses","goes steady with","aches for","cheerleads for",
"blows bubbles in","glows like","quivers like","does heavy petting with","skips school with",
"spews forth","gets grounded for","erupts with","tastes like","total","voluptuous",
"purple","radical","beautiful","really boring","expensive","black","some pretty gnarly",
"groovy","soft","fresh","sweet","sparkling","ecstasy","makeup","agony","nail polish",
"chewing gum","perfume","double-dating","pleasure","desire","Clearsil",
"tampons","fingernails","deodorant","boobs"]
	sPoemLeadins[7] =
["Ah, how",",But",",While","Dig this --",",And",
"So","Man, how!","Oh, how!","Ah, but","Can you believe?"]
	sPoemExpletives[7] =
["Totally Rad","How tubular","Listen","Bitchin'","Awesome",
"Whoa, dude","Way cool","Gnarly","Cool","Gag me with a spoon"]
}
