function refreshLinkDisplay()
{	
	//newLinkStrings += linkID + ":" + form.elements['link_text'].value + ":" + form.elements['tool_tip'].value + ":" + form.elements['link_to'].value + ":" + form.elements['link_url'].value + ":" + new_window;

	links = document.forms['editPage'].elements['LINKS'].value;
	if ( links.length > 0 )
	{
		linksArray = links.split(';');
		DISPLAY_CODE = '';
		for ( $ls = 0 ; $ls < linksArray.length ; $ls++ )
		{
			linkInfo = linksArray[$ls].split('|');
			if ( linkInfo[3] == "external" )
			{
				formattedLink = 'http://'  + linkInfo[4];
			}
			else
			{
				formattedLink = linkInfo[4];
			}
			
			thisLinkString = '<a href="' + formattedLink + '"';
			if ( linkInfo[2] != '' && linkInfo[2] != ' ' ) 
			{
				thisLinkString += ' title="' + linkInfo[2] + '"';
			}	
			if ( linkInfo[5] != 'none' ) 
			{
				thisLinkString += ' target="_blank"';
			}
		
			thisLinkString += '>' + linkInfo[1] + '</a>';
			thisLinkString += createLinkControls(linkInfo[0]);
			thisLinkString += '<BR>';
			DISPLAY_CODE += thisLinkString;
		}
	}
	else
	{
		DISPLAY_CODE = "No Links Defined";
	}
	window.document.getElementById('LINK_DISPLAY').innerHTML = DISPLAY_CODE;
}	

function refreshDocumentDisplay()
{
	docs = document.forms['editPage'].elements['documentDisplayVariables'].value;
	if ( docs.length > 2 )
	{
		docArray = docs.split(';');
		DISPLAY_CODE = '';
		for ( $ds = 0 ; $ds < docArray.length ; $ds++ )
		{
			docInfo = docArray[$ds].split('|');
			thisDocString = docInfo[1] + ' ';
			thisDocString += '<i>(' + docInfo[2] + ')</i>';
			thisDocString += createDocumentControls(docInfo[0]);
			thisDocString += '<BR>';
			DISPLAY_CODE += thisDocString;
		}
	}
	else
	{
		DISPLAY_CODE = "No Documents Defined";
	}
	window.document.getElementById('DOCUMENT_DISPLAY').innerHTML = DISPLAY_CODE;	
}

function createLinkControls(id)
{
	deleteButton = '&nbsp;[&nbsp;<a href="javascript:deleteLink(' + id + ');">Delete</a>&nbsp;]';
	editButton = '&nbsp;[&nbsp;<a href="javascript:popper(\'/' + WMSROOT + '/content/pop_links.php?action=edit&linkID=' + id + '\',\'400\',\'600\',\'LinkEditor\');">Edit</a>&nbsp;]';
	return "&nbsp;&nbsp;<nobr>" + editButton + deleteButton + "</nobr>";
}

function createDocumentControls(id)
{
	deleteButton = '&nbsp;[&nbsp;<a href="javascript:deleteDocument(' + id + ');">Delete</a>&nbsp;]';
	replaceButton = '&nbsp;[&nbsp;<a href="javascript:popper(\'/' + WMSROOT + '/content/pop_documents.php?action=replace&docID=' + id + '\',\'400\',\'600\',\'Picker\');">Replace</a>&nbsp;]';
	return "&nbsp;&nbsp;<nobr>" + replaceButton + deleteButton + "</nobr>";
}

function deleteLink(id)
{
	links = document.forms['editPage'].elements['LINKS'].value;
	linksArray = links.split(';');
	linksString = '';
	linkCount = 0;
	for ( ll = 0 ; ll < linksArray.length ; ll++ )
	{
		linkInfo = linksArray[ll].split('|');
		if ( parseInt(linkInfo[0]) != parseInt(id) )
		{
			if ( ll > 0 && id != 0 )
			{
				linksString += ";";
			}
			linksString += linkCount + "|" + linkInfo[1] + "|" + linkInfo[2] + "|" + linkInfo[3] + "|" + linkInfo[4] ;
			linkCount++;
		}
	}
	document.forms['editPage'].elements['LINKS'].value = linksString;
	refreshLinkDisplay();
	
}

function deleteDocument(id)
{
	docs = document.forms['editPage'].elements['documentDisplayVariables'].value;
	docIDs = document.forms['editPage'].elements['DOCUMENTS'].value;
	
	docArray = docs.split(';');
	idArray = docIDs.split(';');
	
	docsString = '';
	idString = '';
	
	docCount = 0;
	for ( dd = 0 ; dd < docArray.length ; dd++ )
	{
		docInfo = docArray[dd].split('|');

		if ( parseInt(docInfo[0]) != parseInt(id) )
		{
			if ( dd > 0 && docCount > 0 )
			{
				docsString += ";";
				idString += ";";
			}
			docsString += docArray[dd];
			idString += docInfo[0];
			docCount++;
		}
	}
	document.forms['editPage'].elements['documentDisplayVariables'].value = docsString;
	document.forms['editPage'].elements['DOCUMENTS'].value = idString;
	refreshDocumentDisplay();
	
}
