JS_HELPOFF = false;
/* indentify the browser */
DOM = (document.getElementById) ? 1 : 0;
NS4 = (document.layers) ? 1 : 0;
IE4 = (document.all) ? 1 : 0;
OPERA = navigator.userAgent.indexOf("Opera") > -1 ? 1 : 0;

/* edit box stuff */
function insertTag(obj, stag, etag)
{
	if (navigator.userAgent.indexOf("MSIE") > -1 && !OPERA) {
		insertTagIE(obj, stag, etag);
	} else if (window.getSelection && navigator.userAgent.indexOf("Safari") == -1) {
		insertTagMoz(obj, stag, etag);
	} else {
		insertTagNS(obj, stag, etag);
	}
}

function insertTagNS(obj, stag, etag)
{
	obj.value = obj.value+stag+etag;
}

function insertTagMoz(obj, stag, etag)
{
	txt = window.getSelection();

	if (!txt || txt == '') {
		t = document.getElementById('txtb');
		h = document.getElementsByTagName('textarea')[0];
		if (t.selectionStart == t.selectionEnd) {
			t.value = t.value.substring(0, t.selectionStart) + stag + etag +  t.value.substring(t.selectionEnd, t.value.length);
			return;
		}
		txt = t.value.substring(t.selectionStart, t.selectionEnd);
		if (txt) {
			t.value = t.value.substring(0, t.selectionStart) + stag + txt + etag +  t.value.substring(t.selectionEnd, t.value.length);
			return;
		}
	}
	obj.value = obj.value+stag+etag;
}

function insertTagIE(obj, stag, etag)
{
	r=document.selection.createRange();
	if( document.selection.type == 'Text' && (obj.value.indexOf(r.text) != -1) ) {
		a = r.text;
		r.text = stag+r.text+etag;
		if ( obj.value.indexOf(document.selection.createRange().text) == -1 ) {
			document.selection.createRange().text = a;
		}
	}
	else insertAtCaret(obj, stag+etag);
}

function dialogTag(obj, qst, def, stag, etag)
{
	var q;
	q = prompt(qst, def);
	if ( !q ) return;
	stag = stag.replace(/%s/i, q);
	insertTag(obj, stag, etag);
}

function url_insert()
{
	if ( check_selection() )
	dialogTag(document.post_form.msg_body, 'Location:', 'http://', '[url=%s]', '[/url]');
	else
	dialogTag(document.post_form.msg_body, 'Location:', 'http://', '[url]%s[/url]', '');
}

function check_selection()
{
	var rn;
	var sel;

	if ( document.layers ) return 0;
	if ( navigator.userAgent.indexOf("MSIE") < 0 ) return 0;

	r = document.selection.createRange();

	if ( r.text.length && (document.post_form.msg_body.value.indexOf(r.text) != -1) ) {
		a = document.selection.createRange().text;
		rn = Math.random();
		r.text = r.text + ' ' + rn;

		if ( document.post_form.msg_body.value.indexOf(rn) != -1 ) {
			sel = 1;
		} else {
			sel = 0;
		}

		document.selection.createRange().text = a;
	}

	return sel;
}

function storeCaret(textEl)
{
	if (textEl.createTextRange) textEl.caretPos = document.selection.createRange().duplicate();
}

function insertAtCaret(textEl, text)
{
	if (textEl.createTextRange && textEl.caretPos)
	{
		var caretPos = textEl.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
	}
	else
	textEl.value  =  textEl.value + text;
}

function email_insert()
{
	if ( check_selection() ) {
		dialogTag(document.post_form.msg_body, 'Email:', '', '[url=mailto:%s]', '[/url]');
	}
	else
	dialogTag(document.post_form.msg_body, 'Email:', '', '[email]%s[/email]', '');
}

function image_insert()
{
	dialogTag(document.post_form.msg_body, 'Image URL:', 'http://', '[img]%s[/img]', '');
}
function imgleft_insert()
{
	dialogTag(document.post_form.msg_body, 'Image URL:', 'http://', '[img align=left]%s[/img]', '');
}
function imgright_insert()
{
	dialogTag(document.post_form.msg_body, 'Image URL:', 'http://', '[img align=right]%s[/img]', '');
}
function imgcenter_insert()
{
	dialogTag(document.post_form.msg_body, 'Image URL:', 'http://', '[img align=center]%s[/img]', '');
}

function insertParentTagIE(stag, etag)
{
	r=window.opener.document.selection.createRange();
	obj = window.opener.document.post_form.msg_body;

	if( window.opener.document.selection.type == 'Text' && (obj.value.indexOf(r.text) != -1) ) {
		a = r.text;
		r.text = stag+r.text+etag;
		if ( obj.value.indexOf(window.opener.document.selection.createRange().text) == -1 ) {
			window.opener.document.selection.createRange().text = a;
		}
	}
	else insertAtCaret(obj, stag+etag);
}

function insertParentTagNS(stag, etag)
{
	window.opener.document.post_form.msg_body.value = window.opener.document.post_form.msg_body.value + stag + etag;
}

function insertParentTag(stag, etag)
{
	if ( document.all )
	insertParentTagIE(stag, etag);
	else
	insertParentTagNS(stag, etag);

}

function window_open(url,winName,width,height)
{
	xpos = (screen.width-width)/2;
	ypos = (screen.height-height)/2;
	options = "scrollbars=1,width="+width+",height="+height+",left="+xpos+",top="+ypos+"position:absolute";
	window.open(url,winName,options);
}

function layerVis(layer,on)
{
	if (on) {
		if (DOM)
		document.getElementById(layer).style.visibility = "visible";
		else if (NS4)
		document.layers[layer].visibility = "show";
		else if (IE4)
		document.all[layer].style.visibility = "visible";
	} else {
		if (DOM)
		document.getElementById(layer).style.visibility = "hidden";
		else if (NS4)
		document.layers[layer].visibility = "hide";
		else if (IE4)
		document.all[layer].style.visibility = "hidden";
	}
}

function fud_msg_focus(mid_hash)
{
	if (!window.location.hash && !OPERA) {
		window.location.hash = mid_hash;
	}
}



if (navigator.platform == "Win32" && navigator.appName == "Microsoft Internet Explorer" && window.attachEvent) {
	rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, '');
	itsAllGood = (rslt != null && Number(rslt[1]) >= 5.5);

	if (itsAllGood) {
		document.writeln('<style type="text/css">img { visibility:hidden; } </style>');
		window.attachEvent("onload", fnLoadPngs);
	}
}

function fnLoadPngs() {
	for (var i = document.images.length - 1, img = null; (img = document.images[i]); i--) {
		if (img.src.match(/\.png$/i) != null) {
			var src = img.src;
			img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='image')"
			img.src = "blank.gif";
		}
		img.style.visibility = "visible";
	}
}

function addLoadEvent(func)
{
	var oldonload = window.onload;
	if (typeof window.onload != 'function')
	{
		window.onload = func;
	}
	else
	{
		window.onload = function()
		{
			oldonload();
			func();
		}
	}
}
function replaceChars(txt)
{
	txt = noHtml(txt);
	var out = new Array(" ","\r","\n","\r\n");
	var add = new Array("","","","");
	temp = "" + txt;
	for (var i=0;i<out.length;i++)
	{
		while (temp.indexOf(out[i])>-1)
		{
			pos= temp.indexOf(out[i]);
			temp = "" + (temp.substring(0, pos) + add[i] + temp.substring((pos + out[i].length), temp.length));
		}
	}
	return temp;
}
function noHtml(txt)
{
	a = txt.indexOf("<");
	b = txt.indexOf(">");
	len = txt.length;
	c = txt.substring(0, a);
	if(b == -1)
	{
		b = a;
	}
	d = txt.substring((b + 1), len);
	txt = c + d;
	cont = txt.indexOf("<");
	if (cont != -1)
	{
		txt = noHtml(txt);
	}
	return txt;
}
function downfile(s)
{
	window.location.href=s;
}
function sendReqXML(UrlHttpRequest, UrlPostData)
{
	http_request = false;
	if (window.XMLHttpRequest)
	{
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType)
		{
			http_request.overrideMimeType("text/xml");
		}
	}
	else if (window.ActiveXObject)
	{
		try
		{
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {}
		}
	}
	if (!http_request)
	{
		return false;
	}
	http_request.open("POST", UrlHttpRequest, false);
	http_request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	http_request.setRequestHeader("Content-length", UrlPostData.length);
	http_request.send(UrlPostData);
	//var XMLdata = http_request.responseXML;
	//falls kein Erfolgs-Tag vorhanden ist
	return false;
}