function sendCommentDelete(commentId, contentType)
{
	var commentBlock = $(contentType + "Block" + commentId);
	
	if(confirm('Are you sure you want to delete this comment?'))
	{
		createLoadingPop('Deleting Comment');
		
		var params = 'action=delete&contentType=' + contentType + '&contentId=' + commentId + '&ieSucks=' + IeSucksUrlDate();
		new Ajax.Request('/rea/admin/ajaxaction', 
		{
			method: 'get',
			parameters: params,
			onSuccess: function(transport)
				{
					var responseXml = transport.responseXML;
					
					// get base xml element - use to get the three values we need to process
					var xmlBase = responseXml.getElementsByTagName("deletion")[0];
					var result = parseInt(xmlBase.getElementsByTagName("result")[0].firstChild.nodeValue);
					var contentId = parseInt(xmlBase.getElementsByTagName("contentId")[0].firstChild.nodeValue);					

					var resultMessage;
					
					if(result == 1)
					{
						
						new Effect.Fade(commentBlock);
						resultMessage = 'Successfully deleted ' + contentType;
						
						if(document.getElementById(contentType + 'Count') != null) {
							var ccc = document.getElementById(contentType + 'Count');
							var ncc = parseInt(ccc.childNodes[0].nodeValue) - 1;
							
							if(ncc >= 0) {
								ccc.removeChild(ccc.childNodes[0]);
								ccc.appendChild(document.createTextNode(ncc));
							}
						}
					}
					else {
						resultMessage = 'Failed to delete ' + contentType;
					}	

					
					modifyLoadingPop(resultMessage);					
					setTimeout("finalizeAjaxPop()", 1500);

				}
		});	
	}
}


function sendToggleActive(formElement, contentId, contentType) {
	
	var activeStatus = formElement.value;
	var processAction = true;
	var resultStatus = null;
	
	if(activeStatus == 1)
		processAction = confirm("Are you sure you want to deactivate this " + contentType);
		
	if(processAction)
	{
		var loadingText = 'Activating';		
		if(activeStatus == 1)
			loadingText = 'Deactivating';
			
		createLoadingPop(loadingText + ' ' + contentType);
	
		var params = 'action=toggleactive&contentType=' + contentType + '&contentId=' + contentId + '&ieSucks=' + IeSucksUrlDate();
		
		resultStatus = new Ajax.Request('/rea/admin/ajaxaction', 
		{
			method: 'get',
			parameters: params,
			onSuccess: function(transport)
				{
					var responseXml = transport.responseXML;
					
					// get base xml element - use to get the three values we need to process
					var xmlBase = responseXml.getElementsByTagName("activation")[0];
					var result = parseInt(xmlBase.getElementsByTagName("result")[0].firstChild.nodeValue);
					var newActiveStatus = parseInt(xmlBase.getElementsByTagName("newActiveStatus")[0].firstChild.nodeValue);					
										
					var newLoadingTextNode, checkTheBox, optionText, toolTip;
					
					if(result == 1)
					{				
						if(newActiveStatus == 1)
						{
							newLoadingTextNode = 'Successfully activated ' + contentType;
							optionText = 'Deactivate';
							checkTheBox = true;
							toolTip = 'This ' + contentType + ' is currently active and viewable by everyone';
						}
						else
						{
							newLoadingTextNode = 'Successfully deactivated ' + contentType;
							optionText = 'Activate';
							checkTheBox = false;
							toolTip = 'This ' + contentType + ' is currently inactive and viewable by only users associated with your company';
						}
							
						formElement.value = newActiveStatus;
					}
					
					if(formElement.type != null && formElement.type == 'checkbox')
						formElement.checked = checkTheBox;
					else
					if(formElement.type != null && formElement.type == 'hidden') {
						// change link text
						var textContainer = document.getElementById('activeText' + contentId);
						textContainer.removeChild(textContainer.childNodes[0]);
						textContainer.appendChild(document.createTextNode(optionText));
						
						// change image icon
						document.getElementById('activeIcon' + contentId).src = "/images/template/ic-cont-" + optionText.toLowerCase() + ".png";
						
						// toggle inactive message
						toggleDisplay('contentInactiveMessage' + contentId);
						
						if(document.getElementById('activeToolTip' + contentId) != null) {
							var toolTipContainer = document.getElementById('activeToolTip' + contentId);
							toolTipContainer.removeChild(toolTipContainer.childNodes[0]);
							toolTipContainer.appendChild(document.createTextNode(toolTip));
						}
					}					
					else
					{
						formElement.text = optionText;
						formElement.parentNode.selectedIndex = 0;
					}
						
					modifyLoadingPop(newLoadingTextNode);					
					setTimeout("finalizeAjaxPop()", 1500);
					
					return newActiveStatus;
				}
		});			
	}
	else
	{	
		if(formElement.type != null && formElement.type == 'checkbox')
		{
			if(activeStatus == 1)
				formElement.checked = true;
			else
				formElement.checked = false;
		}
		else
		{
			formElement.parentNode.selectedIndex = 0;
		}
	}
	
	return resultStatus;
}

function sendToggleFeatured(formElement, contentId, contentType)
{
	var activeHidden = $("activeHidden" + contentId);
	var activeStatus = formElement.value;
	var processAction = true;
	
	if(activeStatus == 1)
		processAction = confirm("Are you sure you want to unfeature this " + contentType);
		
	if(processAction)
	{
		var loadingText = 'Featuring';		
		if(activeStatus == 1)
			loadingText = 'Unfeaturing';
			
		createLoadingPop(loadingText + ' ' + contentType);
	
		var params = 'action=togglefeatured&contentType=' + contentType + '&contentId=' + contentId + '&ieSucks=' + IeSucksUrlDate();
		
		new Ajax.Request('/rea/admin/ajaxaction', 
		{
			method: 'get',
			parameters: params,
			onSuccess: function(transport)
				{
					var responseXml = transport.responseXML;
					
					// get base xml element - use to get the three values we need to process
					var xmlBase = responseXml.getElementsByTagName("activation")[0];
					var result = parseInt(xmlBase.getElementsByTagName("result")[0].firstChild.nodeValue);
					var newActiveStatus = parseInt(xmlBase.getElementsByTagName("newActiveStatus")[0].firstChild.nodeValue);					
					
					var newLoadingTextNode, checkTheBox, optionText;
					
					if(result == 1) {				
						if(newActiveStatus == 1) {
							newLoadingTextNode = 'Successfully featured ' + contentType;
							optionText = 'Deactivate';
							checkTheBox = true;
						}
						else {
							newLoadingTextNode = 'Successfully unfeatured ' + contentType;
							optionText = 'Activate';
							checkTheBox = false;
						}
							
						formElement.value = newActiveStatus;
					}
					
					if(formElement.type != null && formElement.type == 'checkbox')
						formElement.checked = checkTheBox;
					else {
						formElement.text = optionText;
						formElement.parentNode.selectedIndex = 0;
					}
						
					modifyLoadingPop(newLoadingTextNode);					
					setTimeout("finalizeAjaxPop()", 1500);
				}
		});			
	}
	else
	{	
		if(formElement.type != null && formElement.type == 'checkbox')
		{
			if(activeStatus == 1)
				formElement.checked = true;
			else
				formElement.checked = false;
		}
		else
		{
			formElement.parentNode.selectedIndex = 0;
		}
	}	
}

function sendToggleFavorite(contentId, contentTypeId)
{
	var favoriteHidden = $("favoriteHidden");
	var isFavorite = favoriteHidden.value;
	var processAction = true;
	
	if(isFavorite == 1)
		processAction = confirm("Are you sure you want to do this?");
		
	if(processAction)
	{
		var loadingText = 'Processing your request...';

		createLoadingPop(loadingText);
			
		var params = 'action=togglefavorite' + '&contentId=' + contentId + '&contentTypeId=' + contentTypeId + '&ieSucks=' + IeSucksUrlDate();
		
		new Ajax.Request('/rea/admin/ajaxaction', 
		{
			method: 'get',
			parameters: params,
			onSuccess: function(transport)
				{
					var responseXml = transport.responseXML;
					
					// get base xml element - use to get the three values we need to process
					var xmlBase = responseXml.getElementsByTagName("userFavorite")[0];
					var result = parseInt(xmlBase.getElementsByTagName("result")[0].firstChild.nodeValue);
					var newIsFavorite = parseInt(xmlBase.getElementsByTagName("isFavorite")[0].firstChild.nodeValue);					
					var ctid = parseInt(xmlBase.getElementsByTagName("contentTypeId")[0].firstChild.nodeValue);
					var newLoadingTextNode, newFavoriteText;
					
					if(result == 1)
					{				
						if(newIsFavorite == 1) {
							if(ctid == 12) {
								newLoadingTextNode = 'This user is now in your network';
								newFavoriteText = ' Remove from my network';
							}
							else
							if(ctid == 11) {
								newLoadingTextNode = 'This company is now in your network';
								newFavoriteText = ' Remove from my network';							
							}
							else {
								newLoadingTextNode = 'Successfully added to bookmarks';
								newFavoriteText = 'Remove From Bookmarks';
							}
						}
						else
						{
							if(ctid == 12) {
								newLoadingTextNode = 'You have removed this user from your network';
								newFavoriteText = ' Add to my network';
							}
							else
							if(ctid == 11) {
								newLoadingTextNode = 'You have removed this company from your network';
								newFavoriteText = ' Add to my network';							
							}
							else {
								newLoadingTextNode = 'Successfully removed from bookmarks';
								newFavoriteText = 'Add To Bookmarks';
							}
						}
							
						favoriteHidden.value = newIsFavorite;
						
						var favoriteTextContainer = document.getElementById('favoriteTextContainer');
						favoriteTextContainer.removeChild(favoriteTextContainer.childNodes[1]);						
						favoriteTextContainer.appendChild(document.createTextNode(newFavoriteText));					
					}
					else
						newLoadingTextNode = 'Action failed';
					
					modifyLoadingPop(newLoadingTextNode);					
					setTimeout("finalizeAjaxPop()", 1500);
				}
		});			
	}
}

function rateContent(contentId, contentTypeId, rating) {
		
	var params = 'ctid=' + contentTypeId + '&id=' + contentId + '&rating=' + rating + '&ieSucks=' + IeSucksUrlDate();
	
	new Ajax.Request('/rea/ratecontent', 
	{
		method: 'get',
		parameters: params,
		onSuccess: function(transport)
			{
				var responseXml = transport.responseXML;
				
				// get base xml element - use to get the three values we need to process
				var xmlBase = responseXml.getElementsByTagName("rating")[0];
				var numRatings = parseInt(xmlBase.getElementsByTagName("numRatings")[0].firstChild.nodeValue);
				var starsBase = responseXml.getElementsByTagName("stars")[0];
				var starSrc, star;
				var newStars = starsBase.getElementsByTagName("star");
				
				for(var i = 0; i < newStars.length; i++) {
					star = newStars[i];
					starSrc = star.getElementsByTagName("src")[0].firstChild.nodeValue;
					document.getElementById("rs" + i).src = "/images/template/" + starSrc;					
				}
				
				var ratingSelect = document.getElementById("rateSelector");
				ratingSelect.style.display = "none";
								
				var messageContainer = document.getElementById("ratingMessage");
				messageContainer.appendChild(document.createTextNode("Thank you!"));
				
				var countContainer = document.getElementById("ratingCount");
				countContainer.removeChild(countContainer.childNodes[0]);
				var ratingsText = "Ratings";
				if(numRatings == 1)
					ratingsText = "Rating";
				countContainer.appendChild(document.createTextNode(numRatings + " " + ratingsText));
			}
	});
}

function highlightStars(starCount) {
	
	var i = 1;
	
	for(var i = 1; i <= 5; i++) {
		if(i <= starCount)
			document.getElementById('ratingStar' + i).src = '/images/template/rating-star-whole-on.png';
		else
			document.getElementById('ratingStar' + i).src = '/images/template/rating-star-whole-off.png';
	}
}

function showContentRating() {

	createOpaqueLayer();
	var container = document.getElementById("rateContentContainer");
	container.style.display = "block";

}

var processPop
function createLoadingPop(loadingText)
{
		createOpaqueLayer();
		
		processPop = document.createElement('div');
		processPop.className = 'processPop';
		processPop.id = 'processPop';
		processPop.style.marginTop = (getHeightOffset() + 250) + 'px';
			
		var loadingTextNode = document.createTextNode(loadingText);
	
		var loadingImage = new Image(16, 16);
		loadingImage.src = '/images/admin/mozilla_blu.gif';
		
		processPop.appendChild(loadingImage);	
		processPop.appendChild(loadingTextNode);

		$('pageContainer').appendChild(processPop);
}

function modifyLoadingPop(newText)
{
	if(newText == null || newText == '')
		newText = 'Unable to complete your request';
		
	processPop.innerHTML = '';
	processPop.appendChild(document.createTextNode(newText));
}

function finalizeAjaxPop()
{
	$('pageContainer').removeChild($('processPop'));
	removeOpaqueLayer();
}

function toggleCT() {
	var optionContainer = $('ctInfoSec');
	if(optionContainer.style.display == "none") {
		Effect.BlindDown(optionContainer);
	}
	else {
		Effect.BlindUp(optionContainer);
	}
}

function prepareCT(contentId, contentTypeId) {
	var ctHidden = $("ctHidden");
	var isCT = ctHidden.value;
	
	if(isCT == 1) {
		if(confirm("Are you sure you want to stop tracking this content?")) {
			sendToggleCT(contentId, contentTypeId, isCT, 0, 0);
		}
	}
	else {
		toggleCT();
	}
}

function processCTSave(contentId, contentTypeId) {
	var everyBox = $('ctEvery');
	var summaryBox = $('ctSummary');
	
//	if(!everyBox.checked && !summaryBox.checked) {
	if(!everyBox.checked) {
		alert('You must check at least one option.');
	}
	else {
		var every = 0;
		var summary = 0;
		if(everyBox.checked)
			every = 1;
//		if(summaryBox.checked)
//			summary = 1;
			
		sendToggleCT(contentId, contentTypeId, false, every, summary);
	}
}

function sendToggleCT(contentId, contentTypeId, isCT, every, summary)
{
	var loadingText = 'Processing';
	if(isCT == 1)
		loadingText = 'Removing';

	createLoadingPop(loadingText);
		
	var params = 'action=contenttracking' + '&contentId=' + contentId + '&contentTypeId=' + contentTypeId + '&every=' + every + '&summary=' + summary + '&ieSucks=' + IeSucksUrlDate();
	
	new Ajax.Request('/rea/admin/ajaxaction', 
	{
		method: 'get',
		parameters: params,
		onSuccess: function(transport)
			{
				var responseXml = transport.responseXML;
				
				// get base xml element - use to get the three values we need to process
				var xmlBase = responseXml.getElementsByTagName("contentTracking")[0];
				var result = parseInt(xmlBase.getElementsByTagName("result")[0].firstChild.nodeValue);
				var newIsTracking = parseInt(xmlBase.getElementsByTagName("isTracking")[0].firstChild.nodeValue);					
				
				var newLoadingTextNode, newSubmitButtonSrc;
				
				if(result == 1)
				{			
					if(newIsTracking == 1)
					{
						newLoadingTextNode = 'Successfully tracking this content';
						newSubmitButtonSrc = 'button-stop-track-comments.gif';
						toggleCT();
					}
					else
					{
						newLoadingTextNode = 'You are no longer tracking this content';
						newSubmitButtonSrc = 'button-track-comments.gif';
					}
					
					var favoriteHidden = $('ctHidden');
					favoriteHidden.value = newIsTracking;
					
					var submitButton = $('trackCommentsButton');
					submitButton.src = "/images/template/" + newSubmitButtonSrc;
								
				}
				else
					newLoadingTextNode = 'An error occured. Please try again later';
				
				
				modifyLoadingPop(newLoadingTextNode);					
				setTimeout("finalizeAjaxPop()", 1500);				
			}
	});			
}

function sendToggleListFavorite(contentId, contentTypeId) {

	var processAction = true;
		
	if(processAction) {
		var loadingText = 'Adding to favorites.';
//		if(isFavorite == 1)
//			loadingText = 'Removing from favorites.';

		createLoadingPop(loadingText);
			
		var params = 'action=togglefavorite' + '&contentId=' + contentId + '&contentTypeId=' + contentTypeId + '&ieSucks=' + IeSucksUrlDate();
		
		new Ajax.Request('/rea/admin/ajaxaction', 
		{
			method: 'get',
			parameters: params,
			onSuccess: function(transport)
				{
					var responseXml = transport.responseXML;
					
					// get base xml element - use to get the three values we need to process
					var xmlBase = responseXml.getElementsByTagName("userFavorite")[0];
					var result = parseInt(xmlBase.getElementsByTagName("result")[0].firstChild.nodeValue);
					var newIsFavorite = parseInt(xmlBase.getElementsByTagName("isFavorite")[0].firstChild.nodeValue);					
					
					var newLoadingTextNode, newFavoriteText;
					
					
					if(result == 1) {
						if(newIsFavorite == 1) {
							newLoadingTextNode = 'Successfully added to favorites';
							newFavoriteText = 'Remove From Favorites';
						}
						else {
							newLoadingTextNode = 'Successfully removed from favorites';
							newFavoriteText = 'Add To Favorites';
						}
						
						var favoriteTextContainer = document.getElementById('favoriteTextContainer' + contentId);
						favoriteTextContainer.removeChild(favoriteTextContainer.childNodes[0]);						
						favoriteTextContainer.appendChild(document.createTextNode(newFavoriteText));					
					}
					else
						newLoadingTextNode = 'Action failed';
					
					modifyLoadingPop(newLoadingTextNode);
										
					setTimeout("finalizeAjaxPop()", 1500);
				}
		});			
	}
	
	return false;
}




var inputCount = 0;
function uploadContentImage(formId, isNew, data) {
	
	var headerText, captionValue = "", creditValue = "", inpIndex;
	if(isNew) {
		// new image
		headerText = "Upload Image";
		inputCount++;
		inpIndex = inputCount;
	}
	else {
		// editing image
		headerText = "Edit Image";
		captionValue = data['caption'];
		creditValue = data['credit'];
		inpIndex = data['id'];
	}
	
	
	
	var header = document.createElement('h2');
	header.className = 'popLayerHeader';
	header.appendChild(document.createTextNode(headerText)); 

	var inputCaption = document.createElement('input');
	inputCaption.type = 'text';
	inputCaption.name = 'imageCaption' + inpIndex;
	inputCaption.value = captionValue;
	
	var inputCredit = document.createElement('input');
	inputCredit.type = 'text';
	inputCredit.name = 'imageCredit' + inpIndex;
	inputCredit.value = creditValue;
	
	var table = document.createElement('table');
	table.className = "uploadImageTable";
	
	var captionRow = table.insertRow(0);
	captionRow.insertCell(0).appendChild(document.createTextNode('Image Caption:'));
	captionRow.insertCell(1).appendChild(inputCaption);
	
	var creditRow = table.insertRow(1);
	creditRow.insertCell(0).appendChild(document.createTextNode('Image Credit:'));
	creditRow.insertCell(1).appendChild(inputCredit);
	
	if(isNew) {
		var inputFile = document.createElement('input');
		inputFile.type = 'file';
		inputFile.name = 'imageFile' + inpIndex;
		inputFile.size = "45";
		var fileRow = table.insertRow(2);
		fileRow.insertCell(0).appendChild(document.createTextNode('Image File:'));
		fileRow.insertCell(1).appendChild(inputFile);
	}
		
	var saveButton = document.createElement("input");
	saveButton.type = "image";
	saveButton.src = "/images/template/popup-save-button.gif";
	
	var cancelButton = document.createElement("input");
	cancelButton.type = "image";
	cancelButton.src = "/images/template/popup-cancel-button.gif";
	
	var buttonContainer = document.createElement('div');
	buttonContainer.style.margin = "10px 0 0 0";
	buttonContainer.appendChild(saveButton);
	buttonContainer.appendChild(document.createTextNode(" "));
	buttonContainer.appendChild(cancelButton);	
	
	var popLayer = createPopupLayer({width:'500px'});
	popLayer.appendChild(header);
	popLayer.appendChild(table);
	popLayer.appendChild(buttonContainer);
	
	new Draggable('popLayer', {revert: false});
	
	cancelButton.onclick = function () {
		removePopupLayer();
	}
	
	if(isNew) {
		saveButton.onclick = function() {
			// validate there is a file
			if(trim(inputFile.value) == '') {
				// add error
				var errorContainer = document.createElement("div");
				errorContainer.style.margin = "8px 0 0 0";
				errorContainer.style.display = "none";
				var errorMessage = "<img style='position: relative; top: 2px;' src='/images/template/ic-x.png' alt='' /> <span style='color: #e42224; font-weight: bold; font-family: Arial, font-size: 12px;'>You must select an image file to upload</span>";
				errorContainer.innerHTML = errorMessage;
				popLayer.appendChild(errorContainer);
				Effect.Appear(errorContainer, {duration:1});
			}
			else {
				// good to go
				var form = document.getElementById(formId);
				
				inputCredit.style.display = "none";
				inputCaption.style.display = "none";			
				inputFile.style.display = "none";
				
				var inputIndex = document.createElement('input');
				inputIndex.type = "hidden";
				inputIndex.name = "imgIndexIds[]";
				inputIndex.value = inpIndex;
				
				form.appendChild(inputCredit);
				form.appendChild(inputCaption); 
				form.appendChild(inputFile);
				form.appendChild(inputIndex);
				
				var imgContainer = document.getElementById('uploadImageContainer');
				var imgRow = document.createElement('div');
				imgRow.style.display = 'none';
				imgRow.style.marginBottom = "3px;"
				
				var iconDelete = document.createElement('img');
				iconDelete.src = '/images/template/ic-delete-image.png';
				iconDelete.alt = 'Remove this image';
				iconDelete.title = 'Remove this image';
				iconDelete.style.cursor = "pointer";
				iconDelete.style.position = "relative";
				iconDelete.style.top = "3px";			
				
				var imgRowText = document.createElement('span');
				imgRowText.style.color = "#333";
				imgRowText.style.fontWeight = "bold";
				imgRowText.style.fontSize = "11px";
				imgRowText.title = trim(inputFile.value);
				
				var imgDesc = trim(inputFile.value);
				if(imgDesc.length > 30)
					imgDesc = imgDesc.substring(0, 30) + "...";
				
				imgRowText.appendChild(document.createTextNode('\u00a0\u00a0' + imgDesc));
				
				imgRow.appendChild(iconDelete);
				imgRow.appendChild(imgRowText);
							
				imgContainer.appendChild(imgRow);
				imgContainer.style.display = 'block';
				
				removePopupLayer();
				Effect.Appear(imgRow);
				
				iconDelete.onclick = function() {
					Effect.Fade(iconDelete.parentNode);
					
					form.removeChild(inputCredit);
					form.removeChild(inputCaption);
					form.removeChild(inputFile);
					form.removeChild(inputIndex);
				}
			}		
		}
	}
	else {
		saveButton.onclick = function() {
			
			var form = document.getElementById(formId);
			
			inputCredit.style.display = "none";
			inputCaption.style.display = "none";
			
			var inputIndex = document.createElement('input');
			inputIndex.type = "hidden";
			inputIndex.name = "imgUpdateIds[]";
			inputIndex.value = inpIndex;
			
			form.appendChild(inputCredit);
			form.appendChild(inputCaption); 
			form.appendChild(inputIndex);			
			
			document.getElementById('curImgContainer').style.display = "block";
			removePopupLayer();
		}
	}
}


function copyLinkPop(link) {
	
	var cancelButton = document.createElement("input");
	cancelButton.type = "image";
	cancelButton.src = "/images/template/popup-cancel-button.gif";
	
	var buttonContainer = document.createElement('div');
	buttonContainer.style.margin = "10px 0 0 0";
	buttonContainer.appendChild(cancelButton);	
	
	var popLayer = createPopupLayer({width:'500px'});
	popLayer.style.cursor = "default";
	popLayer.appendChild(document.createTextNode(link));
	popLayer.appendChild(buttonContainer);
	
	cancelButton.onclick = function () {
		removePopupLayer();
	}	
}

function openQuickEdit(fieldType, editIcon, dbFieldName, assocArray, contentId, contentTypeId) {

	var container;
	var textValue;
	var fieldTypes = fieldType.split("|");
	var formField = document.createElement(fieldTypes[0]);
	formField.className = "quickEditField";

	if(fieldTypes[1] != null)
		formField.type = fieldTypes[1];
	
	if(dbFieldName == 'Body') {
		container = document.getElementById('bodyContainer');
		textValue = container.innerHTML;
	}
	else {
		container = editIcon.parentNode;
		var textNode = container.childNodes[0];
		textValue = trim(textNode.nodeValue);			
	}

	formField.value = textValue;
	
	if(assocArray['width'] != null)
		formField.style.width = assocArray['width'];

	if(assocArray['height'] != null)
		formField.style.height = assocArray['height'];

	if(assocArray['styleId'] != null)
		formField.id = assocArray['styleId'];
			
	var saveButton = document.createElement("input");
	saveButton.type = "image";
	saveButton.src = "/images/template/popup-save-button.gif";
	
	var cancelButton = document.createElement("input");
	cancelButton.type = "image";
	cancelButton.src = "/images/template/popup-cancel-button.gif";
	
	var buttonContainer = document.createElement('div');
	buttonContainer.style.margin = "10px 0 0 0";
	buttonContainer.appendChild(saveButton);
	buttonContainer.appendChild(document.createTextNode(" "));
	buttonContainer.appendChild(cancelButton);
	
	var formHeader = document.createElement('h2');
	formHeader.className = 'popLayerHeader';
	formHeader.style.textTransform = "capitalize";
	formHeader.appendChild(document.createTextNode("Update " + dbFieldName + ":"));
	
	var popLayer = createPopupLayer({width:'500px'});
	new Draggable('popLayer', {revert: false});
	
	popLayer.appendChild(formHeader);
	popLayer.appendChild(formField);
	popLayer.appendChild(buttonContainer);
	
	formField.focus();
	
	if(dbFieldName == 'Body')
		tinyMCE.execCommand('mceAddControl', false, 'mceEditor');
		
	cancelButton.onclick = function () {
		if(dbFieldName == 'Body') {
			tinyMCE.execCommand('mceFocus', false, 'mceEditor');                    
			tinyMCE.execCommand('mceRemoveControl', false, 'mceEditor');
		}
		
		removePopupLayer();
	}
	
	saveButton.onclick = function () {		
		
		tinyMCE.triggerSave();
		
		resultStatus = new Ajax.Request('/rea/admin/ajaxaction', 
		{
			method: 'post',
			parameters: {action: 'updatecontent', contentTypeId: contentTypeId, contentId: contentId, dbFieldName: dbFieldName, dbFieldValue: formField.value},
			onSuccess: function(transport)
				{
					var responseXml = transport.responseXML;
					
					var xmlBase = responseXml.getElementsByTagName("updateResult")[0];
					var result = parseInt(xmlBase.getElementsByTagName("result")[0].firstChild.nodeValue);
					// var newText = xmlBase.getElementsByTagName("newText")[0].firstChild.nodeValue;
					
					var resultContainer = document.createElement("div");
					resultContainer.style.margin = "5px 0 0 0";
					resultContainer.style.display = "none";
					
					var resultHtml;
					
					if(result == 1) {
						// SUCCESS
						if(dbFieldName == 'Body') {
							container.innerHTML = formField.value;
						}
						else
							container.childNodes[0].nodeValue = formField.value;
							
						resultHtml = "<img style='position: relative; top: 2px;' src='/images/template/ic-checkmark.png' alt='' /> <span style='color: #579f4f; font-weight: bold; font-family: Arial, font-size: 12px;'>Update successful</span>";						
					}
					else {
						// FAILURE
						resultHtml = "Update failed";
					}
					
					resultContainer.innerHTML = resultHtml;
					popLayer.appendChild(resultContainer);
					Effect.Appear(resultContainer, {duration:1});

					var resetQuickEdit = function() {
						// show original value and hide form field - regardless if the update was successful or not
						if(dbFieldName == 'Body') {
							tinyMCE.execCommand('mceFocus', false, 'mceEditor');                    
							tinyMCE.execCommand('mceRemoveControl', false, 'mceEditor');
						}						
						removePopupLayer();
					}
										
					setTimeout(resetQuickEdit, 1500);
				}
		});
		
	}
}

function toggleQuickEdit(container, display) {
	var icons = getElementsByClassName("quickEditIcon", container);
	if(icons.length > 0) {
		var icon = icons[0];
		icon.style.visibility = display;
	}		
}