function emoticon(theSmilie)
{
	doInsert(" " + theSmilie + " ", "", false);
}

function stat(thevalue) {

  document.form.status.value = thevalue;

}

function codeformat(theform,code) {
  if (code == "img") {
    inserttext = prompt("Voer de URL in naar de afbeelding","http://");
  } else {
    inserttext = prompt("Voer de tekst voor de speciale opmaak in\n["+code+"] tekst [/"+code+"]","");
  }

  if ((inserttext != null) && (inserttext != "")) {
    doInsert("["+code+"]"+inserttext+"[/"+code+"]", "", false);
  }
}

function link(theform,type) {
  linktext = prompt("Voer de alternatieve tekst in (Optioneel)","");

  if (type == "url") {
    prompt_text = "Voer de URL van de Link in";
    prompt_contents = "http://";
  } else {
    prompt_text = "Voer het E-Mail Adres in";
    prompt_contents = "";
  }

  linkurl = prompt(prompt_text,prompt_contents);

  if ((linkurl != null) && (linkurl != "")) {
    if ((linktext != null) && (linktext != "")) {
      doInsert("["+type+"="+linkurl+"]"+linktext+"[/"+type+"] ", "", false);
    } else {
      doInsert("["+type+"]"+linkurl+"[/"+type+"] ", "", false);
    }
  }
}

function list(theform) {

  thelist = "[list]\n";
  listend = "[/list] ";

  listentry = "initial";
  while ((listentry != "") && (listentry != null)) {

    listentry = prompt("Voer een Lijst Item in\nDruk op Cancel of vul niets in om de lijst te stoppen","");

    if ((listentry != "") && (listentry != null)) {
      thelist = thelist+"[*]"+listentry+"\n";
    }
  }
  doInsert(thelist+listend, "", false);
}

function addsmilie(smilietext) {
  doInsert(" " + smilietext + " ", "", false);
}

//--------------------------------------------
// GENERAL INSERT FUNCTION
//--------------------------------------------
// ibTag: opening tag
// ibClsTag: closing tag, used if we have selected text
// isSingle: true if we do not close the tag right now
// return value: true if the tag needs to be closed later

//
var myAgent   = navigator.userAgent.toLowerCase();
var myVersion = parseInt(navigator.appVersion);

var is_ie   = ((myAgent.indexOf("msie") != -1)  && (myAgent.indexOf("opera") == -1));
var is_nav  = ((myAgent.indexOf('mozilla')!=-1) && (myAgent.indexOf('spoofer')==-1)
                && (myAgent.indexOf('compatible') == -1) && (myAgent.indexOf('opera')==-1)
                && (myAgent.indexOf('webtv') ==-1)       && (myAgent.indexOf('hotjava')==-1));

var is_win   =  ((myAgent.indexOf("win")!=-1) || (myAgent.indexOf("16bit")!=-1));
var is_mac    = (myAgent.indexOf("mac")!=-1);

function doInsert(ibTag, ibClsTag, isSingle)
{
	var isClose = false;
	var obj_ta = document.form.bericht;

	if ( (myVersion >= 4) && is_ie && is_win) // Ensure it works for IE4up / Win only
	{
		if(obj_ta.isTextEdit){ // this doesn't work for NS, but it works for IE 4+ and compatible browsers
			obj_ta.focus();
			var sel = document.selection;
			var rng = sel.createRange();
			rng.colapse;
			if((sel.type == "Text" || sel.type == "None") && rng != null){
				if(ibClsTag != "" && rng.text.length > 0)
					ibTag += rng.text + ibClsTag;
				else if(isSingle)
					isClose = true;

				rng.text = ibTag;
			}
		}
		else{
			if(isSingle)
				isClose = true;

			obj_ta.value += ibTag;
		}
	}
	else
	{
		if(isSingle)
			isClose = true;

		obj_ta.value += ibTag;
	}

	obj_ta.focus();

	// clear multiple blanks
//	obj_ta.value = obj_ta.value.replace(/  /, " ");

	//return isClose;
}
