function preview(title_field, html_field, html_mode) {
	var headline = encodeURIComponent(document.getElementById(title_field).value);
	var html = encodeURIComponent(document.getElementById(html_field).value);
	if(!html_mode) {
		html = nl2br(html);
	}
	window.open("/preview.php?headline=" + headline + "&html=" + html, "","width=760,height=300,scrollbars=yes,resizable=no");
}

function trim(str) {
	return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
}

function nl2br(text){
	var re_nlchar = "";
	if(text.indexOf('%0D%0A') > -1) {
		re_nlchar = /%0D%0A/g;
	} else if(text.indexOf('%0A') > -1) {
		re_nlchar = /%0A/g;
	} else if(text.indexOf('%0D') > -1) {
		re_nlchar = /%0D/g;
	} else {
		return text;
	}
	return text.replace(re_nlchar,'<br>');
}

function WriteMailAddress(name, domain) {
	var mail = (name + '@' + domain);
	document.write('<a href="mailto:' + mail + '">' + mail + '</a>')
}

function externalLinks() { 
 if (!document.getElementsByTagName) return; 
 var anchors = document.getElementsByTagName("a"); 
 for (var i=0; i<anchors.length; i++) { 
   var anchor = anchors[i]; 
   if (anchor.getAttribute("href") && 
       anchor.getAttribute("rel") == "external") 
     anchor.target = "_blank"; 
 } 
}

function urlencode( s )
{
   return encodeURIComponent( s ).replace( /\%20/g, '+' ).replace( /!/g, '%21' ).replace( /'/g, '%27' ).replace( /\(/g, '%28' ).replace( /\)/g, '%29' ).replace( /\*/g, '%2A' ).replace( /\~/g, '%7E' );
}

function urldecode( s )
{
   return decodeURIComponent( s.replace( /\+/g, '%20' ).replace( /\%21/g, '!' ).replace( /\%27/g, "'" ).replace( /\%28/g, '(' ).replace( /\%29/g, ')' ).replace( /\%2A/g, '*' ).replace( /\%7E/g, '~' ) );
}

function encode_utf8( s )
{
  return unescape( encodeURIComponent( s ) );
}

function decode_utf8( s )
{
  return decodeURIComponent( escape( s ) );
}

function start() {  
	externalLinks();
}

window.onload = start;




