/* Open a new pop up window. */
function popup(URL, NAME, WIDTH, HEIGHT, SCROLL) {
	HEIGHT = HEIGHT + 23;
	WIDTH = WIDTH + 20;
	LEFT = (screen.availWidth - WIDTH) / 2;
	TOP = (screen.availHeight - HEIGHT) / 2;
	window.open (URL, NAME, "width=" + WIDTH + ",height=" + HEIGHT + ",location=no,menubar=no,personalbar=no,resizable=" + SCROLL + ",scrollbars=" + SCROLL + ",left="+LEFT+",top="+TOP+",status=no,toolbar=no");
}

/* Open the game pop up window. */
function gamePopup(GAME, WIDTH, HEIGHT) {
	URL = "game.php?game=" + GAME + "&w=" + WIDTH + "&h=" + HEIGHT;
	WIDTH = 860;	//WIDTH + 35;
	HEIGHT = HEIGHT + 240;
	LEFT = (screen.availWidth - WIDTH) / 2;
	TOP = (screen.availHeight - HEIGHT) / 2;
	window.open (URL, GAME, "width=" + WIDTH + ",height=" + HEIGHT + ",location=no,menubar=no,personalbar=no,resizable=yes,scrollbars=yes,left="+LEFT+",top="+TOP+",status=no,toolbar=no");
}

/* Count the chars entered in FIELD and update in FIELD2 as MAX - the count */
function count_field_chars(FIELD, FIELD2, MAX) {
	FIELD2.value = MAX - FIELD.value.length;
}

/* CONVERT NEWLINES TO <BR> SEQUESNCES. */
function nl_to_br(obj_message) {
	new_message = "";
	for (q=0; q<obj_message.value.length; q++) {
		if ( obj_message.value.charCodeAt(q) == 13 ) {
			new_message += "<br>";
		} else {
			new_message += obj_message.value.charAt(q);
		}	
	}
	obj_message.value = new_message;
}



/* Here is the browser detect stuff I might use. */
var detect = navigator.userAgent.toLowerCase();
var OS,browser,version,total,thestring;

if (checkIt('konqueror'))
{
	browser = "Konqueror";
	OS = "Linux";
}
else if (checkIt('omniweb')) browser = "OmniWeb"
else if (checkIt('opera')) browser = "Opera"
else if (checkIt('webtv')) browser = "WebTV";
else if (checkIt('icab')) browser = "iCab"
else if (checkIt('msie')) browser = "Internet Explorer"
else if (!checkIt('compatible'))
{
	browser = "Netscape Navigator"
	version = detect.charAt(8);
}
else browser = "An unknown browser";

if (!version) version = detect.charAt(place + thestring.length);

if (!OS)
{
	if (checkIt('linux')) OS = "Linux";
	else if (checkIt('x11')) OS = "Unix";
	else if (checkIt('mac')) OS = "Mac"
	else if (checkIt('win')) OS = "Windows"
	else OS = "an unknown operating system";
}

function checkIt(string)
{
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}
