/**
 * @namespace
 * Class Comment
 * 
 * This class is intended to encapsulate all the methods and attributes of a
 * layer comment.
 * 
 * Created on 04/03/2009
 * 
 * @class Comment
 * 
 * @property {number} _id
 * @property {string} _identity
 * @property {string} _date
 * @property {string} _text
 * 
 * @author "Antonio Perez (tony@layers.com)"
 * @version <1.0>
 *  
 */
function Comment(){
	this._id = "";
	this._displayName = "";
	this._identity = "";
	this._date = new Date();
	this._text = "";
}

Comment.prototype._id;
Comment.prototype._displayName;
Comment.prototype._date;
Comment.prototype._text;
Comment.prototype._identity;



/**
 * parse
 * 
 * This function returns a comment from an XMLDocument returned by the server. It parses the XML received and
 * assign all the fields to the attributes of a comment.
 *
 * Created on 21/07/2009
 * @author Antonio Perez (tony@layers.com)"
 * @version 1.0
 * 
 * @memberOf Comment
 * @funtion
 * 
 * @param {mydata} XMLDocument An XMLDocument previously constructed by the makeRequest function of the WSProxy class
 *
 * @return {Comment} A Comment object
 */
Comment.prototype.parse = function(mycomment){
	try{		
		var fullName = "";
				
		if(mycomment != undefined){
			try{
				this._id = mycomment.attributes.getNamedItem("cid").value;
			}catch(e){
				this._id = "";
			}
			
			try{
				this._identity = mycomment.getElementsByTagName("identity")[0].childNodes[0].nodeValue;
			}catch(e){
				this._identity = "";
			}
			
			
			try{
				this._displayName = mycomment.getElementsByTagName("identity")[0].attributes.getNamedItem("firstName").value + " " + mycomment.getElementsByTagName("identity")[0].attributes.getNamedItem("surName").value;							
			}catch(e){
				this._displayName = this._identity;
			}
			
			try{			
				this._date.setISO8601( mycomment.attributes.getNamedItem("ts").value );
			}catch(e){
				this._date = "";
			}
			
			try{
				this._text = mycomment.childNodes[1].nodeValue;
			}catch(e){
				this._text = "";
			}
			
		}else{
			throw new Exception("Error creating Comment from XML");
		}
		
		return this;
		
	}catch(e){		
		//throw e;
	}
}


/**
 * getDisplayName
 * 
 * Getter of the attribute _identity
 *
 * Created on 21/07/2009
 * @author "Antonio Perez (tony@layers.com)"
 * @version 1.0
 *
 * @memberOf Comment
 * @function
 *
 * @return {string} Comment owner
 */
Comment.prototype.getDisplayName = function(){
	return this._displayName;
}



/**
 * getIdentity
 * 
 * Getter of the attribute _displayName
 *
 * Created on 21/07/2009
 * @author "Antonio Perez (tony@layers.com)"
 * @version 1.0
 *
 * @memberOf Comment
 * @function
 *
 * @return {string} Comment owner
 */
Comment.prototype.getIdentity = function(){
	return this._identity;
}


/**
 * getId
 * 
 * Getter of the attribute id
 *
 * Created on 04/03/2009
 * @author "Pablo Casado (pablo.casado@layers.com)"
 * @version <version>
 * 
 * @memberOf User
 * @function
 *
 * @return {string} A User object
 */
Comment.prototype.getId = function(){
	return this._id;
}

/**
 * getId
 * 
 * Getter of the attribute id
 *
 * Created on 21/07/2009
 * @author "Antonio Perez (tony@layers.com)"
 * @version 1.0
 *
 * @memberOf Comment
 * @function
 *
 * @return {string} The id of the comment
 *
 */
Comment.prototype.getId = function(){
	return this._id;
}

/**
 * getText
 * 
 * Getter of the attribute _text
 *
 * Created on 21/07/2009
 * @author "Antonio Perez (tony@layers.com)"
 * @version 1.0
 *
 * @memberOf Comment
 * @function
 *
 * @return {Date} The date this comment was created.
 *
 */
Comment.prototype.getDate = function(){
	
	return this._date.toDateString();
}


/**
 * getText
 * 
 * Getter of the attribute _date
 *
 * Created on 21/07/2009
 * @author "Antonio Perez (tony@layers.com)"
 * @version 1.0
 *
 * @memberOf Comment
 * @function
 *
 * @return {string} The text of the comment
 *
 */
Comment.prototype.getText = function(id){
	return this._text;
}



