(function(jQuery) {
		  
	var self = null;
 
	jQuery.fn.autogrow = function(o)
	{	
		return this.each(function() {
			new jQuery.autogrow(this, o);
		});
	};
	jQuery.autogrow = function (e, o)
	{
		this.options		  	= o || {};
		this.divCloneTextArea	= null;
		this.interval	 	  	= null;
		this.line_height	  	= this.options.lineHeight || parseInt(jQuery(e).css('line-height'));
		this.min_height		  	= this.options.minHeight || parseInt(jQuery(e).css('min-height'));
		this.max_height		  	= this.options.maxHeight || parseInt(jQuery(e).css('max-height'));
		this.init_height		= this.options.initHeight || parseInt(jQuery(e).css('height'));
		this.textarea		  	= jQuery(e);
		if (this.line_height == NaN)
		{
			this.line_height = 0;
		}
		if (this.min_height == NaN || this.min_height == 0)
		{
			this.min_height = this.textarea.height();
		}
		if (this.init_height == NaN || this.init_height == 0)
		{
			this.init_height = this.textarea.height();
		}
		this.init();
	};
	
	jQuery.autogrow.fn = jQuery.autogrow.prototype={};
 	jQuery.autogrow.fn.extend = jQuery.autogrow.extend = jQuery.extend;
	jQuery.autogrow.fn.extend({						 
		init: function(){			
				var self = this;			
				this.textarea.css({overflow: 'hidden', display: 'block'});
				this.textarea.bind('focus', function() { self.startExpand() } ).bind('blur', function() { self.stopExpand()});
		},				 
		startExpand: function() {				
		  	var self = this;
			this.interval = window.setInterval(function() {self.checkExpand()},100);
		},
		stopExpand: function(){
			try{
				if(this.divCloneTextArea.html()=='') 
				{
					this.textarea.css({'height':this.init_height});
					$(this.divCloneTextArea).remove();
				}
				clearInterval(this.interval);
			}
			catch(e){};
		},
		checkExpand: function() {
			if (this.divCloneTextArea == null)
			{
				this.divCloneTextArea = jQuery('<div></div>');
				var strPadding=this.textarea.css('padding-top')+' '+this.textarea.css('padding-right')+' '+this.textarea.css('padding-bottom')+' '+this.textarea.css('padding-left');
				this.divCloneTextArea.css({'font-size': this.textarea.css('font-size'),'font-family': this.textarea.css('font-family'),'width': this.textarea.css('width'),'padding':strPadding,'display':'none'}).appendTo('body');
			}
			var html = this.textarea.val().replace(/(<|>)/g, '');
			if (jQuery.browser.msie)
			{
				html = html.replace(/\n/g, '<BR>new');
			}
			else
			{
				html = html.replace(/\n/g, '<br>new');
			}
			if ((this.divCloneTextArea.html() != html))
			{
				this.divCloneTextArea.html(html);	
				
				if (this.max_height > 0 && (this.divCloneTextArea.height() + this.line_height > this.max_height))
				{
					this.textarea.css('overflow-y', 'auto');	
				}
				else
				{
					this.textarea.css('overflow-y', 'hidden');
					if (this.textarea.height() < this.divCloneTextArea.height() + this.line_height || (this.divCloneTextArea.height() < this.textarea.height()))
					{	
						if((this.divCloneTextArea.height() + this.line_height)<(this.min_height))
						{
							this.textarea.css({'height': (this.min_height) + 'px'});
						}	
						else
						{
							this.textarea.css({'height': (this.divCloneTextArea.height()+ this.line_height) + 'px'});
						}
					}
				}
			}
			else{
				if((this.divCloneTextArea.height() + this.line_height)<(this.min_height))
				{
					this.textarea.css({'height': (this.min_height) + 'px'});
				}	
				else
				{
					this.textarea.css({'height': (this.divCloneTextArea.height()+ this.line_height) + 'px'});
				}
			}
		}
						 
	 });
})(jQuery)
/*--------------------------------------------------------------------*/
var gObjGrow,gObjAreaComment;
function ym2_txtAreaComment(strSel){
	
	jQuery(strSel).bind('focus',function(){
		if(jQuery(this).val()=='Viết tiếp bình luận hoặc trả lời ...'){
			jQuery(this).val('')
			jQuery(this).parents('.temp').addClass('active');
		}
	});
	jQuery(strSel).blur(function(){
		if(jQuery(this).val()=='') 
		{
			jQuery(this).val('Viết tiếp bình luận hoặc trả lời ...');
			jQuery(this).parents('.temp').removeClass('active');
		}
	});
	jQuery(strSel).autogrow({minHeight:32});
}
jQuery('textarea.areacmt').autogrow({minHeight:30});
jQuery('textarea.areacmt2').autogrow({minHeight:30});

