//
//								main
//

// ultra-simpy browser detect
g_MSIE = document.all ? true : false;

var g_standalone;
var g_session;
var LAYOUT_POLL_DELAY = 500;
var g_width = -1;
var g_height = -1;

var g_currentTopic = -1;
var legal = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-+=@.!#";

//
//								initForum
//
function initForum()
{
	// see if we're standalone or embedded
	var myName = window.name;
	var parentName;
	try
	{
		// if we're embedded in a 3rd party window we'll fail to fetch the parent name
		parentName = window.parent.name;
	}
	catch( e ) {}

	// if window names match, we're really floating standalone
	g_standalone = myName == parentName;

	// determine username
	if( forumUsername.length == 0 )
	{
		forumUsername = 'guest';
	}

	// display username
	var obj = document.getElementById( 'idforumusername' );
	obj.innerHTML = forumUsername + "&nbsp;&nbsp";

	// set login/logout button appropriately
	obj = document.getElementById( 'btnlogin' );
	obj.innerHTML = forumUsername == 'guest' ? 'login' : 'logout';

	// set forum title
	obj = document.getElementById( 'idforumtitle' );
	obj.innerHTML = forumTitle;

	// set initial button states
	enableButton( 'btnhome', false );
	enableButton( 'btnpost', true );
	enableButton( 'btnreply', false );
	enableButton( 'btnsearch', true );
	enableButton( 'btnprof', true );
	enableButton( 'btnadmin', forumAdmin );
	enableButton( 'btnlogin', true );

	// decide whether to display the description
	if( g_standalone && forumDescription )
	{
		obj = document.getElementById( 'iddescrow' );
		if( obj )
		{
			obj.style.display = g_MSIE ? 'block' : 'table-row';
		}
		obj = document.getElementById( 'iddescription' );
		if( obj )
		{
			obj.innerHTML = processHtmlTags( forumDescription );
		}
	}

	// remember our session ID
	g_session = sessionID;

	// load start page
	document.getElementById( 'idfrm' ).src = startPage;
}


//
//								pollResize
//
//	Watch for changes in vertical size of body and width of containing div.
//
function pollResize()
{
	var delay = LAYOUT_POLL_DELAY;
	var b = document.body;
	if( b.offsetWidth != g_width
	 || b.offsetHeight != g_height )
	{
		delay = layout();
	}	
	setTimeout( "pollResize()", delay );
}


//
//						btnEnter
//
function btnEnter( obj )
{
	if( obj.className != 'buttondisabled' )
	{
		obj.className = 'buttonhover';
	}
}

//
//						btnLeave
//
function btnLeave( obj )
{
	if( obj.className != 'buttondisabled' )
	{
		obj.className = 'button';
	}
}

//
//						btnClick
//
function btnClick( obj )
{
	if( obj.className != 'buttondisabled' )
	{
		switch( obj.id )
		{
		case 'btnhome':
			document.location.href = 'index.html';
			break;	
		case 'btnpost':
			document.location.href = 'newtopic.html';
			break;
		case 'btnreply':
			document.location.href = 'reply.html?topicid=' + g_currentTopic;
			break;
		case 'btnsearch':
			document.location.href = 'search.html';
			break;
		case 'btnadmin':
			document.location.href = 'admin.html';
			break;
		case 'btnprof':
			document.location.href = 'myprofile.html';
			break;
		case 'btnlogin':
			document.location.href = obj.innerHTML == 'login'
				? 'login.html'
				: 'logout.html';
			break;
		}
	}
}


//
//								getHostUrl
//
//	Returns the base url of the forum
//
function getHostUrl()
{
	var url = location.href;
	var slash = url.indexOf( ".minuteboard.com" );
	if( slash > 0)
	{
		url = url.substring(0, slash + 16);
	}
	return url;
}

//
//								reload
//
//	Reload the current outer frame.
//
function reload()
{
	document.location.reload();
}

//
//								newUser
//
//	Used on login.html page, toggles visibility of new user fields when 
//	the 'new user' checkbox is clicked
//
function newUser()
{
	var rb = document.getElementsByName( "rbnewuser" );
	var disp = "none";
	if( rb[0].checked )
	{
		// IE and Mozilla use different versions, probably Mozilla's is W3C approved
		disp = g_MSIE ? "block" : "table-row";
	}

	document.getElementById( "idconfirmrow" ).style.display = disp;
	document.getElementById( "idemailrow" ).style.display = disp;
}

//
//								onLoginSubmit
//
//	Does basic client side validation and then submits the new forum data for processing.
//
function onLoginSubmit()
{
	// get the field
	var TAB = "\t";
	var username = document.getElementById( "idusername" ).value;
	var rb = document.getElementsByName( "rbnewuser" )[0].checked;
	var password = document.getElementById( "idpassword" ).value;
	var confirm = document.getElementById( "idconfpassword" ).value;
	var email = document.getElementById( "idemail" ).value;

	// get the hosting page from the parent frame
	var hosturl = getHostUrl();

	// poke it into the hidden form field
	var obj = document.getElementById( 'idhosturl' );
	obj.value = hosturl;

	// sanity check the user inputs
	return validateLoginForm( username, rb, password, confirm, email );
}

//
//						validateLoginForm
//
function validateLoginForm( name, newUser, pass, confPass, email )
{
	// check the username
	if( !checkUsername( name ) )
	{
		return false;
	}

	// make sure they provide a password
	if( pass.length == 0 )
	{
		alert( "You must provide a password." );
		return false;
	}

	// check password for legal chars
	for( i = 0; i < pass.length; i++ )
	{
		var s = pass.substr( i, 1 );
		if( legal.indexOf( s ) == -1 )
		{
			alert( "Illegal character in password: " + pass.charAt(i) + "\nYour password can contain letters, numbers, and the characters _-+=@.!#" );
			return false;
		}
	}

	// make sure passwords match
	if( newUser )
	{
		if( pass != confPass )
		{
			alert( "Password confirmation does not match original.  Try again." );
			return false;
		}

		// make sure email addr is provided, so ultra simply sanity checks on it
		if( email.length == 0 )
		{
			alert( "You must provide an email address so we can email you the information about your new discussion board." );
			return false;
		}
		if( email.length < 6 
		 || email.indexOf("@") == -1 
		 || email.indexOf(".")  == -1 
		 || email.indexOf(",") != -1
		 || email.indexOf(";") != -1
		)
		{
			alert( "That does not appear to be a valid email address. You must provide an email address so we can email you the information about your new discussion board." );
			return false;
		}
	}

	return true;
}

//
//						checkUsername
//
//	Returns true is all goes well.
//
function checkUsername( name )
{
	// check the username
	if( name.length < 2 )
	{
		alert( "The username must be at least two characters long." );
		return false;
	}
	if( name.length > 31 )
	{
		alert( "The username must be 31 characters or less in length." );
		return false;
	}

	// check username for legal chars
	for( i = 0; i < name.length; i++ )
	{
		var s = name.substr( i, 1 );
		if( legal.indexOf( s ) == -1 )
		{
			alert( "Illegal character in username: " + name.charAt(i) + "\nThe username can contain only letters, numbers and the characters _-+=@.!#" );
			return false;
		}
	}
	return true;
}

//
//						onNewTopicPreview
//
function onNewTopicPreview()
{
	// open a new window to show the preview
	var newwin = window.open( "preview.html?mode=newtopic", 
		"preview", 
		"width=500,height=400,resizable=1,scrollbars=1,menubar=0,toobar=0" );
	newwin.focus();
}

//
//						onNewTopicSubmit
//
function onNewTopicSubmit()
{
	// get the two fields
	var title = document.getElementById( 'idtopictitle' ).value;
	var body = document.getElementById( 'idtopicbody' ).value;

	// basic sanity checks
	if( title.length == 0 )
	{
		alert( "You must provide a title for your post." );
		return false;
	}
	if( body.length > 32000 )
	{
		alert( "The message should be less than 32000 characters in length." );
		return false;
	}

	return true;
}

//
//						onReplyPreview
//
function onReplyPreview()
{
	// open a new window to show the preview
	var newwin = window.open( "preview.html?mode=reply", 
		"preview", 
		"width=500,height=400,resizable=1,scrollbars=1,menubar=0,toobar=0" );
	newwin.focus();
}

//
//						onReplyAttachImage
//
function onReplyAttachImage()
{
	// open a new window to show the preview
	var newwin = window.open( "uploadimage.html?maxx=600&maxy=600&thumb=yes",
		"upload", 
		"width=400,height=150,resizable=1,scrollbars=1,menubar=0,toobar=0" );
	newwin.focus();
}


//
//						onReplySubmit
//
function onReplySubmit()
{
	// get the one field
	var body = document.getElementById( 'idtopicbody' ).value;

	// basic sanity checks
	if( body.length == 0 )
	{
		alert( "You must provide some text in your reply message." );
		return false;
	}
	if( body.length > 32000 )
	{
		alert( "The message should be less than 32000 characters in length." );
		return false;
	}

	return true;
}


//
//						drawMessages
//
//	Called to display all message for a topic from showtopic.html
//
//	If fPreview flag is set, assumes it's just previewing a single message for
//	the newtopicpreview.html or replypreview.html pages.
//
function drawMessages( fPreview )
{
	// first do main layout
	myLayout();

	// draw the topic
	var FIELDS = 6;
	var sHTML = '';
	var obj = document.getElementById( "idtopic" );

	sHTML += "<div class='tableheader f16b' style='padding:4px'>" + topicsubject + "</div><br>";
	var i;
	var numMessages = Math.floor( aMessages.length / FIELDS );

	sHTML += "<table class=f14 cellpadding=4 cellspacing=0 width='100%'>";
	for( i = 0; i < numMessages; i++ )
	{
		var idx = i * FIELDS;
		var msgid = 		aMessages[idx++] / 1;
		var created = 		aMessages[idx++];
		var username = 		aMessages[idx++];
		var userimageid = 	aMessages[idx++] / 1;
		var msgbody = 		aMessages[idx++];
		var imagecode = 	aMessages[idx++] / 1;

		// format the body text
		msgbody = processHtmlTags( msgbody );

		// make sure date doesn't wrap in ugly manner
		created = created.replace( /\s+/g, '&nbsp;' );

		// draw the message
		sHTML += "<tr><td class=msgleft width='1%'><div class=f11>" + created + "</div><a href='profile.html?u=" + username + "'>" + username + "</a>";
		if( userimageid )
		{
			sHTML += "<br><a href='" + getImagePath( userimageid ) + "' target=_blank><img src='" + getImagePath( userimageid ) + "t' border=0></a>";
		}
		if( i == (numMessages-1) )
		{
			// add #name to scroll reply form to
			sHTML += '<a name=replyform></a>';
		}
		sHTML += "<td class=msgright>" + msgbody;

		// see if we have an image
		if( imagecode )
		{
			sHTML += "<p class=f11>Attached image:<br><a href='" + getImagePath( imagecode ) + "' target=_blank><img src='" + getImagePath( imagecode ) + "t' border=0 title='click to enlarge'></p><br>";
		}

		// if not in preview mode and we're an admin, add the Delete button
		if( i != 0 && !fPreview && fAdmin )
		{
			sHTML += "<br><input type=button class=tinybutton onclick='removeMessage(" + msgid + ")' value=Delete>";
		}

		// add one dummy nbsp to make sure the cell draws
		sHTML += '&nbsp';

		// spacer liner
		sHTML += "<tr><td height=6>";
	}

	sHTML += "</table>";

	// if previewing, add a gratuitous Close button
	if( fPreview )
	{
		sHTML += "<center><input type=button onclick='window.close()' value='Close'></center>";
	}
	obj.innerHTML = sHTML;
}

//
//						onHtmlCodeSelect
//
//	Called from the htmlcode.html page, this fully select the text in a given
//	text area for cut and paste.
//
function onHtmlCodeSelect( obj )
{
	obj.select();
}

//
//						onAdminSubmit
//
//	Called from admin.html to validate admin config data.
//
function onAdminSubmit()
{
	// check title
	var obj = document.getElementById( 'idtitle' );
	var title = obj.value;
	if( title.length == 0 )
	{
		alert( "Your discussion forum much have a title." );
		return false;
	}

	// check hosturl
	var obj = document.getElementById( 'idhosturl' );
	var hosturl = obj.value;
	if( hosturl.length != 0 && hosturl.indexOf( "http://" ) != 0 )
	{
		alert( "The host URL must start with http://" );
		return false;
	}

	return true;
}

//
//						getPreviewBody
//
//	Called from preview.html
//
function getPreviewBody()
{
	return document.getElementById( 'idtopicbody' ).value;
}

//
//						getPreviewTitle
//
//	Called from preview.html
//
function getPreviewTitle()
{
	return document.getElementById( 'idtopictitle' ).value;
}

//
//						getPreviewImage
//
function getPreviewImage()
{
	return document.getElementById( 'idimage' ).value;
}

//
//						escapeHTML
//
//	Replaces &, <, and > with amper escapes.
//
function escapeHTML( sHTML )
{
	sHTML = sHTML.replace( /&/g, '&amp;' );
	sHTML = sHTML.replace( />/g, '&gt;' );
	sHTML = sHTML.replace( /</g, '&lt;' );
	return sHTML;
}

//
//						onNewTopicAttachImage
//
function onNewTopicAttachImage()
{
	// open a new window to show the preview
	var newwin = window.open( "uploadimage.html?maxx=600&maxy=600&thumb=yes",
		"upload", 
		"width=400,height=150,resizable=1,scrollbars=1,menubar=0,toobar=0" );
	newwin.focus();
}

//
//						attachImage
//
function attachImage( code )
{
	// set the form fields which contain the attached image info
	var obj = document.getElementById( 'idimage' ).value = code;

	// see if we can update an in-place image
	obj = document.getElementById( 'idimg' );
	if( obj != null )
	{
		obj.src = getImagePath( code ) + 't';
	}
}

//
//						getImagePath
//
//	Converts image code to web path.
//
function getImagePath( code )
{
	var dir1 = '000' + Math.floor( code / 1000000 );
	var dir2 = '000' + Math.floor( code / 1000 );
	var img = '000' + (code % 1000);
	dir1 = dir1.substr( dir1.length - 3 );
	dir2 = dir2.substr( dir2.length - 3 );
	img = img.substr( img.length - 3 );
	return '/images/' + dir1 + '/' + dir2 + '/' + img;
}

//
//						onProfilePreview
//
function onProfilePreview()
{
	// open a new window to show the preview
	var newwin = window.open( "profileprev.html", 
		"preview", 
		"width=500,height=400,resizable=1,scrollbars=1,menubar=0,toobar=0" );
	newwin.focus();
}


// public var shared by tagReplace and processHtmlTags
var bNoBreak;

//
//						processHtmlTags
//
function processHtmlTags( sHTML )
{
	// first splint into lines
	var aLines = sHTML.split( '\n' );

	var bInTable = false;
	var i;
	var sOut = '';
	var re;

	for( i = 0; i < aLines.length; i++ )
	{
		bNoBreak = false;
		sHTML = aLines[i];

		// first harvest any URLs (can't do inline replacement because regexp pattern matching keeps
		// tripping over newly installed URLs otherwise)
		var urls = new Array();
		//re = /\bhttp:\/\/([a-z,A-Z,0-9]{2,}\.[a-z,A-Z,0-9\_\/\?\&\-\.\%]+)/;
		re = /\bhttp:\/\/([a-z,A-Z,0-9]{2,}\.[^\s\n]+)/;
		var cnt = 0;
		var htmlTmp = sHTML;
		while( htmlTmp.match( re ) )
		{
			// look for img tag before this
			var off = htmlTmp.indexOf( RegExp.$1 );
			var match = RegExp.$1;
			if( off >= 12 && htmlTmp.substr( off - 12, 5 ) == '[img]' )
			{
				htmlTmp = htmlTmp.substr( off );
				continue;
			}

			// add to list of URLs to replace
			urls[urls.length] = RegExp.$1;
			sHTML = sHTML.replace( re, "_&URL" + cnt + "&_" );
			htmlTmp = htmlTmp.substr( off );
			cnt++;
		}

		// now go back thru and swap in the real URLs snippets
		var j;
		for( j = 0; j < urls.length; j++ )
		{
			re = new RegExp( '_&URL' + j + '&_' );
			var urlsnippet = "<a href='http://" + urls[j] + "' target=_blank>" + urls[j] + "</a>";
			sHTML = sHTML.replace( re, urlsnippet );
		}

		// do smile, frown, and tongue out
		sHTML = sHTML.replace( /:\)/g, '<img src="/i/smile.png">' );
		sHTML = sHTML.replace( /:\-\)/g, '<img src="/i/smile.png">' );

		sHTML = sHTML.replace( /:\(/g, '<img src="/i/frown.png">' );
		sHTML = sHTML.replace( /:\-\(/g, '<img src="/i/frown.png">' );

		sHTML = sHTML.replace( /:p/gi, '<img src="/i/tongue.png">' );
		sHTML = sHTML.replace( /:\-p/gi, '<img src="/i/tongue.png">' );

		// now look for list
		if( sHTML.charAt(0) == '*' )
		{
			sHTML = '<li>' + sHTML.substr(1) + '</li>';
			bNoBreak = true;
		}
        // do our own handy _bold_ words
        re = /\b_([^_]+)_\b/g;
        sHTML = sHTML.replace( re, "<b>$1</b>" );

        // and do handy ~italics~ words
        re = /(^|[\s]+)(\~)([^\~]+)(\~)([\s\.\?\!]+)/g;
        sHTML = sHTML.replace( re, "<em>$1$3$5</em>");

		// proc the phpbb [tags]
		re = /\[([^\]]+)\]/gi;
		sHTML = sHTML.replace( re, tagReplace );
		
		// finally, proc tables
		if( sHTML.charAt(0) == '|' )
		{
			bNoBreak = true;
			if( !bInTable )
			{
				sHTML = '<table class=f14><tr>' + sHTML;
			}
			else
			{
				sHTML = '<tr>' + sHTML;
			}
			bInTable = true;

			sHTML = sHTML.replace( /\|/g, '<td class=bgtinted>' );
		}
		else
		{
			if( bInTable )
			{
				sHTML = '</table>' + sHTML;
			}
			bInTable = false;
		}
		if( !bNoBreak )
		{
			sHTML += '<br>';
		}

		// finally add to output string
		sOut += sHTML;
	}

	// make sure we close out the table
	if( bInTable )
	{
		sOut += '</table>';
	}

	return sOut;
}

// phpbb tags we recognize
var aTags = new Array();
aTags['b'] 		= '<b>';
aTags['/b'] 	= '</b>';
aTags['i'] 		= '<i>';
aTags['/i'] 	= '</i>';
aTags['em'] 	= '<em>';
aTags['/em'] 	= '</em>';
aTags['li'] 	= '<li>';
aTags['/li'] 	= '</li>';
aTags['quote'] 	= '<blockquote class=bgtinted style="margin-bottom:4px"><em>';
aTags['/quote']	= '</em></blockquote>';
aTags['small'] 	= '<small>';
aTags['/small']	= '</small>';
aTags['big'] 	= '<big>';
aTags['/big']	= '</big>';
aTags['img']	= '<img src="';
aTags['/img']	= '">';

//
//						tagReplace
//
//	Handles the phpbb tag substitution
//
function tagReplace( a, b )
{
	b = b.toLowerCase();
	if( b == 'li' || b == '/li' || b == 'quote' || b == '/quote' )
	{
		// skip appending the <br> to this line, it's already getting a break
		bNoBreak = true;
	}
	var ret = aTags[b];
	if( ret == null )
	{
		// not a recognized tag, just literal it
		ret = '[' + b + ']';
	}
	return ret;
}

//
//						removeTopic
//
function removeTopic( code )
{
	var obj = document.getElementById( 'idtitle' + code );
	var title = 'nope';
	if( obj )
	{
		title = obj.innerHTML;
	}
	var fDelete = confirm( 'Are you sure you want to remove the topic "' + title + '"?' );
	if( fDelete )
	{
		document.location.href = 'removetopic.html?topicid=' + code + '&start=' + curTopicNum;
	}
}

//
//						removeMessage
//
function removeMessage( code )
{
	alert( 'removeMessage: ' + code );
	var fDelete = confirm( 'Are you sure you want to remove this message?' );
	if( fDelete )
	{
		document.location.href = 'removemessage.html?msgid=' + code;
	}
}


//
//						openHelp
//
//	Opens a spec'd help page in a small window
//
function openHelp( url )
{
	// open a new window to show the preview
	var newwin = window.open( url,
		"help", 
		"width=400,height=400,resizable=1,scrollbars=1,menubar=0,toobar=0" );
	newwin.focus();
}

//
//						replyOnload
//
//	Called from reply.html onload event
//
function replyOnload()
{
	// draw prev messages in thread
	drawMessages( false );

	// now jump to tricky hidden #name
	setTimeout( "document.getElementById( 'idreplyjump' ).click()", 200 );
}

//
//						onThemeChange
//
//	Called from admin.html when user selects new theme.  We decide whether to show/hide the
//	custom attributes
//
function onThemeChange( obj )
{
    // find idiom for saying "display row"
    var disp = g_MSIE ? "block" : "table-row";

	// see if select says we're doing custom
	disp = obj.value == 'Custom' ? disp : 'none';

    // set all the custom fields
    var aFields = document.getElementsByName( 'customfield' );
    var i;
    for( i = 0; i < aFields.length; i++ )
    {
        aFields[i].style.display = disp;
    }
}

//
//						checkThemeColor
//
function checkThemeColor( obj )
{
	obj.style.color = isValidHexColor( obj.value ) ? 'black' : 'red';
}

//
//						isValidHexColor
//
function isValidHexColor( c )
{
	var i;
	var hex = '01234567890abcdef';

	// check for valid color length
	if( c.length != 6 )
	{
		return false;
	}

	// make sure all chars are hex digits
	c = c.toLowerCase();
	for( i = 0; i < c.length; i++ )
	{
		if( hex.indexOf( c.charAt(i) ) == -1 )
		{
			return false;
		}
	}

	// looks good
	return true;
}

//
//						onAdminThemeSubmit
//
function onAdminThemeSubmit()
{
	// if not doing Custom, skip validation
	if( document.getElementById( 'idtheme' ).value != 'Custom' )
	{
		return true;
	}

	// check all the color values
	var aFields = document.getElementsByTagName( 'input' );
	var i;
	var bError = false;
	for( i = 0; i < aFields.length; i++ )
	{
		var obj = aFields[i];
		if( obj.type != 'text' )
		{
			continue;
		}
		if( isValidHexColor( obj.value ) )
		{
			obj.style.color = 'black';	
		}
		else
		{
			if( obj.value.length == 0 )
			{
				obj.value = '(null)';
			}
			obj.style.color = 'red';
			bError = true;
		}
	}

	// we have an error in the hex color value fields, block submission
	if( bError )
	{
		alert( "Check your color fields.  All fields must be a valid 6 digit hex color value.  Click the help button to the right of the field to learn more about legal hex color values." );
		return false;
	}

	// if we're updating a custom theme, aggregate all the custom values into a single hidden field
	if( document.getElementById( 'idtheme' ).value == 'Custom' )
	{
		var custom = '';
		custom += document.getElementsByName( 'themefont' )[0].value + ';';
		custom += document.getElementsByName( 'themefontsize' )[0].value;
		aFields = document.getElementsByTagName( 'input' );
		for( i = 0; i < aFields.length; i++ )
		{
			if( aFields[i].type != 'text' )
			{
				continue;
			}
			custom += ';' + aFields[i].value;
		}
		document.getElementsByName( 'customtheme' )[0].value = custom;
	}

	// allow form to be submitted
	return true;
}

//
//						grabFocus
//
function grabFocus()
{
	alert( "grab" );
	setTimeout( "window.focus()", 250 );
}

//
//						getSessionID
//
function getSessionID()
{
	if( g_session )
	{
		return g_session;
	}
	else
	{
		try
		{
			return parent.g_session;
		}
		catch(e)
		{
			return '';
		}
	}
}

//
//						addMod
//
function addMod()
{
	var obj = document.getElementById( 'idaddmod' );
	if( obj )
	{
		// validate username
		var username = obj.value;
		if( !checkUsername( username ) )
		{
			return false;
		}

		// looks good, install into hidden field
		obj = document.getElementById( 'idadduser' );
		if( obj )
		{
			obj.value = username;

			// allow form to submit
			return true;
		}
	}

	return false;
}

//
//						removeMod
//
function removeMod( usercode )
{

	// get the form we'll submit
	var frm = document.getElementById( 'idmodform' );
	if( frm )
	{
		// install the value into the hidden remove field
		var obj = document.getElementById( 'idremuser' );
		if( obj )
		{
			obj.value = usercode;
			frm.submit();
		}
	}
}

//
//						myLayout
//
//	Can't get freakin' tables or CSS to lay out a fixed height screen so we'll just 
//	force the issue with javascript.  Man, CSS sucks!
//
function myLayout()
{
	// first make sure this is a page with fancy layout
	var obj = document.getElementById( "idtitlebar" );
	if( obj == null )
	{
		return;
	}

   	// get inner screen height and width, very browser dependent
    var x, y, adjy;
    if (self.innerHeight)
    {
        // all except Explorer
        x = self.innerWidth - 8;
        y = self.innerHeight;
		adjy = -8;
    }
    else if (document.documentElement && document.documentElement.clientHeight)
    {
        // Explorer 6 Strict Mode
        x = document.documentElement.clientWidth;
        y = document.documentElement.clientHeight;
		adjy = 0;
    }
    else if (document.body)
    {
        // other Explorers
        x = document.body.clientWidth;
        y = document.body.clientHeight;
		adjy = 0;
    }

	// see if it changed
	if( x != g_width || y != g_height )
	{
		// going to set up the fixed layout, body should never scroll
		document.body.style.overflow = 'hidden';

		// remember our new size
		g_width = x;
		g_height = y;

		var h = 0;
		obj = document.getElementById( "idtitlebar" );
		obj.style.position = 'absolute';
		obj.style.width = '100%';
		obj.style.top = '0px';
		h += parseInt( obj.offsetHeight );

		obj = document.getElementById( "iddescbar" );
		obj.style.position = 'absolute';
		obj.style.width = '100%';
		obj.style.top = h + 'px';
		h += parseInt( obj.offsetHeight );

		obj = document.getElementById( "idbuttonbar" );
		obj.style.position = 'absolute';
		obj.style.textAlign = 'right';
		obj.style.width = '100%';
		obj.style.top = h + 'px';
		h += parseInt( obj.offsetHeight );

		obj = document.getElementById( "idbuttontable" );
		obj.align = 'right';

		obj = document.getElementById( "idfooterbar" );
		obj.style.position = 'absolute';
		obj.style.width = '100%';
		var bot = g_height - parseInt( obj.offsetHeight );
		obj.style.top = pos(bot) + 'px';

		obj = document.getElementById( "idcontentwrap" );
		obj.style.position = 'absolute';
		obj.style.width = g_width + 'px';
		obj.style.top = h + 'px';
		obj.style.height = pos(bot - h + adjy) + 'px';

		obj = document.getElementById( "idcontent" );
		obj.style.position = 'absolute';
		obj.style.left = '4px';
		obj.style.width = (g_width-8) + 'px';
		obj.style.top = '4px';
		obj.style.height = pos(bot - h + adjy - 8) + 'px';
		obj.style.overflow = 'auto';
	}

	setTimeout( "myLayout()", 500 );
}

//
//						pos
//
function pos( n )
{
	return n < 0 ? 0 : n;
}

//
//						btnChat
//
function btnChat( sRoom )
{
	if( forumUsername == 'guest' )
	{
		alert( "Sorry, you must be logged in to access chat." );
		return;
	}

	var sURL = sRoom == 'mb' ? '/m/b/a/chat/chat.html' : '/m/b/a/chat/chatx.html';
	window.open( sURL,
		"chat", 
		"width=500,height=400,resizable=1,scrollbars=0,menubar=0,toobar=0" );
}

//
//						getUserName
//
function getUserName()
{
	return forumUsername;
}

//
//						getUserPassword
//
function getUserPassword()
{
	return forumPassword;
}
