// JavaScript Document

window.onload = changeColor;

function changeColor()
{
	var Table = document.getElementById("WSmainNav");
	var lis = Table.getElementsByTagName("li");

	for(var i=0;i<lis.length;i++)
	{
		lis[i].onmouseover = mouseIn;
		lis[i].onmouseout = mouseOut;
	}
	lis[lis.length-1].onmouseover = imgIn;
	lis[lis.length-1].onmouseout = imgOut;
	document.getElementById("forumSubmit").onclick = getForum;
	thankYouPg();
}

function mouseIn(img)
{
	this.style.backgroundColor = "#ed1c24";
}

function mouseOut(img)
{
	this.style.backgroundColor = "#FBAD17";
}

function imgIn()
{
	document.getElementById("sparks").src = "http://www.awana.org/wheressparky/images/sparksOff.jpg";
	this.style.backgroundColor = "#ed1c24";
}

function imgOut()
{
	document.getElementById("sparks").src = "http://www.awana.org/wheressparky/images/sparks.jpg";
	this.style.backgroundColor = "#FBAD17";
}

function lengthCheck(field)
{
	var charsUsed = document.getElementById(field).value.length
	if(charsUsed <= 500)
	{
		document.getElementById("charLeft").innerHTML = (500-charsUsed)+" characters left";
		document.getElementById("tfa_PictureCaption50-E").innerHTML = "";
		document.getElementById("submit-").disabled = false;
	}
	else if(charsUsed > 500)
	{
		document.getElementById("charLeft").innerHTML = "0 characters left";
		document.getElementById("tfa_PictureCaption50-E").innerHTML = "Too many characthers";
		document.getElementById("submit-").disabled = true;
	}
}
function getForum()
{
	var sparkyNum = Number(document.getElementById("sparkyID").value);
	var urlNum = new Number();

	switch(Math.ceil(sparkyNum/10))
	{
		case 1:
			urlNum =  130;
			break;
		case 2:
			urlNum =  131;
			break;
		case 3:
			urlNum =  132;
			break;
		case 4:
			urlNum =  140;
			break;
		case 5:
			urlNum =  141;
			break;
		case 6:
			urlNum =  142;
			break;
		case 7:
			urlNum =  143;
			break;
		case 8:
			urlNum =  145;
			break;
		case 9:
			urlNum =  146;
			break;
		case 10:
			urlNum =  147;
			break;
		default:
			break;
	}
	
	if(document.getElementById("sparkyID").value == "")
	{
		document.getElementById("sparkyIDerror").innerHTML = "You must enter a number.";
		document.getElementById("sparkyIDerror").style.display = "block";
	}
	else if(sparkyNum > 100)
	{
		document.getElementById("sparkyIDerror").innerHTML = "That is not a valid Sparky number: too high.";
		document.getElementById("sparkyIDerror").style.display = "block";
	}
	else if(sparkyNum < 1)
	{
		document.getElementById("sparkyIDerror").innerHTML = "That is not a valid Sparky number: too low.";
		document.getElementById("sparkyIDerror").style.display = "block";
	}
	else if(isNaN(sparkyNum))
	{
		document.getElementById("sparkyIDerror").innerHTML = "That is not a valid Sparky number: Not a number.";
		document.getElementById("sparkyIDerror").style.display = "block";
	}
	else
	{
		document.getElementById("sparkyIDerror").innerHTML = "";
		document.getElementById("sparkyIDerror").style.display = "none";
		window.location.href = "http://www2.awana.org/cs/forums/"+urlNum+"/ShowForum.aspx"
	}
}

function enterForum(e)
{
	var charCode = (e.which) ? e.which : e.keyCode;

	if(charCode==13)
	{
		getForum();
	}
}

function showPopUp(popup)
{
	var popupState = document.getElementById(popup).style.visibility;
	if(popupState == "hidden")
	{
		document.getElementById(popup).style.visibility = "visible";
	}
	else
	{
		document.getElementById(popup).style.visibility = "hidden";
	}
}

function thankYouPg()
{
	if(window.location.href.indexOf("default.aspx?id=2442") > 0)
	{
		setTimeout("window.location.href='http://www.awana.org/wheressparky'",3000);
	}
}