function switch_tabs(tab, starttab) 
{
	if (!starttab)
		starttab = 0;

	var tabs = document.getElementById('tabs').getElementsByTagName('li').length + starttab;
	//switch off all tabs and content
	for (i=starttab; i < tabs; i++) {
		document.getElementById('tab'+(i+1)).className = '';
		document.getElementById('tab'+(i+1)+'_content').style.display = 'none';
	}
	//switch on the selected tab and content
	document.getElementById(tab).className = 'selected';
	document.getElementById(tab+'_content').style.display = 'block';
}


function sfHover()
{
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++)
	{
		sfEls[i].onmouseover=function()
		{
			this.className+=" sfhover";
		};
		sfEls[i].onmouseout=function()
		{
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		};
	}
};

if (window.attachEvent)
	window.attachEvent("onload", sfHover);

function clearLoginDefaults()
{
	usernamebox = document.getElementById("username");
	passwordbox = document.getElementById("password");

	if (usernamebox.defaultValue == usernamebox.value)
		usernamebox.value = "";
	if (passwordbox.defaultValue == passwordbox.value)
		passwordbox.value = "";
}

function clearSearchBox()
{
	searchbox = document.getElementById("searchfield");
	if (searchbox.defaultValue == searchbox.value)
		searchbox.value = "";
}

function doLogin()
{
	document.getElementById("phash").value = MD5(document.getElementById("password").value);
	document.getElementById("password").value = "";
}

function nextPage(tabid, pagenum, search, totpages)
{
	var xmlHttp;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
		{
			document.getElementById("tab" + tabid + "_content").innerHTML = xmlHttp.responseText;
			//alert(xmlHttp.responseText);
		}
	}
	document.getElementById("tab" + tabid + "_content").innerHTML = "<div id='centertext'><img src='images/loading.gif' /> Loading...</div>";
	if (tabid < 4)
		xmlHttp.open("GET","nextpage.php?tab=" + tabid + "&page=" + pagenum,true);
	else
		xmlHttp.open("GET","nextpage.php?tab=" + tabid + "&page=" + pagenum + "&search=" + search + "&totpages=" + totpages,true);
	xmlHttp.send(null);
}

function getSchedule(offset)
{
	var xmlHttp;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
		{
			document.getElementById("schedule").innerHTML = xmlHttp.responseText;
			//alert(xmlHttp.responseText);
		}
	}
	document.getElementById("schedule").innerHTML = "<div class='loading'><img src='images/loading.gif' /> Loading...</div>";
	xmlHttp.open("GET","getschedule.php?offset=" + offset,true);
	xmlHttp.send(null);
}

function popStatic(url,winname,w,h)
{
	win=window.open(url,winname,'toolbar=no,resizable=no,scrollbars=no,status=0,directories=no,width=' + w + ',height=' + h);
	if (!win.opener)
		win.opener=self;
	if (win.focus)
		win.focus();
}
function confirmDelete()
{
	var agree = confirm("Are you SURE you wish to delete?  This CAN NOT be reversed!");
	if (agree)
		return true;
	else
		return false;
}

function getCookie(c_name)
{
	if (document.cookie.length>0)
  	{
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1)
		{ 
			c_start=c_start + c_name.length+1; 
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		} 
	}
}

function setCookie(c_name,value,expiredays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+ ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function SetCookieValue(namea , myval )
{
	var count = getCookie(namea)
	if(count == null)
	{
		setCookie(namea, myval, 30);
		return 1;
	}
	else
	{
		//var newcount = parseInt(count) + 1;
		setCookie(namea, myval, 30);
		return count;
	}
}

/*if (!getCookie("timezone"))
{
	var d = new Date();
	var offset = d.getTimezoneOffset()/60;
	var sPath = window.location.pathname;
	setCookie("timezone", -offset, 1);
	if (sPath == "/allgames/")
		getSchedule();
}*/

