function showHelp(page){
	openit(page, 645, 520);
}

var focuscount = 0;
function setFocus(objid){
	var obj = document.getElementById(objid);

	if(!obj && focuscount < 5){
		focuscount++;
		setTimeout("setFocus('" + objid + "');", 500);
	}else if(focuscount < 5){
		obj.focus();
		focuscount = 0;		
	}else{
		focuscount = 0;
	}
}

var ceedit = "";
function insertBIEMLink(ceeditor){
	ceedit = ceeditor;
	openit("PageAddSiteLink.aspx", 645, 520);
}

var secundarycolor = "#006699";

//simplified version of 'makegridscroll' which just makes a div go scroll of the table goes above a certain size
var didsimplescroll = 0;
function simpleScroll(gridid, gridheight){
	var gridobj = document.getElementById(gridid);
	if(typeof(gridobj) == "undefined" || gridobj == null || !gridobj){
		if(didsimplescroll < 20){
			didsimplescroll++;
			setTimeout("simpleScroll('"+gridid+"',"+gridheight+");", 500);
		}
		return;
	}

	var divobj = document.createElement("div");
	gridobj.parentNode.insertBefore(divobj, gridobj);	
	divobj.id = gridid + "scroll";
	divobj.appendChild(gridobj);
	
	divobj.style.height = "1px";
	divobj.style.overflow = "auto";
	gridobj.style.display = "block";

	if(gridobj.offsetHeight > gridheight){	
		divobj.style.width = gridobj.offsetWidth + 18;
		
		if(gridobj.style.marginLeft){
			divobj.style.width = parseInt(divobj.style.width) + parseInt(gridobj.style.marginLeft);
		}
		
		if(gridobj.style.marginRight){
			divobj.style.width = parseInt(divobj.style.width) + parseInt(gridobj.style.marginRight);
		}
		
		divobj.style.height = gridheight;
		divobj.style.overflow = "auto";
	}else{
		divobj.style.overflow = "visible";
		divobj.style.height = gridobj.offsetHeight;
	}
}

//convert a table to a scrollable table
var didmakegridscroll = 0;
function makegridscroll(gridid, gridheight){
	var obj = document.getElementById(gridid);

	//no grid object found with the given id
	if(obj == null || !obj){
		if(didmakegridscroll < 20){
			didmakegridscroll++;
			setTimeout("makegridscroll('"+gridid+"',"+gridheight+");", 500);
		}

		return;
	}

	//make the grid object visible
	obj.style.display = "block";
	
	//clone the given table, incl. all childNodes (true parameter)
	var theader = obj.cloneNode(true);
	theader.id = obj.id + "_theader";

	//sync the spacings etc. between both tables
	theader.cellSpacing = 0;
	theader.cellPadding = 0;
	obj.cellSpacing = 0;
	obj.cellPadding = 0;

	//set the border of the cloned table (header)
	theader.style.borderBottom = "solid 1px #FFFFFF";

	//set the top and bottom border of original table off, because the header table and the div will take over
	obj.style.borderTop = "0px";
	obj.style.borderBottom = "0px";

	//delete all rows from the header table (clone of original table), except the first row (so the header!)
	while(theader.childNodes[0].childNodes.length > 1){
		theader.deleteRow(1);
	}

	//insert the header table above the original table
	obj.parentNode.insertBefore(theader, obj);

	//set all cells in the original table to break-all, so that cells don't get screwed-up when continuous strings are entered
	var objrows = obj.childNodes[0].childNodes;
	for(var i=0; i < objrows.length; i++){
		var objcells = objrows[i].childNodes;
		for(var j=0; j < objcells.length; j++){
			objcells[j].style.wordBreak = "normal";
			objcells[j].style.wordWrap = "break-word";
		}
	}

	//set the width of the header cells the same as the actual(!) width of the header cells of the original table
	var thtrs = theader.childNodes[0].childNodes;
	var thtds = thtrs[0].childNodes;
	var objtds = obj.childNodes[0].childNodes[0].childNodes;
	for(var i=0; i < thtds.length; i++){
		thtds[i].style.width = objtds[i].offsetWidth + 2;
		thtds[i].className = "tblhead";
		thtds[i].style.borderRight = "solid 1px #FFFFFF";
		thtds[i].style.paddingLeft = "2px";
	}

	//delete the header of the original table, because we copied the width above
	obj.deleteRow(0);

	//set the width of all cells in the original table the same as the actual width of the header cells of the header table (so the clone of the original table)
	var objtrs = obj.childNodes[0].childNodes;
	var thtds = theader.childNodes[0].childNodes[0].childNodes;
	for(var i=0; i < objtrs.length; i++){
		var objtds = objtrs[i].childNodes;

		for(var j=0; j < objtds.length; j++){
			try{
				objtds[j].style.width = parseInt(thtds[j].style.width) + 2;
			}catch(e){}
		}
	}
	
	var divobj = document.createElement("div");
	obj.parentNode.insertBefore(divobj, obj);	

	//if a scrollbar is needed (so the height of the grid is more than the gridheight variable (when start scrolling..)
	if(obj.offsetHeight > gridheight){
		//create a div object which encapsulates the original table, and is a fixed height and scrollable
		divobj.id = gridid + "scroll";
		divobj.appendChild(obj);
		divobj.style.height = gridheight;
		divobj.style.width = obj.offsetWidth + 18;
		
		if(obj.style.marginLeft){
			divobj.style.width = parseInt(divobj.style.width) + parseInt(obj.style.marginLeft);
		}
		
		if(obj.style.marginRight){
			divobj.style.width = parseInt(divobj.style.width) + parseInt(obj.style.marginRight);
		}	
		
		divobj.style.overflow = "auto";
		divobj.style.borderBottom = "solid 1px " + secundarycolor;
	}else{
		//don't scroll, and set the border of the original table and the header table to secundary color
		theader.style.borderBottom = "solid 1px " + secundarycolor;
		obj.style.borderBottom = "solid 1px " + secundarycolor;
	}
}

function showObject(obj){
	obj.style.display = "inline";
}

function hideObject(obj){
	obj.style.display = "none";
}

function getXmlObject(){
	var obj=null;

	if (window.ActiveXObject) {
		var bDocument = false;

		var aszDocumentProgIDs = [ "MSXML2.DOMDocument.4.0",
					"MSXML2.DOMDocument.3.0",
					"MSXML2.DOMDocument",
					"MSXML.DOMDocument",
					"Microsoft.XmlDom" ];

		for (var i=0; !bDocument && i < aszDocumentProgIDs.length; i++) {
			try {
				obj = new ActiveXObject(aszDocumentProgIDs[i]);
				bDocument = true;
			}catch(e){
				alert(e.message);
			}
		}
	}

	return obj;
}

function getXmlHttp(){
	var obj=null;

	try{
		obj=new ActiveXObject("Msxml2.XMLHTTP");
	}catch(e){
		try{
			obj=new ActiveXObject("Microsoft.XMLHTTP");
		} catch(oc){
			obj=null;
		}
	}
	
	if(!obj && typeof(XMLHttpRequest) != "undefined") {
		obj=new XMLHttpRequest();
	}
	
	if(obj == null){
		unsupportedBrowser();
	}

	return obj;
}

function unsupportedBrowser(){
	alert("Your browser doesn't support the necessary technology.");
}

function openit(url, w, h){
	var popupscherm = window.open(url,'','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=yes,width='+w+',height='+h);
	popupscherm.focus();
	popupscherm.moveTo((screen.width/2)-(w/2), (screen.height/2)-(h/2));	
}

function openitModal(url, w, h){
	return window.showModalDialog(url,'', 'dialogWidth:'+w+'px;dialogHeight:'+h+'px');
}

/*
Get absolute y position in the browser window of a given object
*/
function findPosY(obj){
	//get y position of an object
	var curtop = 0;
	while (obj.offsetParent){
		curtop += obj.offsetTop;
		obj = obj.offsetParent;
	}
	
	return curtop;
}

function addEventListenerBIEM(object, eventtype, targetfunction){
	try{
		if(typeof(object.addEventListener) == "function"){
			object.addEventListener(eventtype, eval("dom" + targetfunction), true);
		}else{
			if(!object.tagName){
				eval("document.on"+eventtype+" = attr"+targetfunction+";");
			}else if(object.tagName == "BODY"){
				eval("document.body.on"+eventtype+" = attr"+targetfunction+";");
			}else{
				eval("document.getElementById('"+object.id+"').on"+eventtype+" = attr"+targetfunction+";");
			}
		}	
	}catch(e){
		alert(e.message);
		unsupportedBrowser();
	}
}

function removeEventListenerBIEM(object, eventtype, targetfunction){
	try{
		if(typeof(object.removeEventListener) == "function"){
			object.removeEventListener(eventtype, eval("dom" + targetfunction), true);
		}else{
			if(!object.tagName){
				eval("document.on"+eventtype+" = '';");
			}else if(object.tagName == "BODY"){
				eval("document.body.on"+eventtype+" = '';");
			}else{
				eval("document.getElementById('"+object.id+"').on"+eventtype+" = '';");
			}
		}
	}catch(e){
		unsupportedBrowser();
	}
}

function sortSel(obj){
	if(!obj){
		return;
	}

	var sorted = new Array();
	var tmp;
	for(var i=0;i<obj.options.length;i++){
		sorted[sorted.length] = obj.options[i].text+";;"+obj.options[i].value;
	}
	sorted.sort();
	obj.options.length = 0;
	for(var i=0;i<sorted.length;i++){
		tmp = sorted[i].split(';;');
		obj.options[i] = new Option(tmp[0], tmp[1]);
	}
}