var openMenu = 0;
var startMenu = 0;
var menuTimer;

function ge(i) { return document.getElementById(i); }

function openSubMenu(i){
	clearTimeout(menuTimer);
	if(openMenu!=0 && i!=openMenu && ge('submenu_'+openMenu)) ge('submenu_'+openMenu).style.visibility = "hidden";
	if(i!=startMenu && startMenu>0 && ge('submenu_'+startMenu)) ge('submenu_'+startMenu).style.visibility = "hidden";
	if(ge('submenu_'+i)) ge('submenu_'+i).style.visibility = "visible";
	openMenu = i;
}

function houdOpen(){
	clearTimeout(menuTimer);
}

function startSluitSubMenu() {
	menuTimer = setTimeout("sluitSubMenu()",500);
}

function sluitSubMenu(){
	if(openMenu!=0 && ge('submenu_'+openMenu)) ge('submenu_'+openMenu).style.visibility = "hidden";
	if(startMenu>0 && ge('submenu_'+startMenu)) ge('submenu_'+startMenu).style.visibility = "visible";
	openMenu = 0;
}

function zetStart(i){
	startMenu = i;
	openSubMenu(i);
	haalH2();
	//alert(winH);
	if(winH > 688 && ge('onder')) { winH = winH+142; ge('onder').style.top = winH+"px"; 	}
}

var winH;
function haalH2(){
	if(ge('content')){
		if(ge('content').offsetHeight) winH = ge('content').offsetHeight;
		else if (ge('content').innerHeight) winH = ge('content').innerHeight;
	}
}

//geleend....
//--------------------------------------------
// 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.getElementById('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;
}

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