
function checkMandatoryFields( element )
{
	var error = 0;
	var message = "";
	
	if( element.name.indexOf( "picture" ) != -1 )
	{
		if( document.getElementById( 'pictureAltTag' ).value.length == 0 )
		{
			message += "Please provide alternative text for the picture. ";
			error = 1;
		}
	}
	else if( element.name.indexOf( "download" ) != -1 )
	{
		if( document.getElementById( 'downloadTitle' ).value.length == 0 )
		{
			message += "Please provide a title for the download. ";
			error = 1;
		}
	}
	
	if( message.length > 0 )
		alert( message );
		
	return( error );
}

function storeMandatoryFields( element, rowToAppendTo )
{
	if( element.name.indexOf( "picture" ) != -1 )
	{
		var altTag = document.createElement( 'input' );
		altTag.type = 'hidden';
		altTag.value = document.getElementById( 'pictureAltTag' ).value;
		altTag.name = element.name + '_altTag';
		
		rowToAppendTo.appendChild( altTag );
		
		document.getElementById( 'pictureAltTag' ).value = "";
		
		var embedCode = document.createElement( 'input' );
		embedCode.type = 'hidden';
		embedCode.value = document.getElementById( 'embedCode' ).value;
		embedCode.name = element.name + '_embedCode';
		
		rowToAppendTo.appendChild( embedCode );
		
		document.getElementById( 'embedCode' ).value = "";
		
		var vimeoCode = document.createElement( 'input' );
		vimeoCode.type = 'hidden';
		vimeoCode.value = document.getElementById( 'vimeoCode' ).value;
		vimeoCode.name = element.name + '_vimeoCode';
		
		rowToAppendTo.appendChild( vimeoCode );
		
		document.getElementById( 'vimeoCode' ).value = "";
		
		var videoType = document.createElement( 'input' );
		videoType.type = 'hidden';
		
		radioGrp = document.getElementsByName( 'videoType' );
		
		for( i = 0; i < radioGrp.length; i++ )
		{
			if( radioGrp[i].checked )
				videoType.value = radioGrp[i].value;
		}
		
		videoType.name = element.name + '_videoType';
		
		rowToAppendTo.appendChild( videoType );
	}
	else if( element.name.indexOf( "download" ) != -1 )
	{
		var title = document.createElement( 'input' );
		title.type = 'hidden';
		title.value = document.getElementById( 'downloadTitle' ).value;
		title.name = element.name + '_title';
		
		rowToAppendTo.appendChild( title );
		
		document.getElementById( 'downloadTitle' ).value = "";
	}
}

function updateDisplayOrder( ulListId )
{
	try
	{
	var list = document.getElementById( ulListId );
	var items = list.getElementsByTagName( "li" );
	var len = items.length;
		
	var order = new Array();
		
	for( i = 0; i < len; i++ )
	{
		var html = items[i].innerHTML.toLowerCase();
		
		var idxId = html.indexOf( '.php?' );
		
		if( idxId != -1 )
		{
			var idxEqual = html.indexOf( '=', idxId );
			idxEqual++;
			var idxQuote = html.indexOf( '"', idxEqual );
			order.push( html.substring( idxEqual, idxQuote ) );
		}
		else
			order.push( items[i].id );
	}
	
	new Ajax.Request( webRoot + '/includes/UpdateDisplayOrder.php', {
		method: 'get',
		parameters: 'order=' + order.join( "," ) + '&' + 'webRoot=' + webRoot + '&' + 'absolutePath=' + 
			absolutePath + '&' + 'sessionVariableName=' + ulListId,
  		onSuccess: function( transport ){
		}
	});
	}
	catch( err )
	{
		alert( err );
	}
}

function updateDisplayOrder2()
{
	var list = document.getElementById( 'boxes' );
	var items = list.getElementsByTagName( "li" );
	var len = items.length;
		
	var order = "";
		
	for( i = 0; i < len; i++ )
	{
		var html = items[i].innerHTML.toLowerCase();
		
		var idxId = html.indexOf( '.php?id=' );
		var idxEqual = html.indexOf( '=', idxId );
		idxEqual++;
		var idxQuote = html.indexOf( '"', idxEqual );
		id = html.substring( idxEqual, idxQuote );
		var href = document.getElementById( 'featuredItem_' + id + "_link" ).href;
			
		if( order != "" )
			order += ",";
			
		var script = href.substring( href.lastIndexOf( '/' ) + 1, href.lastIndexOf( '?' ) );
		var id = href.substring( href.lastIndexOf( '=' ) + 1, href.length );
		
		order += script + "~" + id;
	}
	
	new Ajax.Request( webRoot + '/includes/UpdateDisplayOrder2.php', {
		method: 'get',
		parameters: 'order=' + order + '&' + 'absolutePath=' + absolutePath,
  		onSuccess: function( transport ){
		}
	});
}

function deleteFromOrderedList( ulListId, checkboxIdName, liIdName )
{
	var checkBoxGrp = document.getElementsByName( checkboxIdName );
	var len = checkBoxGrp.length;
	
	var idxOfCheck = 0;
	
	for( i = 0; i < len; i++ )
	{
		if( checkBoxGrp[i].checked )
			idxOfCheck = i;
	}

	var list = document.getElementById( ulListId );
	var items = list.getElementsByTagName( "li" );
	
	var html = items[idxOfCheck].innerHTML;
	
	var idxDelete = html.indexOf( checkboxIdName );
	
	var idxValue = html.indexOf( 'value=', idxDelete );
	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( 0, array[6].length - 1 );
	
	var success = deleteFromDatabase( absolutePath, webRoot, checkBoxName, tableNameToColumnName,
		thingBeingRemoved, noDataRows );
	
	if( success == 1 || typeof( success ) == "undefined" )
	{
		liIdName += "_" + id;
		
		var child = document.getElementById( liIdName );
		var parent = child.parentNode;
		
		parent.removeChild( child );
	
		if( getNumRows( checkboxIdName ) == 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 = "";
			}
		}
	}
}

function updateDatabase( absolutePath, webRoot, checkBoxName, tableNameToColumnName, value )
{
	var checkBoxGrp = document.getElementsByName( checkBoxName );
	
	var status = 0;
	
	if( checkBoxGrp[0].type == "checkbox" )
	{
		for( var i = 0; i < checkBoxGrp.length; i++ )
		{
			if( checkBoxGrp[i].checked && checkBoxGrp[i].value == value )
				status = 1;
		}
	}
	else if( checkBoxGrp[0].type == "radio" )
	{
		for( var i = 0; i < checkBoxGrp.length; i++ )
		{
			if( checkBoxGrp[i].checked )
				status = checkBoxGrp[i].value;
		}
	}
	
	new Ajax.Request( webRoot + '/includes/UpdateDatabase.php', {
		method: 'get',
		parameters: 'tableNameToColumnName=' + tableNameToColumnName + '&' + 'webRoot=' + webRoot + '&' + 
			'absolutePath=' + absolutePath + '&' + 'status=' + status,
  		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 + "?" ))
	{
		alert('here');
		
		// Using Ajax to delete the row from the database.
		new Ajax.Request( webRoot + '/includes/DeleteFromDatabase.php', {
			method: 'get',
			parameters: 'tableNameToColumnName=' + tableNameToColumnName + '&' + 'webRoot=' + webRoot + '&' + 
				'absolutePath=' + absolutePath,
  			onSuccess: function( transport )
			{
				var table;
				var rows;
				
				if( typeof( headingRow ) !== "undefined" )
				{
					var row = document.getElementById( headingRow );
					var start = row.rowIndex;
					var numRowsKey = headingRow.substring( 0, headingRow.indexOf( 'Row' ) + 3 );
					var numRows = getNumRows( numRowsKey );
					
					table = row.parentNode.parentNode;
					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;
					}
				
					if( end == -1 )
						end = len;
				
					for( i = start; i < end; i++ )
					{
						// Delete the table row from the HTML document.
						table.deleteRow( start );
					
						// Decrement the value of the variable that indicates how many rows are left in the table.
						numRows--;
					}
					
					if( numRows != 0 )
					{
						if( start != 0 )
						{
							start--;
						
							if( rows[start].innerHTML.indexOf( '<td>&nbsp;</td>' ) != -1 )
							{
								document.getElementById( 'contentRows' ).deleteRow( start );
								numRows--;
							}
						}
						else if( rows[start].innerHTML.indexOf( '<td>&nbsp;</td>' ) != -1 )
						{
							document.getElementById( 'contentRows' ).deleteRow( start );
							numRows--;
						}
						else if( start + 1 != rows.length )
						{
							start++;
						
							if( rows[start].innerHTML.indexOf( '<td>&nbsp;</td>' ) != -1 )
							{
								document.getElementById( 'contentRows' ).deleteRow( start );
								numRows--;
							}
						}
					}
				}
				
				for( var i = 1; i < rows.length; i++ )
				{
					if( rows[i].innerHTML.indexOf( '<td>&nbsp;</td>' ) != -1 )
					{
						table.deleteRow( i );
						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 = "";
					}
				}
				
				return( 1 );
			}
		});
	}
	else
	{
		var checkBoxGrp = document.getElementsByName( checkBoxName );
		var len = checkBoxGrp.length;
		
		for( i = 0; i < len; i++ )
		{
			if( checkBoxGrp[i].checked )
				checkBoxGrp[i].checked = false;
		}
		
		return( 0 );
	}
}

function getNumRows( key )
{
	key = key.toLowerCase();
	
	var contents = document.body.innerHTML.toLowerCase();
	
	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 );
}

/*
 * 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";
	}
}
 
function deleteProductSizeRow( rowIdName )
{
	var table = document.getElementById( rowIdName ).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( rowIdName ) );
	
	if( table.rows.length == 1 )
	{
		table.deleteRow( 0 );
		document.getElementById( 'currentSizesRow' ).style.display = "none";
	}
}

/*
 * Delete a picture, download or link given the parent div to which each div is appended.
 */
 
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 );
	}
}

function updateBackgroundColour( absolutePath, webRoot, backgroundColour )
{
	new Ajax.Request( webRoot + '/includes/UpdateBackgroundColour.php', {
		method: 'get',
		parameters: 'backgroundColour=' + backgroundColour + '&' + 'absolutePath=' + absolutePath,
  		onSuccess: function( transport )
		{
		}
	});
}

function showHideProductSizes()
{
	var display = "none";
	
	if( document.getElementById( 'chooseSizes' ).checked )
		display = "";
	
	document.getElementById( 'sizeHeader' ).style.display = display;
	document.getElementById( 'sizeDescriptionHeader' ).style.display = display;
	document.getElementById( 'sizeDescriptionRow' ).style.display = display;
	document.getElementById( 'colourQuantitiesHeader' ).style.display = display;
	document.getElementById( 'colourDescriptionHeader' ).style.display = display;
	document.getElementById( 'colourDescriptionRow' ).style.display = display;
	document.getElementById( 'colourQuantityHeader' ).style.display = display;
	document.getElementById( 'colourQuantityRow' ).style.display = display;
	document.getElementById( 'sizePriceHeader' ).style.display = display;
	document.getElementById( 'sizePriceRow' ).style.display = display;
	document.getElementById( 'postagePriceHeader' ).style.display = display;
	document.getElementById( 'postagePriceRow' ).style.display = display;
	document.getElementById( 'addColourQuantityRow' ).style.display = display;
	document.getElementById( 'blankColourQuantityRow' ).style.display = display;
}

function addColourQuanity()
{
	var sizeDescription = document.getElementById( 'sizeDescription' ).value;
	var colourDescription = document.getElementById( 'colourDescription' ).value;
	var colourQuantity = document.getElementById( 'colourQuantity' ).value;
	var sizePrice = document.getElementById( 'sizePrice' ).value;
	var postagePrice = document.getElementById( 'postagePrice' ).value;
	
	var row = document.getElementById( "sizesToBeAdded" );
	row.style.display = "";
	var rowIndex = row.rowIndex;
	rowIndex++;
	var table = row.parentNode.parentNode;
	
	var row = table.insertRow( rowIndex );
	
	var newSizeDetails = sizeDescription + " - " + colourDescription + " - " + colourQuantity + " - " +
		sizePrice + " - " + postagePrice;
	
	if( sizeDetails != "" )
		sizeDetails += "|";
	
	sizeDetails += sizeDescription + "~" + colourDescription + "~" + colourQuantity + "~" + sizePrice + "~" +
		postagePrice;
	
	var column1 = row.insertCell( 0 );
	column1.setAttribute( 'colspan', '2' );
	column1.setAttribute( 'className', 'white' );
	var span = column1.appendChild( document.createElement( 'span' ) );
	span.className = 'white';
	span.appendChild( document.createTextNode( newSizeDetails ) );
	column1.appendChild( span );
	
	row.appendChild( column1 );
	
	document.getElementById( 'sizeDescription' ).value = "";
	document.getElementById( 'colourDescription' ).value = "";
	document.getElementById( 'colourQuantity' ).value = "";
	document.getElementById( 'sizePrice' ).value = "";
	document.getElementById( 'postagePrice' ).value = "";
	
	document.getElementById( "blankSizesRow" ).style.display = "";
}

function forgottenPassword( absolutePath, webRoot )
{
	var email = document.getElementsByName( 'emailTB' )[0].value;
	
	if( email.length == 0 )
		return;
		
	new Ajax.Request( webRoot + '/shopping/forgotten_password.php', {
		method: 'get',
		parameters: 'emailTB=' + email + '&' + 'absolutePath=' + absolutePath,
  		onSuccess: function( transport )
		{
			document.getElementById( 'message' ).innerHTML = transport.responseText;
			document.getElementById( 'message' ).style.display = "";
			document.getElementsByName( 'emailTB' )[0].value = "";
		}
	});
}

function getProducts( absolutePath, webRoot, filterColumn )
{
	new Ajax.Request( webRoot + '/includes/GetProducts.php', {
		method: 'get',
		parameters: 'filterColumn=' + filterColumn + '&' + 'absolutePath=' + absolutePath,
  		onSuccess: function( transport )
		{
			var div = document.getElementById( 'main_content' );
			var ulList = div.getElementsByTagName( 'ul' );
			
			var products = transport.responseText.split( '\|' );
			var productsLen = products.length;
			
			for( var i = 0; i < productsLen; i++ )
				ulList[i+2].innerHTML = products[i];
			
			for( var i = productsLen + 2; i < ulList.length; i++ )
				ulList[i].innerHTML = "";
			
			if( filterColumn.indexOf( "Online" ) != -1 )
			{
				document.getElementById( "allLink" ).className = "radio";
				document.getElementById( "onlineLink" ).className = "radio_selected";
				document.getElementById( "contractLink" ).className = "radio";
			}
			else if( filterColumn.indexOf( "Contract" ) != -1 )
			{
				document.getElementById( "allLink" ).className = "radio";
				document.getElementById( "onlineLink" ).className = "radio";
				document.getElementById( "contractLink" ).className = "radio_selected";
			}
			else if( filterColumn.indexOf( "All" ) != -1 )
			{
				document.getElementById( "allLink" ).className = "radio_selected";
				document.getElementById( "onlineLink" ).className = "radio";
				document.getElementById( "contractLink" ).className = "radio";
			}
			
			var type = "All";
			
			if( document.getElementById( "onlineLink" ).className == "radio_selected" )
				type = "Online";
			
			else if( document.getElementById( "contractLink" ).className == "radio_selected" )
				type = "Contract";
			
			if( filterColumn == type || filterColumn == "Newest First" || filterColumn == "Oldest First" )
			{
				var div = document.getElementById( 'breadcrumb_trail' );
				var ul = div.getElementsByTagName( 'ul' )[0];
			
				var innerHTML = '<li>YOU ARE HERE:</li><li><a href="index.php">Home</a></li><li>|</li>' +
					'<li><a href="Products.php">Products</a></li><li>|</li>';
				
				if( type == "Online" || type == "Contract" )
				{
					innerHTML += '<li><a ';
			
					if( type == filterColumn )
						innerHTML += 'class="selected"';
					else
						innerHTML += 'href="Products.php?type=' + type + '"';
			
					innerHTML += '>'; 
				
					if( type == "Online" )
						innerHTML += "To Buy Online";
					else if( type == "Contract" )
						innerHTML += "For Contract Use";
					
					innerHTML += '</a></li><li>|</li>';
				}
				
				if( type != filterColumn )
					innerHTML += '<li><a class="selected">' + filterColumn + '</a></li>';
			
				ul.innerHTML = innerHTML;
			}
		}
	});
}

function getPress( absolutePath, webRoot, filterColumn )
{
	new Ajax.Request( webRoot + '/includes/GetPress.php', {
		method: 'get',
		parameters: 'filterColumn=' + filterColumn + '&' + 'absolutePath=' + absolutePath,
  		onSuccess: function( transport )
		{
			var div = document.getElementById( 'main_content' );
			var ulList = div.getElementsByTagName( 'ul' );
			
			var press = transport.responseText.split( '\|' );
			var pressLen = press.length;
			
			for( var i = 0; i < pressLen; i++ )
				ulList[i+1].innerHTML = press[i];
			
			for( var i = pressLen + 1; i < ulList.length; i++ )
				ulList[i].innerHTML = "";
			
			if( filterColumn == "Release" )
			{
				document.getElementById( "allLink" ).className = "radio";
				document.getElementById( "releaseLink" ).className = "radio_selected";
				document.getElementById( "receivedLink" ).className = "radio";
			}
			else if( filterColumn == "Received" )
			{
				document.getElementById( "allLink" ).className = "radio";
				document.getElementById( "releaseLink" ).className = "radio";
				document.getElementById( "receivedLink" ).className = "radio_selected";
			}
			else if( filterColumn == "All" )
			{
				document.getElementById( "allLink" ).className = "radio_selected";
				document.getElementById( "releaseLink" ).className = "radio";
				document.getElementById( "receivedLink" ).className = "radio";
			}
			
			var type = "All";
			
			if( document.getElementById( "releaseLink" ).className == "radio_selected" )
				type = "Press Release";
			
			else if( document.getElementById( "receivedLink" ).className == "radio_selected" )
				type = "Received Press";
			
			if( filterColumn == type || filterColumn == "Newest First" || filterColumn == "Oldest First" )
			{
				var div = document.getElementById( 'breadcrumb_trail' );
				var ul = div.getElementsByTagName( 'ul' )[0];
			
				var innerHTML = '<li>YOU ARE HERE:</li><li><a href="index.php">Home</a></li><li>|</li>' +
					'<li><a href="Press.php">Press</a></li><li>|</li><li><a ';
			
				if( type == filterColumn )
					innerHTML += 'class="selected"';
				else
				{
					innerHTML += 'href="Press.php?type=';
					
					if( type == "Press Release" )
						innerHTML += "Release";
					else if( type == "Received Press" )
						innerHTML += "Received";
					
					innerHTML += '"';
				}
				innerHTML += '>' + type + '</a></li>';
			
				if( type != filterColumn )
					innerHTML += '<li>|</li><li><a class="selected">' + filterColumn + '</a></li>';
			
				ul.innerHTML = innerHTML;
			}
		}
	});
}

function getDesignerProfiles( absolutePath, webRoot, relatedProduct )
{
	new Ajax.Request( webRoot + '/includes/GetDesignerProfiles.php', {
		method: 'get',
		parameters: 'product=' + relatedProduct + '&' + 'absolutePath=' + absolutePath,
  		onSuccess: function( transport )
		{
			var div = document.getElementById( 'main_content' );
			var ulList = div.getElementsByTagName( 'ul' );
			
			var profiles = transport.responseText.split( '\|' );
			var profilesLen = profiles.length;
			
			for( var i = 0; i < profilesLen; i++ )
				ulList[i+1].innerHTML = profiles[i];
			
			for( var i = profilesLen + 1; i < ulList.length; i++ )
				ulList[i].innerHTML = "";
			
			/*if( filterColumn == "Newest First" || filterColumn == "Oldest First" )
			{
				var div = document.getElementById( 'breadcrumb_trail' );
				var ul = div.getElementsByTagName( 'ul' )[0];
			
				ul.innerHTML = '<li>YOU ARE HERE:</li><li><a href="index.php">Home</a></li><li>|</li>' +
					'<li><a href="Press.php">Press/Media</a></li><li>|</li><li><a class="selected">' + 
					filterColumn + '</a></li>';
			}*/
		}
	});
}

function getStockists( absolutePath, webRoot, region )
{
	new Ajax.Request( webRoot + '/includes/GetStockists.php', {
		method: 'get',
		parameters: 'region=' + region + '&' + 'absolutePath=' + absolutePath,
  		onSuccess: function( transport )
		{
			var div = document.getElementById( 'main_content' );
			var ulList = div.getElementsByTagName( 'ul' );
			var ulListLen = ulList.length - 1;
			
			var stockist = transport.responseText.split( '\|' );
			var stockistLen = stockist.length;
			
			if( stockistLen == 1 )
			{
				ulList[1].innerHTML = stockist[0];
				ulList[2].innerHTML = "";
				ulList[3].innerHTML = "";
				ulList[4].innerHTML = "";
			}
			
			if( stockistLen == 2 )
			{
				ulList[1].innerHTML = stockist[0];
				ulList[2].innerHTML = stockist[1];
				ulList[3].innerHTML = "";
				ulList[4].innerHTML = "";
			}
			
			if( stockistLen == 3 )
			{
				ulList[1].innerHTML = stockist[0];
				ulList[2].innerHTML = stockist[1];
				ulList[3].innerHTML = stockist[2];
				ulList[4].innerHTML = "";
			}
			
			if( stockistLen == 4 )
			{
				ulList[1].innerHTML = stockist[0];
				ulList[2].innerHTML = stockist[1];
				ulList[3].innerHTML = stockist[2];
				ulList[4].innerHTML = stockist[3];
			}
		}
	});
}

function getNews( absolutePath, webRoot, sortByColumn )
{
	new Ajax.Request( webRoot + '/includes/GetNews.php', {
		method: 'get',
		parameters: 'sortByColumn=' + sortByColumn + '&' + 'absolutePath=' + absolutePath,
  		onSuccess: function( transport )
		{
			var div = document.getElementById( 'main_content' );
			var ulList = div.getElementsByTagName( 'ul' );
			
			var news = transport.responseText.split( '\|' );
			var newsLen = news.length;
			
			for( var i = 0; i < newsLen; i++ )
				ulList[i+1].innerHTML = news[i];
			
			for( var i = newsLen + 1; i < ulList.length; i++ )
				ulList[i].innerHTML = "";
			
			var div = document.getElementById( 'breadcrumb_trail' );
				var ul = div.getElementsByTagName( 'ul' )[0];
			
				ul.innerHTML = '<li>YOU ARE HERE:</li><li><a href="index.php">Home</a></li><li>|</li>' +
					'<li><a href="News.php">Latest</a></li><li>|</li><li><a class="selected">' + 
					sortByColumn + '</a></li>';
		}
	});
}

function getProjects( absolutePath, webRoot, sortByColumn )
{
	new Ajax.Request( webRoot + '/includes/GetProjects.php', {
		method: 'get',
		parameters: 'sortByColumn=' + sortByColumn + '&' + 'absolutePath=' + absolutePath,
  		onSuccess: function( transport )
		{
			var div = document.getElementById( 'main_content' );
			var ulList = div.getElementsByTagName( 'ul' );
			
			var projects = transport.responseText.split( '\|' );
			var projectsLen = projects.length;
			
			for( var i = 0; i < projectsLen; i++ )
				ulList[i+1].innerHTML = projects[i];
			
			for( var i = projectsLen + 1; i < ulList.length; i++ )
				ulList[i].innerHTML = "";
			
			var div = document.getElementById( 'breadcrumb_trail' );
			var ul = div.getElementsByTagName( 'ul' )[0];
			ul.innerHTML = '<li>YOU ARE HERE:</li><li><a href="index.php">Home</a></li><li>|</li>' +
				'<li><a href="Projects.php">Projects</a></li><li>|</li><li><a class="selected">' +
				sortByColumn + '</a></li>';
		}
	});
}

function updateVAT( absolutePath, webRoot )
{
	new Ajax.Request( webRoot + '/includes/UpdateVAT.php', {
		method: 'get',
		parameters: 'vat=' + document.getElementById( 'vat' ).value + '&' + 'absolutePath=' + absolutePath,
  		onSuccess: function( transport )
		{
			document.getElementById( 'updatedVAT' ).style.display = "";
		}
	});
}

// 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
    });
}