  function insertTag(frmElm,startTag,endTag) {
      if (frmElm.selectionStart != undefined && frmElm.selectionEnd != undefined) {
            selectedtext = startTag+frmElm.value.substring(frmElm.selectionStart,frmElm.selectionEnd)+endTag;
            frmElm.value = frmElm.value.substring(0,frmElm.selectionStart)+selectedtext+frmElm.value.substr(frmElm.selectionEnd);
      }
      else if (document.selection) {frmElm.focus();r = document.selection.createRange();r.text = startTag+r.text+endTag;}
      else frmElm.value += startTag+endTag;
  }


function Mellerum(frmElm) {
  var str = document.selection.createRange().text;
  frmElm.focus();
  var sel = document.selection.createRange();
  sel.text = '&nbsp;';
  return;
}


function insertImg(frmElm,bid,lurl,linkimg) {
if(bid != undefined){
imgid = bid;
}else{
imgid = prompt('Skriv id\'et på billedet?');
}
if(lurl != undefined){
linkurl = lurl;
}else{
linkurl = prompt('Skriv navnet som skal visse som link?');
}
if(linkimg == "img"){
AddToText = '<img onmouseout="LinkChange(this.id,\'Out\')" onmouseover="LinkChange(this.id,\'Over\')" id="img'+imgid+'" class="Link" src="thumb.php?id='+imgid+'&tw=175&th=150" width="175" height="150" onclick="Billeder(\'thumb.php?id='+imgid+'\')">'
}else{
AddToText = '<span onmouseout="LinkChange(this.id,\'Out\')" onmouseover="LinkChange(this.id,\'Over\')" id="img'+imgid+'" class="Link" onclick="Billeder(\'thumb.php?id='+imgid+'\')">'+linkurl+'</span>';
}
if(linkurl != undefined && imgid != undefined){

if (frmElm.selectionStart != undefined && frmElm.selectionEnd != undefined) {
            selectedtext = AddToText;
            frmElm.value = frmElm.value.substring(0,frmElm.selectionStart)+selectedtext+frmElm.value.substr(frmElm.selectionEnd);
      }
      else frmElm.value += AddToText;

}else{
	return false;
}

}

function rute_popup(url,name,win_width,win_height) {
	pos_horizon = ((screen.width/2)-(win_width/2));
	pos_vertical = ((screen.height/2)-(win_height/2));
	window.open(url,name,"width="+win_width+",height="+win_height+",top="+pos_vertical+",left="+pos_horizon+",scrollbars=yes");
}
	
function Billeder(file){
win_width = (screen.width/2)
win_height = (screen.height/2)

pos_horizon = ((screen.width/2)-(win_width/2));
pos_vertical = ((screen.height/2)-(win_height/2));
      newWin=window.open("","ResizeBillede","width="+win_width+",height="+win_height+",top="+pos_vertical+",left="+pos_horizon+",status=no");
      txt='<ht'+'ml><he'+'ad><ti'+'tle>Galleri<\57ti'+'tle><scri';
      txt+='pt language="javascript" type="text/javascript">';
      txt+='function resPic(){h=document.images[0].scrollHeight;';
      txt+='w=document.images[0].scrollWidth;window.resizeTo(w+6,h+32);}<\57scri';
      txt+='pt><\57he'+'ad><bo'+'dy style="overflow:hidden;';
      txt+='border:0px;margin:0px"><i'+'mg src="'+file+'" style="top:0px;left:0px;border:0px;';
      txt+='" onload="resPic();"><\57bo'+'dy><\57ht'+'ml>';
      newWin.document.write(txt);
      newWin.document.close();
}

function LinkChange(p,mode){
    if(mode=="Over"){
		FF = 'verdana'
		FS = '11px'
		CC = '#FFFFFF'
		CS = 'pointer' 
		TD = 'underline'
        }
    else if(mode=="Out"){
		FF = 'verdana'
		FS = '11px'
		CC = '#FFFFFF'
		CS = 'default'
		TD = 'none'
        }
	document.getElementById(p).style.fontSize=FS;
	document.getElementById(p).style.color=CC;
	document.getElementById(p).style.cursor=CS;
	document.getElementById(p).style.fontFamily=FF;
	document.getElementById(p).style.textDecoration=TD;
    }
	

///--------------------------------------------------------------//

function namedlink(theform,thetype) {

	linkurl = prompt(prompt_text,prompt_contents);
	if ((linkurl != null) && (linkurl != "")) {
		if ((linktext != null) && (linktext != "")) {
			AddTxt = "["+thetype+"="+linkurl+"]"+linktext+"[/"+thetype+"] ";
			AddText(AddTxt,theform);
		} else {
			AddTxt = "["+thetype+"]"+linkurl+"[/"+thetype+"] ";
			AddText(AddTxt,theform);
		}
	}
}
function AddText(NewCode,theform) {
	if (theform.mailtext.createTextRange && theform.mailtext.caretPos) {
		var caretPos = theform.mailtext.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? NewCode + ' ' : NewCode;
	} else {
		theform.mailtext.value+=NewCode
	}
	theform.mailtext.focus();
	AddTxt = "";
}