function buildLoginBox( msg )
{
	var tool_box = document.getElementById( "tool_box" );
	clearElement( tool_box );

	var body = document.createElement( "tbody" );

	if( msg )
		body.appendChild( oneCellRow( msg, null, null, "table_style_center red" ) );

	body.appendChild( oneCellRow( nNodeSpan( "Username: ", formInput( "text", "login_username", null, 15, "login_username" ) ), null, null, "table_style_center" ) );
	body.appendChild( oneCellRow( nNodeSpan( "Password: ", formInput( "password", "login_password", null, 15, "login_password" ) ), null, null, "table_style_center" ) );
	body.appendChild( oneCellRow( nNodeSpan( "Keep me logged in: ", formInput( "checkbox", "login_auto", 1, null, "login_auto" ) ), null, null, "table_style_center" ) );
	body.appendChild( oneCellRow( oneNodeSpan( " Login ", null, "submitFormAJAX( 'loginUser', new Array( 'login_auto' ), new Array( 'login_username', 'login_password' ) );", "standard_text link solid" ), null, null, "table_style_center" ) );
	body.appendChild( oneCellRow( oneNodeSpan( "Register", null, "buildRegister()", "link" ), null, null, "table_style_center" ) );

	var anchor = document.createElement( "a" );
	anchor.href = "./register.php";
	anchor.appendChild( oneNodeSpan( "Register", null, null, "link" ) );
	//body.appendChild( oneCellRow( anchor, null, null, "table_style_center" ) );

	defaultDisplayTable( tool_box, oneCellRow( "User Login:", null, null, "standard_text bold solid tab_grey" ), body, null, true, 200, 200 );
}
function buildRegister( error_text)
{
	views['view1'] = 'register';
	views['chatter_box'] = null;
	var content_cell = document.getElementById( "main_window" );
	clearElement( content_cell );

	var table = document.createElement( "table" );
	var tbody = document.createElement( "tbody" );

	if( error_text )
		tbody.appendChild( oneCellRow( error_text, null, 2, "red" ) );

	tbody.appendChild( twoCellRow( "Username", formInput( 'text', 'reg_username', null, 15, 'reg_username' ), "standard_text", "standard_text" ) );
	tbody.appendChild( oneCellRow( ' ', null, 2, "standard_text" ) );
	tbody.appendChild( twoCellRow( "Password", formInput( 'password', 'reg_password', null, 15, 'reg_password' ), "standard_text", "standard_text" ) );
	tbody.appendChild( twoCellRow( "Comfirm Password", formInput( 'password', 'reg_password_confirm', null, 15, 'reg_password_confirm' ), "standard_text", "standard_text" ) );
	tbody.appendChild( oneCellRow( ' ', null, 2 ) );
	tbody.appendChild( twoCellRow( "e-mail", formInput( 'text', 'reg_email', null, 15, 'reg_email' ), "standard_text", "standard_text" ) );
	tbody.appendChild( twoCellRow( "Confirm e-mail", formInput( 'text', 'reg_email_confirm', null, 15, 'reg_email_confirm' ), "standard_text", "standard_text" ) );

	tbody.appendChild( oneCellRow( oneNodeSpan( "Submit", null, "submitFormAJAX( 'registerUser', null, new Array( 'reg_username', 'reg_password', 'reg_password_confirm', 'reg_email', 'reg_email_confirm' ) );" ) ) );

	table.appendChild( tbody );
	content_cell.appendChild( table );
}
function buildToolBox( tool_player )
{
	var tool_box = document.getElementById( "tool_box" );
	clearElement( tool_box );

	var content = ( views['tool_box'] == "tool_box_game" ? buildGameToolbar() : buildUserToolbar() );

	defaultDisplayTable( tool_box, oneCellRow( newTabs( "tool_box_tabs" ) ), content, null, true, 200, 200 );

	addTab( "tool_box_tabs", "User", "defaultAJAX( 'userToolbox', new Array(), new Array() );", "tool_box_user" );
	if( tool_player )
		addTab( "tool_box_tabs", "Game", "defaultAJAX( 'gameToolbox', new Array(), new Array() );", "tool_box_game" );

	orderTabs( "tool_box_tabs", views['tool_box'] );

	if( views['tool_box'] == "tool_box_user" )
		scroll( null, null, "game_list" );	
}
function buildGameToolbar()
{
	var tbody = document.createElement( "tbody" );
	tbody.appendChild( oneCellRow( nNodeSpan( makeImg( './img/player.gif' ), " ", oneNodeSpan( ( playerArray ? playerArray['name'] : '' ), null, "defaultAJAX( 'profileData', new Array( '"+player_id+"'), new Array( 'p' ) )", "link" ) ), null, 2, "standard_text", "player_name" ) );
	tbody.appendChild( oneCellRow( nNodeSpan( "Turns:", " ", oneNodeSpan( '', "doc_turns" ) ), null, 2, "standard_text" ) );
	tbody.appendChild( oneCellRow( oneNodeSpan( 'Inventory', null, "defaultAJAX( 'inventoryData', new Array(), new Array( 'r', 'player' ), 'Inventory: Resources', new Array( new Array( 'view2', 'resources' ) ) )", "link" ), null, 2, "standard_text" ) );

	var equip_table = document.createElement( "table" );
	var equip_body = document.createElement( "tbody" );
	equip_body.id = "equip_list";
	equip_table.appendChild( equip_body );
	equip_table.cellPadding = 0;
	equip_table.cellSpacing = 1;
	equip_table.style.backgroundColor = "black";
	equip_table.border=0;

	tbody.appendChild( twoCellRow( "Equiped Items:", equip_table, "standard_text", null ) );
	//tbody.appendChild( oneCellRow( equip_table, null, null, null ) );

	tbody.appendChild( oneCellRow( "Auto-Queue:", null, 2, "standard_text" ) );
	tbody.appendChild( oneCellRow( oneNodeSpan( '', 'auto_queue' ), null, 2, "standard_text" ) );
	tbody.appendChild( oneCellRow( document.createElement( "hr" ), null, 2, "standard_text" ) );

	var table = document.createElement( "table" );
	var body = document.createElement( "tbody" );

	var row = document.createElement( "tr" );
	row.appendChild( oneCell( oneNodeSpan( makeImg( './img/market0.gif', 25, 20, null, "Market" ), null, "defaultAJAX( 'marketData', new Array(), new Array( 'r' ), 'Market: Resources' );", "link no_rep" ) ) );
	row.appendChild( oneCell( oneDiv( oneDiv( oneDiv( ' ', null, null, null, "mail_check_count", null, 23, 20), null, null, null, "mail_check_img", './img/mail0.gif', 25, 20 ), "defaultAJAX( 'mailData', new Array(), new Array( 'i' ), 'Mail: Inbox' );", null, "link no_rep back_center", "mail_check", null, 25, 20 ) ) );
	row.appendChild( oneCell( oneNodeSpan( makeImg( './img/community0.gif', 25, 20, null, "Community (Friends/Guilds)" ), null, "defaultAJAX( 'communityData', new Array(), new Array( 'f' ), 'Community: Personal' );", "link no_rep" ) ) );
	row.appendChild( oneCell( oneNodeSpan( makeImg( './img/craft0.gif', 25, 20, null, "Item Crafting" ), null, "defaultAJAX( 'beginCraft', new Array(), new Array(), 'Crafting Factory' );", "link no_rep" ) ) );
	row.appendChild( oneCell( oneNodeSpan( makeImg( './img/leaderboard0.gif', 25, 20, null, "Leaderboards" ), null, "defaultAJAX( 'leaderData', new Array( '1' ), new Array( 'l' ), 'Leaderboard: Land' );", "link no_rep" ) ) );
	row.appendChild( oneCell( oneNodeSpan( makeImg( './img/goal0.gif', 25, 20, null, "Goals" ), null, "defaultAJAX( 'goalData', new Array(), new Array(), 'Goals List' );", "link no_rep" ) ) );
	body.appendChild( row );

	var row = document.createElement( "tr" );
	row.appendChild( oneCell( oneDiv( oneDiv( ' ', null, null, null, "hMoveToggleImg", "./img/hMove1.gif", 25, 20 ), "hMoveToggle( null );", 2, "link no_rep" ) ) );
	row.appendChild( oneCell( oneDiv( oneDiv( ' ', null, null, null, "tileOwnerToggleImg", "./img/tileOwner0.gif", 25, 20 ), "tileOwnerToggle( null );", 2, "link no_rep" ) ) );
	//row.appendChild( oneCell( oneNodeSpan( makeImg( './img/tileOwner0.gif', 25, 10 ), null, "defaultAJAX( 'debugOwner', null, null, null );", "link no_rep" ) ) );
	body.appendChild( row )

	table.appendChild( body );
	tbody.appendChild( oneCellRow( table, null, 2, null ) );

	return tbody;
}
function buildUserToolbar()
{
	var tbody = document.createElement( "tbody" );
	tbody.appendChild( oneCellRow( nNodeSpan( "Hello ", oneNodeSpan( 'debug' ) ), null, null, "bold standard_text" ) );
	tbody.appendChild( oneCellRow( nNodeSpan( "[ ", oneNodeSpan( "Lobby", null, "defaultAJAX( 'gameLobby', new Array(), new Array( 'mp_2' ), null, new Array( new Array( 'lobby', 'mp_2' ) ) );", "link" ), " ]", " (game search)" ), null, null, "standard_text" ) );
	tbody.appendChild( oneCellRow( nNodeSpan( "[ ", oneNodeSpan( "Logout", null, "defaultAJAX( 'logout', new Array(), new Array() );", "link" ), " ]" ), null, null, "standard_text" ) );
	tbody.appendChild( oneCellRow( "My Games:", null, null, "standard_text" ) );

	var game_list = document.createElement( "tbody" );
	var myGames = xmlList( data, "myGame" );
	if( myGames )
	{
		if( myGames.length > 0 )
		{
			for(var g = 0, myGame; myGame = myGames[g]; g++ )
			{
				if( xmlVal( myGame, "active" ) )
				{
					var label = "Playing";
					var link = '';
					var style = "bold red";
				}
				else
				{
					var label = "Play";
					var link = "defaultAJAX( 'playGame', new Array( '"+xmlVal( myGame, "id" )+"' ), new Array() )";
					var style = "link";
				}

				var span = oneNodeSpan( label, null, link, style );
				game_list.appendChild( oneCellRow( nNodeSpan( xmlVal( myGame, "name" ), ": [ ", span, " ]" ), null, null, "standard_text" ) );
			}
		}
		else
			game_list.appendChild( oneCellRow( "Playing no Games!", null, null, "standard_text bold" ) );
	}
	else
		game_list.appendChild( oneCellRow( "Playing no Games!", null, null, "standard_text bold" ) );

	var table = document.createElement( "table" );
	table.appendChild( scrollWindow( game_list, 180, 100, "game_list" ) );

	tbody.appendChild( oneCellRow( table, null, null, "standard_text" ) );	

	return tbody;
}
function buildChatterBox()
{
	var sidebar_top = document.getElementById( "sidebar_top" );

	clearElement( sidebar_top );

	if( ! views['chatter_box'] )
	{
		if( game_id )
			views['chatter_box'] = "global";
		else
			views['chatter_box'] = 'lobby';
	}
	chatter_time = null;
	var chatter_content = document.createElement( "tbody" );
	chatter_content.id = "chatter_window";	
	var chatter_data = xmlList( data, "chat" );

	if( chatter_data )
	{
		for( var c = 0, chat; chat = chatter_data[c]; c++ )
		{
			var temp_table = document.createElement( "table" );
			var temp_content = document.createElement( "tbody" );

			var onclick = null;
			var style = null;
			if( parseInt(xmlVal( chat, "owner_type" )) == 1 )
			{
				var onclick = "defaultAJAX( 'profileData', new Array( '"+xmlVal( chat, "owner_id")+"' ), new Array( 'p' ), 'Profile: Player' );";
				var style = "link";
			}
			temp_content.appendChild( oneCellRow( nNodeSpan( oneNodeSpan( xmlVal( chat, "owner_name" ), null, onclick, style ), ": ", xmlVal( chat, "time" ) ), null, null, "standard_text" ) );
			if( ! xmlVal( chat, "owner_ignore" ) )
				temp_content.appendChild( oneCellRow( parseMessage( xmlVal( chat, "msg" ) ), null, null, "standard_text wrap" ) );

			temp_table.appendChild( temp_content );
			temp_table.cellPadding = 0;
			temp_table.cellSpacing = 0;
			temp_table.className = "w100p";
			temp_table.id = "chat_"+xmlVal( chat, "id" );

			chatter_content.appendChild( oneCellRow( temp_table, null, null, "standard_text" ) );
		}
	}
	else
		chatter_content.appendChild( oneCellRow( "All quiet in here", null, null, "standard_text" ) );

	var scroll_content = scrollWindow( chatter_content, 270, 280, "chatter" );
	var table = document.createElement( "table" );
	table.appendChild( scroll_content );

		var content = document.createElement( "tbody" );
		content.appendChild( oneCellRow( table, null, null, null ) );

			var table = document.createElement( "table" );
				var body = document.createElement( "tbody" );
				var view = views['chatter_box'];
				var onclick = "submitFormAJAX( 'submitChatter', new Array(), new Array( 'chatter_text' ), new Array( chatter_time, 1 ), new Array( '"+view.substring( 0, 1 )+"' ) );";
				body.appendChild( twoCellRow( textarea( null, "chatter_text", 4, 22, 10, "soft" ), oneCell( oneDiv( "Submit", null, null, "standard_text", null, null, 50, 60 ), onclick, null, "link solid_100" ), "standard_text" ) );
			table.appendChild( body );
		content.appendChild( oneCellRow( oneDiv( table, null, null, 'solid_100 standard_text no_scroll', null, null, 290, 90), null, null, null ) );
		var view = views['chatter_box'];

		//content.appendChild( oneCellRow( oneDiv( ' ', null, null, "back_blue", "timer_display_chatter", null, "100%", "2" ), null, 2, "table_style_center" ) );
		content.appendChild( oneCellRow( "Refresh", "defaultAJAX( 'getChatter', new Array( chatter_time, 1 ), new Array( '"+view.substring( 0, 1 )+"' ) );", 2, "link table_style_center" ) );
	defaultDisplayTable( sidebar_top, oneCellRow( newTabs( "chatter_tabs" ) ), content, null, true, 300, 400 );

	if( game_id )
	{
		addTab( "chatter_tabs", "Global", "defaultAJAX( 'getChatter', null, new Array( 'g' ), null, new Array( new Array( 'chatter_box', 'global' ) ) );", "global" );
		addTab( "chatter_tabs", "Local", "defaultAJAX( 'getChatter', null, new Array( 'l' ), null, new Array( new Array( 'chatter_box', 'local' ) ) );", "local" );
	}
	else
		addTab( "chatter_tabs", "Lobby Chat", "defaultAJAX( 'getChatter', null, null, null, new Array( new Array( 'chatter_box', 'lobby' ) ) );", "lobby" );
		
	orderTabs( "chatter_tabs", views['chatter_box'] );

	scroll( 'bottom', 10, "chatter" );

}

function updateChatterBox()
{
	var chatter_content = document.getElementById( "chatter_window" );
	if( chatter_content )
	{
		var scroll_bot = scrollBottom( "chatter" );
		var chatter_data = xmlList( data, "chat" );

		if( chatter_data )
		{
			for( var c = 0, chat; chat = chatter_data[c]; c++ )
			{
				var temp_table = document.createElement( "table" );
				var temp_content = document.createElement( "tbody" );

				var onclick = null;
				var style = null;
				if( parseInt(xmlVal( chat, "owner_type" )) == 1 )
				{
					var onclick = "defaultAJAX( 'profileData', new Array( '"+xmlVal( chat, "owner_id")+"' ), new Array( 'p' ), 'Profile: Player' );";
					var style = "link";
				}

				temp_content.appendChild( oneCellRow( nNodeSpan( oneNodeSpan( xmlVal( chat, "owner_name" ), null, onclick, style ), ": ", xmlVal( chat, "time" ) ), null, null, "standard_text" ) );
				if( ! xmlVal( chat, "owner_ignore" ) )
					temp_content.appendChild( oneCellRow( parseMessage( xmlVal( chat, "msg" ), 40 ), null, null, "standard_text wrap" ) );

				temp_table.appendChild( temp_content );
				temp_table.cellPadding = 0;
				temp_table.cellSpacing = 0;
				temp_table.className = "w100p";
				temp_table.style.backgroundColor = "rgb(255,255,0)";
				temp_table.id = "chat_"+xmlVal( chat, "id" );

				chatter_content.appendChild( oneCellRow( temp_table, null, null, "standard_text red_back" ) );

				if( xmlVal( chat, "id" ) )
				{
					var c_id = 'chat_'+xmlVal( chat, "id" );
					chatFade[c_id] = setInterval( "fadeNewData( "+xmlVal( chat, "id" )+", 'chat', chatFade )", 50 );
				}
			}
			if( scroll_bot )
				scroll( 'bottom', 10, "chatter" );
		}
	}
	else
		views['chatter_box'] == null;
}
function buildGamePanes()
{
}
function showPageContent( cache )
{
	views['view1'] = 'page_home';
	views['chatter_box'] = null;
	var content_cell = document.getElementById( "main_window" );
	clearElement( content_cell );

	if( ! cache )
	{
		var content_data = xmlVal( data, "pageContent" );
		xmlData['content_data'] = content_data;
	}
	else
		var content_data = xmlData['content_data'];

	var table = document.createElement( "table" );
	var tbody = document.createElement( "tbody" );

	var content_rows = xmlList( content_data, "pageRow" );
	for( var r = 0, row; row = content_rows[r]; r++ )
	{
		var temp_table = document.createElement( "table" );
		var temp_body = document.createElement( "tbody" );
		var temp_row = document.createElement( "tr" );

		var elements = xmlList( row, "pageElement" );
		if( elements.length > 0 )
		{
			for( var e = 0, ele; ele = elements[e]; e++ )
			{
				var id = xmlVal( ele, 'id' );
				var order = xmlVal( ele, 'order' );
				var cell_table = document.createElement( "table" );
				var cell_tbody = document.createElement( "tbody" );
				if( user_level == 1 && page_admin_view )
				{
					var img1 = img2 = img3 = img4 = null;

					var img1 = makeImg( './img/page_edit.gif', null, null, null, "Edit Element!", "editElement( '"+r+"', '"+e+"' );", "link" );
					var img2 = makeImg( './img/page_delete.gif', null, null, null, "Delete Element!", "defaultAJAX( 'deletePageElement', new Array( '"+id+"' ) );", "link" );

					if( order <= elements.length && order > 1 )
						var img3 = makeImg( './img/page_left.gif', null, null, null, "Move Element Left!", "defaultAJAX( 'movePageElement', new Array( '"+id+"' ), new Array( 'left' ) );", "link" );
					if( order != elements.length && order >= 0 )
						var img4 = makeImg( './img/page_right.gif', null, null, null, "Move Element Right!", "defaultAJAX( 'movePageElement', new Array( '"+id+"' ), new Array( 'right' ) );", "link" );

					var cell = oneCellRow( nNodeSpan( img1, img2, ( img3 ? img3 : '' ), ( img4 ? img4 : '' ) ), null, null, "w100p" );
					cell.style.height = 18;
					cell_tbody.appendChild( cell );
				}
				var content = '';//oneNodeSpan( xmlVal( ele, 'id' ) );
				if( xmlVal( ele, "type" ) == 1 && xmlVal( ele, 'text' ) )
					content = oneNodeSpan( parseMessage( xmlVal( ele, "text" ), null, true, true ) );
				else if( xmlVal( ele, "type" ) == 2 && xmlVal( ele, "filename" ) )
					content = makeImg( './img/page/'+xmlVal( ele, "filename" ), null, null, null, xmlVal( ele, "title" ) );					
				
				var con_cell = oneCellRow( content, null, null, "standard_text" );
				if( xmlVal( ele, 'x' ) )
				{
					con_cell.style.width = xmlVal( ele, 'x' );
					//con_cell.style.height = xmlVal( ele, 'y' );
				}
				cell_tbody.appendChild( con_cell );
				cell_table.appendChild( cell_tbody );
				if( xmlVal( ele, 'x' ) )
				{
					cell_table.style.width = xmlVal( ele, 'x' );
					//con_cell.style.height = xmlVal( ele, 'y' );
				}
				else
					cell_table.style.width = "100%";

				var temp_cell = oneCell( cell_table, null, null, "standard_text"+( user_level == 1  && page_admin_view ? ' solid_grey' : '' ), "ele_"+id )
				if( xmlVal( ele, 'x' ) )
				{
					temp_cell.style.width = xmlVal( ele, 'x' );
					//con_cell.style.height = xmlVal( ele, 'y' );
				}
				else
				{
					temp_cell.style.width = "100%";
					temp_cell.style.height = "100%";
				}
				temp_cell.vAlign = 'top';
				temp_row.appendChild( temp_cell );
			}
		}
		else if( user_level == 1 && page_admin_view )
		{
			temp_row.appendChild( oneCell( 'No Elements', null, null, "standard_text w100p solid_grey" ) );
		}
		if( user_level == 1 && page_admin_view )
		{
			var img1 = img2 = img3 = null;

			var cell = oneCell( makeImg( './img/page_add.gif', null, null, null, "Add an element", "defaultAJAX( 'addPageElement', new Array( '"+xmlVal( row, 'id' )+"' ) );", "link solid_grey") );
			cell.style.width = 16;
			cell.style.height = "100%";
			temp_row.appendChild( cell );

			var img1 = makeImg( './img/page_delete.gif', null, null, null, "Delete Row!", "defaultAJAX( 'deletePageRow', new Array( '"+xmlVal( row, 'id' )+"' ) );", "link" );

			if( xmlVal( row, 'order' ) <= content_rows.length && xmlVal( row, 'order' ) > 1 )
				var img2 = makeImg( './img/page_up.gif', null, null, null, "Move Row Up!", "defaultAJAX( 'movePageRow', new Array( '"+xmlVal( row, 'id' )+"' ), new Array( 'up' ) );", "link" );
			if( xmlVal( row, 'order' ) != content_rows.length && xmlVal( row, 'order' ) >= 0 )
				var img3 = makeImg( './img/page_down.gif', null, null, null, "Move Row Down!", "defaultAJAX( 'movePageRow', new Array( '"+xmlVal( row, 'id' )+"' ), new Array( 'down' ) );", "link" );

			var cell = oneCell( nNodeSpan( img1, ( img2 ? img2 : '' ), document.createElement( "br" ), ( img3 ? img3 : '' ) ) )
			cell.style.width = 16;
			temp_row.appendChild( cell );

		}
		temp_body.appendChild( temp_row );
		temp_table.appendChild( temp_body );
		if( user_level == 1 && page_admin_view )
			temp_table.className = "solid_grey";
		temp_table.style.width = "100%";
		//temp_table.border=1;
		tbody.appendChild( oneCellRow( temp_table ) );
	}
	if( user_level == 1 && page_admin_view )
	{
		tbody.appendChild( oneCellRow( 'Add a Page Row!', "defaultAJAX( 'addPageRow', new Array(), new Array( '"+xmlVal( content_data, "page_name" )+"' ) )", null, "standard_text link" ) );
		tbody.appendChild( oneCellRow( 'Add a Page!', "defaultAJAX( 'addContentPage', new Array(), new Array( '"+xmlVal( content_data, "page_name" )+"' ) )", null, "standard_text link" ) );
	}
	if( user_level == 1 )
	{
		tbody.appendChild( oneCellRow( 'Toggle Admin View!', "toggleAdminView( true )", null, "standard_text link" ) );
		tbody.appendChild( oneCellRow( '', null, null, "standard_text", "edit_element" ) );
	}
	var pages = xmlVal( content_data, "pages" );
	if( pages > 1 )
	{
		var row = page_links( xmlVal( content_data, "page" ), pages, new Array( 'pageContentFront', new Array(), new Array( xmlVal( content_data, 'page_name' ) ) ) );
		tbody.appendChild( row );
	}
	tbody.appendChild( oneCellRow( '', null, null, null, 'news_window' ) );
	table.appendChild( tbody );
	table.style.width = "100%";
	content_cell.appendChild( table );
	content_cell.vAlign = "top";
}
function editElement( r, e )
{
	var edit_element = document.getElementById( "edit_element" );
	clearElement( edit_element );

	var content_rows = xmlList( data, "pageRow" );
	var elements = xmlList( content_rows[r], "pageElement" );
	var ele_data = elements[e];

	if( ele_data )
	{
		var element = document.getElementById( "ele_"+xmlVal( ele_data, 'id' ) );
		element.style.backgroundColor = "yellow";

		var table = document.createElement( "table" );
		var tbody = document.createElement( "tbody" );

		var type = xmlVal( ele_data, 'type' );
		if( type )
		{
			if( type == 1 )
			{
				var textarea = document.createElement( "textarea" );
				textarea.id = "content_text";
				textarea.name = "content_text";
				textarea.rows = 10;
				textarea.cols = 30;
				textarea.maxLength = 10;
				textarea.wrap = "soft";
				if( xmlVal( ele_data, "text" ) )
					textarea.appendChild( document.createTextNode( xmlVal( ele_data, "text" ) ) );

				tbody.appendChild( oneCellRow( textarea ) );
				tbody.appendChild( oneCellRow( 'Edit!', "submitFormAJAX( 'editPageElementContent', null, new Array( 'content_text' ), new Array( '"+xmlVal( ele_data, 'id' )+"', 1 ) )", null, "standard_text link" ) );
			}
			else if( type == 2 )
			{
				tbody.appendChild( twoCellRow( 'Title', formInput( 'text', 'title', xmlVal( ele_data, 'title' ), 20, 'page_content_title' ), "standard_text", "standard_text" ) );
				tbody.appendChild( twoCellRow( 'Link', formInput( 'text', 'link', xmlVal( ele_data, 'link' ), 20, 'page_content_link' ), "standard_text", "standard_text" ) );
				tbody.appendChild( twoCellRow( 'Filename', formInput( 'text', 'filename', xmlVal( ele_data, 'filename' ), 20, 'page_content_filename' ), "standard_text", "standard_text" ) );
				tbody.appendChild( oneCellRow( 'Edit!', "submitFormAJAX( 'editPageElementContent', null, new Array( 'page_content_title', 'page_content_link', 'page_content_filename' ), new Array( '"+xmlVal( ele_data, 'id' )+"', 2 ) )", 2, "standard_text link" ) );				
			}
		}
		else
		{
			tbody.appendChild( oneCellRow( 'Add Text!', "defaultAJAX( 'editPageElementContent', new Array( '"+xmlVal( ele_data, 'id' )+"', 1 ) )", null, "standard_text link" ) );
			tbody.appendChild( oneCellRow( 'Add Image!', "defaultAJAX( 'editPageElementContent', new Array( '"+xmlVal( ele_data, 'id' )+"', 2 ) )", null, "standard_text link" ) );
		}

		table.appendChild( tbody );
		table.className = "solid_100";
		edit_element.appendChild( table );
	}
}
function toggleAdminView( cache )
{
	if( page_admin_view )
		page_admin_view = false;
	else
		page_admin_view = true;

	showPageContent( cache );
}
function buildDefaultMasterContent()
{
	views['view1'] = "front";
	var master_content = document.getElementById( "master_content" );
	clearElement( master_content );
	master_content.style.width = "100%";
		var master_table = document.createElement( "table" );
		master_table.style.cellPadding = 0;
		master_table.style.cellSpacing = 0;
		//master_table.className = "solid_100";
			var master_body = document.createElement( "tbody" );
				var master_row = document.createElement( "tr" );
					var master_cell = document.createElement( "td" );
					master_cell.id = "center_content";
					master_cell.style.width = 600;
					master_cell.style.height = 680;
					//master_cell.className = "solid_100";
					master_cell.vAlign = "top";
						var table = document.createElement( "table" );
							var tbody = document.createElement( "tbody" );
								var row = document.createElement( "tr" );
									var cell = document.createElement( "td" );
									cell.style.width = 600;
									cell.style.height = 80;
									cell.id = "ad_window";
									cell.className = "solid_100";
									cell.appendChild( makeImg( './img/blank.gif' ) );
								row.appendChild( cell );
							tbody.appendChild( row );
								var row = document.createElement( "tr" );
									var cell = document.createElement( "td" );
									cell.style.width = 600;
									cell.style.height = 600;
									cell.id = "main_window";
									cell.className = "solid_100";
									//cell.appendChild( makeImg( './plan.jpg', 600, 600 ) );
								row.appendChild( cell );
							tbody.appendChild( row );
						table.appendChild( tbody );
					master_cell.appendChild( table );
				master_row.appendChild( master_cell );
					var master_cell = document.createElement( "td" );
					master_cell.id = "sidebar_content";
					master_cell.style.width = 250;
					master_cell.style.height = "100%";
					//master_cell.className = "solid_100";
					master_cell.vAlign = "top";
						var table = document.createElement( "table" );
							var tbody = document.createElement( "tbody" );
								var row = document.createElement( "tr" );
									var cell = document.createElement( "td" );
									cell.style.width = 250;
									cell.style.height = 686;
									cell.id = "sidebar_top";
									cell.className = "solid_100";
									cell.appendChild( makeImg( './img/blank.gif' ) );
								row.appendChild( cell );
							tbody.appendChild( row );
						table.appendChild( tbody );
					master_cell.appendChild( table );
				master_row.appendChild( master_cell );
			master_body.appendChild( master_row );
		master_table.appendChild( master_body );
	master_content.appendChild( master_table );
}
function buildExtraBottom()
{
	var body = document.getElementById( "extra1" );
	if( body )
	{
		clearElement( body );
		//checkView( 'extra1', 'bottom_wiki', 'bottom_wookie' );

		var tbody2 = document.createElement( "tbody" );
		tbody2.id = "extra1_body";
		//tbody2.appendChild( oneCellRow( 'fff ' ) );

		defaultDisplayTable( body, oneCellRow( newTabs( "extra_tabs1" ) ), tbody2, null, true, 520, 340 );

		for( var t = 0, tab; tab = extraTabs[t]; t++ )
		{
			addTab( "extra_tabs1", tab['name'], tab['func'], "extra_"+tab['name'] );
		}
		orderTabs( "extra_tabs1", views['extra1'] );

	}
}
function addExtraTab( name, func )
{
	var tag = false;
	for( var t = 0, tab; tab = extraTabs[t]; t++ )
	{
		if( tab[0] == name )
			tag = true;
	}
	if( extraTabs.length == 1 )
		checkView( 'extra1', name );
	if( ! tag )
	{
		extraTabs[extraTabs.length] = new Array( name, func );
		addTab( "extra_tabs1", name, func, "extra_"+name );
		orderTabs( "extra_tabs1", views['extra1'] );
	}
}
function showMiniMap()
{
	var body = document.getElementById( 'extra1_body' );
	clearElement( body );

	views['extra1'] = 'Mini-Map';

	var image_1 = new Image()
	image_1.src = './img/game-'+game_id+'_grid-'+mapData['gridId']+'.png'

	var tile = xmlVal( data, "grid_tile" );
	var tileX = xmlVal( tile, "tileX" );
	var tileY = xmlVal( tile, "tileY" );

	var div1 = oneDiv( oneDiv( makeImg( './img/miniview.gif'), null, null, null, null, null, null, null, 'relative', ( ( parseInt( mapData['gridSizeY'] ) - parseInt( tileY ) ) * ( 20/4 ) ), ( ( parseInt( mapData['gridSizeX'] ) + parseInt( tileX ) ) * ( 20/4 ) ) ), null, null, 'no_rep', null, image_1.src, image_1.width, image_1.height );
	body.appendChild( oneCellRow( div1, null, null, null ) );

	//orderTabs( "extra_tabs1", views['extra1'] );	
}
function buildGameMasterContent()
{
	var master_content = document.getElementById( "master_content" );
	clearElement( master_content );
		var master_table = document.createElement( "table" );
			var master_body = document.createElement( "tbody" );
				var master_row = document.createElement( "tr" );
					var master_cell = document.createElement( "td" );
					master_cell.id = "center_content";
					master_cell.style.width = 550;
					master_cell.style.height = 700;
						var table = document.createElement( "table" );
							var tbody = document.createElement( "tbody" );
								var row = document.createElement( "tr" );
									var cell = document.createElement( "td" );
									cell.style.width = 550;
									cell.style.height = 80;
									cell.id = "ad_window";
									cell.vAlign = "top";
									cell.className = "table_style_center standard_text solid";
									cell.appendChild( document.createTextNode( " " ) );
								row.appendChild( cell );
							tbody.appendChild( row );
								var row = document.createElement( "tr" );
									var cell = document.createElement( "td" );
									cell.style.width = 550;
									cell.style.height = 300;
									cell.id = "middle_pane";
									//cell.className = "";
										var grid_table = document.createElement( "table" );
										grid_table.className = "standard_text";
											var grid_body = document.createElement( "tbody" );
											grid_body.id = "grid_body";
										grid_table.appendChild( grid_body );
									cell.appendChild( grid_table );
								row.appendChild( cell );
							tbody.appendChild( row );
								var row = document.createElement( "tr" );
									var cell = document.createElement( "td" );
									cell.style.width = 550;
									cell.style.height = 20;
									cell.id = "status_bar";
									cell.className = "table_style_center standard_text";
									cell.appendChild( document.createTextNode( " " ) );
								row.appendChild( cell );
							tbody.appendChild( row );
								var row = document.createElement( "tr" );
									var cell = document.createElement( "td" );
									cell.style.width = 550;
									cell.style.height = 300;
									cell.id = "extra_window";
									//cell.className = "solid";
										var table_bottom = document.createElement( "table" );
										table_bottom.className = "standard_text";
											var tbody_bottom = document.createElement( "tbody" );
											tbody_bottom.id = "extra1";
										table_bottom.appendChild( tbody_bottom );
									cell.appendChild( table_bottom );
								row.appendChild( cell );
							tbody.appendChild( row );
						table.appendChild( tbody );
					master_cell.appendChild( table );
				master_row.appendChild( master_cell );
					var master_cell = document.createElement( "td" );
					master_cell.id = "sidebar_content";
					master_cell.style.width = 300;
					master_cell.style.height = 700;
					master_cell.vAlign = "top";
						var table = document.createElement( "table" );
							var tbody = document.createElement( "tbody" );
								var row = document.createElement( "tr" );
									var cell = document.createElement( "td" );
									cell.style.width = 300;
									cell.style.height = 400;
									//cell.id = "sidebar_top";
									cell.vAlign = "top";
									//cell.className = "solid";
										var t_table = document.createElement( "table" );
										t_table.className = "standard_text";
											var t_body = document.createElement( "tbody" );
											t_body.id = "sidebar_top";
										t_table.appendChild( t_body );
									cell.appendChild( t_table );
								row.appendChild( cell );
							tbody.appendChild( row );
								var row = document.createElement( "tr" );
									var cell = document.createElement( "td" );
									cell.style.width = 300;
									cell.style.height = 300;
									cell.id = "sidebar_bottom";
									//cell.className = "solid";
										var t_table = document.createElement( "table" );
										t_table.className = "standard_text";
											var t_body = document.createElement( "tbody" );
											t_body.id = "sidebar_bottom";
											defaultDisplayTable( t_body, oneCellRow( 'Recent Forum Posts', null, null, "table_style_center solid_100 tab_grey" ), null, null, true, 300, 300 );
										t_table.appendChild( t_body );
									cell.appendChild( t_table );
								row.appendChild( cell );
							tbody.appendChild( row );
						table.appendChild( tbody );
					master_cell.appendChild( table );
				master_row.appendChild( master_cell );
			master_body.appendChild( master_row );
		master_table.appendChild( master_body );
	master_content.appendChild( master_table );

}
