
var accordions = new Array();
var clickedCircles = new Array();

function checkMandatoryFields( element )
{
	var error = 0;
	var message = "";
	
	if( element.name.indexOf( "pictures" ) != -1 )
	{
		if( document.getElementById( 'promoLink' ) != null )
		{
			if( document.getElementById( 'promoLink' ).value.length == 0 )
			{
				message += "Please provide a link for the main promo. ";
				error = 1;
			}
		}
	}
	
	if( message.length > 0 )
		alert( message );
		
	return( error );
}

function storeMandatoryFields( element, rowToAppendTo )
{
	if( element.name.indexOf( "pictures" ) != -1 )
	{
		if( document.getElementById( 'promoLink' ) != null )
		{
			var promoLink = document.createElement( 'input' );
			promoLink.type = 'hidden';
			promoLink.value = document.getElementById( 'promoLink' ).value;
			promoLink.name = element.name + '_link';
		
			rowToAppendTo.appendChild( promoLink );
		
			document.getElementById( 'promoLink' ).value = "";
		}
	}
}

function updateDatabase( absolutePath, webRoot, checkBoxName, tableNameToColumnName )
{
	var checkBoxGrp = document.getElementsByName( checkBoxName );
	var len = checkBoxGrp.length;
	
	var status = 1;
	
	for( var i = 0; i < len; i++ )
	{
		if( checkBoxGrp[i].checked == true )
			status = checkBoxGrp[i].value;
	}
	
	new Ajax.Request( webRoot + '/ajaxPHP/cms/UpdateDatabase.php', {
		method: 'get',
		parameters: 'tableNameToColumnName=' + tableNameToColumnName + '&' + 'status=' + status + '&' +
			'webRoot=' + webRoot + '&' + 'absolutePath=' + absolutePath,
  		onSuccess: function( transport )
		{
		}
	});
}

/*
 * Use Ajax to remove a database entry after double checking with the user. checkBoxName is used to 
 * identify the checkbox (along with rowReference) if the user cancels the delete and in which case the 
 * checkbox should be unchecked. tableNameToColumn is used to identify the table and the table row, 
 * thingBeingRemoved is used to customise the confirm message and noDataRows is used to make certain rows 
 * visible or invisible when there are no rows left in tableName to delete.
 */

function deleteFromDatabase( absolutePath, webRoot, checkBoxName, tableNameToColumnName, thingBeingRemoved, 
	noDataRows, headingRow )
{	
	// If the row should be deleted.
	if( confirm( "Are you sure you want to delete this " + thingBeingRemoved + "?" ))
	{
		try
		{
		// Using Ajax to delete the row from the database.
		var currentPage = window.location;
		
		// Using Ajax to delete the row from the database.
		new Ajax.Request( webRoot + '/ajaxPHP/cms/DeleteFromDatabase.php', {
			method: 'get',
			parameters: 'tableNameToColumnName=' + tableNameToColumnName + '&' + 'absolutePath=' + 
				absolutePath + '&' + 'webRoot=' + webRoot,
  			onSuccess: function( transport )
			{
				try
				{
					Shadowbox.close();
				}
				catch( err )
				{
				}
				
				if( headingRow != "" )
					updateHTMLOnSuccess( headingRow, noDataRows );
				
				deleted = 1;
			}
		});
		
		if( headingRow != "" )
			updateHTMLOnSuccess( headingRow, noDataRows );
		else
			return( deleted );
		}
		catch( err )
		{
			alert( err );
		}
	}
	else
	{
		try
		{
			Shadowbox.close();
			return;
		}
		catch( err )
		{
			var checkBoxGrp = document.getElementsByName( checkBoxName );
			var len = checkBoxGrp.length;
		
			for( i = 0; i < len; i++ )
			{
				if( checkBoxGrp[i].checked )
					checkBoxGrp[i].checked = false;
			}
		}
	}
}

// Enables a CMS administrator to choose the featured items for display on the website.

function updateSelectedFeatures( absolutePath, webRoot, type, updateLinkText )
{
	var filesList = document.getElementById( 'selected' );
	
	var ids = "";
	
	for( var i = 0; i < filesList.options.length; i++ )
	{
		if( filesList.options[i].selected ) 
		{
			if( ids != "" )
				ids += ",";
			
			ids += filesList.options[i].value;
		}
	}
	
	var numList = document.getElementById( 'numRowsToRetrieve' );
	
	var numRowsToRetrieve = "";
	
	for( var i = 0; i < numList.options.length; i++ )
	{
		if( numList.options[i].selected ) 
			numRowsToRetrieve = numList.options[i].value;
	}
	
	new Ajax.Request( webRoot + '/ajaxPHP/cms/UpdateFeatured.php', {
		method: 'get',
		parameters: 'type=' + type + '&' + 'absolutePath=' + absolutePath + '&' + 'ids=' + ids + '&' + 
			'updateLinkText=' + updateLinkText + '&' + 'numRowsToRetrieve=' + numRowsToRetrieve + '&' + 
			'webRoot=' + webRoot,
  		onSuccess: function( transport )
		{
			updateDisplayList( transport.responseText, type, updateLinkText );
		}
	});
}

// Enables a CMS administrator to set/change the period after which featured items are automatically 
// changed if not changed before in the CMS.

function updateFeaturedPeriod( absolutePath, webRoot )
{
	var checkBoxGrp = document.getElementsByName( 'period' );
	var len = checkBoxGrp.length;
	
	var period = "";
	
	for( i = 0; i < len; i++ )
	{
		if( checkBoxGrp[i].checked )
			period = checkBoxGrp[i].value;
	}
	
	new Ajax.Request( webRoot + '/ajaxPHP/cms/UpdateFeaturedPeriod.php', {
		method: 'get',
		parameters: 'period=' + period + '&' + 'absolutePath=' + absolutePath + '&' + 'webRoot=' + webRoot,
  		onSuccess: function( transport )
		{
		}
	});
}

// Set or changes the period after which text promotions are automatically changed if not changed before 
// then in the CMS.

function updatePromoPeriod( absolutePath, webRoot )
{
	var checkBoxGrp = document.getElementsByName( 'period' );
	var len = checkBoxGrp.length;
	
	var period = "";
	
	for( i = 0; i < len; i++ )
	{
		if( checkBoxGrp[i].checked )
			period = checkBoxGrp[i].value;
	}
	
	new Ajax.Request( webRoot + '/ajaxPHP/cms/UpdatePromoPeriod.php', {
		method: 'get',


		parameters: 'period=' + period + '&' + 'absolutePath=' + absolutePath + '&' + 'webRoot=' + webRoot,
  		onSuccess: function( transport )
		{
		}
	});
}

// Retrieve a random or latest number of items for display on the website as featured.

function updateFeatured( absolutePath, webRoot, type, updateLinkText )
{	
	var numList = document.getElementById( 'numRowsToRetrieve' );
	
	var numRowsToRetrieve = "";
	
	for( var i = 0; i < numList.options.length; i++ )
	{
		if( numList.options[i].selected ) 
			numRowsToRetrieve = numList.options[i].value;
	}
	
	new Ajax.Request( webRoot + '/ajaxPHP/cms/UpdateFeatured.php', {
		method: 'get',
		parameters: 'type=' + type + '&' + 'absolutePath=' + absolutePath + '&' + 'updateLinkText=' + 
			updateLinkText + '&' + 'numRowsToRetrieve=' + numRowsToRetrieve + '&' + 'webRoot=' + webRoot,
  		onSuccess: function( transport )
		{
			updateDisplayList( transport.responseText, type, updateLinkText );
		}
	});
}

// General purpose function used to refresh the list of items displayed when switching between random, 
// latest and selected for the featured CMS scripts.

function updateDisplayList( contents, type, updateLinkText )
{
	var ul = document.getElementById( 'boxes' );
	var listItems = ul.getElementsByTagName( 'li' );
	var len = listItems.length;
			
	for( var i = 0; i < len; i++ )
		ul.removeChild( listItems[0] );
			
	var temp = contents.split( '@' );
	var editScript = temp[0];
	var configDisplaySetting = temp[2];
	var array = temp[1].split( '%' );
	var len = array.length;
			
	if( len > 0 )
	{
		document.getElementById( 'nothingToDelete' ).style.display = "none";
		document.getElementById( 'deleteHeader' ).style.display = "";
		document.getElementById( 'archiveHeader' ).style.display = "";
	}
	else
		document.getElementById( 'nothingToDelete' ).style.display = "";
		
	for( var i = 0; i < len; i++ )
	{
		var temp = array[i].split( '#' );
	
		var li = document.createElement( 'li' );
		li.style.width = "600px";
				
		var div = document.createElement( 'div' );
		div.setAttribute( 'id', 'div' + temp[0] );
				
		var span = document.createElement( 'span' );
		span.className = "white";
		
		var href = document.createElement( 'a' );
		href.setAttribute( 'href', editScript + '?id=' + temp[0] );
		href.appendChild( document.createTextNode( temp[1] ) );
		
		span.appendChild( href );
		div.appendChild( span );
				
		var input = document.createElement( 'input' );
		input.setAttribute( 'type', 'checkbox' );
		input.setAttribute( 'name', 'delete[]' );
		input.setAttribute( 'id', 'delete[]' );
		input.className = "tick";
		input.onclick = function() { deleteFromOrderedList(); };
				
		div.appendChild( input );
				
		var input = document.createElement( 'input' );
		input.setAttribute( 'type', 'hidden' );
		input.setAttribute( 'value', temp[2] );
				
		div.appendChild( input );
		
		var input = document.createElement( 'input' );
		input.setAttribute( 'type', 'checkbox' );
		input.setAttribute( 'name', 'archive[]' );
		input.setAttribute( 'id', 'archive[]' );
		input.className = "tick2";
		input.onclick = function() { archiveFromDatabase( temp[3] ); };
		
		div.appendChild( input );
		
		li.appendChild( div );
				
		ul.appendChild( li );
	}
	
	if( updateLinkText == 1 )
	{
		var innerHTML = document.getElementById( 'sectionHeader' ).innerHTML;
		
		var idxAll = innerHTML.indexOf( type );
		
		if( idxAll == -1 )
			var idxAll = innerHTML.indexOf( 'select' );
			
		var first = innerHTML.substring( 0, idxAll );
		var idxQuote = innerHTML.indexOf( '"', idxAll );
		
		var second = innerHTML.substring( idxQuote, innerHTML.length );
	
		var idxShow = second.indexOf( 'Show' );
	
		if( type != "all" )
			configDisplaySetting = "all";
		
		innerHTML = first + configDisplaySetting + "','1')" + second.substring( 0, idxShow ) + 'Show ' + 
			configDisplaySetting + '</span></a>';
			
		document.getElementById( 'sectionHeader' ).innerHTML = innerHTML;
			
		setupDrag();
	}
	
	if( type != "select" )
	{
		document.getElementById( 'dropDownHeader' ).style.display = "none";
		//document.getElementById( 'selectPeriodHeader' ).style.display = "none";
		document.getElementById( 'blankHeaderRow' ).style.display = "none";
	}
	else
	{
		document.getElementById( 'dropDownHeader' ).style.display = "";
		//document.getElementById( 'selectPeriodHeader' ).style.display = "";
		document.getElementById( 'blankHeaderRow' ).style.display = "";
	}
	
	var checkBoxGrp = document.getElementsByName( 'action' );
	var len = checkBoxGrp.length;

	for( var i = 0; i < len; i++ )
	{
		if( checkBoxGrp[i].value == type )
			checkBoxGrp[i].checked = true;
	}
	
	document.getElementById( 'actionHeader' ).style.display = "";
}

// In the CMS index pages the order of items can be changed by dragging and dropping. This function is 
// invoked on completion of a drag and drop operation. This function identifies the order of the items. 
// The PHP script updates order of the items in the database.

function updateDisplayOrder()
{
	var list = document.getElementById( 'boxes' );
	var items = list.getElementsByTagName( "li" );
	var len = items.length;
		
	var order = new Array();
		
	for( i = 0; i < len; i++ )
	{
		var html = items[i].innerHTML;
		var idxProjectId = html.indexOf( '.php?id=' );
		var idxEqual = html.indexOf( '=', idxProjectId );
		idxEqual++;
		var idxQuote = html.indexOf( '"', idxEqual );
			
		order.push( html.substring( idxEqual, idxQuote ) );
	}
		
	new Ajax.Request( webRoot + '/ajaxPHP/cms/UpdateDisplayOrder.php', {
		method: 'get',
		parameters: 'order=' + order.join( "," ) + '&' + 'absolutePath=' + absolutePath + '&' + 
			'webRoot=' + webRoot,
  		onSuccess: function( transport ){
		}
	});
}

// Deleting from an ordered list is somewhat different from deleting from an index page containing 
// unordered items. The function still uses the DeleteFromDatabase PHP script to change the database.

function deleteFromOrderedList()
{
	try
	{
	var checkBoxGrp = document.getElementsByName( 'delete[]' );
	var len = checkBoxGrp.length;
	
	var idxOfCheck = 0;
	
	for( i = 0; i < len; i++ )
	{
		if( checkBoxGrp[i].checked )
			idxOfCheck = i;
	}
	
	var list = document.getElementById( 'boxes' );
	var items = list.getElementsByTagName( "li" );
	
	var html = items[idxOfCheck].innerHTML;
	var idxValue = html.indexOf( 'value' );
	var idxStartQuote = html.indexOf( '"', idxValue );
	idxStartQuote++;
	var idxEndQuote = html.indexOf( '"', idxStartQuote );
	
	var temp = html.substring( idxStartQuote, idxEndQuote );
	
	var array = temp.split( ',' );
	
	var id = array[0];
	var absolutePath = array[1];
	var webRoot = array[2];
	var checkBoxName = array[3];
	var tableNameToColumnName = array[4];
	var thingBeingRemoved = array[5];
	var noDataRows = array[6].substring( 1, array[6].length - 1 );
	var headingRow = "";
	
	deleteFromDatabase( absolutePath, webRoot, checkBoxName, tableNameToColumnName, thingBeingRemoved, 
		noDataRows, headingRow );
	
	if( deleted == 1 )
	{
		document.getElementById( 'div' + id ).parentNode.parentNode.removeChild
			( document.getElementById( 'div' + id ).parentNode );
	
		if( getNumRows( 'deletefromorderedlist' ) == 0 )
		{	
			// If no rows are left retrieve the name of the row to update and an integer value to 
			// determine whether the row should be made visible or invisible.
			var rows = noDataRows.split( '|' );
					
			for( i = 0; i < rows.length; i++ )
			{
				var rowNameToStatus = rows[i].split( '~' );
			
				if( rowNameToStatus[1] == "0" )
					document.getElementById( rowNameToStatus[0] ).style.display = "none";
				else
					document.getElementById( rowNameToStatus[0] ).style.display = "";
			}
		}
	}
	}
	catch( err )
	{
		alert( err );
	}
}

function updateLoginStatus()
{
	new Ajax.Request( webRoot + '/ajaxPHP/website/CheckLoginStatus.php', {
		method: 'get',
		parameters: 'absolutePath=' + absolutePath + '&' + 'webRoot=' + webRoot,
  		onSuccess: function( transport )
		{
			var array = transport.responseText.split( '|' );
				
			var loginLink = document.getElementById( 'loginLink' );
			
			if( loginLink != null )
			{
				loginLink.innerHTML = array[0];
				loginLink.href = array[1];
				
				if( array[0] == "logout" )
				{
					document.getElementById( 'loginMenuLink' ).parentNode.style.display = "";
					document.getElementById( 'registerAccountLink' ).parentNode.style.display = "none";
				}
				else
				{
					document.getElementById( 'loginMenuLink' ).parentNode.style.display = "none";
					document.getElementById( 'registerAccountLink' ).parentNode.style.display = "";
				}
				
				//document.getElementById( 'loginMenuLink' ).href = array[2];
			}
		}
	}); 
}

// Display the content specified of the type specified in a Shadowbox at the dimensions specified.

function openShadowbox( type, content, height, width )
{	
	var options = 
	{ 
		onClose: function() { updateLoginStatus(); }, 
		listenOverlay:	false
	};
		
	Shadowbox.init(options);
	
	Shadowbox.open({
		type:	type,
        content:	content,
		height:	height,
		width: width
    });
}

// Get the number of rows that are available for delete on a CMS index page. This controls whether 
// appropriate checkboxes and error messages are displayed.

function getNumRows( key )
{
	key = key.toLowerCase();
	
	var contents = document.body.innerHTML.toLowerCase();
	
	var idxStartTable = contents.lastIndexOf( '<table' );
	var idxEndTable = contents.indexOf( '</table>', idxStartTable );
	contents = contents.substring( idxStartTable, idxEndTable );
	
	var currentIdx = 0;
	var numRows = 0;
	
	var idxDelete = contents.indexOf( key, currentIdx );
	
	while( idxDelete != -1 )
	{
		numRows++;
		currentIdx = idxDelete;
		currentIdx++;
		idxDelete = contents.indexOf( key, currentIdx );
	}
	
	return( numRows );
}

// Is a generic function used to update the CMS display after database delete.

function updateHTMLOnSuccess( headingRow, noDataRows )
{
	var row = document.getElementById( headingRow );
	var start = row.rowIndex;
				
	var table = row.parentNode.parentNode;
	
	var rows = table.rows;
	var len = rows.length;
	var end = -1;
	
	for( i = start; i < len; i++ )
	{
		if( rows[i].innerHTML.indexOf( '<td>&nbsp;</td>' ) != -1 && end == -1 )
		{
			end = i;
			end++;
		}
	}
				
	if( end == -1 )
		end = len;
				
	var numRows = getNumRows( 'deletefromdatabase' );
	
	for( i = start; i < end; i++ )
	{
		// Delete the table row from the HTML document.
		document.getElementById( 'contentRows' ).deleteRow( start );
	}
	
	numRows--;
	
	if( numRows <= 0 )
	{
		// If no rows are left retrieve the name of the row to update and an integer value to 
		// determine whether the row should be made visible or invisible.
		var rows = noDataRows.split( ',' );
					
		for( i = 0; i < rows.length; i++ )
		{
			var rowNameToStatus = rows[i].split( '~' );
			
			if( rowNameToStatus[1] == "0" )
				document.getElementById( rowNameToStatus[0] ).style.display = "none";
			else
				document.getElementById( rowNameToStatus[0] ).style.display = "";
		}
	}
}

/*
 * When deleting a row from a table it is sufficient just to have the id or name of the table row since
 * the table it belongs to can be found using parentNode. The removeChild function can then be used to
 * remove the table row from the table element. However, when adding rows it is necessary to identify
 * where in the table the rows should be inserted. headingRow does just this. It also explains what
 * data follows and therefore should be displayed if data exists and not if it doesn't. Once a row is
 * removed a count of the number of rows is computed and if this is zero the appendTo/header row is no
 * longer displayed. It can easily be displayed again if new data is added. The third argument to this
 * function is used to determine how many rows and left and when the header row should no longer be 
 * displayed.
 */
 
function deleteTableRow( headingRow, rowToDelete, deleteImage )
{
	var table = document.getElementById( rowToDelete ).parentNode;
	
	// Remove the row chosen by the user by navigating to the parent of the table row, the table, and then
	// using the removeChild function.
	table.removeChild( document.getElementById( rowToDelete ) );
	
	// Calculate how many rows are left following the headingRow. Each row has a delete button which
	// is a unique id but whose id has a common part for all rows belonging to the append to row.
	
	// Initially find all images on the page.
	var images = table.getElementsByTagName( 'img' );
	var len = images.length;
	
	var count = 0;
	
	for( i = 0; i < len; i++ )
	{
		// We are only interested in delete images that belong to rows related to headingRow
		if( images[i].id.indexOf( deleteImage ) != -1 )
			count++;
	}
	
	// If there aren't any rows hide the headingRow row so that we are not describing data that doesn't
	// exist.
	if( count == 0 )
	{
		var row = document.getElementById( headingRow );
		
		var rowIndex = row.rowIndex;
		rowIndex++;
		
		table.deleteRow( rowIndex );
		
		row.style.display = "none";
	}
}

// Allows a CMS administrator to choose whether to display workspace information by participant or workspace.

function changeDisplayDetails( absolutePath, webRoot, type )
{
	if( type == "participant" )
		script = "ListByParticipant.php";
	else
		script = "ListByWorkspace.php";
		
	new Ajax.Request( webRoot + '/ajaxPHP/cms/' + script, {
		method: 'get',
		parameters: 'absolutePath=' + absolutePath + '&' + 'webRoot=' + webRoot,
  		onSuccess: function( transport )
		{
			var row = document.getElementById( 'displayHeader' );
			var rowIndex = row.rowIndex;
			rowIndex = rowIndex + 2;
			
			var table = row.parentNode.parentNode;
			var len = table.rows.length - 2;
			
			for( var i = 0; i < len; i++ )
				table.deleteRow( rowIndex );
			
			var array = transport.responseText.split( '|' );
			len = array.length;
			
			if( array[0].length == 0 )
			{
				document.getElementById( 'suspendHeader' ).style.display = "none";
				document.getElementById( 'deleteHeader' ).style.display = "none";
				document.getElementById( 'displayHeader' ).style.display = "none";
				document.getElementById( 'norowstodelete' ).style.display = "";
	
				return;
			}
			
			for( var i = 0; i < len; i++ )
			{
				var rowDetails = array[i].split( '~' );
				
				var id = rowDetails[0];
				var name = rowDetails[1];
				
				var contentRow = table.insertRow( rowIndex );
				var rowIdName = 'rowToDelete' + id;
				contentRow.setAttribute( 'id', rowIdName );
	
				var column1 = contentRow.insertCell( 0 );
				column1.setAttribute( 'width', '361' );
				column1.setAttribute( 'valign', 'top' );
				var span = column1.appendChild( document.createElement( 'span' ) );
				span.className = 'white';
				span.appendChild( document.createTextNode( name ) );
				column1.appendChild( span );
	
				var column2 = row.insertCell( 1 );
				column2.setAttribute( 'width', '44' );
				column2.setAttribute( 'valign', 'top' );
		  
				var checkboxSuspend = document.createElement( 'input' );
				checkboxSuspend.setAttribute( 'type', 'checkbox' );
				checkboxSuspend.setAttribute( 'id', 'suspend[]' );
				checkboxSuspend.setAttribute( 'name', 'suspend[]' );
				
				checkboxSuspend.onclick = function() 
				{ 
					updateDatabase(  absolutePath, webRoot, 'delete[]', 'participants~id~' + id ); 
				};
				
				column2.appendChild( checkboxSuspend );
				
				var column3 = row.insertCell( 2 );
				column3.setAttribute( 'width', '44' );
				column3.setAttribute( 'valign', 'top' );
	
				var checkboxDelete = document.createElement( 'input' );
				checkboxDelete.setAttribute( 'type', 'checkbox' );
				checkboxDelete.setAttribute( 'id', 'delete[]' );
				checkboxDelete.setAttribute( 'name', 'delete[]' );
				checkboxDelete.setAttribute( 'value', id );
				
				checkboxDelete.onclick = function() 
				{ 
					deleteFromDatabase(  absolutePath, webRoot, 'delete[]', 'editors~account_id~' + id + 
						',participants~id~' + id, 'account', 'suspendHeader~0,deleteHeader~0,' +
						'norowstodelete~1,displayHeader~0', 'rowToDelete' + id ); 
				};
				
				column3.appendChild( checkboxDelete );
				
				contentRow.appendChild( column1 );
				contentRow.appendChild( column2 );
				contentRow.appendChild( column3 );
	
				var blankRow = table.insertRow( rowIndex );
				var rowIdName = 'blankrow' + id;
				blankRow.setAttribute( 'id', rowIdName );
	
				var column1 = row.insertCell( 0 );
				blankRow.appendChild( column1 );
			}
		}
	});
}

function updatePersonalOrganisationDetails( absolutePath, webRoot )
{
	new Ajax.Request( webRoot + '/ajaxPHP/website/UpdatePersonalOrganisationDetails.php', {
		method: 'get',
		parameters: 'absolutePath=' + absolutePath + '&' + 'webRoot=' + webRoot,
  		onSuccess: function( transport )
		{
			var array = transport.responseText.split( '~' );
			
			document.getElementById( 'nameValue' ).innerHTML = array[0];
			document.getElementById( 'addressValue' ).innerHTML = array[1];
			document.getElementById( 'postcodeValue' ).innerHTML = array[2];
			document.getElementById( 'regionValue' ).innerHTML = array[3];
			document.getElementById( 'contactNameValue' ).innerHTML = array[4];
			document.getElementById( 'contactTelephoneValue' ).innerHTML = array[5];
			document.getElementById( 'websiteValue' ).innerHTML = array[6];
			document.getElementById( 'emailValue' ).innerHTML = array[7];
			document.getElementById( 'passwordValue' ).innerHTML = array[8];

			if( array.length > 9 )
			{
				document.getElementById( 'tradingNameValue' ).innerHTML = array[9];
				document.getElementById( 'legalNameValue' ).innerHTML = array[10];
				document.getElementById( 'addressValue' ).innerHTML = array[11];
				document.getElementById( 'postcodeValue' ).innerHTML = array[12];
				document.getElementById( 'regionValue' ).innerHTML = array[13];
				document.getElementById( 'websiteValue' ).innerHTML = array[14];
				document.getElementById( 'legalIdentityValue' ).innerHTML = array[15];
				document.getElementById( 'buildingTenureValue' ).innerHTML = array[16];
				//document.getElementById( 'landlordTypeValue' ).innerHTML = array[17];
				//document.getElementById( 'leaseholdLengthValue' ).innerHTML = array[18];
				//document.getElementById( 'leaseholdExpirationValue' ).innerHTML = array[19];
				document.getElementById( 'practitionerTenureValue' ).innerHTML = array[20];
				document.getElementById( 'rentalChargesValue' ).innerHTML = array[21];
				document.getElementById( 'ratesReliefValue' ).innerHTML = array[22];
				document.getElementById( 'workspaceManagerValue' ).innerHTML = array[23];
				document.getElementById( 'selectionPolicyValue' ).innerHTML = array[24];
				//document.getElementById( 'selectionPolicySummaryValue' ).innerHTML = array[25];
			}
		}
	});
}

function editPersonalOrganisationDetails( absolutePath, webRoot )
{
	var options = 
	{ 
		onClose: function() { updatePersonalOrganisationDetails( absolutePath, webRoot ); },
		listenOverlay:	false
	};
		
	Shadowbox.init(options);

	Shadowbox.open({
		type:	"iframe",
        content:	webRoot + '/ajaxPHP/website/EditPersonalOrganisationDetails.php',
		height:	897,
		width: 377
    });	
}

function updateParticipantSpaceRequirements( absolutePath, webRoot )
{
	new Ajax.Request( webRoot + '/ajaxPHP/website/UpdateParticipantSpaceRequirements.php', {
		method: 'get',
		parameters: 'absolutePath=' + absolutePath + '&' + 'webRoot=' + webRoot,
  		onSuccess: function( transport )
		{
			if( transport.responseText.length > 0 )
			{
				var array = transport.responseText.split( '~' );
				
				var noSpaceRequirements = document.getElementById( 'noSpaceRequirements' );
				
				if( noSpaceRequirements != null )
				{
					noSpaceRequirements.style.display = "none";
					document.getElementById( 'spaceRequirementValues' ).style.display = "";
				}
				
				document.getElementById( 'requirementRegionValue' ).innerHTML = array[0];
				document.getElementById( 'artformsValue' ).innerHTML = array[1];
				document.getElementById( 'servicesValue' ).innerHTML = array[2];
				document.getElementById( 'costValue' ).innerHTML  = array[3];
				document.getElementById( 'sizeValue' ).innerHTML = array[4];
				document.getElementById( 'includesServicesChargesValue' ).innerHTML = array[5];
				document.getElementById( 'includesInsuranceValue' ).innerHTML = array[6];
				document.getElementById( 'includesRatesValue' ).innerHTML = array[7];
			}
		}
	});
}

function editParticipantSpaceRequirements( absolutePath, webRoot )
{
	var options = 
	{ 
		onClose: function() { updateParticipantSpaceRequirements( absolutePath, webRoot ); }, 
		listenOverlay:	false
	};
		
	Shadowbox.init(options);

	Shadowbox.open({
		type:	"iframe",
        content:	webRoot + '/ajaxPHP/website/EditSpaceRequirements.php',
		height:	897,
		width: 377
    });
	
	//openShadowbox( 'iframe', webRoot + '/ajaxPHP/website/EditSpaceRequirements.php', 897, 377 );
}

function inviteFriend( webRoot )
{
	openShadowbox( 'iframe', webRoot + '/ajaxPHP/website/InviteFriend.php', 506, 377 );
}

function test( webRoot )
{
	openShadowbox( 'swf', webRoot + '/ajaxPHP/lockedup_housetour.swf', 678, 1000 );
}

function displaySuccessMessage( webRoot, message )
{
	openShadowbox( 'iframe', webRoot + '/ajaxPHP/website/Success.php?message=' + message, 159, 600 );
}

function displayImage( webRoot, filename )
{
	openShadowbox( 'iframe', webRoot + '/ajaxPHP/website/DetailImage.php?filename=' + filename, 375, 500 );
}

function displayWorkspaceEnquiries( webRoot, vacancyId )
{
	openShadowbox( 'iframe', webRoot + '/ajaxPHP/website/GetWorkspaceEnquiries.php?vacancyId=' + vacancyId, 159, 600 );
}

function displayVacancyDetail( absolutePath, webRoot, vacancyId )
{
	openShadowbox( 'iframe', webRoot + '/ajaxPHP/website/GetWorkspaceVacancyDetail.php?vacancyId=' + vacancyId, 800, 727 );
}

function displayFutureSpaceDetail( absolutePath, webRoot, spaceId )
{
	openShadowbox( 'iframe', webRoot + '/ajaxPHP/website/GetFutureSpaceDetail.php?spaceId=' + spaceId, 790, 727 );
}

// Call the GetArtistSpaceDetail PHP script to retrieve and display the details of a specific artist
// space, as identified by spaceId.

function displayArtistSpaceDetail( absolutePath, webRoot, spaceId )
{
	openShadowbox( 'iframe', webRoot + '/ajaxPHP/website/GetArtistSpaceDetail.php?spaceId=' + spaceId, 800, 727 );
}

function displayTermsConditions( absolutePath, webRoot )
{
	openShadowbox( 'iframe', webRoot + '/TermsConditions.php', 3246, 377 );
}

// Call the Question.php script to display the posts in reply to a specific forum question.

function displayForumQuestion( absolutePath, webRoot, questionId )
{
	var options = 
	{ 
		onClose: function() 
		{	 
			updateLoginStatus();
			updateMostRecentQuestions( absolutePath, webRoot ); 
		},
		
		listenOverlay:	false
	};
	
	Shadowbox.init(options);

	Shadowbox.open({
		type:	"iframe",
        content:	webRoot + '/ajaxPHP/website/Question.php?id=' + questionId,
		height:	349,
		width: 600
    });
}

// Display the resident artist detail information in a shadowbox.

function getResidentArtistDetail( absolutePath, webRoot, artistId )
{
	openShadowbox( 'iframe', webRoot + '/ajaxPHP/website/GetResidentArtistDetail.php?id=' + artistId, 500, 700 );
}

function getToolkitKnowledgeDetail( absolutePath, webRoot, toolkitId )
{
	openShadowbox( 'iframe', webRoot + '/ajaxPHP/website/GetToolkitDetail.php?knowledgeId=' + toolkitId, 1205, 617 );
}

function getToolkitKnowHowDetail( absolutePath, webRoot, toolkitId )
{
	openShadowbox( 'iframe', webRoot + '/ajaxPHP/website/GetToolkitDetail.php?knowHowId=' + toolkitId, 1205, 617 );
}

// Use an iframe to call the PHP script as normal by in the context of a shadowbox window. The PHP
// script displays a .tpl form to enable the artist space details to be provided. When these are 
// submitted the artist space is added to the database.

function displaySubmitArtistSpaceForm( absolutePath, webRoot )
{
	openShadowbox( 'iframe', webRoot + '/ajaxPHP/website/SubmitArtistSpace.php', 1220, 377 );	
}

function displaySubmitFutureSpaceForm( absolutePath, webRoot )
{
	openShadowbox( 'iframe', webRoot + '/ajaxPHP/website/SubmitFutureSpace.php', 876, 377 );	
}

function displaySubmitQuestionForm( absolutePath, webRoot, topicId )
{
	if( topicId === undefined )
		openShadowbox( 'iframe', webRoot + '/ajaxPHP/website/SubmitQuestion.php', 476, 360 );	
	else
		openShadowbox( 'iframe', webRoot + '/ajaxPHP/website/SubmitQuestion.php?topicId=' + topicId, 476, 360 );
}

function displayDetailedMap( webRoot, workspaceId )
{
	openShadowbox( 'iframe', webRoot + '/ajaxPHP/website/Map.php?id=' + workspaceId, 310, 580 );
}

// To enable participants to submit resources for immediate viewing or approval 
// (depending on CMS settings).
													
function displaySubmitResourceForm( absolutePath, webRoot )
{
	openShadowbox( 'iframe', webRoot + '/ajaxPHP/website/SubmitResource.php', 1174, 377 );
}

function displayEditResourceForm( absolutePath, webRoot, resourceId )
{
	openShadowbox( 'iframe', webRoot + '/ajaxPHP/website/EditResource.php?id=' + resourceId, 1174, 377 );
}

function displayEditArtistSpaceForm( absolutePath, webRoot, spaceId )
{
	openShadowbox( 'iframe', webRoot + '/ajaxPHP/website/EditArtistSpace.php?id=' + spaceId, 1220, 377 );
}

function displayEditFutureSpaceForm( absolutePath, webRoot, spaceId )
{
	openShadowbox( 'iframe', webRoot + '/ajaxPHP/website/EditFutureSpace.php?id=' + spaceId, 876, 377 );
}

function updateMostRecentPosts( absolutePath, webRoot )
{
	new Ajax.Request( webRoot + '/ajaxPHP/website/GetForumPosts.php', {
		method: 'get',
		parameters: 'absolutePath=' + absolutePath + '&' + 'webRoot=' + webRoot,
  		onSuccess: function( transport )
		{
			var array = transport.responseText.split( '~' );
			
			document.getElementById( 'forumFirstThree' ).innerHTML = array[0];
			document.getElementById( 'forumSecondThree' ).innerHTML = array[1];
		}
	});
}

function updateMostRecentQuestions( absolutePath, webRoot )
{
	new Ajax.Request( webRoot + '/ajaxPHP/website/GetForumQuestions.php', {
		method: 'get',
		parameters: 'absolutePath=' + absolutePath + '&' + 'webRoot=' + webRoot,
  		onSuccess: function( transport )
		{
			var array = transport.responseText.split( '~' );
			
			document.getElementById( 'forumFirstThree' ).innerHTML = array[0];
			document.getElementById( 'forumSecondThree' ).innerHTML = array[1];
		}
	});
}

function updateResourceComments( absolutePath, webRoot, resourceId )
{
	new Ajax.Request( webRoot + '/ajaxPHP/website/GetResourceComments.php', {
		method: 'get',
		parameters: 'absolutePath=' + absolutePath + '&' + 'webRoot=' + webRoot + '&' + 'resourceId=' + resourceId,
  		onSuccess: function( transport )
		{
			var commentsList = transport.responseText;
			
			document.getElementById( 'commentsList' ).innerHTML = commentsList;
		}
	});
}

function removeResource( absolutePath, webRoot, resourceId )
{
	if( confirm( "Are you sure you want to remove this resource from the website?" ))
	{
		new Ajax.Request( webRoot + '/ajaxPHP/website/RemoveResource.php', {
			method: 'get',
			parameters: 'absolutePath=' + absolutePath + '&' + 'webRoot=' + webRoot + '&' + 
				'resourceId=' + resourceId,
  			onSuccess: function( transport )
			{
				var divId = "resourceDiv" + resourceId;
				
				var resourceDiv = document.getElementById( divId );
				var rowDiv = resourceDiv.parentNode;
				
				rowDiv.removeChild( resourceDiv );
				
				resourcesCount--;
				
				if( resourcesCount == 0 )
					rowDiv.parentNode.innerHTML = "<p><strong>You have yet to submit any resources</strong></p>";
			}
		});
	}
}

function removeParticipant( absolutePath, webRoot, participantId )
{
	context = "your";
	
	if( window.location.href.indexOf( 'cms/accounts/index.php' ) != -1 )
		context = "the";
		
	if( confirm( "Are you sure you want to cancel " + context + " account?" ))
	{
		if( confirm( "By cancelling " + context + " account all artist spaces and future spaces you have added will be removed. Are you sure you want to continue?" ))
		{
			parameters = 'absolutePath=' + absolutePath + '&' + 'webRoot=' + webRoot;
			
			if( participantId !== undefined )
				parameters += '&' + 'participantId=' + participantId;
			
			new Ajax.Request( webRoot + '/ajaxPHP/website/RemoveParticipant.php', {
				method: 'get',
				parameters: parameters,
  				onSuccess: function( transport )
				{
					if( participantId !== undefined )
						window.location.reload();
					else
						logout( absolutePath, webRoot );
				}
			});
		}
	}
}

function removeArtistSpace( absolutePath, webRoot, spaceId )
{
	if( confirm( "Are you sure you want to remove this artist space from the website?" ))
	{
		new Ajax.Request( webRoot + '/ajaxPHP/website/RemoveArtistSpace.php', {
			method: 'get',
			parameters: 'absolutePath=' + absolutePath + '&' + 'webRoot=' + webRoot + '&' + 
				'spaceId=' + spaceId,
  			onSuccess: function( transport )
			{
				var divId = "artistSpacesDiv" + spaceId;
				
				var artistSpaceDiv = document.getElementById( divId );
				var rowDiv = artistSpaceDiv.parentNode;
				
				rowDiv.removeChild( artistSpaceDiv );
				
				artistSpacesCount--;
				
				if( artistSpacesCount == 0 )
					rowDiv.parentNode.innerHTML = "<p><strong>You have yet to submit any artist spaces</strong></p>";
			}
		});
	}
}

function removeFutureSpace( absolutePath, webRoot, spaceId )
{
	if( confirm( "Are you sure you want to remove this future space from the website?" ))
	{
		new Ajax.Request( webRoot + '/ajaxPHP/website/RemoveFutureSpace.php', {
			method: 'get',
			parameters: 'absolutePath=' + absolutePath + '&' + 'webRoot=' + webRoot + '&' + 
				'spaceId=' + spaceId,
  			onSuccess: function( transport )
			{
				var divId = "futureSpacesDiv" + spaceId;
				
				var futureSpaceDiv = document.getElementById( divId );
				var rowDiv = futureSpaceDiv.parentNode;
				
				rowDiv.removeChild( futureSpaceDiv );
				
				futureSpacesCount--;
				
				if( futureSpacesCount == 0 )
					rowDiv.parentNode.innerHTML = "<p><strong>You have yet to submit any future spaces</strong></p>";
			}
		});
	}
}

function removeFromFavourities( absolutePath, webRoot, id, type )
{
	if( confirm( "Are you sure you want to remove this from your list of favourities?" ) )
	{
		var accordionName = "favourite";
		
		if( type == "workspaces" )
			accordionName += "Workspaces"; 		
		else if( type == "knowledge" || type == "knowHow" )
			accordionName += 'ToolkitFiles';
		else if( type == "resources" )
			accordionName += 'Resources';
		else if( type == "artistSpaces" )
			accordionName += 'ArtistSpaces';
		else if( type == "futureSpaces" )
			accordionName += 'FutureSpaces';
		else if( type == "questions" )
			accordionName += 'ForumQuestions';
			
		var accordion = accordions[accordionName];
		accordion.showThisHideOpen(0);
		
		new Ajax.Request( webRoot + '/ajaxPHP/website/RemoveFromFavourities.php', {
			method: 'get',
			parameters: 'absolutePath=' + absolutePath + '&' + 'webRoot=' + webRoot + '&' + 
				'id=' + id + '&' + 'type=' + type,
  			onSuccess: function( transport )
			{
				if( type == "knowledge" || type == "knowHow" )
					type = "toolkit";
					
				var divId = type + id;
				
				var favouriteDiv = document.getElementById( divId );
				
				var rowDiv = favouriteDiv.parentNode;
				var sectionDiv = rowDiv.parentNode;
		
				rowDiv.removeChild( favouriteDiv );
		
				var count = sectionTotals[type];
		
				count--;
				
				if( count == 0 )
				{
					sectionDiv.removeChild( rowDiv );
					sectionDiv.innerHTML = "<p><strong>At present you do not have any favourite " + type + 
						".</strong></p>";
				}
				
				accordion.showThisHideOpen(0);
			}
		});
	}
}

function removeWorkspace( absolutePath, webRoot, workspaceId )
{
	if( confirm( "Are you sure you want to remove this workspace from the website?" ))
	{
		new Ajax.Request( webRoot + '/ajaxPHP/website/RemoveWorkspace.php', {
			method: 'get',
			parameters: 'absolutePath=' + absolutePath + '&' + 'webRoot=' + webRoot + '&' + 
				'workspaceId=' + workspaceId,
  			onSuccess: function( transport )
			{
				var divId = "workspace" + workspaceId;
				
				document.getElementById( divId ).innerHTML = "";
				
				workspacesCount--;
				
				if( workspacesCount == 0 )
					document.getElementById( divId ).innerHTML = '<strong>You have yet to submit any workspaces</strong>';
			}
		});
	}
}

function removeVacancy( absolutePath, webRoot, vacancyId, workspaceId )
{
	if( confirm( "Are you sure you want to remove this vacancy from the website?" ))
	{
		new Ajax.Request( webRoot + '/ajaxPHP/website/RemoveVacancy.php', {
			method: 'get',
			parameters: 'absolutePath=' + absolutePath + '&' + 'webRoot=' + webRoot + '&' + 
				'vacancyId=' + vacancyId,
  			onSuccess: function( transport )
			{
				var divId = "vacancies" + vacancyId;
				
				document.getElementById( divId ).innerHTML = "";
				
				var vacanciesCount = workspaceVacancies[workspaceId];
				vacanciesCount--;
				
				if( vacanciesCount == 0 )
					document.getElementById( divId ).innerHTML = '<p><strong>At present there are no vacancies</strong></p>';
			}
		});
	}
}

function rateResource( webRoot, resourceId )
{
	openShadowbox( 'iframe', webRoot + '/ajaxPHP/website/RateResource.php?id=' + resourceId, 190, 360 );
}

// To enable participants to download resources. Participant login/registeration is required for
// statistical purposes.
													
function downloadResource( absolutePath, webRoot, downloadId )
{
	var functionDetails = "downloadResource('" + absolutePath + "','" + webRoot + "','" + 
		downloadId + "' );";
	
	new Ajax.Request( webRoot + '/ajaxPHP/website/CheckLoginStatus.php', {
		method: 'get',
		parameters: 'absolutePath=' + absolutePath + '&' + 'webRoot=' + webRoot,
  		onSuccess: function( transport )
		{
			if( transport.responseText.indexOf( 'login' ) != -1 && displayedLogin == 0 )
			{
				displayedLogin = 1;
				openDownloadResourceShadowbox( absolutePath, webRoot, functionDetails );
			}
			else if( transport.responseText.indexOf( 'logout' ) != -1 && displayedResourceForm == 0 )
			{
				displayedResourceForm = 1;
				var linkPage = document.getElementById('downloadLink' + downloadId).href;
				window.location.href = linkPage;
			}
		}
	});
}

function openDownloadResourceShadowbox( absolutePath, webRoot, functionDetails )
{
	var options = 
	{ 
		onClose: function() { eval( functionDetails ); },
		listenOverlay:	false
	};
		
	Shadowbox.init(options);

	Shadowbox.open({
		type:	"iframe",
        content:	webRoot + "/ajaxPHP/website/Login.php?redirect=0",
		height:	418,
		width: 360
    });
}

// Runs the PHP script to prompt the user to login or register. This function/script is called by other
// functions/scripts when the functionality requires the user to be logged in and they're not. In this
// case the login script will enable the user to login or register and then perform the functionality 
// that was stopped by the user not being logged in.

function displayLogInRegisterForm( webRoot, redirect )
{
	if( redirect === undefined )
		redirect = 0;
	
	openShadowbox( "iframe", webRoot + "/ajaxPHP/website/Login.php?redirect=" + redirect, 418, 360 );
}

// Runs the PHP script to prompt the user to login or register. This function/script is called by other
// functions/scripts when the functionality requires the user to be logged in and they're not. In this
// case the login script will enable the user to login or register and then perform the functionality 
// that was stopped by the user not being logged in.

function displayRegisterForm( webRoot )
{
	openShadowbox( "iframe", webRoot + "/ajaxPHP/website/Register.php", 418, 360 );
}

// Show the resource files in a shadowbox.

function displayResourceDetail( absolutePath, webRoot, resourceId, randomPicNo )
{
	var phpScript = webRoot + '/ajaxPHP/website/GetResourceDetail.php?id=' + resourceId;
	
	if( randomPicNo !== undefined )
		phpScript += "&randomPicNo=" + randomPicNo;
		
	openShadowbox( 'iframe', phpScript, 800, 617 );
}

function editWorkspace( webRoot, workspaceId )
{
	openShadowbox( "iframe", webRoot + "/ajaxPHP/website/EditWorkspace.php?id=" + workspaceId, 971, 377 );
}

function editArtistSpace( webRoot, spaceId )
{
	openShadowbox( "iframe", webRoot + "/ajaxPHP/website/EditArtistSpace.php?spaceId=" + spaceId, 971, 377 );
}

function submitWorkspace( absolutePath, webRoot )
{
	openShadowbox( "iframe", webRoot + "/ajaxPHP/website/SubmitWorkspace.php", 971, 377 );
}

function advancedSearch( absolutePath, webRoot )
{
	openShadowbox( "iframe", webRoot + "/ajaxPHP/website/AdvancedSearch.php", 971, 377 );
}

function editVacancy( webRoot, workspaceId )
{
	openShadowbox( "iframe", webRoot + "/ajaxPHP/website/EditVacancy.php?id=" + workspaceId, 971, 377 );
}

function submitVacancy( webRoot, workspaceId )
{
	openShadowbox( "iframe", webRoot + "/ajaxPHP/website/SubmitVacancy.php?workspaceId=" + workspaceId, 971, 377 );
}

// Enable abusive content to be reported to Inhabit.

function reportAbusiveContent( absolutePath, webRoot, resourceId )
{
	openShadowbox( "iframe", webRoot + "/ajaxPHP/website/ReportAbusiveContent.php?id=" + resourceId, 416, 360 );
}

// Enable participants to leave comments on resources.

function submitResourceComment( absolutePath, webRoot, resourceId )
{
	var options = 
	{ 
		onClose: function() { updateResourceComments( absolutePath, webRoot, resourceId ); },
		listenOverlay:	false
	};
		
	Shadowbox.init(options);

	Shadowbox.open({
		type:	"iframe",
        content:	webRoot + "/ajaxPHP/website/SubmitResourceComment.php?id=" + resourceId,
		height:	416,
		width: 360
    });
	
	//openShadowbox( "iframe", webRoot + "/ajaxPHP/website/SubmitResourceComment.php?id=" + resourceId, 416, 360 );
}

// Again use an iframe to allow the space requirements to be specified and then submitted for storage
// in the database.

function displaySpaceRequirementsForm( webRoot )
{
	openShadowbox( "iframe", webRoot + "/ajaxPHP/website/SpaceRequirements.php", 800, 380 );
}

// Is invoked from within a Workspace detail page. If the user is logged in an enquiry is logged for the
// workspace (workspace_id, participant_id). If the user is not logged in they are presented with a form
// from which they can log in or register.

function registerWorkspaceInterest( webRoot, vacancyId )
{
	openShadowbox( "iframe", webRoot + "/ajaxPHP/website/RegisterWorkspaceInterest.php?id=" + vacancyId, 155, 360 );
}

function registerArtistSpaceInterest( webRoot, spaceId )
{
	openShadowbox( "iframe", webRoot + "/ajaxPHP/website/RegisterArtistSpaceInterest.php?id=" + spaceId, 155, 360 );
}

function registerFutureSpaceInterest( webRoot, spaceId )
{
	openShadowbox( "iframe", webRoot + "/ajaxPHP/website/RegisterFutureSpaceInterest.php?id=" + spaceId, 155, 360 );
}

// Update the database to remove the workspace from the user's list of favourities and update the HTML so that the user sees that
// it has been removed.

function removeFromFavouriteWorkspaces( absolutePath, webRoot, workspaceId )
{
	if( confirm( "Are you sure you want to remove this workspace from your list of favourities?" ) )
	{
		new Ajax.Request( webRoot + '/ajaxPHP/website/RemoveFromFavouriteWorkspaces.php', {
			method: 'get',
			parameters: 'id=' + workspaceId + '&' + 'absolutePath=' + absolutePath + '&' + 'webRoot=' + webRoot,
  			onSuccess: function( transport )
			{
				// Need to delete div containing content.
				var div = document.getElementById( 'workspace' + workspaceId );
				div.parentNode.removeChild( div );
			}
		});
	}
}

function sendEmail( webRoot )
{
	var name = "";
	var email = "";
	var message = "";
	
	var inputs = document.getElementsByTagName( 'input' );
	
	for( i = 0; i < inputs.length; i++ )
	{
		if( inputs[i].id == "name" && inputs[i].value != "Name" )
			name = inputs[i].value;
		
		if( inputs[i].id == "email" && inputs[i].value != "Email" )
			email = inputs[i].value;
	}
	
	var textareas = document.getElementsByTagName( 'textarea' );
	
	for( i = 0; i < textareas.length; i++ )
	{
		if( textareas[i].id == "message" && textareas[i].value != "" )
			message = textareas[i].value;
	}
	
	if( name.length != 0 && email.length != 0 && message.length != 0 )
	{
		var options = 
		{ 
			onClose: function() 
			{
				document.getElementById( 'name' ).value = "Name";
				document.getElementById( 'email' ).value = "Email";
				document.getElementById( 'message' ).value = "Message";
			},
			
			listenOverlay:	false
		};
		
		Shadowbox.init(options);

		Shadowbox.open({
			type:	"iframe",
        	content: webRoot + "/ajaxPHP/website/SendEmail.php?name=" + name + '&email=' + email + '&message=' + 
				message,
			height:	800,
			width: 360
    	});
	}
}

function addToFavouriteFutureSpaces( absolutePath, webRoot, spaceId )
{
	openShadowbox( "iframe", webRoot + "/ajaxPHP/website/AddToFavouriteFutureSpaces.php?id=" + spaceId, 800, 360 );
}

function addToFavouriteResources( absolutePath, webRoot, resourceId )
{
	openShadowbox( "iframe", webRoot + "/ajaxPHP/website/AddToFavouriteResources.php?id=" + resourceId, 425, 360 );
}

function addToFavouriteToolkit( absolutePath, webRoot, getVariable, toolkitId )
{
	openShadowbox( "iframe", webRoot + "/ajaxPHP/website/AddToFavouriteToolkit.php?" + getVariable + '=' + 
		toolkitId, 800, 380 );
}

function addToFavouriteWorkspaces( absolutePath, webRoot, workspaceId, randomPicNo )
{
	openShadowbox( "iframe", webRoot + "/ajaxPHP/website/AddToFavouriteWorkspaces.php?id=" + workspaceId, 800, 380 );
}

function addToFavouriteForumQuestions( absolutePath, webRoot, questionId )
{
	openShadowbox( "iframe", webRoot + "/ajaxPHP/website/AddToFavouriteForumQuestions.php?id=" + questionId, 800, 380 );
}

// Is invoked from the CMS to add or remove a criterion from the list of selected criterions for displaying
// popular data on the website.

function changeSelectedPopularData( absolutePath, webRoot, popularDataId )
{	
	var checked = 0;
	
	var checkboxGroup = document.getElementsByName( 'selected[]' );
	
	for( var i = 0; i < checkboxGroup.length; i++ )
	{
		if( checkboxGroup[i].value == popularDataId )
		{
			if( checkboxGroup[i].checked )
				checked = 1;
		}
	}
	
	new Ajax.Request( webRoot + '/ajaxPHP/cms/ChangeSelectedPopularData.php', {
		method: 'get',
		parameters: 'id=' + popularDataId + '&' + 'checked=' + checked + '&' + 'absolutePath=' + 
			absolutePath + '&' + 'webRoot=' + webRoot,
  		onSuccess: function( transport )
		{
		}
	});
}

// Front-end function used to navigate through the list of popular facts displayed on a page.

function changePopularDataDisplayed( direction )
{
	if( direction == "next" )
	{
		if( popularDataIdx + 1 == popularFigures.length )
			popularDataIdx = 0;
		else
			popularDataIdx++;
	}
	else if( direction == "previous" )
	{
		if( popularDataIdx == 0 )
			popularDataIdx = popularFigures.length - 1;
		else
			popularDataIdx--;
	}
	
	document.getElementById( 'currentPopularFigure' ).innerHTML = popularFigures[popularDataIdx];
	document.getElementById( 'currentPopularDescription' ).innerHTML = popularDescriptions[popularDataIdx];
}

// Is used by the text promo CMS pages to create FCKeditors in which user specified promo texts can be entered or
// changed.

function createEditorInstances( temp )
{
	var periodRow = document.getElementById( 'periodHeader' ).parentNode;
	var rowIndex = periodRow.rowIndex;
	var table = periodRow.parentNode;
	
	var selectedPromoTexts = new Array();
	
	if( temp.length != 0 )
		selectedPromoTexts = temp.split( '|' );
	else
		selectedPromoTexts = temp;
	
	for( var i = 0; i < numEditorInstances; i++ )
	{
		var rowId = "checkboxRow" + i;
		
		var checkboxRow = table.insertRow( rowIndex );
		checkboxRow.setAttribute( 'id', rowId );
		checkboxRow.setAttribute( 'name', rowId );
		
		var column1 = checkboxRow.insertCell( 0 );
		column1.setAttribute( 'colspan', '2' );
		
		var checkboxId = "editorCheckbox" + i;
		var editorId = "editorRow" + i;
		
		var input = document.createElement( 'input' );
		input.setAttribute( 'type', 'checkbox' );
		input.setAttribute( 'id', checkboxId );
		input.setAttribute( 'name', checkboxId );
		input.onclick = function() { hideEditors(); };
		
		if( selectedPromoTexts.length != 0 && i < selectedPromoTexts.length  )
			input.setAttribute( 'checked', 'checked' );
		
		column1.appendChild( input );
		
		rowId = "editorRow" + i;
		rowIndex++;
		
		var editorRow = table.insertRow( rowIndex );
		editorRow.setAttribute( 'id', rowId );
		editorRow.setAttribute( 'name', rowId );
		
		var column1 = editorRow.insertCell( 0 );
		column1.setAttribute( 'colspan', '2' );
		
		var id = "promo" + i;
		
		var fck = new FCKeditor( id );
		fck.BasePath = '../../fckeditor/';
		fck.ToolbarSet = 'promo';
		
		if( selectedPromoTexts.length != 0 && i < selectedPromoTexts.length  )
			fck.Value = selectedPromoTexts[i];
		else
		{
			checkboxRow.style.display = "none";
			editorRow.style.display = "none";
		}
		
		column1.innerHTML = fck.CreateHtml();
		
		rowIndex++;
	}
}

// Also used by the text promotions CMS script to not display certain FCKeditors or all when switching between
// fixed promos and user specified.

function hideEditors()
{
	var checked = 0;
	
	for( var i = 0; i < numEditorInstances; i++ )
	{
		// Is checkbox checked? If not do not display text editor and hide checkbox
		if( !document.getElementById( 'editorCheckbox' + i ).checked )
		{
			document.getElementById( 'editorCheckbox' + i ).checked = false;
			document.getElementById( 'checkboxRow' + i ).style.display = "none";
			document.getElementById( 'editorRow' + i ).style.display = "none";
		}
		
		if( document.getElementById( 'editorRow' + i ).style.display == "" )
			checked = 1;
	}
	
	if( checked == 0 )
		specifyCheckbox.checked = false;
}

// Is called when a text promotion selection is made. Checks whether FCKeditor instances should be displayed
// or not. Hide or display. Checks whether the number of selections has been exceeded.

function checkSelection( value )
{
	var numChecked = 0;
	var numEditorInstancesDisplayed = 0;
	var selectedInput = "";
	
	var inputs = document.getElementsByTagName( 'input' );
	var inputLen = inputs.length;
	
	for( var i = 0; i < inputLen; i++ )
	{
		if( inputs[i].type == "checkbox" )
		{
			if( inputs[i].value == value )
				selectedInput = inputs[i];
			
			if( inputs[i].checked )
			{
				if( inputs[i].id.indexOf( 'editorCheckbox' ) != -1 )
					numEditorInstancesDisplayed++;
					
				numChecked++;
			}
			
			if( inputs[i].value == -1 )
				specifyCheckbox = inputs[i];
		}
	}
	
	// If the checkbox was checked
	if( selectedInput.checked )
	{
		if( specifyCheckbox.checked && value != -1 )
			numChecked--;
			
		// Have too many checkboxes been checked?
		if( numChecked > numEditorInstances )
		{
			alert( "This page only has space for " + numEditorInstances + " promos. If you want to make a change " +
				"to the current selection please uncheck a selected option before selecting another" );
			
			selectedInput.checked = false;
		}
		else
		{
			// If the checkbox checked is the specify your own then display.
			if( selectedInput.value == -1 )
			{
				var numEditorInstancesToDisplay = numEditorInstances - ( numChecked - 1 );
				
				for( var i = 0; i < numEditorInstancesToDisplay; i++ )
				{
					document.getElementById( 'checkboxRow' + i ).style.display = "";
					document.getElementById( 'editorRow' + i ).style.display = "";
					document.getElementById( 'editorCheckbox' + i ).checked = "true";
				}
			}
		}
	}
	else
	{
		// If unchecking the specify own text checkbox then hide all instances and check instance checkboxes.
		if( selectedInput.value == -1 )
		{
			for( var i = 0; i < numEditorInstances; i++ )
			{
				var checkbox = document.getElementById( 'editorCheckbox' + i );
				checkbox.checked = false;
				
				document.getElementById( 'checkboxRow' + i ).style.display = "none";
				document.getElementById( 'editorRow' + i ).style.display = "none";
			}
		}
		else
		{
			var checked = 0;
			
			for( var i = 0; i < numEditorInstances; i++ )
			{
				var checkbox = document.getElementById( 'editorCheckbox' + i );
				
				if( !checkbox.checked && !checked )
				{
					checkbox.checked = 1;
					checked = 1;
					document.getElementById( 'checkboxRow' + i ).style.display = "";
					document.getElementById( 'editorRow' + i ).style.display = "";
				}
			}
		}
	}
}

// General purpose function used in the CMS for deleting drag and drop images.

function deleteDiv( divIdToRemove, headingRow )
{
	var ul = document.getElementById( divIdToRemove ).parentNode.parentNode;
	var li = document.getElementById( divIdToRemove ).parentNode;
	
	ul.removeChild( li );
	
	var listItems = ul.getElementsByTagName( 'li' );
	
	if( listItems.length == 0 )
	{
		var row = document.getElementById( headingRow );
		var table = row.parentNode;
		
		var rowIndex = row.rowIndex;
		table.deleteRow( rowIndex );
		table.deleteRow( rowIndex );
	}
}

/*
// Is invoked when the edit button used to update the name contact details in the myaccount section of the website is
// clicked. This function replaces the static text with HTML text input fields where the details can be changed.

function editNameDetails( absolutePath, webRoot, participantId )
{
	var selectElement = '<select name="title" id="title"><option value="Dr">Dr</option><option value="Mr">Mr</option>' +
		'<option value="Mrs">Mrs</option><option value="Miss">Miss</option></select>';
	
	var len = selectElement.length;
	
	var title = document.getElementById( 'titleValue' ).innerHTML;
	
	var idxValue = selectElement.indexOf( 'value="' + title + '"' );
	var idxChevron = selectElement.indexOf( '>', idxValue );
	
	selectElement = selectElement.substring( 0, idxChevron ) + ' selected="selected" ' + selectElement.substring( idxChevron, len );
	document.getElementById( 'titleValue' ).innerHTML = selectElement;
	
	var participantFirstName = document.createElement( 'input' );
	participantFirstName.setAttribute( 'type', 'text' );
    participantFirstName.setAttribute( 'id', 'firstName' );
	participantFirstName.setAttribute( 'name', 'firstName' );
	participantFirstName.setAttribute( 'value', document.getElementById( 'firstNameValue' ).innerHTML );
	participantFirstName.className = "text";
	
	document.getElementById( 'firstNameValue' ).innerHTML = "";
	document.getElementById( 'firstNameValue' ).appendChild( participantFirstName );

	var participantSurname = document.createElement( 'input' );
	participantSurname.setAttribute( 'type', 'text' );
    participantSurname.setAttribute( 'id', 'surname' );
	participantSurname.setAttribute( 'name', 'surname' );
	participantSurname.setAttribute( 'value', document.getElementById( 'surnameValue' ).innerHTML );
	participantSurname.className = "text";
	
	document.getElementById( 'surnameValue' ).innerHTML = "";
	document.getElementById( 'surnameValue' ).appendChild( participantSurname );
	
	document.getElementById( 'nameEditSaveButton' ).href = "javascript:saveNameDetails('" + absolutePath + "','" + 
		webRoot + "','" + participantId + "');";
	
	document.getElementById( 'nameEditSaveButton' ).innerHTML = "save details";	
}*/

// Is invoked when the edit button used to update the telephone details in the myaccount section of the website is
// clicked. This function replaces the static text with HTML text input fields where the details can be changed.

function editContactDetails( absolutePath, webRoot, participantId )
{
	var participantName = document.createElement( 'input' );
	participantName.setAttribute( 'type', 'text' );
    participantName.setAttribute( 'id', 'name' );
	participantName.setAttribute( 'name', 'name' );
	participantName.setAttribute( 'value', document.getElementById( 'nameValue' ).innerHTML );
	participantName.className = "text";
	
	document.getElementById( 'nameValue' ).innerHTML = "";
	document.getElementById( 'nameValue' ).appendChild( document.createElement( 'br' ) );
	document.getElementById( 'nameValue' ).appendChild( participantName );
	
	var address = document.createElement( 'textarea' );
	address.setAttribute( 'id', 'address' );
	address.setAttribute( 'name', 'address' );
	address.innerHTML = document.getElementById( 'addressValue' ).innerHTML;
	address.className = "text";
	
	document.getElementById( 'addressValue' ).innerHTML = "";
	document.getElementById( 'addressValue' ).appendChild( document.createElement( 'br' ) );
	document.getElementById( 'addressValue' ).appendChild( address );
	document.getElementById( 'addressValue' ).appendChild( document.createElement( 'br' ) );
	
	var postcode = document.createElement( 'input' );
	postcode.setAttribute( 'type', 'text' );
    postcode.setAttribute( 'id', 'postcode' );
	postcode.setAttribute( 'name', 'postcode' );
	postcode.setAttribute( 'value', document.getElementById( 'postcodeValue' ).innerHTML );
	postcode.className = "text";
	
	document.getElementById( 'postcodeValue' ).innerHTML = "";
	document.getElementById( 'postcodeValue' ).appendChild( document.createElement( 'br' ) );
	document.getElementById( 'postcodeValue' ).appendChild( postcode );
	
	document.getElementById( 'regionStatic' ).style.display = "none";
	document.getElementById( 'regionSelect' ).style.display = "";

	var contactName = document.createElement( 'input' );
	contactName.setAttribute( 'type', 'text' );
    contactName.setAttribute( 'id', 'contactName' );
	contactName.setAttribute( 'name', 'contactName' );
	contactName.setAttribute( 'value', document.getElementById( 'contactNameValue' ).innerHTML );
	contactName.className = "text";
	
	document.getElementById( 'contactNameValue' ).innerHTML = "";
	document.getElementById( 'contactNameValue' ).appendChild( document.createElement( 'br' ) );
	document.getElementById( 'contactNameValue' ).appendChild( contactName );
	
	var contactTelephone = document.createElement( 'input' );
	contactTelephone.setAttribute( 'type', 'text' );
    contactTelephone.setAttribute( 'id', 'contactTelephone' );
	contactTelephone.setAttribute( 'name', 'contactTelephone' );
	contactTelephone.setAttribute( 'value', document.getElementById( 'contactTelephoneValue' ).innerHTML );
	contactTelephone.className = "text";
	
	document.getElementById( 'contactTelephoneValue' ).innerHTML = "";
	document.getElementById( 'contactTelephoneValue' ).appendChild( document.createElement( 'br' ) );
	document.getElementById( 'contactTelephoneValue' ).appendChild( contactTelephone );
	
	var website = document.createElement( 'input' );
	website.setAttribute( 'type', 'text' );
    website.setAttribute( 'id', 'website' );
	website.setAttribute( 'name', 'website' );
	website.setAttribute( 'value', document.getElementById( 'websiteValue' ).innerHTML );
	website.className = "text";
	
	document.getElementById( 'websiteValue' ).innerHTML = "";
	document.getElementById( 'websiteValue' ).appendChild( document.createElement( 'br' ) );
	document.getElementById( 'websiteValue' ).appendChild( website );
	
	document.getElementById( 'contactEditSaveButton' ).href = "javascript:saveContactDetails('" + absolutePath + 
		"','" + webRoot + "','" + participantId + "');";
	
	document.getElementById( 'contactEditSaveButton' ).innerHTML = "save details";
}

// When the save button for the telephone details is clicked update these details in the database, hide the save button,
// revert to static text but with the changed values and re-display the edit button.

function saveContactDetails( absolutePath, webRoot, participantId )
{	
	var name = document.getElementById( 'name' ).value;
	var address = document.getElementById( 'address' ).value;
	var postcode = document.getElementById( 'postcode' ).value;
	var sel = document.getElementById( "region" );
	var region = sel.options[sel.selectedIndex].value;
	var contactName = document.getElementById( 'contactName' ).value;
	var contactTelephone = document.getElementById( 'contactTelephone' ).value;
	var website = document.getElementById( 'website' ).value;
	
	new Ajax.Request( webRoot + '/ajaxPHP/website/UpdateContactDetails.php', {
		method: 'get',
		parameters: 'id=' + participantId + '&' + 'name=' + name + '&' + 'address=' + address + '&' + 
			'postcode=' + postcode + '&' + 'region=' + region + '&' + 'contactName=' + contactName + 
			'&' + 'contactTelephone=' + contactTelephone + '&' + 'website=' + website + '&' + 'absolutePath=' + 
			absolutePath + '&' + 'webRoot=' + webRoot,
		onSuccess: function( transport )
		{
			document.getElementById( 'nameValue' ).innerHTML = name;
			document.getElementById( 'addressValue' ).innerHTML = address;
			document.getElementById( 'postcodeValue' ).innerHTML = postcode;
			document.getElementById( 'regionValue' ).innerHTML = region;
			document.getElementById( 'regionStatic' ).style.display = "";
			document.getElementById( 'regionSelect' ).style.display = "none";
			document.getElementById( 'contactNameValue' ).innerHTML = contactName;
			document.getElementById( 'contactTelephoneValue' ).innerHTML = contactTelephone;
			document.getElementById( 'websiteValue' ).innerHTML = website;
			
			document.getElementById( 'contactEditSaveButton' ).href = "javascript:editContactDetails('" + 
				absolutePath + "','" + webRoot + "','" + participantId + "');";
			
			document.getElementById( 'contactEditSaveButton' ).innerHTML = "edit details";
		}
	});
}

// Is invoked when the edit button used to update the logon details in the myaccount section of the website is
// clicked. This function replaces the static text with HTML text input fields where the details can be changed.

function editLoginDetails( absolutePath, webRoot, participantId )
{
	var participantEmail = document.createElement( 'input' );
	participantEmail.setAttribute( 'type', 'text' );
    participantEmail.setAttribute( 'id', 'email' );
	participantEmail.setAttribute( 'name', 'email' );
	participantEmail.setAttribute( 'value', document.getElementById( 'emailValue' ).innerHTML );
	participantEmail.className = "text";
	
	document.getElementById( 'emailValue' ).innerHTML = "";
	document.getElementById( 'emailValue' ).appendChild( document.createElement( 'br' ) );
	document.getElementById( 'emailValue' ).appendChild( participantEmail );

	var participantPassword = document.createElement( 'input' );
	participantPassword.setAttribute( 'type', 'password' );
    participantPassword.setAttribute( 'id', 'password' );
	participantPassword.setAttribute( 'name', 'password' );
	participantPassword.setAttribute( 'value', document.getElementById( 'passwordValue' ).innerHTML );
	participantPassword.className = "text";
	
	document.getElementById( 'passwordValue' ).innerHTML = "";
	document.getElementById( 'passwordValue' ).appendChild( document.createElement( 'br' ) );
	document.getElementById( 'passwordValue' ).appendChild( participantPassword );
	
	document.getElementById( 'loginEditSaveButton' ).href = "javascript:saveLoginDetails('" + absolutePath + 
		"','" + webRoot + "','" + participantId + "');";
	
	document.getElementById( 'loginEditSaveButton' ).innerHTML = "save details";
}

// When the save button for the logon details is clicked update these details in the database, hide the save button,
// revert to static text but with the changed values and re-display the edit button.

function saveLoginDetails( absolutePath, webRoot, participantId )
{	
	var email = document.getElementById( 'email' ).value;
	var password = document.getElementById( 'password' ).value;
	
	new Ajax.Request( webRoot + '/ajaxPHP/website/UpdateLogonDetails.php', {
		method: 'get',
		parameters: 'id=' + participantId + '&' + 'email=' + email + '&' + 'password=' + password + '&' + 
			'absolutePath=' + absolutePath + '&' + 'webRoot=' + webRoot,
		onSuccess: function( transport )
		{
			document.getElementById( 'emailValue' ).innerHTML = email;
			document.getElementById( 'passwordValue' ).innerHTML = password;
			
			document.getElementById( 'loginEditSaveButton' ).href = "javascript:editLoginDetails('" + absolutePath + 
				"','" + webRoot + "','" + participantId + "');";
	
			document.getElementById( 'loginEditSaveButton' ).innerHTML = "edit details";
		}
	});
}

function editSpaceRequirements( absolutePath, webRoot, participantId )
{
	var location = document.createElement( 'input' );
	location.setAttribute( 'type', 'text' );
    location.setAttribute( 'id', 'location' );
	location.setAttribute( 'name', 'location' );
	location.setAttribute( 'value', document.getElementById( 'locationRequirementValue' ).innerHTML );
	location.className = "text";
	
	document.getElementById( 'locationRequirementValue' ).innerHTML = "";
	document.getElementById( 'locationRequirementValue' ).appendChild( location );

	var within = document.createElement( 'input' );
	within.setAttribute( 'type', 'text' );
    within.setAttribute( 'id', 'within' );
	within.setAttribute( 'name', 'within' );
	within.setAttribute( 'value', document.getElementById( 'withinMilesRequirementValue' ).innerHTML );
	within.className = "text";
	
	document.getElementById( 'withinMilesRequirementValue' ).innerHTML = "";
	document.getElementById( 'withinMilesRequirementValue' ).appendChild( within );
	
	var size = document.createElement( 'input' );
	size.setAttribute( 'type', 'text' );
    size.setAttribute( 'id', 'size' );
	size.setAttribute( 'name', 'size' );
	size.setAttribute( 'value', document.getElementById( 'sizeRequirementValue' ).innerHTML );
	size.className = "text";
	
	document.getElementById( 'sizeRequirementValue' ).innerHTML = "";
	document.getElementById( 'sizeRequirementValue' ).appendChild( size );
	
	var available = document.createElement( 'input' );
	available.setAttribute( 'type', 'text' );
    available.setAttribute( 'id', 'location' );
	available.setAttribute( 'name', 'location' );
	available.setAttribute( 'value', document.getElementById( 'availableFromValue' ).innerHTML );
	available.className = "text";
	
	document.getElementById( 'availableFromValue' ).innerHTML = "";
	document.getElementById( 'availableFromValue' ).appendChild( available );
	
	var artists = document.createElement( 'input' );
	artists.setAttribute( 'type', 'text' );
    artists.setAttribute( 'id', 'artists' );
	artists.setAttribute( 'name', 'artists' );
	artists.setAttribute( 'value', document.getElementById( 'artistsRepresentedValue' ).innerHTML );
	artists.className = "text";
	
	document.getElementById( 'artistsRepresentedValue' ).innerHTML = "";
	document.getElementById( 'artistsRepresentedValue' ).appendChild( artists );
	
	var cost = document.createElement( 'input' );
	cost.setAttribute( 'type', 'text' );
    cost.setAttribute( 'id', 'cost' );
	cost.setAttribute( 'name', 'cost' );
	cost.setAttribute( 'value', document.getElementById( 'costValue' ).innerHTML );
	cost.className = "text";
	
	document.getElementById( 'costValue' ).innerHTML = "";
	document.getElementById( 'costValue' ).appendChild( cost );
	
	var service = document.createElement( 'input' );
	service.setAttribute( 'type', 'text' );
    service.setAttribute( 'id', 'service' );
	service.setAttribute( 'name', 'service' );
	service.setAttribute( 'value', document.getElementById( 'includesServiceChargeValue' ).innerHTML );
	service.className = "text";
	
	document.getElementById( 'includesServiceChargeValue' ).innerHTML = "";
	document.getElementById( 'includesServiceChargeValue' ).appendChild( service );
	
	var insurance = document.createElement( 'input' );
	insurance.setAttribute( 'type', 'text' );
    insurance.setAttribute( 'id', 'insurance' );
	insurance.setAttribute( 'name', 'insurance' );
	insurance.setAttribute( 'value', document.getElementById( 'includesInsuranceValue' ).innerHTML );
	insurance.className = "text";
	
	document.getElementById( 'includesServiceChargeValue' ).innerHTML = "";
	document.getElementById( 'includesServiceChargeValue' ).appendChild( insurance );
	
	var rates = document.createElement( 'input' );
	rates.setAttribute( 'type', 'text' );
    rates.setAttribute( 'id', 'rates' );
	rates.setAttribute( 'name', 'rates' );
	rates.setAttribute( 'value', document.getElementById( 'includesRatesValue' ).innerHTML );
	rates.className = "text";
	
	document.getElementById( 'includesRatesValue' ).innerHTML = "";
	document.getElementById( 'includesRatesValue' ).appendChild( rates );
	
	document.getElementById( 'spaceRequirementsEditSaveButton' ).href = "javascript:saveSpaceRequirements('" + 
		absolutePath + "','" + webRoot + "','" + participantId + "');";
	
	document.getElementById( 'spaceRequirementsEditSaveButton' ).innerHTML = "save details";
}

function saveSpaceRequirements( absolutePath, webRoot, participantId )
{	
	var location = document.getElementById( 'location' ).value;
	var within = document.getElementById( 'within' ).value;
	var size = document.getElementById( 'size' ).value;
	var available = document.getElementById( 'available' ).value;
	var artists = document.getElementById( 'artists' ).value;
	var cost = document.getElementById( 'cost' ).value;
	var service = document.getElementById( 'service' ).value;
	var insurance = document.getElementById( 'insurance' ).value;
	var rates = document.getElementById( 'rates' ).value;
	
	new Ajax.Request( webRoot + '/ajaxPHP/website/UpdateSpaceRequirements.php', {
		method: 'get',
		parameters: 'id=' + participantId + '&' + 'location=' + location + '&' + 'within=' + within + '&' + 'size=' + size + '&' +
			'available=' + available + '&' + 'artists=' + artists + '&' + 'cost=' + cost + '&' + 'service=' + service + '&' +
			'insurance=' + insurance + '&' + 'rates=' + rates + '&' + 'absolutePath=' + absolutePath + '&' + 'webRoot=' + webRoot,
		onSuccess: function( transport )
		{
			document.getElementById( 'locationRequirementValue' ).innerHTML = location;
			document.getElementById( 'withinMilesRequirementValue' ).innerHTML = within;
			document.getElementById( 'sizeRequirementValue' ).innerHTML = size;
			document.getElementById( 'availableFromValue' ).innerHTML = available;
			document.getElementById( 'artistsRepresentedValue' ).innerHTML = artists;
			document.getElementById( 'costValue' ).innerHTML = cost;
			document.getElementById( 'includesServiceChargeValue' ).innerHTML = service;
			document.getElementById( 'includesInsuranceValue' ).innerHTML = insurance;
			document.getElementById( 'includesRatesValue' ).innerHTML = rates;
			
			document.getElementById( 'spaceRequirementsEditSaveButton' ).href = "javascript:editSpaceRequirements('" + 
				absolutePath + "','" + webRoot + "','" + participantId + "');";
			
			document.getElementById( 'spaceRequirementsEditSaveButton' ).innerHTML = "edit details";
		}
	});
}

// Resources can be filtered by hits, user rating and date added. In this case retrieve resources by the date they were added.

function getResourceListByDateAdded( absolutePath, webRoot )
{
	new Ajax.Request( webRoot + '/ajaxPHP/website/GetResourceListByDateAdded.php', {
		method: 'get',
		parameters: 'webRoot=' + webRoot + '&' + 'absolutePath=' + absolutePath,
  		onSuccess: function( transport )
		{
			updateResourcesList( transport.responseText, absolutePath, webRoot );
		}
	});
}

// Resources can be filtered by hits, user rating and date added. In this case retrieve resources by the number of
// times they have been accessed.

function getResourceListByHits( absolutePath, webRoot )
{
	new Ajax.Request( webRoot + '/ajaxPHP/website/GetResourceListByHits.php', {
		method: 'get',
		parameters: 'webRoot=' + webRoot + '&' + 'absolutePath=' + absolutePath,
  		onSuccess: function( transport )
		{
			updateResourcesList( transport.responseText, absolutePath, webRoot );
		}
	});
}

// Resources can be filtered by hits, user rating and date added. In this case retrieve resources by user rating.

function getResourceListByRating( absolutePath, webRoot )
{
	new Ajax.Request( webRoot + '/ajaxPHP/website/GetResourceListByRating.php', {
		method: 'get',
		parameters: 'webRoot=' + webRoot + '&' + 'absolutePath=' + absolutePath,
  		onSuccess: function( transport )
		{
			updateResourcesList( transport.responseText, absolutePath, webRoot );
		}
	});
}

function updateLatestResources( absolutePath, webRoot, type )
{
	var innerHTML = document.getElementById( 'latestresources' ).innerHTML;
	
	var start = innerHTML.indexOf( 'topform' );
	var start = innerHTML.lastIndexOf( '<', start - innerHTML.length );
	
	var end = innerHTML.indexOf( '</div>', start );
	
	if( end == -1 )
		end = innerHTML.indexOf( '</DIV>', start );
		
	end += 6;
	
	var radioList = innerHTML.substring( start, end );
	
	new Ajax.Request( webRoot + '/ajaxPHP/website/UpdateLatestResources.php', {
		method: 'get',
		parameters: 'webRoot=' + webRoot + '&' + 'absolutePath=' + absolutePath + '&' + 'type=' + type,
  		onSuccess: function( transport )
		{
			var contents = transport.responseText;
			
			var start = contents.indexOf( '<div class="topform"' );
			start = ( contents.indexOf( '</div>', start ) ) + 6;
	
			var end = contents.indexOf( '<div id="popularTagsHeader"' );
			
			document.getElementById( 'latestresources' ).innerHTML = radioList + contents.substring( start, end );
			
			document.getElementById( type ).checked = "checked";
		}
	});
}

function createResourceListItem( ulList, details, absolutePath, webRoot )
{
	var idToTitle = details.split( '~' );
				
	var listItem = document.createElement( 'li' );
	var ul = document.getElementById( ulList );			
				
	var detailLink = document.createElement( 'a' );
	detailLink.onclick = function() { displayResourceDetail( absolutePath, webRoot, idToTitle[0] ); };
	
	detailLink.setAttribute( 'href', "javascript:displayResourceDetail('" + absolutePath + "','" + webRoot + "','" + 
		idToTitle[0] + "')" );
	
	detailLink.appendChild( document.createTextNode( idToTitle[1] ) );
				 
	listItem.appendChild( detailLink );
				
	ul.appendChild( listItem );
}

function emptyResourceList( id )
{
	var ul = document.getElementById( id );
	var listItems = ul.getElementsByTagName( 'li' );
	var lenListItems = listItems.length;
	
	for( var i = 0; i < lenListItems; i++ )
		ul.removeChild( listItems[0] );
}

// Provides the reusable behaviour of emptying and populating a list.

function updateResourcesList( resourceDetails, absolutePath, webRoot )
{
	emptyResourceList( 'resourceList1' );
	emptyResourceList( 'resourceList2' );
	emptyResourceList( 'resourceList3' );
	
	var array = resourceDetails.split( '|' );
	var arrayLen = array.length;
	
	if( arrayLen > 0 )
	{
		var end = 3;
		
		if( arrayLen < 3 )
			end = arrayLen;
			
		for( var i = 0; i < end; i++ )
			createResourceListItem( 'resourceList1', array[i], absolutePath, webRoot );
	}
	
	if( arrayLen > 3 )
	{
		var end = 6;
		
		if( arrayLen < 6 )
			end = arrayLen;
			
		for( var i = 3; i < end; i++ )
			createResourceListItem( 'resourceList2', array[i], absolutePath, webRoot );
	}
	
	if( arrayLen > 6 )
	{
		var end = 9;
		
		if( arrayLen < 9 )
			end = arrayLen;
			
		for( var i = 6; i < end; i++ )
			createResourceListItem( 'resourceList3', array[i], absolutePath, webRoot );
	}
}

// Is called when the user clicks on a workspace on the website. The details are retrieved from the database
// and used to populate a template. The template contents are returned (fetched) instead of displayed to allow
// it to be displayed in a shadowbox.

function displayWorkspaceDetail( absolutePath, webRoot, workspaceId, randomPicNo )
{
	var phpScript = webRoot + '/ajaxPHP/website/GetWorkspaceDetail.php?workspaceId=' + workspaceId;
	
	if( randomPicNo !== undefined )
		phpScript += "&randomPicNo=" + randomPicNo;
		
	openShadowbox( 'iframe', phpScript, 710, 727 );
}

function getWorkspaceUnits( absolutePath, webRoot )
{
	var sel = document.getElementById( "workspace" );
	var workspaceId = sel.options[sel.selectedIndex].value;
	
	if( workspaceId != "-----" )
	{
		new Ajax.Request( webRoot + '/ajaxPHP/cms/GetWorkspaceUnits.php', {
			method: 'get',
			parameters: 'webRoot=' + webRoot + '&' + 'absolutePath=' + absolutePath + '&' + 'workspaceId=' + workspaceId,
  			onSuccess: function( transport )
			{
				var array = transport.responseText.split( '|' );
				
				var selectElement = document.getElementById( 'unit' );
				
				for( var i = 0; i < array.length; i++ )
				{
					var temp = array[i].split( '~' );
					
					var o = new Option( temp[1], temp[0], false, false );
					
					selectElement.options[selectElement.options.length] = o;
				}
				
				document.getElementById( 'unitRow' ).style.display = "";
			}
		});
	}
}

// Subscribe to a forum question.

function displayOverviewMap( webRoot )
{
	openShadowbox( "iframe", webRoot + "/ajaxPHP/website/WorkspacesMap.php", 650, 900 );
}

// Subscribe to a forum question.

function subscribeToQuestion( absolutePath, webRoot, questionId )
{
	openShadowbox( "iframe", webRoot + "/ajaxPHP/website/QuestionSubscribe.php?id=" + questionId, 425, 360 );
}

// Load the accordions that exist on the page by performing an is null check in loadAccordion.

function loadAccordions( absolutePath, webRoot, pageTitle )
{
	// Popular Tags Accordions.
	// On click of the expand/collapse link.
	accordions['popularTags'] = loadAccordion( 'populartagsLink', 'populartags', pageTitle );
	
	// Forum Accordions
	accordions['forum'] = loadAccordion( 'forumtopicsLink', 'forumtopics', pageTitle );
	
	// Resources Accordions.
	accordions['resources'] = loadAccordion( 'resourcesLink', 'resources', pageTitle );
	
	// Artist Spaces Accordions.
	accordions['artistSpaces'] = loadAccordion( 'artistsspacesLink', 'artistsspaces', pageTitle );
	
	// Workspaces Accordions.
	accordions['workspaces'] = loadAccordion( 'creativespacesLink', 'creativespaces', pageTitle );
	
	// Toolkit Accordions.
	accordions['toolkit'] = loadAccordion( 'toolkitLink', 'toolkit', pageTitle );
	
	// Forum Detail Accordions.
	accordions['forumDetail'] = loadAccordion( 'communityforumsLink', 'communityforums', pageTitle );
	
	// Latest Artist Space Accordions.
	accordions['latestArtistSpace'] = loadAccordion( 'latestresourcesLink', 'latestresources', pageTitle );
	
	// 360 Gallery Accordions.
	accordions['360Gallery'] = loadAccordion( 'fourcolumnfeatureLink', 'fourcolumnfeature', pageTitle );
	
	// Featured Accordions.
	accordions['feature'] = loadAccordion( 'featureLink', 'feature', pageTitle );
	
	// Latest Workspace Accordions.
	accordions['latestWorkspaces'] = loadAccordion( 'latestworkspacesLink', 'latestworkspaces', pageTitle );
	
	// Favourite Workspaces Accordion in the MyAccount section.
	accordions['favouriteWorkspaces'] = loadAccordion( 'favouriteWorkspacesLink', 'favouriteWorkspaces', pageTitle );
	
	// Waiting List Accordion in the MyAccount section.
	accordions['waitingList'] = loadAccordion( 'waitingListLink', 'waitinglist', pageTitle );
	
	// Favourite Toolkit Accordion in the MyAccount section.
	accordions['favouriteToolkitFiles'] = loadAccordion( 'favouriteToolkitFilesLink', 'favouriteToolkitFiles', pageTitle );

	// Favourite Resources Accordion in the MyAccount section.
	accordions['favouriteResources'] = loadAccordion( 'favouriteResourcesLink', 'favouriteResources', pageTitle );
	
	// Favourite Artist Spaces Accordion in the MyAccount section.
	accordions['favouriteArtistSpaces'] = loadAccordion( 'favouriteArtistSpacesLink', 'favouriteArtistSpaces', pageTitle );
	
	// Favourite Future Spaces Accordion in the MyAccount section.
	accordions['favouriteFutureSpaces'] = loadAccordion( 'favouriteFutureSpacesLink', 'favouriteFutureSpaces', pageTitle );

	// Favourite Forum Questions Accordion in the MyAccount section.
	accordions['favouriteForumQuestions'] = loadAccordion( 'favouriteForumQuestionsLink', 'favouriteForumQuestions', pageTitle );
	
	// Toolkit Accordion.
	accordions['toolkit'] = loadAccordion( 'accordianchartsLink', 'accordiancharts', pageTitle );

	// Search Result Accordions.
	accordions['workspaceResults'] = loadAccordion( 'workspaceResultsLink', 'workspaceResults', pageTitle );
	accordions['resourceResults'] = loadAccordion( 'resourceResultsLink', 'resourceResults', pageTitle );
	accordions['artistspaceResults'] = loadAccordion( 'artistspaceResultsLink', 'artistspaceResults', pageTitle );
	accordions['futurespaceResults'] = loadAccordion( 'futurespaceResultsLink', 'futurespaceResults', pageTitle );
	accordions['questionResults'] = loadAccordion( 'questionResultsLink', 'questionResults', pageTitle );
	accordions['toolkitResults'] = loadAccordion( 'toolkitResultsLink', 'toolkitResults', pageTitle );
	
	accordions['popularTags'] = loadAccordion( 'toolkitKnowledgeLink', 'knowledgeAccordion', pageTitle );
}

// Unsets the PHP session variable controlling whether the user is logged or not and changes
// the logout link text to log in.

function logout( absolutePath, webRoot )
{
	new Ajax.Request( webRoot + '/ajaxPHP/website/Logout.php', {
		method: 'get',
		parameters: 'absolutePath=' + absolutePath + '&' + 'webRoot=' + webRoot,
  		onSuccess: function( transport )
		{
			var array = transport.responseText.split( '\|' );
			var array = new Array( "login", "javascript:displayLogInRegisterForm('','1' )" );
			
			var loginLink = document.getElementById( 'loginLink' );
			loginLink.innerHTML = array[0];
			loginLink.href = array[1];
			
			if( array[0] == "logout" )
			{
				document.getElementById( 'loginMenuLink' ).parentNode.style.display = "";
				document.getElementById( 'registerAccountLink' ).parentNode.style.display = "none";
			}
			else
			{
				document.getElementById( 'loginMenuLink' ).parentNode.style.display = "none";
				document.getElementById( 'registerAccountLink' ).parentNode.style.display = "";
			}
				
			//document.getElementById( 'loginMenuLink' ).href = array[2];
			
			if( window.location.toString().indexOf( 'My' ) != -1 )
				window.location = "index.php";
		}
	});
}

// Load a specific accordion with the trigger identified by clickLink, the accordion content identified by showContent and pageTitle
// controlling whether the initial state of the accordion is expanded or collapsed.

function loadAccordion( clickLink, showContent, pageTitle )
{
	accordion = "";
	accordionClicks = new Array();
	accordionContents = new Array();
	
	var linkId = document.getElementById( clickLink );
	
	if( linkId != null )
	{
		accordionClicks.push( linkId );
	
		var divId = document.getElementById( showContent );
	
		if( divId != null )
			accordionContents.push( divId );

		accordion = new fx.Accordion(accordionClicks, accordionContents);
	
		if( pageTitle == "home" || showContent == "populartags" || 
		   	showContent.indexOf( 'feature' ) != -1  || showContent.indexOf( 'latest' ) != -1 )
		{
			accordion.showThisHideOpen(0);
			
			if( document.getElementById( clickLink ).innerHTML != "view all" )
				document.getElementById( clickLink ).innerHTML = "collapse";
		}
		else
		{
			// The trigger link is usually called expand or collapse (depending on state). However, in the case of the forum the
			// trigger link is the name of a forum question. Only update the link text if it is collapse or expand.
			
			if( document.getElementById( clickLink ).innerHTML == "collapse" )
				document.getElementById( clickLink ).innerHTML = "expand";
		}
	}
	
	return( accordion );
}

// In loadAccordion the link text is expand unless it has been opened by loadAccordion, and in which case it is collapse. This function
// sets the link text after this initial setting. If the link exists and the text is expand the user has clicked to open the accordion.
// Therefore, the link text must be updated to collapse to reflect this. In the same way the link text must be updated to expand if the
// user has clicked an open accordion to close it.

function setActiveMenu( divId )
{
	var linkId = divId + "Link";
	
	if( document.getElementById( linkId ) != null )
	{
		viewAll = 0;
		
		if( document.getElementById( 'viewAllResources' ) != null )
		{
			if( document.getElementById( 'viewAllResources' ).checked )
			{
				if( document.getElementById( divId ).style.visibility == "visible" )
					viewAll = 1;
			}
		}
		
		var innerHTML = document.getElementById( linkId ).innerHTML;
		
		if( innerHTML == "view all" && document.getElementById( divId ).style.visibility == "visible" )
			viewAll = 1;
			
		if( innerHTML == "expand" && viewAll == 0 )
			innerHTML = "collapse";
		else if( innerHTML == "collapse" && viewAll == 0 )
			innerHTML = "expand";
		else if( viewAll == 1 )
		{
			innerHTML = "collapse";
			
			for( name in accordions )
			{
				if( name == "360Gallery" && divId != "latestresources" )
				{
					accordion = accordions[name];
					accordion.showThisHideOpen(0);
					//accordion.showThisHideOpen(0);
				}
				else if( name == "latestArtistSpace" && divId == "latestresources" )
				{
					accordion = accordions[name];
					accordion.showThisHideOpen(0);
					accordion.showThisHideOpen(0);
				}
			}
		}
	
		document.getElementById( linkId ).innerHTML = innerHTML;
	}
}

// Swaps the three images shown in a detail page such as artist spaces with the next 3 images for that
// space. If there aren't another three images it shows as many new images as it can and then the first
// however many images from the start of the image list so that three images are shown.

function seeMoreImages( webRoot )
{
	// Holds the array index position of the next image to display.
	var start = imageIdx;
	
	// Initialise variables to control the end of the loop.
	var end = thumbnailImageToDetailImage.length;
	var after = 0;
	
	// Are there another three images to display?
	if( start + 3 < end )
	{
		// Yes, show next three.
		end = start + 3;
	}
	else
	{
		// No, show all the images to the end of the array and set the after variable to control
		// how many images from the start of the array are shown.
		after = ( start + 3 ) - end;
	}
	
	var imageId = 1;
	
	var diff = end - start;
	
	for( var i = start; i < end; i++ )
	{
		var array = thumbnailImageToDetailImage[i].split( '~' );
		
		var thumbnailImage = array[0];
		var detailImage = array[1];
		
		document.getElementById( 'imageLink' + imageId ).href = "javascript:displayImage('" + webRoot + "','" +
			detailImage + "')";
		
	    document.getElementById( 'image' + imageId ).src = "../../phpThumb_1.7.7/phpThumb.php?h=136&w=190&zc=1&" +
			"q=100&src=../images/artistSpaces/" + thumbnailImage;
			
		imageId++;
	}
	
	if( diff == 1 )
	{
		document.getElementById( 'image2' ).src = "#";
		document.getElementById( 'image3' ).src = "#";
	}
	else if( diff == 2 )
		document.getElementById( 'image3' ).src = "#";
	
	if( end <= thumbnailImageToDetailImage.length )
		document.getElementById( 'seeMoreImagesLink' ).style.display = "none";
}

// Adds a user specified link and link title to the list of links to be added when the resource or artist space is submitted.

function newLink( cmsImages )
{
	// Get the link title entered by the user.
	var title = document.getElementById( 'linkTitle' ).value;
	
	// Get the link URL entered by the user.
	var url = document.getElementById( 'linkUrl' ).value;
	
	if( title.length == 0 || title == "Link Title" )
	{
		alert( "Please provide the title for the link" );
		return;
	}
	
	if( url.length == 0 || url == "Link URL" )
	{
		alert( "Please provide the web address for the link" );
		return;
	}
	
	var li = document.createElement( 'li' );
	li.innerHTML = title;
	
	var value = document.getElementById( 'linkTitleToLinkUrl' ).value;
	
	if( value != "" )
		value += "|";
	
	value += title + "~" + url;
	
	document.getElementById( 'linkTitleToLinkUrl' ).value = value;
	
	document.getElementById( 'linksToBeAdded' ).appendChild( li );
	document.getElementById( 'linksToBeAdded' ).style.display = "";
	
	document.getElementById( 'linkTitle' ).value = "Link Title";
	document.getElementById( 'linkUrl' ).value = "Link URL";
}

function newLink( cmsImages )
{
	// Get the link title entered by the user.
	var title = document.getElementById( 'linkTitle' ).value;
	
	// Get the link URL entered by the user.
	var url = document.getElementById( 'linkUrl' ).value;
	
	if( title.length == 0 || title == "Link Title" )
	{
		alert( "Please provide the title for the link" );
		return;
	}
	
	if( url.length == 0 || url == "Link URL" )
	{
		alert( "Please provide the web address for the link" );
		return;
	}
	
	var li = document.createElement( 'li' );
	li.innerHTML = title;
	
	var value = document.getElementById( 'linkTitleToLinkUrl' ).value;
	
	if( value != "" )
		value += "|";
	
	value += title + "~" + url;
	
	document.getElementById( 'linkTitleToLinkUrl' ).value = value;
	
	document.getElementById( 'linksToBeAdded' ).appendChild( li );
	document.getElementById( 'linksToBeAdded' ).style.display = "";
	
	document.getElementById( 'linkTitle' ).value = "Link Title";
	document.getElementById( 'linkUrl' ).value = "Link URL";
}

function newCMSLink( cmsImages )
{
	// Get the URL entered by the user.
	var url = document.getElementById( 'url' ).value;
	
	if( url.length == 0 )
	{
		alert( "Please provide the web address for the link" );
		return;
	}
	
	// How many links need to be added when the form is submitted?
	var images = document.getElementById( 'linksToBeAdded' ).parentNode.getElementsByTagName( 'img' );
	var len = images.length;
	
	var newLinksCount = 0;
	
	for( i = 0; i < len; i++ )
	{
		// We are only interested in delete images that belong to rows related to headingRow
		if( images[i].id.indexOf( 'newLinkDeleteImage' ) != -1 )
			newLinksCount++;
	}
	
	// A table row should be created for each new link following a heading row.
	var row = document.getElementById( 'linksToBeAdded' );
	var rowIndex = row.rowIndex;
	rowIndex++;
		
	var table = row.parentNode.parentNode;
	
	// Create new row immediately after heading row.
	var row = table.insertRow( rowIndex );
	var rowIdName = 'new_link_' + newLinksCount;
	row.setAttribute( 'id', rowIdName );
	
	// Display the URL of the link in the first column of the new row.
	var column1 = row.insertCell( 0 );
	column1.setAttribute( 'width', '129' );
	var span = column1.appendChild( document.createElement( 'span' ) );
	span.className = 'green';
	span.appendChild( document.createTextNode( url ) );
	column1.appendChild( span );
	
	// The above lines simply display the fact that a link has been added with a URL of ...
	// In order for the link to be added to the thread so that it appears on the website
	// it must be stored in an HTML input element. Data stored in input elements is available
	// to PHP when the thread changes are saved. The above data is not.
	var inputLink = document.createElement( 'input' );
	inputLink.setAttribute( 'type', 'hidden' );
	inputLink.setAttribute( 'id', 'new_link_url' + newLinksCount );
	inputLink.setAttribute( 'name', 'new_link_url' + newLinksCount );
	inputLink.setAttribute( 'value', url );
	column1.appendChild( inputLink );
		
	// The second column of the row contains a delete button that when clicked removes the
	// row. The delete button comprises an image, a link to change the image (rollover) and a link
	// to perform the actual row deletion.
	var column2 = row.insertCell( 1 );
	column2.setAttribute( 'width', '341' );
		
	// Create image element that will act as a button.
	var new_row_button = document.createElement( 'img' );
	new_row_button.setAttribute( 'src', cmsImages + '/ButtonDeleteOut.png' );
	new_row_button.setAttribute( 'width', '45' );
	new_row_button.setAttribute( 'height', '15' );
	new_row_button.setAttribute( 'border', '0' );
	
	// Give each button a unique id/name so we know which delete button was clicked when a row is deleted.
	var deleteButtonIdName = 'newLinkDeleteImage' + newLinksCount;
	new_row_button.setAttribute( 'id', deleteButtonIdName );
	new_row_button.setAttribute( 'name', deleteButtonIdName );
	
	// Onmouseover and onmouseout events change the button image appropriately to show whether it is active.
	// On click of the button use the deleteTableRow Javascript function to remove the link from the list of
	// links to be added.
	var button_link = document.createElement( 'a' );
	button_link.className = "rollover";
	button_link.onclick = function() { deleteTableRow( 'linksToBeAdded', rowIdName, 'newLinkDeleteImage' ); };
	
	// The links should surround the image of the button.
	button_link.appendChild( new_row_button );
	// Add link and image to row column.
	column2.appendChild( button_link );
	
	// Add new columns to new row.
	row.appendChild( column1 );
	row.appendChild( column2 );
		
	// Should row heading.
	document.getElementById( 'linksToBeAdded' ).style.display = "";
	
	// Update the list of event listeners for rollover images.
	setupRollovers();
		
	// If this is the first link being added then add a blank row to separate the link data from the rest
	// of the form.
	
	if( newLinksCount == 0 )
	{
		rowIndex++;
		
		var blankRow = document.getElementById( 'linksToBeAdded' ).parentNode.insertRow( rowIndex );
		var firstColumn = blankRow.insertCell(0);
		var secondColumn = blankRow.insertCell(1);
		firstColumn.nodeValue = "&nbsp;";
		secondColumn.nodeValue = "&nbsp;";
	}
	
	// Clear URL text box to make it quicker to add another link.
	document.getElementById( 'url' ).value = "";
}

function newDownload( cmsImages )
{
	// Get the download title entered by the user.
	var title = document.getElementById( 'downloadTitle' ).value;
	
	// Get the download description entered by the user.
	var description = document.getElementById( 'downloadDescription' ).value;
	
	if( title.length == 0 || title == "Download Title" )
	{
		alert( "Please provide a title for the download" );
		return;
	}
	
	if( description.length == 0 || description == "Download Description" )
	{
		alert( "Please provide a description for the download" );
		return;
	}
	
	var li = document.createElement( 'li' );
	li.innerHTML = title;
	
	document.getElementById( 'downloadsToBeAdded' ).appendChild( li );
	document.getElementById( 'downloadsToBeAdded' ).style.display = "";
	
	document.getElementById( 'downloadTitle' ).value = "Download Title";
	document.getElementById( 'downloadDescription' ).value = "Download Description";
	
	var newElem = document.createElement( 'input' );
	newElem.setAttribute( 'type', 'file' );
	newElem.setAttribute( 'id', 'download' );
	newElem.setAttribute( 'name', 'download' );
	
	var newId = "download" + downloadCount;
	
	document.getElementById( 'download' ).name = newId;
	document.getElementById( 'download' ).id = newId;
	document.getElementById( newId ).style.display = "none";
	
	document.getElementById( 'downloadFileHolder' ).appendChild( newElem );
	
	var value = document.getElementById( 'downloadTitleToDownloadDescription' ).value;
	
	if( value != "" )
		value += "|";
	
	value += newId + "~" + title + "~" + description;
	
	document.getElementById( 'downloadTitleToDownloadDescription' ).value = value;
	
	downloadCount++;
}

// Is a generic function to clear the contents of an input field. It is used by the onfocus event to clear previous input and
// therefore simplify new input.

function clearField( inputId, value )
{
	if( document.getElementById( inputId ).value == value )
		document.getElementById( inputId ).value = "";
}

function openAccordion( accordion )
{
	accordion.showThisHideOpen(0);
}

function displaySearchResults( output )
{
	var resultLists = new Array();
	
	if( output.indexOf( '^' ) != -1 )
		resultLists = output.split( '^' );
	else
		resultLists[0] = output;
		
	var len = resultLists.length;
	
	var usedKeys = new Array();
	
	for( var l = 0; l < len; l++ )
	{
		var array = resultLists[l].split( '#' );
		var key = array[0];
		var results = array[1];
		var prevLink = array[2];
		var nextLink = array[3];
		var totalsText = array[4];
	
		var previousLinkParent = document.getElementById( 'previous' + key + 'Link' );
		var nextLinkParent = document.getElementById( 'next' + key + 'Link' );
				
		document.getElementById( key + 'Totals' ).innerHTML = totalsText;
			
		var ul = document.getElementById( key + 'ResultsList' );
		var listItems = ul.getElementsByTagName( 'li' );
		var lenListItems = listItems.length;
	
		var emptyList = 1;
		
		for( var i = 0; i < usedKeys.length; i++ )
		{
			if( usedKeys[i] == key )
				emptyList = 0;
		}
		
		usedKeys.push( key );
		
		if( emptyList )
		{
			for( var i = 0; i < lenListItems; i++ )
				ul.removeChild( listItems[0] );
		}
		
		var accordion;
			
		for( name in accordions )
		{
			if( name == ( key + "Results" ) )
				accordion = accordions[name];
		}
		
		var visibility = document.getElementById( key + "Results" ).style.visibility;
		
		// Need to check whether already open. Only do this one if accordion is already open as this would
		// close it and the code that follows will re-open with the new results.
		if( lenListItems != 0 )
			accordion.showThisHideOpen(0);

		if( results.length == 0 )
		{
			if( previousLinkParent != null )
				previousLinkParent.style.display = "none";
					
			if( nextLinkParent != null ) 
				nextLinkParent.style.display = "none";
			
			document.getElementById( key + "ResultsLink" ).innerHTML = "expand";
			
			continue;
		}
				
		document.getElementById( key + "ResultsLink" ).innerHTML = "collapse";
		
		var array = new Array();
		
		if( results.indexOf( '|' ) != -1 )
			array = results.split( '|' );
		else
		{
			if( results.length != 0 )
				array[0] = results;
		}
		
		for( var i = 0; i < array.length; i++ )
		{
			var searchResult = array[i].split( '~' );
				
			var listItem = document.createElement( 'li' );

			var detailLink = document.createElement( 'a' );
			detailLink.setAttribute( 'href', searchResult[3] );
					
			var heading = document.createElement( 'h3' );
			heading.className = "colour09";
			heading.appendChild( document.createTextNode( searchResult[0] + '/' + searchResult[1] ) );
				 
			detailLink.appendChild( heading );
			listItem.appendChild( detailLink );
				
			var para = document.createElement( 'p' );
			para.appendChild( document.createTextNode( searchResult[2] ) );
				
			ul.appendChild( listItem );
		}
			
		document.getElementById( key + "Results" ).style.height = "0px";
		accordion.showThisHideOpen(0);
		
		if( nextLink != "" )
		{
			var paginateNext = nextLinkParent.firstChild;
			
			if( paginateNext != null )
				paginateNext.setAttribute( 'href', nextLink );
			
			nextLinkParent.style.display = "";
		}
		else
			nextLinkParent.style.display = "none";
					
		if( prevLink != "" )
		{
			var paginatePrev = previousLinkParent.firstChild;
			
			if( paginatePrev != null )
				paginatePrev.setAttribute( 'href', prevLink );
				
			previousLinkParent.style.display = "";
		}
		else
			previousLinkParent.style.display = "none";
	}
}

function updateSearchResults( absolutePath, webRoot, location )
{
	var keywords = "";
	var nextText = "";
	var nextValue = "";
	var prevText = "";
	var prevValue = "";
	
	if( location === undefined )
		location = window.location.href;
	
	temp = new Array();
	
	if( location.indexOf( '?' ) != -1 )
		temp = location.split( '?' );
	else
	{
		temp[0] = "";
		temp[1] = location;
	}
	
	temp = temp[1].split( '&' );
	var len = temp.length;
	
	for( var i = 0; i < len; i++ )
	{
		var keyToValue = temp[i].split( '=' );
		
		if( keyToValue[0] == "keywords" )
			keywords = keyToValue[1];
		else if( keyToValue[0] == "popularTags" )
			keywords = keyToValue[1];
		else if( keyToValue[0] == "popularTagsSearch" )
			keywords = keyToValue[1];
		else if( keyToValue[0].indexOf( 'next' ) != -1 )
		{
			nextText = keyToValue[0];
			nextValue = keyToValue[1];
		}
		else if( keyToValue[0].indexOf( 'prev' ) != -1 )
		{
			prevText = keyToValue[0];
			prevValue = keyToValue[1];
		}
	}
	
	var parameters = 'keywords=' + keywords + '&' + 'absolutePath=' + absolutePath + '&' + 'webRoot=' + 
		webRoot + '&' + 'ajax=1';
		
	var sel = document.getElementById( "noResultsPerPage" );
	
	if( sel != null )
		parameters += '&' + 'noResultsPerPage=' + sel.options[sel.selectedIndex].value;
	
	var sel = document.getElementById( "dateAdded" );
	
	if( sel != null && sel.selectedIndex != 0 )
		parameters += '&' + 'dateAdded=' + sel.options[sel.selectedIndex].value;

	if( nextText != "" )
		parameters += '&' + nextText + '=' + nextValue;
	
	if( prevText != "" )
		parameters += '&' + prevText + '=' + prevValue;
	
	new Ajax.Request( webRoot + '/Search.php', {
		method: 'get',
		parameters: parameters,
  		onSuccess: function( transport )
		{
			displaySearchResults( transport.responseText );
		}
	});
}

function searchArtistSpaces( absolutePath, webRoot, additionalParams )
{
	var parameters = 'absolutePath=' + absolutePath + '&' + 'webRoot=' + webRoot + '&' + 'ajax=1';
	
	var dateAdded = "";
	
	var nextText = "";
	var nextValue = "";
	var prevText = "";
	var prevValue = "";
	
	var temp = window.location.toString().split('?');
	
	if( additionalParams !== undefined && additionalParams.length != 0 )
		temp[1] += additionalParams;
	
	temp = temp[1].split( '&' );
	var len = temp.length;
	
	for( var i = 0; i < len; i++ )
	{
		var keyToValue = temp[i].split( '=' );
		
		if( keyToValue[0] == "artistSpaceKeywords" )
			parameters += '&' + 'keywords=' + keyToValue[1];
		else if( keyToValue[0] == "region" )
			parameters += '&' + 'region=' + keyToValue[1];
		else if( keyToValue[0] == "dateAdded" )
			dateAdded = keyToValue[1];
		else if( keyToValue[0].indexOf( 'next' ) != -1 )
		{
			nextText = keyToValue[0];
			nextValue = keyToValue[1];
		}
		else if( keyToValue[0].indexOf( 'prev' ) != -1 )
		{
			prevText = keyToValue[0];
			prevValue = keyToValue[1];
		}
	}
	
	var sel = document.getElementById( "noResultsPerPage" );
	
	if( sel != null )
		parameters += '&' + 'noResultsPerPage=' + sel.options[sel.selectedIndex].value;
	
	var sel = document.getElementById( "dateAdded" );
	
	if( sel != null && sel.selectedIndex != 0 )
		parameters += '&' + 'dateAdded=' + sel.options[sel.selectedIndex].value;
	else
	{
		if( dateAdded != "" )
			parameters += '&' + 'dateAdded=' + dateAdded;
	}
	
	if( nextText != "" )
		parameters += '&' + nextText + '=' + nextValue;
	
	if( prevText != "" )
		parameters += '&' + prevText + '=' + prevValue;
	
	new Ajax.Request( webRoot + '/SearchArtistSpaces.php', {
		method: 'get',
		parameters: parameters,
  		onSuccess: function( transport )
		{
			displaySearchResults( transport.responseText );
		}
	});
}

function searchFutureSpaces( absolutePath, webRoot, additionalParams )
{
	var parameters = 'absolutePath=' + absolutePath + '&' + 'webRoot=' + webRoot + '&' + 'ajax=1';

	var dateAdded = "";
	
	var nextText = "";
	var nextValue = "";
	var prevText = "";
	var prevValue = "";
	
	var temp = window.location.toString().split('?');
	
	if( additionalParams !== undefined && additionalParams.length != 0 )
		temp[1] += additionalParams;
	
	temp = temp[1].split( '&' );
	var len = temp.length;
	
	for( var i = 0; i < len; i++ )
	{
		var keyToValue = temp[i].split( '=' );
		
		if( keyToValue[0] == "futureSpaceKeywords" )
			parameters += '&' + 'keywords=' + keyToValue[1];
		else if( keyToValue[0] == "region" )
			parameters += '&' + 'region=' + keyToValue[1];
		else if( keyToValue[0].indexOf( 'dateAdded' ) != -1 )
			dateAdded = keyToValue[1];
		else if( keyToValue[0].indexOf( 'next' ) != -1 )
		{
			nextText = keyToValue[0];
			nextValue = keyToValue[1];
		}
		else if( keyToValue[0].indexOf( 'prev' ) != -1 )
		{
			prevText = keyToValue[0];
			prevValue = keyToValue[1];
		}
	}
	
	var sel = document.getElementById( "noResultsPerPage" );
	
	if( sel != null )
		parameters += '&' + 'noResultsPerPage=' + sel.options[sel.selectedIndex].value;
	
	var sel = document.getElementById( "dateAdded" );
	
	if( sel != null && sel.selectedIndex != 0 )
		parameters += '&' + 'dateAdded=' + sel.options[sel.selectedIndex].value;
	else
	{
		if( dateAdded != "" )
			parameters += '&' + 'dateAdded=' + dateAdded;
	}
	
	if( nextText != "" )
		parameters += '&' + nextText + '=' + nextValue;
	
	if( prevText != "" )
		parameters += '&' + prevText + '=' + prevValue;
	
	new Ajax.Request( webRoot + '/SearchFutureSpaces.php', {
		method: 'get',
		parameters: parameters,
  		onSuccess: function( transport )
		{
			displaySearchResults( transport.responseText );
		}
	});
}

function searchForum( absolutePath, webRoot, additionalParams )
{
	var parameters = 'absolutePath=' + absolutePath + '&' + 'webRoot=' + webRoot + '&' + 'ajax=1';
	
	var dateAdded = "";
	
	var nextText = "";
	var nextValue = "";
	var prevText = "";
	var prevValue = "";
	
	var temp = window.location.toString().split('?');
	
	if( additionalParams !== undefined && additionalParams.length != 0 )
		temp[1] += additionalParams;
	
	temp = temp[1].split( '&' );
	var len = temp.length;
	
	for( var i = 0; i < len; i++ )
	{
		var keyToValue = temp[i].split( '=' );
		
		if( keyToValue[0] == "forumKeywords" )
			parameters += '&' + 'keywords=' + keyToValue[1];
		else if( keyToValue[0] == "dateAdded" )
			dateAdded = keyToValue[1];
		else if( keyToValue[0] == "topic" )
			parameters += '&' + 'topic=' + keyToValue[1];
		else if( keyToValue[0].indexOf( 'next' ) != -1 )
		{
			nextText = keyToValue[0];
			nextValue = keyToValue[1];
		}
		else if( keyToValue[0].indexOf( 'prev' ) != -1 )
		{
			prevText = keyToValue[0];
			prevValue = keyToValue[1];
		}
	}
	
	var sel = document.getElementById( "noResultsPerPage" );
	
	if( sel != null )
		parameters += '&' + 'noResultsPerPage=' + sel.options[sel.selectedIndex].value;
	
	var sel = document.getElementById( "dateAdded" );
	
	if( sel != null && sel.selectedIndex != 0 )
		parameters += '&' + 'dateAdded=' + sel.options[sel.selectedIndex].value;
	else
	{
		if( dateAdded != "" )
			parameters += '&' + 'dateAdded=' + dateAdded;
	}
	
	if( nextText != "" )
		parameters += '&' + nextText + '=' + nextValue;
	
	if( prevText != "" )
		parameters += '&' + prevText + '=' + prevValue;
	
	new Ajax.Request( webRoot + '/SearchForum.php', {
		method: 'get',
		parameters: parameters,
  		onSuccess: function( transport )
		{
			displaySearchResults( transport.responseText );
		}
	});
}

function searchResources( absolutePath, webRoot, additionalParams )
{
	var parameters = 'absolutePath=' + absolutePath + '&' + 'webRoot=' + webRoot + '&' + 'ajax=1';
	
	var dateAdded = "";
	
	var nextText = "";
	var nextValue = "";
	var prevText = "";
	var prevValue = "";
	
	var temp = window.location.toString().split('?');
	
	if( additionalParams !== undefined && additionalParams.length != 0 )
		temp[1] += additionalParams;
	
	temp = temp[1].split( '&' );
	var len = temp.length;
	
	for( var i = 0; i < len; i++ )
	{
		var keyToValue = temp[i].split( '=' );
		
		if( keyToValue[0] == "resourceKeywords" )
			parameters += '&' + 'keywords=' + keyToValue[1];
		else if( keyToValue[0] == "dateAdded" )
			dateAdded = keyToValue[1];
		else if( keyToValue[0] == "popularity" )
			parameters += '&' + 'sortBy=' + keyToValue[1];
		else if( keyToValue[0].indexOf( 'next' ) != -1 )
		{
			nextText = keyToValue[0];
			nextValue = keyToValue[1];
		}
		else if( keyToValue[0].indexOf( 'prev' ) != -1 )
		{
			prevText = keyToValue[0];
			prevValue = keyToValue[1];
		}
	}
	
	var sel = document.getElementById( "noResultsPerPage" );
	
	if( sel != null )
		parameters += '&' + 'noResultsPerPage=' + sel.options[sel.selectedIndex].value;
	
	var sel = document.getElementById( "dateAdded" );
	
	if( sel != null && sel.selectedIndex != 0 )
		parameters += '&' + 'dateAdded=' + sel.options[sel.selectedIndex].value;
	else
	{
		if( dateAdded != "" )
			parameters += '&' + 'dateAdded=' + dateAdded;
	}
	
	if( nextText != "" )
		parameters += '&' + nextText + '=' + nextValue;
	
	if( prevText != "" )
		parameters += '&' + prevText + '=' + prevValue;
	
	new Ajax.Request( webRoot + '/SearchResources.php', {
		method: 'get',
		parameters: parameters,
  		onSuccess: function( transport )
		{
			displaySearchResults( transport.responseText );
		}
	});
}

function searchWorkspaces( absolutePath, webRoot, additionalParams )
{
	var parameters = 'absolutePath=' + absolutePath + '&' + 'webRoot=' + webRoot + '&' + 'ajax=1';
	
	var dateAdded = "";
	
	var nextText = "";
	var nextValue = "";
	var prevText = "";
	var prevValue = "";
	
	var temp = window.location.toString().split('?');
	
	if( additionalParams !== undefined && additionalParams.length != 0 )
		temp[1] += additionalParams;
	
	temp = temp[1].split( '&' );
	var len = temp.length;
	
	for( var i = 0; i < len; i++ )
	{
		var keyToValue = temp[i].split( '=' );
		
		if( keyToValue[0] == "artforms" )
			parameters += '&' + 'artforms=' + keyToValue[1];
		else if( keyToValue[0] == "region" )
			parameters += '&' + 'region=' + keyToValue[1];
		else if( keyToValue[0] == "services" )
			parameters += '&' + 'services=' + keyToValue[1];
		else if( keyToValue[0] == "postcode" )
			parameters += '&' + 'postcode=' + keyToValue[1];
		else if( keyToValue[0] == "workspaceKeywords" )
			parameters += '&' + 'keywords=' + keyToValue[1];
		else if( keyToValue[0] == "dateAdded" )
			dateAdded = keyToValue[1];
		else if( keyToValue[0] == "size" )
			parameters += '&' + 'size=' + keyToValue[1];
		else if( keyToValue[0].indexOf( 'next' ) != -1 )
		{
			nextText = keyToValue[0];
			nextValue = keyToValue[1];
		}
		else if( keyToValue[0].indexOf( 'prev' ) != -1 )
		{
			prevText = keyToValue[0];
			prevValue = keyToValue[1];
		}
	}
	
	var sel = document.getElementById( "noResultsPerPage" );
	
	if( sel != null )
		parameters += '&' + 'noResultsPerPage=' + sel.options[sel.selectedIndex].value;
	
	var sel = document.getElementById( "dateAdded" );
	
	if( sel != null && sel.selectedIndex != 0 )
		parameters += '&' + 'dateAdded=' + sel.options[sel.selectedIndex].value;
	else
	{
		if( dateAdded != "" )
			parameters += '&' + 'dateAdded=' + dateAdded;
	}
	
	if( nextText != "" )
		parameters += '&' + nextText + '=' + nextValue;
	
	if( prevText != "" )
		parameters += '&' + prevText + '=' + prevValue;
	
	new Ajax.Request( webRoot + '/SearchWorkspaces.php', {
		method: 'get',
		parameters: parameters,
  		onSuccess: function( transport )
		{
			displaySearchResults( transport.responseText );
		}
	});
}

function searchWorkspaces2( absolutePath, webRoot, additionalParams )
{
	var parameters = 'absolutePath=' + absolutePath + '&' + 'webRoot=' + webRoot + '&' + 'ajax=1';
	
	var dateAdded = "";
	
	var nextText = "";
	var nextValue = "";
	var prevText = "";
	var prevValue = "";
	
	var temp = window.location.toString().split('?');
	
	if( additionalParams !== undefined && additionalParams.length != 0 )
		temp[1] += additionalParams;
	
	temp = temp[1].split( '&' );
	var len = temp.length;
	
	for( var i = 0; i < len; i++ )
	{
		var keyToValue = temp[i].split( '=' );
		
		if( keyToValue[0] == "artforms" )
			parameters += '&' + 'artforms=' + keyToValue[1];
		else if( keyToValue[0] == "region" )
			parameters += '&' + 'region=' + keyToValue[1];
		else if( keyToValue[0] == "services" )
			parameters += '&' + 'services=' + keyToValue[1];
		else if( keyToValue[0] == "postcode" )
			parameters += '&' + 'postcode=' + keyToValue[1];
		else if( keyToValue[0] == "workspaceKeywords" )
			parameters += '&' + 'keywords=' + keyToValue[1];
		else if( keyToValue[0] == "dateAdded" )
			dateAdded = keyToValue[1];
		else if( keyToValue[0] == "size" )
			parameters += '&' + 'size=' + keyToValue[1];
		else if( keyToValue[0].indexOf( 'next' ) != -1 )
		{
			nextText = keyToValue[0];
			nextValue = keyToValue[1];
		}
		else if( keyToValue[0].indexOf( 'prev' ) != -1 )
		{
			prevText = keyToValue[0];
			prevValue = keyToValue[1];
		}
	}
	
	var sel = document.getElementById( "noResultsPerPage" );
	
	if( sel != null )
		parameters += '&' + 'noResultsPerPage=' + sel.options[sel.selectedIndex].value;
	
	var sel = document.getElementById( "dateAdded" );
	
	if( sel != null && sel.selectedIndex != 0 )
		parameters += '&' + 'dateAdded=' + sel.options[sel.selectedIndex].value;
	else
	{
		if( dateAdded != "" )
			parameters += '&' + 'dateAdded=' + dateAdded;
	}
	
	if( nextText != "" )
		parameters += '&' + nextText + '=' + nextValue;
	
	if( prevText != "" )
		parameters += '&' + prevText + '=' + prevValue;
	
	new Ajax.Request( webRoot + '/SearchWorkspaces2.php', {
		method: 'get',
		parameters: parameters,
  		onSuccess: function( transport )
		{
			displaySearchResults( transport.responseText );
		}
	});
}

function navigateForumQuestions( absolutePath, webRoot, colorClass, location )
{
	var topicId = "";
	var nextValue = "";
	var prevValue = "";
	
	if( location === undefined )
		location = window.location.href;
	
	temp = location.split( '&' );
	var len = temp.length;
	
	for( var i = 0; i < len; i++ )
	{
		var keyToValue = temp[i].split( '=' );
		
		if( keyToValue[0] == "topicId" )
			topicId = keyToValue[1];
		else if( keyToValue[0].indexOf( 'next' ) != -1 )
			nextValue = keyToValue[1];
		else if( keyToValue[0].indexOf( 'prev' ) != -1 )
			prevValue = keyToValue[1];
	}
	
	var parameters = 'topicId=' + topicId + '&' + 'absolutePath=' + absolutePath + '&' + 'webRoot=' + webRoot + 
		'&' + 'ajax=1';
		
	if( nextValue != "" )
		parameters += '&next=' + nextValue;
	
	if( prevValue != "" )
		parameters += '&prev=' + prevValue;
	
	new Ajax.Request( webRoot + '/Forum.php', {
		method: 'get',
		parameters: parameters,
  		onSuccess: function( transport )
		{
			var array = transport.responseText.split( '#' );
			var temp = array[0].split( '~' );
			var questionId = temp[0];
			var title = temp[1];
			var postTotal = temp[2];
			var lastPostDate = temp[3];
			var lastPostParticipant = temp[4];
			var prevLink = array[1];
			var nextLink = array[2];
			
			var rows = document.getElementsByClassName( 'row' );
			var len = rows.length;
			
			for( var i = 0; i < len; i++ )
			{
				if( rows[i].parentNode.id.indexOf( 'questionlist' + topicId ) != -1 )
				{
					var innerHTML = rows[i].innerHTML;
					
					var detailLink = "<a href=" + '"' + "javascript:displayForumQuestion('" + absolutePath + "','" + 
						webRoot + "','" + questionId + "')" + '">';

					var idxCol1 = innerHTML.indexOf( 'col1' );
					var idxCol1 = innerHTML.indexOf( '>', idxCol1 );
					idxCol1++;
					var idxEnd = innerHTML.indexOf( '</div>', idxCol1 );
					
					innerHTML = innerHTML.substring( 0, idxCol1 ) + detailLink + title + "</a>" + 
						innerHTML.substring( idxEnd, innerHTML.length );
					
					var idxCol3 = innerHTML.indexOf( 'col3' );
					var idxCol3 = innerHTML.indexOf( '>', idxCol3 );
					idxCol3++;
					var idxEnd = innerHTML.indexOf( '<', idxCol3 );
					
					innerHTML = innerHTML.substring( 0, idxCol3 ) + postTotal + 
						innerHTML.substring( idxEnd, innerHTML.length );
					
					var idxCol4 = innerHTML.indexOf( 'col4' );
					var idxCol4 = innerHTML.indexOf( '>', idxCol4 );
					idxCol4++;
					var idxEnd = innerHTML.indexOf( '</div>', idxCol4 );
					
					innerHTML = innerHTML.substring( 0, idxCol4 ) + lastPostDate + '<br />' +
						'<span class="colour' + colorClass + '">' + lastPostParticipant + '</span></p>' +
						innerHTML.substring( idxEnd, innerHTML.length );
					
					rows[i].innerHTML = innerHTML;
					
					if( prevLink == "" || prevLink === undefined )
						document.getElementById( 'prevquestions' + topicId + 'Link' ).style.display = "none";
					else
					{
						document.getElementById( 'prevquestions' + topicId + 'Link' ).href = prevLink;
						document.getElementById( 'prevquestions' + topicId + 'Link' ).style.display = "";
					}
					
					if( nextLink == "" || nextLink === undefined )
						document.getElementById( 'nextquestions' + topicId + 'Link' ).style.display = "none";
					else
					{
						document.getElementById( 'nextquestions' + topicId + 'Link' ).href = nextLink;
						document.getElementById( 'nextquestions' + topicId + 'Link' ).style.display = "";
					}
				}
			}
		}
	});
}

function checkResidentArtist( absolutePath, webRoot )
{
	var postcode = document.getElementById( 'postcode' ).value;
	
	new Ajax.Request( webRoot + '/ajaxPHP/website/CheckResidentArtist.php', {
		method: 'get',
		parameters: 'postcode=' + postcode + '&' + 'webRoot=' + webRoot + '&' + 'absolutePath=' + absolutePath,
  		onSuccess: function( transport )
		{
			var array = transport.responseText.split( '|' );
			var len = array.length;
			
			var selectElement = document.getElementById( 'addresses' );
			
			for( var i = 0; i < len; i++ )
			{
				var temp = array[i].split( '~' );
				
				var o = new Option( temp[1], temp[0], false, false );
				selectElement.options[selectElement.options.length] = o;
			}
			
			if( len != 0 )
				selectElement.style.display = "";
		}
	});
}

function deleteCurrent( idToDelete, prefix, hiddenIdName )
{
	try
	{
	var hiddenId = prefix + "Hidden" + idToDelete;
	document.getElementById( hiddenId ).parentNode.removeChild( document.getElementById( hiddenId ) );
	var linkId = prefix + "Link" + idToDelete;
	document.getElementById( linkId ).parentNode.removeChild( document.getElementById( linkId ) );
	var paraId = prefix + idToDelete;
	document.getElementById( paraId ).parentNode.removeChild( document.getElementById( paraId ) );
	
	var array = document.getElementById( hiddenIdName ).value.split( '\|' );
	document.getElementById( hiddenIdName ).value = "";
	var len = array.length;
	
	for( var i = 0; i < len; i++ )
	{
		var temp = array[i].split( '~' );
		
		if( temp[0] != idToDelete )
		{
			if( document.getElementById( hiddenIdName ).value != "" )
				document.getElementById( hiddenIdName ).value += "|";
			
			document.getElementById( hiddenIdName ).value += array[i];
		}
	}
	
	if( document.getElementById( hiddenIdName ).value.length == 0 )
	{
		document.getElementById( prefix + 'sHeader' ).parentNode.removeChild
			( document.getElementById( prefix + 'sHeader' ) );
	}
	}
	catch( err )
	{
		alert( err );
	}
}

function addImage()
{
	var innerHTML = document.getElementById( 'downloadLink' ).innerHTML;
	
	var idxHREF = innerHTML.indexOf( 'href' );
	var start = innerHTML.indexOf( '"', idxHREF );
	start++;
	var end = innerHTML.indexOf( '"', start );
	
	if( document.getElementById( 'cropDetails' ).value != "" )
		document.getElementById( 'cropDetails' ).value += "|";
		
	document.getElementById( 'cropDetails' ).value += innerHTML.substring( start, end );
	
	document.getElementById( 'imageContainer' ).innerHTML = "";
	document.getElementById( 'downloadLink' ).innerHTML = "";
	
	document.getElementById( 'selectCropRow' ).style.display = "none";
	document.getElementById( 'addCroppedImageRow' ).style.display = "none";
	
	document.getElementById( 'imagesToBeAdded' ).style.display = "";
	
	var filename = document.getElementById( 'uploadImage' ).value;
	var basename = "";
	
	if( filename.indexOf( '/' ) != -1 )
		basename = filename.substring( filename.lastIndexOf( '/' ) + 1, filename.length );
	else
		basename = filename.substring( filename.lastIndexOf( '\\' ) + 1, filename.length );
		
	var listItem = document.createElement( 'li' );
	listItem.innerHTML = basename;
	
	document.getElementById( 'imagesToBeAddedHeader' ).style.display = "";
	document.getElementById( 'imagesToBeAdded' ).style.display = "";
	document.getElementById( 'imagesToBeAdded' ).appendChild( listItem );
	
	var newElem = document.createElement( 'input' );
	newElem.setAttribute( 'type', 'file' );
	newElem.setAttribute( 'id', 'uploadImage' );
	newElem.setAttribute( 'name', 'uploadImage' );
	
	var remElem = document.getElementById( 'uploadImage' );
	
	remElem.parentNode.replaceChild( newElem, remElem );
	YAHOO.util.Event.on('uploadButton', 'click', uploader.carry);
	
	if( document.getElementById( 'imageDescription' ) != null )
		document.getElementById( 'imageDescription' ).value = "Image Description";
		
	document.getElementById( "submitFormContainer" ).style.width = originalSubmitContainerWidth;
							
	shadowboxHeight = document.getElementById( 'submitFormContainer' ).offsetHeight;
	window.parent.Shadowbox.adjustDims(shadowboxHeight,originalShadowboxWidth); 
}

function swapImage( id, status )
{
	var exists = 0;
	
	for( var i = 0; i < clickedCircles.length; i++ )
	{
		if( clickedCircles[i] == id )
			exists = 1;
	}
	
	if( exists == 0 )
	{
		if( status == 1 )
		{
			document.getElementById( 'black' + id ).style.zIndex = 1;
			document.getElementById( 'green' + id ).style.zIndex = 2;
			document.getElementById( 'black' + id + "Total" ).className = "colour" + colourClass;
			document.getElementById( 'black' + id + "Title" ).className = "colour" + colourClass;
			
			if( document.getElementById( 'blackknowledge1' ) == null )
			{
				for( var i = 0; i < clickedCircles.length; i++ )
				{
					if( clickedCircles[i] != id )
					{
						document.getElementById( 'black' + clickedCircles[i] ).style.zIndex = 2;
						document.getElementById( 'green' + clickedCircles[i] ).style.zIndex = 1;
						document.getElementById( 'black' + clickedCircles[i] + "Total" ).className = "";
						document.getElementById( 'black' + clickedCircles[i] + "Title" ).className = "";
						clickedCircles.splice( i, 1 );
					}
				}
			}
		}
		else
		{
			document.getElementById( 'black' + id ).style.zIndex = 2;
			document.getElementById( 'green' + id ).style.zIndex = 1;
			document.getElementById( 'black' + id + "Total" ).className = "";
			document.getElementById( 'black' + id + "Title" ).className = "";
		}
	}
}

function startStopMouseout( id, fileId, type )
{
	var exists = 0;
	var alreadyClickedQuestion = 0;
	var alreadyClickedFile = 0;
	
	for( var i = 0; i < clickedCircles.length; i++ )
	{
		if( clickedCircles[i] == id )
		{
			clickedCircles.splice( i, 1 );
			exists = 1;
		}
		
		else if( clickedCircles[i].indexOf( 'Cat' ) != -1 && id.indexOf( 'Cat' ) != -1 )
		{
			document.getElementById( 'black' + clickedCircles[i] ).style.zIndex = 2;
			document.getElementById( 'green' + clickedCircles[i] ).style.zIndex = 1;
			
			clickedCircles.splice( i, 1 );
		}
	}
	
	if( exists == 0 )
		clickedCircles.push( id );
	
	if( fileId !== undefined )
	{
		if( type == "knowledge" )
			getToolkitKnowledgeDetail( absolutePath, webRoot, fileId );
		else if( type == "knowHow" )
			getToolkitKnowHowDetail( absolutePath, webRoot, fileId );
	}
}

function displayVideo( filename )
{
	Shadowbox.init();
	
	Shadowbox.open({
		type:	'qt',
        content:	filename,
		height:	530,
		width: 920
    });
}