function IIf(lTest, trueValue, falseValue) {
	if (lTest) {
		return trueValue
	} else {
		return falseValue
	}
}

function SelectValue(oSelect) {
	return oSelect.options[oSelect.selectedIndex].value
}

function BoyGirl(oSelect) {
	return (oSelect.options[oSelect.selectedIndex].value == "M") ? "boy" : "girl"
}

function HeShe(oSelect) {
	return (oSelect.options[oSelect.selectedIndex].value == "M") ? "he" : "she"
}

function HimHer(oSelect) {
	return (oSelect.options[oSelect.selectedIndex].value == "M") ? "him" : "her"
}

function HisHer(oSelect) {
	return (oSelect.options[oSelect.selectedIndex].value == "M") ? "his" : "her"
}

function ManLady(oSelect) {
	return (oSelect.options[oSelect.selectedIndex].value == "M") ? "man" : "lady"
}

function MotherFather(oSelect) {
	return (oSelect.options[oSelect.selectedIndex].value == "M") ? "father" : "mother"
}

function DadMum(oSelect) {
	return (oSelect.options[oSelect.selectedIndex].value == "M") ? "dad" : "mum"
}

function BrotherSister(oSelect) {
	return (oSelect.options[oSelect.selectedIndex].value == "M") ? "brother" : "sister"
}

function InitVowel(string) {
	return ("AEIOUH".indexOf(string.substr(0, 1).toUpperCase()) > -1)
}

function CapIt(string) {
   return string.charAt(0).toUpperCase() + string.substring(1, string.length)
}

function AllTrim(string) {
   return string
}

function ParseList(string, delimiter) {
   var array = string.split(delimiter)
   var returnVal = AllTrim(array[0])
   for (i = 1; i < array.length - 1; i++) {
      returnVal += ", "
      returnVal += AllTrim(array[i])
   }
   return returnVal + " and " + AllTrim(array[array.length - 1])
}

function MakeArray(n) {
   this.length = n
   return this
}

monthNames = new MakeArray(12)
monthNames[1] = "January"
monthNames[2] = "February"
monthNames[3] = "March"
monthNames[4] = "April"
monthNames[5] = "May"
monthNames[6] = "June"
monthNames[7] = "July"
monthNames[8] = "August"
monthNames[9] = "September"
monthNames[10] = "October"
monthNames[11] = "November"
monthNames[12] = "December"

dayNames = new MakeArray(7)
dayNames[1] = "Sunday"
dayNames[2] = "Monday"
dayNames[3] = "Tuesday"
dayNames[4] = "Wednesday"
dayNames[5] = "Thursday"
dayNames[6] = "Friday"
dayNames[7] = "Saturday"

function customDateString(oDate) {
   var theDay = dayNames[oDate.getDay() + 1]
   var theMonth = monthNames[oDate.getMonth() + 1]
   var theYear = oDate.getYear() + 1900
   return theDay + ", " + theMonth + " " + oDate.getDate() + ", " + theYear
}

function Single(string) {
	return (string == "1" || string.toUpperCase() == "ONE") ? true : false
}

function Plural(string) {
   if (string.toUpperCase() == "MOOSE" || string.toUpperCase() == "FISH" || string.toUpperCase() == "DEER" || string.toUpperCase() == "YOU" || string.toUpperCase() == "SHEEP") {
      return string
   }
   if (string.toUpperCase() == "GOOSE") {
      return "geese"
   }
   if (string.toUpperCase() == "MOUSE") {
      return "mice"
   }
   if (string.toUpperCase() == "KNIFE") {
      return "knives"
   }
   if (string.toUpperCase() == "WIFE") {
      return "wives"
   }
   if (string.toUpperCase() == "LIFE") {
      return "lives"
   }

   var cBase = string.substring(0, string.length - 1)
   var cSecLast = string.charAt(string.length - 2)
   var cLast = string.charAt(string.length - 1)
   if (cLast == "s" || cLast == "x") {
      return string + "es"
   }
   if (cLast == "y" && "AEIOUaeiou".indexOf(cSecLast) < 0) {
      return cBase + "ies"
   }
   return string + "s"
}

function OrdinalFor(value) {
   var hundredRemainder = value % 100;
   var tenRemainder = value % 10;
   if (hundredRemainder - tenRemainder == 10) {
      return "th";
   }
 
   switch (tenRemainder) {
      case 1:
         return "st";
      case 2:
         return "nd";
      case 3:
         return "rd";
      default:
         return "th";
   }
}

function BuildStory(form) {
	var oWindow = window.open("","StoryBuilder")
	if (oWindow != null) {
		var cContent = "<HTML><HEAD><TITLE>"+document.title+"</TITLE></HEAD>"
		cContent += '<BODY BGCOLOR="#FFFFFF"><CENTER>'
		cContent += '<p><script language="JavaScript" type="text/javascript" src="/Ads/Flex.js"></script></p>'
		cContent += '<P><FONT SIZE="6">'
		cContent += "<B>"+document.title+"</B></FONT></P></CENTER>"
		cContent += '<P><FONT SIZE="4">'

		cContent += cStory(form)

		cContent += '</P><CENTER><P>~The End~</FONT></P>'
		cContent += '<P><FONT SIZE="2"><I>www.SquiglysPlayhouse.com</I></FONT></P></CENTER>'
		cContent += '</BODY></HTML>'
		oWindow.document.write(cContent)
		oWindow.document.close()
		oWindow.focus()
	} else {
		alert("Could not create story window.")
	}
}
