<!--
// Global Variables //
sList= new Array();	sTxt= new Array();
var tCshehe,tshehe,tCherhis,therhis,tCherhim,therhim,tChershis,thershis,tCherselfhimself,therselfhimself,tACSHEHE;
var pCshehe,pshehe,pCherhis,pherhis,pCherhim,pherhim,pChershis,phershis,pCherselfhimself,pherselfhimself;
var pre='<span class="fl">';var post='</span>';
gList= new Array();gList=["","First","Second","Third","Forth","Fifth","Sixth","Seventh","Eighth"];
tList= new Array();tList=["Ms.","Mr.","Mrs.","Miss","Dr."];
var Tf,Pf,gNum,gTxt,tTxt,pTxt;


// **********************************************************************************
//
//                      		GENERAL FUNCTIONS
//						Adrian Jones, WoodsGood: October 2008
// 
// **********************************************************************************
// clears the key input text box
function doClear(txt) {
	getObject("inCode").value=(txt)?txt:"";

}

// decrypts the customization section and loads defaults into the selections and input text fields
function doDecrypt() {
	var password=getObject("inCode").value.toLowerCase();
	output = (new Rc4B64Class()).Decrypt(code,password);
	if (output.indexOf("ENCRYPT FROM HERE")==-1) {				// check to see that decrypted info. is valid
		output='<p class="c b" style="color:red;"><img class="stopImg" src="images/stop.png">&nbsp;ERROR. Your key is invalid. Please enter a valid key.</p>';
		getObject("custBox").innerHTML=output;
	} else {
		getObject("openBox").style.display="none";				// hide the key input text box
		getObject("custBox").innerHTML=output;					// load up the decrypted block of html
		doLoadDefault();
	}
}

// loads cookie information into the various selections and input text fields
function doLoadSaved() {
// grade information
	var cg=Number(getCookie("grade")); 							// load grade
	if(cg==null || cg=="") return;								// return if no cookie
	getObject("idg").selectedIndex=cg;							// set selected grade level

// teacher information	
	var ctn=getCookie("tNam");									// teacher name cookie
	if(ctn==null || ctn=="") return;							// return if no cookie
	getObject("idt").value=ctn;									// load teacher name
	var t=getCookie("tTit");									// get teacher title
	if(t=="Dr.") getObject("Ts").style.display = "inline";		// if Dr. then show sex
	for(x=0;x<tList.length;x++) {								// find teacher title in select list
		if(t == tList[x]) getObject("Tt").selectedIndex=x;		// and set it
	}
	Tf=(getCookie("tSex")=="true")?true:false;					// get and set teacher sex (female=true)
	getObject("Ts").selectedIndex=(Tf)?0:1;						// and set select index (F=0, M=1)

// principal information	
	var cpn=getCookie("pNam");									// principal name cookie
	if(cpn==null || cpn=="") return;							// return if no cookie
	getObject("idp").value=cpn;									// load principal name
	var p=getCookie("pTit");									// principal title cookie
	if(p=="Dr.") getObject("Ps").style.display = "inline";		// if Dr. then show sex selection
	for(x=0;x<tList.length;x++) {								// find principal title in select list
		if(p == tList[x]) getObject("Pt").selectedIndex=x;		// and set it
	}
	Pf=(getCookie("pSex")=="true")?true:false;					// get principal sex (female=true)
	getObject("Ps").selectedIndex=(Pf)?0:1;						// and set select index (F/M)

// student information
	var csn=getCookie("st");									// student names cookie
	if(csn==null || csn=="") return;							// return if no cookie
	getObject("ids").value=csn;									// load student names
}

// Get names from selections and input fields, set cookies and format text wrappers for story
function doUpdate() {
// grade level
	gNum=getObject("idg").value;		// grade number
	setCookie("grade",gNum,30);			// set it
	gTxt=pre+gList[gNum]+post;			// grade text with wrapper

// teacher information
	var tt=getObject("Tt").value;		// teacher title
	var tn=getObject("idt").value;		// teacher name
	tTxt=pre+tt+'&nbsp;'+tn+post;		// title/name composite with wrapper
	setCookie("tNam",tn,30);			// set teacher name
	setCookie("tTit",tt,30);			// set teacher title
	setCookie("tSex",Tf,30);			// set teacher sex

// principal information
	var pt=getObject("Pt").value;	
	var pn=getObject("idp").value;
	pTxt=pre+pt+'&nbsp;'+pn+post;		// title/name composite with wrapper
	setCookie("pNam",pn,30);			// set principal name
	setCookie("pTit",pt,30);			// set principal title
	setCookie("pSex",Pf,30);			// set principal sex

// student information
	alls=getObject("ids").value;
	setCookie("st",alls,30);			// student names
	var nList=alls.split(",");
	var sc=0;
	for(i=1;i<sList.length;i++) {		// for each name entered
		sList[i]=nList[sc];				// add to list of students
		sc++;if(sc>=nList.length) sc=0;	// if more names needed than entered, reuse names from start
	}
	for(x=0;x<sList.length;x++) {		// for each student name...
		sTxt[x]=pre+sList[x]+post;		// ...add wrapper
	}		
}

// create sex flags
function doGen(idP) {
	idTitle=''+idP+'t';									// title of person
	idSex=''+idP+'s';									// sex of person
	var tit=getObject(idTitle).value;					// get title
	var sex=getObject(idSex);							// get sex object
	sex.style.display = (tit=="Dr.")? "inline":"none";	// if title is Dr. then get enable sex selection
//	alert(sex.value)
	if (idP=="T") {										// sex is male if 'Mr.' or 'Dr.' AND Male
		Tf=(tit=="Mr." || (tit=="Dr." && sex.value=="M"))?false:true;
	} else {
		Pf=(tit=="Mr." || (tit=="Dr." && sex.value=="M"))?false:true;
	}
}

// Set appropriate pronouns based on teacher and principal sex
function doSex() {
	tCshehe  =(Tf)?'She':'He';		tshehe  =tCshehe.toLowerCase();	tACSHEHE=tCshehe.toUpperCase();
	tCherhis =(Tf)?'Her':'His';		therhis =tCherhis.toLowerCase();
	tCherhim =(Tf)?'Her':'Him';		therhim =tCherhim.toLowerCase();
	tChershis=(Tf)?'Hers':'His';	thershis=tChershis.toLowerCase();
	tCherselfhimself=(Tf)?'Herself':'Himself';therselfhimself=tCherselfhimself.toLowerCase();
	tACSHEHE =(Tf)?'SHE':'HE';

	
	pCshehe  =(Pf)?'She':'He';		pshehe  =pCshehe.toLowerCase();
	pCherhis =(Pf)?'Her':'His';		pherhis =pCherhis.toLowerCase();
	pCherhim =(Pf)?'Her':'Him';		pherhim =pCherhim.toLowerCase();
	pChershis=(Pf)?'Hers':'His';	phershis=pChershis.toLowerCase();
	pCherselfhimself=(Pf)?'Herself':'Himself';pherselfhimself=pCherselfhimself.toLowerCase();
}

// check to see that text input fields are not empty; alert if so
function doCheck() {
	if(getObject("idg").value=="" || getObject("idg").value==0) {alert('Please select the grade level');return;}
	if(getObject("idt").value=="") {alert('Please enter the name of the classroom teacher');return;}
	if(getObject("idp").value=="") {alert('Please enter the name of the principal');return;}
	if(getObject("ids").value=="") {alert('Please enter names of your children, separated by commas');return;}
}

// main software routine when create story button clicked
function doAll() {
	doCheck();			// check for all information present
	doUpdate();			// set selections for grade level, teacher and principal name, title and sex
	doSex();			// set pronouns based on sex of teacher and principal
	doStory();			// write out story
}
	
// load defaults into selections and input text fields
function doLoadDefault() {
// default student names
	sTmp='Kalli, '+sDefault;			// add to student list the 0th element (unused)
	sList=sTmp.split(",");				// and split into array of separated student names
	getObject("ids").value=sDefault;	// load the default names to the text area

// default grade level
	getObject("idg").selectedIndex=Number(gDefault);		// default grade
	
// teacher defaults
	getObject("idt").value=teacher[dName];					// teacher name
	getObject("Tt").selectedIndex=Number(teacher[dTitle]);	// teacher title
	getObject("Ts").selectedIndex=Number(teacher[dSex]);	// teacher sex
	Tf=(teacher[dSex]=="0")?true:false;						// teacher is female? true/false flag

// principal defaults
	getObject("idp").value=principal[dName];				// principal name
	getObject("Pt").selectedIndex=Number(principal[dTitle]);// principal title
	getObject("Ps").selectedIndex=Number(principal[dSex]);	// principal sex
	Pf=(principal[dSex]=="0")?true:false;					// principal is female? true/false flag
}

-->