var checkIt;

function IsNumeric(sText)
{
	var ValidChars = "0123456789.";
	var IsNumber=true;
	var Char;

	for (i = 0; i < sText.length && IsNumber == true; i++) 
		{ 
		Char = sText.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) 
			{
			IsNumber = false;
			}
		}
	return IsNumber;
}

function trim(s)
{
	while (s.substring(0,1) == ' ')
	{
		s = s.substring(1,s.length);
	}
	while (s.substring(s.length-1,s.length) == ' ')
	{
		s = s.substring(0,s.length-1);
	}
	return s;
}

function cui()
{
	if (checkIt) clearTimeout(checkIt);
	checkIt = setTimeout('hideall_index()',3000);
}

function getObject(loobject)
{
	if (document.getElementById)
	{
		loobject = document.getElementById(loobject);
	}
	else if (document.all)
	{
		loobject = document.all.item(loobject);
	}
	else
	{
		loobject = null;
	}

return loobject;
}

function showit_index(lcwhich , e)
{
	var loobjectbutton = getObject(lcwhich + 'button');
	var loobject = getObject(lcwhich + 'div');
	
	hideall_index();
	cui();

	if (loobject==null || loobjectbutton==null) return;

	loobject.style.display = 'block';
	loobject.style.visibility = 'visible';
	loobject.style.top = loobjectbutton.offsetTop + 30;
	loobject.style.left = loobjectbutton.offsetLeft + 50;
}

function hideall_index()
{
	loobject = getObject('puzzlesdiv');
	if (loobject==null) return;
	loobject.style.display = 'none';
	loobject.style.visibility = 'hidden';
	loobject = getObject('gamesdiv');
	loobject.style.display = 'none';
	loobject.style.visibility = 'hidden';
	loobject = getObject('illusionsdiv');
	loobject.style.display = 'none';
	loobject.style.visibility = 'hidden';
	loobject = getObject('logicdiv');
	loobject.style.display = 'none';
	loobject.style.visibility = 'hidden';
}

// moves BBobjdiv on index.asp
function moveit()
{
	var height = (document.all) ? document.body.clientHeight : window.innerHeight;
	var width  = (document.all) ? document.body.clientWidth : window.innerWidth;
	var myScroll = (document.all) ? document.body.scrollTop : window.pageYOffset;
	var objCSS = getObject('bbobjdiv');
	if (objCSS==null) return;

	oldtop = parseFloat(objCSS.style.top);
	if (oldtop)
	{
	}
	else
	{
	oldtop = 0;
	}

	newtop = (height + myScroll) - 80;

	objCSS.style.top = Math.round(newtop - (newtop - oldtop) * 0.8);
	objCSS.style.left = width - 80;
	objCSS.style.display = 'block';
	objCSS.style.visibility = 'visible';

	setTimeout("moveit()",40);

return;
}

// clears an input field (see games.asp)
function clearit()
{
loobject=getObject('addurl');
if (loobject==null) return;
loobject.value = '';
}

// doesn't seem to be used
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 = "";
	document.cookie = name+"="+value+expires+"; path=/";
}


// use this one - from Show Sudoku
function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setTime(exdate.getTime()+(expiredays*24*3600*1000));
document.cookie=c_name+ '=' +escape(value)+ ((expiredays==null) ? '' : '; expires='+exdate);
}


function lck()
{
	var lnwidth  = ((document.all) ? document.body.clientWidth : window.innerWidth) - 40;
	var lnheight = ((document.all) ? document.body.clientHeight : window.innerHeight) - 200;

	createCookie("width",lnwidth,10);
	createCookie("height",lnheight,10);

return true;
}
