﻿function commentReply(id, subject) {
	$('parentId').value = id;
	$('commentSubject').value = 'Re: '+ subject;
}

function commentQuote(id, quoteId, subject) {
	commentReply(id, subject);
	content = $('blogcomment-' + quoteId).innerHTML;
	insertStr = '<blockquote class="blogquote">' + content + '</blockquote>';
	tinyMCE.execCommand('mceInsertContent', false, insertStr);
}

function toggleReplies(id) {
	commentId = 'blogcommentul-' + id;
	toggleLoadingId = 'blogloading-' + id;
	toggleId = 'toggle-' + id;
	//alert(toggleLoadingId);
	$(toggleId).hide();
	$(toggleLoadingId).show();

	if ($(commentId).style.display == 'none' || $(commentId).style.height == '0px') {
		Effect.BlindDown(commentId,
			Object.extend({
				delay: 0,
				duration: 0.5,
				//restoreAfterFinish: true,
				afterFinishInternal: function(effect) {
					$(toggleId).toggleClassName('blogreplyhidebutton');
					$(toggleId).removeClassName('blogreplyshowbutton'); 
					$(toggleLoadingId).hide();
					$(toggleId).show();
					//effect.element.undoClipping();
					if ($(toggleId).hasClassName('blogreplyhidebutton') !== true) {
						$(toggleId).toggleClassName('blogreplyhidebutton');
					}
				}
			})
		);
	}
	else {
		Effect.BlindUp(commentId,
			Object.extend({
				delay: 0,
				duration: 0.5,
				//restoreAfterFinish: true,
				afterFinishInternal: function(effect) {
					$(toggleId).toggleClassName('blogreplyshowbutton');
					$(toggleId).removeClassName('blogreplyhidebutton'); 
					$(toggleLoadingId).hide();
					$(toggleId).show();
					effect.element.hide().undoClipping();
					if ($(toggleId).hasClassName('blogreplyshowbutton') !== true) {
						$(toggleId).toggleClassName('blogreplyshowbutton');
					}
				}
			})
		);
	}
}


var formInfo = '';
var formInputs = '';
var formContent = '';
function submitComment(){
	formInputs = $('blogcomment').getInputs();
	formContent = tinyMCE.get('commentContent').getContent();
	tinyMCE.execCommand('mceFocus', false, 'commentContent');
	tinyMCE.execCommand('mceRemoveControl', false, 'commentContent');
	$('blogcomment').request({
		onSuccess: function(transport) {
			var response = transport.responseText;
			formInfo = $('blogcommentform').innerHTML;
			//$('blogcomment').removeChild('commentContent_parent');
			$('blogcommentform').innerHTML = response;
		}
	});
}

function goBack() {
	$('blogcommentform').innerHTML = formInfo;
	so_clearInnerHTML($('commentContent'));
	$('commentContent').appendChild(document.createTextNode(formContent));
	tinyMCE.execCommand('mceAddControl', false, 'commentContent');
	for (var i = 0; i < formInputs.length; i++) {
		$(formInputs[i].id).value = formInputs[i].value;
	}
}


function so_clearInnerHTML(obj) {
	// perform a shallow clone on obj
	nObj = obj.cloneNode(false);
	// insert the cloned object into the DOM before the original one
	obj.parentNode.insertBefore(nObj, obj);
	// remove the original object
	obj.parentNode.removeChild(obj);
}
