/**
 *  提交评论的时候，如何没有评论内容，不提交
 */
function submit_comment() {
    if ( /^[ \n]*$/.test( $('comment_content').value ) ) {
	   alert( "评论内容不能为空");
	   $('comment_content').focus();
	   return false;
	}
	return true;
}

/**
* 保存评论信息
*/
function save_comment(){
	if(submit_comment() != true)
		return false;
	new Ajax.Request('/comment/post.action',
		{
			method:'get',
			parameters: {'goodsId': $('comment_goodsId').value, 'comment.memberId': ($('comment_memberId') == null) ? null : $('comment_memberId').value , 'comment.name': $('comment_name').value, 'comment.content': $('comment_content').value, 'comment.displayFlag': $('comment_displayFlag').value, 'comment.goodsId':$('comment_goodsId').value },
			onSuccess: function(transport) { try{ onGetCommentsByGoodsIdSuccess(transport); $('comment_content').value=''; } catch(e){alert('保存评论出现异常！')}; $("fieldset_saveComment").show(); $("loadcomment").hide();},
			onLoading: function() { $("fieldset_saveComment").hide(); $("loadcomment").show() },
		    onFailure: function(){ alert('保存评论发生错误！'); $("fieldset_saveComment").show(); $("loadcomment").hide(); }
		});
}


/**
* 保存商品提问信息
**/
function save_question(){
	if ( submit_question() ) {
	
    	new Ajax.Request('/comment/postQuestion.action',
    		{
    			method:'get',
    			parameters: {'goodsId': $('questionReply_goodsId').value, 'questionReply.memberId': ($('questionReply_memberId') == null) ? null : $('questionReply_memberId').value , 'questionReply.name': $('questionReply_name').value, 'questionReply.questionContent': $('question_content').value, 'questionReply.displayFlag': $('questionReply_displayFlag').value, 'questionReply.replyFlag':$('questionReply_replyFlag').value ,'questionReply.goodsId':$('questionReply_goodsId').value},
    			onSuccess: function(transport) { try{ onQuestionReplyGoodsIdSuccess(transport); $('question_content').value=''; } catch(e){alert(e);alert('保存提问信息出现异常！')}; $("fieldset_saveQuestion").show(); $("loadquestion").hide();},
    			onLoading: function() { $("fieldset_saveQuestion").hide(); $("loadquestion").show() },
    		    onFailure: function(){ alert('保存提问信息发生错误！'); $("fieldset_saveQuestion").show(); $("loadquestion").hide(); }
    		});
	}
}


/**
 *  提交问题的时候，如何没有问题，不提交
 */
function submit_question() {
    if ( /^[ \n]*$/.test( $('question_content').value ) ) {
	   alert( "提问内容不能为空");
	   $('question_content').focus();
	   return false;
	}
	return true;
}

//用于前台商品
function getCommentsByGoodsId(id,currentPage) {

		new Ajax.Request('/comment/query.action',
		  {
		    method:'get',
		    parameters: {goodsId: id, "page.currentPage": currentPage},
		    onSuccess: function(transport) { try{ onGetCommentsByGoodsIdSuccess(transport); } catch(e){alert('分页查询出现异常！')}; $("ind_comment").hide(); },
		    onLoading: function() { $("ind_comment").show(); },
		    onFailure: function(){ alert('分页查询错误！'); $("ind_comment").hide();}
		  });
}
	
function onGetCommentsByGoodsIdSuccess(transport){
	$('fieldset_comment').innerHTML=transport.responseText;
}



function getQuestionReplyGoodsId(id,currentPage){

		new Ajax.Request('/comment/queryQuestion.action',
			  {
			    method:'get',
			    parameters: {goodsId: id, "page.currentPage": currentPage},
			    onSuccess: function(transport) { try{ onQuestionReplyGoodsIdSuccess(transport); } catch(e){alert('分页查询出现异常！')}; $("indicator").hide(); },
			    onLoading: function() { $("indicator").show(); },
			    onFailure: function(){ alert('分页查询错误！'); $("indicator").hide(); }
			  });
}

function onQuestionReplyGoodsIdSuccess(transport){
	$('fieldset_question').innerHTML=transport.responseText;
}
