function inDiv_toggle(id,var_name)
	{
		var x = document.getElementById(id);
		if (x.style.display == 'block')
			{
				x.style.display='none';
			}
		else
			{
				var rawVar = var_name;
				var fixedVar = myTrim(rawVar);
				x.style.display='block';
				var myText = '<p>'+fixedVar+'</p>';
				document.getElementById(id).innerHTML = myText;
			}
	} //end of inDiv_toggle



function myDiv(id,prefix,var_name,suffix)
	{
		var divID=myTrim(id);
		var buttonName=divID+"_button";
		fixedPrefix=myTrim(prefix);
		var contentVar=myTrim(var_name);
		var firstButton='<img class=float_right src="../../image/show1_small.gif" onClick="unhide(this.title);">';
		firstButton=firstButton+suffix;
		document.write(firstButton);
		var k=document.images.length;
		document.images[k-1].title = divID;
		document.images[k-1].id = buttonName;
		createDiv(divID,fixedPrefix,contentVar);
	}  //end myDiv function

function createDiv(id,prefix,var_name)
    {
		var divTag = document.createElement("div");
        divTag.id = id;
        divTag.setAttribute("align","left");
		divTag.className ='hidden';
		var myText = '<p><b class = "bigred" >'+prefix+':</b> '+var_name+'</p>';
		divTag.innerHTML = myText;
        document.body.appendChild(divTag);
    } //end createDiv


function unhide(divID) 
	{
		switch_button(divID);
		var item = document.getElementById(divID);
		if (item) 
			{
				item.className=(item.className=='hidden')?'unhidden':'hidden';
			}
	}  //end unhide

function switch_button(divID)
	{
		var buttonName=divID+"_button";
		var old_src=document.getElementById(buttonName).src ;
		var last_slash_old_src=old_src.lastIndexOf("/");
		var imgName=old_src.slice(last_slash_old_src+1);
		if (imgName=="show1_small.gif")
			{
				var new_src = old_src.replace(/show1_small.gif/,"hide1_small.gif");
				document.getElementById(buttonName).src=new_src;
			}
			else if (imgName=="show1_large.gif")
				{
					var new_src = old_src.replace(/show1_large.gif/,"hide1_large.gif");
					document.getElementById(buttonName).src=new_src;					
				}
			else if (imgName=="hide1_small.gif")
				{
					var new_src = old_src.replace(/hide1_small.gif/,"show1_small.gif");
					document.getElementById(buttonName).src=new_src;				
				}
			else if (imgName=="hide1_large.gif")
				{
					var new_src = old_src.replace(/hide1_large.gif/,"show1_large.gif");
					document.getElementById(buttonName).src=new_src;				
				}			
			else
				{
					alert("Something is broken.");
				}
	}//end of function switch_button


function toggle_example(id) 
	{
//		var e = document.getElementById(id);
		var icon_id="toggle"+id;
		var old_src=document.getElementById(icon_id).src ;
		var last_slash_old_src=old_src.lastIndexOf("/");
		var iconName=old_src.slice(last_slash_old_src+1);
		if (iconName=="toggle_on.gif")
			{
				var new_src=old_src.replace('toggle_on','toggle_off');
			}
		else
			{
				var new_src=old_src.replace('toggle_off','toggle_on');
			}
		document.getElementById(icon_id).src=new_src;
		var e = document.getElementById(id);
		if(e.style.display != 'block')
			{
				e.style.display = 'block';
			}
		else
			{
				e.style.display = 'none';		
			}
	} //end_toggle_visibility

function toggle_visibility(id) 
	{
//		var e = document.getElementById(id);
		var icon_id="toggle"+id;
		var old_src=document.getElementById(icon_id).src ;
		var last_slash_old_src=old_src.lastIndexOf("/");
		var iconName=old_src.slice(last_slash_old_src+1);
		if (iconName=="toggle_on.gif")
			{
				var new_src=old_src.replace('toggle_on','toggle_off');
			}
		else
			{
				var new_src=old_src.replace('toggle_off','toggle_on');
			}
		document.getElementById(icon_id).src=new_src;
		var e = document.getElementById(id);
		if(e.style.visibility != 'visible')
			{
				e.style.visibility = 'visible';
			}
		else
			{
				e.style.visibility = 'hidden';		
			}
	} //end_toggle_visibility
	
	
function show_field(id1)
  {
		var el = document.getElementById(id1);
		el.style.display = "inline";
  }  //end toggle_td_on
  
  
function hide_field(id1)
  {
		var el = document.getElementById(id1);
		el.style.display = "none";
  }  //end toggle_td_off


function showMe()
	{
		xx=eval("answer_"+question_id);
		document.getElementById('feedback_field').innerHTML = "The correct response is: "+xx;	
	}		
		
		




function myPut(prefix,var_name)
//  To call this function use:     myPut('Definition',def_norm_of_complex_number)
//  The first parameter is a word displayed in bold red  Definition, Fact, Property, etc.
//  The second parameter is the name of the item in the database  -- this is what shows on the page
	{
		var rawVar = var_name;
		var fixedVar = myTrim(rawVar);
		if (prefix =="")
 		    {
				var myText = '<p>'+fixedVar+'</p>';

			}
			else
			{
				
				var myText ='<p>'+'<b class = "bigred" >'+prefix+':</b> '+fixedVar+'</p>';
			}
		document.write (myText);
	} // end myPut function



function makeSwitch(myMode)
	{
		var imageCount=document.images.length;
		for (var i=0; i<imageCount; i++)
			{
				old_src = document.images[i].src;
				if (myMode == "monitor")
				{
					new_src = old_src.replace(/large.gif/,"small.gif");
					document.images[i].src = new_src;
				}
				else
					{
						new_src = old_src.replace(/small.gif/,"large.gif");
						document.images[i].src = new_src;
					}
			}
	}  //end makeSwitch
 

 function myJump(myType,chap_id,grp_id)
	{
		if (myType == "TF")
			{
				myURL = "../tf_quizzes/tf_quiz_presenter.htm?"+chap_id+"&"+grp_id;
				document.getElementById("tfLink").href=myURL;
			}
			else if (myType == "SAN")
				{
					myURL = "../san_quizzes/san_quiz_presenter.htm?"+chap_id+"&"+grp_id;
					document.getElementById("sanLink").href=myURL;
				}
				else if (myType == "MC")
					{
						myURL = "../mc_quizzes/mc_quiz_presenter.htm?"+chap_id+"&"+grp_id;
						document.getElementById("mcLink").href=myURL;
					}
					else if (myType == "FIB")
						{
							myURL = "../fib_quizzes/fib_quiz_presenter.htm?"+chap_id+"&"+grp_id;
							document.getElementById("fibLink").href=myURL;
						}
						else if (myType == "SEL")
							{
								myURL = "../sel_quizzes/sel_quiz_presenter.htm?"+chap_id+"&"+grp_id;
								document.getElementById("selLink").href=myURL;
							}
//alert(myURL);		
//		location.href = myURL;
	}
 
 
 function mySummaryReturn(myPage)
	{
	if(myPage=="quizPage")
		{
			prefix = "../../../meramec_college_algebra/chapter_summaries/college_algebra_summary";
		}
		else
		{
			prefix = "../../meramec_college_algebra/chapter_summaries/college_algebra_summary";
		}
	myURL = prefix+"_"+chapter_id +".html#"+group_id;
//	alert(myURL);
    document.getElementById("summaryLink").href=myURL;
	}
 
 function qs()  //this function gets the chapter_id and group_id from the query string
	{
		var query = window.location.search.substring(1);
		var parms = query.split('&');
		chapter_id = parms[0];
		group_id = parms[1];
	}
 
 function myPrevious()
	{
	if (question_number > 1)
		{
			question_number = question_number-1;
			myReset();
			question_id = question_type+"_"+group_id+"_"+question_number;
			myQuestion(question_id);
		}
		else
		{
			alert("You are viewing the first question.");
			myReset();
			myFirst();
		}
	}
	
function myFirst()
	{
		max_count = eval(question_type+"_"+group_id+"_max_count");
		question_number=1;
		myReset();
		question_id = question_type+"_"+group_id+"_"+question_number;
		myQuestion(question_id);
	}
	
function myLast()
	{
		question_number=max_count;
		myReset();
		question_id = question_type+"_"+group_id+"_"+question_number;
		myQuestion(question_id);
	}	

 
 function myNext()
	{
	if (question_number < max_count)
		{
			question_number = question_number+1;
			myReset();
			question_id = question_type+"_"+group_id+"_"+question_number;
			myQuestion(question_id);
		}
		else
		{
			alert("You are viewing the last question.");
			myReset();
			myLast();
		}
	}
 
 function showresults(response)
		{
		  document.getElementById('feedback_field').innerHTML = eval(response);
		}
 
 function myQuestion(var_name)
	{
		if (question_type=="mc")
			{
				
				var myCount_choice = eval("choice_count_"+var_name);
				
				choice_count_field=myCount_choice;
				var myQuestion_Stem = eval(var_name);
				var myQuestion_choice1 = eval("choice1_"+var_name);
				for (i = 1;i<= myCount_choice;i++)//loop through the choices to retrieve them
					{
						var ai="a"+i;
						document.getElementById(ai).innerHTML =eval("choice"+i+"_"+var_name);
					}
					with (Math)
					{
						var first_row_to_delete = floor(myCount_choice/2)+1;
					}
				for (j=first_row_to_delete;j<=10;j++)
					{
						row_id="row"+j;
						hide_field(row_id);
					}
			}
		var myText = eval(var_name);
		document.getElementById('question_field').innerHTML = myText;
	}  //end myQuestion	
 
 function myReset()
	{
		document.getElementById('question_field').innerHTML = "";
		document.getElementById('feedback_field').innerHTML = "";
		document.getElementById('max_count_field').innerHTML = "There are "+max_count+" questions in this group.";		
		document.getElementById('current_question_field').innerHTML = "You are currently viewing Question "+question_number+".";		
		if (question_type=="tf")
			{
				quiz.answer[0].checked = false;
				quiz.answer[1].checked = false;	
			}
		if (question_type=="san")
			{
				quiz.answer[0].checked = false;
				quiz.answer[1].checked = false;	
				quiz.answer[2].checked = false;					
			}			
		if (question_type =="mc")
			{
				for (k=1;k<=10;k++)
					{
						row_id="row"+k;
						show_field(row_id);
					}
				for (k=21;k<=40;k++)
					{
						var bk="b"+k;
						document.getElementById(bk).innerHTML = "";
					}					
				quiz.box1.checked=false;
				quiz.box2.checked=false;
				quiz.box3.checked=false;
				quiz.box4.checked=false;
				quiz.box5.checked=false;
				quiz.box6.checked=false;
				quiz.box7.checked=false;
				quiz.box8.checked=false;
				quiz.box9.checked=false;
				quiz.box10.checked=false;
				quiz.box11.checked=false;
				quiz.box12.checked=false;
				quiz.box13.checked=false;
				quiz.box14.checked=false;
				quiz.box15.checked=false;
				quiz.box16.checked=false;
				quiz.box17.checked=false;
				quiz.box18.checked=false;
				quiz.box19.checked=false;
				quiz.box20.checked=false;
			}
	}
 
 
 
 
 
 
function lookUp(myDisplay,myWord,myCaption)
//  To call this function use:  lookUp('function','def_function','Definition of Function')
//  The first parameter is the word which appears in the textline -- it looks like a link.
//  The second parameter is the name of the item in the database -- this is what shows in the pop-up
//  The third parameter is the text to appear in the caption bar
//  If the third parameter is '', there will be no caption bar	
	{
		var M = myWord
		var K = ' <b><font color="#0000FF"><u><a  href="#" onMouseOver="return overlib(';
		var JJ = ',CAPTION,'  //+ myCaption +')';
		var J = ')"onMouseOut="nd();">';
//		var XX =  'sum </a></u></font></b>';
		var XX =  myDisplay + '</a></u></font></b>';
		var MM = '\''+ myCaption +'\'';
		var myText =  K + M + JJ + MM + J + XX ;
		document.write (myText);
	} // end lookUp function		
		
		
		

function myIconSez(myImage,mycontent)
//  To call this function use:  myIconSez('small_owl','def_norm_of_complex_number')
//  The first parameter is the name of the icon to be displayed
//  That icon must be a 24X24 gif file in the web/image directory
//  The second parameter is the name of the item in the database  -- this is what shows in the pop-up
	{
		var K = '<a href="#"onMouseOver="return overlib(';
		var J = ')" onMouseOut="nd();">';
		var mypre = K + mycontent + J;
		var A = '<img src="../../image/';
		var B = '.gif" width="24" height="24" border="0" align="absmiddle">';
		var mymid = A + myImage + B;
		var myend = '</a>';
		var myText =  mypre + mymid  + myend;
		document.write (myText);
	} // end myIconSez function






function myTrim(string)
	{
		var newString = RTrim(LTrim(string));
		var myLength = newString.length;
		var startbr = newString.indexOf("<br>");
		if (startbr !=-1)
		{
			var nn = myLength - startbr -4;
			newString = Left(newString,startbr)+'&nbsp;'+Right(newString,nn);
		}
		return newString
	} // end myTrim function


	
function Left(str, n)
	{
		if (n <= 0)     // Invalid bound, return blank string
			return "";
		else if (n > String(str).length)   // Invalid bound, return
			return str;                // entire string
		else // Valid bound, return appropriate substring
			return String(str).substring(0,n);
	}	

function LTrim(str)
	{
		var whitespace = new String(" \t\n\r");
		var s = new String(str);
		if (whitespace.indexOf(s.charAt(0)) != -1) 
		{
			var j=0, i = s.length;
			while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
				j++;
				s = s.substring(j, i);
		}
		return s;
	}

function Right(str, n)
	{
		if (n <= 0)     // Invalid bound, return blank string
			return "";
		else if (n > String(str).length)   // Invalid bound, return
			return str;                     // entire string
		else 
		{ // Valid bound, return appropriate substring
			var iLen = String(str).length;
			return String(str).substring(iLen, iLen - n);
		}
	}
		  
function RTrim(str)
	{
		var whitespace = new String(" \t\n\r");
		var s = new String(str);
		if (whitespace.indexOf(s.charAt(s.length-1)) != -1) 
		{
			var i = s.length - 1;       // Get length of string
			while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
			i--;
			s = s.substring(0, i+1);
		}
		 return s;
	}
