	
var prompttext = new Array();
prompttext['img'] = 'Please input url to image';
prompttext['b'] = 'Please input text to be in bold';
prompttext['i'] = 'Please input text to be in italic';
prompttext['s'] = 'Please input text to be striked';
prompttext['u'] = 'Please input text to be underlined';
prompttext['li'] = 'Please input list item';
prompttext['url'] = 'Please input url';
prompttext['url='] = 'Please input url';
prompttext['urld'] = 'Please input url description';
prompttext['mail'] = 'Please input email 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 && typeof(target.cursorPos) != 'undefined') {

      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);
      var nStart = (sStart == sEnd)? sStart + text.length:sStart;
      var nEnd = sStart + text.length;
      target.setSelectionRange(nStart, nEnd);

    } else {

      target.value += text;

    }

    target.focus();
    storeCursor(target);

  }

}

function applyUBB(style) {

  if (target) {

    var selectedtext = '';
    window.focus();
    if (document.all && typeof(target.cursorPos) != 'undefined') {
      selectedtext = target.cursorPos.text;
    } else if (typeof(target.selectionStart) != 'undefined') {
      selectedtext = target.value.substr(target.selectionStart, target.selectionEnd - target.selectionStart);
    }
	    
    if (style == 'url') {
      selectedtext = '<A href="http://'+selectedtext+'" target="_blank">'+selectedtext+'</A>';
    } else if (style == 'mail') {
      selectedtext = '<A href="mailto:'+selectedtext+'">'+selectedtext+'</A>';
    } else if (style == 'center') {
      selectedtext = '<DIV align="center">'+selectedtext+'</DIV>';
    } else if (style == 'rechts') {
      selectedtext = '<DIV align="right">'+selectedtext+'</DIV>';
    } else if (style == 'wtbl') {
      selectedtext = '<TABLE align="center" width="80%"><TR><TD class="tbl_blok">'+selectedtext+'</TD></TR></TABLE>';
    } else if (style == 'blk') {
      selectedtext = '<BLOCKQUOTE>'+selectedtext+'</BLOCKQUOTE>';
    } else if (style == 'quotes') {
      selectedtext = '“'+selectedtext+'”';
    } else if (style == 'br') {
      selectedtext = '<BR/>';
    } else if (style == 'hr') {
      selectedtext = '<HR/>';
    } else {
      selectedtext = '<'+style+'>'+selectedtext+'</'+style+'>';
    }

    putStr(selectedtext);

  }

}

var popups = new Array();
function openwin(URL, winName, height, width) {

  if (!popups[winName] || popups[winName].closed) {

    var top = (screen.height - height) / 2;
    var left = (screen.width - width) / 2;
    popups[winName] = window.open(URL, winName, 'top='+top+',left='+left+',height='+height+',width='+width+',toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,directories=no,status=no');

  }

  popups[winName].focus();

}

function sizewin() {

  var curHeight = document.body.scrollHeight + 30;
  var curWidth = window.innerWidth || document.body.offsetWidth;
  if (curHeight < 400) window.resizeTo(curWidth+8, curHeight);

}

function closePopups() {

  for (var winName in popups) {

    if (popups[winName] && !popups[winName].closed) popups[winName].close();

  }

}
