var videoCommentDialog				= null;
var lastVideoID						= 0;
var videoSubmitMode					= 0;		// 0=LOAD DIALOG, 1=REFRESH VIDEO COMMENTS
var vcd_doRefreshInline				= false;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function doAddVideoCommentDialog(videoID,refreshInline) {
	if (videoCommentDialog != null) {
	return;
	}
var url								= "/clientServer/?section=VideoCommentDialog&videoID=" + videoID;
lastVideoID							= videoID;
videoCommentDialog					= document.createElement('DIV');
videoSubmitMode						= 0;
handleGetComplete					= 'handleVideoCommentGetComplete';
handleDialogClose					= 'closeAddVideoCommentDialog';
vcd_doRefreshInline					= refreshInline;
doAjaxPopup('commonDialog',videoCommentDialog,url,500,300);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function closeAddVideoCommentDialog() {
closeAjaxPopup(videoCommentDialog);
videoCommentDialog					= null;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function submitVideoCommentForm(formObj) {
var F1								= formObj.COMMENTS;
	if (F1.value.length == 0) {
	alert('Please enter some comments before proceeding.');
	F1.focus();
	return;
	}
	
var videoID							= formObj.videoID.value;
var comments						= encodeURIComponent(F1.value);
var params							= "section=VideoCommentDialog&DOFORM=1&videoID="+videoID+"&comments="+comments;
showLoadingMessage();
handlePostComplete					= 'handleVideoCommentPostComplete';
postAjaxContent('/clientServer/',params);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function handleVideoCommentGetComplete(success,xmlHTTP) {
	switch (videoSubmitMode) {
	case 0:
	responseContainer.innerHTML		= xmlHTTP.responseText;
	break;
	case 1:
	var container					= document.getElementById('videoCommentsPane');
		if (container) {
		container.innerHTML			= xmlHTTP.responseText;
		}
	break;
	}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function refreshVideoComments() {
videoSubmitMode						= 1;
getAjaxContent("/clientServer/?section=VideoComments&videoID="+lastVideoID);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function handleVideoCommentPostComplete(success,xmlHTTP) {
var json							= json_parse(xmlHTTP.responseText);

	if (json['success']) {
	closeAddVideoCommentDialog();
	
		if (vcd_doRefreshInline) {
		refreshVideoComments();
		} else {
		var pageLoc					= '/video/' + json['videoID'] + '/';
		document.location.href		= pageLoc;
		}

	} else {
	responseContainer.innerHTML		= xmlHTTP.responseText;
	}
}