// JavaScript Document

function getXMLHttp()
{
	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;
			}
		}
	}
	return xmlHttp;
}

var totalResources;

function runSearch()
{
	if (originalText == null)
		originalText = document.getElementById('content').innerHTML;
	if (document.getElementById('searchfield').value=="")
	{
		document.getElementById('content').innerHTML=originalText;
	}
	else
	{
		document.getElementById('content').innerHTML="<h1>Search results for "+document.getElementById('searchfield').value+"</h1><table width='100%' border='0' cellspacing='0' cellpadding='0'><tr><td valign='top' width='350'><div id='searchresults'><p>Now searching "+totalResources+" resources...</p></div></td><td class='resourceviewer' valign='top' onmouseover='window.clearTimeout(windowTimeout);'><div id='resourceviewer'><h2>Rating Guide for Game Making Resources</h2><p>This rating guide shows you what each rating (between 1 and 5) should be used for.  The rating system doesn't require you to login, but your IP address is logged, so please don't abuse the system.  To show this guide again, just search for something else and it will appear in this location again.  <b>Remember the rating system is for how useful a resource is for everyone, not just yourself and your current project.</b></p><table border='0' cellpadding='0' cellspacing='10'><tr><td valign='top'><img src='/struct/5but.gif' width='16' height='16' /></td><td valign='top'>This should indicate an excellent, complete resource.  For extensions and examples, it should contain details on how to use it, and for sprites it should cover all or most of the areas it was designed for.</td></tr><tr><td valign='top'><img src='/struct/4but.gif' width='16' height='16' /></td><td valign='top'>This should indicate an almost complete, but still an excellent resource.  For extensions and examples, the resource might be lacking a few minor features, and for sprites it might leave out a few unusual stances (for character sheets).</td></tr><tr><td valign='top'><img src='/struct/3but.gif' width='16' height='16' /></td><td valign='top'>This should indicate an average resource, either in quality or how complete it is.  For extensions and examples, the resource might be lacking a few critical features, and for sprites it might leave out a few common stances (for character sheets).</td></tr><tr><td valign='top'><img src='/struct/2but.gif' width='16' height='16' /></td><td valign='top'>This should indicate an poor resource, either in quality or how complete it is.  The resource could be buggy (for extensions) or of very poor quality for sprites and sounds.</td></tr><tr><td valign='top'><img src='/struct/1but.gif' width='16' height='16' /></td><td valign='top'>This should be reserved for resources that are listed that have links that are no longer working or are of no useful value to <i>anybody</i>.</td></tr></table><h2>Searching Guide for Game Making Resources</h2><p>Did you know you can use our search just like Google's?  You can make queries such as '3d OR extension' (either item is found), '3d AND extension' (both items are found; default), '+3d +extension -physics' (find items with 3d and extension, but without physics), '\"3d extension\"' (find the string '3d extension' in order).  Have fun!</p></div></td></tr></table>";
		xmlHttp=getXMLHttp()
		xmlHttp.onreadystatechange=function()
		{
			if(xmlHttp.readyState==4)
			{
				document.getElementById('searchresults').innerHTML=xmlHttp.responseText;
			}
		}
		xmlHttp.open("GET","fetch.php?mode=search&search="+document.getElementById('searchfield').value,true);
		xmlHttp.send(null);
	}
}

function rate(id,rating)
{
	document.getElementById('ratebox').innerHTML="RATING...";
	xmlHttp=getXMLHttp()
	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
		{
			document.getElementById('ratebox').innerHTML="RATED";
		}
	}
	xmlHttp.open("GET","fetch.php?mode=rate&id="+id+"&rating="+rating,true);
	xmlHttp.send(null);
}

function rateover(rating)
{
	if (rating=="1")
	{
		document.getElementById('rateboxdesc').innerHTML="This should be reserved for resources that are listed that have links that are no longer working or are of no useful value to <i>anybody</i>.";
	}
	else if (rating=="2")
	{
		document.getElementById('rateboxdesc').innerHTML="This should indicate an poor resource, either in quality or how complete it is.  The resource could be buggy (for extensions) or of very poor quality for sprites and sounds.";
	}
	else if (rating=="3")
	{
		document.getElementById('rateboxdesc').innerHTML="This should indicate an average resource, either in quality or how complete it is.  For extensions and examples, the resource might be lacking a few critical features, and for sprites it might leave out a few common stances (for character sheets).";
	}
	else if (rating=="4")
	{
		document.getElementById('rateboxdesc').innerHTML="This should indicate an almost complete, but still an excellent resource.  For extensions and examples, the resource might be lacking a few minor features, and for sprites it might leave out a few unusual stances (for character sheets).";
	}
	else if (rating=="5")
	{
		document.getElementById('rateboxdesc').innerHTML="This should indicate an excellent, complete resource.  For extensions and examples, it should contain details on how to use it, and for sprites it should cover all or most of the areas it was designed for.";
	}
}

function rateout()
{
	document.getElementById('rateboxdesc').innerHTML="";
}

var queryXMLHttp;
var currentID;
var windowTimeout;
var originalText;
queryXMLHttp=null;
windowTimeout=null;
originalText = null;

function showResource(idd)
{
	windowTimeout=window.setTimeout("switchResources("+idd+");", 100);
}

function switchResources(idd)
{
	if (idd==currentID) return;
	currentID=idd;
	document.getElementById('resourceviewer').innerHTML="<p>Loading...</p>";
	if (queryXMLHttp!=null)
	{
		queryXMLHttp.abort();
		queryXMLHttp=null;
	}
	queryXMLHttp=getXMLHttp()
	queryXMLHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
		{
			document.getElementById('resourceviewer').innerHTML=queryXMLHttp.responseText;
		}
	}
	queryXMLHttp.open("GET","fetch.php?mode=getinfo&id="+idd,true);
	queryXMLHttp.send(null);
}

function checkInput()
{
	obj=document.getElementById('searchfield');
	if (obj.value=="Search Here")
		obj.value="";
	obj.style.fontStyle="normal";
	obj.style.color="#000000";
	//obj.style.paddingBottom="2px";
}

function blurInput()
{
	obj=document.getElementById('searchfield');
	if (obj.value=="")
	{
		obj.value="Search Here";
		obj.style.fontStyle="italic";
		obj.style.color="#CCCCCC";
		//obj.style.paddingBottom="1px";
	}
	else
	{
		obj.style.fontStyle="normal";
		obj.style.color="#000000";
		//obj.style.paddingBottom="2px";
	}
}