

window.addEvent('domready', function() {  	
  if(window['lsCmtTreeClass']) {
    lsCmtTreeClass.prototype.typeComment.topic.url_response = aRouter.blog+'ajaxresponsecomment/',
	
	lsCmtTreeClass.prototype.addComment = function(formObj,targetId,targetType) {
		var thisObj=this;
		formObj=$(formObj);			
		JsHttpRequest.query(
        	'POST '+thisObj.typeComment[targetType].url_add,
        	{ params: formObj, security_ls_key: LIVESTREET_SECURITY_KEY },
        	function(result, errors) {
            	if (!result) {
            		thisObj.enableFormComment();
                	msgErrorBox.alert('Error','Please try again later');  
                	return;         
        		}      
        		if (result.bStateError) {        			
					thisObj.enableFormComment();        			
                	msgErrorBox.alert(result.sMsgTitle,result.sMsg);
        		} else {
        			thisObj.responseNewComment(targetId,targetType,$('update-comments'),result.sCommentId,true);
					updateCaptcha();      		
				}                           
	        },
        	true
      	);
      	$('form_comment_text').addClass('loader');		
      	$('form_comment_text').setProperty('readonly',true);
	},
	
	lsCmtTreeClass.prototype.ajaxPreviewComment = function (textId,divPreview) { 
		var text;    
		if (BLOG_USE_TINYMCE && tinyMCE && (ed=tinyMCE.get(textId))) {
			text = ed.getContent();
		} else {
			text = $(textId).value;	
		}	
		JsHttpRequest.query(
			'POST '+aRouter.blog+'ajaxpreviewcomment/',                       
			{ text: text, security_ls_key: LIVESTREET_SECURITY_KEY },
			function(result, errors) {  
				if (!result) {
					msgErrorBox.alert('Error','Please try again later');           
				}
				if (result.bStateError) {
					msgErrorBox.alert('Error','Please try again later');
				} else {    	
					if (!divPreview) {
						divPreview='text_preview';
					}            	
					if ($(divPreview)) {
						$(divPreview).set('html',result.sText).setStyle('display','block');
					}
				}                               
			},
			true
		);
	},
	
	lsCmtTreeClass.prototype.preview = function() {
		var thisObj=this;
		thisObj.ajaxPreviewComment('form_comment_text','comment_preview_'+this.iCurrentShowFormComment);
	}
  }
});
