// beepites:
// <div>
// <textarea maxlength=1500 id="ebbol_lesz_az_editor"></textarea>    
// <p class="charsRemaining">&nbsp;</p>
// </div> 

// init:
// tinyMCE.init({
//		...
//		setup : charcountinit,
//		...	
// });
 
// kell hozza: "php.js" a strip_tags es a html_entity_decode miatt;

function charcountinit(ed) 
{
        ed.onKeyUp.add( 	function (ed, evt) 
							{		
								//refresh_label( ed.id );									// sajnos nagy szovegnel lassu, ki kell venni		
				            } );
        ed.onInit.add( 	function (ed, evt) 
							{		
								refresh_label( ed.id );		
				            } );
}

function refresh_label( editorid )
{
	var max = get_maxlength( editorid );
    var l = calc_chars( editorid );
    var lbl;

	if ( max == undefined )
		lbl = 'Le&uuml;t&eacute;sek sz&aacute;ma: ' + l;
	else				                				                
	    if ( l <= max )
			lbl = 'M&eacute;g ' + ( max - l ) + ' karakternyi hely van.';
		else
			lbl = 'A maxim&aacute;lis hossz (' + max + ' karakter) t&uacute;ll&eacute;pve ' + ( l - max  ) + ' karakterrel';
	lbl += " &nbsp; <a href='javascript:;' onclick='refresh_label( \"" + editorid + "\" );'>&raquo; SZ&Aacute;ML&Aacute;L&Oacute; FRISS&Iacute;T&Eacute;SE</a>";
	$("#"+editorid).parent().find('.charsRemaining').html( lbl );				                
}

function calc_chars( editorid )
{
	var content = tinyMCE.get( editorid );
	var l = html_entity_decode( strip_tags( content.getContent() ) ).length;	
	//var l = content.getContent().length;
	
	return l;
}

function get_maxlength( editorid )
{
	return $("#"+editorid).attr('maxlength');
}
