//<!--
//Begin script for Drug Information tutorial
//Written by Harry Love
//Email if you have questions: hlove@u.washington.edu
//Education Technology Specialist
//University of Washington
//Seattle, WA 98195-7155

//Get the URL of the current document and store it
// in the loc variable
var d = document;
var loc = d.location.href;

//Replace the "//" in "http://currentURL.com" with "/"
//and store that in the loc variable
var newLoc = loc.replace("//", "/");
	
//Split the URL into segments and store them in
// an array using "/" as a delimiter
var linkArray = newLoc.split('/');

//Get the current directory
var curDirectory = linkArray[linkArray.length-2];

//Get the current file
var curFile = linkArray[linkArray.length-1];

//If the current file shows up blank...
if(curFile == "")
{
	//Call the current file "index.html"
	curFile = "index.html";
}

//Separate the current file from its DOS extension
var curFileSplit = curFile.split('.');

//Populate the navList variable with an array of
//the entire tutorial contents
var navList = new Array(
	["dir", "drugs", "index" , "/howto/drugs/" , "Home"],
	["dir", "material", "index", "/howto/drugs/material/", "Drug Resources"],
	["sub", "material", "index", "/howto/drugs/material/", "Section Guide"],
	["sub", "material", "step1", "/howto/drugs/material/step1.html", "Classifying Sources"],
	["sub", "material", "step2", "/howto/drugs/material/step2.html", "Paths to Information"],
	["sub", "material", "step3", "/howto/drugs/material/step3.html", "Resources by Topic"],
	["sub", "material", "step4", "/howto/drugs/material/step4.html", "Resources Descriptions"],
	["sub", "material", "step5", "/howto/drugs/material/step5.html", "Answering the Question"],
	["dir", "practice", "index", "/howto/drugs/practice/", "Practice"],
	["sub", "practice", "index", "/howto/drugs/practice/", "Section Guide"],
	["sub", "practice", "scenario1", "/howto/drugs/practice/scenario1.html", "Side Effects"],
	["sub", "practice", "scenario2", "/howto/drugs/practice/scenario2.html", "Recent News"],
	["sub", "practice", "scenario3", "/howto/drugs/practice/scenario3.html", "Off-Label Uses"],
	["sub", "practice", "scenario4", "/howto/drugs/practice/scenario4.html", "Immunizations"],
	["sub", "practice", "scenario5", "/howto/drugs/practice/scenario5.html", "Herbal Medications"],
	["sub", "practice", "scenario6", "/howto/drugs/practice/scenario6.html", "Foreign Drugs"],
	["sub", "practice", "scenario7", "/howto/drugs/practice/scenario7.html", "Cost of Therapy"],
	["sub", "practice", "scenario8", "/howto/drugs/practice/scenario8.html", "Drug Interactions"],
	["dir", "summary", "index", "/howto/drugs/summary/", "Summary"],
	["sub", "summary", "index", "/howto/drugs/summary/", "Tutorial Summary"],
	["sub", "summary", "selftest", "/howto/drugs/summary/selftest.html", "Test Yourself"],
	["sub", "summary", "evaluation", "/howto/drugs/summary/evaluation.html", "Evaluate This Tutorial"],
	["dir", "sitemap", "index", "/howto/drugs/sitemap/", "Site Map"],
	["dir", "help", "index", "/howto/drugs/help/", "Help/Contact"]);		


function createNavigation()
{
	for(x=0; x < navList.length; x++)
	{
		if(navList[x][0] == "dir")
		{
			if(curDirectory == navList[x][1])
			{
				d.write('<div class="directoryActive"><a href="' + navList[x][3]+ '">' + navList[x][4] + '</a></div>');
			}
			else
			{
				d.write('<a href="' + navList[x][3] + '">' + navList[x][4] + '</a><br />');
			}
		}
		else
		{
			if(curDirectory == navList[x][1] && curFileSplit[0] == navList[x][2])
			{
				d.write('<div class="subDirectoryActive"><a href="' + navList[x][3] + '">' + navList[x][4] + '</a></div>');
			}
			else
			{
				d.write('<div class="subDirectory"><a href="' + navList[x][3] + '">' + navList[x][4] + '</a></div>');
			}
		}
	}
}	

function createPrevNextLinks()
{
	var prevSymbol = '&laquo;&nbsp;';
	var nextSymbol = '&nbsp;&raquo;';
	var space = '&nbsp;|&nbsp;';
	for (x=0;x<navList.length;x++)
	{
		if(navList[x][1] == curDirectory)
		{
			if(navList[x][2] == curFileSplit[0])
			{
				var y = parseInt(x) -1;
				var z = parseInt(x) +1;
				if(y>=0 && z<navList.length)
				{
					if(navList[x][3] != navList[z][3])
					{
						if(navList[x][3] == navList[y][3])
						{
							var y = y - 1;
						}
						d.write(prevSymbol+'<a href="' + navList[y][3] + '" title="' + navList[y][4] + '">Previous</a>');
						d.write(space);
						d.write('<a href="' + navList[z][3] + '" title="' + navList[z][4] + '">Next</a>'+nextSymbol);
					}
				}
				else
				{
					if(y<0)
					{
						d.write(prevSymbol+'Previous');
						d.write(space);
						d.write('<a href="' + navList[z][3] + '" title="' + navList[z][4] + '">Next</a>'+nextSymbol);
					}
					else
					{
						d.write(prevSymbol+'<a href="' + navList[y][3] + '" title="' + navList[y][4] + '">Previous</a>');
						d.write(space);
						d.write('Next'+nextSymbol);
					}
				}	
			}
		}
	}
}

var ie = (navigator.appName.indexOf("Microsoft Internet Explorer") >-1);

function showPopupHelp(e, h, text)
{
	var x = 0;
	var y = 0;
	var bWidth = 0;
	var elem = d.getElementById("popupBox").style;
	var w = elem.width = 300;
	elem.height = h;
	if (ie)
	{
		if(e.toElement.id == "flowchartimage")
		{
			x = e.clientX + document.body.scrollLeft;
			y = e.clientY + document.body.scrollTop;
		}
		else
		{
			x = parseInt(e.offsetX);
			y = parseInt(e.offsetY);
		}
		bWidth = parseInt(d.body.clientWidth);
			
	}
	else
	{
		if(e.relatedTarget.id == "flowchartimage")
		{
			x = e.clientX;
			y = e.clientY;
		}
		else
		{
			x = e.pageX;
			y = e.pageY;
		}
		bWidth = parseInt(window.innerWidth);
		
	}

	if (parseInt(w) + x >= bWidth)
	{
		elem.left = bWidth - parseInt(w) - 50 + "px";
	}
	else
	{	
		elem.left = x - 40 + "px";
	}

	elem.top = y - h - 50 + "px";
	elem.visibility = "visible";
	d.getElementById("popupBox").firstChild.nodeValue = text;
}


function hidePopupHelp()
{
<!-- When the mouse rolls off the calling tag, the onmouseout event calls this function which switches the visibility of the <DIV> box from visible to hidden, thus making the text box disappear from the screen. -->
	document.getElementById("popupBox").style.visibility = "hidden";
}


function evaluateExam()
{
	var numWrong = 0;
	var wrongAnswers = new Array(" ");
	var answer4a = d.ditExam.textfield1a.value;
	var answer4b = d.ditExam.textfield1b.value;
	var answer4c = d.ditExam.textfield1c.value;
	var answer4d = d.ditExam.textfield1d.value;
	var answer4e = d.ditExam.textfield1e.value;
	var answer4f = d.ditExam.textfield1f.value;
	var answer5a = d.ditExam.textfield2a.value;
	var answer5b = d.ditExam.textfield2b.value;
	var answer5c = d.ditExam.textfield2c.value;
	var answer5d = d.ditExam.textfield2d.value;
	var answer5e = d.ditExam.textfield2e.value;

	if(!d.ditExam.radiobutton1[1].checked)
	{
		numWrong = numWrong + 10;
		wrongAnswers[wrongAnswers.length-1] = "1";
	}
	
	if(!d.ditExam.radiobutton2[3].checked)
	{
		numWrong = numWrong + 10;
		if(wrongAnswers[wrongAnswers.length-1] != " ")
		{
			wrongAnswers[wrongAnswers.length] = "2";
		}
		else
		{
			wrongAnswers[wrongAnswers.length-1] = "2";
		}
	}
	
	if(!d.ditExam.radiobutton3[1].checked)
	{
		numWrong = numWrong + 10;
		if(wrongAnswers[wrongAnswers.length-1] != " ")
		{
			wrongAnswers[wrongAnswers.length] = "3";
		}
		else
		{
			wrongAnswers[wrongAnswers.length-1] = "3";
		}
	}
	
	if(answer4a == "c" || answer4a == "C")
	{
		numWrong = numWrong;
	}
	else
	{
		numWrong = numWrong + 10;
		if(wrongAnswers[wrongAnswers.length-1] != " ")
		{
			wrongAnswers[wrongAnswers.length] = "4i";
		}
		else
		{
			wrongAnswers[wrongAnswers.length-1] = "4i";
		}
	}
					
	if(answer4b == "f" || answer4b == "F")
	{
		numWrong = numWrong;
	}
	else
	{
		numWrong = numWrong + 10;
		if(wrongAnswers[wrongAnswers.length-1] != " ")
		{
			wrongAnswers[wrongAnswers.length] = "4ii";
		}
		else
		{
			wrongAnswers[wrongAnswers.length-1] = "4ii";
		}
	}
	
	if(answer4c == "d" || answer4c == "D")
	{
		numWrong = numWrong;
	}
	else
	{
		numWrong = numWrong + 10;
		if(wrongAnswers[wrongAnswers.length-1] != " ")
		{
			wrongAnswers[wrongAnswers.length] = "4iii";
		}
		else
		{
			wrongAnswers[wrongAnswers.length-1] = "4iii";
		}
	}
	
	if(answer4d == "b" || answer4d == "B")
	{
		numWrong = numWrong;
	}
	else
	{
		numWrong = numWrong + 10;
		if(wrongAnswers[wrongAnswers.length-1] != " ")
		{
			wrongAnswers[wrongAnswers.length] = "4iv";
		}
		else
		{
			wrongAnswers[wrongAnswers.length-1] = "4iv";
		}
	}
	
	if(answer4e == "a" || answer4e == "A")
	{
		numWrong = numWrong
	}
	else
	{
		numWrong = numWrong + 10;
		if(wrongAnswers[wrongAnswers.length-1] != " ")
		{
			wrongAnswers[wrongAnswers.length] = "4v";
		}
		else
		{
			wrongAnswers[wrongAnswers.length-1] = "4v";
		}
	}
	
	if(answer4f == "e" || answer4f == "E")
	{
		numWrong = numWrong
	}
	else
	{
		numWrong = numWrong + 10;
		if(wrongAnswers[wrongAnswers.length-1] != " ")
		{
			wrongAnswers[wrongAnswers.length] = "4vi";
		}
		else
		{
			wrongAnswers[wrongAnswers.length-1] = "4vi";
		}
	}
	
	if(answer5a != "3")
	{
		numWrong = numWrong + 2;
		if(wrongAnswers[wrongAnswers.length-1] != " ")
		{
			wrongAnswers[wrongAnswers.length] = "5 #1";
		}
		else
		{
			wrongAnswers[wrongAnswers.length-1] = "5 #1";
		}
	}
	
	if(answer5b != "4")
	{
		numWrong = numWrong + 2;
		if(wrongAnswers[wrongAnswers.length-1] != " ")
		{
			wrongAnswers[wrongAnswers.length] = "5 #2";
		}
		else
		{
			wrongAnswers[wrongAnswers.length-1] = "5 #2";
		}
	}
	
	if(answer5c != "1")
	{
		numWrong = numWrong + 2;
		if(wrongAnswers[wrongAnswers.length-1] != " ")
		{
			wrongAnswers[wrongAnswers.length] = "5 #3";
		}
		else
		{
			wrongAnswers[wrongAnswers.length-1] = "5 #3";
		}
	}
	
	if(answer5d != "2")
	{
		numWrong = numWrong + 2;
		if(wrongAnswers[wrongAnswers.length-1] != " ")
		{
			wrongAnswers[wrongAnswers.length] = "5 #4";
		}
		else
		{
			wrongAnswers[wrongAnswers.length-1] = "5 #4";
		}
	}
	
	if(answer5e != "5")
	{
		numWrong = numWrong + 2;
		if(wrongAnswers[wrongAnswers.length-1] != " ")
		{
			wrongAnswers[wrongAnswers.length] = "5 #5";
		}
		else
		{
			wrongAnswers[wrongAnswers.length-1] = "5 #5";
		}
	}
	
	createCookie("NumberWrong", numWrong, "" , "");
	createCookie("WrongAnswerListLength", wrongAnswers.length, "" , "");
	createCookie("WrongAnswerList", wrongAnswers, "" , "");
	d.location.href="evaluation.html";
}


function openNewWindow(url)
{
	window.open(url, "newWindow");
}


function closeNewWindow()
{
	this.window.close();
}


function createCookie(name, value, path, expires)
{
	value = escape(value);

	if(value == "")
	{
		var nowDate = new Date();
		nowDate.setSeconds(nowDate.getSeconds() + 10);
		expires = nowDate.toGMTString();
	}

	if(path != "")
	{
		path = ";Path=" + path;
	}
	d.cookie = name + "=" + value + ";expires =" + expires + path;
}


function getCookieValue(name)
{
	var value = d.cookie;
	var cookieStart = value.indexOf(" " + name + "=");
	if (cookieStart == -1)
	{
		cookieStart = value.indexOf((name) + "=");
	}

	if(cookieStart == -1)
	{
		value = null;
	}
	
	else
	{
		cookieStart = value.indexOf("=", cookieStart) + 1;
		var cookieEnd = value.indexOf(";", cookieStart);
		if(cookieEnd == -1)
		{
			cookieEnd = value.length;
		}
		value = unescape(value.substring(cookieStart, cookieEnd));
	}
	return value;
}

function writeResults()
{
	if (!getCookieValue("NumberWrong"))
	{
		
	}
	else
	{
		var numWrong = getCookieValue("NumberWrong");
		var score = 100-numWrong;
		var numWrongAnswers = getCookieValue("WrongAnswerListLength");
		var wrongAnswers = getCookieValue("WrongAnswerList");
		wrongAnswers = wrongAnswers.split(',');
		
		if(numWrong >= 90 && numWrong < 100)
		{
			if(numWrong > 90)
			{
				d.write("<p>You received " + (100-numWrong)/10 + " points out of 10 on this exam for a score of " + score + "%.</p>");
			}
			else
			{
				d.write("<p>You received 1 point out of 10 on this exam for a score of 10%.</p>");
			}
		}
		if(numWrong == 100)
		{
			d.write("<p>You received 0 points out of 10 on this exam for a score of 0%.</p>");
		}
		if(numWrong < 90 && numWrong > 10)
		{
			d.write("<p>You received " + (100-numWrong)/10 + " points out of 10 on this exam for a score of " + score + "%.</p>");
		}
	
		if(numWrong <= 10)
		{
			d.write("<p>You&#8217;re an expert!  You should be able to find the drug information you need with ease.</p><p>");
		}
		else if(numWrong >10 && numWrong <=50)
		{
			d.write("<p>Congratulations! You have an understanding of how to formulate your questions and what resources may be appropriate for your search.  You will be able to find your information more quickly as you use the resources more.</p><p>");
		}
		else
		{
			  d.write("<p>You should review the <a href='/howto/drugs/material/index.html'>&#8220;Drug Resources&#8221;</a> section, and then practice using the resources to gain more familiarity with them.</p><p>");
		}
			
		if(wrongAnswers[0] != ' ')
		{
			if(wrongAnswers[0] != "undefined")
			{	
				for(y = 0; y < numWrongAnswers; y++)
				{
					d.write("You missed question " + wrongAnswers[y]  + ".<br />");
				}
				d.write("</p><p>If you wish, you may <a href='/howto/drugs/summary/selftest.html'>retake the exam</a>, or review the <a href='/howto/drugs/material/index.html'>&#8220;Drug Resources&#8221;</a> section and take the exam again at a later time.</p>");
			}
		}
	}
}

// End script for Drug Information tutorial
//-->