var EP_translated_textareas = {};
function EP_ttexta_wrap(idn,stt,ent) {
	EP_translated_textareas[idn].wrapSelection(stt,ent);
}
function EP_ttexta_rep(idn,tex) {
	EP_translated_textareas[idn].replaceSelection(tex);
}
function EP_ttexta_link(idn,lty) {
	var linka = prompt((lty=='link')?'Hivatkozás URL-je (webcíme)':'Kép URL-je (webcíme)');
	if ( linka === null ) return(true);
	if ( linka === false ) return(true);
	if ( linka.strip() == '' ) return(true);
	if ( linka.match(/^https?:\/\//) == null ) linka = 'http://'+linka;
	if ( lty == 'link' ) {
		if ( linka.match(/^http:\/\/w*[.]eropolis[.]hu\//) ) {
			linka = linka.replace(/^http:\/\/w*[.]*eropolis[.]hu/,'');
			linka = 'EROPOLIS:'+linka;
		} else {
			linka = '!link:'+linka;
		}
	 } else {
		linka = '!kep:'+linka;
	 }
	 EP_ttexta_rep(idn,' '+linka+' ');
}

function EP_divtrans_sub(tx,transtype) {
	if ( tx.indexOf('\n') == -1 ) {
		tx = tx.replace(/\r/g,'\n');
	}
	tx = tx.replace(/</g,'&lt;');
	tx = tx.replace(/>/g,'&gt;');
	tx = tx.replace(/&/g,'&amp;');
	var smileys = [ [':-*[)]+', 'smiley.gif', ':-)'], [':-*[(]+', 'sad.gif', ':-('], [':-*[*]', 'kiss.gif', ':-*'],
		[':-*D+', 'grin.gif', ':-D'], [':-*[Oo]', 'shocked.gif', ':-O'], [':-*[pP]', 'tongue.gif', ':-P'],
		[';-*[)]+', 'wink.gif', ';-)'], [':-*/', 'undecided.gif', ':-/'] ];
	var i;
	var r;
	var rep;
	for(i=0;i<smileys.length;i++) {
		rep = '<img src="http://images.eropolis.hu/imgs/smile/'+smileys[i][1]+'" width="15" height="15" alt="'+smileys[i][2]+'">';
		/*
		r = new RegExp('^'+smileys[i][0]+'(\\s)','g');
		tx = tx.replace(r,rep+'$1');
		r = new RegExp('(\\s)'+smileys[i][0]+'(\\s)','g');
		tx = tx.replace(r,'$1'+rep+'$2');
		r = new RegExp('(\\s)'+smileys[i][0]+'$','g');
		tx = tx.replace(r,'$1'+rep);
		r = new RegExp('^'+smileys[i][0]+'$','g');
		tx = tx.replace(r,rep);
		*/
		r = new RegExp('^'+smileys[i][0],'g');
		tx = tx.replace(r,rep);
		r = new RegExp('(\\s)'+smileys[i][0],'g');
		tx = tx.replace(r,'$1'+rep);
		r = new RegExp(smileys[i][0]+'$','g');
		tx = tx.replace(r,rep);
	}
	if ( ( transtype == 'relaxed' ) || ( transtype == 'relaxed-nomail' ) ) {
		tx = tx.replace(/(\s)(https?[:]\S+)/g,'$1<a href="$2" target="_blank">$2</a>');
		tx = tx.replace(/(\s)[!]link[:](https?[:]\S+)/g,'$1<a href="$2" target="_blank">$2</a>');
		tx = tx.replace(/^(https?[:]\S+)/g,'<a href="$1" target="_blank">$1</a>');
		tx = tx.replace(/^[!]link[:](https?[:]\S+)/g,'<a href="$1" target="_blank">$1</a>');
		tx = tx.replace(/[!]kep[:](\S+)/g, '<a href="$1" target="_blank" rel="lightbox"><img src="$1" width="200" border="0" alt="kattints az eredeti m&eacute;retben val&oacute; megtekint&eacute;shez!"></a>');
		if ( transtype == 'relaxed' )
			tx = tx.replace(/([a-zA-Z0-9_%.!=:-]+@[a-zA-Z0-9-]+[.][a-zA-Z0-9.-]+)/g,'<a href="mailto:$1">$1</a>');
		else
			tx = tx.replace(/[a-zA-Z0-9_%.!=:-]+@[a-zA-Z0-9-]+[.][a-zA-Z0-9.-]+/g,'<i>(t&ouml;r&ouml;lt email c&iacute;m)</i>');
	}
	else {
		tx = tx.replace(/(\s)(https?[:]\S+)/g,'$1<i>(t&ouml;r&ouml;lt link)</i>');
		tx = tx.replace(/(\s)[!]link[:](https?[:]\S+)/g,'$1<i>(t&ouml;r&ouml;lt link)</i>');
		tx = tx.replace(/^(https?[:]\S+)/g,'<i>(t&ouml;r&ouml;lt link)</i>');
		tx = tx.replace(/^[!]link[:](https?[:]\S+)/g,'<i>(t&ouml;r&ouml;lt link)</i>');
		tx = tx.replace(/[a-zA-Z0-9_%.!=:-]+@[a-zA-Z0-9-]+[.][a-zA-Z0-9.-]+/g,'<i>(t&ouml;r&ouml;lt email c&iacute;m)</i>');
		tx = tx.replace(/[!]kep[:](\S+)/g, '<i>(t&ouml;r&ouml;lt k&eacute;p)</i>');
	}
	tx = tx.replace(/EROPOLIS[:](\S+)/g, '<a href="http://www.eropolis.hu/$1" target="_blank">EROPOLIS:$1</a>');
	tx = tx.replace(/ettp:(\S+)/g, '<a href="http://www.eropolis.hu/$1" target="_blank">EROPOLIS:$1</a>');
	tx = tx.replace(/[*]([^*]+)[*]/g,'<b>$1</b>');
	tx = tx.replace(/\b_([^_]+)_\b/g,'<u>$1</u>');
	tx = tx.replace(/\n/g,'<br/>\n');
	return(tx);
}
function EP_divtrans_sizesub(mat) {
	x = mat.split('=',2);
	x[1] = x[1].replace(/[^0-9%]+/g,'');
	if ( x[1].substr(x[1].length-1,1) == '%' ) {
		x[1] = x[1].substr(0,x[1].length-1);
		if ( parseInt(x[1]) > 100 ) x[1] = '100';
		x[1] += '%';
	} else {
		if ( parseInt(x[1]) > 450 ) x[1] = '450';
	}
	mat = x[0]+'="'+x[1]+'"';
	return(mat);
}
function EP_divtrans() {
 $$('[eptrans]').each(function (el) {
 	var ine = el.down();
	var isrelax = el.getAttribute('eptrans');
	var te = ine.innerHTML;
	var t1,t2,tp,tn;
	if ( ( el.hasAttribute('eptransallowhtml') === true ) && ( el.getAttribute('eptransallowhtml') == 'yes' ) ) {
		t2 = '';
		while(te!='') {
			tn = '';
			tp = te.indexOf('[html]');
			if ( tp != -1 ) {
				t2 += EP_divtrans_sub(te.substr(0,tp),isrelax);
				te = te.substr(tp+6);
				tp = te.indexOf('[/html]');
				if ( tp == -1 ) {
					tn = te;
					te = '';
				} else {
					tn = te.substr(0,tp);
					te = te.substr(tp+7);
				}
				if ( tn != '' ) {
					tn = tn.replace(/width=['"]?[0-9%]+['"]?/gi,EP_divtrans_sizesub);
					t2 += tn;
				}
			} else {
				t2 += EP_divtrans_sub(te,isrelax);
				te = '';
			}
		}
		el.innerHTML = t2;
	} else {
		el.innerHTML = EP_divtrans_sub(te,isrelax);
	}
 });
 if ( ( EP_show_ads ) && ( EP_show_ads === true ) ) {
 	var i;
 	EPtranslatedBannerZones = [];
 	for(i=0;i<EP_ads_db.length;i++) {
 		EP_current_adslot = EP_ads_db[i];
 		$$('[EP_BANNER="'+EP_current_adslot[0].toString()+'"]').each(function (el) {
 			var nc = '<iframe id="'+EP_current_adslot[1]+'" name="'+EP_current_adslot[1]+'" src="http://bannerserver.hu/www/delivery/afr.php?refresh=300&zoneid='+EP_current_adslot[0]+'&target=_blank&source='+EP_ads_source+'&cb='+EP_ads_rand+'" framespacing="0" frameborder="no" scrolling="no" width="'+EP_current_adslot[2]+'" height="'+EP_current_adslot[3]+'" allowtransparency="true"><a href="http://bannerserver.hu/www/delivery/ck.php?n='+EP_current_adslot[4]+'&cb='+EP_ads_rand+'" target="_blank"><img src="http://bannerserver.hu/www/delivery/avw.php?zoneid='+EP_current_adslot[0]+'&cb='+EP_ads_rand+'&n='+EP_current_adslot[4]+'&source='+EP_ads_source+'" border="0" alt="" width="'+EP_current_adslot[2]+'" height="'+EP_current_adslot[3]+'" /></a></iframe>';
 			el.innerHTML = nc;
 			EPtranslatedBannerZones.push(EP_current_adslot[0].toString()+'::'+EP_current_adslot[1]);
 		});
 	}
 }
 $$('textarea[formatbar]').each(function(el) {
 	EP_translated_textareas[el.id] = new Control.TextArea(el);
 	if (el.getAttribute('formatbar')=='nolinks') var lt = '';
 	else var lt = '<input type="button" class="epEditorButton link" value="  " title="link (hivatkozás) beszúrása" onClick="EP_ttexta_link(\''+el.id+'\',\'link\');"/> '+
 			'<input type="button" class="epEditorButton image" value="  " title="külső kép (link/hivatkozás alapján) beszúrása" onClick="EP_ttexta_link(\''+el.id+'\',\'kep\');"/> ';
 	var te = '<div class="myBlogBax" style="margin-bottom:0px;text-align: center;"><input type="button" class="epEditorButton bold" value="  " title="kiválasztott szöveget félkövérre" onClick="EP_ttexta_wrap(\''+el.id+'\',\'*\',\'*\');"/> '+
		'<input type="button" class="epEditorButton underline" value="  " title="kiválasztott szöveget aláhúzottra" onClick="EP_ttexta_wrap(\''+el.id+'\',\'_\',\'_\');"/> '+lt+
		'<input type="button" class="epEditorButton happy" value="  " title=":) (vidám) smiley beszúrása" onClick="EP_ttexta_rep(\''+el.id+'\',\' :) \');"/> '+
		'<input type="button" class="epEditorButton sad" value="  " title=":( (szomorú) smiley beszúrása" onClick="EP_ttexta_rep(\''+el.id+'\',\' :( \');"/> '+
		'<input type="button" class="epEditorButton kiss" value="  " title=":* (csók) smiley beszúrása" onClick="EP_ttexta_rep(\''+el.id+'\',\' :* \');"/> '+
		'<input type="button" class="epEditorButton wink" value="  " title=";) (kacsint) smiley beszúrása" onClick="EP_ttexta_rep(\''+el.id+'\',\' ;) \');"/> '+
		'<input type="button" class="epEditorButton shocked" value="  " title=":o (meglepett) smiley beszúrása" onClick="EP_ttexta_rep(\''+el.id+'\',\' :o \');"/> '+
		'<input type="button" class="epEditorButton grin" value="  " title=":D (röhög) smiley beszúrása" onClick="EP_ttexta_rep(\''+el.id+'\',\' :D \');"/> '+
		'<input type="button" class="epEditorButton tongue" value="  " title=":P (nyelvet ölt) smiley beszúrása" onClick="EP_ttexta_rep(\''+el.id+'\',\' :P \');"/> '+
		'<input type="button" class="epEditorButton undecided" value="  " title=":/ (húzza a száját) smiley beszúrása" onClick="EP_ttexta_rep(\''+el.id+'\',\' :/ \');"/> ';
	el.insert({'before':te});
 });
 epLightBox.updateImageList();
}

