HJ.WriteReply = Class.create();

HJ.WriteReply.prototype = Object.extend(new Af.HtmlDialog(), {
      
	initialize: function(title, handler, content) {
		this._initializeDialog(title, handler, content);
		this.handler = handler;
		this.obj = null;
		this.replyHtml = null;
		this.questionId = null;
	},
  
  
	templateLoaded: function() {
		this.replyView = document.getElementById("replyView");
		this.doSetInfo();
},

	setObj: function(replyHTML, questionId,obj) {
			this.obj = obj;
			this.replyHtml = replyHTML;
			this.questionId = questionId;
			this.doSetInfo();
	},

	doSetInfo: function() {
		if(this.replyHtml !="" && this.replyView!=null) {
				this.replyView.innerHTML = this.replyHtml;
				this.seeingStarImgLink = document.getElementById("seeingStarImgLink");
				this.seeingStarImgLink.onclick = this.doShowEarnedPoints.bind(this);
				//this.seeingStarImgLink.onmouseover = this.doShowEarnedPoints.bind(this);
				//this.seeingStarImgLink.onmouseout = this.doHideEarnedPoints.bind(this);
				this.saveReply = document.getElementById("saveReply");
				this.dontSaveReply = document.getElementById("dontSaveReply");
				this.replyTextObj = document.getElementById("replyTextArea");
				this.memberNameArr = document.getElementsByName("userName");
				for (var userIndex=0;userIndex<this.memberNameArr.length ; userIndex++){
					this.memberNameArr[userIndex].onclick = this.showProfile.bindAsEventListener(this);
				}
				
				this.replyTextObj.focus();
				this.replyTextObj.value="";
				
				this.saveReply.onclick = this.doSaveReply.bind(this);
				this.armedButton = this.saveReply;
				this.dontSaveReply.onclick = this.doDontSaveReply.bind(this);
		}
	},
	doSaveReply: function() {
		if(this.replyTextObj.value == ""){
			showMessageDialog("Please enter a reply to question.", "Request", 300, 100);
			return false;
		}
		var req = new Af.DataRequest(svcURL,this.reqSaveReviewDetailCompleted.bind(this), this.reqFailed.bind(this), null, this.reqTimedOut.bind(this));
		req.addService("CommunityQAService", "saveReply");
		req.addParameter("UUID", this.questionId);
		var xmlString = "<messages>";
		xmlString += "<editableMessage>" + xmlEncode(this.replyTextObj.value) + "</editableMessage>";
		xmlString += "</messages>";
		req.xmlDoc = xmlString;
		ajaxEngine.processRequest(req);
		this.hide();
	},
	doDontSaveReply: function() {
		this.hide();
	},
	reqSaveReviewDetailCompleted: function(response) {
		app.thankYouNote.doOpenThankYouDialog(response.responseText);
		this.handler.doShowQuestionAnswerDetail(this.questionId);
	},
	reqFailed: function(dataRequest, msg) {
		    showMessageDialog("We are currently unable to save this review.  Please try again.", "Excuse us!", 500, 200);
	},

	reqTimedOut: function(dataRequest) {
		    showMessageDialog("We are currently unable to save this review.  Please try again." , "Excuse us!", 500, 200);
	},
	
	doShowSeeingStarPage: function() {
		app.seeingStar.loadSeeingStarTemplate();
		return false;
	},

	showProfile:function(evt){
		app.question.doShowMemberProfile(evt);
	},

	doShowEarnedPoints:function(){
		app.seeingStar.doLearnAboutPoints();
	},

	doHideEarnedPoints:function(){
		app.seeingStar.hideLearnAboutPoints();
	}
	

});

