/*
	Used to dynamically change images on the site.
*/
function lyfe_changeimage(image, url)
{
	image.src = url;
}


/*
	Moves the user to the top of the page.
*/
function lyfe_gototop()
{
	document.location.hash = 'jump_top';
}


/*
	Shows/hides the list of invitees on the add forum page.
*/
function lyfe_forumadd_showinvitees(is_public)
{
	if (is_public == "yes")
	{
		document.getElementById('area_middle_invite_list').style.display = 'none';
	}
	else
	{
		document.getElementById('area_middle_invite_list').style.display = 'block';
	}
}


/*
	Used to initialise the page.
*/
function lyfe_init(show_goals, show_news, show_newsletter, show_contribute, show_chase, show_search, show_account)
{
	lyfe_hideshow('area_left_goals', show_goals);
	lyfe_hideshow('area_left_news', show_news);
	lyfe_hideshow('area_left_newsletter', show_newsletter);
	lyfe_hideshow('area_right_contribute', show_contribute);
	lyfe_hideshow('area_right_chase', show_chase);
	lyfe_hideshow('area_right_search', show_search);
	lyfe_account(show_account);
}


/*
	Manages the showing and hiding of the account section.
*/
function lyfe_account(section_show)
{
	// Hide the "hidden" pane.
	document.getElementById('area_right_account_hidden').style.display = 'none';
	
	// Hide the non-authenticated state panes if they exist.
	if (document.getElementById('area_right_account_login'))
		document.getElementById('area_right_account_login').style.display = 'none';
	if (document.getElementById('area_right_account_reminder'))
		document.getElementById('area_right_account_reminder').style.display = 'none';
	if (document.getElementById('area_right_account_signup'))
		document.getElementById('area_right_account_signup').style.display = 'none';

	// Hide the authenticated state panes if they exist.
	if (document.getElementById('area_right_account_menu'))
		document.getElementById('area_right_account_menu').style.display = 'none';
		
	// Now display what was requested.
	if (document.getElementById('area_right_account_'+section_show))
		document.getElementById('area_right_account_'+section_show).style.display = 'block';
}


/*
	Show or hides a section.
*/
function lyfe_hideshow(section_id, show_section)
{
	if (show_section)
	{
		document.getElementById(section_id+'_hidden').style.display = 'none';
		document.getElementById(section_id+'_shown').style.display = 'block';
	}
	else
	{
		document.getElementById(section_id+'_hidden').style.display = 'block';
		document.getElementById(section_id+'_shown').style.display = 'none';
	}
}


/*
	Sends an HTTP request and returns the resulting response text.

	url			URL to connect to.
	parameters	parameters to POST.	
*/
function lyfe_request(url, parameters)
{
	// Set up request processor.
	var request;
	
	// Send the command.
	if (window.XMLHttpRequest) 
	{
		request = new XMLHttpRequest();
		request.open("POST", url, false);
		request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
		request.send(parameters);
	}
	else if (window.ActiveXObject) 
	{
		request = new ActiveXObject("Microsoft.XMLHTTP");
		if (request) 
		{
			request.open("POST", url, false);
			request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
			request.send(parameters);
		}
	}

	// Process response on a successful return.
	if (request.status == 200)
	{
		return request.responseText;
	}
}
