			function showLobby()
			{
				clearGrid = true;

				var grid_body = document.getElementById("grid_body");
				clearElement( grid_body );

				var content = document.createElement( "tbody" );
				var lobbyGames = xmlList( data, "lobbyGame" );

				checkView( 'lobby', 'mp_2', 'mp_1', 'sp_1' );
				if( lobbyGames )
				{
					var scroll_content = document.createElement( "tbody" );

					var row = document.createElement( "tr" );
					row.appendChild( oneCell( "Name", null, null, "standard_text bold" ) );
					if( views['lobby'] != 'sp_1' )
						row.appendChild( oneCell( "# Players", null, null, "standard_text bold" ) );
					row.appendChild( oneCell( "Game Age", null, null, "standard_text bold" ) );
					row.appendChild( oneCell( "", null, null, "standard_text bold" ) );
					scroll_content.appendChild( row );

					for( var g = 0, lobbyGame; lobbyGame = lobbyGames[g]; g++ )
					{
						var row = document.createElement( "tr" );

						if( xmlVal( lobbyGame, "playing" ) )
						{
							var text = "Play";
							var onclick = "defaultAJAX( 'playGame', new Array( '"+xmlVal( lobbyGame, "id" )+"' ), new Array() );";
							var style = '';
						}
						else
						{
							var text = "Join";
							var onclick = "defaultAJAX( 'joinGame', new Array( '"+xmlVal( lobbyGame, "id" )+"' ), new Array() );";
							var style = " red";
						}
						var span = oneNodeSpan( text, null, onclick, "link"+style );
						row.appendChild( oneCell( xmlVal( lobbyGame, "name" ), null, null, "standard_text" ) );
						if( views['lobby'] != 'sp_1' )
							row.appendChild( oneCell( xmlVal( lobbyGame, "players" ), null, null, "standard_text" ) );
						row.appendChild( oneCell( xmlVal( lobbyGame, "game_age" ), null, null, "standard_text" ) );
						row.appendChild( oneCell( nNodeSpan( "[ ", span, " ]" ), null, null, "standard_text" ) );

						scroll_content.appendChild( row );

					}
					var content = scrollWindow( scroll_content,  450, 280, "lobby_games" );
				}
				else
					content.appendChild( oneCellRow( "I am empty!!!", null, null, "standard_text" ) );

				defaultDisplayTable( grid_body, oneCellRow( newTabs( "lobby_tabs" ) ), content, null, true, 500, 300 );

				addTab( "lobby_tabs", "Single Player", "defaultAJAX( 'gameLobby', new Array(), new Array( 'sp_1' ), null, new Array( new Array( 'lobby', 'sp_1' ) ) );", "sp_1" );
				addTab( "lobby_tabs", "Multi-Player (Single game)", "defaultAJAX( 'gameLobby', new Array(), new Array( 'mp_1' ), null, new Array( new Array( 'lobby', 'mp_1' ) ) );", "mp_1" );
				addTab( "lobby_tabs", "Multi-Player (Persistent)", "defaultAJAX( 'gameLobby', new Array(), new Array( 'mp_2' ), null, new Array( new Array( 'lobby', 'mp_2' ) ) );", "mp_2" );

				orderTabs( "lobby_tabs", views['lobby'] );
				scroll( null, null, "lobby_games" );


					navRecord = false;
					defaultAJAX( 'getChatter', new Array(), new Array(), null, new Array( new Array( 'chatter_box', 'lobby' ) ) );
					navRecord = true;
			}
			function showNews()
			{
				var headlines = xmlVal( data, "headlines" );
				if( headlines )
					var content_cell = document.getElementById("news_window");
				else
					var content_cell = document.getElementById( "main_window" );

				if( content_cell )
				{
					clearElement( content_cell );
					content_cell.vAlign = "top";

					var content_table = document.createElement( "table" );
					var content_body = document.createElement( "tbody" );

					if( headlines )
						content_body.appendChild( oneCellRow( 'Latest News:', null, null, 'bold standard_text') );
					var news = xmlList( data, 'news_item' );

					if( news.length > 0 )
					{
						var news_table = document.createElement( "table" );
						news_table.className = "w100p";
						var news_tbody = document.createElement( "tbody" );
						news_table.appendChild( news_tbody );
						content_body.appendChild( oneCellRow( news_table ) );
						for( var n = 0, news_item; news_item = news[n]; n++ )
						{
							var link = "defaultAJAX( 'getNews', new Array( '"+xmlVal( news_item, 'id' )+"' ) )";
							if( headlines )
								var div = '';
							else
								var div = oneDiv( nNodeSpan( " (", xmlVal( news_item, "comment_total" ), " Comments)" ), link, null, "link tab_grey no_wrap table_style_right" );
							news_tbody.appendChild( oneCellRow( nNodeSpan( oneNodeSpan( xmlVal( news_item, 'title' ), null, link, 'link' ), " -- ", xmlVal( news_item, 'date' ), " -- Posted By: ", xmlVal( news_item, 'username' ), div ), null, null, 'standard_text solid tab_grey' ) );
							if( ! headlines )
							{
								news_tbody.appendChild( oneCellRow( parseMessage( xmlVal( news_item, 'text' ), null, true, true ), null, null, 'standard_text solid w100p' ) );

								if( news_item.getAttribute( 'id' ) == 'single' )
								{
									var edit_news = news_item;
									content_body.appendChild( oneCellRow( 'Comments:', null, null, 'bold standard_text' ) );
		
									var comments = xmlList( news_item, 'comment' );
	
									if( comments.length > 0 )
									{
										var table = document.createElement( "table" );
										var tbody = document.createElement( "tbody" );
										for( var n = 0, comment; comment = comments[n]; n++ )
										{
											tbody.appendChild( oneCellRow( nNodeSpan( xmlVal( comment, 'date' ), " -- Posted By: ", xmlVal( comment, 'username' ) ), null, null, 'standard_text solid tab_grey' ) );
											tbody.appendChild( oneCellRow( parseMessage( xmlVal( comment, 'text' ), null, true, true ), null, null, 'standard_text solid w100p' ) );
										}
										table.appendChild( tbody );
										table.className = "w100p";
										content_body.appendChild( oneCellRow( table ) );
									}
									else
										content_body.appendChild( oneCellRow( 'No comments', null, null, 'bold table_style_center solid standard_text' ) );

									var form_table = document.createElement( "table" );
									var form_body = document.createElement( "tbody" );
									form_body.appendChild( oneCellRow( 'Got something to say about this news item? Post a comment!', null, 2, 'bold standard_text' ) );
									form_body.appendChild( twoCellRow( "Comment Text:", textarea( null, "comment_text", 10, 50, 10, "soft" ), 'standard_text', null ) );
									form_body.appendChild( oneCellRow( oneNodeSpan('Submit', null, "submitFormAJAX( 'submitComment', null, new Array( 'comment_text' ), new Array( 1, '"+xmlVal( news_item, 'id' )+"' ) )", "link" ), null, 2, 'table_style_center' ) );
		
									form_table.appendChild( form_body );
									content_body.appendChild( oneCellRow( form_table, null, null, "solid" ) );
								}
							}
						}
					}
					else
						content_body.appendChild( oneCellRow( 'No News', null, null, 'standard_text' ) );

					if( ! headlines )
					{
						if( user_level == 1 )
						{
								var form_table = document.createElement( "table" );
								var form_body = document.createElement( "tbody" );
								form_body.appendChild( oneCellRow( ( edit_news ? 'Edit this' : 'Post new' )+' News Item', null, 2, 'bold standard_text' ) );
								form_body.appendChild( twoCellRow( "Title:", formInput( 'text', 'news_title', ( edit_news ? xmlVal( edit_news, 'title' ) : null ), 70, 'bug_title' ), 'standard_text', null ) );
								var text_area = textarea( null, "news_text", 10, 50, 10, "soft" );	
								if( edit_news )
									text_area.appendChild( document.createTextNode( xmlVal( edit_news, 'text' ) ) );
								form_body.appendChild( twoCellRow( "Text:", text_area, 'standard_text', null ) );
								form_body.appendChild( oneCellRow( oneNodeSpan( ( edit_news ? 'Edit' : 'Submit' ), null, "submitFormAJAX( '"+( edit_news ? 'editNews' : 'submitNews' )+"', null, new Array( 'news_title', 'news_text' ), new Array( '"+( edit_news ? xmlVal( edit_news, 'id' ) : '' )+"' ) )", "link" ), null, 2, 'table_style_center' ) );

								form_table.appendChild( form_body );
								content_body.appendChild( oneCellRow( form_table, null, null, "solid" ) );
						}
					}
					content_table.appendChild( content_body );
					content_table.className = "w100p";
					content_cell.appendChild( content_table );
				}
			}
			function showBugs()
			{
				var content_cell = document.getElementById( "main_window" );
				clearElement( content_cell );
				content_cell.vAlign = "top";

				var content_table = document.createElement( "table" );
				var content_body = document.createElement( "tbody" );

				var bugs = xmlList( data, 'bug' );

				if( bugs.length > 0 )
				{
					var bug_table = document.createElement( "table" );
					bug_table.className = "w100p";
					var bug_tbody = document.createElement( "tbody" );
					bug_table.appendChild( bug_tbody );
					content_body.appendChild( oneCellRow( bug_table ) );

					for( var n = 0, bug; bug = bugs[n]; n++ )
					{
						var link = "defaultAJAX( 'getBugs', new Array( '"+xmlVal( bug, 'id' )+"' ) )";
						bug_tbody.appendChild( oneCellRow( nNodeSpan( oneNodeSpan( xmlVal( bug, 'title' ), null, link, 'link' ), " -- ", xmlVal( bug, 'date' ), " -- Posted By: ", xmlVal( bug, 'username' ), oneDiv( nNodeSpan( " (", xmlVal( bug, "comment_total" ), " Comments)" ), link, null, " link tab_grey no_wrap table_style_right" ) ), null, null, 'standard_text solid tab_grey' ) );
						bug_tbody.appendChild( oneCellRow( parseMessage( xmlVal( bug, 'text' ), null, true, true ), null, null, 'standard_text solid w100p' ) );

						if( bug.getAttribute( 'id' ) == 'single' )
						{
							content_body.appendChild( oneCellRow( 'Comments:', null, null, 'bold standard_text' ) );
	
							var comments = xmlList( data, 'comment' );
	
							if( comments.length > 0 )
							{
								var table = document.createElement( "table" );
								var tbody = document.createElement( "tbody" );
								for( var n = 0, comment; comment = comments[n]; n++ )
								{
									tbody.appendChild( oneCellRow( nNodeSpan( xmlVal( comment, 'date' ), " -- Posted By: ", xmlVal( comment, 'username' ) ), null, null, 'standard_text solid tab_grey' ) );
									tbody.appendChild( oneCellRow( parseMessage( xmlVal( comment, 'text' ), null, true ), null, null, 'standard_text solid w100p' ) );
								}
								table.appendChild( tbody );
								table.className = "w100p";
								content_body.appendChild( oneCellRow( table ) );
							}
							else
								content_body.appendChild( oneCellRow( 'No comments', null, null, 'bold table_style_center solid standard_text' ) );

							var form_table = document.createElement( "table" );
							var form_body = document.createElement( "tbody" );
							form_body.appendChild( oneCellRow( 'Got something to say about this bug? Post a comment!', null, 2, 'bold standard_text' ) );
							form_body.appendChild( twoCellRow( "Description:", textarea( null, "comment_text", 10, 50, 10, "soft" ), 'standard_text', null ) );
							form_body.appendChild( oneCellRow( oneNodeSpan('Submit', null, "submitFormAJAX( 'submitComment', null, new Array( 'comment_text' ), new Array( 2, '"+xmlVal( bug, 'id' )+"' ) )", "link" ), null, 2, 'table_style_center' ) );
	
							form_table.appendChild( form_body );
							content_body.appendChild( oneCellRow( form_table, null, null, "solid" ) );
						}
					}
				}
				else
					content_body.appendChild( oneCellRow( 'No bugs', null, null, 'bold table_style_center solid standard_text' ) );
				
				//if( bugs.length > 0 )
				{
					//if( bugs[0].getAttribute( 'id' ) != 'single' )
					{
						var form_table = document.createElement( "table" );
						var form_body = document.createElement( "tbody" );
						form_body.appendChild( oneCellRow( 'Found a new bug? Add it to the list!', null, 2, 'bold standard_text' ) );
						form_body.appendChild( twoCellRow( "Title:", formInput( 'text', 'bug_title', null, 70, 'bug_title' ), 'standard_text', null ) );
						form_body.appendChild( twoCellRow( "Description:", textarea( null, "bug_text", 10, 50, 10, "soft" ), 'standard_text', null ) );
						form_body.appendChild( twoCellRow( "Priority:", '', 'standard_text', null ) );
						form_body.appendChild( oneCellRow( oneNodeSpan('Submit', null, "submitFormAJAX( 'submitBug', new Array(), new Array( 'bug_title', 'bug_text' ) )", "link" ), null, 2, 'table_style_center' ) );
	
						form_table.appendChild( form_body );
						content_body.appendChild( oneCellRow( form_table, null, null, "solid" ) );
					}
				}
				content_table.appendChild( content_body );
				content_table.className = "w100p";
				content_cell.appendChild( content_table );
			}
			function showGameInfo()
			{
				clearGrid = true;

				var grid_body = document.getElementById("grid_body");
				clearElement( grid_body );

				grid_body.style.width = "90%";
				grid_body.style.cellPadding = "5px";

				var row = twoCellRow( "Game ID:", xmlval( data, "gameId" ) );
				row.className = "table_style";
				grid_body.appendChild( row );

				var row = twoCellRow( "Players:", xmlval( data, "gamePlayers" ) );
				row.className = "table_style";
				grid_body.appendChild( row );

				var row = twoCellRow( "Start Date:", xmlval( data, "gameStartTime" ) );
				row.className = "table_style";
				grid_body.appendChild( row );

				grid_body.appendChild( historyNavBar() );
			}
			function showTradeResult()
			{
				clearGrid = true;

				var grid_body = document.getElementById("grid_body");
				clearElement( grid_body );

				grid_body.appendChild( oneCellRow( xmlVal( data, "tradeData" ), null, 2, "tab_closed" ) )
				
				grid_body.appendChild( oneCellRow( "Back to Market", "getMarketData();", 2, "table_style_center link" ) );
				grid_body.appendChild( oneCellRow( "Back to Map", "refreshData();", 2, "table_style_center link" ) );				
			}
			function standardResult()
			{
				var resultData = data.getElementsByTagName("resultData")[0];

				if( resultData.hasChildNodes() )
				{
					clearGrid = true;

					var grid_body = document.getElementById("grid_body");
					clearElement( grid_body );

					grid_body.appendChild( oneCellRow( resultData.firstChild.nodeValue, null, 2, "tab_closed" ) )
					grid_body.appendChild( historyNavBar() );				
				}
				else
					refreshData();
			}

			function profileData()
			{
				view = "profile";
				clearGrid = true;
				middle_pane.vAlign = "top";
				var grid_body = document.getElementById("grid_body");
				clearElement( grid_body );

				var table = document.createElement( "table" );
				var tbody = document.createElement( "tbody" );

				xmlData['profile'] = xmlVal( data, "profileData" );
				if( xmlData['profile'] )
				{
					var profile_type = xmlVal( xmlData['profile'], "profile_type" );
					var profile_type_name =  xmlVal( xmlData['profile'], "profile_type_name" );
					var profile_id = xmlVal( xmlData['profile'], "profile_id" );
					var profile_age = xmlVal( xmlData['profile'], "profile_age" );
					var profile_relation = xmlVal( xmlData['profile'], "profile_relation" );

					var relations = new Array();
					relations[1] = 'You';
					relations[2] = 'Guildmate';
					relations[3] = 'Ally';
					relations[4] = 'Enemy';
					relations[5] = 'NAP';
					relations[6] = 'Neutral';

					if( profile_type == "player" )
					{
						var profile_name = xmlVal( xmlData['profile'], "profile_name" );
						var profile_bio = xmlVal( xmlData['profile'], "profile_bio" );

						var guild_name = xmlVal( xmlData['profile'], "guild_name" );
						var guild_id = xmlVal( xmlData['profile'], "guild_id" );
						var relation = ( guild_id && profile_relation  ? " ["+relations[profile_relation]+"]" : '' );

						tbody.appendChild( twoCellRow( "Name:", profile_name, "standard_text", "standard_text" ) );
						tbody.appendChild( twoCellRow( "Age:", profile_age, "standard_text", "standard_text" ) );
						tbody.appendChild( twoCellRow( "Guild:", nNodeSpan( oneNodeSpan( guild_name, null, ( guild_id ? "defaultAJAX( 'profileData', new Array( '"+guild_id+"' ), new Array( 'g' ), 'Profile: guild' )" : null ), ( guild_id ? "link" : null ) ), relation ), "standard_text", "standard_text" ) );

						table.appendChild( tbody );
						var cell2 = oneCell( table );
						cell2.style.width = "100%";

						var cell1 = oneCell( makeImg( './img/'+profile_type+profile_relation+'.gif', 60, 60 ) );
						cell1.style.backgroundImage = "url('./img/large/template.gif')";
						cell1.className = "no_rep back_center";
						cell1.style.width = 60;
						var header = nCellRow( cell1, cell2 );
	
						var tbody = document.createElement( "tbody" );

						if( profile_relation != 1 )
						{
							tbody.appendChild( nCellRow( oneCell( nNodeSpan( makeImg( './img/mail.gif'), " Send Message" ), "writeMail( '"+profile_name+"' )", null, "table_style_center link" ), oneCell( "Add to Friends List", "defaultAJAX( 'addCommunity', new Array( '"+profile_id+"' ), new Array( 'P', 'f' ), null )", null, "table_style_center link" ) ) );
							tbody.appendChild( nCellRow( oneCell( "something", "", null, "table_style_center link" ), oneCell( "Add to Ignore List", "defaultAJAX( 'addCommunity', new Array( '"+profile_id+"' ), new Array( 'P', 'i' ), null )", null, "table_style_center link" ) ) );
						}
						tbody.appendChild( oneCellRow( "Bio:", null, 2, "table_style_left") );
						tbody.appendChild( oneCellRow( profile_bio, null, 2, "standard_text" ) );
						tbody.appendChild( oneCellRow( " ", null, 2, "table_style_left") );
						tbody.appendChild( oneCellRow( "Goal Achievements:", null, 2, "table_style_left") );
						if( profile_relation == 1 )
							tbody.appendChild( oneCellRow( rulesTable( xmlVal( xmlData['profile'], "Rules" ), 1, 1 ), null, 2, null ) );

						var body = scrollWindow( tbody, 490, 200 );
						var temp_scroll = true;
					}
					else if( profile_type == "guild" )
					{
						var profile_name = xmlVal( xmlData['profile'], "profile_name");

						tbody.appendChild( twoCellRow( "Guild Name:", profile_name, "standard_text", "standard_text" ) );
						tbody.appendChild( twoCellRow( "Age:", profile_age, "standard_text", "standard_text" ) );
						tbody.appendChild( twoCellRow( "Diplomacy:", relations[profile_relation], "standard_text", "standard_text" ) );

						table.appendChild( tbody );
						var cell2 = oneCell( table );
						cell2.style.width = "100%";

						var cell1 = oneCell( makeImg( './img/x_close.gif', 60, 60 ) );
						//cell1.style.backgroundImage = "url('./img/large/template.gif')";
						cell1.className = "no_rep back_center";
						cell1.style.width = 60;
						var header = nCellRow( cell1, cell2 );
	
						var tbody = document.createElement( "tbody" );

						var members = xmlVal( xmlData['profile'], "member" );

						if( profile_relation == 2 )
						{
							tbody.appendChild( oneCellRow( oneNodeSpan( "Guild Member Tools", null, "guildTools()", "link" ), null, 2, "table_style_center", "guild_edit" ) );
							tbody.appendChild( oneCellRow( document.createElement( "hr" ), null, 2, null ) );
						}
						else if( xmlVal( xmlData['profile'], "relGuildDip" ) == 1 )
						{
							tbody.appendChild( oneCellRow( "MyGuild Diplomacy:", null, 2, "standard_text" ) );
							if( profile_relation == 3 )
								tbody.appendChild( oneCellRow( oneNodeSpan( "Break Alliance!", null, "defaultAJAX( 'deleteCommunity', new Array( '"+null+"' ), new Array() )", "link" ), null, 2, "table_style_center" ) );
							else
								tbody.appendChild( twoCellRow( oneCell( oneNodeSpan( "Make "+profile_name+" an Ally!", null, "defaultAJAX( 'addCommunity', new Array( '"+profile_id+"' ), new Array( 'G', 'a' ) )", "link" ) ), oneCell( oneNodeSpan( "Declare "+profile_name+" an Enemy!", null, "defaultAJAX( 'addCommunity', new Array( '"+profile_id+"' ), new Array( 'G', 'e' ) )", "link" ) ), "table_style_center", "table_style_center" ) );
							tbody.appendChild( oneCellRow( document.createElement( "hr" ), null, 2, null ) );
						}
						var member_count = xmlVal( xmlData['profile'], "member_count" );

						tbody.appendChild( oneCellRow( nNodeSpan( "Members:", " (", member_count, " member", ( member_count > 1 ? 's' : '' ), ")" ), null, 2, "table_style" ) );
						for( var m = 0, member; member = members[m]; m++ )
						{
							var mem_id = member.getElementsByTagName( "member_id" )[0].firstChild.nodeValue;
							
							tbody.appendChild( oneCellRow( oneNodeSpan( xmlVal( member, "member_name" ), null, "defaultAJAX( 'profileData', new Array( '"+mem_id+"' ), new Array( 'p' ), 'Profile: player' )", "link" ), null, 2, "table_style" ) );
						}
						tbody.appendChild( oneCellRow( document.createElement( "hr" ), null, 2, null ) );
						tbody.appendChild( oneCellRow( rulesTable( xmlVal( xmlData['profile'], "Rules" ), xmlVal( xmlData['profile'], "manGuildDip" ), 2 ), null, 2, null ) );

						var body = scrollWindow( tbody, 490, 200 );
						var temp_scroll = true;
					}
					else if( profile_type == "structure" )
					{
						var profile_name = xmlVal( xmlData['profile'], "profile_name" );
						var profile_name = ( profile_name ? profile_name : "[debug]" );
						var profile_age = xmlVal( xmlData['profile'], "profile_age" );

						var guild_name = xmlVal( xmlData['profile'], "guild_name" );
						var guild_id = xmlVal( xmlData['profile'], "guild_id" );
						var relation = ( guild_id && profile_relation != "n/a" ? " ["+( profile_relation == 1 ? 'Member' : relations[profile_relation])+"]" : '' );

						tbody.appendChild( twoCellRow( "Name:", profile_name, "standard_text", "standard_text" ) );
						tbody.appendChild( twoCellRow( "Age:", profile_age, "standard_text", "standard_text" ) );
						tbody.appendChild( twoCellRow( "Diplomacy:", relations[profile_relation], "standard_text", "standard_text" ) );

						table.appendChild( tbody );
						var cell2 = oneCell( table );
						cell2.style.width = "100%";

						var cell1 = oneCell( makeImg( './img/'+profile_type_name+profile_relation+'.gif', 60, 60 ) );
						cell1.style.backgroundImage = "url('./img/large/template.gif')";
						cell1.className = "no_rep back_center";
						cell1.style.width = 60;
						var header = nCellRow( cell1, cell2 );
	
						var tbody = document.createElement( "tbody" );

						owner_name = xmlVal( xmlData['profile'], "owner_name" );
						owner_id = xmlVal( xmlData['profile'], "owner_id" );
						owner_type = xmlVal( xmlData['profile'], "owner_type" );

						tbody.appendChild( twoCellRow( "Owner:", oneNodeSpan( owner_name, null, "defaultAJAX( 'profileData', new Array( '"+owner_id+"' ), new Array( '"+owner_type.substring( 0, 1 )+"' ), 'Profile: "+owner_type+"' )", "link" ), "table_style_left", "table_style_right" ) );

						tbody.appendChild( twoCellRow( "Guild:", nNodeSpan( oneNodeSpan( guild_name, null, ( guild_id ? "defaultAJAX( 'profileData', new Array( '"+guild_id+"' ), new Array( 'g' ), 'Profile: guild' )" : null ), ( guild_id ? "link" : null ) ), relation ), "table_style_left", "table_style_right" ) );

						tbody.appendChild( twoCellRow( "Location:", xmlVal( xmlData['profile'], "profile_position" ), "table_style_left", "table_style_right" ) );

						if( profile_type_name == "mine" )
						{
							//mine specifics
						}
						else if( profile_type_name == "siegecamp" )
						{
							//siege specifics
						}
						else if( profile_type_name == "tower" )
						{
							var tMax = xmlVal( xmlData['profile'], "profile_tileOwner_max" );
							var tCount = xmlVal( xmlData['profile'], "profile_tileOwner_count" );
							var tPer =  Math.round( ( tCount / tMax ) * 100 )+"%";
							tbody.appendChild( twoCellRow( "Land Ownership:", tCount+"/"+tMax+" tiles ("+tPer+")", "table_style_left", "table_style_right" ) );
						}

						var tbody2 = document.createElement( "tbody" );
						var manStruct = xmlVal( xmlData['profile'], "manStruct" );
						var manInv = xmlVal( xmlData['profile'], "manInv" );
						if( manStruct )
							tbody2.appendChild( twoCellRow( oneNodeSpan( "Remove Structure", null, "defaultAJAX( 'deleteStructure', new Array( '"+profile_id+"' ), new Array(), null, null, null, null, 'Removing structure. Please wait, our demo men are lazy too...', 'backtrack' )" , "link table_style_center" ), oneNodeSpan( "Rename Structure", null, "renameStructureDialog( "+profile_id+", '"+profile_name+"' )", "link  table_style" ) ), "table_style_center", "table_style_center" );
						if( manInv )
						{
							var equip = document.createElement( "tbody" );

							updateSlotList( equip, xmlVal( xmlData['profile'], "equipment" ), 'inventory', profile_id, 'struct' );
							var table = document.createElement( "table" );
							table.appendChild( equip );
							table.cellSpacing = 1;
							table.cellPadding = 0;
							table.style.backgroundColor = "black";
	
							tbody2.appendChild( twoCellRow( oneNodeSpan( "Inventory", null, "defaultAJAX( 'inventoryData', new Array( '"+profile_id+"' ), new Array( 'r', 'struct' ), 'Inventory: Resources', new Array( new Array( 'view2', 'resources' ) ) )", "link" ), oneNodeSpan( table ), "table_style_center", "table_style_right" ) );
						}
						if( manStruct )
						{
							var npcs = document.createElement( "tbody" );

							updateSlotList( npcs, xmlVal( xmlData['profile'], "npcs" ), 'npc', profile_id, 'struct' );
							var table = document.createElement( "table" );
							table.appendChild( npcs );
							table.cellSpacing = 1;
							table.cellPadding = 0;
							table.style.backgroundColor = "black";
	
							tbody2.appendChild( twoCellRow( oneNodeSpan( "NPC Units", null, "defaultAJAX( 'npcData', new Array( '"+profile_id+"' ), new Array( 'struct' ) )", "link" ), oneNodeSpan( table ), "table_style_center", "table_style_right" ) );

							tbody2.appendChild( oneCellRow( document.createElement("hr"), null, 2, null ) );

							tbody2.appendChild( oneCellRow( "Attributes:", null, 2, "table_style_left" ) );

							var att = xmlList( xmlData['profile'], "attribute" );
							if( att.length > 0 )
							{
								for( var a = 0; a < att.length; a++ )
								{
									var attribute = att[a];
									var a_name = xmlVal( attribute, "name" );
									var a_value = xmlVal( attribute, "value" );
									a_value = ( a_value ? a_value : "[debug]" );
	
									tbody2.appendChild( twoCellRow( a_name+":", a_value, "table_style_center", "table_style_center" ) );
								}
							}
							else
								tbody2.appendChild( oneCellRow( "None", null, 2, "table_style_center" ) );

							tbody2.appendChild( oneCellRow( "Advancement Options", "structureAdvList( "+profile_id+" )", 2, "table_style_left link" ) );

						}

						var table = document.createElement( "table" );
						table.appendChild( tbody2 );
						table.style.width = "100%";
						tbody.appendChild( oneCellRow( table, null, 2, "table_style", "tower_toolbox") );

						if( profile_type_name == "mine" )
						{
							//mine specifics
						}
						else if( profile_type_name == "siegecamp" )
						{
							//siege specifics
						}
						else if( profile_type_name == "tower" )
						{

							tbody.appendChild( oneCellRow( document.createElement( "hr" ), null, 2, null ) );
							tbody.appendChild( oneCellRow( "Competitors", null, 2, "table_style_center" ) );

							var competitors = xmlList( xmlData['profile'], "competitor" );
							if( competitors.length > 0 )
							{
								for( var c = 0, comp; comp = competitors[c]; c++ )
								{
									var id = xmlVal( comp, "id" );
									var name = xmlVal( comp, "name" );
									var x = xmlVal( comp, "x" );
									var y = xmlVal( comp, "y" );
									var tile_count = xmlVal( comp, "tile_count" );
									var owner_tile_count1 = xmlVal( comp, "owner_tile_count1" );
									var owner_tile_count2 = xmlVal( comp, "owner_tile_count2" );
									var ownerTile = '';
									if( owner_tile_count1 && owner_tile_count2 )
									{
										var ownerTile = nNodeSpan( "( ", oneNodeSpan( ( owner_tile_count1 > 0 ? owner_tile_count1 : '0' ), null, null, "bold blue" ), " | ", oneNodeSpan( (owner_tile_count2 > 0 ? owner_tile_count2 : '0' ), null, null, "bold red" ), " )" );
									}
									var table = document.createElement( "table" );
									var tbody3 = document.createElement( "tbody" );
									tbody3.id = "comp"+c;

									tbody3.appendChild( oneCellRow( nNodeSpan( oneNodeSpan( name, null, "defaultAJAX( 'profileData', new Array( '"+id+"' ), new Array( 's' ), 'Profile: structure' )", "link" ), "  ( "+x+", "+y+" ) ", " [ ", oneNodeSpan( tile_count+" tiles ", null, "defaultAJAX( 'contestMap', new Array( "+profile_id+", "+id+"), null, 'Contest Map' )", "link" ), ownerTile, " ]", makeImg( "./img/examine.gif", 12, 10, "comp"+c+"Img", "View Details", "showContest( "+c+", "+profile_relation+", '"+profile_name+"', '"+profile_id+"' )", "link" ) ), null, 2, "w100p standard_text" ) );
									table.appendChild( tbody3 );
									tbody.appendChild( oneCellRow( table, null, 2, "standard_text" ) );
								}
							}
							else
								tbody.appendChild( oneCellRow( "None", null, 2, "table_style_center standard_text" ) );
						}

						tbody.appendChild( oneCellRow( document.createElement( "hr" ), null, 2, null ) );

						var body = scrollWindow( tbody, 490, 200 );
						var temp_scroll = true;
					}
					if( body )
						defaultDisplayTable( grid_body, header, body, null, true, 520, 220 );
				}

				grid_body.appendChild( historyNavBar() );

				if( temp_scroll )
					scroll();			

			}
			function rulesTable( rulesData, man_rules, owner_type )
			{
				var m_table = document.createElement( "table" );
				var m_tbody = document.createElement( "tbody" );
				
					var table1 = document.createElement( "table" );
						var tbody = document.createElement( "tbody" );

							var row = document.createElement( "tr" );
							row.appendChild( oneCell( '' ) );
							row.appendChild( oneCell( 'Guild', ( man_rules ? "ruleElements( this, null, 2, null, null, "+owner_type+" )" : null ), null, "standard_text solid", "r_r2" ) );
							row.appendChild( oneCell( 'Ally', ( man_rules ? "ruleElements( this, null, 3, null, null, "+owner_type+" )" : null ), null, "standard_text solid", "r_r3" ) );
							row.appendChild( oneCell( 'Enemy', ( man_rules ? "ruleElements( this, null, 4, null, null, "+owner_type+" )" : null ), null, "standard_text solid", "r_r4" ) );
							row.appendChild( oneCell( 'NAP', ( man_rules ? "ruleElements( this, null, 5, null, null, "+owner_type+" )" : null ), null, "standard_text solid", "r_r5" ) );
							row.appendChild( oneCell( 'Neutral', ( man_rules ? "ruleElements( this, null, 6, null, null, "+owner_type+" )" : null ), null, "standard_text solid", "r_r6" ) );
							tbody.appendChild( row );

							if( rulesData )
							{
								var rules = xmlList( rulesData, "genRule" );
								for( var r = 0, rule; rule = rules[r]; r++ )
								{
									var row = document.createElement( "tr" );
									row.appendChild( oneCell( xmlVal( rule, "name" ), null, null, "standard_text solid" ) );

									row.appendChild( oneCell( parseRule( xmlVal( xmlVal( rule, "guild" ), 'val' ) ), ( man_rules ? "ruleElements( this, 'genRule', 2, "+xmlVal( rule, "id" )+", '"+r+"', "+owner_type+" )" : null ), null, "stantard_text center solid"+( xmlVal( xmlVal( rule, "guild" ), 'type' ) == 2 ? ' back_cyan' : ( xmlVal( xmlVal( rule, "guild" ), 'type' ) == 1 ? ' back_blue' : '' ) ), "r_2_"+(parseInt(r)+1) ) );
									row.appendChild( oneCell( parseRule( xmlVal( xmlVal( rule, "ally" ), 'val' ) ), ( man_rules ? "ruleElements( this, 'genRule', 3, "+xmlVal( rule, "id" )+", '"+r+"', "+owner_type+" )" : null ), null, "stantard_text center solid"+( xmlVal( xmlVal( rule, "ally" ), 'type' ) == 2 ? ' back_cyan' : ( xmlVal( xmlVal( rule, "ally" ), 'type' ) == 1 ? ' back_blue' : '' ) ), "r_3_"+(parseInt(r)+1) ) );
									row.appendChild( oneCell( parseRule( xmlVal( xmlVal( rule, "enemy" ), 'val' ) ), ( man_rules ? "ruleElements( this, 'genRule', 4, "+xmlVal( rule, "id" )+", '"+r+"', "+owner_type+" )" : null ), null, "stantard_text center solid"+( xmlVal( xmlVal( rule, "enemy" ), 'type' ) == 2 ? ' back_cyan' : ( xmlVal( xmlVal( rule, "enemy" ), 'type' ) == 1 ? ' back_blue' : '' ) ), "r_4_"+(parseInt(r)+1) ) );
									row.appendChild( oneCell( parseRule( xmlVal( xmlVal( rule, "nap" ), 'val' ) ), ( man_rules ? "ruleElements( this, 'genRule', 5, "+xmlVal( rule, "id" )+", '"+r+"', "+owner_type+" )" : null ), null, "stantard_text center solid"+( xmlVal( xmlVal( rule, "nap" ), 'type' ) == 2 ? ' back_cyan' : ( xmlVal( xmlVal( rule, "nap" ), 'type' ) == 1 ? ' back_blue' : '' ) ), "r_5_"+(parseInt(r)+1) ) );
									row.appendChild( oneCell( parseRule( xmlVal( xmlVal( rule, "neutral" ), 'val' ) ), ( man_rules ? "ruleElements( this, 'genRule', 6, "+xmlVal( rule, "id" )+", '"+r+"', "+owner_type+" )" : null ), null, "stantard_text center solid"+( xmlVal( xmlVal( rule, "neutral" ), 'type' ) == 2 ? ' back_cyan' : ( xmlVal( xmlVal( rule, "neutral" ), 'type' ) == 1 ? ' back_blue' : '' ) ), "r_6_"+(parseInt(r)+1) ) );

									row.ClassName = "solid";
									tbody.appendChild( row );
								}
							}
				
					table1.appendChild( tbody );
					table1.className = "solid";

					var table2 = document.createElement( "table" );
						var tbody = document.createElement( "tbody" );

						if( man_rules )
						{
							var table3 = document.createElement( "table" );
							var tbody3 = document.createElement( "tbody" );

							table3.id = "rule_tools_table";
							tbody3.id = "rule_tools";

							table3.appendChild( tbody3 );	
							tbody.appendChild( oneCellRow( table3 ) );
							var tab2_text = "debug";
						}
					/*
						else
						{

							if( rulesData )
							{
								var tab2_text = "Specific Guild Rules:";
								var row = document.createElement( "tr" );
								row.appendChild( oneCell( 'Me', null, null, "standard_text solid" ) );
								row.appendChild( oneCell( 'My Guild', null, null, "standard_text solid" ) );
								tbody.appendChild( row );

								var my_rules = xmlVal( rulesData, "my_rules" );

								var row = document.createElement( "tr" );

								var rules = xmlVal( my_rules, "myRule" );
								row.appendChild( oneCell( parseRule( xmlVal( rule, "me" ) ), null, null, "stantard_text center solid" ) );
								row.appendChild( oneCell( parseRule( xmlVal( rule, "myguild" ) ), null, null, "stantard_text center solid" ) );

								row.ClassName = "solid";
								tbody.appendChild( row );
								
							}

						}
					*/
					table2.appendChild( tbody );
					//table2.className = "solid";

				m_tbody.appendChild( twoCellRow( "General Guild Diplomacy Rules:", tab2_text, "standard_text", "standard_text" ) )
				m_tbody.appendChild( twoCellRow( table1, table2 ) );
				m_table.appendChild( m_tbody );
				return m_table;
			}
			function ruleElements( element, rule_type, rel, action, r, owner_type )
			{
				if( isNaN( parseInt( element.id.substring( 2, 3 ) ) ) )
				{
					var dip = element.id.substring( 3 );

					var array = new Array();
					//array[0] = element;
					for( var x = 1; x <= 6; x++ )
					{
						var ele = document.getElementById( "r_"+dip+"_"+x );
						if( ele )
							array[array.length] = ele;
					}
					selectBlinkElement( array );
				}
				else
				{
					selectBlinkElement( element );
				}

				var rule_tools = document.getElementById( "rule_tools" );
				var rule_tools_table = document.getElementById( "rule_tools_table" );

				if( r && rule_type )
				{
					var rule = xmlList( xmlVal( xmlData['profile'], "Rules" ), rule_type )[r];
					var rel_array = new Array( null, null, 'guild', 'ally', 'enemy', 'nap', 'neutral' );
					var rules_options = xmlVal( rule, 'options' ).split( '' );
				}
				else
					rules_options = new Array( 1, 1, 0, 0, 0 );
				if( blinkOn && rule_tools )
				{
					clearElement( rule_tools );

					var row = document.createElement( "tr" );
					if( rules_options[0] == 1 )
						row.appendChild( oneCell( makeImg( './img/no.gif' ), null, null, "center" ) );
					if( rules_options[1] == 1 )
						row.appendChild( oneCell( makeImg( './img/yes.gif' ), null, null, "center" ) );
					if( rules_options[2] == 1 )
						row.appendChild( oneCell( '%', null, null, "standard_text center" ) );
					if( rules_options[4] == 1 )
						row.appendChild( oneCell( makeImg( './img/fight.gif' ), null, null, "center" ) );
					if( owner_type == 1 )
						row.appendChild( oneCell( 'G', null, null, "standard_text center" ) );

					row.className = "solid";

					rule_tools.appendChild( row );
					
					var row = document.createElement( "tr" );
					if( rules_options[0] == 1 )
						row.appendChild( oneCell( formInput( "radio", "rule_radio", 0, null, "rule_radio", ( rule && !dip ? ( xmlVal( rule, rel_array[rel] ) <= 0 ? true : false ) : false ) ) ) );
					if( rules_options[1] == 1 )
						row.appendChild( oneCell( formInput( "radio", "rule_radio", 1, null, "rule_radio", ( rule && !dip ? ( xmlVal( rule, rel_array[rel] ) == 1 ? true : false ) : false ) ) ) );
					if( rules_options[2] == 1 )
						row.appendChild( oneCell( nNodeSpan( formInput( "radio", "rule_radio", 2, null, "rule_radio", ( rule && !dip ? ( xmlVal( rule, rel_array[rel] ) == 2 ? true : false ) : false ) ), formInput( "text", "debug3", 1, 2, "debug3") ) ) );
					if( rules_options[4] == 1 )
						row.appendChild( oneCell( formInput( "radio", "rule_radio", 4, null, "rule_radio", ( rule && !dip ? ( xmlVal( rule, rel_array[rel] ) == 4 ? true : false ) : false ) ) ) );
					if( owner_type == 1 )
						row.appendChild( oneCell( formInput( "radio", "rule_radio", -1, null, "rule_radio", false ) ) );

					row.className = "solid";
					var span = parseInt(rules_options[0]) + parseInt(rules_options[1]) + parseInt(rules_options[2]) + parseInt(rules_options[3]) + parseInt(rules_options[4]);
					rule_tools.appendChild( row );
					rule_tools.appendChild( oneCellRow( "Update", "submitFormAJAX( 'updateRules', new Array( new Array( 'radio', 'rule_radio' ) ), null, new Array( "+rel+", "+action+", "+owner_type+" ) )", span, "standard_text link solid center" ) );
					rule_tools_table.className = "solid";
				}
				else
				{
					clearElement( rule_tools );
					rule_tools_table.className = null;
				}
			}
			function parseRule( rule )
			{
				var element;
				switch( parseInt( rule ) )
				{
					case 1:
						element = makeImg( './img/yes.gif' );
						break;
					case 2:
						element = 'cut';
						break;
					case 3:
						element = '$';
						break;
					case 4:
						element = makeImg( './img/fight.gif' );
						break;
					default:
						element = makeImg( './img/no.gif' );
						break;
				}

				return element;
			}
			function showContest( c, p_rel, p_name, p_id )
			{
				var body = document.getElementById( "comp"+c );
				if( body.childNodes.length == 1 )
				{
					var comps = xmlList( xmlData['profile'], "competitor" );
					var comp = comps[c];
					if( comp )
					{
						var table = document.createElement( "table" );
						var tbody = document.createElement( "tbody" );
						var row = document.createElement( "tr" );

							var table2 = document.createElement( "table" );
							var tbody2 = document.createElement( "tbody" );

							var s_type1 = true;
							var struct_type1 = ( s_type1 ? "tower" : "siegecamp" );
								tbody2.appendChild( oneCellRow( makeImg( './img/'+struct_type1+p_rel+'.gif', 60, 60 ), null, null, "table_style_center" ) );
								tbody2.appendChild( oneCellRow( p_name, null, null, "table_style_center" ) );

									var equip = document.createElement( "tbody" );
									var intel = xmlVal( data, "profile_intel" );
									var equip_list = xmlVal( intel, "equipment" );

									updateSlotList( equip, equip_list );

									var table3 = document.createElement( "table" );
									table3.appendChild( equip );
									table3.cellSpacing = 1;
									table3.cellPadding = 0;
									table3.style.backgroundColor = "black";
						
									tbody2.appendChild( oneCellRow( table3, null, null, "center" ) );
		
								tbody2.appendChild( oneCellRow( "Intel Age: "+xmlVal( intel, "intel_age" ), null, null, "table_style_center" ) );
								var run = xmlVal( comp, "profileRun" );
								tbody2.appendChild( oneCellRow( nNodeSpan( "Winning streak: ", ( run ? run : '' ) ), null, null, "table_style_center" ) );
		
							table2.appendChild( tbody2 );
							table2.cellPadding = 0;
							table2.cellSpacing = 0;

						var cell = oneCell( table2, null, null, "table_style_center" );
						cell.style.width = 120;
						row.appendChild( cell );

						row.appendChild( oneCell( "Vs.", null, null, "table_style_center w100p" ) );

							var table2 = document.createElement( "table" );
							var tbody2 = document.createElement( "tbody" );

							var s_type2 = xmlVal( comp,  "comp_type_name" );
								tbody2.appendChild( oneCellRow( makeImg( './img/'+s_type2+xmlVal( comp, "owner_rel" )+'.gif', 60, 60 ), null, null, "table_style_center" ) );
								tbody2.appendChild( oneCellRow( xmlVal( comp, "name" ), null, null, "table_style_center" ) );

									var equip = document.createElement( "tbody" );
									var equip_list = xmlVal( comp, "c_equipment" );

									updateSlotList( equip, equip_list );

									var table3 = document.createElement( "table" );
									table3.appendChild( equip );
									table3.cellSpacing = 1;
									table3.cellPadding = 0;
									table3.style.backgroundColor = "black";

									tbody2.appendChild( oneCellRow( table3, null, null, "center" ) );

								tbody2.appendChild( oneCellRow( "Intel Age: "+xmlVal( comp, "intel_age" ), null, null, "table_style_center" ) );
								var run = xmlVal( comp, "competitorRun" );
								tbody2.appendChild( oneCellRow( nNodeSpan( "Winning streak: ", ( run ? run : '' ) ), null, null, "table_style_center" ) );						
							table2.appendChild( tbody2 );
							table2.cellPadding = 0;
							table2.cellSpacing = 0;

						var cell = oneCell( table2, null, null, "table_style_center" );
						cell.style.width = 120;
						row.appendChild( cell );

						tbody.appendChild( row );

						var comp_time = comp.getElementsByTagName( "timestamp" )[0].firstChild.nodeValue;
						tbody.appendChild( oneCellRow( "Next contest in: "+comp_time , null, 3, "table_style_center" ) );
						var comp_id = xmlVal( comp, "comp_id" );
						tbody.appendChild( oneCellRow( "[debug: force contest check]" , "defaultAJAX( 'debugContest', new Array( "+comp_id+", "+p_id+" ), null, null )", 3, "table_style_center link" ) );

						table.appendChild( tbody );
						table.border=0;
						table.cellPadding = 0;
						table.cellSpacing = 0;
						table.className = "w100p";
						body.appendChild( oneCellRow( table, null, 2, "table_style w100p tab_border" ) );
					}
				}
				else
				{
					while( body.childNodes.length > 1 )
					{
						body.removeChild( body.childNodes[1] );
					}	
				}
				scroll();
			}
			function structureAdvList( tower )
			{
				var table = document.createElement( "table" );
				table.cellPadding = 0;
				table.cellSpacing = 0;
				var tbody = document.createElement( "tbody" );

				var row = document.createElement( "tr" );
				row.appendChild( oneCell( "Name:", null, null, "standard_text bold" ) ); 
				row.appendChild( oneCell( "Cost:", null, 2, "standard_text bold" ) ); 
				row.appendChild( oneCell( "Time:", null, null, "standard_text bold" ) ); 
				var cell = oneCell( makeImg( "./img/x_close.gif", 9, 9, null, null, "killFloatDiv();", "link" ), null, null, null );
				cell.style.textAlign = "right";
				row.appendChild( cell );

				tbody.appendChild( row );
				tbody.appendChild( oneCellRow( document.createElement( "hr" ), null, 5, null ) );

				var advOptions = xmlVal( xmlData['profile'], "advOptions" );
				var options = xmlList( advOptions, "option" );

				if( options )
				{
					if( options.length > 0 )
					{
						for( var o = 0, option; option = options[o]; o++ )
						{
							var row = document.createElement( "tr" );

							row.appendChild( oneCell( xmlVal( option, "name" )+" ("+xmlVal( option, "adv_lvl" )+") ", null, null, "standard_text bold" ) );
							var cell = oneCell( "[ ", null, null, "standard_text" );

							var costs = xmlVal( option, "cost" );
							var resources = xmlList( costs, "resource" );

							//var flag = null;
							var master_flag = false;
							for( var r = 0, res; res = resources[r]; r++ )
							{
								var flag = xmlVal( res, "flag" );
								if( ! master_flag )
									master_flag = ( flag ? true : false );
								var span = nNodeSpan( makeImg( './img/res'+xmlVal( res, "name" )+'.gif' ), " ", oneNodeSpan( xmlVal( res, "quant" ), null, null, ( flag == 2 ? "red bold" : '' ) ), "," );
								if( flag == 1 )
									span.className = "back_red";
								cell.appendChild( span );
							}

							row.appendChild( cell );
							row.appendChild( oneCell( xmlVal( option, "adv_turns" )+" turns ]", null, null, "standard_text" ) );
							row.appendChild( oneCell( xmlVal( option, "adv_time" ), null, null, "standard_text" ) );
							row.appendChild( oneCell( ( master_flag ? '' : nNodeSpan( "[ ", oneNodeSpan( "Adv.", null, "defaultAJAX( 'structureAdv', new Array( '"+tower+"', '"+xmlVal( option, "id" )+"' ), null, null );", "link" ), " ]" ) ), null, null, "standard_text" ) );

							tbody.appendChild( row );
						}
					}
				}
				else
					tbody.appendChild( oneCellRow( "No Adv Options", null, null, "standard_text" ) );
				
				table.appendChild( tbody );
				table.cellSpacing = 2;
				table.cellPadding = 1;

				displayFloatDiv( table, true );
			}
			function guildTools()
			{
				var table = document.createElement( "table" );
				table.cellPadding = 0;
				table.cellSpacing = 0;
				var tbody = document.createElement( "tbody" );

				var cell = oneCellRow( makeImg( "./img/x_close.gif", 9, 9, null, null, "killFloatDiv();", "link" ), null, 2, null );
				cell.style.textAlign = "right";
				tbody.appendChild( cell );

				tbody.appendChild( oneCellRow( oneNodeSpan( "Leave Guild", null, "defaultAJAX( 'guildRemove', null, null, null );", "link" ), null, 2, "standard_text" ) );
				tbody.appendChild( oneCellRow( oneNodeSpan( "Guild Diplomacy", null, "defaultAJAX( 'communityData', new Array(), new Array( 'a' ), 'Community: Guild', new Array( new Array( 'view1', 'guild' ), new Array( 'view2', 'ally' ) ), null );", "link" ), null, 2, "standard_text" ) );
				tbody.appendChild( oneCellRow( oneNodeSpan( "Send Invite", null, "guildInviteDialog();", "link" ), null, null, "standard_text" ) );
				table.appendChild( tbody );

				displayFloatDiv( table );
			}
			function guildInviteDialog()
			{
				killFloatDiv();
				var master_cell = document.getElementById( "guild_edit" );
				clearElement( master_cell );

				var table = document.createElement( "table" );
				var tbody = document.createElement( "tbody" );

				tbody.appendChild( oneCellRow( document.createElement( "hr" ), null, 2, "table_style_center w100p" ) );
				tbody.appendChild( oneCellRow( "Enter Name of Player to Invite", null, 2, "table_style_center w100p" ) );
				tbody.appendChild( oneCellRow( formInput( 'text', 'invitee_name', null, 30, 'invitee_name' ), null, 2, "table_style_center w100p" ) );
				tbody.appendChild( oneCellRow( nNodeSpan( "[", oneNodeSpan( "Send Invite", null, "submitFormAJAX( 'guildInvite', null, new Array( 'invitee_name' ) )", "link" ), "] [", oneNodeSpan( "Cancel", null, "guildToolsLink()", "link" ), "]" ), null, 2, "table_style_center" ) );

				table.appendChild( tbody );
				table.className = "table_Style_center w100p";
				master_cell.appendChild( table );
			}
			function guildToolsLink()
			{
				killFloatDiv();
				var master_cell = document.getElementById( "guild_edit" );
				clearElement( master_cell );
				master_cell.appendChild( nNodeSpan( "[", oneNodeSpan( 'Guild Member Tools', null, "guildTools()", "link" ), "]" ) );

			}
			function renameStructureDialog( profile_id, profile_name )
			{
				var master_cell = document.getElementById( "tower_toolbox" );
				clearElement( master_cell );

				var table = document.createElement( "table" );
				var tbody = document.createElement( "tbody" );

				tbody.appendChild( oneCellRow( document.createElement( "hr" ), null, 2, "table_style_center w100p" ) );
				tbody.appendChild( oneCellRow( formInput( 'text', 'struct_name', profile_name, 30, 'struct_name' ), null, 2, "table_style_center" ) );
				tbody.appendChild( oneCellRow( oneNodeSpan( "Submit New Structure Name", null, "submitFormAJAX( 'renameStructure', new Array(), new Array( 'struct_name' ), new Array( '"+profile_id+"' ) );", "link" ), null, 2, "table_style_center" ) );

				table.appendChild( tbody );
				master_cell.appendChild( table );

				scroll();
			}
			function showCommunityData()
			{
				clearGrid = true;
				middle_pane.vAlign = "top";
				var grid_body = document.getElementById("grid_body");
				clearElement( grid_body );

				checkView( 'view1', 'user', 'guild');

				if( views['view1'] == "guild" )
					checkView( 'view2', 'ally', 'nap', 'enemy' );
				else
					checkView( 'view2', 'friends', 'ignore' );

				var body_span = 2;
				var guild_id = null;
				if( views['view1'] == "guild" )
				{
					guild_id = xmlVal( data, "guild_id" );
		
					if( guild_id )
						var body_span = 3;
				}

				var tbody = document.createElement("tbody");

				if( views['view1'] == "guild" && ! guild_id )
					tbody = getInvitesTable();
				else
				{
					var contentBody = getCommunityTable();
					var body2 = scrollWindow( contentBody, 490, ( views['view1'] == "guild" ? 170 : 200 ) );	
					var str = views['view2'];
					defaultDisplayTable( tbody, oneCellRow( newTabs( "tabs2" ) ), body2, new Array( 'communityData', new Array(), new Array( str.substring(0, 1 ) ) ), null, 515, 200, body_span );
				}

				if( views['view1'] == "guild" )
				{
					var tbody2 = document.createElement("tbody");

					if( guild_id )
					{
						tbody2.appendChild( twoCellRow( oneCell( nNodeSpan( "Guild Name:" ), null, null, "table_style_left"), oneCell( oneNodeSpan( data.getElementsByTagName( "guild_name" )[0].firstChild.nodeValue, null, "defaultAJAX( 'profileData', new Array( '"+guild_id+"' ), new Array( 'g' ), 'Profile: guild' )", "link" ), null, null, "table_style_right" ), null, null, true ) );
					}
					else
					{
						tbody2.appendChild( oneCellRow( oneNodeSpan( "Create New Guild", null, "createGuildDialog()", "link" ), null, 2, "table_style_center", "create_guild" ) );
						tbody2.appendChild( oneCellRow( document.createElement( "hr" ) , null, 2, "table_style_center bold" ) );
						tbody2.appendChild( oneCellRow( "Guild Invites" , null, 2, "table_style_center" ) );
					}

					var table = document.createElement( "table" );
					table.appendChild( tbody );
					table.cellPadding = 0;
					table.cellSpacing = 0;

					tbody2.appendChild( oneCellRow( table, null, 2, "standard_text w100p" ) );
				}
				else
					tbody2 = tbody;

				defaultDisplayTable( grid_body, oneCellRow( newTabs( "tabs1" ) ), tbody2, null, true, 520, 220 );

				addTab( "tabs1", "Personal", "defaultAJAX( 'communityData', new Array(), new Array( 'f' ), 'Community: Personal', new Array( new Array( 'view1', 'user' ), new Array( 'view2', 'friends' ) ), null );", "user" );
				addTab( "tabs1", "Guild", "defaultAJAX( 'communityData', new Array(), new Array( 'a' ), 'Community: Guild', new Array( new Array( 'view1', 'guild' ), new Array( 'view2', 'ally' ) ), null );", "guild" );	

				if( views['view1'] == "guild" )
				{
					addTab( "tabs2", "Allies", "defaultAJAX( 'communityData', new Array(), new Array( 'a' ), 'Community: Guild', new Array( new Array( 'view1', 'guild' ), new Array( 'view2', 'ally' ) ), null );", "ally" );
					addTab( "tabs2", "NAP", "defaultAJAX( 'communityData', new Array(), new Array( 'n' ), 'Community: Guild', new Array( new Array( 'view1', 'guild' ), new Array( 'view2', 'nap' ) ), null );", "nap" );
					addTab( "tabs2", "Enemies", "defaultAJAX( 'communityData', new Array(), new Array( 'e' ), 'Community: Guild', new Array( new Array( 'view1', 'guild' ), new Array( 'view2', 'enemy' ) ), null );", "enemy" );
				}
				else
				{
					addTab( "tabs2", "Friends List", "defaultAJAX( 'communityData', new Array(), new Array( 'f' ), 'Community: Personal', new Array( new Array( 'view1', 'user' ), new Array( 'view2', 'friends' ) ), null );", "friends" );
					addTab( "tabs2", "Ignore List", "defaultAJAX( 'communityData', new Array(), new Array( 'i' ), 'Community: Personal', new Array( new Array( 'view1', 'user' ), new Array( 'view2', 'ignore' ) ), null );", "ignore" );	
				}
				grid_body.appendChild( historyNavBar() );

				orderTabs( "tabs1", views['view1'] );
				orderTabs( "tabs2", views['view2'] );
			}
			function createGuildDialog()
			{
				var master_cell = document.getElementById( "create_guild" );
				clearElement( master_cell );

				var table = document.createElement( "table" );
				var tbody = document.createElement( "tbody" );

				tbody.appendChild( oneCellRow( document.createElement( "hr" ), null, 2, "table_style_center w100p" ) );
				tbody.appendChild( oneCellRow( "Enter Guild Name", null, 2, "table_style_center w100p" ) );
				tbody.appendChild( oneCellRow( formInput( 'text', 'guild_name', null, 30, 'guild_name' ), null, 2, "table_style_center w100p" ) );
				tbody.appendChild( oneCellRow( oneNodeSpan( "Create Guild", null, "submitFormAJAX( 'createGuild', null, new Array( 'guild_name' ) )", "link" ), null, 2, "table_style_center w100p" ) );

				table.appendChild( tbody );
				master_cell.appendChild( table );
			}
			function getCommunityTable()
			{
				var temp_body = document.createElement("tbody");

				var community_list = null;
				community_list = data.getElementsByTagName("comm");
				if( community_list.length > 0 )
				{	
					for( var c = 0, comm; comm = community_list[c]; c++ )
					{
						var row = document.createElement("tr");
						row.style.height = "15";

						var onclick = null;
						var comm_type = null;
						var target_id = xmlVal( comm, "comm_target_id" );
						var type = xmlVal( comm, "comm_type" );
						if( target_id != player_id )
						{
							if( type == 1 )
								comm_type = "player";
							else if( type == 2 )
								comm_type = "guild";
							onclick = "defaultAJAX( 'profileData', new Array( '"+target_id+"' ), new Array( '"+comm_type.substring( 0, 1 )+"' ), 'Profile: "+comm_type+"' );";
						}
						var proposal = xmlVal( comm, "comm_proposed" );
						var guild_man_dip = xmlVal( data, "guild_man_dip" );
						var text1 = '';
						var span1 = '';
						if( proposal == 1 )
						{
							var text1 = "[Proposed]";
							if( guild_man_dip )
								var span1 = nNodeSpan( "[", oneNodeSpan( "Withdraw", null, null, "link" ), "]" );
						}
						else if( proposal == 2 )
						{
							var text1 = "[Proposal from]";
							if( guild_man_dip )
							{
								var spanA = oneNodeSpan( "Accept", null, "defaultAJAX( 'addCommunity', new Array( '"+xmlVal( comm, "comm_target_id" )+"' ), new Array( 'G', '"+xmlVal( comm, "comm_status" )+"' ) )", "link" );
								var spanB = oneNodeSpan( "Decline", null, "defaultAJAX( 'deleteCommunity', new Array( '"+xmlVal( comm, "comm_target_id" )+"' ), new Array( 'G', '"+xmlVal( comm, "comm_status" )+"' ) )", "link" );
								var span1 = nNodeSpan( "[", spanA, "/", spanB, "]" );
							}
						}
						row.appendChild( oneCell( nNodeSpan( text1, " ", oneNodeSpan( xmlVal( comm, "comm_target_name" ), null, onclick, "link" ), " ", span1 ), null, null, "table_style_left" ) );
						if( type == 1 || (type == 2 && guild_man_dip && proposal != 2 ) )
							row.appendChild( oneCell( makeImg( './img/x_close.gif' ), "defaultAJAX( 'deleteCommunity', new Array( '"+xmlVal( comm, "comm_id" )+"' ), null, null );", null, "table_style_left link" ) );

						temp_body.appendChild( row );
					}
				}
				else
				{
					var comm_type = xmlVal( data, "communityType" );

					if( comm_type == "f")
						var tag = "friends";
					if( comm_type == "i")
						var tag = "ignored users";
					if( comm_type == "a")
						var tag = "alies";
					if( comm_type == "e")
						var tag = "enemies";
					if( comm_type == "n")
						var tag = "NAPs";


					temp_body.appendChild( oneCellRow( "No "+tag, null, null, "table_style" ) );
				}
				return temp_body;
			}

			function getInvitesTable()
			{
				var temp_body = document.createElement("tbody");

				var invites = null;
				invites = data.getElementsByTagName("invite");
				if( invites.length > 0 )
				{	
					for( var i = 0, invite; invite = invites[i]; i++ )
					{
						var invite_guild_name = invite.getElementsByTagName( "invite_guild_name" )[0].firstChild.nodeValue;
						var invite_guild_id = invite.getElementsByTagName( "invite_guild_id" )[0].firstChild.nodeValue;
						var invite_id = invite.getElementsByTagName( "invite_id" )[0].firstChild.nodeValue;

						var row = document.createElement("tr");
						row.appendChild( oneCell( invite_guild_name+" ", "defaultAJAX( 'profileData', new Array( '"+invite_guild_id+"' ), new Array( 'g' ), 'Profile: guild'  )", 2, "link standard_text" ) );
						row.appendChild( oneCell( nNodeSpan( " [ ", oneNodeSpan( "Accept", null, "defaultAJAX( 'processGuildInvite', new Array( '"+invite_id+"' ), new Array( 'accept' ), null )", "link" ), " ] " ), null, null, "table_style_right" ) );
						row.appendChild( oneCell( nNodeSpan( " [ ", oneNodeSpan( "Decline", null, "defaultAJAX( 'processGuildInvite', new Array( '"+invite_id+"' ), new Array( 'decline' ), null )", "link" ), " ] " ), null, null, "table_style_right" ) );
						row.className = "table_style w100p";
						temp_body.appendChild( row );
					}
				}
				else
				{
					temp_body.appendChild( oneCellRow( "No Guild Invites", null, null, "table_style" ) );
				}
				return temp_body;
			}

			function showMarketData( sell )
			{
				clearGrid = true;
				middle_pane.vAlign = "top";
				var grid_body = document.getElementById("grid_body");
				clearElement( grid_body );

				checkView( 'view2', 'marketData', 'addSale' );
				checkView( 'view1', 'resources', 'equipment', 'data', 'tradeData' );

				var body2 = ( views['view2'] == "addSale" ? getAddSale() : getSalesTable() );

				if( views['view2'] == "tradeData" )
					var scrollBody = scrollWindow( body2, 490, 210 );
				else
					var scrollBody = body2;

				var tbody = document.createElement("tbody");
				var str = views['view1'];
				defaultDisplayTable( tbody, oneCellRow( newTabs( "tabs2" ) ), scrollBody, new Array( 'marketData', new Array(), new Array( str.substring(0, 1) ) ), ( views['view2'] == "tradeData" ? true : false ) );

				defaultDisplayTable( grid_body, oneCellRow( newTabs( "tabs1" ) ), tbody, null, true, 520, 270 );

				addTab( "tabs1", "Resources", "defaultAJAX( 'marketData', new Array(), new Array( 'r' ), 'Market: Resources', new Array( new Array( 'view2', 'marketData' ), new Array( 'view1', 'resources' ) ), null );", "resources" );
				addTab( "tabs1", "Equipment", "defaultAJAX( 'marketData', new Array(), new Array( 'i' ), 'Market: Equipment', new Array( new Array( 'view2', 'marketData' ), new Array( 'view1', 'equipment' ) ), null );", "equipment" );	
				addTab( "tabs1", "Data", "defaultAJAX( 'marketData', new Array(), new Array( 'd' ), 'Market: Data', new Array( new Array( 'view1', 'marketData' ), new Array( 'view2', 'data' ) ), null );", "data" );

				var view = views['view1'];

				if( views['view2'] == "tradeData" )
					addTab( "tabs2", "Trade Item", null, "tradeData" );
				addTab( "tabs2", "Buy", "defaultAJAX( 'marketData', new Array(), new Array( '"+( view.substring(0, 1) )+"' ), 'Market: '+views['view2'], new Array( new Array( 'view2', 'marketData' ), new Array( 'view1', '"+views['view1']+"' ) ), null );", 'marketData' );
				addTab( "tabs2", "Sell", "defaultAJAX( 'sellTrade', new Array(), new Array( '"+( view.substring(0, 1) )+"' ), 'Market: '+views['view2'], new Array( new Array( 'view2', 'addSale' ), new Array( 'view1', '"+views['view1']+"' ) ), null );", 'addSale' );

				grid_body.appendChild( historyNavBar() );	

				if( views['view2'] == "tradeData" )
					scroll();	

				orderTabs( "tabs1", views['view1'] );
				orderTabs( "tabs2", views['view2'] );		
			}

			function pushPrice( quant, price, max_quant, price_type )
			{
				if( quant )
					cur_quant = quant;
				if( max_quant )
					cur_max_quant = max_quant;
				if( price )
					cur_price = price;
				if( price_type )
					cur_price_type = price_type;

			}
			function updatePrice( quant, price, max_quant, element )
			{
				if( quant == null && price == null && max_quant == null )
				{
					quant = cur_quant;
					price = cur_price;
					max_quant = cur_max_quant;
				}
				else
				{
					cur_quant = quant;
					cur_price = price;
					cur_max_quant = max_quant;
				}

				if( parseInt(quant) > parseInt(max_quant) )
				{
					quant = parseInt(max_quant);
					element.setAttribute( "value", parseInt(max_quant) );
					element.value = parseInt(max_quant);
					cur_quant = parseInt(max_quant);
				}

				if( price) //change
				{
					var total = ( quant ? parseInt(quant) : 0 ) * parseFloat(price);

					var total_price = document.getElementById( "total_price" );
					if( total_price.hasChildNodes() )
						clearElement( total_price );

					total = number_format( Math.ceil(total), 0, ".", "," );
	
					total_price.appendChild( document.createTextNode(total) );
				}
					
			}
			function parseQuant( type, string )
			{
				cur_type = type;

				if( string )
				{
					var start = string.indexOf( '(' );
					var end = string.indexOf( ')' );
				
					var type_string = string.substring( 0, start - 1);
					var quant = string.substring( start + 1, end );
					cur_max_quant = quant;
					updateQuant( cur_quant );
					var quant_input = document.getElementById( "quant" );
					quant_input.setAttribute( "maxlength", quant.length );
					filterPriceType( type_string );
				}
			}
			function updateQuant( quant )
			{
				if( parseInt(quant) > parseInt(cur_max_quant) )
				{
					var element = document.getElementById("quant");
					element.setAttribute( "value", parseInt(cur_max_quant) );
					element.value = parseInt(cur_max_quant);
					cur_quant = parseInt(cur_max_quant);
				}
				else
					cur_quant = quant;
				
			}
			function filterPriceType( item_name, element )
			{
				if( element )
					var select = element;
				else
					var select = document.getElementById("price_item");

				var price_list = data.getElementsByTagName("price_item");

				clearElement( select );

				var option = document.createElement("option");
				option.appendChild( document.createTextNode( "Select price type" ) );
				select.appendChild( option );

				for( var i = 0, item; item = price_list[i]; i++ )
				{
					var name = item.getElementsByTagName("type")[0].firstChild.nodeValue;

					if( name != item_name )
					{
						var option = document.createElement("option");
						option.value = item.getElementsByTagName("type_id")[0].firstChild.nodeValue;
						option.appendChild( document.createTextNode( name ) );
						select.appendChild( option ); 
					}					
				}
			}
			function getAddSale()
			{
				//views['view1'] = "addSale";
				var temp_body = document.createElement("tbody");

				var select = document.createElement("select");
				select.name = "inv_item";
				select.onchange = new Function( "return parseQuant( this.options[this.selectedIndex].value, this.options[this.selectedIndex].firstChild.nodeValue );" );
				var option = document.createElement("option");
				option.appendChild( document.createTextNode( "Select item from your Inventory" ) );
				select.appendChild( option );

				var inventory = data.getElementsByTagName("sale_item");

				for( var i = 0, item; item = inventory[i]; i++ )
				{
					var option = document.createElement("option");
					var name = item.getElementsByTagName("type")[0].firstChild.nodeValue;
					var quant = item.getElementsByTagName("quantity")[0];
					quant = ( quant.hasChildNodes() ? quant.firstChild.nodeValue : 1 );
					option.value = item.getElementsByTagName("type_id")[0].firstChild.nodeValue;
					option.appendChild( document.createTextNode( name+" ("+quant+")" ) );
					select.appendChild( option );
				}				
				temp_body.appendChild( twoCellRow( "Item", select, "table_style_left" ) );

				var input = document.createElement( "input" );
				input.setAttribute("type", "text");
				input.setAttribute("size", "6");
				input.setAttribute("name", "quant");
				input.setAttribute("id", "quant");
				input.setAttribute("value", cur_quant );
				input.onkeyup = new Function( "return updateQuant( this.value );" );

				temp_body.appendChild( twoCellRow( "Quantity", input, "table_style_left" ) );

				var select = document.createElement("select");
				select.name = "price_item";
				select.id = "price_item";
				select.onchange = new Function( "return pushPrice( null, null, null, this.options[this.selectedIndex].value );" );

				filterPriceType( null, select );				

				temp_body.appendChild( twoCellRow( "Price Type", select, "table_style_left" ) );

				var input = document.createElement( "input" );
				input.setAttribute("type", "text");
				input.setAttribute("size", "4");
				input.setAttribute("name", "price_input");
				input.setAttribute("id", "price_input");
				input.setAttribute("value", cur_price );
				input.onkeyup = new Function( "return pushPrice( null, this.value, null, null );" );

				temp_body.appendChild( twoCellRow( "Price/Unit", input, "table_style_left" ) );

				temp_body.appendChild( oneCellRow( oneNodeSpan( "Submit Trade!", null, "submitTrade( '"+sub_view+"');", "tab_border link" ), null, 2, "table_style_center" ) );

				return temp_body;
			}
			function getSalesTable()
			{
				var temp_body = document.createElement("tbody");

				var sales = null;
				sales = xmlList( data, "sale" );
				if( sales.length > 0 )
				{
					if( sales[0].getAttribute("id") == "single" )
					{
						cur_quant = 1;
						views['view2'] = "tradeData";
						var sale = sales[0];

						var text = xmlVal( sale, "item_name" );
						var item_type = xmlVal( sale, "item_type" );

						if( item_type == 1 )
							var span = nNodeSpan( text+" ", makeImg( "./img/res"+text+".gif", 19, 14 ) );
						else if( item_type == 2 )
							var span = nNodeSpan( text+" ", makeImg( "./img/"+text.toLowerCase()+".gif", 20, 20 ) );

						temp_body.appendChild( twoCellRow( "Item Type", span, "table_style_left", "table_style_right" ) );

						var quantity = xmlVal( sale, "quantity" );
						temp_body.appendChild( twoCellRow( "Quantity", number_format( quantity, 0, ".", "," ), "table_style_left", "table_style_right" ) );

						var price = xmlVal( sale, "price" );
						var priceType = xmlVal( sale, "price_type" );
						temp_body.appendChild( twoCellRow( "Price per Unit*", nNodeSpan( xmlVal( sale, "price" ), " ", makeImg( "./img/res"+priceType+".gif", 19, 14 ) ), "table_style_left", "table_style_right" ) );

						var owner_type = xmlVal( sale, "owner_type" );

						temp_body.appendChild( twoCellRow( "Trade Owner", oneNodeSpan( xmlVal( sale, "owner_name" ), null, "defaultAJAX( 'profileData', new Array( '"+xmlVal( sale, "owner_id" )+"' ), new Array( '"+owner_type.substring( 0, 1 )+"' ), 'Profile: "+owner_type+"' )", "link" ), "table_style_left", "table_style_right" ) );
						temp_body.appendChild( twoCellRow( "Trade Age", '', "table_style_left", "table_style_right" ) );
						temp_body.appendChild( twoCellRow( "Time Remaining", '', "table_style_left", "table_style_right" ) );

						var input = formInput( 'text', 'trade_quant', cur_quant, 4, 'trade_quant' );
						input.setAttribute("maxlength", quantity.length );
						input.onkeyup = new Function( "return updatePrice( this.value, "+price+", "+quantity+", this );" );

						var span = nNodeSpan( "Buy ", input, " unit(s)" );

						temp_body.appendChild( oneCellRow( span, null, 2, "table_style_center" ) );

						var span = nNodeSpan( "Total Price: ", oneNodeSpan( null, "total_price", null ), " ", oneNodeSpan( makeImg( "./img/res"+priceType+".gif", 19, 14 ) ) );
						pushPrice( cur_quant, price, quantity );

						temp_body.appendChild( oneCellRow( span, null, 2, "table_style_center" ) );

						if( xmlVal( sale, "owner" ) == "1" )
						{
							temp_body.appendChild( oneCellRow( "This is yours, you can't buy it!", null, 2, "table_style_center" ) );
							temp_body.appendChild( oneCellRow( oneNodeSpan( "Edit Trade Details!", null, "defaultAJAX( 'editTrade', new Array( '"+xmlVal( sale, "trade_id" )+"' ), null, null );", "link" ), null, 2, "table_style_center" ) );
							temp_body.appendChild( oneCellRow( oneNodeSpan( "Remove Trade!", null, "defaultAJAX( 'deleteTrade', new Array( '"+xmlVal( sale, "trade_id" )+"' ), null, null);", "link" ), null, 2, "table_style_center" ) );
						}
						else
							temp_body.appendChild( oneCellRow( oneNodeSpan( "Buy This!", "buy_submit", "submitFormAJAX( 'purchaseTrade', new Array( 'trade_quant' ), null, new Array( '"+xmlVal( sale, "trade_id" )+"' ) );", "link" ), null , 2, "table_style_center" ) );

						temp_body.appendChild( oneCellRow( "*Total price to be rounded up to nearest whole unit", null, 2, "table_style_small_center wrap" ) );
					}
					else
					{
						//views['view1'] = "marketData";
						var row = document.createElement("tr");
						//row.style.borderWidth = "1";
						//row.style.borderStyle = "solid";
						row.style.height = "15";

						row.appendChild( oneCell( "Item Type", null, null, "bold table_style_left" ) );
						row.appendChild( oneCell( "Quantity", null, null, "bold table_style_center" ) );
						row.appendChild( oneCell( "Price/Unit", null, null, "bold table_style_center" ) );

						temp_body.appendChild( row );
	
						for( var s = 0, sale; sale = sales[s]; s++ )
						{
							var row = document.createElement("tr");

							var extra_style = null;
							var note = '';
							if( xmlVal( sale, "owner" ) == "1" )
							{
								var extra_style = " tab_grey";
								var note = " (This trade belongs to you!)";
							}

							var text = xmlVal( sale, "item_name" );
							var item_type = xmlVal( sale, "item_type" );

							if( item_type == 1 )
								var span = nNodeSpan( makeImg( "./img/res"+text+".gif", 19, 14 ), " ", text );
							else if( item_type == 2 )
								var span = nNodeSpan( makeImg( "./img/"+text.toLowerCase()+".gif", 20, 20 ), " ", text );

							row.appendChild( oneCell( span, "defaultAJAX( 'marketData', new Array( '"+xmlVal( sale, "trade_id" )+"' ), new Array() );", null, "table_style_left link" ) );
							row.appendChild( oneCell( number_format( xmlVal( sale, "quantity" ), 0, ".", "," ), null, null, "table_style_center" ) );
							row.appendChild( oneCell( nNodeSpan( xmlVal( sale, "price" ), " ", makeImg( "./img/res"+xmlVal( sale, "price_type" )+".gif", 19, 14 ) ), null, null, "table_style_center" ) );

							temp_body.appendChild( row );
						}
					}
				}
				else
				{
					temp_body.appendChild( oneCellRow( "No Trades", null, 3, "table_style" ) );
				}
				return temp_body;
			}
			function writeMail( player_to )
			{
				clearGrid = true;
				middle_pane.vAlign = "top";
				var grid_body = document.getElementById("grid_body");
				clearElement( grid_body );

				var body = document.createElement( "tbody" );
				body.appendChild( twoCellRow( "To:", formInput( 'text', 'mail_to', player_to, 60, 'mail_to' ), "standard_text" ) );
				body.appendChild( twoCellRow( "Subject:", formInput( 'text', 'mail_subject', null, 60, 'mail_subject' ), "standard_text" ) );
				body.appendChild( twoCellRow( "Message:", textarea( null, 'mail_msg', 10, 45, null, true ), "standard_text" ) );

				body.appendChild( oneCellRow( oneNodeSpan( 'Submit', null, "submitFormAJAX( 'writeMail', null, new Array( 'mail_to', 'mail_subject', 'mail_msg' ) )" ), null, 2, 'table_style_center' ) );

				defaultDisplayTable( grid_body, oneCellRow( "Write new mail...", null, null, "tab_grey" ), body, null, true, 525, 270 );
				grid_body.appendChild( historyNavBar() );
			}
			function showMailData( new_mail )
			{
				clearGrid = true;
				middle_pane.vAlign = "top";
				var grid_body = document.getElementById("grid_body");
				clearElement( grid_body );

				checkView( 'view1', 'inbox', 'outbox' );

				if( views['view1'] == "inbox" )
					checkView( 'view2', 'inbox_in', 'inbox_saved', 'inbox_draft' );
				if( views['view1'] == "outbox" )
					checkView( 'view2', 'outbox_outgoing', 'outbox_sent' );

				var body2 = ( views['view1'] == "addMail" ? getAddMail() : getMailTable() );

				if( views['view1'] == "mData" )
					var scrollBody = scrollWindow( body2, 490, 220 );
				else
					var scrollBody = body2;

				var tbody = document.createElement("tbody");
				var str = ( views['view2'] == "inbox_in" ? 'i' : ( views['view2'] == "inbox_saved" ? 'v' : ( views['view2'] == "inbox_draft" ? 'd' : ( views['view2'] == "outbox_outgoing" ? 'o' : ( views['view2'] == "outbox_sent" ? 's' : 'i' ) ) ) ) );
				defaultDisplayTable( tbody, oneCellRow( newTabs( "tabs2" ) ), scrollBody, new Array( 'mailData', new Array(), new Array( str ) ), ( views['view1'] == "mData" ? true : false ), null, null );
				defaultDisplayTable( grid_body, oneCellRow( newTabs( "tabs1" ) ), tbody, null, true, 525, ( views['view1'] == "mData" ? 260 : 270 ) );

				addTab( "tabs1", "Inbox", "defaultAJAX( 'mailData', new Array(), new Array( 'i' ), 'Mail: Inbox', new Array( new Array( 'view1', 'inbox' ), new Array( 'view2', 'inbox_in' ) ) );", "inbox" );
				addTab( "tabs1", "Outbox", "defaultAJAX( 'mailData', new Array(), new Array( 'o' ), 'Mail: Outbox', new Array( new Array( 'view1', 'outbox' ), new Array( 'view2', 'outbox_outgoing' ) ) );", "outbox" );

				if( views['view1'] == "outbox" )
				{
					addTab( "tabs2", "Outgoing", "defaultAJAX( 'mailData', new Array(), new Array( 'o' ), 'Mail: Outbox: Outgoing', new Array( new Array( 'view1', 'outbox' ), new Array( 'view2', 'outbox_outgoing' ) ) );", "outbox_outgoing" );
					addTab( "tabs2", "Sent", "defaultAJAX( 'mailData', new Array(), new Array( 's' ), 'Mail: Outbox: Sent', new Array( new Array( 'view1', 'outbox' ), new Array( 'view2', 'outbox_sent' ) ) );", "outbox_sent" );
				}
				else
				{
					addTab( "tabs2", "Recieved", "defaultAJAX( 'mailData', new Array(), new Array( 'i' ), 'Mail: Inbox', new Array( new Array( 'view1', 'inbox' ), new Array( 'view2', 'inbox_in' ) ) );", "inbox_in" );
					addTab( "tabs2", "Saved", "defaultAJAX( 'mailData', new Array(), new Array( 'v' ), 'Mail: Inbox: Saved', new Array( new Array( 'view1', 'inbox' ), new Array( 'view2', 'inbox_saved' ) ) );", "inbox_saved" );
					addTab( "tabs2", "Draft", "defaultAJAX( 'mailData', new Array(), new Array( 'd' ), 'Mail: Inbox: Draft', new Array( new Array( 'view1', 'inbox' ), new Array( 'view2', 'inbox_draft' ) ) );", "inbox_draft" );
				}
				if( views['view1'] == "outbox" )
				{
					grid_body.appendChild( oneCellRow( "Write new message", "writeMail()", 2, "table_style_center link" ) );
				}
				grid_body.appendChild( historyNavBar() );

				orderTabs( "tabs1", views['view1'] );
				orderTabs( "tabs2", views['view2'] );
			}

			function getMailTable()
			{
				var temp_body = document.createElement("tbody");

				var mails = null;
				mails = data.getElementsByTagName("mail");
				if( mails.length > 0 )
				{
					if( mails[0].getAttribute("id") == "single" )
					{
						cur_quant = 1;
						views['view1'] = "mData";
						var mail = mails[0];
						
						if( views['view1'] == "outbox" )
							temp_body.appendChild( twoCellRow( "To: ", xmlVal( mail, "to" ), "table_style_left", "table_style_right" ) );
						else
							temp_body.appendChild( twoCellRow( "From: ", xmlVal( mail, "from" ), "table_style_left", "table_style_right" ) );
						temp_body.appendChild( twoCellRow( "Date: ", xmlVal( mail, "date" ), "table_style_left", "table_style_right" ) );
						temp_body.appendChild( twoCellRow( "Subject: ", xmlVal( mail, "title" ), "table_style_left", "table_style_right" ) );

						temp_body.appendChild( oneCellRow( "Message:", null, 2, "table_style_left bold" ) );
						temp_body.appendChild( oneCellRow( parseMessage( xmlVal( mail, "message" ), null, null, true ), null, 2, "w100p standard_text" ) );
					}
					else
					{

						var tag = null;

						if( views['view2'] == "inbox_saved" )
							tag = "v";
						else if( views['view2'] == "outbox_outgoing" )
							tag = "o";
						else if( views['view2'] == "outbox_sent" )
							tag = "s";
						else
							tag = "i";

						var t_tag = tag.substring( 0, 2 );

						//view = "mailData";
						var row = document.createElement("tr");
						row.style.borderWidth = "1";
						row.style.borderStyle = "solid";
						row.style.borderColor = "black";


						row.appendChild( oneCell( "Subject", null, null, "table_style_left" ) );

						if( views['view1'] == "outbox" )
							row.appendChild( oneCell( "To", null, null, "table_style_center" ) );
						else
							row.appendChild( oneCell( "From", null, null, "table_style_center" ) );

						row.appendChild( oneCell( "Date", null, null, "table_style_center" ) );

						var checkbox = document.createElement( "input" );
						checkbox.type = "checkbox";
						checkbox.onmouseup = new Function( "return checkAllMail();" );
						row.appendChild( oneCell( checkbox, null, null, "table_style_left" ) );

						temp_body.appendChild( row );
	
						for( var m = 0, mail; mail = mails[m]; m++ )
						{
							var mail_id = xmlVal( mail, "mail_id" );
							var extra_style = '';
							var new_mail = '';
							var status = xmlVal( mail, "status" );
							if( status == 2 || status == 8 )
							{
								extra_style = " bold";
								new_mail = makeImg( './img/mail.gif' );
							}

							var onclick = "defaultAJAX( 'mailData', new Array( '"+mail_id+"' ), new Array( '"+tag+"' ) );";

							var row = document.createElement("tr");

							row.appendChild( oneCell( nNodeSpan( new_mail, " ", xmlVal( mail, "title" ) ), onclick, null, "table_style_left link"+extra_style ) );

							if( views['view1'] == "outbox" )
								row.appendChild( oneCell( xmlVal( mail, "to" ), onclick, null, "table_style_center link"+extra_style ) );
							else
								row.appendChild( oneCell( xmlVal( mail, "from" ), onclick, null, "table_style_center link"+extra_style ) );

							row.appendChild( oneCell( xmlVal( mail, "date" ), onclick, null, "table_style_center link"+extra_style ) );

							var checkbox = document.createElement( "input" );
							checkbox.type = "checkbox";
							checkbox.name = "mailCheck"+m;
							checkbox.id = "mailCheck"+m;
							checkbox.value = mail_id;
							row.appendChild( oneCell( checkbox ) );

							temp_body.appendChild( row );
						}
						var row = document.createElement( "tr" );
	
						var str = ( views['view2'] == "inbox_in" ? 'i' : ( views['view2'] == "inbox_saved" ? 'v' : ( views['view2'] == "inbox_draft" ? 'd' : ( views['view2'] == "outbox_outgoing" ? 'o' : ( views['view2'] == "outbox_sent" ? 's' : 'i' ) ) ) ) );

						if( views['view1'] == "inbox" )
						{
							var img1 = makeImg( './img/mail.gif', null, null, null, "Mark Unread", "defaultAJAX( 'processMail', getMailCheck(), new Array( 'u', '"+str+"' ), null, null )", "link" );
							var img2 = makeImg( './img/open_mail.gif', null, null, null, "Mark Read", "defaultAJAX( 'processMail', getMailCheck(), new Array( 'r', '"+str+"' ), null, null )", "link"  );
						}
						var img3 = makeImg( './img/delete.gif', null, null, null, "Delete", "defaultAJAX( 'processMail', getMailCheck(), new Array( 'd', '"+str+"' ), null, null )", "link"  );

						row.appendChild( oneCell( nNodeSpan( ( img1 ? img1 : '' ), ' ', ( img2 ? img2 : '' ), ' ', img3 ), null, 3, "table_style_right" ) );
						row.appendChild( oneCell( makeImg( './img/point_down_left.gif' ), null, null, "table_style" ) );
						temp_body.appendChild( row );
					}
				}
				else
				{
					temp_body.appendChild( oneCellRow( "No Mails", null, 3, "table_style" ) );
				}
				return temp_body;
			}
			function getMailCheck()
			{
				var array = new Array();
				for( var m = 0; m <= 8; m++ )
				{
					var checkbox = document.getElementById( "mailCheck"+m );

					if( checkbox )
					{
						if( checkbox.checked == true )
						{
							array[array.length] = checkbox.value.toString();
						}
					}
				}
				return array;
			}
			function checkAllMail()
			{
				for( var m = 0; m <= 8; m++ )
				{
					var checkbox = document.getElementById( "mailCheck"+m );

					if( checkbox )
					{
						if( checkbox.checked == true )
							checkbox.checked = false;
						else
							checkbox.checked = true;
					}
				}
			}

			function showLeaderData()
			{
				clearGrid = true;
				middle_pane.vAlign = "top";
				var grid_body = document.getElementById("grid_body");
				clearElement( grid_body );

				var temp_body = document.createElement( "tbody" );

				checkView( 'view1', 'leader_land', 'leader_tasks' );
				checkView( 'view2', 'players', 'teams' );

				var tbody = document.createElement("tbody");
				var view = views['view1'];
				defaultDisplayTable( tbody, oneCellRow( newTabs( "tabs2" ) ), getLeaderTable(), new Array( 'leaderData', new Array( ( views['view1'] == 'teams' ? '2' : '1' ) ), new Array( '"+view.substring( 7, 8 )+"' ) ), null, null, null );
				defaultDisplayTable( grid_body, oneCellRow( newTabs( "tabs1" ) ), tbody, null, true, 525, 270 );

				addTab( "tabs1", "Land", "defaultAJAX( 'leaderData', new Array( '"+( views['view1'] == 'teams' ? 2 : 1 )+"' ), new Array( 'l' ), 'Leadertable: Land', new Array( new Array( 'view1', 'leader_land' ), new Array( 'view2', '"+views['view2']+"' ) ) );", "leader_land" );
				addTab( "tabs1", "Tasks", "defaultAJAX( 'leaderData', new Array( '"+( views['view1'] == 'teams' ? 2 : 1 )+"' ), new Array( 't' ), 'Leadertable: Tasks', new Array( new Array( 'view1', 'leader_tasks' ), new Array( 'view2', '"+views['view2']+"' ) ));", "leader_tasks" );

				
				addTab( "tabs2", "Players", "defaultAJAX( 'leaderData', new Array( '1' ), new Array( '"+view.substring( 7, 8 )+"' ), 'Leadertable: Land', new Array( new Array( 'view1', '"+views['view1']+"' ), new Array( 'view2', 'players' ) ) );", "players" );
				addTab( "tabs2", "Teams", "defaultAJAX( 'leaderData', new Array( '2' ), new Array( '"+view.substring( 7, 8 )+"' ), 'Leadertable: Tasks', new Array( new Array( 'view1', '"+views['view1']+"' ), new Array( 'view2', 'teams' ) ) );", "teams" );

				grid_body.appendChild( historyNavBar() );

				orderTabs( "tabs1", views['view1'] );
				orderTabs( "tabs2", views['view2'] );

			}

			function getLeaderTable()
			{
				var temp_body = document.createElement("tbody");

				var leaders = null;
				leaders = data.getElementsByTagName("leader");
				if( leaders.length > 0 )
				{
					var row = document.createElement("tr");
					row.style.borderWidth = "1";
					row.style.borderStyle = "solid";
					row.style.borderColor = "black";

					row.appendChild( oneCell( "Rank", null, null, "table_style_left bold" ) );

					if( views['view2'] == "players" )
						row.appendChild( oneCell( "Player Name", null, null, "table_style_center bold w100p" ) );
					else
						row.appendChild( oneCell( "Team Name", null, null, "table_style_center bold w100p" ) );

					if( views['view1'] == "leader_land" )
					{
						row.appendChild( oneCell( "Land", null, null, "table_style_center bold" ) );
						row.appendChild( oneCell( "Towers", null, null, "table_style_center" ) );
						row.appendChild( oneCell( "L/T", null, null, "table_style_center" ) );
					}
					else if( views['view1'] == "tasks")
					{
						row.appendChild( oneCell( "Task Leader info...", null, null, "table_style_center" ) );
					}

					temp_body.appendChild( row );
	
					for( var l = 0, leader; leader = leaders[l]; l++ )
					{
						var row = document.createElement("tr");

						row.appendChild( oneCell( xmlVal( leader, "rank" ), onclick, null, "table_style_left" ) );

						var onclick = null;

						if( views['view2'] == "teams" )
							var sorter = "guild";
						else
							var sorter = "player";

						onclick = "defaultAJAX( 'profileData', new Array( '"+xmlVal( leader, "owner_id" )+"' ), new Array( '"+sorter.substring( 0, 1 )+"' ), 'Profile: "+sorter+"'  );";

						row.appendChild( oneCell( xmlVal( leader, "name" ), onclick, null, "table_style_left link" ) );

						if( views['view1'] == "leader_land" )
						{
							row.appendChild( oneCell( xmlVal( leader, "land_area" ), null, null, "table_style_center" ) );
							row.appendChild( oneCell( xmlVal( leader, "towers" ), null, null, "table_style_center" ) );
							row.appendChild( oneCell( xmlVal( leader, "land_per_tower" ), null, null, "table_style_center" ) );
						}
						else if( views['view1'] == "tasks")
						{
							//row.appendChild( oneCell( leader.getElementsByTagName("debug")[0].firstChild.nodeValue, null, null, "table_style_center" ) );
							row.appendChild( oneCell( "debug", null, null, "table_style_center" ) );
						}

						temp_body.appendChild( row );
					}
				}
				else
				{
					temp_body.appendChild( oneCellRow( "No Leaders", null, 3, "table_style" ) );
				}
				return temp_body;
			}


			function showInventoryData()
			{
				views['view1'] = "inventoryData";

				clearGrid = true;
				middle_pane.vAlign = "top";
				var grid_body = document.getElementById("grid_body");
				clearElement( grid_body );

				var invOwnerName = xmlVal( data,  "invOwnerName" );
				var invOwnerId = xmlVal( data, "invOwnerId" );
				var invOwnerType = xmlVal( data, "invOwnerType" );
				var filter = null;

				checkView( 'view2', 'resources', 'equipment', 'data' );

				var body = getInvTable( invOwnerId, invOwnerType );
				
				if( views['view1'] == "iData" )
					var scrollBody = scrollWindow( body, 490, 220 );
				else
					var scrollBody = body;

				var tbody = document.createElement( "tbody" );
				var str = ( views['view2'] == "resources" ? 'r' : ( views['view2'] == "equipment" ? 'i' : ( views['view2'] == "data" ? 'd' : 'r' ) ) );
				defaultDisplayTable( tbody, oneCellRow( newTabs( "tabs1" ) ), scrollBody, new Array( 'inventoryData', new Array( invOwnerId ), new Array( str, ( invOwnerType ? invOwnerType : 'player' )  ) ), ( views['view1'] == "iData" ? true : false ) );

				var name_header = oneCellRow( nNodeSpan( "[ ", oneNodeSpan( invOwnerName+"'s", null, "defaultAJAX( 'profileData', new Array( '"+invOwnerId+"' ), new Array( '"+( invOwnerType == 'struct' ? 's' : invOwnerType.substring( 0, 1 ) )+"' ), 'Profile: structure')", "link" ), " Inventory ]" ), null, 2, "table_style_left solid_100 tab_grey" );
				defaultDisplayTable( grid_body, name_header, tbody, null, true, 530, 260 );

				addTab( "tabs1", "Resources", "defaultAJAX( 'inventoryData', new Array( '"+invOwnerId+"' ), new Array( 'r', '"+( invOwnerType ? invOwnerType : 'player' )+"' ), 'Inventory: Resources', new Array( new Array( 'view2', 'resources' ) ) );", "resources" );
				addTab( "tabs1", "Equipment", "defaultAJAX( 'inventoryData', new Array( '"+invOwnerId+"' ), new Array( 'i', '"+( invOwnerType ? invOwnerType : 'player' )+"' ), 'Inventory: Equipment', new Array( new Array( 'view2', 'equipment' ) ) );", "equipment" );
				addTab( "tabs1", "Data", "defaultAJAX( 'inventoryData', new Array( '"+invOwnerId+"' ), new Array( 'd', '"+( invOwnerType ? invOwnerType : 'player' )+"' ), 'Inventory: Data', new Array( new Array( 'view2', 'data' ) ) );", "data" );

				grid_body.appendChild( historyNavBar() );

				orderTabs( "tabs1", views['view2'] );				
			}

			function getInvTable( invOwnerId, invOwnerType )
			{
				var temp_body = document.createElement("tbody");

				var items = null;
				items = xmlList( data, "item" );
				if( items.length > 0 )
				{
					if( items[0].getAttribute("id") == "single" )
					{
						cur_quant = 1;
						views['view1'] = "iData";
						var item = items[0];

						var text = xmlVal( item, "item_name" );
						var item_id = xmlVal( item, "item_id" );
						var cat = xmlVal( item, "item_cat" );
						var droppable = xmlVal( data, "droppable" ); //double check use of 'data'
						var deed = xmlVal( item, "deed" );
						var deployable = xmlVal( item, "deploy" );
						var equipable = xmlVal( item, "equipable" );
						var manEquip = xmlVal( item, "manEquip" );
						var quantity = xmlVal( item, "quantity" );
						var grabable = xmlVal( data, "grabable" );

						if( cat == "resource" )
							var span = nNodeSpan( makeImg( "./img/res"+text+".gif", 19, 14 ), " ", text );
						else
							var span = nNodeSpan( makeImg( "./img/"+text.toLowerCase()+".gif", 20, 20 ), " ", text );

						temp_body.appendChild( twoCellRow( "Name: ", span, "table_style_left", "table_style_right" ) );

						temp_body.appendChild( twoCellRow( "Quantity: ", ( quantity ? number_format( quantity, 0, ".", "," ) : ' ' ), "table_style_left", "table_style_right" ) );

						if( deed )
						{
								temp_body.appendChild( oneCellRow( "This item is a deed", null, 2, "table_style_center" ) );
								temp_body.appendChild( oneCellRow( "It is a structure that can be placed on the map", null, 2, "table_style_center" ) );
						}
						if( deployable )
								temp_body.appendChild( oneCellRow( nNodeSpan( "[ ", oneNodeSpan( "Deploy Deed", null, "defaultAJAX( 'submitBuild', new Array( '"+item_id+"' ), null, null, null, null, null, 'Building structure. Please wait, our builders are lazy...' )", "link" ), " ]" ), null, 2, "table_style_center" ) );

						if( equipable )
						{
							if( cat == "item" )
							{
								var link = null;
								if( xmlVal( item, "equiped" ) )
								{
									if( manEquip )
										link = "unequip";
									var img = "Yes ";
								}
								else
								{
									if( manEquip )
										link = "equip";
									var img = 'No ';
								}
								temp_body.appendChild( twoCellRow( "Equiped: ", nNodeSpan( img, ( manEquip ? nNodeSpan( "[", oneNodeSpan( link, null, "defaultAJAX( 'toggleEquip', new Array( '"+item_id+"' ), null, null )", "link" ), "]" ) : null ) ), "table_style_left", "table_style_center" ) );
							}
						}
						if( droppable )
							temp_body.appendChild( oneCellRow( nNodeSpan( "[ ", oneNodeSpan( "drop", null, "defaultAJAX( 'transferItem', new Array( '"+item_id+"' ), new Array( '"+cat.substring( 0, 1 )+"', 'drop' ), null )", "link" ), " into ", droppable, " ]" ), null, 2, "table_style_center" ) );
						else if( grabable )
							temp_body.appendChild( oneCellRow( nNodeSpan( "[ ", oneNodeSpan( "pickup", null, "defaultAJAX( 'transferItem', new Array( '"+item_id+"' ), new Array( '"+cat.substring( 0, 1 )+"', 'pickup' ), null )", "link" ), " from ", grabable, " ]" ), null, 2, "table_style_center" ) );
						
						if( quantity > 1 )
							temp_body.appendChild( oneCellRow( nNodeSpan( "[ ", oneNodeSpan( "split", null, "splitStack( this )", "link" ), " ]" ), null, 2, "table_style_center", "split_stack" ) );

						var stack_list = xmlList( item, "stack_item" );
						if( stack_list.length > 0 )
						{
							temp_body.appendChild( oneCellRow( nNodeSpan( "[ ", oneNodeSpan( "stack", null, "stackStack( this )", "link" ), " ]" ), null, 2, "table_style_center", "stack_stack" ) );	
						}
						temp_body.appendChild( oneCellRow( document.createElement("hr"), null, 2, null ) );

						temp_body.appendChild( oneCellRow( "Attributes:", null, 2, "table_style_left" ) );

						var att = xmlList( item, "attribute" );
						if( att.length > 0 )
						{
							for( var a = 0; a < att.length; a++ )
							{
								var attribute = att[a];
								var a_name = xmlVal( attribute, "name" );
								var a_value = xmlVal( attribute, "value" );
								a_value = ( a_value ? a_value : "[debug]" );

								temp_body.appendChild( twoCellRow( a_name, a_value, "table_style_center", "table_style_center" ) );
							}
						}
						else
							temp_body.appendChild( oneCellRow( "None", null, 2, "table_style_center" ) );

					}
					else
					{
						views['view1'] = "inventoryData";

						var j = 0;

						for( var i = 0, item; item = items[i]; i++ )
						{
							var cat = xmlVal( item, "item_cat" );

							if( ( cat == "resource" && views['view2'] == "resources" ) || ( cat == "item" && views['view2'] == "equipment" ) || ( cat == "data" && views['view2'] == "data" ) )
							{
								j++;
								if( j == 1 )
								{
									var row = document.createElement("tr");

									row.appendChild( oneCell( "Item Type", null, null, "table_style_left" ) );
		
									row.appendChild( oneCell( "Quantity", null, null, "table_style_center" ) );

									if( sub_view == "equipment" )
	 									row.appendChild( oneCell( "Equiped", null, null, "table_style_center" ) );

									row.style.borderWidth = "1";
									row.style.borderStyle = "solid";
									row.style.borderColor = "black";
									temp_body.appendChild( row );
								}

								var row = document.createElement("tr");

								var text = xmlVal( item, "item_name" );
								if( cat == "resource" )
									var span = nNodeSpan( makeImg( "./img/res"+text+".gif", 19, 14 ), " ", text );
								else
									var span = nNodeSpan( makeImg( "./img/"+text.toLowerCase()+".gif", 20, 20 ), " ", text );

								row.appendChild( oneCell( span, "defaultAJAX( 'inventoryData', new Array( '"+invOwnerId+"', '"+xmlVal( item, "item_id" )+"' ), new Array( '"+( views['view2'] == "resources" ? 'r' : ( views['view2'] == "equipment"? 'i' : ( views['view2'] == "data"? 'd' : '' ) ) )+"', '"+( invOwnerType ? invOwnerType : 'player' )+"' ), 'Inventory: '+views['view2'], new Array( new Array( 'view2', '"+views['view2']+"' ) ) );", null, "table_style_left link" ) );

								var quant = xmlVal( item, "quantity" );

								row.appendChild( oneCell( ( quant ? number_format( quant, 0, ".", "," ) : ' ' ), null, null, "table_style_center" ) );
	
								var equip = xmlVal( item, "equiped" );
								if( cat == "item" && equip )
									row.appendChild( oneCell( makeImg( './img/yes.gif', 15, 15 ), null, null, "table_style_center" ) );
								else
									row.appendChild( oneCell( ' ', null, null, "table_style_center" ) );
	
								temp_body.appendChild( row );
							}
						}
						if( j == 0 )
							temp_body.appendChild( oneCellRow( "No Items b", null, null, "table_style" ) );
					}
				}
				else
				{
					temp_body.appendChild( oneCellRow( "No Items a", null, 3, "table_style_center" ) );
				}
				return temp_body;
			}


			function splitStack()
			{
				var item = data.getElementsByTagName("item")[0];
				var split_stack = document.getElementById("split_stack");
				clearElement( split_stack );

				var stack_stack = document.getElementById("stack_stack");
				if( stack_stack )
				{
					clearElement( stack_stack );
					stack_stack.appendChild( nNodeSpan( "[ ", oneNodeSpan( "stack", null, "stackStack( this )", "link" ), " ]" ) );
				}

				var table = document.createElement("table");
				table.style.width = "100%";
				//table.border = 1;
				var tbody = document.createElement("tbody");

				tbody.appendChild( oneCellRow( document.createElement("hr"), null, 2, null ) );
				var cell1 = oneCell( "Stack 1 ", null, null, "table_style_right" );
				cell1.style.width = "50%";
				var cell2 = oneCell( " Stack 2", null, null, "table_style_left" );
				cell2.style.width = "50%";

				tbody.appendChild( twoCellRow( cell1, cell2, null, null, true ) );

				var quant = parseInt( xmlVal( item, "quantity" ) );
				var first_stack = quant - 1;
				var span1 = oneNodeSpan( first_stack.toString(), "first_stack", null, "table_style_center" );

				var input = formInput( 'text', 'second_stack', 1, 4, 'second_stack' );
				input.setAttribute("maxlength", quant.length );
				input.onkeyup = new Function( "return updateFirstStack( this.value, "+quant+", this );" );
				cur_quant = 1;

				var span = nNodeSpan( span1, " / ", input );
				tbody.appendChild( oneCellRow( span, null, 2, "table_style_center") );
				tbody.appendChild( oneCellRow( oneNodeSpan( "Split Stack", null, "submitSplit("+xmlVal( item, "item_id" )+", '"+views['view2']+"' );", "link" ), null, 2, "table_style_center" ) );
				tbody.appendChild( oneCellRow( document.createElement("hr"), null, 2, null ) );
				table.appendChild( tbody );
				split_stack.appendChild( table );
			}
			function stackStack()
			{
				var item = data.getElementsByTagName("item")[0];
				var stack_stack = document.getElementById("stack_stack");
				clearElement( stack_stack );

				var split_stack = document.getElementById("split_stack");
				if( split_stack )
				{
					clearElement( split_stack );
					split_stack.appendChild( nNodeSpan( "[ ", oneNodeSpan( "split", null, "splitStack( this )", "link" ), " ]" ) );
				}
				var table = document.createElement("table");
				table.style.width = "100%";
				//table.border = 1;
				var tbody = document.createElement("tbody");
				tbody.appendChild( oneCellRow( document.createElement("hr"), null, 2, null ) );
				tbody.appendChild( oneCellRow( "stack with...", null, null, "table_style_center" ) );


				var select = document.createElement("select");
				select.name = "stack_item";
				select.onchange = new Function( "return parseQuant( this.options[this.selectedIndex].value, null );" );
				var stack_list = item.getElementsByTagName("stack_item");

				for( var i = 0, s_item; s_item = stack_list[i]; i++ )
				{
					var option = document.createElement("option");
					var name = s_item.getElementsByTagName("si_name")[0].firstChild.nodeValue;
					var quant = s_item.getElementsByTagName("si_quantity")[0].firstChild.nodeValue;
					var s_id = s_item.getElementsByTagName("si_id")[0].firstChild.nodeValue
					option.value = s_id;
					option.appendChild( document.createTextNode( name+" ("+quant+")" ) );
					select.appendChild( option );

					if( stack_list.length == 1 )
						parseQuant( s_id, null );
				}
				tbody.appendChild( oneCellRow( select, null, null, "table_style_center" ) );

				tbody.appendChild( oneCellRow( oneNodeSpan( "Stack", null, "submitStack("+xmlVal( item, "item_id" )+", '"+views['view2']+"' );", "link" ), null, 2, "table_style_center" ) );
				//tbody.appendChild( oneCellRow( document.createElement("hr"), null, 2, null ) );
				table.appendChild( tbody );
				stack_stack.appendChild( table );
			}
			function updateFirstStack( split, full_quant, element )
			{
				cur_quant = split;
				var rem = full_quant - split;
				if( split <= 0 )
				{
					cur_quant = 1;
					var rem = full_quant - 1;
				}

				if( split >= full_quant )
				{
					cur_quant = ( full_quant - 1 );
					var rem = 1;
				}
				element.value = cur_quant;

				var first_stack = document.getElementById( "first_stack" );

				clearElement( first_stack );
				first_stack.appendChild( document.createTextNode( rem ) );					
			}

			function showGoalData()
			{
				clearGrid = true;
				middle_pane.vAlign = "top";
				var grid_body = document.getElementById("grid_body");
				clearElement( grid_body );

				checkView( 'view2', 'all', 'collect', 'build', 'claim', 'goal' );
				checkView( 'view1', 'current', 'complete' );

				var body = getGoalTable();
				
				if( views['view2'] == "Goal" )
					var scrollBody = scrollWindow( body, 490, 215 );
				else
					var scrollBody = body;

				var temp_body = document.createElement( "tbody" );
				var str1 = ( views['view1'] == 'complete' ? 'old' : 'cur' );
				var str2 = ( views['view2'] == 'collect' ? 'c' : ( views['view2'] == 'build' ? 'b' : ( views['view2'] == 'claim' ? 'l' : 'a' ) ) );
				defaultDisplayTable( temp_body, oneCellRow( newTabs( "tabs2" ) ), scrollBody, new Array( 'goalDdata', new Array(), new Array( str1, str2 ) ), ( views['view1'] == "gData" ? true : false ), null, null );
				defaultDisplayTable( grid_body, oneCellRow( newTabs( "tabs1" ) ), temp_body, null, true, 525, 270 );

				addTab( "tabs1", "Current", "defaultAJAX( 'goalData', new Array(), new Array( 'cur', '"+( views['view2'] == 'collect' ? 'c' : ( views['view2'] == 'build' ? 'b' : ( views['view2'] == 'claim' ? 'l' : 'a' ) ) )+"' ), 'Goals: Current', new Array( new Array( 'view1', 'current') , new Array( 'view2', '"+views['view2']+"' ) ) );", "current" );
				addTab( "tabs1", "Complete", "defaultAJAX( 'goalData', new Array(), new Array( 'old', '"+( views['view2'] == 'collect' ? 'c' : ( views['view2'] == 'build' ? 'b' : ( views['view2'] == 'claim' ? 'l' : 'a' ) ) )+"' ), 'Goals: Completed', new Array( new Array( 'view1', 'complete') , new Array( 'view2', '"+views['view2']+"' ) ) );", "complete" );	

				if( views['view2'] == "Goal" )
					addTab( "tabs2", "debug", null, "Goal" );
				addTab( "tabs2", "All", "defaultAJAX( 'goalData', new Array(), new Array( '"+( views['view1'] == "complete" ? 'old' : 'cur' )+"', 'a' ), 'Goals: '+views['view1'], new Array( new Array( 'view1', '"+views['view1']+"') , new Array( 'view2', 'all' ) ) );", "all" );
				addTab( "tabs2", "Collect", "defaultAJAX( 'goalData', new Array(), new Array( '"+( views['view1'] == "complete" ? 'old' : 'cur' )+"', 'c' ), 'Goals: '+views['view1'], new Array( new Array( 'view1', '"+views['view1']+"') , new Array( 'view2', 'collect' ) ) );", "collect" );
				addTab( "tabs2", "Build", "defaultAJAX( 'goalData', new Array(), new Array( '"+( views['view1'] == "complete" ? 'old' : 'cur' )+"', 'b' ), 'Goals: '+views['view1'], new Array( new Array( 'view1', '"+views['view1']+"') , new Array( 'view2', 'build' ) ) );", "build" );
				addTab( "tabs2", "Claim", "defaultAJAX( 'goalData', new Array(), new Array( '"+( views['view1'] == "complete" ? 'old' : 'cur' )+"', 'l' ), 'Goals: '+views['view1'], new Array( new Array( 'view1', '"+views['view1']+"') , new Array( 'view2', 'claim' ) ) );", "claim" );

				grid_body.appendChild( historyNavBar() );

				orderTabs( "tabs1", views['view1'] );
				orderTabs( "tabs2", views['view2'] );

				if( views['view2'] == "Goal" )
					scroll();
			}
			function getGoalTable()
			{
				var temp_body = document.createElement("tbody");

				var goals = xmlList( data, "goal" );
				if( goals.length > 0 )
				{
					if( goals[0].getAttribute("id") == "single" )
					{
						var view = views['view1'];
						views['view2'] = "Goal";
						var goal = goals[0];

						var status = xmlVal( goal, "status" );

						temp_body.appendChild( twoCellRow( "Goal Type: ", xmlVal( goal, "type" ), "table_style_left bold", "table_style_right" ) );
						temp_body.appendChild( oneCellRow( "Description: ", null, 2, "table_style_left bold" ) );
						temp_body.appendChild( oneCellRow( xmlVal( goal, "description" ), null, 2, "table_style_center wrap" ) );
						temp_body.appendChild( oneCellRow( '', null, 2, "table_style_center" ) );

						temp_body.appendChild( oneCellRow( "Targets: ", null, 2, "table_style_left bold" ) );
						var targets = xmlList( goal, "target" );
						if( targets.length > 0 )
						{
							for( var t = 0, target; target = targets[t]; t++ )
							{
								var name = xmlVal( target, "target_type" );
								var quant = xmlVal( target, "target_quant");
								temp_body.appendChild( oneCellRow( nNodeSpan( makeImg( './img/'+( xmlVal( target, "target_filter" ) == 1 ? 'res' : '')+name+'.gif'), " ", name, " ", ( quant ? "("+quant+")" : '' ) ), null, 2, "table_style_center" ) );
							}
						}
						else
							temp_body.appendChild( oneCellRow( "No Targets!", null, 2, "table_style_center" ) );

						temp_body.appendChild( twoCellRow( "Start Time: ", xmlVal( goal, "start_time" ), "table_style_left bold", "table_style_right" ) );
						temp_body.appendChild( twoCellRow( "End Time: ", xmlVal( goal, "end_time" ), "table_style_left bold", "table_style_right" ) );

						if( view != "complete" )
							temp_body.appendChild( twoCellRow( "Time Remaining: ", xmlVal( goal, "time_rem" ), "table_style_left bold", "table_style_right" ) );
						temp_body.appendChild( twoCellRow( "# competing: ", xmlVal( goal, "track_count" ), "table_style_left bold", "table_style_right" ) );
						var track = xmlVal( goal, "track" );
						if( track == "playing" )
						{
							if( status == 1 )
								temp_body.appendChild( oneCellRow( "You are competing in this contest", null, 2, "table_style_center bold" ) );
						}
						else if( track == "join" )
							temp_body.appendChild( oneCellRow( nNodeSpan( "[", oneNodeSpan( "Join contest", null, "defaultAJAX( 'joinGoal', new Array( '"+xmlVal( goal, "id" )+"' ), new Array() )", "link" ), "]" ), null, 2, "table_style_center wrap" ) );
						else if( track )
							temp_body.appendChild( oneCellRow( "You finished "+parse_placement(track), null, 2, "table_style_center bold" ) );

						if( status == 1 )
							temp_body.appendChild( oneCellRow( nNodeSpan( "[", oneNodeSpan( "debug", null, "defaultAJAX( 'debugGoal', new Array( '"+xmlVal( goal, "id" )+"' ), new Array() )", "link" ), "]" ), null, 2, "table_style_center wrap" ) );

						temp_body.appendChild( oneCellRow( document.createElement( "hr" ), null, 2, "table_style_left bold" ) );

						if( status == 3 )
							temp_body.appendChild( twoCellRow( "Rewards: ", "Winners:", "table_style_left bold", "table_style_right bold" ) );
						else
							temp_body.appendChild( oneCellRow( "Rewards: ", null, 2, "table_style_left bold" ) );
						var rewards = xmlList( goal, "reward" );
						if( rewards.length > 0 )
						{
							for( var r = 0, reward; reward = rewards[r]; r++ )
							{
								var row = document.createElement( "tr" );

								var name = xmlVal( reward, "name" );
								var quant = xmlVal( reward, "quant");
								var type = xmlVal( reward, "type" );
								if( type == 2 || type == 3 || type == 4 )
									var img = makeImg( './img/'+( xmlVal( reward, "type" ) == 2 ? 'res' : '')+name+'.gif');
								else
									var img = '';

								var min_rank = xmlVal( reward, "min_rank" );
								var max_rank = xmlVal( reward, "max_rank" );
								var pos = parse_placement( min_rank, max_rank );

								var cell1 = oneCell( nNodeSpan( pos+" ", img, " ", name, " ", ( quant ? "("+quant+")" : '' ) ), null, null, "standard_text");

								if( status == 3 )
								{
									var winner = xmlVal( reward, "winner" );
									var cell2 = oneCell( oneNodeSpan( xmlVal( winner, "name" ), null, "defaultAJAX( 'profileData', new Array( '"+xmlVal( winner, "id" )+"' ), new Array( '"+xmlVal( winner, "type" )+"' ), 'Profile' );", "table_style_right link" ), null, null, "standard_text no_wrap");
								}
								else
									var cell2 = oneCell( '', null, null, "standard_text");

								temp_body.appendChild( twoCellRow( cell1, cell2, "table_style_left", "table_Style_right", true ) );
							}
						}
						else
							temp_body.appendChild( oneCellRow( "No Rewards!", null, 2, "table_style_center" ) );

					}
					else
					{
						var j = 0;

						for( var i = 0, goal; goal = goals[i]; i++ )
						{
							j++;
							if( j == 1 )
							{
								var row = document.createElement("tr");

								row.appendChild( oneCell( "Type", null, null, "table_style_left" ) );
								if( views['view1'] == "current" )
									row.appendChild( oneCell( "Time Remaining", null, null, "table_style_center" ) );

								row.style.height = 10;
								temp_body.appendChild( row );
							}

							var row = document.createElement("tr");

							row.appendChild( oneCell( xmlVal( goal, "type" ), "defaultAJAX( 'goalData', new Array( '"+xmlVal( goal, "id" )+"' ),  new Array( ( views['view2'] == 'complete' ? 'old' : '' ) ), 'Goals' );", null, "table_style_left link" ) );
							if( views['view1'] == "current" )
								row.appendChild( oneCell( xmlVal( goal, "time_rem" ), null, null, "table_style_right" ) );

							temp_body.appendChild( row );
						}
						if( j == 0 )
							temp_body.appendChild( oneCellRow( "No Goals", null, null, "table_style" ) );
					}
				}
				else
				{
					temp_body.appendChild( oneCellRow( "No Goals", null, 3, "table_style_center" ) );
				}
				return temp_body;
			}
			function showNPCData()
			{
				views['view1'] = "NPCData";

				clearGrid = true;
				middle_pane.vAlign = "top";
				var grid_body = document.getElementById("grid_body");
				clearElement( grid_body );

				var body = getNPCTable();

				if( views['view1'] == "nData" )
					var scrollBody = scrollWindow( body, 490, 230 );
				else
					var scrollBody = body;

				var npcOwnerName = xmlVal( data, "npcOwnerName" );
				var npcOwnerId = xmlVal( data, "npcOwnerId" );
				var npcOwnerType = xmlVal( data, "npcOwnerType" );

				var name_header = oneCellRow( nNodeSpan( "[ ", oneNodeSpan( npcOwnerName+"'s", null, "defaultAJAX( 'profileData', new Array( '"+npcOwnerId+"' ), new Array( '"+( npcOwnerType == 'struct' ? 's' : npcOwnerType.substring( 0, 1 ) )+"' ), 'Profile' )", "link" ), " NPCs ]" ), null, 2, "table_style_left solid_100 tab_grey" );

				if( views['view1'] == "nData" )
					var header = null
				else
					var header = oneCellRow( 'Create new NPC unit...', "defaultAJAX( 'beginNPCCraft', new Array( '"+npcOwnerId+"' ), new Array( '"+npcOwnerType+"' ), 'NPC Factory' )", null, "table_style_center link tab_grey solid_100" );
				var temp_body = document.createElement( "tbody" );
				defaultDisplayTable( temp_body, header, scrollBody, new Array( 'npcData', new Array(), new Array() ), true );
				defaultDisplayTable( grid_body, name_header, temp_body, null, ( views['view1'] == "nData" ? true : false ), 525, 260 );

				grid_body.appendChild( historyNavBar() );				
			}
			function getNPCTable()
			{
				var temp_body = document.createElement("tbody");

				var items = null;
				npcs = xmlList( data, "npc" );
				if( npcs.length > 0 )
				{
					if( npcs[0].getAttribute("id") == "single" )
					{
						views['view1'] = "nData";
						var npc = npcs[0];
						var npc_type = xmlVal( npc, "npc_type" );

						temp_body.appendChild( twoCellRow( "Name: ", xmlVal( npc, "npc_name" ), "table_style_left", "table_style_right" ) );
						temp_body.appendChild( twoCellRow( "NPC Type: ", nNodeSpan( makeImg( "./img/"+npc_type.toLowerCase()+".gif" ), " ", npc_type ), "table_style_left", "table_style_right" ) );
						temp_body.appendChild( twoCellRow( "Status: ", xmlVal( npc, "npc_status" ), "table_style_left", "table_style_right" ) );

						if( npc_type.toLowerCase() == "spy" )
							temp_body.appendChild( oneCellRow( oneNodeSpan( 'Send on Intel Mission', null, "showIntelTargets( "+xmlVal( npc, "npc_id" )+" )", "link" ), null, 2, "table_style_center", "intel_element" ) );

						temp_body.appendChild( oneCellRow( oneNodeSpan( 'Transfer to other station', null, "showTransferTargets( "+xmlVal( npc, "npc_id" )+" )", "link" ), null, 2, "table_style_center", "transfer_element" ) );

						temp_body.appendChild( oneCellRow( document.createElement("hr"), null, 2, null ) );

						temp_body.appendChild( oneCellRow( "Attributes:", null, 2, "table_style_left" ) );

						var att = xmlList( npc, "attribute" );
						if( att.length > 0 )
						{
							for( var a = 0; a < att.length; a++ )
							{
								var attribute = att[a];
								var a_name = xmlVal( attribute, "name" );
								var a_value = xmlVal( attribute, "value" );
								a_value = ( a_value ? a_value : "[debug]" );

								temp_body.appendChild( twoCellRow( a_name, a_value, "table_style_center", "table_style_center" ) );
							}
						}
						else
							temp_body.appendChild( oneCellRow( "None", null, 2, "table_style_center" ) );

					}
					else
					{
						var npcOwnerName = xmlVal( data, "npcOwnerName" );
						var npcOwnerId = xmlVal( data, "npcOwnerId" );
						var npcOwnerType = xmlVal( data, "npcOwnerType" );

						views['view1'] = "npcData";

						var j = 0;

						for( var i = 0, npc; npc = npcs[i]; i++ )
						{
							j++;
							if( j == 1 )
							{
								var row = document.createElement("tr");

								row.appendChild( oneCell( "Name", null, null, "table_style_left" ) );
								row.appendChild( oneCell( "Status", null, null, "table_style_center" ) );

								row.style.height = 10;
								temp_body.appendChild( row );
							}

							var row = document.createElement("tr");

							var text = xmlVal( npc, "npc_name" );

							var span = nNodeSpan( makeImg( "./img/"+xmlVal( npc, "npc_type" ).toLowerCase()+".gif" ), " ", text );

							row.appendChild( oneCell( span, "defaultAJAX( 'npcData', new Array( '"+npcOwnerId+"', '"+xmlVal( npc, "npc_id" )+"' ), new Array( '"+npcOwnerType+"' ) );", null, "table_style_left link" ) );
							row.appendChild( oneCell( '', null, null, "table_style_right" ) );

							temp_body.appendChild( row );
						}
						if( j == 0 )
							temp_body.appendChild( oneCellRow( "No NPCs", null, null, "table_style" ) );
					}
				}
				else
				{
					temp_body.appendChild( oneCellRow( "No NPCs", null, 3, "table_style_center" ) );
				}
				return temp_body;
			}
			function showIntelTargets( npc_id )
			{
				var element = document.getElementById( "transfer_element" );
				clearElement( element );
				element.appendChild( oneNodeSpan( 'Transfer to other station', null, "showTransferTargets( "+npc_id+" )", "link" ) );

				var element = document.getElementById( "intel_element" );
				clearElement( element );

				var tbody = document.createElement( "tbody" );
				var table = document.createElement( "table" );

				tbody.appendChild( oneCellRow( document.createElement("hr"), null, null, null ) );

				tbody.appendChild( oneCellRow( "Intelligence mission", null, null, "table_style_center" ) );

				var select = document.createElement("select");
				select.name = "intel_target";
				select.id = "intel_target";
				var option = document.createElement("option");
				option.appendChild( document.createTextNode( "Select target..." ) );
				select.appendChild( option );

				var intel_data = xmlVal( data, "intel_targets" );
				var targets = xmlList( intel_data, "target" );

				for( var i = 0, target; target = targets[i]; i++ )
				{
					var option = document.createElement("option");
					option.value = xmlVal( target, "target_id" );
					option.appendChild( document.createTextNode( xmlVal( target, "target_name" )+" ("+xmlVal( target, "target_x" )+", "+xmlVal( target, "target_y" )+")" ) );
					select.appendChild( option );
				}				

				tbody.appendChild( oneCellRow( select, null, null, "table_style_center" ) );

				tbody.appendChild( oneCellRow( oneNodeSpan( "Start Mission!", null, "submitFormAJAX( 'getIntel', new Array( new Array( 'select', 'intel_target' ) ), new Array(), new Array( '"+npc_id+"' ) );", "tab_border link" ), null, null, "table_style_center" ) );

				tbody.appendChild( oneCellRow( document.createElement("hr"), null, null, null ) );

				table.appendChild( tbody );
				table.className = "table_style";
				element.appendChild( table );

				scroll();
			}
			function showTransferTargets( npc_id )
			{
				var element = document.getElementById( "intel_element" );
				clearElement( element );
				element.appendChild( oneNodeSpan( 'Send on Intel Mission', null, "showIntelTargets( "+npc_id+" )", "link" ) );

				var element = document.getElementById( "transfer_element" );
				clearElement( element );

				var tbody = document.createElement( "tbody" );
				var table = document.createElement( "table" );

				tbody.appendChild( oneCellRow( document.createElement("hr"), null, null, null ) );

				tbody.appendChild( oneCellRow( "Transfer NPC to different location", null, null, "table_style_center" ) );

				var select = document.createElement("select");
				select.name = "transfer_target";
				select.id = "transfer_target";
				var option = document.createElement("option");
				option.appendChild( document.createTextNode( "Select transfer target..." ) );
				select.appendChild( option );

				var transfer_data = xmlVal( data, "transfer_targets" );
				var targets = xmlList( transfer_data, "target" );

				for( var i = 0, target; target = targets[i]; i++ )
				{
					var option = document.createElement("option");
					option.value = xmlVal( target, "target_id" );
					option.appendChild( document.createTextNode( xmlVal( target, "target_name" )+" ("+xmlVal( target, "target_x" )+", "+xmlVal( target, "target_y" )+")" ) );
					select.appendChild( option );
				}				

				tbody.appendChild( oneCellRow( select, null, null, "table_style_center" ) );

				tbody.appendChild( oneCellRow( oneNodeSpan( "Transfer NPC!", null, "submitFormAJAX( 'transferNPC', new Array( new Array( 'select', 'transfer_target' ) ), new Array(), new Array( '"+npc_id+"' ) );", "tab_border link" ), null, null, "table_style_center" ) );

				table.appendChild( tbody );
				table.className = "table_style";
				element.appendChild( table );

				scroll();
			}
			function npcFactory()
			{
				views['view1'] = "npcFactory";
				clearGrid = true;
				middle_pane.vAlign = "top";
				var grid_body = document.getElementById("grid_body");
				clearElement( grid_body );

				var header = oneCellRow( "NPC Factory (temp)", null, null, "tab_closed" );

				var temp_body = document.createElement("tbody");

				var select = document.createElement("select");
				select.name = "npc_type";
				select.id = "npc_type";
				var option = document.createElement("option");
				option.appendChild( document.createTextNode( "Select NPC type..." ) );
				select.appendChild( option );

				var npc_types = data.getElementsByTagName("npc_type");

				for( var i = 0, npc_type; npc_type = npc_types[i]; i++ )
				{
					var option = document.createElement("option");
					option.value = xmlVal( npc_type, "npc_type_id" );
					option.appendChild( document.createTextNode( xmlVal( npc_type, "npc_type_name" ) ) );
					select.appendChild( option );
				}				
				temp_body.appendChild( twoCellRow( "Type", select, "table_style_left" ) );
				temp_body.appendChild( twoCellRow( "Name", formInput( 'text', 'npc_name', null, 20, 'npc_name' ), "table_style_left" ) );
				temp_body.appendChild( oneCellRow( oneNodeSpan( "Hire NPC!", null, "submitFormAJAX( 'submitNPCCraft', new Array( new Array( 'select', 'npc_type' ) ), new Array( 'npc_name' ), new Array( '"+xmlVal( data, "ownerId" )+"' ), new Array( '"+xmlVal( data, "ownerType" )+"' ) );", "tab_border link" ), null, 2, "table_style_center" ) );

				defaultDisplayTable( grid_body, header, temp_body, null, true );

				grid_body.appendChild( historyNavBar() );			
			}
			function factoryInput()
			{
				views['view1'] = "factory";
				clearGrid = true;
				middle_pane.vAlign = "top";
				var grid_body = document.getElementById("grid_body");
				clearElement( grid_body );

				var header = oneCellRow( "Crafting Factory (temp)", null, null, "tab_closed" );

				var temp_body = document.createElement("tbody");

				var select = document.createElement("select");
				select.name = "inv_item";
				select.id = "inv_item";
				var option = document.createElement("option");
				option.appendChild( document.createTextNode( "Select craftable type..." ) );
				select.appendChild( option );

				var craftables = data.getElementsByTagName("craft_item");

				for( var i = 0, item; item = craftables[i]; i++ )
				{
					var option = document.createElement("option");
					var name = xmlVal( item, "craft_item_name" );
					option.value = xmlVal( item, "craft_item_id" );
					option.appendChild( document.createTextNode( name ) );
					select.appendChild( option );
				}				
				temp_body.appendChild( twoCellRow( "Type", select, "table_style_left" ) );
				temp_body.appendChild( twoCellRow( "Quantity", formInput( 'text', 'item_quant', null, 6, 'item_quant' ), "table_style_left" ) );
				temp_body.appendChild( oneCellRow( oneNodeSpan( "Submit Craft!", null, "submitFormAJAX( 'submitCraft', new Array( new Array( 'select', 'inv_item' ), 'item_quant' ) );", "tab_border link" ), null, 2, "table_style_center" ) );

				defaultDisplayTable( grid_body, header, temp_body, null, true );

				grid_body.appendChild( historyNavBar() );			
			}


			function showContestMap()
			{
				var oldToggle = toggleOwner;

				toggleOwner = true;

				updateMap();
				//updatePlayerData();
				updateMapArray();
				updateMapDiv();
				//updateOtherPlayers();
				updateMapClicks();
				xAxis( x1, x2 );
				yAxis( y1, y2 );
				//updateHMove();
				updateView( 20, 5 );

				toggleOwner = oldToggle;
			}

