
function validatePlantForm(_is_logged)
{
	bolRes = true;

	resetCommentErrors(_is_logged)
	
	bolRes = checkComment() && bolRes;
	if(!_is_logged)
	{
		bolRes = checkCaptcha() && bolRes;
	}

	return bolRes;
}

function resetCommentErrors(_is_logged)
{
	document.getElementById("CommentError").innerHTML = "";
	if(!_is_logged)
	{
		document.getElementById("CaptchaError").innerHTML = "";
	}
}

function checkComment()
{
	var objComment = objWysiwyg.getContent();
	var objError = document.getElementById("CommentError");
	
	if(objComment == "")
	{
		objError.innerHTML = "Обязательное поле";
		return false;
	}
	
	return true;
}

function checkCaptcha()
{
	var objCaptcha = document.getElementById("Captcha");
	var objError = document.getElementById("CaptchaError");
	
	if(objCaptcha.value == "")
	{
		objError.innerHTML = "Обязательное поле";
		return false;
	}
	
	return true;
}

function removeAjaxComment(_objLink, _custId, _commentId, _plantId)
{
	var objAjaxPage = new AjaxPageManage();
	objAjaxPage.setResponseData = function() {doRemoveComment(_objLink);}
	objAjaxPage.getAjaxPage('get_plant_comment', ['action', 'userId', 'commentId'], ["DELETE", _custId, _commentId]);
}

function doRemoveComment(_objLink)
{
	var objTable = _objLink.parentNode.parentNode.parentNode;
	objTable.parentNode.removeChild(objTable);
}

function getAjaxComment(_userId, _plantId, _isPublic, _is_logged)
{
	document.getElementById("CommentFormError").innerHTML = "";
	
	var CaptchaId = 0;
	var Captcha = "";
	
	if(!_is_logged)
	{
		CaptchaId = document.getElementById("captchaId").value;
		Captcha = document.getElementById("Captcha").value;
	}
	var UserComment = objWysiwyg.getContent();
	
	var objAjaxPage = new AjaxPageManage();
	objAjaxPage.doLoading = function() {}
	objAjaxPage.setResponseData = function() {doAddComment(objAjaxPage.responseText, _is_logged); doHideLoader("addCommentLoader");}
	
	objAjaxPage.getAjaxPage('get_plant_comment', ['action', 'userId', 'plantId', 'captchaId', 'Captcha', 'UserComment', 'isPublic'], ["ADD", _userId, _plantId, CaptchaId, Captcha, UserComment, _isPublic]);
}

function doAddComment(_responseText, _is_logged)
{
	if(_responseText.length > 1)
	{
		var objContainer = document.getElementById("commentContainer");
		objContainer.innerHTML += _responseText;
		
		objWysiwyg.setContent("");
	}
	else
	{
		objError = document.getElementById("CommentFormError");

		if(_responseText == 1)
		{
			objError.innerHTML = "Произошла ошибка, попробуйте еще раз позже";
		}
		else if(_responseText == 2)
		{
			objError.innerHTML = "Сообщение успешно отправлено";
		}
		else if(_responseText == 3)
		{
			objError.innerHTML = "Неправильно заполнена проверка";
		}
	}

	if(!_is_logged)
	{
		document.getElementById("Captcha").value = "";
	}
}
