function addResp(TContentId, TContentTypeId, RE, errorDiv, commentDiv, userId) {

	if($('addMainComment').value == 'Добавить отзыв') {


		$('addMainComment').value = '';
		return false;


	}

	if(!$('addMainComment').value) {

		$('addMainComment').focus();
		$('addMainComment_error').innerHTML = 'Поле отзыва не должно быть пустым';
		return false;


	}


	addResp.TContentId = TContentId;
	addResp.TContentTypeId = TContentTypeId;
	addResp.RE = RE;
	addResp.errorDiv = errorDiv;
	addResp.commentDiv = commentDiv;
	addResp.userId = userId;

	if(!userId)
	showConfirmAutorize('addResp_',0);
	else
	addResp_();
}













function addResp_() {

	wait(1,1);

	$('addMainComment_error').innerHTML = '';

	var pars = 'act=when_user_leave_resp&artistid=' + addResp.TContentId;
	var search_node_Ajax = new Ajax.Request(ajax_path, {method: 'post', parameters: pars, onComplete: addResp__});





}

function addResp__(RequestFromServer) {

	if(RequestFromServer.responseText != '0' && RequestFromServer.responseText != 0) {
		$('addMainComment_error').innerHTML = 'Оставлять отзыв к одному и тому же исполнителю можно не чаще, чем раз в сутки!';
		wait_();
		$('aut_info').innerHTML = RequestFromServer.responseText;
		return false;


	}
	else {
		addRsp();
	}
	wait_(1,1);


}



function addRsp() {


	addComment(addResp.TContentId, addResp.TContentTypeId, addResp.RE,addResp.errorDiv, addResp.commentDiv);
}



function addComment(TContentId, TContentTypeId, RE, errorDiv, commentDiv) {
	if($(commentDiv).value == '') {
		$(errorDiv).innerHTML = '<font color="Red">Вы не можете отправлять пустой комментарий</font>';
	}
	else {
		if(RE == 0) {
			var anonim = ($F('add_anonim')) ? 1 : 0;
		}
		else {
			if($F('re_anonim_' + RE)) var anonim = 1;
			if(!$F('re_anonim_' + RE)) var anonim = 0;
		}

		showWait();
		var pars = 'act=add_comment&contentid=' + TContentId + '&contenttypeid=' + TContentTypeId + '&comment=' + encodeText($F(commentDiv)) + '&re=' + RE + '&anonim=' + anonim;
		var search_node_Ajax = new Ajax.Request(ajax_path, {method: 'post', parameters: pars, onComplete: addComment_Result});
	}
}





function updateComment(commentId,errorDiv,commentDiv) {
	if($(commentDiv).value == '') {
		$(errorDiv).innerHTML = '<font color="Red">Вы не можете отправлять пустой комментарий</font>';
	}
	else {
		if($F('edit_anonim_' + commentId)) var anonim = 1;
		if(!$F('edit_anonim_' + commentId)) var anonim = 0;
		showWait();
		var pars = 'act=update_comment&commentid=' + commentId + '&comment=' + encodeText($F(commentDiv)) + '&anonim=' + anonim;
		var search_node_Ajax = new Ajax.Request(ajax_path, {method: 'post', parameters: pars, onComplete: updateComment_Result});
	}
}

function updateCommentAnonim(commentId,errorDiv,commentDiv) {
	if($(commentDiv).value == '') {
		$(errorDiv).innerHTML = '<font color="Red">Вы не можете отправлять пустой комментарий</font>';
	}
	else {
		if($F('edit_an_' + commentId)) var anonim = 1;
		if(!$F('edit_an_' + commentId)) var anonim = 0;
		var pars = 'act=update_comment&commentid=' + commentId + '&comment=' + encodeText($F(commentDiv)) + '&anonim=' + anonim;
		var search_node_Ajax = new Ajax.Request(ajax_path, {method: 'post', parameters: pars, onComplete: updateComment_Result});
	}
}


function removeComment(commentId) {
		showWait();
		var pars = 'act=remove_comment&commentid=' + commentId;
		var search_node_Ajax = new Ajax.Request(ajax_path, {method: 'post', parameters: pars, onComplete: removeComment_Result});
}


function hideAllCommentsTextAreas() {


	 var i = 0;

		while(document.getElementsByName("commentsForm")[i] != null) {

			document.getElementsByName("commentsForm")[i].style.display = 'none';
			i++;

		}



	$("commentAddingForm").hide();




}

function hideAllAnswereButtons() {

	var i = 0;

		while(document.getElementsByName("answ_dis")[i] != null) {

			document.getElementsByName("answ_dis")[i] .hide();
			document.getElementsByName("answ_en")[i] .show();
			i++;

		}


		var i = 0;

		while(document.getElementsByName("edit_dis")[i] != null) {

			document.getElementsByName("edit_dis")[i] .hide();
			document.getElementsByName("edit_en")[i] .show();
			i++;

		}


		var i = 0;

		while(document.getElementsByName("comment_main_block")[i] != null) {

			document.getElementsByName("comment_main_block")[i] .show();
			i++;

		}
}

//function hideAllEditButtons() {
//
//	var i = 0;
//
//		while(document.getElementsByName("edit_dis")[i] != null) {
//
//			document.getElementsByName("edit_dis")[i] .hide();
//			document.getElementsByName("edit_en")[i] .show();
//			i++;
//
//		}
//
//
//}


function showHideCommentForm() {

		var i = 0;

		while(document.getElementsByName("commentsForm")[i] != null) {
			document.getElementsByName("commentsForm")[i] .style.display = 'none';
			i++;
		}

		var i = 0;

		while(document.getElementsByName("answ_dis")[i] != null) {

			document.getElementsByName("answ_dis")[i] .hide();
			document.getElementsByName("answ_en")[i] .show();
			i++;

		}

		var i = 0;

		while(document.getElementsByName("edit_dis")[i] != null) {

			document.getElementsByName("edit_dis")[i] .hide();
			document.getElementsByName("edit_en")[i] .show();
			i++;

		}


		var i = 0;

		while(document.getElementsByName("comment_main_block")[i] != null) {

			document.getElementsByName("comment_main_block")[i] .show();
			i++;

		}




	 	if($('commentAddingForm').style.display != 'none') {
	 		$('commentAddingForm').hide();
	 		return false;
	 	}
	 	$('commentAddingForm').show();



}


function focusResponseForm() {

	if($('addMainComment').value == 'Добавить отзыв') {
		$('addMainComment').innerHTML = '';

	}
	$('addMainComment').style.fontSize = '12px';
		$('addMainComment').style.color = '#000';
		$('addMainComment').style.fontWeight = 'normal';


}


