
function processToDoPopupListAjaxCall(userId,entryId,objectId,action) {
	var url = document.getElementById('todo_list_edit_url').value;
//	alert(url);
//	var jsonRequest = new Request.JSON(
//						{
//							url: 		url, 
//							onComplete: ajaxParseToDoEditAction
//						}).post(
//							{
//								'userId'				: userId,
//								'entryId'				: entryId,
//								'objectId'				: objectId,
//								'ajaxBehavior'			: true,
//								'action'				: action
//							})
	$.ajax({
	  type: 'POST',
	  url: url,
	  data: {
								'userId'				: userId,
								'entryId'				: entryId,
								'objectId'				: objectId,
								'ajaxBehavior'			: true,
								'action'				: action
							},
	  dataType: 'json',
	  success: ajaxParseToDoEditAction
	})
//	alert('after sending ajax request');
//							alert(jsonRequest);
//	return jsonRequest;
}

function removeToDoFromList(userId,entryId,objectId) {
	processToDoPopupListAjaxCall(userId,entryId,objectId,"removeObject");
}

function addEntryToDosToList(button,entryId) {
	popupTable.innerHTML = "<br><p align=center><img src=\"" + contextPath + "/images/bigrotation2.gif\"></p>";
//	alert('about to open popup for button=' + button);
	openPopup(button);
//	alert('opened popup');
	var objectId = null;
	var userId = document.getElementById('userId').value;
//	alert('userId=' + userId);
	processToDoPopupListAjaxCall(userId,entryId,objectId,"addEntryObjects");
}

function addEntryToTodoList(button,entryId) {
	popupTable.innerHTML = "<br><p align=center><img src=\"" + contextPath + "/images/bigrotation2.gif\"></p>";
//	alert('about to open popup for button=' + button);
	openPopup(button);
//	alert('opened popup');
	var objectId = null;
	var userId = document.getElementById('userId').value;
//	alert('userId=' + userId);
	processToDoPopupListAjaxCall(userId,entryId,objectId,"addEntry");
}

function addToDoToList(userId,entryId,objectId) {
	processToDoPopupListAjaxCall(userId,entryId,objectId,"addObject");
}

function getPopUpContents(entryId) {
	var userId = document.getElementById('userId').value;
	processToDoPopupListAjaxCall(userId,entryId,objectId,"getPopupContents");
}

function ajaxParseToDoEditAction(response)
{ 
	parseToDoActionResponse(response);
}

function parseToDoActionResponse (response) {
//alert('response=' + response);
	if (response.action == 'removeObject') {
		updateToDoDialogWithRemovedObject(response);
	}
	if (response.action == 'addObject') {
		updateToDoDialogWithAddedObject(response);
	}
	if (response.action == 'addEntryObjects') {
		updateToDoDialogWithAddedEntryObjects(response);
	}
	if (response.action == 'addEntry') {
		updateToDoDialogWithAddedEntry(response);
	}
}

function updateToDoDialogWithRemovedObject (response) {
	var objectId = response.objectId;
	hideObjectRemoveButton(objectId);
	showObjectAddButton(objectId);
}

function updateToDoDialogWithAddedObject (response) {
	var objectId = response.objectId;
	hideObjectAddButton(objectId);
	showObjectRemoveButton(objectId);
}

function updateToDoDialogWithAddedEntryObjects (response) {
	var objectId = response.objectId;
	var popupTable = document.getElementById("popupTable");
	var html = response.generatedHtml;
	html = unescape(response.generatedHtml);
	popupTable.innerHTML = html;
}
function updateToDoDialogWithAddedEntry(response) {
	var popupTable = document.getElementById("popupTable");
	var html = response.generatedHtml;
	html = unescape(response.generatedHtml);
	popupTable.innerHTML = html;
}

function showObjectRemoveButton (objectId) {
	var div = document.getElementById('objectButtonRemove' + objectId);
	if (div != null) {
		div.style.display='block';
	}
}

function hideObjectRemoveButton (objectId) {
	var div = document.getElementById('objectButtonRemove' + objectId);
	if (div != null) {
		div.style.display='none';
	}
}

function showObjectAddButton (objectId) {
	var div = document.getElementById('objectButtonAdd' + objectId);
	div.style.display='block';
}

function hideObjectAddButton (objectId) {
	var div = document.getElementById('objectButtonAdd' + objectId);
	div.style.display='none';
}


