function Resize()
{
	//if (this.clientWidth > 200) this.style.width = "200px";
}
/* Call All body[onload] Scripts */
function LoadScripts()
{
	SetContainerHeight();
}

/* Call All body[onresize] Scripts */
function ResizeScripts()
{
	SetContainerHeight();
}

function SetContainerHeight()
{
  	mainCon = document.getElementById("container");


	//I Forget why this is necessary at this point, but it is
	mainCon.style.height = mainCon.clientHeight + "px";
	
	//set it
	if (mainCon.clientHeight < WindowHeight() ) 
	{
    	 mainCon.style.height = (WindowHeight()) + "px";
	}
	
	/* weird code to set #left and #content to #container.clientHeight - #header.clientHeight */
	/* i'm not sure which is more flakey -- doing this via css hacks or this way */
	/* ... tired of css hacks for now */

	var header = document.getElementById("header");
	
	for (var i = 0; i < mainCon.childNodes.length ; i++)
	{
		if (	mainCon.childNodes[i].nodeName == "DIV" &&
				mainCon.childNodes[i].attributes.getNamedItem("id").value != "header" ) 
		{
			mainCon.childNodes[i].style.height = mainCon.clientHeight - header.clientHeight + "px";
		}
	}
 	return;
}

/* 
Grabbed from:
http://blog.agileware.net/index.php/archives/2006/02/21/make-a-page-at-least-100-of-your-browser-height/
*/
function WindowHeight() {
  var height = 0;

	if( typeof( window.innerHeight ) == 'number' ) {
		//Non-IE
		height = window.innerHeight;
	} else if( document.documentElement && document.documentElement.clientHeight ) {
		//IE 6+ in 'standards compliant mode'
		height = document.documentElement.clientHeight;
  } else if( document.body && document.body.clientHeight ) {
		//IE 4 compatible
		height = document.body.clientHeight;   
	}
  
	return parseInt(height);
}

function ShowIRCInfo()
{
	ShowHiddenDiv('ircInfo');	
}

function ShowStory(id, maxStory)
{
	var i, offset;
	var content = document.getElementById('content');
	
	//hide all 
	var tags = content.getElementsByTagName('div');
	for (i=0; i< tags.length; i++)
	{
		if (tags[i].id.substr(0,5) == "story" &&
			tags[i].className.indexOf("storyDiv") != -1	)
			if ((offset = tags[i].className.indexOf('visible')) != -1 )
			{				
				HideDiv(tags[i].id,true);
				tags[i].className = tags[i].className.substr(0,offset) + 
					tags[i].className.substr(offset+7);
			}
	}
	//for (i = 0; i < maxStory ; i++)
	//	document.getElementById('story'+i).style.display = 'none';
	
	var targetDiv = document.getElementById('story'+id);
	ShowHiddenDiv('story' + id);
	targetDiv.className += ' visible';
}

function HideIRCInfo()
{
	HideDiv('ircInfo', true);
}
/* hide div (later: shrink content div?) */
function HideDiv(id, shrink)
{
	var targetDiv = document.getElementById(id);
	var targetHeight = targetDiv.offsetHeight; //for some reason in IE clientHeight == 0

	targetDiv.style.display = "none";
	
	if (shrink) //only shrink on request
	{		
		var container = document.getElementById('container');
		var content = document.getElementById('content');
		var left = document.getElementById('left');
	
		content.style.height = left.style.height = left.clientHeight - targetHeight + "px";
		container.style.height = container.clientHeight - targetHeight + "px";
	}
}

/* show a hidden div in the #content area and expand things downward as necessary */
function ShowHiddenDiv(id)
{
	var targetDiv = document.getElementById(id);
	var contentDiv = document.getElementById('content');
	var containerDiv = document.getElementById('container');
	var leftDiv = document.getElementById('left');
	
	targetDiv.style.display = 'block';
	var targetHeight = targetDiv.offsetHeight;	//for some reason in IE clientHeight == 0
	
	containerDiv.style.height = containerDiv.clientHeight + targetHeight + "px";
	leftDiv.style.height = contentDiv.style.height = 
		contentDiv.clientHeight + targetHeight + "px";	
}

/* there are many cleaner way of doing this */
function GuidelineToggle(activeDiv)
{
	var greeterEl = document.getElementById('greeter');
	var opEl = document.getElementById('op');
	var generalEl = document.getElementById('general');
	var greeterLink = document.getElementById('greeterLink');
	var opLink = document.getElementById('opLink');
	var generalLink = document.getElementById('generalLink');
	
	var content = document.getElementById('content');
	
	document.getElementById("container").style.height="auto";

	/* set everything back to "normal" */
	greeterLink.className = opLink.className = generalLink.className = "";
	generalEl.style.display = greeterEl.style.display = opEl.style.display = "none";

	content.style.height ="1px";
	content.style.height="auto";
	
	/* then show and highlight appropriate elements */
	switch(activeDiv)
	{
		case 'greeter':
			greeterLink.className = "active";
			greeterEl.style.display = "block";
			break;
		case 'general':
			generalLink.className = "active";
			generalEl.style.display = "block";
			break;
		case 'op':
			opLink.className = "active";
			opEl.style.display = "block";
			break;			
	}
	
	SetContainerHeight();
}

/** "Roll's Up" a div by hiding all ps **/
function RollUp(id)
{
	var el = document.getElementById(id);
	if (el.className.indexOf('greyed') < 0) el.className += " greyed";
	
	for (var i = 0; i < el.childNodes.length ; i++)
	{
		if (el.childNodes[i].tagName == "P")
		{
			el.childNodes[i].style.display = "none";
		}
	}
}

/** "Roll's Down" a div by hiding all ps **/
function RollDown(id)
{
	var offset = 0;
	
	var el = document.getElementById(id);
	offset = el.className.indexOf('greyed');
	if ( offset > -1)
	{
		//6 is length of the word "greyed"
		el.className = el.className.substring(0,offset) + el.className.substring(offset+6);
	}
	for (var i = 0; i < el.childNodes.length ; i++)
	{
		if (el.childNodes[i].tagName == "P")
		{
			el.childNodes[i].style.display = "block";
		}
	}
}

function ValidateNick()
{
	if (this.nick.value=="") 
	{
		alert("Please enter a nick (screename) to use in the room.");
		return false;
	} else {
		return true;
	}
}


function ValidateDeadLinkForm()
{
	if (document.forms.deadLinkForm.email.value=="")
	{
		alert("You must include your email address with this report.");
		return false;
	}
	
	return true;
}

function URLVerify(expected)
{
	var i = window.location.href.toUpperCase().indexOf(expected.toUpperCase());
	var ret;
	
	//fail both if not at the beginning of the url, and not in it at all
	if (i == null || i > 10 || i < 0)
	{
		ret = false;
	} else {
		ret = true;
	}
	
	return ret;		
								   
}