//count num of character in editor currently
function countCharacter(contentId)
{
	for(var i=0;i>-1;i++)
	{
		try{
			//mce_editor_0_max,mce_editor_0_lengths,mce_editor_0_totalCharacter
			if(document.getElementById('mce_editor_'+ i +'_parent') != null)
			{
				var content=tinyMCE.getHtmlContent('mce_editor_'+ i);
				if(null != content){
					//you can get value of muliple textarea when textarea is translated editor.
					var totalCharacter = parseFloat(document.getElementById('mce_editor_'+ i +'_totalCharacter').value);
					document.getElementById('mce_editor_'+ i +'_max').innerHTML=totalCharacter.formatNum();
					var j=parseFloat(content.length);
					if (j<0){
						continue;
					}
					document.getElementById('mce_editor_'+ i +'_lengths').innerHTML=parseInt((j/totalCharacter)*100);
					document.getElementById('mce_editor_'+ i +'_lengths').style.color="red";
				}
			}else{
				break;
			}
		}catch(e)
		{
			document.getElementById('mce_editor_'+ i +'_lengths').innerHTML='0';
			document.getElementById('mce_editor_'+ i +'_lengths').style.color="red";
		}
	}
	//reset current editor
	if(current_editor_id){
		tinyMCE.selectedInstance = tinyMCE.getInstanceById(current_editor_id);
	}
	return true;
}
//formate num from 25000 to 25,000
Number.prototype.formatNum=function(pointPsti)
{ 
       if(this=='')return false; 
            
            if(typeof(pointPsti)=='undefined')
            { 
                var pointPsti=3; 
            }else
            { 
            	if(isNaN(pointPsti))
            	{
            		pointPsti=3
            	}; 
            } 
            
            var num=this+'', numDc='', temp=''; 
            
            if(num.indexOf('.')>-1)
            { 
            	ptPs=num.indexOf('.'); numDc=num.substr(ptPs); num=num.substr(0,ptPs);
            } 
            for(var i=num.length-1; i>=0;temp+=num.substr(i,1), i--); 
            
            var re=new RegExp('(.{'+pointPsti+'})','g'); 
                temp=temp.replace(re,'$1,'); num='';  
                               
            for(var i=temp.length-1; i>=0; num+=temp.substr(i,1), i--); 
                num=num.replace(/^\,|\,$/,'')+numDc; 
            return num; 
           
} 
//count num of character for multiple textarea according by id
setInterval("countCharacter()",1000);
