// JavaScript Document
			
function renderButton(id, destLink, soundFile, graphicNormal, graphicMouseover, altText, extraEvent, width, height)
{
	//Create normal and mouseover images for image/link
	window[id + "_Normal"] = new Image();
	window[id + "_Normal"].src = "images/" + graphicNormal;
	window[id + "_Mouseover"] = new Image();
	window[id + "_Mouseover"].src = "images/" + graphicMouseover;
	
	if (extraEvent==null)
		{extraEvent="";}
	if (width==null)
		{width="120";}
	if (height==null)
		{height="31";}
	
	document.write('<a href="' + destLink + '" ' +
	extraEvent +
	'onFocus="swap(\'' + id + '\', \'' + id + "_Mouseover" + '\'), playRolloverSound(\'' + soundFile + '\')" ' +
	'onMouseOver="swap(\'' + id + '\', \'' + id + "_Mouseover" + '\'), playRolloverSound(\'' + soundFile + '\')" ' +
	'onBlur="swap(\'' + id + '\', \'' + id + "_Normal" + '\'), cancelRolloverSound()" ' +
	'onMouseOut="swap(\'' + id + '\', \'' + id + "_Normal" + '\'), cancelRolloverSound()">' +
	'<img src="images/' + graphicNormal + '" ' +
	'name="' + id + '" ' + 
	'alt="' + altText + '" ' +
	'width="' + width + '" height="' + height + '" border="0" /></a>'); 
}

function renderReplayButton(id, destLink, soundFile, graphicNormal, graphicMouseover, altText, extraEvent, width, height)
{
	//Create normal and mouseover images for image/link
	window[id + "_Normal"] = new Image();
	window[id + "_Normal"].src = "images/" + graphicNormal;
	window[id + "_Mouseover"] = new Image();
	window[id + "_Mouseover"].src = "images/" + graphicMouseover;
	
	if (extraEvent==null)
		{extraEvent="";}
	if (width==null)
		{width="120";}
	if (height==null)
		{height="31";}
	
	document.write('<a href="' + destLink + '" ' +
	extraEvent +
	'onFocus="swap(\'' + id + '\', \'' + id + "_Mouseover" + '\')" ' +
	'onMouseOver="swap(\'' + id + '\', \'' + id + "_Mouseover" + '\')" ' +
	'onBlur="swap(\'' + id + '\', \'' + id + "_Normal" + '\')" ' +
	'onMouseOut="swap(\'' + id + '\', \'' + id + "_Normal" + '\')">' +
	'<img src="images/' + graphicNormal + '" ' +
	'name="' + id + '" ' + 
	'alt="' + altText + '" ' +
	'width="' + width + '" height="' + height + '" border="0" /></a>'); 
}
	
function swap()
{
	try
	{
		if (document.images)
		{
			for (var x=0;x<swap.arguments.length;x+=2)
				{document[swap.arguments[x]].src = eval(swap.arguments[x+1] + ".src");}
		}
	}
	catch (err)
		{ return;}
}

function loginCheck()
{
	if (readCookie('KIM_LO') != null)
		{window.location.href = "LO_welcome.html";}
}
			
function writeLogin(name)
{
	if (name == "")
	{
		alert ("Please enter a first name or nickname.");
		return false;
	}
	else
	{
		createCookie("KIM_LO",name,"7");
		createCookie("KIM_BOARD","null","7");
		createCookie("KIM_SCORE","0","7");
	}
}

function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	
	var valueString = value + "";
	valueString = valueString.replace(/ /g,"%32");
	valueString = valueString.replace(/,/g,"%44");

	var cookieInfo = name+"="+valueString+expires+"; path=/";
	document.cookie = cookieInfo;
}

function appendCookie(name,value,days)
{
	var boardStatus = readCookie(name);
	createCookie(name, boardStatus + "%44" + value, days);
}

function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0)
		{
			var cookieInfo=c.substring(nameEQ.length,c.length);
			cookieInfo = cookieInfo.replace(/%32/g," ");
			cookieInfo = cookieInfo.replace(/%44/g,",");
			return cookieInfo;
		}
	}
	return null;
}

function eraseCookie(name)
{
	createCookie(name,"",-1);
}

function eraseAllCookies()
{
	createCookie("KIM_BOARD","",-1);
	createCookie("KIM_SCORE","0",7);
	createCookie("KIM_LO","",-1);
	createCookie("KIM_QUESTION","0",7);
	window.location.href = "main.html";
	
}

function renderNarrationState()
{
	if (readCookie('KIM_SND') != 0)
		{document.write('on.');}
	else
		{document.write('off.');}
}