function ubb(first) {
    var second= (ubb.arguments[1]) ? ubb.arguments[1] : '';
    var fieldname = (ubb.arguments[2]) ? ubb.arguments[2] : 'bericht';
    var formname = (ubb.arguments[3]) ? ubb.arguments[3] : 'form';

    if (document.selection) { //IE
        if (document.selection.createRange().text && document.selection.createRange().parentElement().id == fieldname) { // selection in field
            var SelectedString = document.selection.createRange().text;
            var ReplaceString = first+SelectedString+second;
            document.selection.createRange().text = ReplaceString;
        }else {
            document.forms[formname].elements[fieldname].setActive();
            document.selection.createRange().duplicate().text = first+' '+second;
        }
    }else {
        document.forms[formname].elements[fieldname].value += first+' '+second;
    }
}   
  
function openwin(url, width, height) {
	
	var maxWidth = screen.width - (screen.width - screen.availWidth) * 2;
	var maxHeight = screen.height - (screen.height - screen.availHeight) * 2;
	var minWidth = 300;

	
	if (width > maxWidth) {
		width = maxWidth;
	}
	if (height > maxHeight) {
		height = maxHeight;
	}
	
	if (width < minWidth) {
		width = minWidth;
	}

	var left = (screen.width - width) / 2;
	var top = (screen.height - height) / 2;
	
	if (openwin.arguments[3] == 1) {
			window.resizeTo(width, height);
			window.moveTo(left, top);	
			window.location= url;		
	}else{
	  window.open(url,"_blank","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,copyhistory=0,left=" + left + ",top=" + top + ",height=" + height + ",width=" + width);	
	}
	
}
