//slideshow functions
/* usage:
 in the body, where you want the slideshow:
	<script>
	show1=new slideshow("show1");
	show1.numSlides=5;
	show1.baseSlideImgName="communications2.08_";
	show1.slideImageExtension="gif";
	show1.slideWidth=499;		
	show1.slideHeight=376;
	//for actions (where 1 is the slide #):
	show1.captions[1]="Good tips here!";
	initSlideShow(show1);
	.
	.
	.
	</script>
*/
function slideshow(name){
	this.nameOfShow=name;
	this.numSlides;
	this.captionHeight=30;//not used
	this.captions=new Array();
	this.currentSlide=1;
	this.baseSlideImgName;
	this.slideImageExtension;
	this.slideWidth;		
	this.slideHeight;
	this.slideBorder;
	this.useDropShadow=false;
	this.baseSlideURL="http://courses.mindedge.com/static/"
	this.prevArrowHTML="<img src='http://courses.mindedge.com/static/slideShowLeftArrow.gif' border=0 alt='previous slide'>"//default left arrow
	this.nextArrowHTML="<img src='http://courses.mindedge.com/static/slideShowRightArrow.gif' border=0 alt='next slide'>"//default right arrow
	this.message="Click on the arrows to navigate through the presentation";//default message
	this.slideShowTimerID=0;
	this.speed=9000;
	
	this.nextSlide=function(){
		if(this.currentSlide==this.numSlides){
			//this.pauseSlideShow();
			return;
		}else{
			this.currentSlide++;
			nextImgSrc=this.baseSlideURL+this.baseSlideImgName+this.currentSlide+"."+this.slideImageExtension;
			findDOM(this.nameOfShow+"_imgDiv",1).background="no-repeat top url("+nextImgSrc+")";
			findDOM(this.nameOfShow+"_counterSpan",0).innerHTML=this.currentSlide;
			if(this.captions.length){
				theCaption=(this.captions[this.currentSlide])?this.captions[this.currentSlide]:"&nbsp;";
				findDOM(this.nameOfShow+"_captionsDiv",0).innerHTML=theCaption;
			}
			if(this.currentSlide==this.numSlides){//just in case
				this.pauseSlideShow();
			}
		}	
	}
	
	this.prevSlide=function(){
		if(this.currentSlide==1){
			return;
		}else{
			this.currentSlide--;
			prevImgSrc=this.baseSlideURL+this.baseSlideImgName+this.currentSlide+"."+this.slideImageExtension;
			findDOM(this.nameOfShow+"_imgDiv",1).background="no-repeat top url("+prevImgSrc+")";
			findDOM(this.nameOfShow+"_counterSpan",0).innerHTML=this.currentSlide;
			if(this.captions.length){
				theCaption=(this.captions[this.currentSlide])?this.captions[this.currentSlide]:"&nbsp;";
				findDOM(this.nameOfShow+"_captionsDiv",0).innerHTML=theCaption;
				//findDOM(this.nameOfShow+"_captionsDiv",1).visibility=(theCaption!="&nbsp;")?"visible":'hidden';
			}
		}
	}
	
	this.goToFirstSlide=function(){
		this.currentSlide=2;
		this.prevSlide();
	}
	
	this.goToLastSlide=function(){
		this.currentSlide=this.numSlides-1;
		this.nextSlide();
		this.pauseSlideShow();
	}
	
	this.playSlideShow=function(){
		if(this.currentSlide==this.numSlides){
			this.currentSlide=0;//will be set to 1 in nextSlide()
		}
		this.nextSlide();
		findDOM(this.nameOfShow+"_slideShowPlayBtnSpan",1).display="none";
		findDOM(this.nameOfShow+"_slideShowPauseBtnSpan",1).display="inline";
		this.slideShowTimerID=setTimeout(this.nameOfShow+".playSlideShow()",this.speed);
	}
	
	this.pauseSlideShow=function(){
		if(this.slideShowTimerID){
			clearTimeout(this.slideShowTimerID);
			this.slideShowTimerID=0;
		}
		findDOM(this.nameOfShow+"_slideShowPlayBtnSpan",1).display="inline";
		findDOM(this.nameOfShow+"_slideShowPauseBtnSpan",1).display="none";
	}
	
}

function initSlideShow(whichShow){
	/**/
	//document.write("<center><font face='verdana' size=1>"+whichShow.message+"</font><p><a href=\"javascript:"+whichShow.nameOfShow+".prevSlide()\">"+whichShow.prevArrowHTML+"</a>&nbsp;");
	//document.write("<center><span style='border:1px solid black;padding:3px;background-color:white;width:70px; text-align:center'><span id='"+whichShow.nameOfShow+"_counterSpan'>1</span> of "+whichShow.numSlides+"</span>");
	//document.write("&nbsp;<a href='javascript:"+whichShow.nameOfShow+".nextSlide()'>"+whichShow.nextArrowHTML+"</a>");
	//document.write("<BR>&nbsp;<br>");
	//new code for later
	//document.write("<center><font face='verdana' size=1>"+whichShow.message+"</font>");
	document.write("<center>");
	if(whichShow.useDropShadow){
		document.write("<div id='shadolllwBox1' style='margin-top:2px;position:relative;width:"+(whichShow.slideWidth+6)+"px;height:"+(whichShow.slideHeight+6)+"px;'>");
		document.write("<div id='shadowBox2' style='width:"+(whichShow.slideWidth+1)+"px;height:"+(whichShow.slideHeight+2)+"px;'>");
		document.write("<div id='shadowBox3' style='width:"+(whichShow.slideWidth-4)+"px;height:"+(whichShow.slideHeight-4)+"px;'>");
		document.write("<div id='shadowBox4'>");
		document.write("<div id='"+whichShow.nameOfShow+"_imgDiv' style='border:"+whichShow.slideBorder+";width:"+whichShow.slideWidth+"px;height:"+whichShow.slideHeight+"px; background:no-repeat top url("+whichShow.baseSlideURL+whichShow.baseSlideImgName+whichShow.currentSlide+"."+whichShow.slideImageExtension+")'>&nbsp;</div>");
		document.write("</div>");
		document.write("</div>");
		document.write("</div>");
		document.write("</div>");
	}else{
		document.write("<div id='"+whichShow.nameOfShow+"_imgDiv' style='border:"+whichShow.slideBorder+";margin-top:5px;width:"+whichShow.slideWidth+"px;height:"+whichShow.slideHeight+"px; background:no-repeat top url("+whichShow.baseSlideURL+whichShow.baseSlideImgName+whichShow.currentSlide+"."+whichShow.slideImageExtension+")'>&nbsp;</div>");
	}
	if(whichShow.captions.length){
		document.write("<div id='"+whichShow.nameOfShow+"_captionsDiv' style='visibility:visible;border:1px solid black;margin-top:2px;width:"+(whichShow.slideWidth-30)+"px; padding:4px;text-align:center;' class='h1maincolor'>&nbsp;</div>");
		theCaption=(whichShow.captions[whichShow.currentSlide])?whichShow.captions[whichShow.currentSlide]:"&nbsp;";
		findDOM(whichShow.nameOfShow+"_captionsDiv",0).innerHTML=theCaption;
		//if(theCaption=="&nbsp;"){findDOM(whichShow.nameOfShow+"_captionsDiv",1).visibility='hidden';}

	}
	//new nav code
	document.write("<div style='margin-top:4px;padding-top:10px;text-align:center;width:366px;height:63px;background:top no-repeat url(http://courses.mindedge.com/images/slideshowNav/solidbg5.gif);'>");
	document.write("<div style='float:left;padding-left:45px;'><a href='javascript:"+whichShow.nameOfShow+".goToFirstSlide()'><img src='http://courses.mindedge.com/images/slideshowNav/rew6b.jpg' border=0 alt='first slide' style='margin-right:3px;'></a>");
	document.write("<a href='javascript:"+whichShow.nameOfShow+".prevSlide()'><img src='http://courses.mindedge.com/images/slideshowNav/back6b.jpg' border=0 alt='previous slide' style='margin-right:5px;'></a>");
	document.write("<span id='"+whichShow.nameOfShow+"_slideShowPlayBtnSpan' style='display:'><a href='javascript:"+whichShow.nameOfShow+".playSlideShow()'><img src='http://courses.mindedge.com/images/slideshowNav/play6b.jpg' border=0 alt='play' ></a></span>");
	document.write("<span id='"+whichShow.nameOfShow+"_slideShowPauseBtnSpan' style='display:none'><a href='javascript:"+whichShow.nameOfShow+".pauseSlideShow()'><img src='http://courses.mindedge.com/images/slideshowNav/pause6b.jpg' border=0 alt='pause' ></a></span>");
	document.write("<a href='javascript:"+whichShow.nameOfShow+".nextSlide()'><img src='http://courses.mindedge.com/images/slideshowNav/fwd6b.jpg' border=0 alt='next slide' style='margin-left:5px;'></a>");
	document.write("<a href='javascript:"+whichShow.nameOfShow+".goToLastSlide()'><img src='http://courses.mindedge.com/images/slideshowNav/ffwd6b.jpg' border=0 alt='last slide' style='margin-left:3px;'></a>");
	if(navigator.appName.indexOf("Internet Explorer")>-1){
		document.write("</div><div style='float:left;padding-left:10px;padding-top:9px;'><span style='margin-left:25px;margin-bottom:12px;border:1px solid black;padding:2px;background-color:white;width:70px; text-align:center'><span id='"+whichShow.nameOfShow+"_counterSpan'>1</span> of "+whichShow.numSlides+"</span>");
	}else{
		document.write("</div><div style='float:left;padding-left:15px;padding-top:12px;'><span style='margin-left:25px;margin-bottom:12px;border:1px solid black;padding:2px;background-color:white;width:80px; text-align:center'><span id='"+whichShow.nameOfShow+"_counterSpan'>1</span> of "+whichShow.numSlides+"</span>");
	}
	document.write("</div></div>");
	document.write("</center><br>");
	
	//now preload the images
	//use an array for tmp, so each image will load fully (will have time to load w/o getting a new value for src)
	tmp=new Array();
	for(g=0;g<whichShow.numSlides;g++){
		tmp[g]=new Image();
		tmp[g].src=whichShow.baseSlideURL+whichShow.baseSlideImgName+(g+1)+"."+whichShow.slideImageExtension
		
	}
}
//end slideshow functions//

//start flashcard functions
/*
tester=new flashcardShow("tester");
tester.cardWidth=300;		
tester.cardHeight=400;
tester.cardBorder="1px solid black";
tester.useDropShadow=false;
tester.backgoundColor="#ffe4b5";
tester.textcolor="#808000";
tester.selectedWordListFileName='/static/HighFrequency_short.xml';
initFlashcardShow(tester);
*/
function initFlashcardShow(whichShow){
	document.write("<center>");
	if(whichShow.useDropShadow){
		document.write("<div id='shadolllwBox1' style='margin-top:2px;position:relative;width:"+(whichShow.cardWidth+6)+"px;height:"+(whichShow.cardHeight+6)+"px;'>");
		document.write("<div id='shadowBox2' style='width:"+(whichShow.cardWidth+1)+"px;height:"+(whichShow.cardHeight+2)+"px;'>");
		document.write("<div id='shadowBox3' style='width:"+(whichShow.cardWidth-4)+"px;height:"+(whichShow.cardHeight-4)+"px;'>");
		document.write("<div id='shadowBox4'>");
	}
	
	document.write('<div id="'+whichShow.nameOfShow+'_flashCard" style=" #position: relative; overflow: hidden;display: table;background-color:'+whichShow.backgoundColor+';border:'+whichShow.cardBorder+';width:'+whichShow.cardWidth+'px;height:'+whichShow.cardHeight+'px;">');
	document.write('<div style=" #position: absolute; #top: 50%;display: table-cell; vertical-align: middle;text-align:left;#left:0%;width:100%">');
	document.write('<div id="'+whichShow.nameOfShow+'_wordDisplay" class="flashCardWordDiv" style=" #position: relative; #top: -50%;color:'+whichShow.textcolor+';text-align:center;font-size:14pt;padding-bottom:10px;"><a href="javascript:'+whichShow.nameOfShow+'.getWordListClick(\''+whichShow.selectedWordListFileName+'\')">Load Flashcards</a></div>');
	document.write('<div id="'+whichShow.nameOfShow+'_meaningDisplay" class="flashCardMeaningDiv" style=" #position: relative; #top: -50%;text-align:center;;font-size:14pt;border-top:3px dotted '+whichShow.dottedlinecolor+';color:'+whichShow.textcolor+';padding-top:10px;padding-bottom:3px;">&nbsp;</div>');
	
	document.write('</div>');
	document.write('</div>');
		
	if(whichShow.useDropShadow){
		document.write("</div>");
		document.write("</div>");
		document.write("</div>");
		document.write("</div>");
	}
	
	//new nav code
	document.write("<div style='margin-top:4px;padding-top:10px;text-align:center;width:366px;height:63px;background:top no-repeat url(http://courses.mindedge.com/images/slideshowNav/solidbg5.gif);'>");
	document.write("<div style='float:left;padding-left:45px;'>");
	document.write("<a href='javascript:"+whichShow.nameOfShow+".rewindClick()'><img src='http://courses.mindedge.com/images/slideshowNav/rew6b.jpg' border=0 alt='first flashcard' style='margin-right:3px;'></a>");
	document.write("<a href='javascript:"+whichShow.nameOfShow+".previousClick()'><img src='http://courses.mindedge.com/images/slideshowNav/back6b.jpg' border=0 alt='previous flashcard' style='margin-right:5px;'></a>");
	document.write("<span id='"+whichShow.nameOfShow+"_slideShowPlayBtnSpan' style='display:'><a href='javascript:"+whichShow.nameOfShow+".showMeaningClick()'><img src='http://courses.mindedge.com/images/slideshowNav/flip_t.jpg' border=0 alt='show meaning' ></a></span>");
	//document.write("<span id='"+whichShow.nameOfShow+"_slideShowPauseBtnSpan' style='display:none'><a href='javascript:"+whichShow.nameOfShow+".pauseSlideShow()'><img src='http://courses.mindedge.com/images/slideshowNav/pause6b.jpg' border=0 alt='pause' ></a></span>");
	document.write("<a href='javascript:"+whichShow.nameOfShow+".nextClick()'><img src='http://courses.mindedge.com/images/slideshowNav/fwd6b.jpg' border=0 alt='next flashcard' style='margin-left:5px;'></a>");
	document.write("<a href='javascript:"+whichShow.nameOfShow+".ffwdClick()'><img src='http://courses.mindedge.com/images/slideshowNav/ffwd6b.jpg' border=0 alt='last flashcard' style='margin-left:3px;'></a>");
	if(navigator.appName.indexOf("Internet Explorer")>-1){
		document.write("</div><div style='float:left;padding-left:10px;padding-top:9px;'><span style='margin-left:25px;margin-bottom:12px;border:1px solid black;padding:2px;background-color:white;width:70px; text-align:center'><span id='"+whichShow.nameOfShow+"_progressDisplay'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span>");
	}else{
		document.write("</div><div style='float:left;padding-left:15px;padding-top:12px;'><span style='margin-left:25px;margin-bottom:12px;border:1px solid black;padding:2px;background-color:white;width:80px; text-align:center'><span id='"+whichShow.nameOfShow+"_progressDisplay'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span>");
	}
	document.write("</div></div>");
	document.write("<a href='javascript:"+whichShow.nameOfShow+".printShow()'>printable version</a>");
	document.write("</center><br>");
	//whichShow.getWordListClick(whichShow.selectedWordListFileName)
	//whichShow.position = 0;
	//whichShow.rewindClick();

}//end init


function flashcardShow(name){
	// generic variable pertaining to AJAX request
	this.xmlHttp
	this.nameOfShow=name;
	this.responseText;
	this.selectedWordListFileName;
	
	this.keys = new Array();
	this.values = new Array();
	this.notes = new Array();
	this.wordListName = "bubba";
	this.n = 0;
	this.position = -1;
	
	this.cardWidth=200;		
	this.cardHeight=200;
	this.cardBorder=1;
	this.useDropShadow=false;
	this.backgoundColor="#ffffff";
	this.dottedlinecolor="#cccccc";
	this.retryCount=0;
	this.tryCount=0;
	this.meaningShown=false;
	
	this.testClick=function() {
		alert("something is working!")
		this.readXMLFile(this.selectedWordListFileName, this.wordListStateChangedHandler);
		alert(this.n+" words")
	}
	
	this.previousClick=function() {
		this.previousWord();
		this.meaningShown=false;
		this.updateWordDisplay(false);	
	}
	
	this.rewindClick=function() {
		this.position=0;
		this.meaningShown=false;
		this.updateWordDisplay(false);	
	}
	
	this.showMeaningClick=function() {
		this.meaningShown=(this.meaningShown)?false:true;
		this.updateWordDisplay(this.meaningShown);
	}
	
	this.nextClick=function() {
		this.nextWord();
		this.meaningShown=false;
		this.updateWordDisplay(false);
	}
	
	this.ffwdClick=function() {
		this.position=this.n-1;
		this.meaningShown=false;
		this.updateWordDisplay(false);
	}
	
	this.getWordListClick=function(wordListFileName){
		this.selectedWordListFileName = wordListFileName;
		this.readXMLFile(wordListFileName, this.wordListStateChangedHandler)
	}
	
	this.getPackDetailsClick=function(packFileName) {
		this.readXMLFile("pack1.xml", this.packStateChangedHandler)
	}
	
	// ------------------------------------------------------------------------
	this.readXMLFile=function(fileName, stateChangeHandler) {
	    // alert("Entering read");
	    tmpHTTP=this.GetXmlHttpObject()
		//alert("1 "+this.nameOfShow)
	    //alert("1 "+xmlHttp)
	    if (tmpHTTP==null){
	        alert ("Your browser does not support AJAX!");
	        return;
	    }
	    //alert("ready to send request for "+fileName);
		tmpHTTP.open("GET", fileName);
	    //alert("2 "+xmlHttp)
	    tmpHTTP.setRequestHeader("Pragma", "no-cache"); 
		//alert("3 "+xmlHttp)
	    tmpHTTP.setRequestHeader("Expires", "Mon, 26 Jul 1997 05:00:00 GMT"); 
		tmpHTTP.setRequestHeader("Cache-Control", "no-store, must-revalidate,must-revalidate, max-age=-1"); 
	    //alert("4 "+xmlHttp)
	    //this.xmlHttp.onreadystatechange=stateChangeHandler;
	    //this.xmlHttp.send(null); 
		//alert("2 "+this.nameOfShow)
	    if(window.XMLHttpRequest){//non-IE
			tmpHTTP.send(null);
		}	
		else if(window.ActiveXObject){//IE
			tmpHTTP.send();
		}
		//alert("3 "+this.nameOfShow)
		tmp=this;
	    //alert("5 "+xmlHttp)
	    tmpHTTP.onreadystatechange=function() {
			//alert("this.xmlHttp.onreadystatechange "+tmpHTTP)
			if(tmpHTTP.readyState==4){
				tmp.xmlHttp=tmpHTTP; 
				//alert("4 "+tmp.nameOfShow)
			    //alert("request sent\n\n"+tmpHTTP.responseText);
				stateChangeHandler(tmpHTTP);			
			}
		}
	   
	    
	    // update("packTitle", "Working..");
	}
	// -------------------- Async Call Handlers -------------------------------
	this.packStateChangedHandler=function(tmpHTTP) {
	    if (tmpHTTP.readyState==4){
			this.tryCount=0;
	        this.responseText=tmpHTTP.responseText;
	        responseXML=tmpHTTP.responseText;
	        //alert("responseText is\n"+tmpHTTP.responseText)
	        packXML = responseXML.getElementsByTagName("Pack")[0];
	        //alert("packXML is\n"+packXML);
	        // Update the pack name
	        this.update(this.name+"_packTitle", packXML.attributes.getNamedItem("name").value);
	        
	        // Updating the worldlist list
	        this.strOut = "";
	        for(i=0; i<packXML.childNodes.length; i++) {
	        	this.childNode = packXML.childNodes[i];
	        	if(this.childNode.nodeType==1) {
	        		this.listName = this.childNode.attributes.getNamedItem("name").value;
	        		this.strOut += "<a href=\"#\" onClick=\"getWordListClick('pack1.xml', '" + this.listName + "'); return false;\">"
	        		this.strOut += this.childNode.attributes.getNamedItem("name").value + "</a><br>"
	        	}
	        }
	        
	        this.update(this.name+"_wordlistList", strOut);
	    }
	}
	
	this.wordListStateChangedHandler=function(tmpHTTP){
	    if(tmpHTTP.readyState==4){
			//alert("in wordListStateChangedHandler\n\n"+tmpHTTP.responseText)
			//alert(tmp)
	 		tmp.processWordList(tmpHTTP);
	 		if(tmp.keys[0]=="undefined"||!tmp.keys[0]||tmp.keys[0]==""){
				alert("retrying\n"+this.nameOfShow+"\n"+tmp.nameOfShow)
				setTimeout(tmp.nameOfShow+".processWordList("+tmpHTTP+")",5000);
			}
			if(!tmp.n){
				//alert("retrying\n"+this.nameOfShow+"\n"+tmp.nameOfShow);
				setTimeout(tmp.nameOfShow+".getWordListClick("+tmp.selectedWordListFileName+")",5000);
				//this.getWordListClick(this.selectedWordListFileName)
			}
	 		tmp.shuffleList_mike();
			tmp.updateWordDisplay(false);  	
	    } 
	}
	// ---------------------------------------------------------------------------
	
	// -------------- Utility Functions ------------------------------------------
	
	this.processWordList=function(tmpHTTP){
		//alert("in processWordList\n\n"+tmpHTTP.responseXML)
		listNode = tmpHTTP.responseXML.getElementsByTagName("WordList")[0];
		this.n = 0
		this.wordListName = listNode.attributes.getNamedItem("name").value;
		this.keys = new Array();
		this.values = new Array();
		this.notes = new Array();
		for(j=0; j<listNode.childNodes.length; j++) {
			wordNode = listNode.childNodes[j];
			if(wordNode.attributes){
				//alert("wordNode.nodeType="+wordNode.nodeType+"\n\n"+wordNode.attributes.getNamedItem("key").value+"\n\n"+this.n);
			}
			if(wordNode.nodeType==1){
				this.keys[this.n] = wordNode.attributes.getNamedItem("key").value;
				this.values[this.n] = wordNode.attributes.getNamedItem("value").value;
				this.notes[this.n] = "";
				this.n++;
				/*
				if(this.keys[this.n]=="undefined"||!this.keys[this.n]||this.keys[this.n]==""){
					//alert("retrying 3\n")
					this.n--;
					setTimeout(this.nameOfShow+".processWordList(tmpHTTP)",50000);
				}
				*/
			}
		}
		this.position = 0;
		//alert(this.n)
		if(this.keys[0]=="undedfined"||!this.keys[0]||this.keys[0]==""){
			//alert("retrying");
			setTimeout(this.nameOfShow+".processWordList(tmpHTTP)",5000);
			//this.getWordListClick(this.selectedWordListFileName)
		}else{
			this.rewindClick()
		}
	}
	
	this.nextWord=function() {
		if(this.position<(this.n-1)) {
			this.position++;
		}
		else {
			alert ("You are at the end of the list!");
		}
	}
	
	this.previousWord=function() {
		if(this.position>0) {
			this.position--;
		}
		else {
			alert ("You are at the beginning of the list");
		}
	}
	
	this.updateWordDisplay=function(showMeaning) {
		//if(!this.n){
		if((this.keys[this.position]==""||this.keys[this.position]=="undefined"||!this.keys[this.position])&&this.retryCount<3){
			//alert("retrying 2\nposition="+this.position+"\nkey="+this.keys[this.position]);
			this.retryCount++;
			//this.getWordListClick(this.selectedWordListFileName)
			//this.updateWordDisplay(false);
			setTimeout(this.nameOfShow+".updateWordDisplay(0)",9000);
			//setTimeout(this.updateWordDisplay(false),9000);
		}
		if(this.position!=-1) {
			this.update(this.nameOfShow+"_wordDisplay", this.keys[this.position]);
			if(showMeaning==true) {
				this.update(this.nameOfShow+"_meaningDisplay", this.values[this.position]);
			} else {
				this.update(this.nameOfShow+"_meaningDisplay", "");
			}
			//this.progressString = this.wordListName + " - " + (this.position+1) + "/" + this.n
			this.progressString = (this.position+1) + " of " + this.n
			this.update(this.nameOfShow+"_progressDisplay", this.progressString);
		}
		else {
			//alert("No valid worldist is currently in progress\n\nWordlist: "+this.selectedWordListFileName)
			alert("No valid worldist is currently in progress\n\nPlease click the link to load the flashcards")
		}
	}
	
	
	this.update=function(id, text) {
		document.getElementById(id).innerHTML = text;
	}
	
	
	this.shuffleList_mike = function(){ 
       //new function
	   //old shuffle function would drop words resulting in "undedfined"
 
	    for(var j, x, i = this.keys.length; i; ){
			j = parseInt(Math.random() * i);
			tmpPos=--i;
			tempKey = this.keys[tmpPos];
			this.keys[tmpPos] = this.keys[j];
			this.keys[j] = tempKey;
			tempVal = this.values[tmpPos];
			this.values[tmpPos] = this.values[j];
			this.values[j] = tempVal;
		}	   
	}
	
	this.shuffleList=function(rounds) {
		// Making sure the first word is swapped
		this.t = Math.floor(Math.random()*this.n) + 1;
		this.swapWords(0, this.t);
		
		for(r=0; r<rounds; r++){			
			this.i = Math.floor(Math.random()*this.n) + 1;
			this.j = Math.floor(Math.random()*this.n) + 1;
			this.swapWords(this.i, this.j);
		}
	}
	
	this.swapWords=function(i, j) {
		this.tempKey = this.keys[i];
		this.tempValue = this.values[i];
		this.tempNote = this.notes[i];
			
		this.keys[i] = this.keys[j];
		this.values[i] = this.values[j];
		this.notes[i] = this.notes[j];
		
		this.keys[j] = this.tempKey;
		this.values[j] = this.tempValue;
		this.notes[j] = this.tempNote;
	}
	
	this.GetXmlHttpObject=function() {
	    xmlHttp_ = null;
	    // alert("Entering get object");
	    try {
	      // Firefox, Opera 8.0+, Safari
	       xmlHttp_ = new XMLHttpRequest();
	    }
	    catch (e) {
	      // Internet Explorer
	      try {
	        xmlHttp_ = new ActiveXObject("Msxml2.XMLHTTP");
	      }
	      catch (e) {
	      	try {
	        	xmlHttp_ = new ActiveXObject("Microsoft.XMLHTTP");
	      	}
	      	catch (e) {
	      		alert(e);
	      	}
	      }
	    }
	    //alert("Exiting get object.\n\nxmlHttp_ is "+xmlHttp_);
	    return xmlHttp_;
	}
	
	this.printShow=function(){
		if(!this.keys.length){
			//load the list and wait a second for the xml processing to finish, using settimeout to wait, as it's the best way here MWarner 4/21/2010
			this.update(this.nameOfShow+"_wordDisplay", "loading flashcards");
			this.getWordListClick(this.selectedWordListFileName);
			setTimeout(this.nameOfShow+".printShow()",1000);
			return;
		}
		if(findDOM("courseTitleTD",0)){
			courseTitle=findDOM("courseTitleTD",0).innerHTML;
			assignmentTitle=(findDOM("assignmentTitleSPAN",0))?"<hr>"+findDOM("assignmentTitleSPAN",0).innerHTML:"";
			if(assignmentTitle==""){//no assignment, try module title
				assignmentTitle=(findDOM("moduleTitleTD",0))?"<hr>"+findDOM("moduleTitleTD",0).innerHTML:"";
			}
		}else{
			courseTitle="";
			assignmentTitle=""
		}
		tmpHTML="<html><body><center><table border=1 cellpadding=4>";
		tmpHTML+="<tr><td align=center colspan=2><strong>"+courseTitle+assignmentTitle+"</strong></td></tr>";
		for(g=0;g<this.keys.length;g++){
			tmpHTML+="<tr><td align=left>"+this.keys[g]+"</td><td align=left>"+this.values[g]+"</td></tr>";		
		}
		tmpHTML+="</table></body></html>";
		new_win=window.open('', '', 'width=450,height=450,directories=no,status=no,location=no,toolbar=no,scrollbars=yes,resizable=yes,menubar=yes,copyhistory=no'); 
		new_win.document.open();
		new_win.document.write(tmpHTML);
		new_win.document.close();
		new_win.focus();
	}
	
}//end "class"

//end flashcard functions


function view_hide_object(objectID,whichProperty){
	whichObjStyle=findDOM(objectID,1);
	if(whichProperty=="display"){
		if(whichObjStyle.display=='none'){
			whichObjStyle.display='block'
		}else{
			whichObjStyle.display='none'
		}
	}else{
	
		if(whichObjStyle.visibility=='hidden'){
			whichObjStyle.visibility='visible'
		}else{
			whichObjStyle.visibility='hidden'
		}
	
	}
}

//old function call...use new function code
function expandit(curobj){
	view_hide_object(curobj+"_answer","display");
}



//forum functions
var msg_id_array=new Array();
function view_hide_FullMessage(whichMsg){
	whichMsgStyle=findDOM(whichMsg+"_content",1);
	if(findDOM(whichMsg+"_is_new_icon",1).display=='block'){
		findDOM(whichMsg+"_is_new_icon",1).display='none'
		//call php with function below to add user's idxNum to array of users who've read this msg
		markMessageRead(whichMsg);
	}
	if(whichMsgStyle.display=='none'){
		whichMsgStyle.display='block'
		findDOM(whichMsg+"_showHideLink",0).innerHTML='<img src="/images/p/forum/m2.gif" alt="" border="0">'
	}else{
		whichMsgStyle.display='none'
		findDOM(whichMsg+"_showHideLink",0).innerHTML='<img src="/images/p/forum/p.gif" alt="" border="0">'
	}
}

function expandAll_contractAll(exp_cont_display,whichSubArray){
	whichBunchOfMessages=eval(whichSubArray).split(":");
	if(!whichBunchOfMessages||!whichBunchOfMessages.length||!findDOM(whichBunchOfMessages[0]+"_content",0)){return}
	for(g=0;g<whichBunchOfMessages.length;g++){
		findDOM(whichBunchOfMessages[g]+"_content",1).display=exp_cont_display
		findDOM(whichBunchOfMessages[g]+"_showHideLink",0).innerHTML=(exp_cont_display=='block')?'<img src="/images/p/forum/m2.gif" alt="" border="0">':'<img src="/images/p/forum/p.gif" alt="" border="0">';
		if(findDOM(whichBunchOfMessages[g]+"_is_new_icon",1).display!='none'){
			findDOM(whichBunchOfMessages[g]+"_is_new_icon",1).display='none'
			//call php with function below to add user's idxNum to array of users who've read this msg
			//markMessageRead(msg_id_array[g]);
		}
	}
	//do them all at once with a single query
	markMultipleMessagesRead(eval(whichSubArray));
}

function markMessageRead(whichMsg){
	cheater= new Image();
	pathToPage="/p/onlineEd/markForumMsgRead.php?c="+whichMsg
	cheater.src=(pathToPage);
}

function markMultipleMessagesRead(whichBunchOfMessages){
	cheater= new Image();
	pathToPage="/p/onlineEd/markForumMsgRead.php?c="+whichBunchOfMessages;//msg_id_array.join(":");
	//alert(pathToPage)
	cheater.src=(pathToPage);
}

//functions to open an image in a window of the appropriate size for the image
function opengraphic(img){
	graphic= new Image();
	graphic.src=(img);
	check_for_graphic(img);
 }

 //double, in case I used this one, too
function opengraphic2(img){
	graphic= new Image();
	graphic.src=(img);
	check_for_graphic(img);
 }

function check_for_graphic(img){
	if((graphic.width!=0)&&(graphic.height!=0)){
		viewGraphic(img);
	}else{
		the_function="check_for_graphic('"+img+"')";
		interval=setTimeout(the_function,20);
	}
}

function viewGraphic(img){
	window_w=graphic.width+25;
	window_h=graphic.height+25;
	params="width="+window_w+",height="+window_h;
	newWin=window.open(img,"",params);
}

//generic pop-up window function
//all params are passed in the call
//win_features is toolbar, menubar, height, width, etc
function doWindowOpen(win_url,win_name,win_features,set_parent){ 
	var new_win;
	new_win=window.open(win_url, win_name, win_features); 
	if(set_parent==1){
		new_win.par=self 
	} 
	new_win.focus();
}

//generic pop-up window function where the content will be passed as an arg
//good for small amounts of text
//all params are passed in the call:
//win_features is toolbar, menubar, height, width, etc

function doWindowOpenWriteText(win_features,content){ 
	var new_win;
	content="<html><head><title>Pop-up content</title></head><body bgcolor=white><font size=2>"+content+"</font></body></html>";
	new_win=window.open('', '', win_features); 
	new_win.document.open();
	new_win.document.write(content);
	new_win.document.close();
	new_win.focus();
}

//random code generator functions
function makeDiscountCode(whichForm,whichField,howLongShouldCodeBe){
	whichForm[whichField].value=GenerateDiscountCode(howLongShouldCodeBe);
}

function GenerateDiscountCode(howLongShouldCodeBe) {
    var length=howLongShouldCodeBe;//length of sCode
    var sCode = "";
    var noPunction = 1;
    var randomLength = 0;

    if (randomLength) {
        length = Math.random();
        length = parseInt(length * 100);
        length = (length % 7) + 6
    }

    for (i=0; i < length; i++) {
        numI = getRandomNum();
        if (noPunction) { while (checkPunc(numI)) { numI = getRandomNum(); } }
        sCode = sCode + String.fromCharCode(numI);
    }
    return sCode//.toUpperCase();
}

function getRandomNum() {
    // between 0 - 1
    var rndNum = Math.random()
    // rndNum from 0 - 1000
    rndNum = parseInt(rndNum * 1000);
    // rndNum from 33 - 127
    rndNum = (rndNum % 94) + 33;
    return rndNum;
}

function checkPunc(num) {
    if ((num >=33) && (num <=47)) { return true; }
    if ((num >=58) && (num <=64)) { return true; }
    if ((num >=91) && (num <=96)) { return true; }
    if ((num >=123) && (num <=126)) { return true; }
    return false;
}

function save_iea_time(who){
	pullerUrl="/tools/IEA_courseTimeGetter.php?a=s&mI="+who+"&t="+$timer_totalTime+"&cI="+whichCourseID;
	//alert(pullerUrl)
	AJAX_request(pullerUrl,saveTimeAndGoHome);
	//window.location="/home/";
}

function saveTimeAndGoHome(msg){
	return;//don't do this.  Not sure why I added it in the first place.
	if(confirm(msg+"\nYou will now be logged out.  Click cancel be redirected to the home page where you can enter another course or re-enter this course.")){
		window.location="/home/";
	}else{
		window.location="/p/member/memberLogout.php";
	}
}

var who_is_being_timed;
var $returnedTime;
var $timer_usedTime;
var $timer_totalTime;

//iea timer starts here 
function start_iea_time(who,course){
	who_is_being_timed=who;
	retrieve_iea_time(who,course);
	/* removed to eliminate the cookie use MWarner 10/22/09
	if(!GetCookie(timerCookieDataName)||$timer_totalTime==0){//||$timer_totalTime>250*60*60){//also watch out for very large times.  There's been an issue with folks having more than 1500 hours after one day in the course.
	//if(!$timer_totalTime){
		//$timer_usedTime=retrieve_iea_time(who,course);
		retrieve_iea_time(who,course);
		//if(isNaN($timer_usedTime)){$timer_usedTime=0;}
		$timer_totalTime=$timer_usedTime;
		//SetCookie(timerCookieDataName,$timer_totalTime);
	}else{
		//alert("got here 4")
		//alert("4:"+$timer_totalTime)
		if(isNaN($timer_usedTime)){$timer_usedTime=0;}
		$timer_usedTime=GetCookie(timerCookieDataName)
		$timer_totalTime=($timer_usedTime>$timer_totalTime&&$timer_usedTime<250*60*60)?$timer_usedTime:$timer_totalTime;//new 5/25/07 to keep timer from resetting to the lower db value
	}
	*/
	Timer_start();
}

var whichCourseID;
function retrieve_iea_time(who,which){
	whichCourseID=which;
	pullerUrl="/tools/IEA_courseTimeGetter.php?a=g&mI="+who+"&cI="+which
	AJAX_request(pullerUrl,setTimerVal);
}

function setTimerVal(val){
	val=parseInt(val);
	$returnedTime=val;
	if(parseInt($timer_usedTime) < parseInt(val)){$timer_usedTime=val;}
	if(parseInt($timer_totalTime) < parseInt(val)){$timer_totalTime=val;}
	//safety check...sometimes it comes back as Nnull or NaN, as javascript sees it
	if(!val || isNaN(val)){
		//alert(val)
		retrieve_iea_time(theData[0],whichCourseID);
	}else{
		findDOM($timerField,0).value= getFormattedTime(val,false);
	}
	//alert($timer_totalTime)
	//don't set the cookie Mwarner 10/23/09
	//SetCookie(timerCookieDataName,$timer_totalTime)
}

//pullerUrl is the url of the code to execute
//returnToFunction is the javascript function that will do something with the responseText
function AJAX_request(pullerUrl,returnToFunction){
	xhr=null;
	// non-IE
	if (window.XMLHttpRequest) {
		xhr = new XMLHttpRequest();
	}
	// IE version - activeX
	else if (window.ActiveXObject){
		xhr = new ActiveXObject("Microsoft.XMLHTTP");
	}
	xhr.open("GET",pullerUrl);
	/*only needed for POST
	xhr.setRequestHeader(
		'Content-Type',
		'application/x-www-form-urlencoded; charset=UTF-8');
	*/
	xhr.setRequestHeader("Pragma", "no-cache"); 
	xhr.setRequestHeader("Expires", "Mon, 26 Jul 1997 05:00:00 GMT"); 
	xhr.setRequestHeader("Cache-Control", "no-store, must-revalidate,must-revalidate, max-age=-1"); 
			
	if(window.XMLHttpRequest){//non-IE
		xhr.send(null);
	}	
	else if(window.ActiveXObject){//IE
		xhr.send();
	}
	xhr.onreadystatechange=function() {
		if(xhr.readyState==4){
			returnToFunction(xhr.responseText);			
		}
	}
}


function getFormattedTime(tmp_secs,format){
	if(tmp_secs==""||!tmp_secs){
		return "00:00:00";
		//return (format)?"00:00:00":"0";	
	}
	hours = Math.floor(tmp_secs/3600);
	tmp_secs = tmp_secs - (hours*3600);
	
	minutes = Math.floor(tmp_secs/60);
	tmp_secs = tmp_secs - (minutes*60);
	
	seconds = Math.floor(tmp_secs);
	if(format){
		formattedTime=(hours)?(hours>1)?hours+"hrs ":hours+"hr ":"";
		formattedTime+=(minutes)?minutes+"min ":"";
		formattedTime+=(seconds>1||!seconds)?seconds+"secs":seconds+"sec";
		return formattedTime;
	}else{
		return addLeadingZero(hours)+":"+addLeadingZero(minutes)+":"+addLeadingZero(seconds);
	}
}

function addLeadingZero(whichNumber){
	if(!whichNumber){return "00"}//for 0, etc
	whichNumber=whichNumber.toString()
	if(whichNumber.length<2){
		whichNumber="0"+whichNumber
	}
	return whichNumber;
}

function disableSubmitButton(buttonValue){
	for(b=0;b<document.forms.length;b++){
		for(g=0;g<document.forms[b].elements.length;g++){
			if(document.forms[b].elements[g].type=="submit"&&document.forms[b].elements[g].value==buttonValue){
				document.forms[b].elements[g].disabled=true;
			}
		}
	}
}

function returnFalse(){//frakkin IE needs it this way on a link...used to be able to put the 'onclick="return false"' inline
	return false;
}

function confirmResetTest(){
	if(confirm('Are you sure you want to delete these test results?')){
		document.location=document.location.href+'&resetTest=true';
	}	
}

function bookmarksite(){
	bookmarkSet=0;
	title=document.title;
	tmp=document.location.href.split("?");//strip off query string
	url=tmp[0];
	if(window.sidebar){ // firefox
		window.sidebar.addPanel(title, url, "");
		bookmarkSet=1;
	}
	if(window.opera && window.print && !bookmarkSet){ // opera
		var elem = document.createElement('a');
		elem.setAttribute('href',url);
		elem.setAttribute('title',title);
		elem.setAttribute('rel','sidebar');
		elem.click();
		bookmarkSet=1;
	} 
	if(document.all && !bookmarkSet){// ie
		window.external.AddFavorite(url, title);
	}
}

function strip_HTML(str){
	//remove html tags
	str = str.replace(/(<([^>]+)>)/ig,"");
	//replace &nbsp; with actual spaces
	str = str.replace(/&nbsp;/ig," ");
	return str;
}

function trim(string){
  return string.replace(/^\s+/, "").replace(/\s+$/, "");
}

function viewComponentContent(which,responseTitle){
	if(navigator.appName=="Microsoft Internet Explorer" || 1){//new way.  IE update broke the old way
		if(responseTitle){
			responseTitle=responseTitle;
		}else{
			responseTitle="Expert response";
		}
		if(window.location.href.indexOf("mindedge.com")>-1){
			new_win=window.open('/jscripts/response_pop-up.php?t='+escape(responseTitle)+'&which='+which, '', 'height=500px,width=500px,menubar=yes,scrollbars=auto'); 
		}else{
			new_win=window.open('response_pop-up.html?t='+escape(responseTitle)+'&which='+which, '', 'height=500px,width=500px,menubar=yes,scrollbars=auto'); 
		}
		
	}else{
		content="<html"+"><script src=\"/jscripts/findDOM.js\""+"></script"+"><script src=\"/jscripts/functions.js\""+"></script"+"><style"+">body, p, blockquote, div{font-family:Verdana;font-size:14px;}</style>";
	
		if(findDOM("domain-specific-css",0)){
			content+="<style>"+findDOM("domain-specific-css",0).innerHTML+"</style>";
		}
		content+="\n<body style='padding:0px;margin:0px;'"+"><div style='height:500px;overflow:auto;padding:6px;'"+"><b"+">Your response</b>";
		content+="<blockquote style='border:1px solid #cccccc;background-color:#ffffe0;padding:4px;'"+">"+findDOM("studentInput_"+which,0).value+"</blockquote>";
		if(responseTitle){
			content+="<b>"+responseTitle+"</b>";
		}else{
			content+="<b>Expert response</b>";
		}
		content+="<blockquote style='border:1px solid #cccccc;background-color:#ffffe0;padding:4px;'"+">"+findDOM("sampleResponse_"+which,0).value+"</blockquote>";
		content+="</div"+"></body"+"></html>";
		
		new_win=window.open('', '', 'height=500px,width=500px,menubar=yes,scrollbars=auto'); 
		new_win.document.open();
		new_win.document.write(content);
		new_win.document.close();
		new_win.focus();
	}

}


//te expand textareas based on content size.  uses onkeyup MWarner 10/30/08
function resizeTextarea(which){
	tmp=which.value.split('\n')
	numLines=tmp.length
	if(tmp[tmp.length-1]==""){
		numLines--;
	}
	//which.rows=(numLines>which.rows)?numLines:which.rows;
	which.rows=countLines(which);
}


function countLines(which) {
	minRows=4;
	strtocount=which.value;
	cols=which.cols
	hard_lines = 1;
	last = 0;
	while ( true ) {
		last = strtocount.indexOf("\n", last+1);
		hard_lines++;
		if ( last == -1 ) break;
	}
	soft_lines = Math.round(strtocount.length / (cols-1));
	soft_lines=(hard_lines > soft_lines)?hard_lines:soft_lines;
	if(soft_lines<minRows){soft_lines=minRows;}
	return (soft_lines >25)?25:soft_lines-1;//limit the size to 25 rows, otherwise it's hard to use with loong text MWarner
}