﻿Type.registerNamespace('MySpace.ProfileDisplay');

MySpace.ProfileDisplay.CommentModule = function(){
	MySpace.ProfileDisplay.CommentModule.initializeBase(this);
};

MySpace.ProfileDisplay.CommentModule.prototype = {
	/// comments
	_MIN_COMMENT_LENGTH: 2,

	/// Fields
	_formElement: null,
	_txtElement: null,
	_previewElement: null,
	_submitBtnElement: null,
	_feedbackElement: null,
	_uid: null,

	/// Properties
	get_uid: function(){ return this._uid; },
	set_uid: function(value){ this._uid = value; },
	
	/// Events	
	initialize : function(){
		// todo: debug -- console.log("comment Module initialize" );
		this._wire();
		this._attachEvents();
	},
	
	dispose : function(){
		this._formElement = null;
		this._previewElement = null;
		this._submitBtnElement = null;
		this._txtElement = null;
		this._feedbackElement = null;
	},
	
	/// Private Methods
	_wire: function(){
		this._formElement = $get("commentEntryForm");
		this._previewElement = $get("commentPreview");
		this._submitBtnElement = $get("friendCommentBtn");
		this._txtElement = $get("friendCommentText");
		this._feedbackElement = $get("friendCommentFeedback");
	},
	
	_attachEvents: function(){
		var x = this;
		$addHandlers( x._submitBtnElement, { click: function(e){ x.submit(); } }, x );
	},
	
	/// Public Methods
	submit: function(){
		if (this.isValid()){
			alert("So far you've typed \""+this._txtElement.value+"\"");
		}
	},

	isValid: function(){
		var s = this._txtElement.value;
		if (s.trim().length < this._MIN_COMMENT_LENGTH){
			this._feedbackElement.innerHTML = String.format("Your message is too short. The minimum comment length is {0} characters.", this._MIN_COMMENT_LENGTH);
			this._feedbackElement.style.display = "block";
			return false;
		}
		this._feedbackElement.innerHTML = "";
		this._feedbackElement.style.display = "none";
		return true;
	}

};
// MySpace.ProfileDisplay.UIElement );
MySpace.ProfileDisplay.CommentModule.registerClass('MySpace.ProfileDisplay', Sys.Component );
