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 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);

  } 
}

function helpline(help) {
	document.getElementById('helpbox').innerHTML = eval(help + "_help");
}
function emoticon(text) {
	text = ' ' + text + ' ';
	if (document.forms[0].ces.createTextRange && document.forms[0].ces.caretPos) {
		var caretPos = document.forms[0].ces.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
		document.forms[0].ces.focus();
	} else {
	document.forms[0].ces.value  += text;
	document.forms[0].ces.focus();
	}
}

shortcut.add('Alt+B', function(){ applyUBB('b'); });
shortcut.add('Alt+S', function(){ applyUBB('s'); });
shortcut.add('Alt+I', function(){ applyUBB('i'); });
shortcut.add('Alt+U', function(){ applyUBB('u'); });
shortcut.add('Alt+W', function(){ applyUBB('url'); });
shortcut.add('Alt+A', function(){ applyUBB('img'); });

