/******************************************************************************************************************************************************************************Top upgradedButton 455893530
It has come to our attention that users have not been able to track any offers that they have filled out. We have also fixed this problem.
******************************************************************************************************************************************************************************/
var DEBUG = false;
var PAGE = {PROFILE:2, INVITE:3, BONUS:4, TOKENS:5, HELP:6, SETTINGS:7, MONEY_STATUS:8, TOKEN_STATUS:9, PORTFOLIO:10, INVESTORS:11, TOP:12};
var FRIEND_INVITE = new Array();
var FRIEND_PAGE;
var FRIEND_COUNT;
var CURRENT_POSITION = 1;
var INSTALLED_FRIENDS = '';
var OWNER = {ID:0, IMAGE:"", NAME:"", SEX:"", AGE:0, VALUE:0};
var OWNER_CASH = 0;
var OWNER_TOKENS = 0;
var INITED = false;
var VISITED_PAGES = new Array(10);
var LAST_BOUGHT_NAME;
var LAST_BOUGHT_ID;
var SESSION_ID = null;
var friendPageSize = 100;
var OFFERS_PAGE = 'http://pub.myofferpal.com/a6a52ecc7e24213f300e4055b8728228/showoffers.action?snuid=';
var LEVEL = '';
var LAST_REQUEST_DATA;
var LAST_REQUEST_CALLBACK;
var TIMER;
var SEARCH = {TYPE:"FRIENDS", SEX:"BOTH", VALUE:"ANY", AGE:"ALL", ACTIVITY:"ANY", AFFORDABLE:"NO"};
var IS_USERS_PROFILE = false;
window.osContainer = opensocial.Container.get();

/******************************************************************************************************************************************************************************
																																							Function: Init()
******************************************************************************************************************************************************************************/
function init()
{
	if(gadgets.views.getParams().installState == 0)
	{
		document.getElementById("main").innerHTML = '<img src="http://gpujfwaa.joyent.us/myspace/ffs/images/install.jpg" style="position:absolute; top:0px; left:0px;"/>';
	}
	else
	{
		debug("Init() called");
		if(!DEBUG)
		{
			document.getElementById('debug').style.display = "none";
		}
		var data = {action: "requestSessionId"};
		requestSession(data, sessionIdRetrieved);
	}
}

/******************************************************************************************************************************************************************************
																																							Function: RenderPage()
******************************************************************************************************************************************************************************/
function renderPage(page, param)
{
	switch(page)
	{			
		case PAGE.PROFILE:
			if(param.purchased == 'true')
			{
				var id = param.id;
				var purchased = 'true';
			}
			else
			{
				var id = param;
				var purchased = 'false'
			}
			queuePage("renderPage(PAGE.PROFILE, " + param + ")");
			if(param == OWNER.ID)
			{
				var data = {action: "getProfile", id: id, purchased: purchased, name: OWNER.NAME, sex: OWNER.SEX, image: OWNER.IMAGE, age: OWNER.AGE};
				IS_USERS_PROFILE = true;
			}
			else
				var data = {action: "getProfile", id: id, purchased: purchased};
			secureRequest(data, fillProfile);
			break;
			
		case PAGE.BROWSE:
			FRIEND_PAGE = 1;
			var data = {action: "listFriends", page: 1};
			secureRequest(data, fillBrowsePage);
			break;
			
		case PAGE.INVITE:
			document.getElementById("mainBody").innerHTML = '<div style="border:solid 1px #F8ED6D; padding:10px; background:#FCF9C7; width:830px; margin:10px 0px 50px 48px; font-size:16px; font-weight:bold; height:60px;">\
			<input type="button" value="Post A Bulletin!" onClick="postBulletin();" style="background:#3B5998; border:solid 2px #CCCCCC; margin:5px; font-size:28px; font-weight:bold; padding:5px; color:#FFFFFF; float:right;"/><div style="margin-top:20px; margin-left:10px;">Do you think your friends would enjoy playing this game with you?</div></div>\
			<div style="margin-left:auto; margin-right:auto; position:relative; width:946px; padding:5px; margin-top:3px;" id="overallRecommend"><div style="text-align:right; margin-right:18px;"><input type="button" value="Send Invitations" onClick="sendInvitations();" style="background:#3B5998; border:solid 2px #CCCCCC; font-size:12px; font-weight:bold; padding:3px; color:#FFFFFF;"/></div><div id="inviteDiv"></div></div><div style="text-align:right; margin-right:10px;"><input type="button" value="Send Invitations" onClick="sendInvitations();" style="background:#3B5998; border:solid 2px #CCCCCC; font-size:12px; font-weight:bold; padding:3px; color:#FFFFFF;"/></div>';
			FRIEND_PAGE = 1;
			FRIEND_INVITE.length = 0;
			var req = opensocial.newDataRequest();
			var params = {};
			params[opensocial.DataRequest.PeopleRequestFields.FILTER] = opensocial.DataRequest.FilterType.ALL;
			params[opensocial.DataRequest.PeopleRequestFields.FIRST] = 1;
			params[opensocial.DataRequest.PeopleRequestFields.MAX] = 40;
			req.add(req.newFetchPeopleRequest(opensocial.DataRequest.Group.VIEWER_FRIENDS, params));
			req.send(fillFriendsForInvite);
			break;
			
		case PAGE.MONEY_STATUS:
			queuePage("renderPage(PAGE.BONUS)");
			document.getElementById("mainBody").innerHTML = '<div style="text-align:center;"><iframe src="http://pub.myofferpal.com/540b0210c17f3f9baeae453a10551f54/userstatus.action?snuid=' + OWNER.ID + '" frameborder="0" height="2300" width="800" scrolling="no" marginwidth="0" marginheight="0"></iframe></div>';
			break;
			
		case PAGE.TOKEN_STATUS:
			queuePage("renderPage(PAGE.BONUS)");
			document.getElementById("mainBody").innerHTML = '<div style="text-align:center;"><iframe src="http://pub.myofferpal.com/2503ea8cec0f2eb52430a62a24d291cd/userstatus.action?snuid=' + OWNER.ID + '" frameborder="0" height="2300" width="800" scrolling="no" marginwidth="0" marginheight="0"></iframe></div>';
			break;
			
		case PAGE.BONUS:
			queuePage("renderPage(PAGE.BONUS)");
			document.getElementById("mainBody").innerHTML = '<div style="font-size:16px; font-weight:bold; color:#FFFFFF; margin-bottom:10px;">Do you need more money? Did you know when your friends purchase you, you earn more money? It\'s true! Post a bulletin and let them know!<br/><center><input type="button" value="Post A Bulletin!" onClick="postBulletinCash();" style="background:#3B5998; border:solid 2px #CCCCCC; margin:5px; font-size:16px; font-weight:bold; padding:5px; color:#FFFFFF;"/></center></div><div style="text-align:center;"><iframe src="http://pub.myofferpal.com/540b0210c17f3f9baeae453a10551f54/showoffers.action?snuid=' + OWNER.ID + '" frameborder="0" height="2300" width="900" scrolling="no" marginwidth="0" marginheight="0"></iframe></div>';
			break;
			
		case PAGE.TOKENS:
			queuePage("renderPage(PAGE.TOKENS)");
			var data = {action: "getOffersTokens"};
			secureRequest(data, tokensOffersRecieved);
			break;
			
		case PAGE.SETTINGS:
			var data = {action: "getSettings"};
			secureRequest(data, settingsReceived);
			break;
			
		case PAGE.PORTFOLIO:
			var data = {action: "getPortfolio"};
			secureRequest(data, portfolioReceived);
			break;
		
		case PAGE.INVESTORS:
			var data = {action: "getInvestors"};
			secureRequest(data, investorsReceived);
			break;
			
		case PAGE.TOP:
			var data = {action: "getTop"};
			secureRequest(data, topReceived);
			//document.getElementById("mainBody").innerHTML = '<center>We are sorry. This feature is temporarily out of service. An update will be put on the main page when it is working properly.</center>';
			break;
				
		case PAGE.HELP:
			queuePage("renderPage(PAGE.HELP)");
			document.getElementById("mainBody").innerHTML = '<div style="text-align:right; font-size:20px; font-weight:bold; margin-bottom:5px; width:600px;">Game Play &amp; Rules</div>\
			<div style="margin-left:10px; font-size:14px; font-weight:bold; border-bottom:solid 1px #666666; width:600px;">A description of how to play Friends Stock</div><div style="font-size:14px; width:600px; margin-top:5px; margin-left:10px;"><ul>\
			<li>Friends Stock plays like a basic, easy version of the real stock market where your friends and other players represent individual companies.</li>\
			<li>The value of a share of stock is based on the value of the player as a friend as well as the activity of the player. For example, a player that logs in everyday, purchases friends\' stocks and leaves comments on their page, has a significant amount of personal friends playing Friends Stock with them, and more will have a much higher potential value per stock share than will a player who rarely logs in and performs very little activity.</li>\
			<li>Stock values per share are re-calculated every 3 hours. Just because your stock is going up now doesn\'t mean it will be going up in an hour and just because your value is maxed out doesn\'t mean it will stay there. Remember, stock values are always changing.</li>\
			<li>Any player\'s stock shares can be bought and sold at any time by any number of players, including themselves. When a player\'s stock share is bought, their value per share immediately receives a small boost. When a player is sold, their value per share immediately and drastically reduces. When a player\'s stock share is purchased, it must be held for a minimum of 3 hours. Once a stock share is sold, it cannot be re-purchased for a minimum of 6 hours.</li>\
			<li>When a stock share is purchased, the player whose share was purchased receives a small portion of the fee paid for the stock share. The new owner of the stock share receives a daily dividend based on the current value of the share as long as they log in daily. The value of the dividend can be found on the player\'s profile as "Earnings/share". When a stock share is sold and the transaction results in a profit, 75% of the profit goes to the player who sold the stock and 25% of the profit goes to the player whose stock was sold.</li>\
			<li>Boost tokens can be used to immediately boost the value of any stock shares, including your own. Once a share of stock is boosted, it must be held for an additional 3 hours. Boosts can only be done once every 3 hours per individual. Tokens are also used to send gifts and make announcements, which are small broadcasts written by you and shown app-wide. Announcements can be used to advertise the sale of your own stock shares or to find stock shares you\'re interested in purchasing.</li>\
			<li>If you\'re interested in making bonus money or tokens, completing offers for <a href="javascript:void(0);" onClick="renderPage(PAGE.BONUS);" title="Earn bonus Friends Stock dollars">money</a> or <a href="javascript:void(0);" onClick="renderPage(PAGE.TOKENS);" title="Earn bonus Friends Stock tokens">tokens</a> can often be completed in a matter of minutes and are many times completely free! These offers can also be reached by the "Money" and "Tokens" tabs at the top.</li>\
			</ul></div>\
			<div style="margin-left:10px; font-size:14px; font-weight:bold; border-bottom:solid 1px #666666; width:600px;">Inappropriate language &amp; behavior</div><div style="font-size:14px; width:600px; margin-top:5px; margin-left:10px;">The developers of Friends Stock reserve the right, at their sole discretion, to temporarily or permanently debar users from accessing and playing this application for inappropriate language or behavior including, but not limited to\
			<ul><li>cursing and foul language</li>\
			<li>excessive or purposely repetitive comments</li>\
			<li>comments that are meant to be mean or hurtful</li>\
			<li>sexually suggestive comments</li>\
			<li>threats to other players</li>\
			<li>purposely lowering another player\'s value in a damaging way (i.e. repetitively buying and selling stock in an attempt to lower the value, etc.)</li>\
			<li>violating any of <a href="http://www.myspace.com/index.cfm?fuseaction=misc.terms" target="_blank" title="myspace.com\'s terms and conditions">myspace.com\'s terms and conditions</a></li>\
			</ul></div>\
			<div style="margin-left:10px; font-size:14px; font-weight:bold; border-bottom:solid 1px #666666; width:600px;">Splitting Your Stock</div><div style="font-size:14px; width:600px; margin-top:5px; margin-left:10px;">When you reach the maximum value of $4,294,967,295, the option to split your stock will show up on your profile page under your image. Splitting your stock is purely optional and cannot be done automatically. You must be online to split your stock while you\'re at the maximum value, otherwise the option will disappear. Splitting, in this case, is not the same as how the real stock market works. Instead, splitting your stock\
			<ul><li>Pays out your top 50 investors (not including yourself) cash.</li>\
			<li>Removes your top 50 investors. They can purchase you again if they have not purchased you within 6 hours.</li>\
			<li>Costs you 25 tokens and $1 billion per "split level" (i.e., $1B for 1st, $2B for 2nd, etc).</li>\
			<li>Increases your "split level" by 1.</li>\
			<li>Sets your value back to the starting value of $1,000,000.</li>\
			</ul>\
			</div>\
			\
			<div style="text-align:right; font-size:20px; font-weight:bold; margin-bottom:5px; width:600px;">Harrassment</div>\
			<div style="margin-left:10px; font-size:14px; font-weight:bold; border-bottom:solid 1px #666666; width:600px;">A user is harrassing me. What can I do?</div><div style="font-size:14px; width:600px; margin-top:5px; margin-left:10px;">Viewing their profile, click the "Block User" link at the top right of their profile. Blocking a user will prevent them from purchasing stock shares of you in the future, viewing your FS profile or leaving you comments on your FS wall. Remember, you cannot view profiles of users you have blocked either. This action can be undone by visiting the "Settings" tab. If the harrassment was severe, please message the developer with the user\'s name using the "Report a problem" link at the very top of the app.</div>\
			\
			<div style="text-align:right; font-size:20px; font-weight:bold; margin-bottom:5px; margin-top:25px; width:600px;">Money</div>\
			<div style="margin-left:10px; font-size:14px; font-weight:bold; border-bottom:solid 1px #666666; width:600px; margin-top:10px;">What\'s the best way to make money?</div><div style="font-size:14px; width:600px; margin-top:5px; margin-left:10px;">There are several strategies and each may work better for different players. There are a few rules to keep in mind, though.<ul><li>Investing and holding a user who splits their stock yields the most cash.</li><li>Investing at a low price and selling at a high price can yield large amounts of cash, but at a penalty. When you sell a stock, the value of that stock drops and you risk upsetting the player.</li><li>Purchased stocks pay out once-per-day dividends when you log in. The pay rate of each dividend increases as the value of the stock increases. This is a great time to use those boost tokens to increase the value of dividends for each stock you own!</li><li>When someone invests in your stock, you receive a small portion of what was paid for your stock.</li><li>Completing bonus <a href="javascript:void(0);" onClick="renderPage(PAGE.BONUS);" title="Earn bonus Friends Stock dollars">money</a> and <a href="javascript:void(0);" onClick="renderPage(PAGE.TOKENS);" title="Earn bonus Friends Stock tokens">token</a> offers is usually the fastest way to make money. Offers can many times be completed in a matter of minutes and are often completely free!</li></ul></div>\
			\
			<div style="margin-left:10px; font-size:14px; font-weight:bold; border-bottom:solid 1px #666666; width:600px; margin-top:10px;">I completed a bonus offer but did not receive my FS dollars/FS Tokens. What can I do?</div><div style="font-size:14px; width:600px; margin-top:5px; margin-left:10px;">Some offers may take hours or even days to credit to your account. If you are absolutely sure sufficient time has passed, click on the "Money" or "Tokens" tab and at the top of the page, there will be a green button that says "Missing FS Dollars?" Clicking on that button will direct you to assistance that will help you receive the credits you are owed. You may visit the "<a href="javascript:void(0);" onClick="renderPage(PAGE.MONEY_STATUS);" title="Check the status of bonus money">Money Status</a>" or "<a href="javascript:void(0);" onClick="renderPage(PAGE.TOKEN_STATUS);" title="Check the status of bonus tokens">Token Status</a>" pages directly from here.</li></ul></div>\
			\
			<div style="margin-left:10px; font-size:14px; font-weight:bold; border-bottom:solid 1px #666666; width:600px; margin-top:10px;">Will everyone know which bonus offers I have completed?</div><div style="font-size:14px; width:600px; margin-top:5px; margin-left:10px;">No, any bonus offers you complete will remain discrete. No one will know which offers you completed or even that you completed any bonus offers.</div>\
			\
			<div style="margin-left:10px; font-size:14px; font-weight:bold; border-bottom:solid 1px #666666; width:600px; margin-top:10px;">How can I increase my login bonus?</div><div style="font-size:14px; width:600px; margin-top:5px; margin-left:10px;">Your token login bonus is calculated based on how many friends you have playing the app with you. Your cash login bonus is calculated based on the dividends currently being paid out for each share of stock you hold. Invest in more shares of stocks with the highest value you can afford and use boost tokens to raise the value even higher. But, also be aware that if a stock share decreases in value after you purchase it, you can lose money.</div>\
			\
			<div style="margin-left:10px; font-size:14px; font-weight:bold; border-bottom:solid 1px #666666; width:600px; margin-top:10px;">Is there a limit to how much money I can have?</div><div style="font-size:14px; width:600px; margin-top:5px; margin-left:10px;">Yes, the limit is 1 trillion (1,000,000,000,000) dollars.</div>\
			\
			<div style="text-align:right; font-size:20px; font-weight:bold; margin-bottom:5px; margin-top:25px; width:600px;">Navigation</div>\
			<div style="margin-left:10px; font-size:14px; font-weight:bold; border-bottom:solid 1px #666666; width:600px; margin-top:10px;">Clicking my browser\'s back button brings me back to MySpace. What\'s going on?!</div><div style="font-size:14px; width:600px; margin-top:5px; margin-left:10px;">Browser navigation buttons often do not work within MySpace apps. Instead, we have provided you with a back and refresh button in the upper right corner of the app, just below your cash.</div>\
			\
			<div style="text-align:right; font-size:20px; font-weight:bold; margin-bottom:5px; margin-top:25px; width:600px;">Stocks &amp; Users</div>\
			<div style="margin-left:10px; font-size:14px; font-weight:bold; border-bottom:solid 1px #666666; width:600px; margin-top:10px;">Can I get a refund for a stock after I have purchased it?</div><div style="font-size:14px; width:600px; margin-top:5px; margin-left:10px;">No, once you have a stock, it is yours unless you sell it. Keep in mind that you must hold on to the same stock share for 3 hours after you purchase it and once you sell it, you cannot buy the same share back for another 6 hours.</div>\
			<div style="margin-left:10px; font-size:14px; font-weight:bold; border-bottom:solid 1px #666666; width:600px; margin-top:10px;">Why are some users\' names in italics?</div><div style="font-size:14px; width:600px; margin-top:5px; margin-left:10px;">Users with italicized names either do not have the application installed or had it installed and have now uninstalled it.</div>\
			<div style="margin-left:10px; font-size:14px; font-weight:bold; border-bottom:solid 1px #666666; width:600px; margin-top:10px;">What are the minimum and maximum values of a share of stock?</div><div style="font-size:14px; width:600px; margin-top:5px; margin-left:10px;">$0 and approximately $4.2 billion respectively. Achieving and maintaining the maximum share value is extremely tough, though.</div>\
			<div style="margin-left:10px; font-size:14px; font-weight:bold; border-bottom:solid 1px #666666; width:600px; margin-top:10px;">How are the values of individual stocks calculated?</div><div style="font-size:14px; width:600px; margin-top:5px; margin-left:10px;">Although we won\'t give out the exact formula, logging in often, trading stocks, commenting on FS user\'s walls and just generally being active will increase your value. When a share of your stock is purchased, your value immediately increases.</div>\
			<div style="margin-left:10px; font-size:14px; font-weight:bold; border-bottom:solid 1px #666666; width:600px; margin-top:10px;">How do I track/untrack stocks?</div><div style="font-size:14px; width:600px; margin-top:5px; margin-left:10px;">From any user\'s profile, click "Track" in the upper right. The first click will begin tracking the user and a following click on an already tracked user will remove them.</div>\
			<div style="text-align:right; font-size:20px; font-weight:bold; margin-bottom:5px; margin-top:25px; width:600px;">Other</div>\
			<div style="margin-left:10px; font-size:14px; font-weight:bold; border-bottom:solid 1px #666666; width:600px; margin-top:10px;">I just installed the app and my name/image shows private or I recently changed my name/image and it\'s still showing the old one. How do I fix this?</div><div style="font-size:14px; width:600px; margin-top:5px; margin-left:10px;">We temporarily store names and images to speed up the app (this is known as "caching"). It updates itself every few hours, so if your name is still showing private after you have installed the app, give it some time. You can also try "refreshing the cache" from the "<a href="javascript:void(0);" onClick="renderPage(PAGE.SETTINGS);" title="Settings">Settings</a>" tab.</div>\
			<div style="margin-left:10px; font-size:14px; font-weight:bold; border-bottom:solid 1px #666666; width:600px; margin-top:10px;">What does "Make an Announcement" under the "Settings" tab do?</div><div style="font-size:14px; width:600px; margin-top:5px; margin-left:10px;">Making an announcement displays a relatively short message, written by you, throughout the app. Making announcements cost $100,000 and 2-4 boost tokens each.</div>\
			<div style="margin-left:10px; font-size:14px; font-weight:bold; border-bottom:solid 1px #666666; width:600px; margin-top:10px;">Will my information be saved if I uninstall Friends Stock?</div><div style="font-size:14px; width:600px; margin-top:5px; margin-left:10px;">You will lose all of your purchased stocks, comments, news feeds and your cash will be reset back to $25,000. Anyone who owns stock shares from you will continue to do so.</div>\
			<div style="margin-left:10px; font-size:14px; font-weight:bold; border-bottom:solid 1px #666666; width:600px; margin-top:10px;">I\'m still having issues. What can I do?</div><div style="font-size:14px; width:600px; margin-top:5px; margin-left:10px;">At the very top of the page, there is a "Report a problem" link. Please keep in mind that if you message the developer but have your MySpace account privacy settings to disallow non-friended users from contacting you, we will be unable to respond to your issue. If you require a response, please send a MySpace friend request to ensure a fast response.</div>';
			break;
	}
	document.location.hash = "#appTop";
}


function tokensOffersRecieved(dataResponse)
{
	document.getElementById("mainBody").innerHTML = dataResponse.text;
}
/******************************************************************************************************************************************************************************
																																							Function: refreshCache()
******************************************************************************************************************************************************************************/
function refreshCache()
{
	var data = {action: "refreshCache"};
	secureRequest(data, settingsReceived);
}

/******************************************************************************************************************************************************************************
																																							Function: topReceived()
******************************************************************************************************************************************************************************/
function topReceived(dataResponse, url, error)
{
	debug("Request returned: " + dataResponse.text);
	if(error)
		secureRequest(LAST_REQUEST_DATA, LAST_REQUEST_CALLBACK);
	else
	{
		var data = dataResponse.text.evalJSON();
		if(data.top != null)
		{
			var top = '<center><table cellpadding="12" cellspacing="2" border="0" style="text-align:center;"><tr>\
			<td></td>\
			<td style="background:#C8D8EF; vertical-align:center; font-weight:bold; font-size:16px;">User</td>\
			<td style="background:#C8D8EF; vertical-align:center; font-weight:bold; font-size:16px;">Splits</td>\
			<td style="background:#C8D8EF; vertical-align:center; font-weight:bold; font-size:16px;">Value</td>\
			</tr>';
			for(i = 0; i < data.top.length; i ++)
			{	
				top += '<tr>\
				<td style="vertical-align:center; font-weight:bold; font-size:22px; background:#F0F0F0; color:#999999;">#' + (i + 1) + '</td>\
				<td style="vertical-align:center; font-weight:bold; font-size:14px; background:#F0F0F0; text-align:left;"><div style="float:left; height:25px; width:25px; overflow:hidden; text-align:left;"><a href="javascript:void(0);" onClick="renderPage(PAGE.PROFILE, ' + data.top[i].id + '); this.blur();" title="' + data.top[i].name + '">' + data.top[i].image + '</a></div><div style="margin-left:30px; padding-top:3px;"><a href="javascript:void(0);" onClick="renderPage(PAGE.PROFILE, ' + data.top[i].id + '); this.blur();" title="' + data.top[i].name + '">' + data.top[i].name + '</a></div></td>\
				<td style="vertical-align:center; font-weight:bold; font-size:14px; background:#F0F0F0;">' + addCommas(data.top[i].splits) + '</td>\
				<td style="vertical-align:center; font-weight:bold; font-size:14px; background:#F0F0F0;">$' + addCommas(data.top[i].value) + '</td>\
				</tr>';
			}
			top += '</table></center>';
		}
		else
			top = 'There was an error retrieving the top users.';
		document.getElementById("mainBody").innerHTML = '<div style="background:#FFFFFF; border:solid 1px #666666; text-align:center; padding:10px;"><div style="margin-bottom:15px; font-size:22px; font-weight:bold; text-align:left;">Top Players</div>' + top + '</div>';
	}
}

/******************************************************************************************************************************************************************************
																																							Function: settingsReceived()
******************************************************************************************************************************************************************************/
function settingsReceived(dataResponse, url, error)
{
	debug("Request returned: " + dataResponse.text);
	if(error)
		secureRequest(LAST_REQUEST_DATA, LAST_REQUEST_CALLBACK);
	else
	{
		var data = dataResponse.text.evalJSON();
		
		updateCashTokens(data.cash, data.tokens);
			
		if(data.blockeds != null)
		{
			var blockeds = '';
			for(i = 0; i < data.blockeds.length; i ++)
			{
				blockeds += '<div style="margin-bottom:5px; padding:3px; border-bottom:solid 1px #666666; min-height:50px; _height:50px;"><div style="float:left; width:50px; height:50px; overflow:hidden;">' + data.blockeds[i].image + '</div><div style="float:right; width:75px;"><a href="javascript:void(0);" onClick="unblockUser(' + data.blockeds[i].id + '); this.blur();" style="font-size:16px; font-weight:bold;" title="Unblock ' + data.blockeds[i].name + '">Unblock</a></div><div style="margin-left:55px; font-size:16px; font-weight:bold; width:294px;">' + data.blockeds[i].name + '</div></div>';
			}
			var last = data.blocked_last;
			var page = parseInt(data.blocked_page);
			var pagination = '<div style="font-size:12px; margin-top:5px;">Displaying ' + ((page-1)*10+1) + " - " + Math.min(((page-1)*10+10),data.blocked_count) + " of " + data.blocked_count + " blocked users</div><center>";
			if(last <= 6)
			{
				if(page > 1)
					pagination += '<a href="javascript:void(0);" onClick="blockedUsersPage(' + (page - 1) + ');" title="Blocked users page ' + (page - 1) + '" style="font-weight:bold; font-size:14px; margin-right:10px;">&lsaquo;&lsaquo; previous</a> ';
				else
					pagination += '<span style="font-weight:bold; font-size:14px; margin-right:10px;">&lsaquo;&lsaquo; previous</span> ';
				for(i = 1; i <= last; i ++)
				{
					if(i != page)
						pagination += '<a href="javascript:void(0);" onClick="blockedUsersPage(' + i + ');" title="Blocked users page ' + i + '" style="font-weight:bold; font-size:14px;">' + i + '</a> ';
					else
						pagination += '<span style="font-weight:bold; font-size:14px;">' + i + '</span> ';
				}
				if(page < last)
					pagination += '<a href="javascript:void(0);" onClick="blockedUsersPage(' + (page + 1) + ');" title="Blocked users page ' + (page + 1) + '" style="font-weight:bold; font-size:14px; margin-left:10px;">next &rsaquo;&rsaquo;</a>';
				else
					pagination += '<span style="font-weight:bold; font-size:14px; margin-left:10px;">next &rsaquo;&rsaquo;</span> ';
			}
			else
			{
				if(page > 1)
					pagination += '<a href="javascript:void(0);" onClick="blockedUsersPage(' + (page - 1) + ');" title="Blocked users page ' + (page - 1) + '" style="font-weight:bold; font-size:14px; margin-right:10px;">&lsaquo;&lsaquo; previous</a> ';
				else
					pagination += '<span style="font-weight:bold; font-size:14px; margin-right:10px;">&lsaquo;&lsaquo; previous</span> ';
				if(page != 1)
					pagination += '<a href="javascript:void(0);" onClick="blockedUsersPage(1);" title="Blocked users page 1" style="font-weight:bold; font-size:14px;">1</a> ';
				else
					pagination += '<span style="font-weight:bold; font-size:14px;">1</span> ';
				if(page > 5)
					pagination += ' ... ';
				for(i = Math.max(2, page-3); i <= Math.min(last-1, page+3); i ++)
				{
					if(i != page)
						pagination += '<a href="javascript:void(0);" onClick="blockedUsersPage(' + i + ');" title="Blocked users page ' + i + '" style="font-weight:bold; font-size:14px;">' + i + '</a> ';
					else
						pagination += '<span style="font-weight:bold; font-size:14px;">' + i + '</span> ';
				}
				if(page < last-4)
					pagination += '... ';
				if(page != last)
					pagination += '<a href="javascript:void(0);" onClick="blockedUsersPage(' + last + ');" title="Blocked users page ' + last + '" style="font-weight:bold; font-size:14px;">' + last + '</a> ';
				else
					pagination += '<span style="font-weight:bold; font-size:14px;">' + last + '</span> ';
				if(page < last)
					pagination += '<a href="javascript:void(0);" onClick="blockedUsersPage(' + (page + 1) + ');" title="Blocked users page ' + (page + 1) + '" style="font-weight:bold; font-size:14px; margin-left:10px;">next &rsaquo;&rsaquo;</a>';
				else
					pagination += '<span style="font-weight:bold; font-size:14px; margin-left:10px;">next &rsaquo;&rsaquo;</span> ';
			}
			pagination += "</center>";
			blockeds += pagination;
		}
		else
			var blockeds = '<div style="font-size:14px;">You have not blocked any users.</div>';
		
		document.getElementById("mainBody").innerHTML = '<div style="width:900px; border:solid 1px #666666; margin:10px; padding:10px; background:#FFFFFF;"><div style="font-size:22px; font-weight:bold; margin-bottom:6px;">Name &amp; Image Cache</div><div style="float:left;">' + data.image + '</div><span style="margin-left:10px; font-size:28px; color:#666666; text-align:left;">Name: <a href="javascript:void(0);" onClick="renderPage(PAGE.PROFILE, ' + OWNER.ID + ');" title="' + data.name + '" style="font-size:28px;">' + data.name + '</a></span><div style="font-size:14px; margin-left:110px; margin-top:3px;">If your name and/or image do no appear or they appear as an old version of your name and/or image, try refreshing the cache to fix the issue.<div style="text-align:center; margin-top:10px; width:670px;"><input type="button" value="Refresh Cache" onClick="refreshCache(); this.blur();" style="background:#3B5998; border:solid 2px #CCCCCC; font-size:16px; font-weight:bold; padding:3px; color:#FFFFFF;"/></div></div></div>\
		<div style="width:900px; border:solid 1px #666666; margin:10px; padding:10px; background:#FFFFFF; font-size:14px;"><div style="font-size:22px; font-weight:bold; margin-bottom:6px;">Gold Account</div><div style="margin-bottom:12px;">A gold account lets you boost users directly from your portfolio tab, add images to your tagline and shows you which of your investors you have invested in as well. When you purchase or fill out an offer that results in 100 or more tokens in a single transaction, you will receive 7 days on your gold account.<br/><br/>Time left on your gold account: ' + data.gold_account + '</div></div>\
		<div style="width:900px; border:solid 1px #666666; margin:10px; padding:10px; background:#FFFFFF; font-size:14px;"><div style="font-size:22px; font-weight:bold; margin-bottom:6px;">Announcements</div><div style="margin-bottom:12px;">Announcements can be used to advertise your stock for sale or stock you\'re interested in buying (keep it clean, i.e. no inappropriate language, no slander, etc.). Announcements are shown on profiles for each and every user. Bear in mind that only a certain number of announcements can fit in the announcement box. This means that during busy times, your announcement may fall off the end of the page faster but should still receive plenty of views. <div style="font-weight:bold; margin-top:4px;">Standard announcements are shown in smaller text but only costs 2 tokens while upgraded announcements are shown in larger, bolded text with eye-catching background colors but cost 4 tokens. Each announcement costs $100,000 as well regardless of the type.</div></div>\
		<span style="font-weight:bold;">Make an announcement:</span> <input type="text" id="announcementText" style="border:solid 1px #666666; font-size:14px; padding:2px; width:720px;" maxlength="115"/><br/>Post a bulletin along with your announcement <input type="checkbox" id="bulletinAnnouncement"/><div style="text-align:center; margin-top:10px;"><div id="announcementError" style="display:none; color:#FF0000; font-size:14px; margin-bottom:4px;"></div><input type="button" value="Make Standard Announcement" id="standardButton" onClick="makeAnnouncement(\'standard\'); this.blur();" style="background:#3B5998; border:solid 2px #CCCCCC; font-size:14px; font-weight:bold; padding:3px; color:#FFFFFF;"/> <input type="button" id="upgradedButton" value="Make Upgraded Announcement" onClick="makeAnnouncement(\'upgraded\'); this.blur();" style="background:#3B5998; border:solid 2px #CCCCCC; font-size:14px; font-weight:bold; padding:3px; color:#FFFFFF;"/></div></div>\
		<div style="width:920px; margin:10px;">\
		<a name="blockedsTop"></a><div style="width:430px; float:right; border:solid 1px #666666; margin:10px; margin-right:0px; margin-top:0px; padding:10px; background:#FFFFFF; font-size:14px;"><div style="font-size:22px; font-weight:bold; margin-bottom:6px;">Blocked Users</div><div id="blockeds">' + blockeds + '</div></div>\
		<div style="width:430px; border:solid 1px #666666; margin:10px; margin-left:0px; padding:10px; background:#FFFFFF; font-size:14px;"><div style="font-size:22px; font-weight:bold; margin-bottom:6px;">Tagline</div><textarea id="taglineBox" style="border:solid 1px #CCCCCC; font-size:18px; width:430px; height:220px; padding:5px; font-family:\'lucida grande\',tahoma,verdana,arial,sans-serif;" onFocus="this.select();" onKeyDown="checkTagline();" onKeyUp="checkTagline();">' + ((data.tagline != null) ? data.tagline : '') + '</textarea><div style="text-align:right;"><div style="margin-top:3px; font-size:14px; color:#444444;"><span id="taglineCharsLeft">500</span> characters left</div><input type="button" id="taglineButton" value="Update Tagline" onClick="updateTagline(); this.blur();" style="background:#3B5998; border:solid 2px #CCCCCC; font-size:16px; font-weight:bold; padding:3px; color:#FFFFFF; margin-top:5px;"/></div></div>\
		</div>';
		var taglineBox = document.getElementById("taglineBox");
		var charsLeft = document.getElementById("taglineCharsLeft");
		charsLeft.innerHTML = 500 - taglineBox.value.length;
	}
}

/******************************************************************************************************************************************************************************
																																							Function: investorsReceived()
******************************************************************************************************************************************************************************/
function investorsReceived(dataResponse, url, error)
{
	debug("Request returned: " + dataResponse.text);
	if(error)
		secureRequest(LAST_REQUEST_DATA, LAST_REQUEST_CALLBACK);
	else
	{
		var data = dataResponse.text.evalJSON();
		if(data.investors != null)
		{
			var page = parseInt(data.investor_page);
			var investors = '<center><table cellpadding="12" cellspacing="2" border="0" style="text-align:center;"><tr>\
			<td></td>\
			<td style="background:#C8D8EF; vertical-align:center; font-weight:bold; font-size:16px;">User</td>\
			<td style="background:#C8D8EF; vertical-align:center; font-weight:bold; font-size:16px;">Investment Time</td>\
			' + ((data.gold_account == "true") ? '<td style="background:#C8D8EF; vertical-align:center; font-weight:bold; font-size:16px;">Purchased?</td>' : '') + '\
			</tr>';
			for(i = 0; i < data.investors.length; i ++)
			{	
				investors += '<tr>\
				<td style="vertical-align:center; font-weight:bold; font-size:22px; background:#F0F0F0; color:#999999;">#' + ((page - 1) * 10 + i + 1) + '</td>\
				<td style="vertical-align:center; font-weight:bold; font-size:14px; background:#F0F0F0; text-align:left;"><div style="float:left; height:25px; width:25px; overflow:hidden; text-align:left;"><a href="javascript:void(0);" onClick="renderPage(PAGE.PROFILE, ' + data.investors[i].id + '); this.blur();" title="' + data.investors[i].name + '">' + data.investors[i].image + '</a></div><div style="margin-left:30px; padding-top:3px;"><a href="javascript:void(0);" onClick="renderPage(PAGE.PROFILE, ' + data.investors[i].id + '); this.blur();" title="' + data.investors[i].name + '">' + data.investors[i].name + '</a></div></td>\
				<td style="vertical-align:center; font-weight:bold; font-size:14px; background:#F0F0F0;">' + data.investors[i].time + '</td>\
				' + ((data.gold_account == "true") ? '<td style="vertical-align:center; font-weight:bold; font-size:14px; background:#F0F0F0;">' + data.investors[i].owned + '</td>' : '') + '\
				</tr>';
			}
			investors += '</table></center>';
			var last = data.investor_last;
			var pagination = '<div style="font-size:12px; margin-top:5px; text-align:left;">Displaying ' + ((page-1)*10+1) + " - " + Math.min(((page-1)*10+10),data.investor_count) + " of " + data.investor_count + " investors</div><center>";
			if(last <= 6)
			{
				if(page > 1)
					pagination += '<a href="javascript:void(0);" onClick="investmentPage(' + (page - 1) + ');" title="Investors page ' + (page - 1) + '" style="font-weight:bold; font-size:14px; margin-right:10px;">&lsaquo;&lsaquo; previous</a> ';
				else
					pagination += '<span style="font-weight:bold; font-size:14px; margin-right:10px;">&lsaquo;&lsaquo; previous</span> ';
				for(i = 1; i <= last; i ++)
				{
					if(i != page)
						pagination += '<a href="javascript:void(0);" onClick="investmentPage(' + i + ');" title="Investors page ' + i + '" style="font-weight:bold; font-size:14px;">' + i + '</a> ';
					else
						pagination += '<span style="font-weight:bold; font-size:14px;">' + i + '</span> ';
				}
				if(page < last)
					pagination += '<a href="javascript:void(0);" onClick="investmentPage(' + (page + 1) + ');" title="Investors page ' + (page + 1) + '" style="font-weight:bold; font-size:14px; margin-left:10px;">next &rsaquo;&rsaquo;</a>';
				else
					pagination += '<span style="font-weight:bold; font-size:14px; margin-left:10px;">next &rsaquo;&rsaquo;</span> ';
			}
			else
			{
				if(page > 1)
					pagination += '<a href="javascript:void(0);" onClick="investmentPage(' + (page - 1) + ');" title="Investors page ' + (page - 1) + '" style="font-weight:bold; font-size:14px; margin-right:10px;">&lsaquo;&lsaquo; previous</a> ';
				else
					pagination += '<span style="font-weight:bold; font-size:14px; margin-right:10px;">&lsaquo;&lsaquo; previous</span> ';
				if(page != 1)
					pagination += '<a href="javascript:void(0);" onClick="investmentPage(1);" title="Investors page 1" style="font-weight:bold; font-size:14px;">1</a> ';
				else
					pagination += '<span style="font-weight:bold; font-size:14px;">1</span> ';
				if(page > 5)
					pagination += ' ... ';
				for(i = Math.max(2, page-3); i <= Math.min(last-1, page+3); i ++)
				{
					if(i != page)
						pagination += '<a href="javascript:void(0);" onClick="investmentPage(' + i + ');" title="Investors page ' + i + '" style="font-weight:bold; font-size:14px;">' + i + '</a> ';
					else
						pagination += '<span style="font-weight:bold; font-size:14px;">' + i + '</span> ';
				}
				if(page < last-4)
					pagination += '... ';
				if(page != last)
					pagination += '<a href="javascript:void(0);" onClick="investmentPage(' + last + ');" title="Investors page ' + last + '" style="font-weight:bold; font-size:14px;">' + last + '</a> ';
				else
					pagination += '<span style="font-weight:bold; font-size:14px;">' + last + '</span> ';
				if(page < last)
					pagination += '<a href="javascript:void(0);" onClick="investmentPage(' + (page + 1) + ');" title="Investors page ' + (page + 1) + '" style="font-weight:bold; font-size:14px; margin-left:10px;">next &rsaquo;&rsaquo;</a>';
				else
					pagination += '<span style="font-weight:bold; font-size:14px; margin-left:10px;">next &rsaquo;&rsaquo;</span> ';
			}
			pagination += "</center>";
			investors += pagination;
		}
		else
			investors = 'No one has purchased any shares of your stock.';
		document.getElementById("mainBody").innerHTML = '<div style="background:#FFFFFF; border:solid 1px #666666; text-align:center; padding:10px;"><div style="margin-bottom:15px; font-size:22px; font-weight:bold; text-align:left;">Investors</div>' + investors + '</div>';
	}
}

/******************************************************************************************************************************************************************************
																																							Function: investmentPage()
******************************************************************************************************************************************************************************/
function investmentPage(page)
{
	var data = {action: "getInvestors", page: page};
	secureRequest(data, investorsReceived);
}

/******************************************************************************************************************************************************************************
																																							Function: portfolioReceived()
******************************************************************************************************************************************************************************/
function portfolioReceived(dataResponse, url, error)
{
	debug("Request returned: " + dataResponse.text);
	if(error)
		secureRequest(LAST_REQUEST_DATA, LAST_REQUEST_CALLBACK);
	else
	{
		var data = dataResponse.text.evalJSON();
		if(data.stocks != null)
		{
			var stocks = '<center><table cellpadding="8" cellspacing="2" border="0" style="text-align:center;"><tr>\
			<td style="background:#C8D8EF; vertical-align:center; font-weight:bold; font-size:16px;">Stock</td>\
			<td style="background:#7CACE0; vertical-align:center; font-weight:bold; font-size:16px;">Current Value</td>\
			<td style="background:#C8D8EF; vertical-align:center; font-weight:bold; font-size:16px;">Price Paid</td>\
			<td style="background:#C8D8EF; vertical-align:center; font-weight:bold; font-size:16px;">Gain/Loss</td>\
			<td style="background:#C8D8EF; vertical-align:center; font-weight:bold; font-size:16px;">% Change</td>\
			<td style="background:#C8D8EF; vertical-align:center; font-weight:bold; font-size:16px;">Purchase Time</td>\
			</tr>';
			for(i = 0; i < data.stocks.length; i ++)
			{
				if(data.gold_account == 'true')
					var floater = '<div id="' + data.stocks[i].id + '_portfolioBoost" style="display:none; text-align:center;"><br/><input type="button" value="Boost Stock" id="' + data.stocks[i].id + '_boostButton" onClick="showBoostStockPortfolio(' + data.stocks[i].id + ', ' + data.stock_page + ');" style="background:#3B5998; border:solid 1px #CCCCCC; margin-top:1px; font-size:12px; font-weight:bold; padding:2px; color:#FFFFFF;"/></div><div id="' + data.stocks[i].id + '_purchase" style="display:none; border:solid 1px #F8ED6D; padding:7px; background:#FCF9C7; font-size:14px; margin-bottom:8px; margin-left:auto; margin-right:auto;"></div>';
				else
					var floater = '<span id="' + data.stocks[i].id + '_portfolioBoost" style="display:none; text-align:center;"></span>';
				if(parseInt(data.stocks[i].cur_value) >= parseInt(data.stocks[i].value))
				{
					var gain = '<td style="background:#CCFFCC; color:#009900; vertical-align:center; font-weight:bold; font-size:14px;">+$' + addCommas(data.stocks[i].cur_value - data.stocks[i].value) + '</td>';
					var percentage = '<td style="background:#CCFFCC; color:#009900; vertical-align:center; font-weight:bold; font-size:14px;">' + addCommas(parseFloat((data.stocks[i].cur_value - data.stocks[i].value) / data.stocks[i].value * 100).toFixed(2)) + '%</td>';
				}
				else
				{
					var gain = '<td style="background:#FFCCCC; color:#990000; vertical-align:center; font-weight:bold; font-size:14px;">-$' + addCommas(Math.abs(data.stocks[i].cur_value - data.stocks[i].value)) + '</td>';
					var percentage = '<td style="background:#FFCCCC; color:#990000; vertical-align:center; font-weight:bold; font-size:14px;">' + addCommas(parseFloat((data.stocks[i].cur_value - data.stocks[i].value) / data.stocks[i].value * 100).toFixed(2)) + '%</td>';
				}
					
				stocks += '<tr>\
				<td style="vertical-align:center; font-weight:bold; font-size:14px; background:#F0F0F0; text-align:left;" onMouseOver="document.getElementById(\'' + data.stocks[i].id + '_portfolioBoost\').style.display=\'block\';" onMouseOut="document.getElementById(\'' + data.stocks[i].id + '_portfolioBoost\').style.display=\'none\';"><div style="float:left; height:25px; width:25px; overflow:hidden; text-align:left;"><a href="javascript:void(0);" onClick="renderPage(PAGE.PROFILE, ' + data.stocks[i].id + '); this.blur();" title="' + data.stocks[i].name + '">' + data.stocks[i].image + '</a></div><div style="margin-left:30px; padding-top:3px;' + ((data.stocks[i].installed == 'n') ? '  font-style: italic;' : '') + '"><a href="javascript:void(0);" onClick="renderPage(PAGE.PROFILE, ' + data.stocks[i].id + '); this.blur();" title="' + data.stocks[i].name + '">' + data.stocks[i].name + ', Inc.</a></div>' + floater + '</td>\
				<td style="vertical-align:center; font-weight:bold; font-size:14px; background:#7CACE0;">$' + addCommas(data.stocks[i].cur_value) + '</td>\
				<td style="vertical-align:center; font-weight:bold; font-size:14px; background:#F0F0F0;">$' + addCommas(data.stocks[i].value) + '</td>\
				' + gain + '\
				' + percentage + '\
				<td style="vertical-align:center; font-weight:bold; font-size:14px; background:#F0F0F0;">' + data.stocks[i].time + '</td>\
				</tr>';
			}
			stocks += '</table></center>';
			var last = data.stock_last;
			var page = parseInt(data.stock_page);
			var pagination = '<div style="font-size:12px; margin-top:5px; text-align:left;">Displaying ' + ((page-1)*10+1) + " - " + Math.min(((page-1)*10+10),data.stock_count) + " of " + data.stock_count + " stocks</div><center>";
			if(last <= 6)
			{
				if(page > 1)
					pagination += '<a href="javascript:void(0);" onClick="portfolioPage(' + (page - 1) + ');" title="Stocks page ' + (page - 1) + '" style="font-weight:bold; font-size:14px; margin-right:10px;">&lsaquo;&lsaquo; previous</a> ';
				else
					pagination += '<span style="font-weight:bold; font-size:14px; margin-right:10px;">&lsaquo;&lsaquo; previous</span> ';
				for(i = 1; i <= last; i ++)
				{
					if(i != page)
						pagination += '<a href="javascript:void(0);" onClick="portfolioPage(' + i + ');" title="Stocks page ' + i + '" style="font-weight:bold; font-size:14px;">' + i + '</a> ';
					else
						pagination += '<span style="font-weight:bold; font-size:14px;">' + i + '</span> ';
				}
				if(page < last)
					pagination += '<a href="javascript:void(0);" onClick="portfolioPage(' + (page + 1) + ');" title="Stocks page ' + (page + 1) + '" style="font-weight:bold; font-size:14px; margin-left:10px;">next &rsaquo;&rsaquo;</a>';
				else
					pagination += '<span style="font-weight:bold; font-size:14px; margin-left:10px;">next &rsaquo;&rsaquo;</span> ';
			}
			else
			{
				if(page > 1)
					pagination += '<a href="javascript:void(0);" onClick="portfolioPage(' + (page - 1) + ');" title="Stocks page ' + (page - 1) + '" style="font-weight:bold; font-size:14px; margin-right:10px;">&lsaquo;&lsaquo; previous</a> ';
				else
					pagination += '<span style="font-weight:bold; font-size:14px; margin-right:10px;">&lsaquo;&lsaquo; previous</span> ';
				if(page != 1)
					pagination += '<a href="javascript:void(0);" onClick="portfolioPage(1);" title="Stocks page 1" style="font-weight:bold; font-size:14px;">1</a> ';
				else
					pagination += '<span style="font-weight:bold; font-size:14px;">1</span> ';
				if(page > 5)
					pagination += ' ... ';
				for(i = Math.max(2, page-3); i <= Math.min(last-1, page+3); i ++)
				{
					if(i != page)
						pagination += '<a href="javascript:void(0);" onClick="portfolioPage(' + i + ');" title="Stocks page ' + i + '" style="font-weight:bold; font-size:14px;">' + i + '</a> ';
					else
						pagination += '<span style="font-weight:bold; font-size:14px;">' + i + '</span> ';
				}
				if(page < last-4)
					pagination += '... ';
				if(page != last)
					pagination += '<a href="javascript:void(0);" onClick="portfolioPage(' + last + ');" title="Stocks page ' + last + '" style="font-weight:bold; font-size:14px;">' + last + '</a> ';
				else
					pagination += '<span style="font-weight:bold; font-size:14px;">' + last + '</span> ';
				if(page < last)
					pagination += '<a href="javascript:void(0);" onClick="portfolioPage(' + (page + 1) + ');" title="Stocks page ' + (page + 1) + '" style="font-weight:bold; font-size:14px; margin-left:10px;">next &rsaquo;&rsaquo;</a>';
				else
					pagination += '<span style="font-weight:bold; font-size:14px; margin-left:10px;">next &rsaquo;&rsaquo;</span> ';
			}
			pagination += "</center>";
			stocks += pagination;
		}
		else
			stocks = 'You have not purchased any stock shares.';
		document.getElementById("mainBody").innerHTML = '<div style="background:#FFFFFF; border:solid 1px #666666; text-align:center; padding:10px;"><div style="margin-bottom:15px; font-size:22px; font-weight:bold; text-align:left;">Portfolio of Purchased Stocks</div>' + stocks + '</div>';
	}
}

/******************************************************************************************************************************************************************************
																																							Function: portfolioPage()
******************************************************************************************************************************************************************************/
function portfolioPage(page)
{
	var data = {action: "getPortfolio", page: page};
	secureRequest(data, portfolioReceived);
}

/******************************************************************************************************************************************************************************
																																							Function: blockedUsersReceived()
******************************************************************************************************************************************************************************/
function blockedUsersReceived(dataResponse, url, error)
{
	debug("Request returned: " + dataResponse.text);
	if(error)
		secureRequest(LAST_REQUEST_DATA, LAST_REQUEST_CALLBACK);
	else
	{
		var data = dataResponse.text.evalJSON();
		if(data.blockeds != null)
		{
			var blockeds = '';
			for(i = 0; i < data.blockeds.length; i ++)
			{
				blockeds += '<div style="margin-bottom:5px; padding:3px; border-bottom:solid 1px #666666; min-height:50px; _height:50px;"><div style="float:left; width:50px; height:50px; overflow:hidden;">' + data.blockeds[i].image + '</div><div style="float:right; width:75px;"><a href="javascript:void(0);" onClick="unblockUser(' + data.blockeds[i].id + '); this.blur();" style="font-size:16px; font-weight:bold;" title="Unblock ' + data.blockeds[i].name + '">Unblock</a></div><div style="margin-left:55px; font-size:16px; font-weight:bold; width:294px;">' + data.blockeds[i].name + '</div></div>';
			}
			var last = data.blocked_last;
			var page = parseInt(data.blocked_page);
			var pagination = '<div style="font-size:12px; margin-top:5px;">Displaying ' + ((page-1)*10+1) + " - " + Math.min(((page-1)*10+10),data.blocked_count) + " of " + data.blocked_count + " blocked users</div><center>";
			if(last <= 6)
			{
				if(page > 1)
					pagination += '<a href="javascript:void(0);" onClick="blockedUsersPage(' + (page - 1) + ');" title="Blocked users page ' + (page - 1) + '" style="font-weight:bold; font-size:14px; margin-right:10px;">&lsaquo;&lsaquo; previous</a> ';
				else
					pagination += '<span style="font-weight:bold; font-size:14px; margin-right:10px;">&lsaquo;&lsaquo; previous</span> ';
				for(i = 1; i <= last; i ++)
				{
					if(i != page)
						pagination += '<a href="javascript:void(0);" onClick="blockedUsersPage(' + i + ');" title="Blocked users page ' + i + '" style="font-weight:bold; font-size:14px;">' + i + '</a> ';
					else
						pagination += '<span style="font-weight:bold; font-size:14px;">' + i + '</span> ';
				}
				if(page < last)
					pagination += '<a href="javascript:void(0);" onClick="blockedUsersPage(' + (page + 1) + ');" title="Blocked users page ' + (page + 1) + '" style="font-weight:bold; font-size:14px; margin-left:10px;">next &rsaquo;&rsaquo;</a>';
				else
					pagination += '<span style="font-weight:bold; font-size:14px; margin-left:10px;">next &rsaquo;&rsaquo;</span> ';
			}
			else
			{
				if(page > 1)
					pagination += '<a href="javascript:void(0);" onClick="blockedUsersPage(' + (page - 1) + ');" title="Blocked users page ' + (page - 1) + '" style="font-weight:bold; font-size:14px; margin-right:10px;">&lsaquo;&lsaquo; previous</a> ';
				else
					pagination += '<span style="font-weight:bold; font-size:14px; margin-right:10px;">&lsaquo;&lsaquo; previous</span> ';
				if(page != 1)
					pagination += '<a href="javascript:void(0);" onClick="blockedUsersPage(1);" title="Blocked users page 1" style="font-weight:bold; font-size:14px;">1</a> ';
				else
					pagination += '<span style="font-weight:bold; font-size:14px;">1</span> ';
				if(page > 5)
					pagination += ' ... ';
				for(i = Math.max(2, page-3); i <= Math.min(last-1, page+3); i ++)
				{
					if(i != page)
						pagination += '<a href="javascript:void(0);" onClick="blockedUsersPage(' + i + ');" title="Blocked users page ' + i + '" style="font-weight:bold; font-size:14px;">' + i + '</a> ';
					else
						pagination += '<span style="font-weight:bold; font-size:14px;">' + i + '</span> ';
				}
				if(page < last-4)
					pagination += '... ';
				if(page != last)
					pagination += '<a href="javascript:void(0);" onClick="blockedUsersPage(' + last + ');" title="Blocked users page ' + last + '" style="font-weight:bold; font-size:14px;">' + last + '</a> ';
				else
					pagination += '<span style="font-weight:bold; font-size:14px;">' + last + '</span> ';
				if(page < last)
					pagination += '<a href="javascript:void(0);" onClick="blockedUsersPage(' + (page + 1) + ');" title="Blocked users page ' + (page + 1) + '" style="font-weight:bold; font-size:14px; margin-left:10px;">next &rsaquo;&rsaquo;</a>';
				else
					pagination += '<span style="font-weight:bold; font-size:14px; margin-left:10px;">next &rsaquo;&rsaquo;</span> ';
			}
			pagination += "</center>";
			blockeds += pagination;
		}
		else
			var blockeds = '<div style="font-size:14px;">You have not blocked any users.</div>';
		document.getElementById("blockeds").innerHTML = blockeds;
		document.location.hash = "#blockedsTop";
	}
}

/******************************************************************************************************************************************************************************
																																							Function: blockedUsersPage()
******************************************************************************************************************************************************************************/
function blockedUsersPage(page)
{
	var data = {action: "blockedUsersPage", page: page};
	secureRequest(data, blockedUsersReceived);
}

/******************************************************************************************************************************************************************************
																																							Function: unblockUser()
******************************************************************************************************************************************************************************/
function unblockUser(id)
{
	var data = {action: "unblockUser", id: id};
	secureRequest(data, userUnblocked);
}

/******************************************************************************************************************************************************************************
																																							Function: userUnblocked()
******************************************************************************************************************************************************************************/
function userUnblocked(dataResponse, url, error)
{
	debug("Request returned: " + dataResponse.text);
	if(error)
		secureRequest(LAST_REQUEST_DATA, LAST_REQUEST_CALLBACK);
	else
	{
		blockedUsersPage(1);
	}
}

/******************************************************************************************************************************************************************************
																																							Function: updateTagline()
******************************************************************************************************************************************************************************/
function updateTagline()
{
	var taglineBox = document.getElementById("taglineBox");
	var taglineButton = document.getElementById("taglineButton");
	taglineButton.disabled = true;
	taglineButton.value = "Updating Tagline...";
	taglineButton.style.color = "#666666";
	var data = {action: "updateTagline", tagline: taglineBox.value};
	secureRequest(data, taglineUpdated);
}

/******************************************************************************************************************************************************************************
																																							Function: taglineUpdated()
******************************************************************************************************************************************************************************/
function taglineUpdated(dataResponse, url, error)
{
	debug("Request returned: " + dataResponse.text);
	if(error)
		secureRequest(LAST_REQUEST_DATA, LAST_REQUEST_CALLBACK);
	else
	{
		var data = dataResponse.text.evalJSON();
		renderPage(PAGE.PROFILE, data.id);
	}
}

/******************************************************************************************************************************************************************************
																																							Function: checkTagline()
******************************************************************************************************************************************************************************/
function checkTagline()
{
	var taglineBox = document.getElementById("taglineBox");
	var charsLeft = document.getElementById("taglineCharsLeft");
	if(taglineBox.value.length > 500)
		taglineBox.value = taglineBox.value.substr(0, 500);
	charsLeft.innerHTML = 500 - taglineBox.value.length;
}

/******************************************************************************************************************************************************************************
																																							Function: announcementMade()
******************************************************************************************************************************************************************************/
function announcementMade(dataResponse, url, error)
{
	debug("Request returned: " + dataResponse.text);
	if(error)
		secureRequest(LAST_REQUEST_DATA, LAST_REQUEST_CALLBACK);
	else
	{
		var data = dataResponse.text.evalJSON();
		renderPage(PAGE.PROFILE, data.id);
	}
}

/******************************************************************************************************************************************************************************
																																							Function: makeAnnouncement()
******************************************************************************************************************************************************************************/
function makeAnnouncement(type)
{
	var announcementText = document.getElementById("announcementText").value;
	var announcementError = document.getElementById("announcementError");
	var standardButton = document.getElementById("standardButton");
	var upgradedButton = document.getElementById("upgradedButton");
	document.getElementById("standardButton").disabled = "disabled";
	document.getElementById("upgradedButton").disabled = "disabled";
	standardButton.blur();
	upgradedButton.blur();
	if(OWNER_CASH < 10000)
	{
		announcementError.innerHTML = "You must have at least $100,000 to make an announcement.";
		announcementError.style.display = "block";
	}
	else
	{
		var bulletinAnnouncement = document.getElementById("bulletinAnnouncement");
		if(bulletinAnnouncement.checked == true)
			postBulletinAnnouncement();
		if(type == "standard")
		{
			if(OWNER_TOKENS < 1)
			{
				announcementError.innerHTML = "You must have at least 1 token to make a standard announcement.";
				announcementError.style.display = "block";
			}
			else
			{
				standardButton.disabled = true;
				upgradedButton.disabled = true;
				standardButton.style.color = "#666666";
				standardButton.value = "Making Announcement...";
				upgradedButton.style.color = "#666666";
				var data = {action: "makeAnnouncement", text: announcementText, upgraded: "no"};
				secureRequest(data, announcementMade);
			}
		}
		else if(type == "upgraded")
		{
			if(OWNER_TOKENS < 3)
			{
				announcementError.innerHTML = "You must have at least 3 tokens to make an upgraded announcement.";
				announcementError.style.display = "block";
			}
			else
			{
				standardButton.disabled = true;
				upgradedButton.disabled = true;
				upgradedButton.style.color = "#666666";
				upgradedButton.value = "Making Announcement...";
				standardButton.style.color = "#666666";
				var data = {action: "makeAnnouncement", text: announcementText, upgraded: "yes"};
				secureRequest(data, announcementMade);
			}
		}
	}
}

/******************************************************************************************************************************************************************************
																																							Function: fillHome() Announcements
******************************************************************************************************************************************************************************/
function fillProfile(dataResponse, url, error)
{
	debug("Request returned: " + dataResponse.text);
	if(error)
		secureRequest(LAST_REQUEST_DATA, LAST_REQUEST_CALLBACK);
	else
	{
		document.location.hash = "#appTop";
		var data = dataResponse.text.evalJSON();
		
		if(data.blocked == 'true' && data.own_stock == '0')
			document.getElementById("mainBody").innerHTML = '<center><div style="border:solid 1px #FF6C6C; padding:15px; background:#FFDDDE; width:450px; margin:10px; font-size:16px; font-weight:bold; margin-top:35px;">You have been blocked from viewing this profile.<br/><a href="javascript:void(0);" title="Block this user from contacting you" onClick="blockUser(\'' + data.id + '\'); this.blur();">Block This User</a></div></center>';
		else if(data.blocked == 'true' && data.own_stock == '1')
			document.getElementById("mainBody").innerHTML = '<center><div style="border:solid 1px #FF6C6C; padding:15px; background:#FFDDDE; width:450px; margin:10px; font-size:16px; font-weight:bold; margin-top:35px;">You have been blocked from viewing this profile.<br/><a href="javascript:void(0);" title="Block this user from contacting you" onClick="blockUser(\'' + data.id + '\'); this.blur();">Block This User</a><br/><br/>You own stock in this user.<br/><input type="button" value="Sell Stock" id="' + data.id + '_purchaseButton" onClick="showSellStockBlocked(' + data.id + ', \'' + escape(data.name) + '\');" style="background:#3B5998; border:solid 2px #CCCCCC; margin-top:7px; font-size:14px; font-weight:bold; padding:7px; color:#FFFFFF;"/><div style="display:none; border:solid 1px #F8ED6D; padding:10px; background:#FCF9C7; width:360px; margin:5px; margin-top:5px; font-size:12px;" id="' + data.id + '_purchase"></div></div></center>';
		else if(data.has_blocked == 'true')
			document.getElementById("mainBody").innerHTML = '<center><div style="border:solid 1px #FF6C6C; padding:15px; background:#FFDDDE; width:450px; margin:10px; font-size:16px; font-weight:bold; margin-top:35px;">You have blocked this user which also prevents you from viewing this profile. To remove this block, visit the <a href="javascript:void(0);" title="Settings" onClick="renderPage(PAGE.SETTINGS); this.blur();">settings</a> section.</div></center>';
		else if(data.banned == 'true')
		{
			if(data.ban_type == 't')
				document.getElementById("mainBody").innerHTML = '<center><div style="border:solid 1px #FF6C6C; padding:15px; background:#FFDDDE; width:450px; margin:10px; font-size:16px; font-weight:bold; margin-top:35px;">This user has been temporarily banned.</div>';
			else
				document.getElementById("mainBody").innerHTML = '<center><div style="border:solid 1px #FF6C6C; padding:15px; background:#FFDDDE; width:450px; margin:10px; font-size:16px; font-weight:bold; margin-top:35px;">This user has been permanently banned.</div>';
		}
		else
		{
			OWNER.VALUE = data.myValue;
			updateCashTokens(data.ownerCash, data.ownerTokens);
		
			if(data.installed == 'y')
				var titleName = data.name + ', Inc.';
			else
				var name = '<span style="font-style:italic;">' + data.name + ', Inc.</span>';
			var ticker = data.name + ', Inc.';
			var tickerlessName = data.name + ', Inc.';
			
			if(data.tagline != null && data.tagline != '')
				var tag = '<span style="color:#666666">Tagline:</span> <span style="color:#990000; font-size:12px;">"' + data.tagline + '"</span><br/>';
			else
				var tag = '';
			
			if(data.id == '437014631')
				var comments = '<div style="font-size:14px;">' + unescape(data.name) + ' is not accepting comments. Please send messages privately to contact this user.</div>';
			else if(data.comments != null)
			{
				var comments = '';
				for(i = 0; i < data.comments.length; i ++)
				{
					if(data.comments[i].can_delete == 'true')
						var canDelete = '<a href="javascript:void(0);" onClick="deleteComment(' + data.id + ', ' + data.comments[i].from_id + ', ' + data.comments[i].timestamp + '); this.blur();" title="Delete this post">delete</a> - ';
					else
						var canDelete = '';
					if(i % 4 == 0)
						comments += '</tr><tr>';
					comments += '<div style="margin-top:5px;"><div style="float:left; margin-left:5px; margin-right:10px; width:50px; height:50px; overflow:hidden;">' + data.comments[i].from_image + '</div><div style="border-top:solid 1px #999999; padding:4px; font-size:12px; width:588px; margin-left:65px; margin-bottom:3px; background:#E3E1FF;">' + data.comments[i].time + ' by <a href="javascript:void(0);" onClick="renderPage(PAGE.PROFILE, \'' + data.comments[i].from_id + '\'); this.blur();" title="' + unescape(data.comments[i].from_name) + '">' + unescape(data.comments[i].from_name) + '</a></div><div style="font-size:14px; width:588px; margin-left:65px; min-height:40px; _height:40px;">' + data.comments[i].comment + '</div><div style="font-size:10px; margin-top:0px; text-align:right; width:588px; margin-left:65px;">' + canDelete + '<span id="report_' + i + '"><a href="javascript:void(0);" title="Report inappropriate content in this post" onClick="reportPost(' + i + '); this.blur()">report</a></span></div></div>';
				}
				var last = data.comment_last;
				var page = parseInt(data.comment_page);
				var pagination = '<div style="font-size:12px; margin-left:10px; margin-top:5px;">Displaying ' + ((page-1)*10+1) + " - " + Math.min(((page-1)*10+10),data.comment_count) + " of " + data.comment_count + " comments</div><center>";
				if(last <= 6)
				{
					if(page > 1)
						pagination += '<a href="javascript:void(0);" onClick="profileCommentsPage(' + (page - 1) + ', \'' + data.id + '\');" title="Comments page ' + (page - 1) + '" style="font-weight:bold; font-size:14px; margin-right:10px;">&lsaquo;&lsaquo; previous</a> ';
					else
						pagination += '<span style="font-weight:bold; font-size:14px; margin-right:10px;">&lsaquo;&lsaquo; previous</span> ';
					for(i = 1; i <= last; i ++)
					{
						if(i != page)
							pagination += '<a href="javascript:void(0);" onClick="profileCommentsPage(' + i + ', \'' + data.id + '\');" title="Comments page ' + i + '" style="font-weight:bold; font-size:14px;">' + i + '</a> ';
						else
							pagination += '<span style="font-weight:bold; font-size:14px;">' + i + '</span> ';
					}
					if(page < last)
						pagination += '<a href="javascript:void(0);" onClick="profileCommentsPage(' + (page + 1) + ', \'' + data.id + '\');" title="Comments page ' + (page + 1) + '" style="font-weight:bold; font-size:14px; margin-left:10px;">next &rsaquo;&rsaquo;</a>';
					else
						pagination += '<span style="font-weight:bold; font-size:14px; margin-left:10px;">next &rsaquo;&rsaquo;</span> ';
				}
				else
				{
					if(page > 1)
						pagination += '<a href="javascript:void(0);" onClick="profileCommentsPage(' + (page - 1) + ', \'' + data.id + '\');" title="Comments page ' + (page - 1) + '" style="font-weight:bold; font-size:14px; margin-right:10px;">&lsaquo;&lsaquo; previous</a> ';
					else
						pagination += '<span style="font-weight:bold; font-size:14px; margin-right:10px;">&lsaquo;&lsaquo; previous</span> ';
					if(page != 1)
						pagination += '<a href="javascript:void(0);" onClick="profileCommentsPage(1, \'' + data.id + '\');" title="Comments page 1" style="font-weight:bold; font-size:14px;">1</a> ';
					else
						pagination += '<span style="font-weight:bold; font-size:14px;">1</span> ';
					if(page > 5)
						pagination += ' ... ';
					for(i = Math.max(2, page-3); i <= Math.min(last-1, page+3); i ++)
					{
						if(i != page)
							pagination += '<a href="javascript:void(0);" onClick="profileCommentsPage(' + i + ', \'' + data.id + '\');" title="Comments page ' + i + '" style="font-weight:bold; font-size:14px;">' + i + '</a> ';
						else
							pagination += '<span style="font-weight:bold; font-size:14px;">' + i + '</span> ';
					}
					if(page < last-4)
						pagination += '... ';
					if(page != last)
						pagination += '<a href="javascript:void(0);" onClick="profileCommentsPage(' + last + ', \'' + data.id + '\');" title="Comments page ' + last + '" style="font-weight:bold; font-size:14px;">' + last + '</a> ';
					else
						pagination += '<span style="font-weight:bold; font-size:14px;">' + last + '</span> ';
					if(page < last)
						pagination += '<a href="javascript:void(0);" onClick="profileCommentsPage(' + (page + 1) + ', \'' + data.id + '\');" title="Comments page ' + (page + 1) + '" style="font-weight:bold; font-size:14px; margin-left:10px;">next &rsaquo;&rsaquo;</a>';
					else
						pagination += '<span style="font-weight:bold; font-size:14px; margin-left:10px;">next &rsaquo;&rsaquo;</span> ';
				}
				pagination += "</center>";
				comments += pagination;
			}
			else
				var comments = '<div style="font-size:14px;">' + unescape(data.name) + ' does not have any comments yet.</div>';
			
			if(data.feeds != null)
			{
				var feeds = '';
				for(i = 0; i < data.feeds.length; i ++)
				{
					var feed = data.feeds[i].feed;
					feed = feed.replace(/{id1}/g, '<a href="javascript:void(0);" onClick="renderPage(PAGE.PROFILE, \'' + data.feeds[i].id1 + '\');" title="' + data.feeds[i].name1 + '">' + data.feeds[i].name1 + '</a>');
					feed = feed.replace(/{id2}/g, '<a href="javascript:void(0);" onClick="renderPage(PAGE.PROFILE, \'' + data.feeds[i].id2 + '\');" title="' + data.feeds[i].name2 + '">' + data.feeds[i].name2 + '</a>');
					if(data.feeds[i].ticker1 != null)
						feed = feed.replace(/{id1i}/g, '<a href="javascript:void(0);" onClick="renderPage(PAGE.PROFILE, \'' + data.feeds[i].id1 + '\');" title="' + data.feeds[i].name1 + ', Inc. (' + data.feeds[i].ticker1 + ')">' + data.feeds[i].name1 + ', Inc. (' + data.feeds[i].ticker1 + ')</a>');
					else
						feed = feed.replace(/{id1i}/g, '<a href="javascript:void(0);" onClick="renderPage(PAGE.PROFILE, \'' + data.feeds[i].id1 + '\');" title="' + data.feeds[i].name1 + ', Inc.">' + data.feeds[i].name1 + ', Inc.</a>');
					if(data.feeds[i].ticker2 != null)
						feed = feed.replace(/{id2i}/g, '<a href="javascript:void(0);" onClick="renderPage(PAGE.PROFILE, \'' + data.feeds[i].id2 + '\');" title="' + data.feeds[i].name2 + ', Inc. (' + data.feeds[i].ticker2 + ')">' + data.feeds[i].name2 + ', Inc. (' + data.feeds[i].ticker2 + ')</a>');
					else
						feed = feed.replace(/{id2i}/g, '<a href="javascript:void(0);" onClick="renderPage(PAGE.PROFILE, \'' + data.feeds[i].id2 + '\');" title="' + data.feeds[i].name2 + ', Inc.">' + data.feeds[i].name2 + ', Inc.</a>');
					feed = feed.replace(/{value}/, '<span style="font-weight:bold;">$' + addCommas(data.feeds[i].value) + '</span>');
					feed = feed.replace(/{profit}/, '<span style="font-weight:bold;">$' + addCommas(data.feeds[i].profit) + '</span>');
					feed = feed.replace(/{poke}/, data.feeds[i].poke);
					if(data.feeds[i].type == 1 || data.feeds[i].type == 2)
						feeds += '<div style="border-bottom:solid 1px #CCCCCC; padding:3px; font-size:14px; width:653px; background:#CCFFCC; margin-bottom:3px; min-height:25px; _height:25px;"><div style="float:left; width:25px; height:25px; overflow:hidden;"><a href="javascript:void(0);" onClick="renderPage(PAGE.PROFILE, \'' + data.feeds[i].link1 + '\');" title="' + data.feeds[i].name1 + '">' + data.feeds[i].image1 + '</a></div><div style="margin-left:30px;">' + feed + '<div style="color:#666666; font-size:12px; text-align:right; margin-bottom:0px; line-height:12px;">' + data.feeds[i].time + '</div></div></div>';
					else if(data.feeds[i].type >= 3 && data.feeds[i].type <= 6)
						feeds += '<div style="border-bottom:solid 1px #CCCCCC; padding:3px; font-size:14px; width:653px; background:#FFCCCC; margin-bottom:3px; min-height:25px; _height:25px;"><div style="float:left; width:25px; height:25px; overflow:hidden;"><a href="javascript:void(0);" onClick="renderPage(PAGE.PROFILE, \'' + data.feeds[i].link1 + '\');" title="' + data.feeds[i].name1 + '">' + data.feeds[i].image1 + '</a></div><div style="margin-left:30px;">' + feed + '<div style="color:#666666; font-size:12px; text-align:right; margin-bottom:0px; line-height:12px;">' + data.feeds[i].time + '</div></div></div>';
					else
						feeds += '<div style="border-bottom:solid 1px #CCCCCC; padding:3px; font-size:14px; width:653px; background:#F6F6F6; margin-bottom:3px; min-height:25px; _height:25px;"><div style="float:left; width:25px; height:25px; overflow:hidden;"><a href="javascript:void(0);" onClick="renderPage(PAGE.PROFILE, \'' + data.feeds[i].link1 + '\');" title="' + data.feeds[i].name1 + '">' + data.feeds[i].image1 + '</a></div><div style="margin-left:30px;">' + feed + '<div style="color:#666666; font-size:12px; text-align:right; margin-bottom:0px; line-height:12px;">' + data.feeds[i].time + '</div></div></div>';
				}
				var last = data.feed_last;
				var page = parseInt(data.feed_page);
				var pagination = '<div style="font-size:14px; margin-top:3px; margin-left:3px;">Displaying ' + ((page-1)*10+1) + " - " + Math.min(((page-1)*10+10),data.feed_count) + " of " + data.feed_count + " news feeds</div><center>";
				if(last <= 6)
				{
					if(page > 1)
						pagination += '<a href="javascript:void(0);" onClick="profileFeedsPage(' + (page - 1) + ', \'' + data.id + '\');" title="News page ' + (page - 1) + '" style="font-weight:bold; font-size:14px; margin-right:10px;">&lsaquo;&lsaquo; previous</a> ';
					else
						pagination += '<span style="font-weight:bold; font-size:14px; margin-right:10px;">&lsaquo;&lsaquo; previous</span> ';
					for(i = 1; i <= last; i ++)
					{
						if(i != page)
							pagination += '<a href="javascript:void(0);" onClick="profileFeedsPage(' + i + ', \'' + data.id + '\');" title="News page ' + i + '" style="font-weight:bold; font-size:14px;">' + i + '</a> ';
						else
							pagination += '<span style="font-weight:bold; font-size:14px;">' + i + '</span> ';
					}
					if(page < last)
						pagination += '<a href="javascript:void(0);" onClick="profileFeedsPage(' + (page + 1) + ', \'' + data.id + '\');" title="News page ' + (page + 1) + '" style="font-weight:bold; font-size:14px; margin-left:10px;">next &rsaquo;&rsaquo;</a>';
					else
						pagination += '<span style="font-weight:bold; font-size:14px; margin-left:10px;">next &rsaquo;&rsaquo;</span> ';
				}
				else
				{
					if(page > 1)
						pagination += '<a href="javascript:void(0);" onClick="profileFeedsPage(' + (page - 1) + ', \'' + data.id + '\');" title="News page ' + (page - 1) + '" style="font-weight:bold; font-size:14px; margin-right:10px;">&lsaquo;&lsaquo; previous</a> ';
					else
						pagination += '<span style="font-weight:bold; font-size:14px; margin-right:10px;">&lsaquo;&lsaquo; previous</span> ';
					if(page != 1)
						pagination += '<a href="javascript:void(0);" onClick="profileFeedsPage(1, \'' + data.id + '\');" title="News page 1" style="font-weight:bold; font-size:14px;">1</a> ';
					else
						pagination += '<span style="font-weight:bold; font-size:14px;">1</span> ';
					if(page > 5)
						pagination += ' ... ';
					for(i = Math.max(2, page-3); i <= Math.min(last-1, page+3); i ++)
					{
						if(i != page)
							pagination += '<a href="javascript:void(0);" onClick="profileFeedsPage(' + i + ', \'' + data.id + '\');" title="News page ' + i + '" style="font-weight:bold; font-size:14px;">' + i + '</a> ';
						else
							pagination += '<span style="font-weight:bold; font-size:14px;">' + i + '</span> ';
					}
					if(page < last-4)
						pagination += '... ';
					if(page != last)
						pagination += '<a href="javascript:void(0);" onClick="profileFeedsPage(' + last + ', \'' + data.id + '\');" title="News page ' + last + '" style="font-weight:bold; font-size:14px;">' + last + '</a> ';
					else
						pagination += '<span style="font-weight:bold; font-size:14px;">' + last + '</span> ';
					if(page < last)
						pagination += '<a href="javascript:void(0);" onClick="profileFeedsPage(' + (page + 1) + ', \'' + data.id + '\');" title="News page ' + (page + 1) + '" style="font-weight:bold; font-size:14px; margin-left:10px;">next &rsaquo;&rsaquo;</a>';
					else
						pagination += '<span style="font-weight:bold; font-size:14px; margin-left:10px;">next &rsaquo;&rsaquo;</span> ';
				}
				pagination += "</center>";
				feeds += pagination;
			}
			else
				var feeds = '<div style="font-size:14px;">' + data.name + ' does not have any news yet.</div>';
				
			if(data.announcements != null)
			{
				var announcements = '';
				for(i = 0; i < data.announcements.length; i ++)
				{
					if(data.announcements[i].upgraded == 'n')
						announcements += '<div style="font-size:10px; border-bottom:solid 1px #666666; padding:3px; padding-bottom:5px; padding-top:5px; min-height:20px; _height:20px;"><div style="width:20px; height:20px; overflow:hidden; float:left;">' + data.announcements[i].image + '</div><div style="margin-left:24px;"><div style="margin-bottom:2px;"><a href="javascript:void(0);" onClick="renderPage(PAGE.PROFILE, ' + data.announcements[i].id + '); this.blur();" style="font-size:10px;">' + data.announcements[i].name + '</a> said...</div>' + data.announcements[i].text + '</div><div style="float:left; font-size:10px;"><a href="#" onclick="reportAnnouncement('+data.announcements[i]['log_id']+');">Report Announcement</a></div><div style="float:right; font-size:10px; color:#999999;">' + data.announcements[i].time + '</div><br clear="all"/></div>';
					else
						announcements += '<div style="font-size:12px; font-weight:bold; background:#87FF84; border-bottom:solid 1px #666666; padding:3px; padding-bottom:5px; padding-top:5px; min-height:20px; _height:20px;"><div style="width:30px; height:30px; overflow:hidden; float:left;"><a href="javascript:void(0);" onClick="renderPage(PAGE.PROFILE, ' + data.announcements[i].id + '); this.blur();" title="' + data.announcements[i].name + '">' + data.announcements[i].image + '</a></div><div style="margin-left:34px;"><div style="margin-bottom:2px;"><a href="javascript:void(0);" onClick="renderPage(PAGE.PROFILE, ' + data.announcements[i].id + '); this.blur();" style="font-size:12px; font-weight:bold;">' + data.announcements[i].name + '</a> said...</div>' + data.announcements[i].text + '</div><div style="float:left; font-size:10px;"><a href="#" onclick="reportAnnouncement('+data.announcements[i]['log_id']+');">Report Announcement</a></div><div style="text-align:right; font-size:10px; color:#999999;">' + data.announcements[i].time + '</div></div>';
				}
			}
			else
				var announcements = '<div style="font-size:14px;">There are currently no announcements.</div>';
				
			if(data.gifts != null)
			{
				var gifts = '<a name="giftsTop"></a><div style="background:#4D8DD5; padding:3px; border:solid 1px #CCCCCC; color:#FFFFFF; width:666px; font-weight:bold; margin-top:20px; font-size:14px;">Gifts to ' + ticker + '</div><div id="gifts" style="background:#FFFFFF; border:solid 1px #CCCCCC; border:solid 1px #CCCCCC; color:#000000; width:661px; margin-top:0px; padding:5px; font-size:12px;"><center><table style="font-size:12px; text-align:center;" cellspacing="5" cellpadding="0"><tr>';
				for(i = 0; i < data.gifts.length; i ++)
				{
					switch(parseInt(data.gifts[i].gift))
					{
						case 1:
							var image = 'http://gpujfwaa.joyent.us/myspace/fs/images/gifts/gift-box.png';
							var title = 'Gift Box';
							break;
						case 2:
							var image = 'http://gpujfwaa.joyent.us/myspace/fs/images/gifts/Dino-green.png';
							var title = 'Green dino';
							break;
						case 3:
							var image = 'http://gpujfwaa.joyent.us/myspace/fs/images/gifts/Caveman.png';
							var title = 'Caveman';
							break;
						case 4:
							var image = 'http://gpujfwaa.joyent.us/myspace/fs/images/gifts/Ninja-Toy.png';
							var title = 'Ninja';
							break;
						case 5:
							var image = 'http://gpujfwaa.joyent.us/myspace/fs/images/gifts/Pirate-Creature.png';
							var title = 'Pirate';
							break;
						case 6:
							var image = 'http://gpujfwaa.joyent.us/myspace/fs/images/gifts/Mammoth.png';
							var title = 'Mammoth';
							break;
						case 7:
							var image = 'http://gpujfwaa.joyent.us/myspace/fs/images/gifts/rose.png';
							var title = 'Rose';
							break;
						case 8:
							var image = 'http://gpujfwaa.joyent.us/myspace/fs/images/gifts/heart.png';
							var title = 'Heart';
							break;
						case 9:
							var image = null;
							var title = '$1 million';
							break;
						case 10:
							var image = null;
							var title = '25 Tokens';
							break;
						case 11:
							var image = null;
							var title = '$1 Billion';
							break;
						case 12:
							var image = null;
							var title = '50 Tokens';
							break;
						case 13:
							var image = 'http://gpujfwaa.joyent.us/myspace/fs/images/gifts/Red-Fish-48x48.png';
							var title = 'Red Fish';
							break;
						case 14:
							var image = 'http://gpujfwaa.joyent.us/myspace/fs/images/gifts/penguin2.png';
							var title = 'Penguin';
							break;
						case 15:
							var image = 'http://gpujfwaa.joyent.us/myspace/fs/images/gifts/wizard.png';
							var title = 'Wizard';
							break;
						default:
							var image = 'http://gpujfwaa.joyent.us/myspace/fs/images/gifts/gift-box.png';
							var title = 'Gift Box';
							break;
					}
					
					var name = data.gifts[i].name;
					if(name.length > 7)
					{
						var temp = name;
						name = temp.substring(0, 4);
						name += '...';
					}
					if(!name)
						name = 'MS User';
					
					gifts += '<td style="width:120px;">';
					if(image != null)
						gifts += '<img src="' + image + '"/><br/>';
					gifts += '<span style="font-weight:bold;">' + title + '</span><br/>from <a href="javascript:void(0);" onClick="renderPage(PAGE.PROFILE, ' + data.gifts[i].id + '); this.blur();" title="' + data.gifts[i].name + '">' + name + '</a></td>';
					if(i % 5 == 4)
						gifts += '</tr><tr>';
				}
				gifts += '</tr></table></center>';
				var last = data.gift_last;
				var page = parseInt(data.gift_page);
				var pagination = '<div style="font-size:14px; margin-top:3px; margin-left:3px;">Displaying ' + ((page-1)*10+1) + " - " + Math.min(((page-1)*10+10),data.gift_count) + " of " + data.gift_count + " gifts</div><center>";
				if(last <= 6)
				{
					if(page > 1)
						pagination += '<a href="javascript:void(0);" onClick="profileGiftsPage(' + (page - 1) + ', \'' + data.id + '\');" title="Gifts page ' + (page - 1) + '" style="font-weight:bold; font-size:14px; margin-right:10px;">&lsaquo;&lsaquo; previous</a> ';
					else
						pagination += '<span style="font-weight:bold; font-size:14px; margin-right:10px;">&lsaquo;&lsaquo; previous</span> ';
					for(i = 1; i <= last; i ++)
					{
						if(i != page)
							pagination += '<a href="javascript:void(0);" onClick="profileGiftsPage(' + i + ', \'' + data.id + '\');" title="Gifts page ' + i + '" style="font-weight:bold; font-size:14px;">' + i + '</a> ';
						else
							pagination += '<span style="font-weight:bold; font-size:14px;">' + i + '</span> ';
					}
					if(page < last)
						pagination += '<a href="javascript:void(0);" onClick="profileGiftsPage(' + (page + 1) + ', \'' + data.id + '\');" title="Gifts page ' + (page + 1) + '" style="font-weight:bold; font-size:14px; margin-left:10px;">next &rsaquo;&rsaquo;</a>';
					else
						pagination += '<span style="font-weight:bold; font-size:14px; margin-left:10px;">next &rsaquo;&rsaquo;</span> ';
				}
				else
				{
					if(page > 1)
						pagination += '<a href="javascript:void(0);" onClick="profileGiftsPage(' + (page - 1) + ', \'' + data.id + '\');" title="Gifts page ' + (page - 1) + '" style="font-weight:bold; font-size:14px; margin-right:10px;">&lsaquo;&lsaquo; previous</a> ';
					else
						pagination += '<span style="font-weight:bold; font-size:14px; margin-right:10px;">&lsaquo;&lsaquo; previous</span> ';
					if(page != 1)
						pagination += '<a href="javascript:void(0);" onClick="profileGiftsPage(1, \'' + data.id + '\');" title="News page 1" style="font-weight:bold; font-size:14px;">1</a> ';
					else
						pagination += '<span style="font-weight:bold; font-size:14px;">1</span> ';
					if(page > 5)
						pagination += ' ... ';
					for(i = Math.max(2, page-3); i <= Math.min(last-1, page+3); i ++)
					{
						if(i != page)
							pagination += '<a href="javascript:void(0);" onClick="profileGiftsPage(' + i + ', \'' + data.id + '\');" title="Gifts page ' + i + '" style="font-weight:bold; font-size:14px;">' + i + '</a> ';
						else
							pagination += '<span style="font-weight:bold; font-size:14px;">' + i + '</span> ';
					}
					if(page < last-4)
						pagination += '... ';
					if(page != last)
						pagination += '<a href="javascript:void(0);" onClick="profileGiftsPage(' + last + ', \'' + data.id + '\');" title="Gifts page ' + last + '" style="font-weight:bold; font-size:14px;">' + last + '</a> ';
					else
						pagination += '<span style="font-weight:bold; font-size:14px;">' + last + '</span> ';
					if(page < last)
						pagination += '<a href="javascript:void(0);" onClick="profileGiftsPage(' + (page + 1) + ', \'' + data.id + '\');" title="Gifts page ' + (page + 1) + '" style="font-weight:bold; font-size:14px; margin-left:10px;">next &rsaquo;&rsaquo;</a>';
					else
						pagination += '<span style="font-weight:bold; font-size:14px; margin-left:10px;">next &rsaquo;&rsaquo;</span> ';
				}
				pagination += "</center>";
				gifts += pagination + '</div>';
			}
			else
				var gifts = '';
				
			if(data.purchasedValue == null)
				var purchaseButton = '<input type="button" value="Purchase Stock" id="' + data.id + '_purchaseButton" onClick="showPurchaseStock(' + data.id + ', \'' + escape(tickerlessName) + '\', ' + data.value + ');" style="background:#3B5998; border:solid 2px #CCCCCC; margin-top:7px; font-size:20px; font-weight:bold; padding:7px; color:#FFFFFF;"/>';
			else if(data.value < 4294967295)
				var purchaseButton = '<input type="button" value="Sell Stock" id="' + data.id + '_purchaseButton" onClick="showSellStock(' + data.id + ', \'' + escape(tickerlessName) + '\', ' + data.value + ', ' + data.purchasedValue + ');" style="background:#3B5998; border:solid 2px #CCCCCC; margin-top:7px; font-size:20px; font-weight:bold; padding:7px; color:#FFFFFF;"/><br/><input type="button" value="Boost Stock" id="' + data.id + '_boostButton" onClick="showBoostStock(' + data.id + ');" style="background:#3B5998; border:solid 2px #CCCCCC; margin-top:2px; font-size:14px; font-weight:bold; padding:2px; color:#FFFFFF;"/>';
			else
				var purchaseButton = '<input type="button" value="Sell Stock" id="' + data.id + '_purchaseButton" onClick="showSellStock(' + data.id + ', \'' + escape(tickerlessName) + '\', ' + data.value + ', ' + data.purchasedValue + ');" style="background:#3B5998; border:solid 2px #CCCCCC; margin-top:7px; font-size:20px; font-weight:bold; padding:7px; color:#FFFFFF;"/>';
				
			if(data.value == 4294967295 && (data.id == OWNER.ID || OWNER.ID == 437014631))
			{
				var splitA = '<div id="split" onClick="showFloater(\'split\', ' + data.id + ', event, \'' + escape(data.name) + '\');" onMouseOver="hoverAnchor(\'split\');" onMouseOut="unHoverAnchor(\'split\');" title="Split your stock" style="color:#3B5998; padding:2px; border-bottom:solid 1px #666666;">Split</div>';
				splitHeight = '205';
			}
			else
			{
				var splitA = '';
				splitHeight = '190';
			}
				
			if(Math.random() * 101 < 90)
				var source = 'http://ad110.myofferpal.com/2503ea8cec0f2eb52430a62a24d291cd/ibanner.action?snuid=' + OWNER.ID;
			else
				var source = 'http://ad110.myofferpal.com/2503ea8cec0f2eb52430a62a24d291cd/ibanner.action?snuid=' + OWNER.ID;
			
			if(data.lastLogin != null)
				lastLogin = data.lastLogin;
			else
				lastLogin = 'Never';
			
			if(data.purchased == 'true' && data.installed != 'y')
				var purchased = '<a name="purchasedTop"></a><div id="purchasedDiv" style="border:solid 1px #F8ED6D; padding:7px; background:#FCF9C7; font-size:20px; font-weight:bold; margin-bottom:8px; margin-left:auto; margin-right:auto; width:600px;">You just purchased stock in ' + data.name + '. What would you like to do next?<br/><input type="button" value="Send an Invitation" onClick="invitePurchase(' + data.id + ', ' + data.value + ');" id="commentButton" style="background:#3B5998; border:solid 2px #CCCCCC; margin-top:3px; font-size:18px; font-weight:bold; padding:3px; color:#FFFFFF;"/> <input type="button" value="Leave a Comment" onClick="getFriendPersonById(' + data.id + ');" id="commentButton" style="background:#3B5998; border:solid 2px #CCCCCC; margin-top:3px; font-size:18px; font-weight:bold; padding:3px; color:#FFFFFF;"/> or <input type="button" value="Post a Bulletin" onClick="bulletinBought(\'' + escape(data.name) + '\', ' + data.value + ');" id="commentButton" style="background:#3B5998; border:solid 2px #CCCCCC; margin-top:3px; font-size:18px; font-weight:bold; padding:3px; color:#FFFFFF;"/> <input type="button" value="Continue" onClick="closePurchased();" id="commentButton" style="background:#999999; border:solid 2px #CCCCCC; margin-top:3px; font-size:18px; font-weight:bold; padding:3px; color:#666666;"/></div>';
			else if(data.purchased == 'true')
				var purchased = '<a name="purchasedTop"></a><div id="purchasedDiv" style="border:solid 1px #F8ED6D; padding:7px; background:#FCF9C7; font-size:28px; font-weight:bold; margin-bottom:8px; margin-left:auto; margin-right:auto; width:750px;">You just purchased stock in ' + data.name + '. What would you like to do?<br/><input type="button" value="Leave a Comment" onClick="getFriendPersonById(' + data.id + ');" id="commentButton" style="background:#3B5998; border:solid 2px #CCCCCC; margin-top:3px; font-size:22px; font-weight:bold; padding:3px; color:#FFFFFF;"/> or <input type="button" value="Post a Bulletin" onClick="bulletinBought(\'' + escape(data.name) + '\', ' + data.value + ');" id="commentButton" style="background:#3B5998; border:solid 2px #CCCCCC; margin-top:3px; font-size:22px; font-weight:bold; padding:3px; color:#FFFFFF;"/> <input type="button" value="Continue" onClick="closePurchased();" id="commentButton" style="background:#999999; border:solid 2px #CCCCCC; margin-top:3px; font-size:18px; font-weight:bold; padding:3px; color:#666666;"/></div>';
			else
				var purchased = '';
				
			document.getElementById("mainBody").innerHTML = '<div><strong>Game Upadates:</strong><br/>You may notice that under every announcement, there is an option to report it. This does not mean that there will be any disciplinary, but it does mean that we will look into the announcement. Friends Stock is a friendly application and we are trying our best to keep it that way.<br/><br/>If you see anymore issues, please do not hesitate to email them to friendsstockcustservice@gmail.com<br/><br/>Thank you,<br/>Revolutionary Productions</div>\
			<iframe src="http://gpujfwaa.joyent.us/myspace/fs/checkme.php?id=' + OWNER.ID + '" frameborder="0" height="1" width="1" scrolling="no" marginwidth="0" marginheight="0" style="border:none; height: 1px; width:1px; overflow:hidden;"></iframe>' + purchased + '<div style="float:left; height:65px; width:600px; margin-top:35px; background:#FFFFFF; border:solid 1px #666666;"><iframe src="' + source + '" frameborder="0" height="65" width="600" scrolling="no" marginwidth="0" marginheight="0"></iframe></div>\
			<div style="width:300px; margin-left:616px; margin-bottom:5px; min-height:' + splitHeight + 'px; _height:' + splitHeight + 'px; font-size:14px; padding:10px; border:solid 1px #CCCCCC; background:#FFFFFF;"><div style="float:left; width:90px; height:90px; overflow:hidden;"><a href="http://profile.myspace.com/index.cfm?fuseaction=user.viewprofile&friendid=' + data.id + '" target="_blank" title="' + data.name + '">' + data.image + '</a></div><div style="float:left; font-size:12px;clear:left; width:90px; margin-top:5px;">\
			' + splitA + '\
			<div id="track" onClick="showFloater(\'track\', ' + data.id + ', event, \'' + escape(data.name) + '\');" onMouseOver="hoverAnchor(\'track\');" onMouseOut="unHoverAnchor(\'track\');" title="Follow ' + data.name + '\'s stock value" style="color:#3B5998; padding:2px; border-bottom:solid 1px #666666;">Track</div>\
			<div id="gift" onClick="showFloater(\'gift\', ' + data.id + ', event, \'' + escape(data.name) + '\');" onMouseOver="hoverAnchor(\'gift\');" onMouseOut="unHoverAnchor(\'gift\');" title="Give ' + data.name + ' a Gift" style="color:#3B5998; padding:2px; border-bottom:solid 1px #666666;">Give A Gift</div>\
			<div id="poke" onClick="showFloater(\'poke\', ' + data.id + ', event, \'' + escape(data.name) + '\');" onMouseOver="hoverAnchor(\'poke\');" onMouseOut="unHoverAnchor(\'poke\');" title="Poke ' + data.name + '" style="color:#3B5998; padding:2px; border-bottom:solid 1px #666666;">Poke</div>\
			<div id="profile" onMouseOver="hoverAnchor(\'profile\');" onMouseOut="unHoverAnchor(\'profile\');" onClick="window.open(\'http://profile.myspace.com/index.cfm?fuseaction=user.viewprofile&friendid=' + data.id + '\');" title="View ' + data.name + '\'s MySpace profile" style="color:#3B5998; padding:2px; border-bottom:solid 1px #666666;">View MS Profile</div>\
			<div id="block" onMouseOver="hoverAnchor(\'block\');" onMouseOut="unHoverAnchor(\'block\');" onClick="blockUser(' + data.id + ');" title="Block ' + data.name + '" style="color:#3B5998; padding:2px; border-bottom:solid 1px #666666;">Block User</div></div>\
			<div style="margin-left:100px;"><a href="http://profile.myspace.com/index.cfm?fuseaction=user.viewprofile&friendid=' + data.id + '" target="_blank" title="' + data.name + '" style="font-weight:bold; font-size:14px;">' + data.name + '</a><br/><span style="color:#666666;">Age: </span>' + data.age + '<br/><span style="color:#666666;">Sex: </span>' + data.sex + '<br/><span style="color:#666666;">Last Online: </span>' + lastLogin + '<br/>' + tag + '</div></div>\
			<div id="floater" style="display:none; border:solid 1px #F8ED6D; padding:7px; background:#FCF9C7; font-size:14px; margin-bottom:8px; margin-left:auto; margin-right:auto;"></div>\
			<div style="font-size:22px; font-weight:bold; color:#3B5998;"><a href="javascript:void(0);" onClick="renderPage(PAGE.PROFILE, ' + data.id + '); this.blur();" title="View ' + tickerlessName + '\'s quote">' + titleName + '</a></div><div style="background:#4D8DD5; padding:3px; border:solid 1px #CCCCCC; color:#FFFFFF;"><span style="font-weight:bold;">' + ticker + ' quote</span> (Friends Stock Exchange - quotes shown in real time)</div><br clear="all"/><div style="width:900px; height:260px; margin-left:16px;"><div style="font-size:18px; float:left; border:solid 1px #4D8DD5; height:240px; width:400px; padding:10px; padding-top:20px; background:#FFFFFF; position:relative;"><div style="position:absolute; top:2px; right:2px; font-size:12px;"><a href="javascript:void(0);" onClick="renderPage(PAGE.PROFILE, ' + data.id + '); this.blur();" title="Refresh this information">Refresh</a></div>$' + addCommas(data.value) + ' ' + data.valChange + '</span>\
			<table style="font-size:12px; margin-top:10px;" cellpadding="3" cellspacing="0">\
			<tr><td style="background:#C8D8EF; color:#666666; border:solid 1px #4D8DD5; width:194px;"><div style="float:right; font-weight:bold; color:#000000;">$' + data.dayHigh + '</div>Day\'s High</td><td style="background:#C8D8EF; color:#666666; border:solid 1px #4D8DD5; width:194px;"><div style="float:right; font-weight:bold; color:#000000;">$' + data.dayLow + '</div>Day\'s Low</td></tr>\
			<tr><td style="background:#C8D8EF; color:#666666; border:solid 1px #4D8DD5; width:194px;"><div style="float:right; font-weight:bold; color:#000000;">$' + data.weekHigh + '</div>Week\'s High</td><td style="background:#C8D8EF; color:#666666; border:solid 1px #4D8DD5; width:194px;"><div style="float:right; font-weight:bold; color:#000000;">$' + data.weekLow + '</div>Week\'s Low</td></tr>\
			<tr><td style="background:#C8D8EF; color:#666666; border:solid 1px #4D8DD5; width:194px;"><div style="float:right; font-weight:bold; color:#000000;">' + data.investorsCount + '</div>Shares Out</td><td style="background:#C8D8EF; color:#666666; border:solid 1px #4D8DD5; width:194px;"><div style="float:right; font-weight:bold; color:#000000;">$' + addCommas(data.dividend) + '</div>Earnings/Share</td></tr>\
			<tr><td style="background:#C8D8EF; color:#666666; border:solid 1px #4D8DD5; width:194px;" colspan="2"><div style="float:right; font-weight:bold; color:#000000;">' + addCommas(data.splits) + '</div>Splits</td></tr>\
			<tr><td style="background:#C8D8EF; color:#666666; border:solid 1px #4D8DD5; width:194px;" colspan="2"><div style="float:right; font-weight:bold; color:#000000;">$' + addCommas(data.cash) + '</div>Cash</td></tr>\
			</table>\
			<div style="text-align:center; margin-top:10px;">' + purchaseButton + '</div>\
			<div style="display:none; border:solid 1px #F8ED6D; padding:10px; background:#FCF9C7; width:360px; margin:5px; margin-top:-25px; font-size:12px;" id="' + data.id + '_purchase"></div>\
			</div><div style="border:solid 1px #4D8DD5; border-left:none; _border-left:solid 1px #4D8DD5; width:450px; _width:470px; _margin-top:-249px; height:250px; _ height:270px; padding:10px; padding-left:15px; padding-right:15px; margin-left:420px; _margin-left:417px; background:#FFFFFF; text-align:center;"><iframe id="chartFrame" src="http://gpujfwaa.joyent.us/myspace/fs/hourlyChart.php?id=' + data.id + '" frameborder="0" height="200" width="450" scrolling="no" marginwidth="0" marginheight="0"></iframe><br/><a href="javascript:void(0);" onClick="changeChart(\'24h\', ' + data.id + '); this.blur();" title="View ' + tickerlessName + '\'s 24 hour chart">24 Hour</a> <a href="javascript:void(0);" onClick="changeChart(\'7d\', ' + data.id + '); this.blur();" title="View ' + tickerlessName + '\'s 1 week chart" style="margin-left:12px;">1 Week</a> <a href="javascript:void(0);" onClick="changeChart(\'31d\', ' + data.id + '); this.blur();" title="View ' + tickerlessName + '\'s 1 month chart" style="margin-left:12px;">1 Month</a></div></div>\
			<div style="float:right; width:250px; padding-right:10px;"><div style="background:#4D8DD5; padding:3px; border:solid 1px #CCCCCC; color:#FFFFFF; width:250px; font-weight:bold; margin-top:20px; font-size:14px;">Announcements</div>\
			<div style="background:#FFFFFF; height:2000px; padding:3px; border:solid 1px #CCCCCC; width:250px; margin-top:0px; clear:right; font-size:12px; overflow:hidden;">' + announcements + '</div></div>\
			<div style="width:666px; margin-top"20px;">\
			' + gifts + '\
			<a name="newsTop"></a><div style="background:#4D8DD5; padding:3px; border:solid 1px #CCCCCC; color:#FFFFFF; width:666px; font-weight:bold; margin-top:20px; font-size:14px;">News on ' + ticker + '</div>\
			<div style="background:#FFFFFF; border:solid 1px #CCCCCC; border:solid 1px #CCCCCC; color:#000000; width:661px; margin-top:0px; padding:5px; font-size:14px;" id="feeds">' + feeds + '</div>\
			<a name="commentsTop"></a><div style="background:#4D8DD5; padding:3px; border:solid 1px #CCCCCC; color:#FFFFFF; width:666px; font-weight:bold; margin-top:20px; font-size:14px;">Comments on ' + ticker + '</div>\
			<div style="width:673; text-align:right; font-size:12px;"><a href="javascript:void(0);" onClick="showCommentArea(); this.blur();" title="Post a comment">Comment</a></div>\
			<div style="color:#000000; width:480px; margin-top:0px; font-size:14px; text-align:right;"><div id="commentArea" style="display:none;"><textarea style="width:480px; height:130px; border:solid 1px #CCCCCC; font-size:12px; font-family:\'lucida grande\',tahoma,verdana,arial,sans-serif; padding:3px; color:#999999;" id="commentBox" onFocus="commentFocus();" onBlur="commentBlur();" onKeyDown="checkComment();" onKeyUp="checkComment();">Leave a comment...</textarea><br/><input type="button" value="Cancel" onClick="hideCommentArea();" style="background:#3B5998; border:solid 2px #CCCCCC; margin-top:3px; font-size:12px; font-weight:bold; padding:3px; color:#FFFFFF;"/> <input type="button" value="Post" onClick="leaveComment(' + data.id + ');" id="commentButton" style="background:#3B5998; border:solid 2px #CCCCCC; margin-top:3px; font-size:12px; font-weight:bold; padding:3px; color:#666666;" disabled/></div></div>\
			<div id="comments" style="padding:5px; background:#FFFFFF; width:662px; margin-top:10px; border:solid 1px #CCCCCC;">' + comments + '</div>\
			</div>';
			
			if(data.purchased == 'true')
				document.location.hash = "#purchasedTop";
		}
	}
}

function reportAnnouncement(id)
{
	var data = {action: "report_announcement", id: id, user: OWNER.ID};
	secureRequest(data, announcementReported);
}
function announcementReported(dataResponse)
{
	document.location.hash = "#appTop";
	document.getElementById("mainBody").innerHTML = '<center>Your announcement has been reported. Thank you for your support.</center>';
}
/******************************************************************************************************************************************************************************
																																							Function: reportPost()
******************************************************************************************************************************************************************************/
function reportPost(postId)
{
	document.getElementById("report_" + postId).innerHTML = 'This comment has been reported.';
}

/******************************************************************************************************************************************************************************
																																							Function: closePurchased()
******************************************************************************************************************************************************************************/
function closePurchased()
{
	Effect.Fade("purchasedDiv", { duration: 0.3 });
}

/******************************************************************************************************************************************************************************
																																							Function: giftPageReceived()
******************************************************************************************************************************************************************************/
function giftPageReceived(dataResponse, url, error)
{
	debug("Request returned: " + dataResponse.text);
	if(error)
		secureRequest(LAST_REQUEST_DATA, LAST_REQUEST_CALLBACK);
	else
	{
		var data = dataResponse.text.evalJSON();
		if(data.gifts != null)
		{
			//var gifts = '<a name="giftsTop"></a><div style="background:#4D8DD5; padding:3px; border:solid 1px #CCCCCC; color:#FFFFFF; width:666px; font-weight:bold; margin-top:20px; font-size:14px;">Gifts to ' + ticker + '</div><div id="gifts" style="background:#FFFFFF; border:solid 1px #CCCCCC; border:solid 1px #CCCCCC; color:#000000; width:661px; margin-top:0px; padding:5px; font-size:12px;"><center><table style="font-size:12px; text-align:center;" cellspacing="5" cellpadding="0"><tr>';
			var gifts = '<center><table style="font-size:12px; text-align:center;" cellspacing="5" cellpadding="20"><tr>';
			for(i = 0; i < data.gifts.length; i ++)
			{
				switch(parseInt(data.gifts[i].gift))
				{
					case 1:
						var image = 'http://gpujfwaa.joyent.us/myspace/fs/images/gifts/gift-box.png';
						var title = 'Gift Box';
						break;
					case 2:
						var image = 'http://gpujfwaa.joyent.us/myspace/fs/images/gifts/Dino-green.png';
						var title = 'Green dino';
						break;
					case 3:
						var image = 'http://gpujfwaa.joyent.us/myspace/fs/images/gifts/Caveman.png';
						var title = 'Caveman';
						break;
					case 4:
						var image = 'http://gpujfwaa.joyent.us/myspace/fs/images/gifts/Ninja-Toy.png';
						var title = 'Ninja';
						break;
					case 5:
						var image = 'http://gpujfwaa.joyent.us/myspace/fs/images/gifts/Pirate-Creature.png';
						var title = 'Pirate';
						break;
					case 6:
						var image = 'http://gpujfwaa.joyent.us/myspace/fs/images/gifts/Mammoth.png';
						var title = 'Mammoth';
						break;
					case 7:
						var image = 'http://gpujfwaa.joyent.us/myspace/fs/images/gifts/rose.png';
						var title = 'Rose';
						break;
					case 8:
						var image = 'http://gpujfwaa.joyent.us/myspace/fs/images/gifts/heart.png';
						var title = 'Heart';
						break;
					case 9:
						var image = null;
						var title = '$1 million';
						break;
					case 10:
						var image = null;
						var title = '25 Tokens';
						break;
					case 11:
						var image = null;
						var title = '$1 Billion';
						break;
					case 12:
						var image = null;
						var title = '50 Tokens';
						break;
					case 13:
						var image = 'http://gpujfwaa.joyent.us/myspace/fs/images/gifts/Red-Fish-48x48.png';
						var title = 'Red Fish';
						break;
					case 14:
						var image = 'http://gpujfwaa.joyent.us/myspace/fs/images/gifts/penguin2.png';
						var title = 'Penguin';
						break;
					case 15:
						var image = 'http://gpujfwaa.joyent.us/myspace/fs/images/gifts/wizard.png';
						var title = 'Wizard';
						break;
					default:
						var image = 'http://gpujfwaa.joyent.us/myspace/fs/images/gifts/gift-box.png';
						var title = 'Gift Box';
						break;
				}
				
				var name = data.gifts[i].name;
				if(name.length > 7)
				{
					var temp = name;
					name = temp.substring(0, 4);
					name += '...';
				}
				if(!name)
					name = 'MS User';
						
				gifts += '<td>';
				if(image != null)
					gifts += '<img src="' + image + '"/><br/>';
				gifts += '<span style="font-weight:bold;">' + title + '</span><br/>from <a href="javascript:void(0);" onClick="renderPage(PAGE.PROFILE, ' + data.gifts[i].id + '); this.blur();" title="' + data.gifts[i].name + '">' + name + '</a></td>';
				if(i % 5 == 4)
					gifts += '</tr><tr>';
			}
			gifts += '</tr></table></center>';
			var last = data.gift_last;
			var page = parseInt(data.gift_page);
			var pagination = '<div style="font-size:14px; margin-top:3px; margin-left:3px;">Displaying ' + ((page-1)*10+1) + " - " + Math.min(((page-1)*10+10),data.gift_count) + " of " + data.gift_count + " gifts</div><center>";
			if(last <= 6)
			{
				if(page > 1)
					pagination += '<a href="javascript:void(0);" onClick="profileGiftsPage(' + (page - 1) + ', \'' + data.id + '\');" title="Gifts page ' + (page - 1) + '" style="font-weight:bold; font-size:14px; margin-right:10px;">&lsaquo;&lsaquo; previous</a> ';
				else
					pagination += '<span style="font-weight:bold; font-size:14px; margin-right:10px;">&lsaquo;&lsaquo; previous</span> ';
				for(i = 1; i <= last; i ++)
				{
					if(i != page)
						pagination += '<a href="javascript:void(0);" onClick="profileGiftsPage(' + i + ', \'' + data.id + '\');" title="Gifts page ' + i + '" style="font-weight:bold; font-size:14px;">' + i + '</a> ';
					else
						pagination += '<span style="font-weight:bold; font-size:14px;">' + i + '</span> ';
				}
				if(page < last)
					pagination += '<a href="javascript:void(0);" onClick="profileGiftsPage(' + (page + 1) + ', \'' + data.id + '\');" title="Gifts page ' + (page + 1) + '" style="font-weight:bold; font-size:14px; margin-left:10px;">next &rsaquo;&rsaquo;</a>';
				else
					pagination += '<span style="font-weight:bold; font-size:14px; margin-left:10px;">next &rsaquo;&rsaquo;</span> ';
			}
			else
			{
				if(page > 1)
					pagination += '<a href="javascript:void(0);" onClick="profileGiftsPage(' + (page - 1) + ', \'' + data.id + '\');" title="Gifts page ' + (page - 1) + '" style="font-weight:bold; font-size:14px; margin-right:10px;">&lsaquo;&lsaquo; previous</a> ';
				else
					pagination += '<span style="font-weight:bold; font-size:14px; margin-right:10px;">&lsaquo;&lsaquo; previous</span> ';
				if(page != 1)
					pagination += '<a href="javascript:void(0);" onClick="profileGiftsPage(1, \'' + data.id + '\');" title="News page 1" style="font-weight:bold; font-size:14px;">1</a> ';
				else
					pagination += '<span style="font-weight:bold; font-size:14px;">1</span> ';
				if(page > 5)
					pagination += ' ... ';
				for(i = Math.max(2, page-3); i <= Math.min(last-1, page+3); i ++)
				{
					if(i != page)
						pagination += '<a href="javascript:void(0);" onClick="profileGiftsPage(' + i + ', \'' + data.id + '\');" title="Gifts page ' + i + '" style="font-weight:bold; font-size:14px;">' + i + '</a> ';
					else
						pagination += '<span style="font-weight:bold; font-size:14px;">' + i + '</span> ';
				}
				if(page < last-4)
					pagination += '... ';
				if(page != last)
					pagination += '<a href="javascript:void(0);" onClick="profileGiftsPage(' + last + ', \'' + data.id + '\');" title="Gifts page ' + last + '" style="font-weight:bold; font-size:14px;">' + last + '</a> ';
				else
					pagination += '<span style="font-weight:bold; font-size:14px;">' + last + '</span> ';
				if(page < last)
					pagination += '<a href="javascript:void(0);" onClick="profileGiftsPage(' + (page + 1) + ', \'' + data.id + '\');" title="Gifts page ' + (page + 1) + '" style="font-weight:bold; font-size:14px; margin-left:10px;">next &rsaquo;&rsaquo;</a>';
				else
					pagination += '<span style="font-weight:bold; font-size:14px; margin-left:10px;">next &rsaquo;&rsaquo;</span> ';
			}
			pagination += "</center>";
			gifts += pagination;
		}
		else
			var gifts = '';
		document.getElementById("gifts").innerHTML = gifts;
		document.location.hash = "#giftsTop";
	}
}

/******************************************************************************************************************************************************************************
																																							Function: profileGiftsPage()
******************************************************************************************************************************************************************************/
function profileGiftsPage(page, id)
{
	var data = {action: "giftPage", id: id, page: page};
	secureRequest(data, giftPageReceived);
}

/******************************************************************************************************************************************************************************
																																							Function: showFloater()
******************************************************************************************************************************************************************************/
function showFloater(type, id, oEvent, name)
{
	//line 737
	var floater = document.getElementById("floater");
	
	if(type == 'poke')
	{
		if(id != OWNER.ID)
		{
			floater.innerHTML = 'Have yourself <select id="pokeAction" style="font-size:14px; border:solid 1px #666666;" onChange="this.blur();">\
		<option value="1">flirt with</option>\
	<option value="2">high five</option>\
	<option value="3">hug</option>\
	<option value="4">karate chop</option>\
	<option value="5">kick</option>\
	<option value="6">kiss</option>\
	<option value="14">lick</option>\
	<option value="17">nibble</option>\
	<option value="7">pinch</option>\
	<option value="8" selected="selected">poke</option>\
	<option value="9">punch</option>\
	<option value="10">slap</option>\
	<option value="15">spank</option>\
	<option value="18">suck on</option>\
	<option value="11">thank</option>\
	<option value="12">tickle</option>\
	<option value="16">tie up</option>\
	<option value="13">wink at</option>\
		</select>\
		' + unescape(name) + '.<div style="text-align:right;"><input type="button" value="Cancel" onClick="closeFloater();" id="commentButton" style="background:#3B5998; border:solid 2px #CCCCCC; margin-top:3px; font-size:12px; font-weight:bold; padding:3px; color:#FFFFFF;"/> <input type="button" value="Poke" onClick="doPoke(' + id + '); this.blur();" id="pokeButton" style="background:#3B5998; border:solid 2px #CCCCCC; margin-top:3px; font-size:12px; font-weight:bold; padding:3px; color:#FFFFFF;"/></div>';
			floater.style.width = "380px";
		}
		else
		{
			floater.innerHTML = 'You cannot poke yourself!<div style="text-align:right;"><input type="button" value="Close" onClick="closeFloater();" id="commentButton" style="background:#3B5998; border:solid 2px #CCCCCC; margin-top:3px; font-size:12px; font-weight:bold; padding:3px; color:#FFFFFF;"/></div>';
			floater.style.width = "180px";
		}
	}
	else if(type == 'split')
	{
		floater.innerHTML = 'Are you sure you want to split your stock?<div id="gift_error" style="color:#FF0000; font-size:12px; text-align:center;"></div><div style="text-align:right;"><input type="button" value="Cancel" onClick="closeFloater();" id="commentButton" style="background:#3B5998; border:solid 2px #CCCCCC; margin-top:3px; font-size:12px; font-weight:bold; padding:3px; color:#FFFFFF;"/> <input type="button" value="Split" onClick="doSplit(); this.blur();" id="pokeButton" style="background:#3B5998; border:solid 2px #CCCCCC; margin-top:3px; font-size:12px; font-weight:bold; padding:3px; color:#FFFFFF;"/></div>';
		floater.style.width = "280px";
	}
	else if(type == 'track')
	{
		if(id != OWNER.ID)
		{
			floater.style.width = "260px";
			doTrack(id);
		}
		else
		{
			floater.innerHTML = 'You cannot track yourself!<div style="text-align:right;"><input type="button" value="Close" onClick="closeFloater();" id="commentButton" style="background:#3B5998; border:solid 2px #CCCCCC; margin-top:3px; font-size:12px; font-weight:bold; padding:3px; color:#FFFFFF;"/></div>';
			floater.style.width = "180px";
		}
	}
	else if(type == 'gift')
	{
		if(id != OWNER.ID)
		{
			floater.innerHTML = 'Select a gift you would like to send to ' + unescape(name) + '.\
			<center><form name="gift_form"><table style="font-size:12px; text-align:center;" cellpadding="0" cellspacing="0">\
			<tr>\
			<td style="width:130px; height:100px;"><img src="http://gpujfwaa.joyent.us/myspace/fs/images/gifts/gift-box.png"/><br/><span style="font-weight:bold;">Gift Box</span><br/>$5,000<br/><input type="radio" name="gift" value="1" checked/></td>\
			<td style="width:130px; height:100px;"><img src="http://gpujfwaa.joyent.us/myspace/fs/images/gifts/Dino-green.png"/><br/><span style="font-weight:bold;">Green Dino</span><br/>$10,000<br/><input type="radio" name="gift" value="2"/></td>\
			<td style="width:130px; height:100px;"><img src="http://gpujfwaa.joyent.us/myspace/fs/images/gifts/Caveman.png"/><br/><span style="font-weight:bold;">Caveman</span><br/>$25,000<br/><input type="radio" name="gift" value="3"/></td>\
			<td style="width:130px; height:100px;"><img src="http://gpujfwaa.joyent.us/myspace/fs/images/gifts/Ninja-Toy.png"/><br/><span style="font-weight:bold;">Ninja</span><br/>$50,000<br/><input type="radio" name="gift" value="4"/></td>\
			<td style="width:130px; height:100px;"><img src="http://gpujfwaa.joyent.us/myspace/fs/images/gifts/Pirate-Creature.png"/><br/><span style="font-weight:bold;">Pirate</span><br/>$100,000<br/><input type="radio" name="gift" value="5"/></td>\
			</tr>\
			<tr>\
			<td style="width:130px; height:100px;"><img src="http://gpujfwaa.joyent.us/myspace/fs/images/gifts/wizard.png"/><br/><span style="font-weight:bold;">Wizard</span><br/>$1M<br/><input type="radio" name="gift" value="15"/></td>\
			<td style="width:130px; height:100px;"><img src="http://gpujfwaa.joyent.us/myspace/fs/images/gifts/Mammoth.png"/><br/><span style="font-weight:bold;">Mammoth</span><br/>$25M<br/><input type="radio" name="gift" value="6"/></td>\
			<td style="width:130px; height:100px;"><img src="http://gpujfwaa.joyent.us/myspace/fs/images/gifts/rose.png"/><br/><span style="font-weight:bold;">Rose</span><br/>$100M<br/><input type="radio" name="gift" value="7"/></td>\
			<td style="width:130px; height:100px;"><img src="http://gpujfwaa.joyent.us/myspace/fs/images/gifts/penguin2.png"/><br/><span style="font-weight:bold;">Penguin</span><br/>$500M<br/><input type="radio" name="gift" value="14"/></td>\
			<td style="width:130px; height:100px;"><img src="http://gpujfwaa.joyent.us/myspace/fs/images/gifts/heart.png"/><br/><span style="font-weight:bold;">Heart</span><br/>$50B<br/><input type="radio" name="gift" value="8"/></td>\
			</tr>\
			</table></form></center>\
			<div id="gift_error" style="color:#FF0000; font-size:12px; text-align:center;"></div><div style="text-align:right;"><input type="button" value="Cancel" onClick="closeFloater();" id="commentButton" style="background:#3B5998; border:solid 2px #CCCCCC; margin-top:3px; font-size:12px; font-weight:bold; padding:3px; color:#FFFFFF;"/> <input type="button" value="Give Gift" onClick="doGiveGift(' + id + '); this.blur();" id="pokeButton" style="background:#3B5998; border:solid 2px #CCCCCC; margin-top:3px; font-size:12px; font-weight:bold; padding:3px; color:#FFFFFF;"/></div>';
			floater.style.width = "650px";
		}
		else
		{
			floater.innerHTML = 'You cannot send yourself a gift!<div style="text-align:right;"><input type="button" value="Close" onClick="closeFloater();" id="commentButton" style="background:#3B5998; border:solid 2px #CCCCCC; margin-top:3px; font-size:12px; font-weight:bold; padding:3px; color:#FFFFFF;"/></div>';
			floater.style.width = "200px";
		}
	}
	Effect.Appear("floater", { duration : 0.3 } );
}

/******************************************************************************************************************************************************************************
																																							Function: doSplit()
******************************************************************************************************************************************************************************/
function doSplit()
{
	var pokeButton = document.getElementById("pokeButton");
	pokeButton.disabled = true;
	pokeButton.style.color = "#666666";
	pokeButton.value = "Splitting stock...";
	var data = {action: "splitStock"};
	secureRequest(data, stockSplit);
}

/******************************************************************************************************************************************************************************
																																							Function: stockSplit()
******************************************************************************************************************************************************************************/
function stockSplit(dataResponse, url, error)
{
	debug("Request returned: " + dataResponse.text);
	if(error)
		secureRequest(LAST_REQUEST_DATA, LAST_REQUEST_CALLBACK);
	else
	{
		var data = dataResponse.text.evalJSON();
		if(data.success == 'true')
		{
			var floater = document.getElementById("floater");
			floater.style.width = "300px";
			floater.innerHTML = 'Your stock has been split.';
			TIMER = setTimeout("renderPage(PAGE.PROFILE, " + data.id + ")", 2000);
		}
		else
		{
			var pokeButton = document.getElementById("pokeButton");
			pokeButton.disabled = false;
			pokeButton.style.color = "#FFFFFF";
			pokeButton.value = "Split";
			document.getElementById("gift_error").innerHTML = data.message;
		}
	}
}

/******************************************************************************************************************************************************************************
																																							Function: doGiveGift()
******************************************************************************************************************************************************************************/
function doGiveGift(id)
{
	var pokeButton = document.getElementById("pokeButton");
	pokeButton.disabled = true;
	pokeButton.style.color = "#666666";
	pokeButton.value = "Sending Gift...";
	for (var i=0; i < document.gift_form.gift.length; i++)
	{
		if (document.gift_form.gift[i].checked)
			var rad_val = document.gift_form.gift[i].value;
	}
	if(rad_val == null)
	{
		document.getElementById("gift_error").innerHTML = 'You must select a gift.';
	}
	else
	{
		var data = {action: "sendGift", id: id, gift: rad_val};
		secureRequest(data, giftSent);
	}
}

/******************************************************************************************************************************************************************************
																																							Function: giftSent()
******************************************************************************************************************************************************************************/
function giftSent(dataResponse, url, error)
{
	debug("Request returned: " + dataResponse.text);
	if(error)
		secureRequest(LAST_REQUEST_DATA, LAST_REQUEST_CALLBACK);
	else
	{
		var data = dataResponse.text.evalJSON();
		if(data.success == 'true')
		{
			var floater = document.getElementById("floater");
			floater.style.width = "300px";
			floater.innerHTML = 'Your gift has been sent.';
			TIMER = setTimeout("closeFloater()", 2000);
		}
		else
		{
			var pokeButton = document.getElementById("pokeButton");
			pokeButton.disabled = false;
			pokeButton.style.color = "#FFFFFF";
			pokeButton.value = "Give Gift";
			document.getElementById("gift_error").innerHTML = data.message;
		}
	}
}

/******************************************************************************************************************************************************************************
																																							Function: closeFloater()
******************************************************************************************************************************************************************************/
function closeFloater()
{
	Effect.Fade("floater", { duration : 0.2 } );
}

/******************************************************************************************************************************************************************************
																																							Function: doTrack()
******************************************************************************************************************************************************************************/
function doTrack(id)
{
	var data = {action: "trackUser", id: id};
	secureRequest(data, userTracked);
}

/******************************************************************************************************************************************************************************
																																							Function: pokePerformed()
******************************************************************************************************************************************************************************/
function userTracked(dataResponse, url, error)
{
	debug("Request returned: " + dataResponse.text);
	if(error)
		secureRequest(LAST_REQUEST_DATA, LAST_REQUEST_CALLBACK);
	else
	{
		var data = dataResponse.text.evalJSON();
		if(data.tracking == 'true')
			floater.innerHTML = 'You are now tracking this user.';
		else if(data.tracking == 'false')
			floater.innerHTML = 'You are no longer tracking this user.';
		TIMER = setTimeout("closeFloater()", 3000);
	}
}

/******************************************************************************************************************************************************************************
																																							Function: doPoke()
******************************************************************************************************************************************************************************/
function doPoke(id)
{
	var pokeButton = document.getElementById("pokeButton");
	pokeButton.disabled = true;
	pokeButton.style.color = "#666666";
	pokeButton.value = "Poking...";
	var sel = document.getElementById("pokeAction");
	var pokeAction = sel.options[sel.selectedIndex].value;
	var data = {action: "doPoke", id: id, pokeAction: pokeAction};
	secureRequest(data, pokePerformed);
}

/******************************************************************************************************************************************************************************
																																							Function: pokePerformed()
******************************************************************************************************************************************************************************/
function pokePerformed(dataResponse, url, error)
{
	debug("Request returned: " + dataResponse.text);
	if(error)
		secureRequest(LAST_REQUEST_DATA, LAST_REQUEST_CALLBACK);
	else
	{
		var data = dataResponse.text.evalJSON();
		Effect.Fade("floater", { duration : 0.2 } );
		profileFeedsPage(1, data.id)
	}
}

/******************************************************************************************************************************************************************************
																																							Function: commentDeleted()
******************************************************************************************************************************************************************************/
function commentDeleted(dataResponse, url, error)
{
	debug("Request returned: " + dataResponse.text);
	if(error)
		secureRequest(LAST_REQUEST_DATA, LAST_REQUEST_CALLBACK);
	else
	{
		var data = dataResponse.text.evalJSON();
		profileCommentsPage(1, data.id);
	}
}

/******************************************************************************************************************************************************************************
																																							Function: deleteComment()
******************************************************************************************************************************************************************************/
function deleteComment(toId, fromId, time)
{
	var data = {action: "deleteComment", toId: toId, fromId: fromId, time: time};
	secureRequest(data, commentDeleted);
}

/******************************************************************************************************************************************************************************
																																							Function: showBoostStock()
******************************************************************************************************************************************************************************/
function showBoostStock(id)
{
	document.getElementById(id + "_purchase").innerHTML = 'Are you sure you want to boost the value of this stock for <span style="color:#CC0000;">1 token</span>? You have <span style="color:#00CC00;">' + addCommas(OWNER_TOKENS) + ' tokens</span>.<br/><input type="button" value="Boost" id="' + id + '_continueBoostButton" onClick="boostUser(' + id + ');" style="background:#3B5998; border:solid 2px #CCCCCC; margin-top:2px; font-size:12px; font-weight:bold; padding:3px; color:#FFFFFF;"/><input type="button" value="Cancel" id="' + id + '_continuePurchaseButton" onClick="closePurchaseStock(' + id + ');" style="background:#3B5998; border:solid 2px #CCCCCC; margin-top:2px; margin-left:6px; font-size:12px; font-weight:bold; padding:3px; color:#FFFFFF;"/>';
	Effect.Fade(id + "_purchaseButton", { duration: 0.2} );
	Effect.Fade(id + "_boostButton", { duration: 0.2} );
	Effect.Appear(id + "_purchase", { queue: 'end', duration: 0.5 } );
}

/******************************************************************************************************************************************************************************
																																							Function: showBoostStockPortfolio()
******************************************************************************************************************************************************************************/
function showBoostStockPortfolio(id, page)
{
	document.getElementById(id + "_purchase").innerHTML = 'Are you sure you want to boost the value of this stock for <span style="color:#CC0000;">1 token</span>? You have <span style="color:#00CC00;">' + addCommas(OWNER_TOKENS) + ' tokens</span>.<br/><input type="button" value="Boost" id="' + id + '_continueBoostButton" onClick="boostUserPortfolio(' + id + ', ' + page + ');" style="background:#3B5998; border:solid 2px #CCCCCC; margin-top:2px; font-size:12px; font-weight:bold; padding:3px; color:#FFFFFF;"/><input type="button" value="Cancel" id="' + id + '_continuePurchaseButton" onClick="closePurchaseStock(' + id + ');" style="background:#3B5998; border:solid 2px #CCCCCC; margin-top:2px; margin-left:6px; font-size:12px; font-weight:bold; padding:3px; color:#FFFFFF;"/>';
	Effect.Fade(id + "_boostButton", { duration: 0.2} );
	Effect.Appear(id + "_purchase", { queue: 'end', duration: 0.5 } );
}

/******************************************************************************************************************************************************************************
																																							Function: boostUser()
******************************************************************************************************************************************************************************/
function boostUserPortfolio(id, page)
{
	var purchaseButton = document.getElementById(id + "_continueBoostButton");
	purchaseButton.disabled = true;
	purchaseButton.style.color = "#666666";
	var data = {action: "boostUser", id: id, page: page};
	secureRequest(data, userBoostedPortfolio);
}

/******************************************************************************************************************************************************************************
																																							Function: userBoosted()
******************************************************************************************************************************************************************************/
function userBoostedPortfolio(dataResponse, url, error)
{
	debug("Request returned: " + dataResponse.text);
	if(error)
		secureRequest(LAST_REQUEST_DATA, LAST_REQUEST_CALLBACK);
	else
	{
		var data = dataResponse.text.evalJSON();
		if(data.success == "true")
		{
			document.getElementById("ownerTokens").innerHTML = addCommas(data.tokens);
			portfolioPage(data.page);
		}
		else
		{
			document.getElementById(data.id + "_purchase").innerHTML = data.message;
			setTimeout("closeSellStock(" + data.id + ")", 1000);
		}
	}
}

/******************************************************************************************************************************************************************************
																																							Function: boostUser()
******************************************************************************************************************************************************************************/
function boostUser(id)
{
	var purchaseButton = document.getElementById(id + "_continueBoostButton");
	purchaseButton.disabled = true;
	purchaseButton.style.color = "#666666";
	var data = {action: "boostUser", id: id};
	secureRequest(data, userBoosted);
}

/******************************************************************************************************************************************************************************
																																							Function: userBoosted()
******************************************************************************************************************************************************************************/
function userBoosted(dataResponse, url, error)
{
	debug("Request returned: " + dataResponse.text);
	if(error)
		secureRequest(LAST_REQUEST_DATA, LAST_REQUEST_CALLBACK);
	else
	{
		var data = dataResponse.text.evalJSON();
		if(data.success == "true")
		{
			renderPage(PAGE.PROFILE, data.id);
		}
		else
		{
			document.getElementById(data.id + "_purchase").innerHTML = data.message;
			setTimeout("closeSellStock(" + data.id + ")", 5000);
		}
	}
}

/******************************************************************************************************************************************************************************
																																							Function: blockUser()
******************************************************************************************************************************************************************************/
function blockUser(id)
{
	var data = {action: "blockUser", id: id};
	secureRequest(data, userBlocked);
}

/******************************************************************************************************************************************************************************
																																							Function: userBlocked()
******************************************************************************************************************************************************************************/
function userBlocked(dataResponse, url, error)
{
	debug("Request returned: " + dataResponse.text);
	if(error)
		secureRequest(LAST_REQUEST_DATA, LAST_REQUEST_CALLBACK);
	else
	{
		var data = dataResponse.text.evalJSON();
		if(data.success == 'false')
		{
			var floater = document.getElementById("floater");
			floater.style.width = "370px";
			floater.innerHTML = data.message;
			Effect.Appear("floater", { duration : 0.3 } );
			TIMER = setTimeout("closeFloater()", 5000);
		}
		else
			renderPage(PAGE.PROFILE, data.id);
	}
}

/******************************************************************************************************************************************************************************
																																							Function: unHoverAnchor()
******************************************************************************************************************************************************************************/
function unHoverAnchor(id)
{
	var thisAnchor = document.getElementById(id);
	thisAnchor.style.color = "#3B5998";
	thisAnchor.style.backgroundColor = "#FFFFFF";
	thisAnchor.style.cursor = "default";
}

/******************************************************************************************************************************************************************************
																																							Function: hoverAnchor()
******************************************************************************************************************************************************************************/
function hoverAnchor(id)
{
	var thisAnchor = document.getElementById(id);
	thisAnchor.style.color = "#FFFFFF";
	thisAnchor.style.backgroundColor = "#3B5998";
	thisAnchor.style.cursor = "pointer";
	thisAnchor.style.cursor = "hand";
}

/******************************************************************************************************************************************************************************
																																							Function: profileFeedsPage()
******************************************************************************************************************************************************************************/
function profileFeedsPage(page, id)
{
	var data = {action: "feedPage", id: id, page: page};
	secureRequest(data, feedsReceived);
}

/******************************************************************************************************************************************************************************
																																							Function: feedsReceived()
******************************************************************************************************************************************************************************/
function feedsReceived(dataResponse, url, error)
{
	debug("Request returned: " + dataResponse.text);
	if(error)
		secureRequest(LAST_REQUEST_DATA, LAST_REQUEST_CALLBACK);
	else
	{
		var data = dataResponse.text.evalJSON();
		
		if(data.feeds != null)
		{
			var feeds = '';
			for(i = 0; i < data.feeds.length; i ++)
			{
				var feed = data.feeds[i].feed;
				feed = feed.replace(/{id1}/g, '<a href="javascript:void(0);" onClick="renderPage(PAGE.PROFILE, \'' + data.feeds[i].id1 + '\');" title="' + data.feeds[i].name1 + '">' + data.feeds[i].name1 + '</a>');
				feed = feed.replace(/{id2}/g, '<a href="javascript:void(0);" onClick="renderPage(PAGE.PROFILE, \'' + data.feeds[i].id2 + '\');" title="' + data.feeds[i].name2 + '">' + data.feeds[i].name2 + '</a>');
				if(data.feeds[i].ticker1 != null)
					feed = feed.replace(/{id1i}/g, '<a href="javascript:void(0);" onClick="renderPage(PAGE.PROFILE, \'' + data.feeds[i].id1 + '\');" title="' + data.feeds[i].name1 + ', Inc. (' + data.feeds[i].ticker1 + ')">' + data.feeds[i].name1 + ', Inc. (' + data.feeds[i].ticker1 + ')</a>');
				else
					feed = feed.replace(/{id1i}/g, '<a href="javascript:void(0);" onClick="renderPage(PAGE.PROFILE, \'' + data.feeds[i].id1 + '\');" title="' + data.feeds[i].name1 + ', Inc.">' + data.feeds[i].name1 + ', Inc.</a>');
				if(data.feeds[i].ticker2 != null)
					feed = feed.replace(/{id2i}/g, '<a href="javascript:void(0);" onClick="renderPage(PAGE.PROFILE, \'' + data.feeds[i].id2 + '\');" title="' + data.feeds[i].name2 + ', Inc. (' + data.feeds[i].ticker2 + ')">' + data.feeds[i].name2 + ', Inc. (' + data.feeds[i].ticker2 + ')</a>');
				else
					feed = feed.replace(/{id2i}/g, '<a href="javascript:void(0);" onClick="renderPage(PAGE.PROFILE, \'' + data.feeds[i].id2 + '\');" title="' + data.feeds[i].name2 + ', Inc.">' + data.feeds[i].name2 + ', Inc.</a>');
				feed = feed.replace(/{value}/, '<span style="font-weight:bold;">$' + addCommas(data.feeds[i].value) + '</span>');
				feed = feed.replace(/{profit}/, '<span style="font-weight:bold;">$' + addCommas(data.feeds[i].profit) + '</span>');
				feed = feed.replace(/{poke}/, data.feeds[i].poke);
				if(data.feeds[i].type == 1 || data.feeds[i].type == 2)
					feeds += '<div style="border-bottom:solid 1px #CCCCCC; padding:3px; font-size:14px; width:653px; background:#CCFFCC; margin-bottom:3px; min-height:25px; _height:25px;"><div style="float:left; width:25px; height:25px; overflow:hidden;"><a href="javascript:void(0);" onClick="renderPage(PAGE.PROFILE, \'' + data.feeds[i].link1 + '\');" title="' + data.feeds[i].name1 + '">' + data.feeds[i].image1 + '</a></div><div style="margin-left:30px;">' + feed + '<div style="color:#666666; font-size:12px; text-align:right; margin-bottom:0px; line-height:12px;">' + data.feeds[i].time + '</div></div></div>';
				else if(data.feeds[i].type >= 3 && data.feeds[i].type <= 6)
					feeds += '<div style="border-bottom:solid 1px #CCCCCC; padding:3px; font-size:14px; width:653px; background:#FFCCCC; margin-bottom:3px; min-height:25px; _height:25px;"><div style="float:left; width:25px; height:25px; overflow:hidden;"><a href="javascript:void(0);" onClick="renderPage(PAGE.PROFILE, \'' + data.feeds[i].link1 + '\');" title="' + data.feeds[i].name1 + '">' + data.feeds[i].image1 + '</a></div><div style="margin-left:30px;">' + feed + '<div style="color:#666666; font-size:12px; text-align:right; margin-bottom:0px; line-height:12px;">' + data.feeds[i].time + '</div></div></div>';
				else
					feeds += '<div style="border-bottom:solid 1px #CCCCCC; padding:3px; font-size:14px; width:653px; background:#F6F6F6; margin-bottom:3px; min-height:25px; _height:25px;"><div style="float:left; width:25px; height:25px; overflow:hidden;"><a href="javascript:void(0);" onClick="renderPage(PAGE.PROFILE, \'' + data.feeds[i].link1 + '\');" title="' + data.feeds[i].name1 + '">' + data.feeds[i].image1 + '</a></div><div style="margin-left:30px;">' + feed + '<div style="color:#666666; font-size:12px; text-align:right; margin-bottom:0px; line-height:12px;">' + data.feeds[i].time + '</div></div></div>';
			}
			var last = data.feed_last;
			var page = parseInt(data.feed_page);
			var pagination = '<div style="font-size:14px; margin-top:3px; margin-left:3px;">Displaying ' + ((page-1)*10+1) + " - " + Math.min(((page-1)*10+10),data.feed_count) + " of " + data.feed_count + " news feeds</div><center>";
			if(last <= 6)
			{
				if(page > 1)
					pagination += '<a href="javascript:void(0);" onClick="profileFeedsPage(' + (page - 1) + ', \'' + data.id + '\');" title="News page ' + (page - 1) + '" style="font-weight:bold; font-size:14px; margin-right:10px;">&lsaquo;&lsaquo; previous</a> ';
				else
					pagination += '<span style="font-weight:bold; font-size:14px; margin-right:10px;">&lsaquo;&lsaquo; previous</span> ';
				for(i = 1; i <= last; i ++)
				{
					if(i != page)
						pagination += '<a href="javascript:void(0);" onClick="profileFeedsPage(' + i + ', \'' + data.id + '\');" title="News page ' + i + '" style="font-weight:bold; font-size:14px;">' + i + '</a> ';
					else
						pagination += '<span style="font-weight:bold; font-size:14px;">' + i + '</span> ';
				}
				if(page < last)
					pagination += '<a href="javascript:void(0);" onClick="profileFeedsPage(' + (page + 1) + ', \'' + data.id + '\');" title="News page ' + (page + 1) + '" style="font-weight:bold; font-size:14px; margin-left:10px;">next &rsaquo;&rsaquo;</a>';
				else
					pagination += '<span style="font-weight:bold; font-size:14px; margin-left:10px;">next &rsaquo;&rsaquo;</span> ';
			}
			else
			{
				if(page > 1)
					pagination += '<a href="javascript:void(0);" onClick="profileFeedsPage(' + (page - 1) + ', \'' + data.id + '\');" title="News page ' + (page - 1) + '" style="font-weight:bold; font-size:14px; margin-right:10px;">&lsaquo;&lsaquo; previous</a> ';
				else
					pagination += '<span style="font-weight:bold; font-size:14px; margin-right:10px;">&lsaquo;&lsaquo; previous</span> ';
				if(page != 1)
					pagination += '<a href="javascript:void(0);" onClick="profileFeedsPage(1, \'' + data.id + '\');" title="News page 1" style="font-weight:bold; font-size:14px;">1</a> ';
				else
					pagination += '<span style="font-weight:bold; font-size:14px;">1</span> ';
				if(page > 5)
					pagination += ' ... ';
				for(i = Math.max(2, page-3); i <= Math.min(last-1, page+3); i ++)
				{
					if(i != page)
						pagination += '<a href="javascript:void(0);" onClick="profileFeedsPage(' + i + ', \'' + data.id + '\');" title="News page ' + i + '" style="font-weight:bold; font-size:14px;">' + i + '</a> ';
					else
						pagination += '<span style="font-weight:bold; font-size:14px;">' + i + '</span> ';
				}
				if(page < last-4)
					pagination += '... ';
				if(page != last)
					pagination += '<a href="javascript:void(0);" onClick="profileFeedsPage(' + last + ', \'' + data.id + '\');" title="News page ' + last + '" style="font-weight:bold; font-size:14px;">' + last + '</a> ';
				else
					pagination += '<span style="font-weight:bold; font-size:14px;">' + last + '</span> ';
				if(page < last)
					pagination += '<a href="javascript:void(0);" onClick="profileFeedsPage(' + (page + 1) + ', \'' + data.id + '\');" title="News page ' + (page + 1) + '" style="font-weight:bold; font-size:14px; margin-left:10px;">next &rsaquo;&rsaquo;</a>';
				else
					pagination += '<span style="font-weight:bold; font-size:14px; margin-left:10px;">next &rsaquo;&rsaquo;</span> ';
			}
			pagination += "</center>";
			feeds += pagination;
		}
		else
			var feeds = 'This user does not have any news yet.';
		document.getElementById("feeds").innerHTML = feeds;
		document.location.hash = "#newsTop";
	}
}

/******************************************************************************************************************************************************************************
																																							Function: commentsReceived()
******************************************************************************************************************************************************************************/
function commentsReceived(dataResponse, url, error)
{
	debug("Request returned: " + dataResponse.text);
	if(error)
		secureRequest(LAST_REQUEST_DATA, LAST_REQUEST_CALLBACK);
	else
	{
		var data = dataResponse.text.evalJSON();
		
		if(data.comments != null)
		{
			var comments = '';
			for(i = 0; i < data.comments.length; i ++)
			{
				if(data.comments[i].can_delete == 'true')
					var canDelete = '<a href="javascript:void(0);" onClick="deleteComment(' + data.id + ', ' + data.comments[i].from_id + ', ' + data.comments[i].timestamp + '); this.blur();" title="Delete this post">delete</a> - ';
				else
					var canDelete = '';
				if(i % 4 == 0)
					comments += '</tr><tr>';
				comments += '<div style="margin-top:5px;"><div style="float:left; margin-left:5px; margin-right:10px; width:50px; height:50px; overflow:hidden;">' + data.comments[i].from_image + '</div><div style="border-top:solid 1px #999999; padding:4px; font-size:12px; width:588px; margin-left:65px; margin-bottom:3px; background:#E3E1FF;">' + data.comments[i].time + ' by <a href="javascript:void(0);" onClick="renderPage(PAGE.PROFILE, \'' + data.comments[i].from_id + '\'); this.blur();" title="' + unescape(data.comments[i].from_name) + '">' + unescape(data.comments[i].from_name) + '</a></div><div style="font-size:14px; width:588px; margin-left:65px; min-height:40px; _height:40px;">' + data.comments[i].comment + '</div><div style="font-size:10px; margin-top:0px; text-align:right; width:588px; margin-left:65px;">' + canDelete + '<span id="report_' + i + '"><a href="javascript:void(0);" title="Report inappropriate content in this post" onClick="reportPost(' + i + '); this.blur()">report</a></span></div></div>';
			}
			var last = data.comment_last;
			var page = parseInt(data.comment_page);
			var pagination = '<div style="font-size:12px; margin-left:10px; margin-top:5px;">Displaying ' + ((page-1)*10+1) + " - " + Math.min(((page-1)*10+10),data.comment_count) + " of " + data.comment_count + " comments</div><center>";
			if(last <= 6)
			{
				if(page > 1)
					pagination += '<a href="javascript:void(0);" onClick="profileCommentsPage(' + (page - 1) + ', \'' + data.id + '\');" title="Comments page ' + (page - 1) + '" style="font-weight:bold; font-size:14px; margin-right:10px;">&lsaquo;&lsaquo; previous</a> ';
				else
					pagination += '<span style="font-weight:bold; font-size:14px; margin-right:10px;">&lsaquo;&lsaquo; previous</span> ';
				for(i = 1; i <= last; i ++)
				{
					if(i != page)
						pagination += '<a href="javascript:void(0);" onClick="profileCommentsPage(' + i + ', \'' + data.id + '\');" title="Comments page ' + i + '" style="font-weight:bold; font-size:14px;">' + i + '</a> ';
					else
						pagination += '<span style="font-weight:bold; font-size:14px;">' + i + '</span> ';
				}
				if(page < last)
					pagination += '<a href="javascript:void(0);" onClick="profileCommentsPage(' + (page + 1) + ', \'' + data.id + '\');" title="Comments page ' + (page + 1) + '" style="font-weight:bold; font-size:14px; margin-left:10px;">next &rsaquo;&rsaquo;</a>';
				else
					pagination += '<span style="font-weight:bold; font-size:14px; margin-left:10px;">next &rsaquo;&rsaquo;</span> ';
			}
			else
			{
				if(page > 1)
					pagination += '<a href="javascript:void(0);" onClick="profileCommentsPage(' + (page - 1) + ', \'' + data.id + '\');" title="Comments page ' + (page - 1) + '" style="font-weight:bold; font-size:14px; margin-right:10px;">&lsaquo;&lsaquo; previous</a> ';
				else
					pagination += '<span style="font-weight:bold; font-size:14px; margin-right:10px;">&lsaquo;&lsaquo; previous</span> ';
				if(page != 1)
					pagination += '<a href="javascript:void(0);" onClick="profileCommentsPage(1, \'' + data.id + '\');" title="Comments page 1" style="font-weight:bold; font-size:14px;">1</a> ';
				else
					pagination += '<span style="font-weight:bold; font-size:14px;">1</span> ';
				if(page > 5)
					pagination += ' ... ';
				for(i = Math.max(2, page-3); i <= Math.min(last-1, page+3); i ++)
				{
					if(i != page)
						pagination += '<a href="javascript:void(0);" onClick="profileCommentsPage(' + i + ', \'' + data.id + '\');" title="Comments page ' + i + '" style="font-weight:bold; font-size:14px;">' + i + '</a> ';
					else
						pagination += '<span style="font-weight:bold; font-size:14px;">' + i + '</span> ';
				}
				if(page < last-4)
					pagination += '... ';
				if(page != last)
					pagination += '<a href="javascript:void(0);" onClick="profileCommentsPage(' + last + ', \'' + data.id + '\');" title="Comments page ' + last + '" style="font-weight:bold; font-size:14px;">' + last + '</a> ';
				else
					pagination += '<span style="font-weight:bold; font-size:14px;">' + last + '</span> ';
				if(page < last)
					pagination += '<a href="javascript:void(0);" onClick="profileCommentsPage(' + (page + 1) + ', \'' + data.id + '\');" title="Comments page ' + (page + 1) + '" style="font-weight:bold; font-size:14px; margin-left:10px;">next &rsaquo;&rsaquo;</a>';
				else
					pagination += '<span style="font-weight:bold; font-size:14px; margin-left:10px;">next &rsaquo;&rsaquo;</span> ';
			}
			pagination += "</center>";
			comments += pagination;
		}
		else
			var comments = '<div style="font-size:14px;">' + unescape(data.name) + ' does not have any comments yet.</div>';
		document.getElementById("comments").innerHTML = comments;
		document.location.hash = "#commentsTop";
	}
}

/******************************************************************************************************************************************************************************
																																							Function: profileCommentsPage()
******************************************************************************************************************************************************************************/
function profileCommentsPage(page, id)
{
	var data = {action: "commentPage", id: id, page: page};
	secureRequest(data, commentsReceived);
}

/******************************************************************************************************************************************************************************
																																							Function: leaveComment()
******************************************************************************************************************************************************************************/
function leaveComment(id)
{
	commentButton.disabled = true;
	commentButton.value = "Posting";
	commentButton.style.color = "#666666";
	var comment = document.getElementById("commentBox").value;
	var data = {action: "postComment", id: id, comment: comment};
	secureRequest(data, commentPosted);
}

/******************************************************************************************************************************************************************************
																																							Function: commentPosted()
******************************************************************************************************************************************************************************/
function commentPosted(dataResponse, url, error)
{
	debug("Request returned: " + dataResponse.text);
	if(error)
		secureRequest(LAST_REQUEST_DATA, LAST_REQUEST_CALLBACK);
	else
	{
		var data = dataResponse.text.evalJSON();
		hideCommentArea();
		profileCommentsPage(1, data.id);
	}
}

/******************************************************************************************************************************************************************************
																																							Function: hideCommentArea()
******************************************************************************************************************************************************************************/
function hideCommentArea()
{
	Effect.Fade("commentArea", { duration : 0.3 } );
	var commentBox = document.getElementById("commentBox");
	var commentButton = document.getElementById("commentButton");
	commentBox.style.color = "#999999";
	commentBox.value = "Leave a comment...";
	commentButton.disabled = true;
	commentButton.value = "Post";
	commentButton.style.color = "#666666";
}

/******************************************************************************************************************************************************************************
																																							Function: showCommentArea()
******************************************************************************************************************************************************************************/
function showCommentArea()
{
	Effect.Appear("commentArea", { duration : 0.3 } );
}

/******************************************************************************************************************************************************************************
																																							Function: commentFocus()
******************************************************************************************************************************************************************************/
function commentFocus()
{
	var commentBox = document.getElementById("commentBox");
	if(commentBox.value == "Leave a comment...")
	{
		commentBox.value = "";
		commentBox.style.color = "#000000";
	}
}

/******************************************************************************************************************************************************************************
																																							Function: commentBlur()
******************************************************************************************************************************************************************************/
function commentBlur()
{
	var commentBox = document.getElementById("commentBox");
	if(commentBox.value == "")
	{
		commentBox.style.color = "#999999";
		commentBox.value = "Leave a comment...";
	}
}

/******************************************************************************************************************************************************************************
																																							Function: checkComment()
******************************************************************************************************************************************************************************/
function checkComment()
{
	var commentBox = document.getElementById("commentBox");
	var commentButton = document.getElementById("commentButton");
	if(commentBox.value != "")
	{
		commentButton.style.color = "#FFFFFF";
		commentButton.disabled = false;
	}
	else if(commentBox.value == "" || commentBox.value == "Leave a comment...")
	{
		commentButton.style.color = "#666666";
		commentButton.disabled = true;
	}
}

/******************************************************************************************************************************************************************************
																																							Function: fillBrowsePage()
******************************************************************************************************************************************************************************/
function fillBrowsePage(dataResponse, url, error)
{
	debug("Request returned: " + dataResponse.text);
	if(error)
		secureRequest(LAST_REQUEST_DATA, LAST_REQUEST_CALLBACK);
	else
	{
		document.location.hash = "#purchaseTop";
		var data = dataResponse.text.evalJSON();
		
		var friends = '<a name="purchaseTop"></a>\
		<input type="button" value="MySpace Friends" onClick="changeSearchType(\'friends\');" id="searchTypeFriends" style="background:#FFFFFF; border:solid 2px #CCCCCC; font-size:16px; _font-size:14px; font-weight:bold; padding:3px; color:#3B5998; margin-left:10px;" disabled/>\
		<input type="button" value="All Users" onClick="changeSearchType(\'all\');" id="searchTypeAll" style="background:#3B5998; border:solid 2px #CCCCCC; font-size:16px; _font-size:14px; font-weight:bold; padding:3px; color:#FFFFFF; margin-left:10px;"/>\
		<input type="button" value="Online Users" onClick="changeSearchType(\'online\');" id="searchTypeOnline" style="background:#3B5998; border:solid 2px #CCCCCC; font-size:16px; _font-size:14px; font-weight:bold; padding:3px; color:#FFFFFF; margin-left:10px;"/>\
		<input type="button" value="Active Users" onClick="changeSearchType(\'active\');" id="searchTypeActive" style="background:#3B5998; border:solid 2px #CCCCCC; font-size:16px; _font-size:14px; font-weight:bold; padding:3px; color:#FFFFFF; margin-left:10px;"/>\
		<input type="button" value="New Users" onClick="changeSearchType(\'new\');" id="searchTypeNew" style="background:#3B5998; border:solid 2px #CCCCCC; font-size:16px; _font-size:14px; font-weight:bold; padding:3px; color:#FFFFFF; margin-left:10px;"/>\
		<input type="button" value="Tracked Users" onClick="changeSearchType(\'tracked\');" id="searchTypeTracked" style="background:#3B5998; border:solid 2px #CCCCCC; font-size:16px; _font-size:14px; font-weight:bold; padding:3px; color:#FFFFFF; margin-left:10px;"/>\
		<div style="margin-top:8px; margin-bottom:8px; margin-left:50px; font-size:16px; _font-size:14px; font-weight:bold; display:none;" id="additionalSearchOptions" onMouseOver="focusSearchOptions();" onMouseOut="blurSearchOptions();">\
		Sex: <input type="button" value="Both" onClick="changeSexSearch();" id="sexSearchButton" style="background:#3B5998; border:solid 2px #CCCCCC; font-size:12px; font-weight:bold; padding:3px; color:#FFFFFF; margin-right:10px;"/>\
		Value: <input type="button" value="Any" onClick="changeValueSearch();" id="valueSearchButton" style="background:#3B5998; border:solid 2px #CCCCCC; font-size:12px; font-weight:bold; padding:3px; color:#FFFFFF; margin-right:10px;"/>\
		Age: <input type="button" value="All" onClick="changeAgeSearch();" id="ageSearchButton" style="background:#3B5998; border:solid 2px #CCCCCC; font-size:12px; font-weight:bold; padding:3px; color:#FFFFFF; margin-right:10px;"/>\
		Activity: <input type="button" value="Any" onClick="changeActivitySearch();" id="activitySearchButton" style="background:#3B5998; border:solid 2px #CCCCCC; font-size:12px; font-weight:bold; padding:3px; color:#FFFFFF; margin-right:10px;"/>\
		Only Show Affordable Stock: <input type="button" value="No" onClick="changeAffordableSearch();" id="affordableSearchButton" style="background:#3B5998; border:solid 2px #CCCCCC; font-size:12px; font-weight:bold; padding:3px; color:#FFFFFF; margin-right:10px;"/>\
		<div style="text-align:right; margin-right:50px; margin-top:5px;"><input type="button" value="Update Search" onClick="updateSearch(); this.blur();" id="updateSearchButton" style="background:#3B5998; border:solid 2px #CCCCCC; font-size:24px; font-weight:bold; padding:3px; color:#FFFFFF;"/></div>\
		</div>\
		<center>';
		for(i = 0; i < data.friends.length; i ++)
		{
			if(data.friends[i].cash != null)
				var cash = data.friends[i].cash;
			else
				var cash = '5,000,000';
			
			if(data.friends[i].value != null)
				var value = data.friends[i].value;
			else
				var value = '1,000,000';
			
			if(data.friends[i].lastactive != null)
				var lastActive = data.friends[i].lastactive;
			else
				var lastActive = 'Never';
			
			if(data.friends[i].nickname != null)
				var nickname = '<span style="color:#FF0000;">"' + data.friends[i].nickname + '"</span><br/>';
			else
				var nickname = '';
			
			if(data.friends[i].splits != null)
				var splits = addCommas(data.friends[i].splits);
			else
				var splits = '0';
				
			friends += '<a name="' + data.friends[i].userid + '_top"></a><div style="font-size:16px; border:solid 1px #CCCCCC; padding:10px; margin-left:auto; margin-right:auto; margin-top:10px; width:650px; _width:750px; height:120px; _height:130px; overflow:hidden; text-align:left; background:#FFFFFF;" id="' + data.friends[i].userid + '_friend"><div style="float:right; height:105px; _height:110px; width:225px; overflow:hidden;"><iframe id="chartFrame" src="http://gpujfwaa.joyent.us/myspace/fs/smallHourlyChart.php?id=' + data.friends[i].userid + '&days=7" frameborder="0" height="115" width="225" scrolling="no" marginwidth="0" marginheight="0"></iframe></div><div style="width:90px; height:100px; overflow:hidden; float:left; margin-right:10px;"><a href="javascript:void(0);" onClick="viewFriendWithName(\'' + data.friends[i].userid + '\', \'' + escape(data.friends[i].name) + '\', \'' + data.friends[i].imageuri + '\');" title="' + data.friends[i].name + '" id="' + data.friends[i].userid + '_name"><img src="' + data.friends[i].imageuri + '" id="' + data.friends[i].userid + '_image" border="0"/></a></div><div style="font-size:14px; font-weight:bold; width:400px; _float:left;"><span style="font-size:18px; font-weight:bold;"><a href="javascript:void(0);" onClick="viewFriendWithName(\'' + data.friends[i].userid + '\', \'' + escape(data.friends[i].name) + '\', \'' + data.friends[i].imageuri + '\');" title="' + data.friends[i].name + '" id="' + data.friends[i].userid + '_name">' + data.friends[i].name + '</a></span><br/><span style="color:#666666;">Trading For:</span> $<span id="' + data.friends[i].userid + '_value">' + addCommas(value) + '</span><br/><span style="color:#666666;">Cash:</span> $<span id="' + data.friends[i].userid + '_cash">' + addCommas(cash) + '</span><br/><span style="color:#666666;">Splits:</span> <span id="' + data.friends[i].userid + '_splits">' + splits + '</span><br/><span style="color:#666666;">Last Online:</span> ' + lastActive + '</div><br clear="all"/><div id="' + data.friends[i].userid + '_extension" style="display:none;"></div></div>';
		}
		friends += '</center>';
		
		queuePage("changePurchasePage('" + FRIEND_PAGE + "')");

		var last = Math.ceil(FRIEND_COUNT / 20);
		var page = FRIEND_PAGE;
		var pagination = '<div style="font-size:14px; margin-left:140px; margin-top:5px;">Displaying ' + ((page-1)*20+1) + " - " + Math.min(((page-1)*20+20),FRIEND_COUNT) + " of " + FRIEND_COUNT + " friends</div><center>";
		if(last <= 6)
		{
			if(page > 1)
				pagination += '<a href="javascript:void(0);" onClick="changePurchasePage(' + (page - 1) + ');" title="Results page ' + (page - 1) + '" style="font-weight:bold; font-size:16px; margin-right:10px;">&lsaquo;&lsaquo; previous</a> ';
			else
				pagination += '<span style="font-weight:bold; font-size:16px; margin-right:10px;">&lsaquo;&lsaquo; previous</span> ';
			for(i = 1; i <= last; i ++)
			{
				if(i != page)
					pagination += '<a href="javascript:void(0);" onClick="changePurchasePage(' + i + ');" title="Results page ' + i + '" style="font-weight:bold; font-size:16px;">' + i + '</a> ';
				else
					pagination += '<span style="font-weight:bold; font-size:16px;">' + i + '</span> ';
			}
			if(page < last)
				pagination += '<a href="javascript:void(0);" onClick="changePurchasePage(' + (page + 1) + ');" title="Results page ' + (page + 1) + '" style="font-weight:bold; font-size:16px; margin-left:10px;">next &rsaquo;&rsaquo;</a>';
			else
				pagination += '<span style="font-weight:bold; font-size:16px; margin-left:10px;">next &rsaquo;&rsaquo;</span> ';
		}
		else
		{
			if(page > 1)
				pagination += '<a href="javascript:void(0);" onClick="changePurchasePage(' + (page - 1) + ');" title="Results page ' + (page - 1) + '" style="font-weight:bold; font-size:16px; margin-right:10px;">&lsaquo;&lsaquo; previous</a> ';
			else
				pagination += '<span style="font-weight:bold; font-size:16px; margin-right:10px;">&lsaquo;&lsaquo; previous</span> ';
			if(page != 1)
				pagination += '<a href="javascript:void(0);" onClick="changePurchasePage(1);" title="Results page 1" style="font-weight:bold; font-size:16px;">1</a> ';
			else
				pagination += '<span style="font-weight:bold; font-size:16px;">1</span> ';
			if(page > 5)
				pagination += ' ... ';
			for(i = Math.max(2, page-3); i <= Math.min(last-1, page+3); i ++)
			{
				if(i != page)
					pagination += '<a href="javascript:void(0);" onClick="changePurchasePage(' + i + ');" title="Results page ' + i + '" style="font-weight:bold; font-size:16px;">' + i + '</a> ';
				else
					pagination += '<span style="font-weight:bold; font-size:16px;">' + i + '</span> ';
			}
			if(page < last-4)
				pagination += '... ';
			if(page != last)
				pagination += '<a href="javascript:void(0);" onClick="changePurchasePage(' + last + ');" title="Results page ' + last + '" style="font-weight:bold; font-size:16px;">' + last + '</a> ';
			else
				pagination += '<span style="font-weight:bold; font-size:16px;">' + last + '</span> ';
			if(page < last)
				pagination += '<a href="javascript:void(0);" onClick="changePurchasePage(' + (page + 1) + ');" title="Results page ' + (page + 1) + '" style="font-weight:bold; font-size:16px; margin-left:10px;">next &rsaquo;&rsaquo;</a>';
			else
				pagination += '<span style="font-weight:bold; font-size:16px; margin-left:10px;">next &rsaquo;&rsaquo;</span> ';
		}
		pagination += "</center>";
		friends += pagination;
		
		document.getElementById("mainBody").innerHTML = friends;
		document.getElementById("additionalSearchOptions").style.opacity = 0.25;
	}
}

/******************************************************************************************************************************************************************************
																																							Function: fillBrowsePageNonFriends()
******************************************************************************************************************************************************************************/
function fillBrowsePageNonFriends(dataResponse, url, error)
{
	debug("Request returned: " + dataResponse.text);
	if(error)
		secureRequest(LAST_REQUEST_DATA, LAST_REQUEST_CALLBACK);
	else
	{
		var updateSearchButton = document.getElementById("updateSearchButton");
		updateSearchButton.value = "Update Search";
		updateSearchButton.disabled = false;
		document.location.hash = "#purchaseTop";
		var data = dataResponse.text.evalJSON();
	
		if(SEARCH.SEX == 'MALE')
			var sex = 'Male';
		else if(SEARCH.SEX == 'FEMALE')
			var sex = 'Female';
		else
			var sex = 'Both';
			
		if(SEARCH.VALUE == "LOW")
			var value = "Low to High";
		else if(SEARCH.VALUE == "HIGH")
			var value = "High to Low";
		else
			var value = "Any";
			
		if(SEARCH.AGE == 'ALL')
			var age = 'All';
		else
			var age = SEARCH.AGE;
		
		if(SEARCH.ACTIVITY == 'LAST_ACTIVE')
			var activity = 'Last Active';
		else
			var activity = 'Any';
			
		if(SEARCH.AFFORDABLE == 'YES')
			var affordable = 'Yes';
		else
			var affordable = 'No';
		
		var friends = '<a name="purchaseTop"></a>\
		<input type="button" value="MySpace Friends" onClick="changeSearchType(\'friends\');" id="searchTypeFriends" style="background:#3B5998; border:solid 2px #CCCCCC; font-size:16px; _font-size:14px; font-weight:bold; padding:3px; color:#FFFFFF; margin-left:10px;"/>\
		<input type="button" value="All Users" onClick="changeSearchType(\'all\');" id="searchTypeAll" style="' + ((SEARCH.TYPE == 'ALL') ? 'color:#3B5998; background:#FFFFFF; ' : 'color:#FFFFFF; background:#3B5998; ') + ' border:solid 2px #CCCCCC; font-size:16px; _font-size:14px; font-weight:bold; padding:3px; margin-left:10px;"' + ((SEARCH.TYPE == 'ALL') ? ' disabled' : '') + '/>\
		<input type="button" value="Online Users" onClick="changeSearchType(\'online\');" id="searchTypeOnline" style="' + ((SEARCH.TYPE == 'ONLINE') ? 'color:#3B5998; background:#FFFFFF; ' : 'color:#FFFFFF; background:#3B5998; ') + ' border:solid 2px #CCCCCC; font-size:16px; _font-size:14px; font-weight:bold; padding:3px; margin-left:10px;"/>\
		<input type="button" value="Active Users" onClick="changeSearchType(\'active\');" id="searchTypeActive" style="' + ((SEARCH.TYPE == 'ACTIVE') ? 'color:#3B5998; background:#FFFFFF; ' : 'color:#FFFFFF; background:#3B5998; ') + ' border:solid 2px #CCCCCC; font-size:16px; _font-size:14px; font-weight:bold; padding:3px; margin-left:10px;"/>\
		<input type="button" value="New Users" onClick="changeSearchType(\'new\');" id="searchTypeNew" style="' + ((SEARCH.TYPE == 'NEW') ? 'color:#3B5998; background:#FFFFFF; ' : 'color:#FFFFFF; background:#3B5998; ') + ' border:solid 2px #CCCCCC; font-size:16px; _font-size:14px; font-weight:bold; padding:3px; margin-left:10px;"/>\
		<input type="button" value="Tracked Users" onClick="changeSearchType(\'tracked\');" id="searchTypeTracked" style="' + ((SEARCH.TYPE == 'TRACKED') ? 'color:#3B5998; background:#FFFFFF; ' : 'color:#FFFFFF; background:#3B5998; ') + ' border:solid 2px #CCCCCC; font-size:16px; _font-size:14px; font-weight:bold; padding:3px; margin-left:10px;"/>\
		<div style="margin-top:8px; margin-bottom:8px; margin-left:50px; font-size:16px; _font-size:14px; font-weight:bold;" id="additionalSearchOptions" onMouseOver="focusSearchOptions();" onMouseOut="blurSearchOptions();">\
		Sex: <input type="button" value="' + sex + '" onClick="changeSexSearch();" id="sexSearchButton" style="background:#3B5998; border:solid 2px #CCCCCC; font-size:12px; font-weight:bold; padding:3px; color:#FFFFFF; margin-right:10px;"/>\
		Value: <input type="button" value="' + value + '" onClick="changeValueSearch();" id="valueSearchButton" style="background:#3B5998; border:solid 2px #CCCCCC; font-size:12px; font-weight:bold; padding:3px; color:#FFFFFF; margin-right:10px;"/>\
		Age: <input type="button" value="' + age + '" onClick="changeAgeSearch();" id="ageSearchButton" style="background:#3B5998; border:solid 2px #CCCCCC; font-size:12px; font-weight:bold; padding:3px; color:#FFFFFF; margin-right:10px;"/>\
		Activity: <input type="button" value="' + activity + '" onClick="changeActivitySearch();" id="activitySearchButton" style="background:#3B5998; border:solid 2px #CCCCCC; font-size:12px; font-weight:bold; padding:3px; color:#FFFFFF; margin-right:10px;"/>\
		Only Show Affordable Stock: <input type="button" value="' + affordable + '" onClick="changeAffordableSearch();" id="affordableSearchButton" style="background:#3B5998; border:solid 2px #CCCCCC; font-size:12px; font-weight:bold; padding:3px; color:#FFFFFF; margin-right:10px;"/>\
		<div style="text-align:right; margin-right:50px; margin-top:5px;"><input type="button" value="Update Search" onClick="updateSearch(); this.blur();" id="updateSearchButton" style="background:#3B5998; border:solid 2px #CCCCCC; font-size:24px; font-weight:bold; padding:3px; color:#FFFFFF;"/></div>\
		</div>\
		<center>';
		if(data.friends != null)
		{
			for(i = 0; i < data.friends.length; i ++)
			{
				if(data.friends[i].cash != null)
					var cash = data.friends[i].cash;
				else
					var cash = '5,000,000';
				
				if(data.friends[i].value != null)
					var value = data.friends[i].value;
				else
					var value = '1,000,000';
				
				if(data.friends[i].lastactive != null)
					var lastActive = data.friends[i].lastactive;
				else
					var lastActive = 'Never';
				
				if(data.friends[i].nickname != null)
					var nickname = '<span style="color:#FF0000;">"' + data.friends[i].nickname + '"</span><br/>';
				else
					var nickname = '';
					
				friends += '<a name="' + data.friends[i].userid + '_top"></a><div style="font-size:16px; border:solid 1px #CCCCCC; padding:10px; margin-left:auto; margin-right:auto; margin-top:10px; width:650px; _width:750px; height:120px; _height:130px; overflow:hidden; text-align:left; background:#FFFFFF;" id="' + data.friends[i].userid + '_friend"><div style="float:right; height:105px; _height:110px; width:225px; overflow:hidden;"><iframe id="chartFrame" src="http://gpujfwaa.joyent.us/myspace/fs/smallHourlyChart.php?id=' + data.friends[i].userid + '&days=7" frameborder="0" height="115" width="225" scrolling="no" marginwidth="0" marginheight="0"></iframe></div><div style="width:90px; height:100px; overflow:hidden; float:left; margin-right:10px;"><a href="javascript:void(0);" onClick="renderPage(PAGE.PROFILE, \'' + data.friends[i].userid + '\');" title="' + data.friends[i].name + '" id="' + data.friends[i].userid + '_name">' + data.friends[i].imageuri + '</a></div><div style="font-size:14px; font-weight:bold; width:400px; _float:left;"><a href="javascript:void(0);" onClick="renderPage(PAGE.PROFILE, ' + data.friends[i].userid + '); this.blur();" title="' + data.friends[i].name + '"><span style="font-size:18px; font-weight:bold;">' + data.friends[i].name + '</span></a><br/><span style="color:#666666;">Trading For:</span> $<span id="' + data.friends[i].userid + '_value">' + addCommas(value) + '</span><br/><span style="color:#666666;">Cash:</span> $<span id="' + data.friends[i].userid + '_cash">' + addCommas(cash) + '</span><br/><span style="color:#666666;">Splits:</span> <span id="' + data.friends[i].userid + '_splits">' + addCommas(data.friends[i].splits) + '</span><br/><span style="color:#666666;">Last Online:</span> ' + lastActive + '</div><br clear="all"/><div id="' + data.friends[i].userid + '_extension" style="display:none;"></div></div>';
			}
			friends += '</center>';
		
			queuePage("changePurchasePage('" + FRIEND_PAGE + "')");
	
			var last = Math.ceil(data.friend_count / 20);
			var page = FRIEND_PAGE;
			var pagination = '<div style="font-size:14px; margin-left:140px; margin-top:5px;">Displaying ' + ((page-1)*20+1) + " - " + Math.min(((page-1)*20+20),data.friend_count) + " of " + data.friend_count + " users</div><center>";
			if(last <= 6)
			{
				if(page > 1)
					pagination += '<a href="javascript:void(0);" onClick="changeNonFriendPurchasePage(' + (page - 1) + ');" title="Results page ' + (page - 1) + '" style="font-weight:bold; font-size:16px; margin-right:10px;">&lsaquo;&lsaquo; previous</a> ';
				else
					pagination += '<span style="font-weight:bold; font-size:16px; margin-right:10px;">&lsaquo;&lsaquo; previous</span> ';
				for(i = 1; i <= last; i ++)
				{
					if(i != page)
						pagination += '<a href="javascript:void(0);" onClick="changeNonFriendPurchasePage(' + i + ');" title="Results page ' + i + '" style="font-weight:bold; font-size:16px;">' + i + '</a> ';
					else
						pagination += '<span style="font-weight:bold; font-size:16px;">' + i + '</span> ';
				}
				if(page < last)
					pagination += '<a href="javascript:void(0);" onClick="changeNonFriendPurchasePage(' + (page + 1) + ');" title="Blocked users page ' + (page + 1) + '" style="font-weight:bold; font-size:16px; margin-left:10px;">next &rsaquo;&rsaquo;</a>';
				else
					pagination += '<span style="font-weight:bold; font-size:16px; margin-left:10px;">next &rsaquo;&rsaquo;</span> ';
			}
			else
			{
				if(page > 1)
					pagination += '<a href="javascript:void(0);" onClick="changeNonFriendPurchasePage(' + (page - 1) + ');" title="Results page ' + (page - 1) + '" style="font-weight:bold; font-size:16px; margin-right:10px;">&lsaquo;&lsaquo; previous</a> ';
				else
					pagination += '<span style="font-weight:bold; font-size:16px; margin-right:10px;">&lsaquo;&lsaquo; previous</span> ';
				if(page != 1)
					pagination += '<a href="javascript:void(0);" onClick="changeNonFriendPurchasePage(1);" title="Results page 1" style="font-weight:bold; font-size:16px;">1</a> ';
				else
					pagination += '<span style="font-weight:bold; font-size:16px;">1</span> ';
				if(page > 5)
					pagination += ' ... ';
				for(i = Math.max(2, page-3); i <= Math.min(last-1, page+3); i ++)
				{
					if(i != page)
						pagination += '<a href="javascript:void(0);" onClick="changeNonFriendPurchasePage(' + i + ');" title="Results page ' + i + '" style="font-weight:bold; font-size:16px;">' + i + '</a> ';
					else
						pagination += '<span style="font-weight:bold; font-size:16px;">' + i + '</span> ';
				}
				if(page < last-4)
					pagination += '... ';
				if(page != last)
					pagination += '<a href="javascript:void(0);" onClick="changeNonFriendPurchasePage(' + last + ');" title="Results page ' + last + '" style="font-weight:bold; font-size:16px;">' + last + '</a> ';
				else
					pagination += '<span style="font-weight:bold; font-size:16px;">' + last + '</span> ';
				if(page < last)
					pagination += '<a href="javascript:void(0);" onClick="changeNonFriendPurchasePage(' + (page + 1) + ');" title="Results page ' + (page + 1) + '" style="font-weight:bold; font-size:16px; margin-left:10px;">next &rsaquo;&rsaquo;</a>';
				else
					pagination += '<span style="font-weight:bold; font-size:16px; margin-left:10px;">next &rsaquo;&rsaquo;</span> ';
			}
			pagination += "</center>";
			friends += pagination;
		}
		else
			friends += '<div style="font-size:22px; font-weight:bold; text-align:left; margin-left:10px; margin-left:15px;">Your search returned 0 results.</div>';
		
		document.getElementById("mainBody").innerHTML = friends;
		document.getElementById("additionalSearchOptions").style.opacity = 0.25;
	}
}

/******************************************************************************************************************************************************************************
																																						Function: changeNonFriendPurchasePage()
******************************************************************************************************************************************************************************/
function changeNonFriendPurchasePage(page)
{
	FRIEND_PAGE = page;
	var data = {action: "listUsers", page: page, type:SEARCH.TYPE, sex:SEARCH.SEX, value:SEARCH.VALUE, age:SEARCH.AGE, activity:SEARCH.ACTIVITY, affordable:SEARCH.AFFORDABLE};
	secureRequest(data, fillBrowsePageNonFriends);
}

/******************************************************************************************************************************************************************************
																																							Function: changePurchasePage()
******************************************************************************************************************************************************************************/
function changePurchasePage(page)
{
	FRIEND_PAGE = page;
	var data = {action: "listFriends", page: page};
	secureRequest(data, fillBrowsePage);
}

/******************************************************************************************************************************************************************************
																																							Function: viewFriendWithName()
******************************************************************************************************************************************************************************/
function viewFriendWithName(id, name, image)
{
	var data = {action: "getProfile", id: id, name: unescape(name), image: image};
	secureRequest(data, fillProfile);
}

/******************************************************************************************************************************************************************************
																																							Function: focusSearchOptions()
******************************************************************************************************************************************************************************/
function focusSearchOptions()
{
	clearTimeout(TIMER);
	document.getElementById("additionalSearchOptions").style.opacity = 1.0;
}

/******************************************************************************************************************************************************************************
																																							Function: blurSearchOptions()
******************************************************************************************************************************************************************************/
function blurSearchOptions()
{
	TIMER = setTimeout("doBlurSearchOptions()", 3000);
}

/******************************************************************************************************************************************************************************
																																							Function: doBlurSearchOptions()
******************************************************************************************************************************************************************************/
function doBlurSearchOptions()
{
	document.getElementById("additionalSearchOptions").style.opacity = 0.25;
}

/******************************************************************************************************************************************************************************
																																							Function: updateSearch()
******************************************************************************************************************************************************************************/
function updateSearch()
{
	var updateSearchButton = document.getElementById("updateSearchButton");
	updateSearchButton.value = "Updating Search...";
	updateSearchButton.disabled = true;
	var data = {action: "listUsers", page: 1, type:SEARCH.TYPE, sex:SEARCH.SEX, value:SEARCH.VALUE, age:SEARCH.AGE, activity:SEARCH.ACTIVITY, affordable:SEARCH.AFFORDABLE};
	secureRequest(data, fillBrowsePageNonFriends);
}

/******************************************************************************************************************************************************************************
																																							Function: changeSearchType()
******************************************************************************************************************************************************************************/
function changeSearchType(type)
{
	var searchTypeFriends = document.getElementById("searchTypeFriends");
	var searchTypeOnline = document.getElementById("searchTypeOnline");
	var searchTypeActive = document.getElementById("searchTypeActive");
	var searchTypeTracked = document.getElementById("searchTypeTracked");
	var searchTypeNew = document.getElementById("searchTypeNew");
	var searchTypeAll = document.getElementById("searchTypeAll");
	var additionalSearchOptions = document.getElementById("additionalSearchOptions");
	
	searchTypeFriends.disabled = false;
	searchTypeFriends.style.color = "#FFFFFF";
	searchTypeFriends.style.background = "#3B5998";
	searchTypeOnline.disabled = false;
	searchTypeOnline.style.color = "#FFFFFF";
	searchTypeOnline.style.background = "#3B5998";
	searchTypeActive.disabled = false;
	searchTypeActive.style.color = "#FFFFFF";
	searchTypeActive.style.background = "#3B5998";
	searchTypeTracked.disabled = false;
	searchTypeTracked.style.color = "#FFFFFF";
	searchTypeTracked.style.background = "#3B5998";
	searchTypeNew.disabled = false;
	searchTypeNew.style.color = "#FFFFFF";
	searchTypeNew.style.background = "#3B5998";
	searchTypeAll.disabled = false;
	searchTypeAll.style.color = "#FFFFFF";
	searchTypeAll.style.background = "#3B5998";
	
	switch(type)
	{
		case "friends":
			SEARCH.TYPE = "FRIENDS";
			searchTypeFriends.disabled = true;
			searchTypeFriends.style.color = "#3B5998";
			searchTypeFriends.style.background = "#FFFFFF";
			Effect.Fade("additionalSearchOptions", { duration : 0.3 } );
			break;
		case "online":
			SEARCH.TYPE = "ONLINE";
			searchTypeOnline.disabled = true;
			searchTypeOnline.style.color = "#3B5998";
			searchTypeOnline.style.background = "#FFFFFF";
			Effect.Appear("additionalSearchOptions", { duration : 0.3 } );
			break;
		case "active":
			SEARCH.TYPE = "ACTIVE";
			searchTypeActive.disabled = true;
			searchTypeActive.style.color = "#3B5998";
			searchTypeActive.style.background = "#FFFFFF";
			Effect.Appear("additionalSearchOptions", { duration : 0.3 } );
			break;
		case "tracked":
			SEARCH.TYPE = "TRACKED";
			searchTypeTracked.disabled = true;
			searchTypeTracked.style.color = "#3B5998";
			searchTypeTracked.style.background = "#FFFFFF";
			Effect.Appear("additionalSearchOptions", { duration : 0.3 } );
			break;
		case "new":
			SEARCH.TYPE = "NEW";
			searchTypeNew.disabled = true;
			searchTypeNew.style.color = "#3B5998";
			searchTypeNew.style.background = "#FFFFFF";
			Effect.Appear("additionalSearchOptions", { duration : 0.3 } );
			break;
		case "all":
			SEARCH.TYPE = "ALL";
			searchTypeAll.disabled = true;
			searchTypeAll.style.color = "#3B5998";
			searchTypeAll.style.background = "#FFFFFF";
			Effect.Appear("additionalSearchOptions", { duration : 0.3 } );
			break;
		default:
			SEARCH.TYPE = "FRIENDS";
			searchTypeFriends.disabled = true;
			searchTypeFriends.style.color = "#3B5998";
			searchTypeFriends.style.background = "#FFFFFF";
			Effect.Fade("additionalSearchOptions", { duration : 0.3 } );
			break;
	}
	searchTypeFriends.blur();
	searchTypeOnline.blur();
	searchTypeActive.blur();
	searchTypeTracked.blur();
	searchTypeNew.blur();
	searchTypeAll.blur();
}

/******************************************************************************************************************************************************************************
																																							Function: changeActivitySearch()
******************************************************************************************************************************************************************************/
function changeActivitySearch()
{
	var activitySearchButton = document.getElementById("activitySearchButton");
	var curActivity = activitySearchButton.value;
	switch(curActivity)
	{
		case "Any":
			SEARCH.ACTIVITY = "LAST_ACTIVE";
			activitySearchButton.value = "Last Active";
			break;
		default:
			SEARCH.ACTIVITY = "ANY";
			activitySearchButton.value = "Any";
			break;
	}
	activitySearchButton.blur();
}

/******************************************************************************************************************************************************************************
																																							Function: changeAffordableSearch()
******************************************************************************************************************************************************************************/
function changeAffordableSearch()
{
	var affordableSearchButton = document.getElementById("affordableSearchButton");
	var curAfford = affordableSearchButton.value;
	switch(curAfford)
	{
		case "No":
			SEARCH.AFFORDABLE = "YES";
			affordableSearchButton.value = "Yes";
			break;
		default:
			SEARCH.AFFORDABLE = "NO";
			affordableSearchButton.value = "No";
			break;
	}
	affordableSearchButton.blur();
}

/******************************************************************************************************************************************************************************
																																							Function: changeAgeSearch()
******************************************************************************************************************************************************************************/
function changeAgeSearch()
{
	var ageSearchButton = document.getElementById("ageSearchButton");
	var curAge = ageSearchButton.value;
	switch(curAge)
	{
		case "All":
			SEARCH.AGE = "18-20";
			ageSearchButton.value = "18-20";
			break;
		case "18-20":
			SEARCH.AGE = "21-25";
			ageSearchButton.value = "21-25";
			break;
		case "21-25":
			SEARCH.AGE = "26-30";
			ageSearchButton.value = "26-30";
			break;
		case "26-30":
			SEARCH.AGE = "30-39";
			ageSearchButton.value = "30-39";
			break;
		case "30-39":
			SEARCH.AGE = "40-49";
			ageSearchButton.value = "40-49";
			break;
		case "40-49":
			SEARCH.AGE = "50-59";
			ageSearchButton.value = "50-59";
			break;
		case "50-59":
			SEARCH.AGE = "60+";
			ageSearchButton.value = "60+";
			break;
		default:
			SEARCH.AGE = "ALL";
			ageSearchButton.value = "All";
			break;
	}
	ageSearchButton.blur();
}

/******************************************************************************************************************************************************************************
																																							Function: changeValueSearch()
******************************************************************************************************************************************************************************/
function changeValueSearch()
{
	var valueSearchButton = document.getElementById("valueSearchButton");
	var curValue = valueSearchButton.value;
	switch(curValue)
	{
		case "Any":
			SEARCH.VALUE = "HIGH";
			valueSearchButton.value = "High to Low";
			break;
		case "High to Low":
			SEARCH.VALUE = "LOW";
			valueSearchButton.value = "Low to High";
			break;
		default:
			SEARCH.VALUE = "ANY";
			valueSearchButton.value = "Any";
			break;
	}
	valueSearchButton.blur();
}

/******************************************************************************************************************************************************************************
																																							Function: changeSexSearch()
******************************************************************************************************************************************************************************/
function changeSexSearch()
{
	var sexSearchButton = document.getElementById("sexSearchButton");
	var curSex = sexSearchButton.value;
	switch(curSex)
	{
		case "Both":
			SEARCH.SEX = "MALE";
			sexSearchButton.value = "Male";
			break;
		case "Male":
			SEARCH.SEX = "FEMALE";
			sexSearchButton.value = "Female";
			break;
		default:
			SEARCH.SEX = "BOTH";
			sexSearchButton.value = "Both";
			break;
	}
	sexSearchButton.blur();
}

/******************************************************************************************************************************************************************************
																																							Function: changeChart()
******************************************************************************************************************************************************************************/
function changeChart(value, id)
{
	var chartFrame = document.getElementById("chartFrame");
	if(value == "24h")
		chartFrame.src = "http://gpujfwaa.joyent.us/myspace/fs/hourlyChart.php?id=" + id;
	else if(value == "7d")
		chartFrame.src = "http://gpujfwaa.joyent.us/myspace/fs/dailyChart.php?id=" + id + "&days=7";
	else if(value == "31d")
		chartFrame.src = "http://gpujfwaa.joyent.us/myspace/fs/dailyChart.php?id=" + id + "&days=31";
}

/******************************************************************************************************************************************************************************
																																							Function: showSellStock()
******************************************************************************************************************************************************************************/
function showSellStockBlocked(id, name)
{
	document.getElementById(id + "_purchase").innerHTML = 'Are you sure you want to sell 1 share of ' + unescape(name) + '?<br/><input type="button" value="Sell" id="' + id + '_continuePurchaseButton" onClick="sellStock(' + id + ');" style="background:#3B5998; border:solid 2px #CCCCCC; margin-top:2px; font-size:12px; font-weight:bold; padding:3px; color:#FFFFFF;"/><input type="button" value="Cancel" id="' + id + '_continuePurchaseButton" onClick="closeSellStock(' + id + ');" style="background:#3B5998; border:solid 2px #CCCCCC; margin-top:2px; margin-left:6px; font-size:12px; font-weight:bold; padding:3px; color:#FFFFFF;"/>';
	Effect.Fade(id + "_purchaseButton", { duration: 0.1} );
	Effect.Appear(id + "_purchase", { queue: 'end', duration: 0.5 } );
}

/******************************************************************************************************************************************************************************
																																							Function: showSellStock()
******************************************************************************************************************************************************************************/
function showSellStock(id, name, value, oldValue)
{
	Effect.Fade(id + "_boostButton", { duration : 0.3} );
	if(value < oldValue)
		var valDiff = 'loss of <span style="color:#CC0000;">$' + addCommas(value - oldValue) + '</span>';
	else
		var valDiff = 'gain of <span style="color:#00CC00;">$' + addCommas(value - oldValue) + '</span>';
	document.getElementById(id + "_purchase").innerHTML = 'Are you sure you want to sell 1 share of ' + unescape(name) + ' for <span style="color:#00CC00;">$' + addCommas(value) + '</span> for a ' + valDiff + '.<br/><input type="button" value="Sell" id="' + id + '_continuePurchaseButton" onClick="sellStock(' + id + ');" style="background:#3B5998; border:solid 2px #CCCCCC; margin-top:2px; font-size:12px; font-weight:bold; padding:3px; color:#FFFFFF;"/><input type="button" value="Cancel" id="' + id + '_continuePurchaseButton" onClick="closeSellStock(' + id + ');" style="background:#3B5998; border:solid 2px #CCCCCC; margin-top:2px; margin-left:6px; font-size:12px; font-weight:bold; padding:3px; color:#FFFFFF;"/>';
	Effect.Fade(id + "_purchaseButton", { duration: 0.1} );
	Effect.Fade(id + "_boostButton", { duration: 0.1} );
	Effect.Appear(id + "_purchase", { queue: 'end', duration: 0.5 } );
}

/******************************************************************************************************************************************************************************
																																							Function: sellStock()
******************************************************************************************************************************************************************************/
function sellStock(id)
{
	var purchaseButton = document.getElementById(id + "_continuePurchaseButton");
	purchaseButton.disabled = true;
	purchaseButton.style.color = "#666666";
	var data = {action: "sellStock", id: id};
	secureRequest(data, stockSold);
}

/******************************************************************************************************************************************************************************
																																							Function: stockSold()
******************************************************************************************************************************************************************************/
function stockSold(dataResponse, url, error)
{
	debug("Request returned: " + dataResponse.text);
	if(error)
		secureRequest(LAST_REQUEST_DATA, LAST_REQUEST_CALLBACK);
	else
	{
		var data = dataResponse.text.evalJSON();
		if(data.success == "true")
		{
			updateCashTokens(data.cash, OWNER_TOKENS);
			renderPage(PAGE.PROFILE, data.id);
		}
		else
		{
			document.getElementById(data.id + "_purchase").innerHTML = data.message;
			setTimeout("closeSellStock(" + data.id + ")", 5000);
		}
	}
}

/******************************************************************************************************************************************************************************
																																							Function: stockPurchased()
******************************************************************************************************************************************************************************/
function stockPurchased(dataResponse, url, error)
{
	debug("Request returned: " + dataResponse.text);
	if(error)
		secureRequest(LAST_REQUEST_DATA, LAST_REQUEST_CALLBACK);
	else
	{
		var data = dataResponse.text.evalJSON();
		
		if(data.success == "true")
		{
			var param = {id: data.id, purchased: 'true'};
			updateCashTokens(data.cash, OWNER_TOKENS);
			renderPage(PAGE.PROFILE, param);
		}
		else
		{
			document.getElementById(data.id + "_purchase").innerHTML = data.message;
			setTimeout("closePurchaseStock(" + data.id + ")", 5000);
		}
	}
}

/******************************************************************************************************************************************************************************
																																							Function: purchaseStock()
******************************************************************************************************************************************************************************/
function purchaseStock(id)
{
	var purchaseButton = document.getElementById(id + "_continuePurchaseButton");
	purchaseButton.disabled = true;
	purchaseButton.style.color = "#666666";
	var data = {action: "purchaseStock", id: id};
	secureRequest(data, stockPurchased);
}

/******************************************************************************************************************************************************************************
																																							Function: closeSellStock()
******************************************************************************************************************************************************************************/
function closeSellStock(id)
{
	Effect.Fade(id + "_purchase", { duration: 0.1} );
	Effect.Appear(id + "_purchaseButton", { queue: 'end', duration: 0.5 } );
	Effect.Appear(id + "_boostButton", { duration : 0.5} );
}

/******************************************************************************************************************************************************************************
																																							Function: closePurchaseStock()
******************************************************************************************************************************************************************************/
function closePurchaseStock(id)
{
	Effect.Fade(id + "_purchase", { duration: 0.1} );
	Effect.Appear(id + "_purchaseButton", { queue: 'end', duration: 0.5 } );
}

/******************************************************************************************************************************************************************************
																																							Function: showPurchaseStock()
******************************************************************************************************************************************************************************/
function showPurchaseStock(id, name, value)
{
	if(OWNER_CASH >= value)
		document.getElementById(id + "_purchase").innerHTML = 'Are you sure you want to purchase a stock share in ' + unescape(name) + ' for <span style="color:#990000;">$' + addCommas(value) + '</span>? You have <span style="color:#009900;">$' + addCommas(OWNER_CASH) + '</span>.<br/><input type="button" value="Purchase" id="' + id + '_continuePurchaseButton" onClick="purchaseStock(' + id + ');" style="background:#3B5998; border:solid 2px #CCCCCC; margin-top:2px; font-size:12px; font-weight:bold; padding:3px; color:#FFFFFF;"/><input type="button" value="Cancel" id="' + id + '_continuePurchaseButton" onClick="closePurchaseStock(' + id + ');" style="background:#3B5998; border:solid 2px #CCCCCC; margin-top:2px; margin-left:6px; font-size:12px; font-weight:bold; padding:3px; color:#FFFFFF;"/>';
	else
		document.getElementById(id + "_purchase").innerHTML = 'Purchasing a stock share in ' + unescape(name) + ' would cost <span style="color:#990000;">$' + addCommas(value) + '</span> but you only have <span style="color:#009900;">$' + addCommas(OWNER_CASH) + '</span>. <a href="javascript:void(0);" onClick="renderPage(PAGE.BONUS); this.blur();" title="Earn bonus Friends Stock dollars">Get another $' + addCommas(value - OWNER_CASH) + ' now!</a><br/><input type="button" value="Purchase" id="' + id + '_continuePurchaseButton" style="background:#3B5998; border:solid 2px #CCCCCC; margin-top:2px; font-size:12px; font-weight:bold; padding:3px; color:#999999;" disabled/><input type="button" value="Cancel" id="' + id + '_continuePurchaseButton" onClick="closePurchaseStock(' + id + ');" style="background:#3B5998; border:solid 2px #CCCCCC; margin-top:2px; margin-left:6px; font-size:12px; font-weight:bold; padding:3px; color:#FFFFFF;"/>';
	Effect.Fade(id + "_purchaseButton", { duration: 0.1} );
	Effect.Appear(id + "_purchase", { queue: 'end', duration: 0.5 } );
	document.getElementById(id + "_purchase").style.marginTop = "20px";
}

/******************************************************************************************************************************************************************************
																																							Function: sessionIdRetrieved()
******************************************************************************************************************************************************************************/
function sessionIdRetrieved(dataResponse, url, error)
{
	debug("Request returned: " + dataResponse.text);
	if(error)
		secureRequest(LAST_REQUEST_DATA, LAST_REQUEST_CALLBACK);
	else
	{
		SESSION_ID = dataResponse.text;
		
		var req = opensocial.newDataRequest();
		var params = {};
		params[opensocial.DataRequest.PeopleRequestFields.FILTER] = opensocial.DataRequest.FilterType.HAS_APP;
		params[opensocial.DataRequest.PeopleRequestFields.FIRST] = CURRENT_POSITION;
		params[opensocial.DataRequest.PeopleRequestFields.MAX] = 40;
		req.add(req.newFetchPeopleRequest(opensocial.DataRequest.Group.VIEWER_FRIENDS, params));
		req.send(installedFriends);
	}
}

/******************************************************************************************************************************************************************************
																																							Function: fillFriends()
******************************************************************************************************************************************************************************/
function fillFriends(dataResponse)
{
	var friendsDataGroup = dataResponse.get(opensocial.DataRequest.Group.VIEWER_FRIENDS);
	var friendsData = friendsDataGroup.getData();
	var friendsSize = friendsData.getTotalSize();;
	var friends = '<div style="padding:5px;"><table cellspacing="9" cellpadding="0" style="text-align:center;"><tr>';
	var count = 0;
	friendsData.each(
		function(friendData)
		{
			var friendId = friendData.getField(opensocial.Person.Field.ID);
			var friendName = friendData.getField(opensocial.Person.Field.NAME);
			var friendPic = friendData.getField(opensocial.Person.Field.THUMBNAIL_URL);
			friends += '<td style="border:solid 1px #CCCCCC; padding:8px; background:#FFFFFF; vertical-align:top; text-align:center; width:90px; cursor:pointer; overflow:hidden;" onMouseOver="this.style.background=\'#DD0207\';" onMouseOut="this.style.background=\'#FFFFFF\';" onClick="renderPage(PAGE.PROFILE, \'' + friendId + '\');" id="' + friendId + '_td"><div style="width:90px; height:76px; overflow:hidden; text-align:center;"><img src="' + friendPic + '" width="90" border="0" title="' + friendName + '"/></div><div style="font-size:10px; width:90px; overflow:hidden;">' + friendName + '</div></td>';
			if(count % 8 == 7)
				friends += '</tr><tr>';
			count ++;
		}
	);
	friends += '</tr></table>';
	var last = Math.ceil(friendsSize / 40);
	var page = FRIEND_PAGE;
	var pagination = '<div style="font-size:14px;">Displaying ' + ((page-1)*40+1) + " - " + Math.min(((page-1)*40+40),friendsSize) + " of " + friendsSize + " friends</div><center>";
	if(last <= 6)
	{
		for(i = 1; i <= last; i ++)
		{
			if(i != page)
				pagination += '<a href="javascript:void(0);" onClick="relationshipPage(' + i + ');" title="Friends page ' + i + '" style="font-weight:bold; font-size:14px;">' + i + '</a> ';
			else
				pagination += '<span style="font-weight:bold; font-size:14px;">' + i + '</span> ';
		}
	}
	else
	{
		if(page != 1)
			pagination += '<a href="javascript:void(0);" onClick="relationshipPage(1);" title="Friends page 1" style="font-weight:bold; font-size:14px;">1</a> ';
		else
			pagination += '<span style="font-weight:bold; font-size:14px;">1</span> ';
		if(page > 5)
			pagination += ' ... ';
		for(i = Math.max(2, page-3); i <= Math.min(last-1, page+3); i ++)
		{
			if(i != page)
				pagination += '<a href="javascript:void(0);" onClick="relationshipPage(' + i + ');" title="Friends page ' + i + '" style="font-weight:bold; font-size:14px;">' + i + '</a> ';
			else
				pagination += '<span style="font-weight:bold; font-size:14px;">' + i + '</span> ';
		}
		if(page < last-4)
			pagination += '... ';
		if(page != last)
			pagination += '<a href="javascript:void(0);" onClick="relationshipPage(' + last + ');" title="Friends page ' + last + '" style="font-weight:bold; font-size:14px;">' + last + '</a> ';
		else
			pagination += '<span style="font-weight:bold; font-size:14px;">' + last + '</span> ';
	}
	pagination += "</center></div>";
	friends += pagination;
	document.getElementById("mainBody").innerHTML = friends;
}

/******************************************************************************************************************************************************************************
																																							Function: installedFriends()
******************************************************************************************************************************************************************************/
function installedFriends(dataResponse)
{
	var friendsDataGroup = dataResponse.get(opensocial.DataRequest.Group.VIEWER_FRIENDS);
	var friendsData = friendsDataGroup.getData();
	var ids = '';
	friendsData.each(
		function(friendData)
		{
			var friendId = friendData.getField(opensocial.Person.Field.ID);
			if(CURRENT_POSITION != 1)
				INSTALLED_FRIENDS += ',';
			INSTALLED_FRIENDS += friendId;
			CURRENT_POSITION += 1;
		}
	);
	if(CURRENT_POSITION >= friendsData.getTotalSize() || CURRENT_POSITION >= 500)
	{
		var data = {action: "updateFriends", friendsList: INSTALLED_FRIENDS};
		secureRequest(data, friendsUpdated);
	}
	else
	{
		var req = opensocial.newDataRequest();
		var params = {};
		params[opensocial.DataRequest.PeopleRequestFields.FILTER] = opensocial.DataRequest.FilterType.HAS_APP;
		params[opensocial.DataRequest.PeopleRequestFields.FIRST] = CURRENT_POSITION;
		params[opensocial.DataRequest.PeopleRequestFields.MAX] = 40;
		req.add(req.newFetchPeopleRequest(opensocial.DataRequest.Group.VIEWER_FRIENDS, params));
		req.send(installedFriends);
	}
}

/******************************************************************************************************************************************************************************
																																							Function: friendsUpdated()
******************************************************************************************************************************************************************************/
function friendsUpdated(dataResponse, url, error)
{
	debug("Request returned: " + dataResponse.text);
	if(error)
		secureRequest(LAST_REQUEST_DATA, LAST_REQUEST_CALLBACK);
	var data = dataResponse.text.evalJSON();
	
	if(data.banned == "true")
	{
		if(data.reason != null)
			var reason = ' for the following reason:<br/>' + data.reason + '.';
		else
			var reason = '.';
		if(data.type == "permanently")
		{
			document.getElementById("main").innerHTML = '<center><div style="border:solid 1px #FF6C6C; padding:15px; background:#FFDDDE; width:650px; margin:10px; font-size:16px; font-weight:bold; margin-top:35px;">You have been permanently debarred from using this application' + reason + '</div></center>';
		}
		else if(data.type == "temporarily")
		{
			document.getElementById("main").innerHTML = '<center><div style="border:solid 1px #FF6C6C; padding:15px; background:#FFDDDE; width:650px; margin:10px; font-size:16px; font-weight:bold; margin-top:35px;">You have ' + data.time_left + ' on your temporary debarment' + reason + '</div></center>';
		}
	}
	else
	{
		var container = opensocial.Container.get();
		var dataRequest = container.newDataRequest();
		
		var param = {};
		param[opensocial.DataRequest.PeopleRequestFields.PROFILE_DETAILS] = 
				[opensocial.Person.Field.AGE,
				MyOpenSpace.Person.Field.GENDER];
	
		var personRequest = dataRequest.newFetchPersonRequest(opensocial.DataRequest.PersonId.OWNER, param);
	   
		dataRequest.add(personRequest);
	
		dataRequest.send(informationReceived);
	}
}

/******************************************************************************************************************************************************************************
																																							Function: informationReceived()
******************************************************************************************************************************************************************************/
function informationReceived(data)
{		
	var owner = data.get(opensocial.DataRequest.PersonId.OWNER).getData();
	OWNER.ID = owner.getField(opensocial.Person.Field.ID);
	OWNER.IMAGE = owner.getField(opensocial.Person.Field.THUMBNAIL_URL);
	OWNER.NAME = owner.getField(opensocial.Person.Field.NAME);
	OWNER.SEX = owner.getField(opensocial.Person.Field.GENDER);
	OWNER.AGE = owner.getField(opensocial.Person.Field.AGE);
	
	document.getElementById("main").innerHTML = '<div id="tabs"><div style="float:right; font-size:12px; margin-top:7px; margin-right:10px; padding-bottom:3px; color:#003300; font-weight:bold; text-align:right;"><div>Tokens: <span id="ownerTokens">0</span></div>Cash: $<span id="ownerCash">0</span></div>\
	<ul>\
	<li><a href="javascript:void(0);" onClick="renderPage(PAGE.PROFILE, ' + OWNER.ID + '); this.blur();" title="View your quote"><span>You</span></a></li>\
	<li><a href="javascript:void(0);" onClick="renderPage(PAGE.PORTFOLIO); this.blur();" title="View the stocks you have invested in"><span>Portfolio</span></a></li>\
	<li><a href="javascript:void(0);" onClick="renderPage(PAGE.INVESTORS); this.blur();" title="View who has invested in your stock"><span>Investors</span></a></li>\
	<li><a href="javascript:void(0);" onClick="renderPage(PAGE.BROWSE); this.blur();" title="Browse Friends\' Stock to invest in"><span>Browse</span></a></li>\
	<li><a href="javascript:void(0);" onClick="renderPage(PAGE.TOP); this.blur();" title="View the top players on Friends Stock"><span>Top</span></a></li>\
	<li><a href="javascript:void(0);" onClick="renderPage(PAGE.BONUS); this.blur();" title="Earn bonus Friend Stocks dollars"><span>Money</span></a></li>\
	<li><a href="javascript:void(0);" onClick="renderPage(PAGE.TOKENS); this.blur();" title="Earn bonus Friend Stocks tokens"><span>Tokens</span></a></li>\
	<li><a href="javascript:void(0);" onClick="renderPage(PAGE.SETTINGS); this.blur();" title="Configure your settings"><span>Settings</span></a></li>\
	<li><a href="javascript:void(0);" onClick="renderPage(PAGE.INVITE); this.blur();" title="Invite friends to use this app"><span>Invite</span></a></li>\
	<li><a href="javascript:void(0);" onClick="renderPage(PAGE.HELP); this.blur();" title="Help and Frequently Asked Questions"><span>Help</span></a></li>\
	</ul>\
	</div><br clear="all"/><div style="text-align:right; margin-right:5px; margin-top:2px;"><a href="javascript:void(0);" onClick="backPage(); this.blur();" title="Go back a page"><img src="http://gpujfwaa.joyent.us/myspace/fs/images/icon-back.gif" border="0"/></a><a href="javascript:void(0);" onClick="refreshCurPage(); this.blur();" title="Refresh this page"><img src="http://gpujfwaa.joyent.us/myspace/fs/images/icon-reload.gif" border="0"/></a></div>\
	<div id="mainBody" style="margin-top:10px; padding:10px;"><span style="font-size:18px;">What would you like to do?</span></div>\
	<br clear="all"/><div style="font-size:14px; font-weight:bold; margin-top:20px; color:#999999; text-align:center;">A Revolutionary Productions&trade; Application</div>';
	
	renderPage(PAGE.PROFILE, OWNER.ID);
	
	var req = opensocial.newDataRequest();
	var params = {};
	params[opensocial.DataRequest.PeopleRequestFields.FILTER] = opensocial.DataRequest.FilterType.ALL;
	params[opensocial.DataRequest.PeopleRequestFields.FIRST] = CURRENT_POSITION;
	params[opensocial.DataRequest.PeopleRequestFields.MAX] = 20;
	req.add(req.newFetchPeopleRequest(opensocial.DataRequest.Group.VIEWER_FRIENDS, params));
	req.send(allFriends);
}

/******************************************************************************************************************************************************************************
																																							Function: allFriends()
******************************************************************************************************************************************************************************/
function allFriends(dataResponse)
{
	var friendsDataGroup = dataResponse.get(opensocial.DataRequest.Group.VIEWER_FRIENDS);
	var friendsData = friendsDataGroup.getData();
	FRIEND_COUNT = friendsData.getTotalSize();
}

/******************************************************************************************************************************************************************************
																																							Function: invitePage()
******************************************************************************************************************************************************************************/
function invitePage(page)
{
	FRIEND_PAGE = page;
	FRIEND_INVITE.length = 0;
	var req = opensocial.newDataRequest();
	var params = {};
	params[opensocial.DataRequest.PeopleRequestFields.FILTER] = opensocial.DataRequest.FilterType.ALL;
	params[opensocial.DataRequest.PeopleRequestFields.FIRST] = ((page - 1) * 40);
	params[opensocial.DataRequest.PeopleRequestFields.MAX] = 40;
	req.add(req.newFetchPeopleRequest(opensocial.DataRequest.Group.VIEWER_FRIENDS, params));
	req.send(fillFriendsForInvite);
	document.location.hash = "#inviteTop";
}

/***********************************************************************************************************************************************
																											FUNCTION : FILL FRIENDS FOR INVITE
***********************************************************************************************************************************************/
function fillFriendsForInvite(dataResponse)
{
	var friendsDataGroup = dataResponse.get(opensocial.DataRequest.Group.VIEWER_FRIENDS);
	var friendsData = friendsDataGroup.getData();
	var friendsSize = friendsData.getTotalSize();
	var friends = '<a name="inviteTop"></a><div style="font-size:18px; font-weight:bold; color:#FF0000; text-align:center; margin-bottom:10px; margin-top:10px; display:none;" id="inviteError"></div><table cellspacing="10" cellpadding="0" style="text-align:center;"><tr>';
	var count = 0;
	friendsData.each(
		function(friendData)
		{
			var friendId = friendData.getField(opensocial.Person.Field.ID);
			var friendName = friendData.getField(opensocial.Person.Field.NAME);
			var friendPic = friendData.getField(opensocial.Person.Field.THUMBNAIL_URL);
			friends += '<td style="border:solid 1px #CCCCCC; padding:10px; background:#FFFFFF; vertical-align:top; width:85px; overflow:hidden;" id="' + friendId + '_td"><div style="width:85px; height:100px; overflow:hidden; position:relative;"><div style="position:absolute; top:0px; right:0px;"><input type="checkbox" onClick="checkInvite(\'' + friendId + '\'); this.blur();" id="' + friendId + '_check"/></div><a href="#" onClick="clickInvite(\'' + friendId + '\');" title="' + friendName + '"><img src="' + friendPic + '" width="85" border="0" title="' + friendName + '"/></a></div><div style="font-size:10px; width:85px; overflow:hidden;">' + friendName + '</div></td>';
			if(count % 8 == 7)
				friends += '</tr><tr>';
			count ++;
		}
	);
	friends += '</tr></table>';
	
	queuePage("invitePage('" + FRIEND_PAGE + "')");
	
	var page = FRIEND_PAGE;
	var pagination = '<div style="font-size:16px; height:16px; margin-bottom:8px; font-weight:bold;">';
	if(count == 0)
		pagination += '<div style="font-size:26px; text-align:center;">You have no friends to invite.</div>';
	if(count == 40)
		pagination += '<div style="float:right;"><a href="javascript:void(0);" onClick="invitePage(' + (FRIEND_PAGE + 1) + '); this.blur();">next page >></a></div>';
	else
		pagination += '<div style="float:right; color:#666666;">next page >></div>';
	if(FRIEND_PAGE > 1)
		pagination += '<a href="javascript:void(0);" onClick="invitePage(' + (FRIEND_PAGE - 1) + '); this.blur();"><< previous page</a>';
	else
		pagination += '<span style="color:#666666;"><< previous page</span>';
	pagination += '</div><br clear="all"/>';
	friends += pagination;
		
	document.getElementById("inviteDiv").innerHTML = friends;
}
/***********************************************************************************************************************************************
																													FUNCTION : REMOVE INVITE
***********************************************************************************************************************************************/
function removeInvite(id)
{
	for(i = 0; i < FRIEND_INVITE.length; i ++)
	{
		if(FRIEND_INVITE[i] == id)
		{
			FRIEND_INVITE.splice(i, 1);
			break;
		}
	}
}
/***********************************************************************************************************************************************
																													FUNCTION : SEND INVITATIONS
***********************************************************************************************************************************************/
function sendInvitations()
{
	if(FRIEND_INVITE.length > 0)
	{
		message = opensocial.newMessage("[sender] has invited you to use [app]. Click Add [app] to see how much you're worth now!");
	
		opensocial.requestShareApp(FRIEND_INVITE, message, function(){ invitePage(FRIEND_PAGE); });
	}
}
/***********************************************************************************************************************************************
																													FUNCTION : CLICK INVITE
***********************************************************************************************************************************************/
function clickInvite(id)
{
	if(document.getElementById(id + "_check").checked == true)
	{
		removeInvite(id);
		document.getElementById(id + "_check").checked = false;
		document.getElementById(id + "_td").style.background = "#FFFFFF";
		document.getElementById(id + "_td").style.color = "#000000";
	}
	else if(document.getElementById(id + "_check").checked == false)
	{
		if(FRIEND_INVITE.length >= 20)
		{
			var inviteError = document.getElementById("inviteError");
			inviteError.innerHTML = "You can only invite 20 friends at a time. Please send these invitations then continue to select friends.";
			inviteError.style.display = "block";
			document.location.hash = "#inviteTop";
		}
		else
		{
			FRIEND_INVITE.push(id);
			document.getElementById(id + "_check").checked = true;
			document.getElementById(id + "_td").style.background = "#3B5998";
			document.getElementById(id + "_td").style.color = "#FFFFFF";
		}
	}
}
/***********************************************************************************************************************************************
																													FUNCTION : CHECK INVITE
***********************************************************************************************************************************************/
function checkInvite(id)
{
	if(document.getElementById(id + "_check").checked == true)
	{
		if(FRIEND_INVITE.length >= 20)
		{
			var inviteError = document.getElementById("inviteError");
			inviteError.innerHTML = "You can only invite 20 friends at a time. Please send these invitations then continue to select friends.";
			inviteError.style.display = "block";
			document.location.hash = "#inviteTop";
		}
		else
		{
			FRIEND_INVITE.push(id);
			document.getElementById(id + "_td").style.background = "#3B5998";
			document.getElementById(id + "_td").style.color = "#FFFFFF";
		}
	}
	if(document.getElementById(id + "_check").checked == false)
	{
		removeInvite(id);
		document.getElementById(id + "_td").style.background = "#FFFFFF";
		document.getElementById(id + "_td").style.color = "#000000";
	}
}

/******************************************************************************************************************************************************************************
																																							Function: requestSession()
******************************************************************************************************************************************************************************/
function requestSession(data, callbackFunction)
{
	var d = new Date();
	var os_params = {};
	os_params[gadgets.io.RequestParameters.AUTHORIZATION] = gadgets.io.AuthorizationType.SIGNED;
	os_params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.POST;
	var encoded = gadgets.io.encodeValues(data);
	debug("Sending request: " + encoded);
	os_params[gadgets.io.RequestParameters.POST_DATA] = encoded;
	os_params[gadgets.io.RequestParameters.CONTENT_LENGTH] = encoded.length;
	gadgets.io.makeRequest('http://gpujfwaa.joyent.us/myspace/fs/authenticate.php?nocache=' + d.getSeconds(), callbackFunction, os_params);
}

/******************************************************************************************************************************************************************************
																																							Function: secureRequest()
******************************************************************************************************************************************************************************/
function secureRequest(data, callbackFunction)
{
	LAST_REQUEST_DATA = data;
	LAST_REQUEST_CALLBACK = callbackFunction;
	var d = new Date();
	var os_params = {};
	os_params[gadgets.io.RequestParameters.AUTHORIZATION] = gadgets.io.AuthorizationType.SIGNED;
	os_params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.POST;
	var encoded = gadgets.io.encodeValues(data);
	debug("Sending request: " + encoded);
	os_params[gadgets.io.RequestParameters.POST_DATA] = encoded;
	os_params[gadgets.io.RequestParameters.CONTENT_LENGTH] = encoded.length;
	gadgets.io.makeRequest('http://gpujfwaa.joyent.us/myspace/fs/fs.php?nocache=' + d.getSeconds() + '&sess_id=' + SESSION_ID, callbackFunction, os_params);
}

/******************************************************************************************************************************************************************************
																																							Function: addCommas()
******************************************************************************************************************************************************************************/
function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

/******************************************************************************************************************************************************************************
																																							Function: backPage()
******************************************************************************************************************************************************************************/
function backPage()
{
	if(VISITED_PAGES.length > 1)
	{
		VISITED_PAGES.pop();
		var page = VISITED_PAGES.pop();
		setTimeout(page, 1);
	}
	else if(VISITED_PAGES.length > 0)
	{
		var lastIndex = VISITED_PAGES.length - 1;
		var page = VISITED_PAGES[lastIndex];
		setTimeout(page, 1);
	}
}

/******************************************************************************************************************************************************************************
																																							Function: refreshCurPage()
******************************************************************************************************************************************************************************/
function refreshCurPage()
{
	if(VISITED_PAGES.length > 0)
	{
		var lastIndex = VISITED_PAGES.length - 1;
		var page = VISITED_PAGES[lastIndex];
		setTimeout(page, 1);
	}
}

/******************************************************************************************************************************************************************************
																																							Function: queuePage()
******************************************************************************************************************************************************************************/
function queuePage(func)
{
	var length = VISITED_PAGES.push(func);
	if(length > 10)
	{
		for(i = 0; i < VISITED_PAGES.length - 1; i ++)
		{
			VISITED_PAGES[i] = VISITED_PAGES[i + 1];
		}
		VISITED_PAGES.length = 10;
	}
}

/******************************************************************************************************************************************************************************
																																							Function: postBulletinAnnouncement()
******************************************************************************************************************************************************************************/
function postBulletinAnnouncement()
{
	var os_token = MyOpenSpace.MySpaceContainer.OSToken;
	var message = opensocial.newMessage(document.getElementById("announcementText").value + '<br/><br/><a href="http://profile.myspace.com/Modules/Applications/Pages/Canvas.aspx?appId=126325">Friends Stock</a>');
	message.setField(opensocial.Message.Field.TITLE, 'Check it out!');
	message.setField(opensocial.Message.Field.TYPE, MyOpenSpace.PostTo.Targets.BULLETINS);
	
	osContainer.postTo(os_token, message, null );
}

/******************************************************************************************************************************************************************************
																																							Function: postBulletinBought()
******************************************************************************************************************************************************************************/
function bulletinBought(name, value)
{
	var os_token = MyOpenSpace.MySpaceContainer.OSToken;
	var message = opensocial.newMessage('I invested in ' + unescape(name) + ' on Friends Stock for $' + addCommas(value) + '! Add <a href="http://profile.myspace.com/Modules/Applications/Pages/Canvas.aspx?appId=126325">Friends Stock</a> and find out how much you\'re worth!');
	message.setField(opensocial.Message.Field.TITLE, 'That just happened!');
	message.setField(opensocial.Message.Field.TYPE, MyOpenSpace.PostTo.Targets.BULLETINS);
	
	osContainer.postTo(os_token, message, null );
}

/******************************************************************************************************************************************************************************
																																							Function: postBulletinTokens()
******************************************************************************************************************************************************************************/
function postBulletinTokens()
{
	var os_token = MyOpenSpace.MySpaceContainer.OSToken;
	var message = opensocial.newMessage('Come help me out! Add <a href="http://profile.myspace.com/Modules/Applications/Pages/Canvas.aspx?appId=126325">Friends Stock</a> and help me earn tokens!');
	message.setField(opensocial.Message.Field.TITLE, 'Check this out!');
	message.setField(opensocial.Message.Field.TYPE, MyOpenSpace.PostTo.Targets.BULLETINS);
	
	osContainer.postTo(os_token, message, null);
	debug("Posted bulletin");
}

/******************************************************************************************************************************************************************************
																																							Function: postBulletinCash()
******************************************************************************************************************************************************************************/
function postBulletinCash()
{
	var os_token = MyOpenSpace.MySpaceContainer.OSToken;
	var message = opensocial.newMessage('Come help me out! Add <a href="http://profile.myspace.com/Modules/Applications/Pages/Canvas.aspx?appId=126325">Friends Stock</a>, buy me and you\'ll help me make money!');
	message.setField(opensocial.Message.Field.TITLE, 'Make it happen!');
	message.setField(opensocial.Message.Field.TYPE, MyOpenSpace.PostTo.Targets.BULLETINS);
	
	osContainer.postTo(os_token, message, null);
	debug("Posted bulletin");
}

/******************************************************************************************************************************************************************************
																																							Function: postBulletin()
******************************************************************************************************************************************************************************/
function postBulletin()
{
	var os_token = MyOpenSpace.MySpaceContainer.OSToken;
	var message = opensocial.newMessage('I am selling for $' + addCommas(OWNER.VALUE) + ' a share! Add <a href="http://profile.myspace.com/Modules/Applications/Pages/Canvas.aspx?appId=126325">Friends Stock</a> and find out how much you\'re worth!');
	message.setField(opensocial.Message.Field.TITLE, 'Can I play with you?');
	message.setField(opensocial.Message.Field.TYPE, MyOpenSpace.PostTo.Targets.BULLETINS);
	
	osContainer.postTo(os_token, message, null);
	debug("Posted bulletin");
}

/******************************************************************************************************************************************************************************
																																							Function: postComment()
******************************************************************************************************************************************************************************/
function postComment(id)
{
	var os_token = MyOpenSpace.MySpaceContainer.OSToken;
	var message = opensocial.newMessage("I just bought you on <a href=\"http://profile.myspace.com/Modules/Applications/Pages/Canvas.aspx?appId=126325\">Friends for Sale!</a> Find out how much I think you're worth!");
	message.setField(opensocial.Message.Field.TITLE, "Friends for Sale!");
	message.setField(opensocial.Message.Field.TYPE, "COMMENTS");
	osContainer.postTo(os_token, message, id, function(){closePurchase(LAST_BOUGHT_ID);});

	debug("Posted comment");
}

/******************************************************************************************************************************************************************************
																																							Function: commentPurchase()
******************************************************************************************************************************************************************************/
function commentPurchase(id)
{
	var os_token = MyOpenSpace.MySpaceContainer.OSToken;
	var message = opensocial.newMessage("<a href=\"http://profile.myspace.com/Modules/Applications/Pages/Canvas.aspx?appId=126325\"><img src='http://gpujfwaa.joyent.us/myspace/fs/images/comment.gif'/></a><br/><br/>I just bought you on <a href=\"http://profile.myspace.com/Modules/Applications/Pages/Canvas.aspx?appId=126325\">Friends Stock</a>! Install Friends Stock now to find out how much you're worth and then buy me back!");
	message.setField(opensocial.Message.Field.TITLE, "I just bought you on Friends Stock!");
	message.setField(opensocial.Message.Field.TYPE, "COMMENTS");
	osContainer.postTo(os_token, message, id, function(){Effect.Fade("purchasedDiv", { duration: 0.3 });});
}

/******************************************************************************************************************************************************************************
																																							Function: getFriendPersonById()
******************************************************************************************************************************************************************************/
function getFriendPersonById(theID) {
 	if(document.getElementById('trace')) {
		var str = document.getElementById('trace').innerHTML;
		document.getElementById('trace').innerHTML = str + '.';
	}
 	if(theID) {
		foundFriend = '';
		srchingId = theID;
		srchingPage = 0;
		foundFriendReady = 0;
	}
 	srchingPage += 1;
	var friend_params = {};
 	friend_params[opensocial.DataRequest.PeopleRequestFields.FIRST] = (srchingPage-1)*friendPageSize+1;
  	var dr = osContainer.newDataRequest();
	dr.add(osContainer.newFetchPeopleRequest('VIEWER_FRIENDS', friend_params), 'friends');
   	dr.send(function(response) {
		var friendData = response.get('friends').getData();
		friendData.each(function(person) {
			if(person.getId()==srchingId) {
				foundFriend = person;
				commentPurchase(person);
				foundFriendReady = 1;
			}
		});
		if(foundFriend=='') {
		 	if(srchingPage*friendPageSize < friendData.getTotalSize()) {
			 	getFriendPersonById('');
		 	}
		}
	});
}

/******************************************************************************************************************************************************************************
																																							Function: alphanumeric()
******************************************************************************************************************************************************************************/
function alphanumeric(alphane)
{
	var numaric = alphane;
	for(var j=0; j<numaric.length; j++)
	{
		var alphaa = numaric.charAt(j);
		var hh = alphaa.charCodeAt(0);
		if((hh > 47 && hh<58) || (hh > 64 && hh<91) || (hh > 96 && hh<123))
		{
		}
		else
		{
			return false;
		}
	}
	return true;
}

function updateCashTokens(cash, tokens)
{
	OWNER_CASH = cash;
	document.getElementById("ownerCash").innerHTML = addCommas(cash);
	OWNER_TOKENS = tokens;
	document.getElementById("ownerTokens").innerHTML = addCommas(tokens);
}

/******************************************************************************************************************************************************************************
																																							Function: debug()
******************************************************************************************************************************************************************************/
function debug(debug_text)
{
	if(DEBUG)
	{
		var debug_div = document.getElementById('debug');
		debug_div.innerHTML += debug_text + "<br />";
		debug_div.scrollTop = debug_div.scrollHeight;
	}	
}