
var imageTag = false;
var theSelection = false;

// Check for Browser & Platform for PC & IE specific bits
var clientPC = navigator.userAgent.toLowerCase(); // Get client info
var clientVer = parseInt(navigator.appVersion); // Get browser version

var is_ie = ((clientPC.indexOf("msie") != -1) && (clientPC.indexOf("opera") == -1));
var is_nav  = ((clientPC.indexOf('mozilla')!=-1) && (clientPC.indexOf('spoofer')==-1)
                && (clientPC.indexOf('compatible') == -1) && (clientPC.indexOf('opera')==-1)
                && (clientPC.indexOf('webtv')==-1) && (clientPC.indexOf('hotjava')==-1));

var is_win   = ((clientPC.indexOf("win")!=-1) || (clientPC.indexOf("16bit") != -1));
var is_mac    = (clientPC.indexOf("mac")!=-1);


// Helpline messages
b_help = "Fetter Text: [b]text[/b]  (alt+b)";
i_help = "Kursiver Text: [i]text[/i]  (alt+i)";
u_help = "Unterstrichener Text: [u]text[/u]  (alt+u)";
q_help = "Text zitieren: [quote]text[/quote]  (alt+q)";
q2_help = "Text zitieren mit Namen: [quote=Name]text[/quote]";
p_help = "Bild eingügen: [img]http://image_url[/img]  (alt+p)";
img_help = "Bild eingügen: [img:width=400]http://image_url[/img]";
li_help = "Liste: [li]Text[/li]";
a_help = "Close all open bbCode tags";
url_help = "URL mit anderen Namen: [url=http://www.]Linkname[/url]";
url2_help = "URL mit anderen Namen: [url!=http://www.]Linkname[/url]";
more_1_help = "[+]Titel[:]Text[/]";
more_2_help = "[-]Titel[:]Text[/]";
hr_help = "Trennlinie: [hr]";
s_help = "Schriftfarbe: [color=red]Text[/color]  Tip: Du kannst ebenfalls color=#FF0000 benutzen";
f_help = "Schriftgröße: [size=x-small]Kleiner Text[/size]";
// Define the bbCode tags
bbcode = new Array();
bbtags = new Array('[b]','[/b]','[i]','[/i]','[u]','[/u]','[li]','[/li]','[quote]','[/quote]','[quote=]','[/quote]','[img]','[/img]','[url=','][/url]','[+][:]','[/]','[hr]','[hr]','[-][:]','[/]','[img:]','[/img]','[url!=]','[/url]');
imageTag = false;

// Shows the help messages in the helpline window
function helpline(help) {
	document.post.helpbox.value = eval(help + "_help");
}


// Replacement for arrayname.length property
function getarraysize(thearray) {
	for (i = 0; i < thearray.length; i++) {
		if ((thearray[i] == "undefined") || (thearray[i] == "") || (thearray[i] == null))
			return i;
		}
	return thearray.length;
}

// Replacement for arrayname.push(value) not implemented in IE until version 5.5
// Appends element to the array
function arraypush(thearray,value) {
	thearray[ getarraysize(thearray) ] = value;
}

// Replacement for arrayname.pop() not implemented in IE until version 5.5
// Removes and returns the last element of an array
function arraypop(thearray) {
	thearraysize = getarraysize(thearray);
	retval = thearray[thearraysize - 1];
	delete thearray[thearraysize - 1];
	return retval;
}


function checkForm() {

	formErrors = false;

	if (document.post.text.value.length < 2) {
		formErrors = "You must enter a message when posting";
	}

	if (formErrors) {
		alert(formErrors);
		return false;
	} else {
		bbstyle(-1);
		//formObj.preview.disabled = true;
		//formObj.submit.disabled = true;
		return true;
	}
}

function emoticon(text) {
	text = '' + text + '';
	if (document.post.text.createTextRange && document.post.text.caretPos) {
		var caretPos = document.post.text.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
		document.post.text.focus();
	} else {
	document.post.text.value  += text;
	document.post.text.focus();
	}
}

function bbfontstyle(bbopen, bbclose) {
	if ((clientVer >= 4) && is_ie && is_win) {
		theSelection = document.selection.createRange().text;
		if (!theSelection) {
			document.post.text.value += bbopen + bbclose;
			document.post.text.focus();
			return;
		}
		document.selection.createRange().text = bbopen + theSelection + bbclose;
		document.post.text.focus();
		return;
	} else {
		document.post.text.value += bbopen + bbclose;
		document.post.text.focus();
		return;
	}
	storeCaret(document.post.text);
}


function bbstyle(bbnumber) {

	donotinsert = false;
	theSelection = false;
	bblast = 0;

	if (bbnumber == -1) { // Close all open tags & default button names
		while (bbcode[0]) {
			butnumber = arraypop(bbcode) - 1;
			document.post.text.value += bbtags[butnumber + 1];
			buttext = eval('document.post.addbbcode' + butnumber + '.value');
			eval('document.post.addbbcode' + butnumber + '.value ="' + buttext.substr(0,(buttext.length - 1)) + '"');
		}
		imageTag = false; // All tags are closed including image tags :D
		document.post.text.focus();
		return;
	}

	if ((clientVer >= 4) && is_ie && is_win)
		theSelection = document.selection.createRange().text; // Get text selection

	if (theSelection) {
		// Add tags around selection
		document.selection.createRange().text = bbtags[bbnumber] + theSelection + bbtags[bbnumber+1];
		document.post.text.focus();
		theSelection = '';
		return;
	}

	// Find last occurance of an open tag the same as the one just clicked
	for (i = 0; i < bbcode.length; i++) {
		if (bbcode[i] == bbnumber+1) {
			bblast = i;
			donotinsert = true;
		}
	}

	if (donotinsert) {		// Close all open tags up to the one just clicked & default button names
		while (bbcode[bblast]) {
				butnumber = arraypop(bbcode) - 1;
				document.post.text.value += bbtags[butnumber + 1];
				buttext = eval('document.post.addbbcode' + butnumber + '.value');
				eval('document.post.addbbcode' + butnumber + '.value ="' + buttext.substr(0,(buttext.length - 1)) + '"');
				imageTag = false;
			}
			document.post.text.focus();
			return;
	} else { // Open tags

		if (imageTag && (bbnumber != 14)) {		// Close image tag before adding another
			document.post.text.value += bbtags[15];
			lastValue = arraypop(bbcode) - 1;	// Remove the close image tag from the list
			document.post.addbbcode14.value = "Img";	// Return button back to normal state
			imageTag = false;
		}

		// Open tag
		document.post.text.value += bbtags[bbnumber];
		if ((bbnumber == 14) && (imageTag == false)) imageTag = 1; // Check to stop additional tags after an unclosed image tag
		arraypush(bbcode,bbnumber+1);
		eval('document.post.addbbcode'+bbnumber+'.value += "*"');
		document.post.text.focus();
		return;
	}
	storeCaret(document.post.text);
}

// Insert at Claret position. Code from
// http://www.faqts.com/knowledge_base/view.phtml/aid/1052/fid/130
function storeCaret(textEl) {
	if (textEl.createTextRange) textEl.caretPos = document.selection.createRange().duplicate();
}


function imgaug(path, imgwidth, imgheight) {
	imgwindow =	window.open( "", 0 , "height=" + imgheight + ",width=" + imgwidth + ",scrollbars=no,hotkeys=yes,locationbar=no,menubar=no,resizable=no,status=no,scrolling=no,innerwidth=" + imgwidth + ",innerheight=" + imgheight + ",marginwidth=0,marginheight=0" );
	imgwindow.document.write( "<html><head><title>" + path + "</title></head>");
	imgwindow.document.write( "<body marginwidth=0 marginheight=0 bgcolor='#ffffff' style='margin:0px'>" );
	imgwindow.document.write( "<a href='javascript:window.close();'><img src='images/" + path + "' width='" + imgwidth + "' height='" + imgheight + "' alt='Fenster schlie&szlig;en' border='0'></a>" );
	imgwindow.document.write( "</body></html>" );
}

function fame(path, imgwidth, imgheight) {
	imgwindow =	window.open( "", 0 , "height=" + imgheight + ",width=" + imgwidth + ",scrollbars=no,hotkeys=yes,locationbar=no,menubar=no,resizable=no,status=no,scrolling=no,innerwidth=" + imgwidth + ",innerheight=" + imgheight + ",marginwidth=0,marginheight=0" );
	imgwindow.document.write( "<html><head><title>Hall of Fame</title></head>");
	imgwindow.document.write( "<body marginwidth=0 marginheight=0 bgcolor='#ffffff' style='margin:0px'>" );
	imgwindow.document.write( "<a href='javascript:window.close();'><img src='images/" + path + "' width='" + imgwidth + "' height='" + imgheight + "' alt='Fenster schlie&szlig;en' border='0'></a>" );
	imgwindow.document.write( "</body></html>" );
}

function update_drp2() {
    var x=document.frm_auswahl.drp2.length;
    for(var n=0; n<x; n++)
        document.frm_auswahl.drp2.options[0]=null;
    for(n=0; n<liste2.length; n++) {
        if(liste2[n][2]==document.frm_auswahl.drp1.value) {
            var NeuerEintrag=new Option(liste2[n][1], liste2[n][0]);
            document.frm_auswhal.drp2.options[document.frm_auswahl.drp2.length]=NeuerEintrag;
        }
    }
}

function setCheckboxes(the_form)
{
    var elts      = document.forms[the_form].elements['ID[]'];
    var elts_cnt  = (typeof(elts.length) != 'undefined')
                  ? elts.length
                  : 0;

    if (elts_cnt) {
        for (var i = 0; i < elts_cnt; i++) {
            elts[i].checked = !elts[i].checked;
        }
    } else {
        elts.checked        = !elts.checked;
    }

    return true;
}

function fill()
{
    var rObj = document.add.anrede;
    for (var i=0; i<rObj.length; i++) if (rObj[i].checked) var val = rObj[i].value;
    if (val == 'herr') { var anrede = 'An Herrn'}
    if (val == 'frau') {var anrede = 'An Frau'}
    if (val == 'firma') {var anrede = 'An'}
    document.add.text.value = document.add.text.value = anrede + '\n' + document.add.vorname.value + ' ' + document.add.nachname.value + '\n' 	+ document.add.strasse.value + '\n' + document.add.plzort.value;
}
//-->

