HJ.Question = Class.create();

HJ.Question.prototype = {

	initialize: function() {
		this.url = basePageURL + "MHMBrowse.htm";
		this.targetContainerId = "pageBottom";
		this.data = null;
		this.tl = null;
		this.replyHTML="";
		this.userObj =null;
		this.userScrName = null;
		this.catName = null;
		this.CategoryUUID=null;
		this.questionIDToSendMail=null;
	},
	loadQATemplate: function () {
	  if(this.tl == null) {
		this.tl = new Af.TemplateLoader(this.url, this.targetContainerId, "MOMTemplateDiv");
	    this.tl.listener = this;
	    this.tl.loadTemplate();	
	  } else {
		this.tl.reAttachElement();
		this.beforeQuestionShow.style.display = "block";
		this.afterQuestionShow.style.display = "none";
		this.searchResultsShowDiv.style.display ="none";
		this.resultDiv.style.display ="none";
		this.browseCatTable.style.display="block";
		this.browseTopicsLink.className="open";
		this.newQuestionsLink.className="open";
		this.loadCategoryInfo();
		//this.textSearch.focus();
	    }
	  return false;
	},
	templateLoaded: function() {
		this.recentAdditions = document.getElementById("recentAdditionDiv");
		this.resultTitle = document.getElementById("resultTitle");
		this.searchResultsShowDiv = document.getElementById("searchResultsShowDiv");
		this.resultDiv = document.getElementById("resultDiv");
		this.resultDiv.style.display ="none";
		this.browseTopicsLink = document.getElementById("browseTopicsLink");
		this.browseTopicsLink.onclick= this.doShowHideTopics.bind(this);
		this.newQuestionsLink = document.getElementById("newQuestionsLink");
		this.newQuestionsLink.onclick= this.doShowHideNewQuestions.bind(this);
		this.browseCatTable = document.getElementById("BrowsePopularTopicTable");
		this.addNewQuestion = document.getElementById("addNewQuestion");
		this.addNewQuestion.onclick = this.doAddNewQuestion.bind(this);
		this.questionId= null;
		this.beforeQuestionShow = document.getElementById("beforeQuestionShow");
		this.afterQuestionShow = document.getElementById("afterQuestionShow");
		this.searchBtn = document.getElementById("btnSearch");
		this.searchBtn.onclick = this.doSearch.bind(this);
		this.textSearch = document.getElementById("txtSearch");
		
	  this.seeingStarLink = document.getElementById("seeingStarLink");
		//this.seeingStarLink.onmouseover = this.doShowPoints.bind(this);
		//this.seeingStarLink.onmouseout = this.doHidePoints.bind(this);
		this.seeingStarLink.onclick = this.doShowPoints.bind(this);

		this.textSearch.onchange = this.doSearch.bindAsEventListener(this);
		this.textSearch.onfocus = this.focusOnTextBox.bindAsEventListener(this);
		this.textSearch.onblur = this.focusLostTextBox.bindAsEventListener(this);
		this.defaultValue = this.textSearch.value;
		
		if (is_ie) {
			 this.textChanger = new Af.TextChanger(this.textSearch);
		}

		this.emailToSendThanks =null;
		this.emailToName =null;
		this.questionText = null;
		this.questionDesc = "";
		this.loadCategoryInfo();

        this.dontSeeLocalQuestions = 
                  document.getElementById("dontSeeLocalQuestions");
        this.createQuestionLink = 
                  document.getElementById("createQuestionLink");
        this.createQuestionLink.onclick = this.doAddNewQuestion.bind(this);
        this.loadMyProfile();
	},

	loadCategoryInfo: function() {
		 var req = new Af.DataRequest(svcURL,this.categoryInfoLoadCompleted.bind(this), this.reqFailedLoadCat.bind(this), null, this.reqLoadCatTimedOut.bind(this));
		 req.addService("CommunityQAService", "getQACategoryList");
		  ajaxEngine.processRequest(req);
		  return false;
	},
    categoryInfoLoadCompleted: function(response, msg) {
		  this.categoryInfoTable = new Af.HtmlColumnRepeater2("planeCategoryTable","name,count",2);
		  this.holidayCategoryTable = new Af.HtmlColumnRepeater("holidayCategoryTable","name,count",1);
		  this.categoryInfoTable.listener = this;
		  this.holidayCategoryTable.listener = this;
		  var questionDS = new Af.XMLToDataSet(response.responseXML);
		  this.questionData = questionDS.data;
		  var holidayCatList = new Array();
		  var planeCatList = new Array();
		  for(var i = 0; i < this.questionData["CategoryInfo"].length; i++){
			  if(this.questionData["CategoryInfo"][i]["owner"] == "Camps"){
				  holidayCatList.push(this.questionData["CategoryInfo"][i]);
			  }else{
  				  planeCatList.push(this.questionData["CategoryInfo"][i]);
			  }
		  }
		  this.categoryInfoTable.setDataList(planeCatList);
		  this.holidayCategoryTable.setDataList(holidayCatList);
		 // this.dataTable = new Af.DataTable(this.questionData["CategoryInfo"]);

		  this.loadRecentAdditions();
	},
		
	reqFailedLoadCat: function(dataRequest, msg) {
		showMessageDialog("We are currently unable to load the categories. Please try again.", "Excuse us!", 350, 100);
	},

	reqLoadCatTimedOut: function(dataRequest) {
		showMessageDialog("We are currently unable to load the categories. Please try again.", "Excuse us!", 350, 100);
	},
	loadRecentAdditions: function() {
		//this.textSearch.value = "";
		var req = new Af.DataRequest(svcURL,this.recentAdditionLoadCompleted.bind(this), this.reqLoadNewQuesFailed.bind(this), null, this.reqLoadNewQuesTimedOut.bind(this));
		req.addService("CommunityQAService", "getNewQuestions");
		req.addParameter("limit","Ten");
		ajaxEngine.processRequest(req);
		return false;
	},
	reqLoadNewQuesFailed:function(){
	 showMessageDialog("We are currently unable to load the categories, Please try again.", "Excuse us!", 350, 100);
	},
	reqLoadNewQuesTimedOut:function(){
		showMessageDialog("We are currently unable to load the categories, Please try again.", "Excuse us!", 350, 100);
	},
	recentAdditionLoadCompleted: function(dataRequest, msg) {
		this.resultDiv.style.display="none";
		this.searchResultsShowDiv.style.display ="none";
		this.recentAdditions.style.display="block";
		var previousHTML = "<table cellSpacing='0'><tbody><tr><td><p>Share your knowledge by being one of the first people to reply to these new questions.</p></td></tr></tbody></table>";
		this.recentAdditions.innerHTML = previousHTML+dataRequest.responseText;
		this.doAttachReplyToQuestion();
		this.handleQuestionDetailTemplate();
		this.doSearchByCategory();
			
	},

	 doShowHideNewQuestions:function(){
		 if (this.newQuestionsLink.className=="open"){
			 this.recentAdditions.style.display="none";
			 this.newQuestionsLink.className="closed";
		 }
		 else{
				this.recentAdditions.style.display="block";
				this.newQuestionsLink.className="open";
		 }
		 return false;
	 },

	 doShowHideTopics:function(){
		 if (this.browseTopicsLink.className=="open"){
				this.browseCatTable.style.display="none";
				this.browseTopicsLink.className="closed";
		 }
		 else{
				this.browseCatTable.style.display="block";
				this.browseTopicsLink.className="open";
		 }
		 return false;
	 },


	 doAttachReplyToQuestion:function(){
		this.addReply = document.getElementsByName("reply");
		for (var index=0;index< this.addReply.length;index++ ){
					this.addReply[index].onclick = this.doAddReply.bindAsEventListener(this);
					this.questionId = this.addReply[index].id;
		}
		return false;
	},

	doAddNewQuestion: function() {
			if(this.dialog == null) {
			this.dialog = new HJ.HomajoonQA("Ask a new question", this, null);
			 this.dialog.width = "520px";
		}
		var obj = new Object();
		this.dialog.showHTMLTemplate(basePageURL + "AskNewQuestion.htm", "pageBottom", "askNewQuestionDiv");
		this.dialog.centerDialog(350, 350);
		this.dialog.setObj(obj, true);
		return false;
	},

	columnSelected: function(columnRepeater, n) {
		var obj = columnRepeater.dlist[n];	
		this.CategoryUUID = obj.UUID;
		this.catName = obj['name'];
		this.getBrowseCatResult();
		return false;
	},
	
	columnRepeaterRowSelected: function(columnRepeater,  n) {	         
		this.columnSelected(columnRepeater, n);
		return false;
    },

	getBrowseCatResult:function(){
			if(this.CategoryUUID==null){
				return false;
			}
		var req = new Af.DataRequest(svcURL,this.requestBrowseCatCompleted.bind(this), this.reqFailedCatResult.bind(this), null, this.reqTimedoutCatResult.bind(this));
		req.addService("CommunityQAService", "getSearchResultsForQA");
		req.addParameter("UUID",this.CategoryUUID);
		ajaxEngine.processRequest(req);
		//this.doAttachReplyToQuestion();
		//this.handleQuestionDetailTemplate();
		//this.doSearchByCategory();
		return false;
		},

	doSearchByCategory:function(){
		this.catIdArr  = document.getElementsByName("catName");
		for (var idx = 0;idx<this.catIdArr.length;idx++){
			this.catIdArr[idx].onclick = this.doBindToCategory.bindAsEventListener(this);
		}/*
		this.memberNameArr = document.getElementsByName("memberName");
		for (var userIndex=0;userIndex<this.memberNameArr.length ; userIndex++){
			this.memberNameArr[userIndex].onclick = this.doShowMemberProfile.bindAsEventListener(this);
		}*/
 },

	doBindToCategory:function(evt){
		var e = evt.target ? evt.target : evt.srcElement;
		if (e != null) {	
			this.CategoryUUID = e.id;
			this.getBrowseCatResult();
		}
		return false;
	},

	requestBrowseCatCompleted: function(response) {
		this.resultDiv.style.display="block";
		this.resultTitle.innerHTML = this.catName;
		this.searchResultsShowDiv.style.display ="block";
		this.searchResultsShowDiv.innerHTML = response.responseText;
		this.newQuestionsLink.className= "closed";
		this.recentAdditions.style.display="none";
		/*this.sortBy = document.getElementById("optionSortBy");
		this.sortBy.onchange =  this.doSortQuestions.bind(this); */
		
		this.handleQuestionSearchTemplate();
		this.doSearchByCategory();
		},

		reqFailedCatResult:function(){
		 showMessageDialog("We are currently unable to load question for this category, Please try again.", "Excuse us!", 350, 100);
		},
		reqTimedoutCatResult:function(){
			showMessageDialog("We are currently unable to load question for this category, Please try again.", "Excuse us!", 350, 100);
		},

	doAddReply: function(evt) {
			var e = evt.target ? evt.target : evt.srcElement;
			if (e != null) {
				this.questionId = e.id;
				//to get the question details from db
				this.doShowQuestionDetail(this.questionId);
			}
			return false;
	},

		doShowQuestionDetail: function(questionId) {
		var req = new Af.DataRequest(svcURL,this.questionDetailLoadCompleted.bind(this), this.reqFailedQuesDetails.bind(this), null, this.reqTimedOutQuesDetails.bind(this));
		req.addService("CommunityQAService", "getQuestionDetailsForReply");
		req.addParameter("UUID",questionId);
		ajaxEngine.processRequest(req);
		return false;
	},

	questionDetailLoadCompleted: function(response, msg) {
		this.replyHTML = response.responseText;
		this.loadReplyTemplate(this.replyHTML);
	},

	reqFailedQuesDetails:function(){
		 showMessageDialog("We are currently unable to show details of this question. Please try again.", "Excuse us!", 350, 100);
	},

	reqTimedOutQuesDetails:function(){
		showMessageDialog("We are currently unable to show details of this question. Please try again.", "Excuse us!", 350, 100);
	},
	loadReplyTemplate:function(replyHTML){
	if(this.replyDialog == null) {
				this.replyDialog = new HJ.WriteReply("Reply to a question", this, null);
				this.replyDialog.width = "520px";
	}
		var obj = new Object();
		this.replyDialog.showHTMLTemplate(basePageURL + "WriteReply.htm", "pageBottom", "replyToQuestion");
		this.replyDialog.centerDialog(350, 350);
		this.replyDialog.setObj(replyHTML,this.questionId, obj);
		return false;
	},

	handleQuestionDetailTemplate: function() {
		 this.showQuestionDetail = document.getElementsByName("showQuestionDetail");
		 for (quesIndex = 0;quesIndex < this.showQuestionDetail.length ;quesIndex++ ) {
			 this.showQuestionDetail[quesIndex].onclick = this.doGetQuestionDetails.bindAsEventListener(this);
		 }
		 this.memberNames = document.getElementsByName("memberName");		
		 if(this.memberNames != null){
			 for (var userIndex=0;userIndex<this.memberNames.length ; userIndex++){
				this.memberNames[userIndex].onclick = this.doShowMemberProfile.bindAsEventListener(this);
			 }
		 }
	},

	handleQuestionSearchTemplate: function() {
		 this.searchQuestion = document.getElementsByName("showQuestionDetail");
		 for (quesIndex = 0;quesIndex < this.searchQuestion.length ;quesIndex++ ) {
			 this.searchQuestion[quesIndex].onclick = this.doGetQuestionDetails.bindAsEventListener(this);
		 }
		 	this.questionIdList="";
			for (var quesIndex = 0;quesIndex < this.searchQuestion.length ;quesIndex++ ) {
				 if (this.questionIdList==""){
						this.questionIdList = this.searchQuestion[quesIndex].id;
				 }else{
						 this.questionIdList += ","+this.searchQuestion[quesIndex].id;
				 }
		 }
		 this.memberNames = document.getElementsByName("memberName");		
		 if(this.memberNames != null){
			 for (var userIndex=0;userIndex<this.memberNames.length ; userIndex++){
				this.memberNames[userIndex].onclick = this.doShowMemberProfile.bindAsEventListener(this);
			 }
		 }
	},


	doGetQuestionDetails: function(evt) {
		var e = evt.target ? evt.target : evt.srcElement;
		if (e != null) {
		this.questionId = e.id;
		this.questionIDToSendMail = e.id;
		this.doShowQuestionAnswerDetail(this.questionId);
		}
	},
	
	doShowQuestionAnswerDetail:function(questionId){
		if(questionId == null || questionId == ""){
			return;
		}
		var req = new Af.DataRequest(svcURL,this.questionAnswerDetailLoadCompleted.bind(this), this.reqFailedQADetails.bind(this), null, this.reqTimedOutQADetails.bind(this));
		req.addService("CommunityQAService", "getQuestionDetails");
		req.addParameter("UUID",questionId);
		ajaxEngine.processRequest(req);
	},

	reqFailedQADetails:function(){
		showMessageDialog("We are currently unable to load question and answers added by this user. Please try again.", "Excuse us!", 400, 100);
	},
	reqTimedOutQADetails:function(){
		showMessageDialog("We are currently unable to load question and answers added by this user. Please try again.", "Excuse us!", 400, 100);
	},
	questionAnswerDetailLoadCompleted:function(response, msg){
		this.beforeQuestionShow.style.display = "none";
		this.afterQuestionShow.style.display = "block";
		this.resultDiv.style.display="none";
		this.searchResultsShowDiv.style.display ="none";
		this.newQuestionsLink.className="open"
		this.recentAdditions.style.display="block";
		this.afterQuestionShow.innerHTML = response.responseText;
		
		this.doAttachReplyToQuestion();
		this.handleQuestionDetailTemplate();
		
		this.memberNames = document.getElementsByName("memberName");
		
		for (var userIndex=0;userIndex<this.memberNames.length ; userIndex++){
			this.memberNames[userIndex].onclick = this.doShowMemberProfile.bindAsEventListener(this);
		}	

		this.sendThanks =  document.getElementsByName("sendThanks");
		for (tnxIdx=0; tnxIdx<this.sendThanks.length;++tnxIdx ){
			this.sendThanks[tnxIdx].onclick = this.doSendThanks.bindAsEventListener(this);
		}
		this.sendToFriend =  document.getElementById("sendToFriend");
		if(this.sendToFriend!=null){
			this.sendToFriend.onclick = this.doSendToFriend.bind(this);
		}
		this.showPublicProfile =  document.getElementsByName("showPublicProfile");
		for(Ip = 0; Ip < this.showPublicProfile.length; Ip++) {
			this.showPublicProfile[Ip].onclick = this.doShowMemberProfile.bindAsEventListener(this);
		}
		
	},

	doSendThanks: function(evt) {
		var e = evt.target ? evt.target : evt.srcElement;
		if (e != null) {
				var strArray = (e.id).split(",");
				this.emailToSendThanks = strArray[0];
				this.emailToName = strArray[1];
				this.loadScreenName();
		}
		if (this.thanksDialog != null) {
			delete this.thanksDialog;
		}
		var handler = {
				templateLoaded: function() {
						this.parent.replyThanksDialogLoaded();
				},
						parent:this
		}
		this.thanksDialog = new Af.HtmlDialog("&nbsp;", handler, null);
		this.thanksDialog.width = "235px";
		this.thanksDialog.showHTMLTemplate(basePageURL + "MHMThankYouNote.htm", "pageBottom", "ThanksDiv");
		this.thanksDialog.centerDialog(350, 350);
		this.doSetMessage();
	},

		replyThanksDialogLoaded: function() {
		this.from = document.getElementById("from");
		this.To = document.getElementById("To");
		this.toEMail = document.getElementById("toEmail");
		this.messageBottom = document.getElementById("messageBottom");
		this.questionSpan = document.getElementById("questionSpan");
		this.replyDontSendThanks = document.getElementById("replyDontSendThanks");
		this.replySendThanks = document.getElementById("replySendThanks");
		
		this.replyDontSendThanks.onclick = this.doReplyThanksDontSend.bind(this);
		this.replySendThanks.onclick = this.doReplyThanksSend.bind(this);
		this.doSetMessage();
	},

	 doSetMessage:function(){
		this.questionText = document.getElementById("questionText").value;
		this.questionDesc = document.getElementById("queDescription").value;
		if(this.To!=null && this.To!=undefined){
			this.To.innerHTML = "To: "+this.emailToName;
		}
		if(this.from!=null && this.from!=undefined){
			this.from.innerHTML = "<br/>"+this.userScrName;
		}
		if(this.questionSpan!=null){
			this.questionSpan.innerHTML = this.questionText;
		}
		if(this.messageBottom!=null){
			this.messageDefaultValue = this.messageBottom.value;
		}
		
	},

		doReplyThanksDontSend: function() {
		this.thanksDialog.hide();
	},

	doReplyThanksSend: function() {
		var req = new Af.DataRequest(svcURL,this.reqSendThanksCompleted.bind(this), this.reqFailedSendThanks.bind(this), null, this.reqTimedOutSendThanks.bind(this));
		req.addService("CommunityQAService", "sendThanksEMail");
		req.addParameter("emailId", this.emailToSendThanks);
		req.addParameter("xslTemplate", "sendThanks.xsl");
		
		var message1 = "Thank you for your very helpful response to my question in Jooners's section on In the Know:";
		var strXml = "<messages>";
		strXml += "<messageTop>" + xmlEncode(message1) + "</messageTop>";
		strXml += "<question>" + xmlEncode(this.questionText) + "</question>";
		if(this.messageBottom.value==this.messageDefaultValue){
				var m2 = "Your generosity has helped me a lot.";
				strXml+= "<messageBottom>" + xmlEncode(m2) + "</messageBottom>";
		}else{
				strXml += "<messageBottom>" + xmlEncode(this.messageBottom.value) + "</messageBottom>";
		}
		strXml += "</messages>";
		req.xmlDoc = strXml;
		ajaxEngine.processRequest(req);
		this.thanksDialog.hide();
	},
	
	reqSendThanksCompleted: function(response) {
		app.thankYouNote.doOpenThankYouDialog(response.responseText);
	},
	reqFailedSendThanks:function(){
		showMessageDialog("We are currently unable to send thank you email. Please try again.", "Excuse us!", 350, 100);
	},
	reqTimedOutSendThanks:function(){
		showMessageDialog("We are currently unable to send thank you email. Please try again.", "Excuse us!", 350, 100);
	},
	doSortQuestions:function(){
		if(this.questionIdList == null || this.questionIdList.length == 0){
			return;
		}
		var req = new Af.DataRequest(svcURL,this.reqSortQuestionCompleted.bind(this), this.reqSortQuesFailed.bind(this), null, this.reqSortQuesTimedOut.bind(this));
		req.addService("CommunityQAService", "sortQuestion");
		req.addParameter("sortBy",this.sortBy.value);
		req.addParameter("questionIdList",this.questionIdList);
		ajaxEngine.processRequest(req);
	},

	 reqSortQuestionCompleted:function(response){
			this.resultDiv.style.display="block";
			this.searchResultsShowDiv.style.display="block";
			this.searchResultsShowDiv.innerHTML = response.responseText;
			this.handleQuestionDetailTemplate();
			this.doSearchByCategory();
	 },

	reqSortQuesFailed: function(dataRequest, msg) {
		    showMessageDialog("We are currently unable to sort these records. Please try again.", "Excuse us!", 350, 100);
	},
	reqSortQuesTimedOut: function(dataRequest) {
		    showMessageDialog("We are currently unable to sort these records. Please try again.", "Excuse us!", 350, 100);
	},

	doSearch:function(){
		if(this.textSearch.value == "" || this.textSearch.value == undefined)  {
			showMessageDialog("Please enter a word in the search box.", "Request", 300, 100);
			return; 
		}
		var req = new Af.DataRequest(svcURL,this.reqSearchCompleted.bind(this), this.reqSearchFailed.bind(this), null, this.reqSearchTimedOut.bind(this));
		req.addService("CommunityQAService", "searchQuestions");
		req.addParameter("searchParam",this.textSearch.value);
		ajaxEngine.processRequest(req);
		return;
	},

	reqSearchCompleted:function(response){
		this.resultDiv.style.display ="block";
		this.searchResultsShowDiv.style.display ="block";
		this.browseCatTable.style.display="none";
		this.recentAdditions.style.display="none";
		this.browseTopicsLink.className="closed";
		this.newQuestionsLink.className="closed";
		
		var unMatchedHTML = "<table cellSpacing='5' width='100%'><tbody><p style='margin-bottom:10px;'>We're sorry. There are no Jooners Questions that match this search request.</p><p style='margin-bottom:10px;'>May we recommend:</p><ul><li>Words are correctly spelled</li><li>Try more general keywords</li><li>Try different, but similar, keywords</li><li>Try fewer keywords</li></ul></tbody></table>";
		if(trim(unMatchedHTML).length!=trim(response.responseText).length){
			var searchText = trim(this.textSearch.value);
			searchText = searchText.replace(/([\\|^$(),[\]{}.*+?])/g, '\\$1' );
			if( /^\s*$/.test( searchText ) ) {
				return false;
			}
			var searchArray = searchText.split(" ");
			var resultText = response.responseText;
			var highlightStartTag = "<span class='searchTerms'>";
			var highlightEndTag = "</span>";
			for (var i = 0; i < searchArray.length; i++) {
				resultText = this.doHighlight(resultText, searchArray[i], highlightStartTag, highlightEndTag);
			}
			this.searchResultsShowDiv.innerHTML= resultText;
		}else{
			this.searchResultsShowDiv.innerHTML = response.responseText;
		}
		//this.sortBy = document.getElementById("optionSortBy");
		//this.sortBy.onchange =  this.doSortQuestions.bind(this);
		//this.handleQuestionDetailTemplate();
		this.handleQuestionSearchTemplate();
		this.doSearchByCategory();
		},

	reqSearchFailed: function(dataRequest, msg) {
		showMessageDialog("We are currently unable to search qustion for this text. Please try again.", "Excuse us!", 350, 100);
	},

	reqSearchTimedOut: function(dataRequest) {
		showMessageDialog("We are currently unable to search qustion for this text. Please try again.", "Excuse us!", 350, 100);
	},

	 doSendToFriend:function(){
		this.doSetMessage();
		this.loadScreenName();
		if (this.sendToFriendDialog == null) {
			this.sendToFriendDialog = new HJ.SendQuestionToFriend("Share a Question", this, null);
			this.sendToFriendDialog.width = "370px";
		}
		var obj = new Object();
		this.sendToFriendDialog.showHTMLTemplate(basePageURL + "SendQuestionToFriend.htm", "pageBottom", "sendToFriendContent");
		this.sendToFriendDialog.centerDialog(350, 350);
		this.sendToFriendDialog.setObj(obj);
	 },

	loadScreenName: function() {
		var req = new Af.DataRequest(svcURL,this.userScreenNameLoadCompleted.bind(this), this.reqFailedLoadScreen.bind(this), null, this.loadScrTimedout.bind(this));
		req.addService("AccessControlSvc", "getMyProfile");
		ajaxEngine.processRequest(req);
	},

	userScreenNameLoadCompleted: function(dataRequest) {
		var xmlDataSource = new Af.XMLToDataSet(dataRequest.responseXML);
		this.userObj = xmlDataSource.data;
		this.userScrName = this.userObj.userId;
	},
	reqFailedLoadScreen:function(){
	},

	loadScrTimedout:function(){
	},

	doShowMemberProfile:function(evt){
		var e = evt.target ? evt.target : evt.srcElement;
			if (e != null) { 
			app.memberProfile.loadMemberProfileTemplate(e.id);
		}
	},
	
	doHighlight:function(bodyText, searchTerm, highlightStartTag, highlightEndTag){
		if ((!highlightStartTag) || (!highlightEndTag)) {
				highlightStartTag = "<span class='searchTerms'>";
				highlightEndTag = "</span>";
		}
		var newText = "";
		var i = -1;
		var lcSearchTerm = searchTerm.toLowerCase();
		var lcBodyText = bodyText.toLowerCase();

		while (bodyText.length > 0) {
			i = lcBodyText.indexOf(lcSearchTerm, i+1);
			if (i < 0) {
				newText += bodyText;
				bodyText = "";
			}
			else {
				// skip anything inside an HTML tag
				if (bodyText.lastIndexOf(">", i) >= bodyText.lastIndexOf("<", i)) {
					// skip anything inside a <script> block
					if (lcBodyText.lastIndexOf("/script>", i) >= lcBodyText.lastIndexOf("<script", i)) {
							newText += bodyText.substring(0, i) + highlightStartTag + bodyText.substr(i, searchTerm.length) + highlightEndTag;
							bodyText = bodyText.substr(i + searchTerm.length);
							lcBodyText = bodyText.toLowerCase();
							i = -1;
					}
				}
			}
		}
		return newText;
	 },


	doOpenSeeingStarPage: function() {
		app.seeingStar.loadSeeingStarTemplate();
		return false;
	},

	doShowPoints:function(){
		app.seeingStar.doLearnAboutPoints();
		return false;
	},

	doHidePoints:function(){
		app.seeingStar.hideLearnAboutPoints();
		return false;
	},

	focusOnTextBox: function(evt) {
		//this.textSearch.focus();
		this.browseCatTable.style.display="none";
		this.recentAdditions.style.display="none";
		this.browseTopicsLink.className="closed";
		this.newQuestionsLink.className="closed";	
		this.textSearch.value = "";
		this.textSearch.focus();
	},

	focusLostTextBox:function(evt){
		var s = this.textSearch.value;
		if (s == null) {
		s = "";
		} else {
		s = trim(s);
		}
		if (s == trim(this.defaultValue) || s == "") {
		this.textSearch.value = this.defaultValue;
		consumeEvent(evt);
		}
	},

	loadMyProfile: function() {
	   var req = new Af.DataRequest(svcURL,
       this.requestMyProfileLoadCompleted.bind(this), this.requestFailedCommon.bind(this), null, this.requestTimedoutCommon.bind(this));
	   req.addService("AccessControlSvc", "getMyProfile");
	   ajaxEngine.processRequest(req);
	},
	 
	 requestMyProfileLoadCompleted: function(response) {
	   //debugA(response.responseText);
		var xds = new Af.XMLToDataSet(response.responseXML);
        var userObj = xds.data;
        if (userObj.zip != null && userObj.zip.substring(0,2) == "94") {
		    this.dontSeeLocalQuestions.style.display = "none";
        } else {
		    this.dontSeeLocalQuestions.style.display = "block";
        }
     },

	 requestFailedCommon: function(dataRequest, msg) {
        //no-op
    },

	 requestTimedoutCommon: function(dataRequest, msg) {
        //no-op
    }
}

