function checkAll(theElement) {
	var theForm = theElement.form, z = 0;
	while (theForm[z].type == 'checkbox' && theForm[z].name != 'checkall') {
		theForm[z].checked = true;
		z++;
	}
}
function uncheckAll(theElement) {
	var theForm = theElement.form, z = 0;
	while (theForm[z].type == 'checkbox' && theForm[z].name != 'checkall') {
		theForm[z].checked = false;
		z++;
	}
}

var prompttext = new Array();
prompttext['img'] = 'Insert image url';
prompttext['b'] = 'Insert text to make bold';
prompttext['i'] = 'Insert text to make italic';
prompttext['s'] = 'Insert text to put a stroke through';
prompttext['u'] = 'Insert text to underline';
prompttext['url'] = 'Insert url';
prompttext['mail'] = 'Insert e-mail address';

var target = null;
function getTarget(el) {

  target = (document.getElementById)? document.getElementById(el):0;

}

function storeCursor(el) {

  if (document.all && el.createTextRange) el.cursorPos = document.selection.createRange().duplicate();

}

function putStr(text) {

  if (target) {

    if (document.all && target.cursorPos) {

      target.cursorPos.text = text;

    } else if (typeof(target.selectionStart) != 'undefined') {

      var sStart = target.selectionStart;
      var sEnd = target.selectionEnd;
      target.value = target.value.substr(0, sStart) + text + target.value.substr(sEnd, target.value.length);
      target.selectionStart = (sStart == sEnd)? sStart + text.length:sStart;
      target.selectionEnd = sStart + text.length;

    } else {

      target.value += text;

    }

    target.focus();
    storeCursor(target);

  }
}

function applyUBB(style) {

  if (target) {

    var selectedtext = '';
    if (document.all && target.cursorPos) {
      selectedtext = target.cursorPos.text;
    } else if (typeof(target.selectionStart) != 'undefined') {
      selectedtext = target.value.substr(target.selectionStart, target.selectionEnd - target.selectionStart);
    }

    if (!selectedtext) selectedtext = prompt(prompttext[style], '');
    if (!selectedtext) { target.focus(); return; }

    if (style == 'url=') {
      var description = prompt(prompttext['urld'], '');
      if (!description) { target.focus(); return; }
      selectedtext = '[url='+selectedtext+']'+description+'[/url]';
    } else {
      selectedtext = '['+style+']'+selectedtext+'[/'+style+']';
    }

    putStr(selectedtext);

  } 
}

b_help = "Bold text: [b]text[/b]  (alt+b)";
i_help = "Italic text: [i]text[/i]  (alt+i)";
u_help = "Underlined text: [u]text[/u]  (alt+u)";
s_help = "Stroked through text: [s]text[/s]  (alt+s)";
w_help = "URL: [url]http://www.yoursite.com[/url] (alt+w)";
m_help = "Mail: [mail]info@yoursite.com[/mail] (alt+m)";
a_help = "Image: [img]http://www.yoursite.com/image.jpg[/img]  (alt+a)";

function helpline(help) {
	document.post.helpbox.value = eval(help + "_help");
}
function emoticon(text) {
	text = ' ' + text + ' ';
	if (document.post.gbMessage.createTextRange && document.post.gbMessage.caretPos) {
		var caretPos = document.post.gbMessage.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
		document.post.gbMessage.focus();
	} else {
	document.post.gbMessage.value  += text;
	document.post.gbMessage.focus();
	}
}
