/* Film comment functions. */

/**
 * commentSubmitID must be set in the template which calls these functions. It
 * should be the result of this statement from the controller:
 *
 * $this->generateSubmitID('/pageGroup/commentajax');
 */

function ajaxPostComment(refID, elComment, elToSwap) {

	var url = siteURL + '/' + pageGroup + '/commentajax'

	jQuery.ajax({ url: url,
		data: {'action': 'post_comment', 'refID' : refID, 'comment': jQuery(elComment).val(), 'submitID' : commentSubmitID, 'step' : '1', 'parentID' : 0},
		type: 'post',
		success: function (responseText) {

			// Mysterious IE7 bug with inserting response text forces manual js calls.
			//jQuery(elToSwap).html(responseText);

			document.getElementById(elToSwap.replace('#', '')).innerHTML = responseText;

		}
	});

	jQuery(elToSwap).html(loadingGraphic);

	//trackClick(url);

}

function ajaxFetchCommentsList(page, refID, elToSwap) {

	var url = siteURL + '/' + pageGroup + '/commentajax'

	jQuery.ajax({ url: url,
		data: {'action': 'list_comments', 'refID' : refID, 'page' : page},
		type: 'post',
		success: function (responseText) {

			// Mysterious IE7 bug with inserting response text forces manual js calls.
			//jQuery(elToSwap).html(responseText);

			document.getElementById(elToSwap.replace('#', '')).innerHTML = responseText;

		}
	});

	jQuery(elToSwap).html(loadingGraphic);

	//trackClick(url);

}

function ajaxDeleteComment(refID, commentID, elToSwap) {

	var url = siteURL + '/' + pageGroup + '/commentajax'

	jQuery.ajax({ url: url,
		data: {'action': 'delete_comment', 'refID' : refID, 'commentID' : commentID, 'submitID' : commentSubmitID, 'step' : '1'},
		type: 'post',
		success: function (responseText) {

			// Mysterious IE7 bug with inserting response text forces manual js calls.
			//jQuery(elToSwap).html(responseText);

			document.getElementById(elToSwap.replace('#', '')).innerHTML = responseText;

		}
	});

	jQuery(elToSwap).html(loadingGraphic);

	//trackClick(url);

}
