		function deleteOption(object,index) {
			object.options[index] = null;
		}
		
		function addOption(object,text,value) {
			var defaultSelected = false;
			var selected = false;
			var optionName = new Option(text, value, defaultSelected, selected)
			object.options[object.length] = optionName;
		}
		
		function copySelected(fromObject,toObject) {
			var target = toObject.id;
			
			for (var i=0, l=fromObject.options.length;i<l;i++) {
				if (fromObject.options[i].selected){
					if ((fromObject.options[i].text != '') || (fromObject.options[i].value !='')){
						addOption(toObject,fromObject.options[i].text,fromObject.options[i].value);
					}
				}
			}
		
			for (var i=fromObject.options.length-1;i>-1;i--) {
				if (fromObject.options[i].selected){
					if ((fromObject.options[i].text != '') || (fromObject.options[i].value !='')){
						deleteOption(fromObject,i);
					}
				}
			}
			
			//sizeFields(toObject, fromObject);
			sorteerLijst(toObject);
			//if(target=='sel'){			
			//	updateEdit(toObject);		
			//}else{
			//	resetEdit(fromObject);	
			//}
		}
		
		function copyAll(fromObject,toObject) {
			var target = toObject.id;
			for (var i=0, l=fromObject.options.length;i<l;i++) {
				if ((fromObject.options[i].text != '') || (fromObject.options[i].value !='')){
					addOption(toObject,fromObject.options[i].text,fromObject.options[i].value);
				}
			}
			for (var i=fromObject.options.length-1;i>-1;i--) {
				if ((fromObject.options[i].text != '') || (fromObject.options[i].value !='')){
					deleteOption(fromObject,i);
				}
			}
			
			//sizeFields(toObject, fromObject);
			sorteerLijst(toObject);
			//if(target=='sel'){			
				//updateEdit(toObject);		
			//}else{
				//resetEdit(fromObject);	
			//}			
		}
		
		function sizeFields(toObject, fromObject) {
			var toLen = toObject.options.length;
			var fromLen = fromObject.options.length;
			if (toLen < 5){
				toObject.size = 5;
			}else if(toLen > 15){
				toObject.size = 15;
			}else{
				toObject.size = toLen;
			}
			
			if (fromLen < 5){
				fromObject.size = 5;
			}else if(fromLen > 15){
				fromObject.size = 15;
			}else{
				fromObject.size = fromLen;
			}
		}
		
		//------------------------------------------------------------------------
		
		function sorteerLijst(lijst) {
		
			var arr_optionsValue = new Array(); // array to hold the Value of the OPTIONS
        	var arr_optionsText = new Array(); // array to hold the Text of the OPTIONS
        	
			// populate the array
	        for (count=0;count<lijst.options.length;count++){
//	            arr_optionsText[count] = lijst.options[count].text.toLowerCase();
	            arr_optionsText[count] = lijst.options[count].text
	        }
	        // sort them
	        arr_optionsText.sort();
	        // get the correct values
	        for (i=0;i<arr_optionsText.length;i++){
	            for (j=0;j<lijst.options.length;j++){
//	                if (lijst.options[j].text.toLowerCase()==arr_optionsText[i]){
	                if (lijst.options[j].text==arr_optionsText[i]){
	                    arr_optionsValue[i]=lijst.options[j].value;
	                }
	            }
	        }
	        // empty the dd
	        lijst.options.length=0;
	        // repopulate the list
	        for (i=0;i<arr_optionsText.length;i++){	            
	        	lijst.options[i]= new Option(arr_optionsText[i],arr_optionsValue[i]);	            
	        }				
		}
		
		//------------------------------------------------------------------------
		
		function loadFolder(fromObject, toObject){
			alert('Hier moet een functie geschreven worden die de inhoud\nvan de gekozen folder in de linker selectbox laadt.')
		}
		
		
		
		function updateEdit(selectBox) {
			var opts = selectBox.options;
			for(var i=0; i<opts.length;i++){
				//alert(opts[i].value);
				document.getElementById(opts[i].value).style.display = '';
			}
			
		}
		
		function resetEdit(selectBox) {
			var opts = selectBox.options;
			for(var i=0; i<opts.length;i++){
				//alert(opts[i].value);
				document.getElementById(opts[i].value).style.display = '';
			}
			
		}
		
		//FUNCTIES VOOR SITE CHANNELS
		
		var activeEdit = "channel_default";
		
		function showEdit(selectBox) {
			//var nummer = selectBox.form.sel.options.selectedIndex +1;
			//alert(nummer);			
			//var defaultTable = document.getElementById("channel_default");
			
			var editObjId = "channel_" + selectBox.form.sel.options[selectBox.form.sel.options.selectedIndex].value;			
			var editTable = document.getElementById(editObjId);
			var oldEditTable = document.getElementById(activeEdit);
			if(editTable){
				oldEditTable.style.display="none";
				editTable.style.display = "";
				activeEdit = editObjId;
			}else{
				oldEditTable.style.display="none";
				document.getElementById("channel_default").style.display = "";
				activeEdit = "channel_default";
			}
		}
		
		function addEdit(selectBox) {
			for(var i = 0; i < selectBox.options.length;i++){
				if(selectBox.options[i].selected){
					addHTML(selectBox.options[i].value);
				}
			}			
		}
		
		function addAllEdit(selectBox) {
			for(var i = 0; i < selectBox.options.length;i++){
				addHTML(selectBox.options[i].value);				
			}			
		}
		
		function removeEdit(selectBox) {
			for(var i = 0; i < selectBox.options.length;i++){
				if(selectBox.options[i].selected){
					var editObj = document.getElementById("channel_"+selectBox.options[i].value);
					editObj.parentNode.removeChild(editObj);
					
				}
			}
			document.getElementById("channel_default").style.display = "";
			activeEdit = "channel_default";	
		}
		
		function removeAllEdit() {
			var editCol = document.getElementById("instellingen_col");
					
			var html = '<table cellspacing="0" class="instellingen_tbl" id="channel_default">\n';
			html += '<tr class="header">\n';
			html += '<td colspan="2"><p>Instellingen</p></td>\n';
			html += '</tr>\n';
			html += '</table>\n';
			
			editCol.innerHTML = html;		
		}
		
		function addHTML(channel) {
			var editCol = document.getElementById("instellingen_col");
			var channelNaam = channel;
			var html = '<table cellspacing="0" class="instellingen_tbl" id="channel_'+channelNaam+'" style="display:none;">\n';
			html += '<tr class="header">\n';
			html += '<td colspan="2"><p>Instellingen ' + channelNaam +'</p></td>\n';
			html += '</tr>\n';
			html += '<tr>\n';
			html += '<td class="col1"><p>Opties</p></td>\n';
			html += '<td class="col2">';
			html += '<input type="checkbox" name="'+channelNaam+'_active" id="'+channelNaam+'_active" /><label>Actief</label>';
			html += '<input type="checkbox" name="'+channelNaam+'_killframes" id="'+channelNaam+'_killframes" /><label>Frames</label>';
			html += '</td>\n';
			html += '</tr>\n';
			html += '<tr>\n';
			html += '<td class="col1"><p>Volgorde</p></td>\n';
			html += '<td class="col2"><input type="text" name="'+channelNaam+'_volgorde" /></td>\n';
			html += '</tr>\n';
			html += '<tr>\n';
			html += '<td class="col1"><p>Style</p></td>\n';
			html += '<td class="col2"><input type="text" name="'+channelNaam+'_style" /></td>\n';
			html += '</tr>\n';
			html += '<tr>\n';
			html += '<td class="col1"><p>Target</p></td>\n';
			html += '<td class="col2"><input type="text" name="'+channelNaam+'_target" /></td>\n';
			html += '</tr>\n';
			html += '<tr>\n';
			html += '<td class="col1"><p>Header</p></td>\n';
			html += '<td class="col2"><textarea rows="5" name="'+channelNaam+'_header"></textarea></td>\n';
			html += '</tr>\n';

//			html += '<tr>\n';
//			html += '<td class="col1"><p>Boodschap</p></td>\n';
//			html += '<td class="col2"><textarea rows="5" name="'+channelNaam+'_message"></textarea></td>\n';
//			html += '</tr>\n';
//			html += '<tr>\n';
//			html += '<td class="col1"><p>Linknaam</p></td>\n';
//			html += '<td class="col2"><textarea rows="5" name="'+channelNaam+'_linknaam"></textarea></td>\n';
//			html += '</tr>\n';

			html += '<tr>\n';
			html += '<td class="col1"><p>Tekst voor</p></td>\n';
			html += '<td class="col2"><textarea rows="5" name="'+channelNaam+'_tekstvoor"></textarea></td>\n';
			html += '</tr>\n';
			html += '<tr>\n';
			html += '<td class="col1"><p>Tekst link</p></td>\n';
			html += '<td class="col2"><textarea rows="5" name="'+channelNaam+'_tekstlink"></textarea></td>\n';
			html += '</tr>\n';
			html += '<tr>\n';
			html += '<td class="col1"><p>Tekst na</p></td>\n';
			html += '<td class="col2"><textarea rows="5" name="'+channelNaam+'_tekstna"></textarea></td>\n';
			html += '</tr>\n';
			html += '<tr>\n';
			html += '<td class="col1"><p>Melding</p></td>\n';
			html += '<td class="col2"><textarea rows="5" name="'+channelNaam+'_melding"></textarea></td>\n';
			html += '</tr>\n';

			html += '<tr class="header">\n';
			html += '<td colspan="2"><p>Instellingen datahub</p></td>\n';
			html += '</tr>\n';
			html += '<tr>\n';
			html += '<td class="col1"><p>Skin</p></td>\n';
			html += '<td class="col2"><input type="text" name="'+channelNaam+'_skin" /></td>\n';
			html += '</tr>\n';
			html += '<tr>\n';
			html += '<td class="col1"><p>Logon</p></td>\n';
			html += '<td class="col2">';
			html += '<input type="checkbox" name="'+channelNaam+'_logon" id="'+channelNaam+'_logon" />';
			html += '</td>\n';
			html += '</tr>\n';

			html += '</table>\n';
			//alert(html);
			editCol.innerHTML += html;
			//alert(editCol.innerHTML);
		}
		

		//FUNCTIES VOOR SITE GROEPEN
		
		
		
		
		
		// schrijf de rijen
		
		//zet de waarden
		
		
		function setRechten(selectBox) {
			optArr.length = 0;
			//loop door de options
			for(var i=0; i<selectBox.options.length; i++){
				//sla de waarden op
				
				var chkbx_rd = selectBox.options[i].value + "_read";
				var chkbx_wrt = selectBox.options[i].value + "_write";
							
				if(document.getElementById(chkbx_rd)){
		
					var rd = document.getElementById(chkbx_rd).status;
					var wrt = document.getElementById(chkbx_wrt).status;
		
					saveRechten(i,selectBox.options[i].value,rd,wrt);
					
				}else{		
					saveRechten(i,selectBox.options[i].value,false,false);
					
				}				
			}
			writeTableRows();
		}
		
		function writeTableRows() {
		
			var anon_read = '';
			if(document.getElementById('anoniem_read').status){
				anon_read = 'checked="checked"';
			}		
			document.getElementById('rechten_container').innerHTML = '';
			var html = '<table cellspacing="0" id="rechten_tbl">\n';
			html += '<tr class="header">\n';
			html += '<td colspan="3"><p>Rechten</p></td>\n';
			html += '</tr>\n';
			html += '<tr class="header">\n';
			html += '<td><p>naam</p></td>\n';
			html += '<td><p>lezen</p></td>\n';
			html += '<td><p>schrijven</p></td>\n';
			html += '</tr>\n';
			
			html += '<tr class="hi" id="anoniem">';
			html += '<td class="col1"><p>anoniem</p></td>';
			html += '<td class="col2"><input type="checkbox" name="anoniem_read" id="anoniem_read" '+anon_read+' /></td>';
			html += '<td class="col3">&nbsp;</td>';
			html += '</tr>';
			
		
			for(var i=0; i<optArr.length; i++){
				html += optArr[i].wrtRow(optArr[i].nummer, optArr[i].naam, optArr[i].lees, optArr[i].schrijf);
			}
		
			html += '</table>\n';
		
			document.getElementById('rechten_container').innerHTML = html;	
			
		}
		
		
		
		var optArr = new Array();
		
		function saveRechten(optie,naam,rd,wrt){
			//alert(optArr.length);
			//optArr.count = 0;			
			optArr[optie] = new optieObj(optie,naam,rd,wrt);
		}
		
		function optieObj(optie,naam,rd,wrt){
			this.nummer = optie;
			this.naam = naam;
			this.lees = rd;
			this.schrijf = wrt;			
			this.wrtRow = writeTableRow;
		}
		
		function writeTableRow(nr, nm, ls, schr){
			var nummer = nr;
			var naam = nm;
			var lees = ls;
			var schrijf = schr;
			var chkd_rd ='';
			var chkd_wrt ='';
			if(lees){
				chkd_rd = 'checked="checked"';
			}
			if(schrijf){
				chkd_wrt = 'checked="checked"';
			} 
			
			
			var html = '';
			if(nummer%2 != 0){
				html += '<tr class="hi" id="'+naam+'">\n';
			}else{
				html += '<tr id="'+naam+'">\n';
			}			
			html += '<td class="col1"><p>'+naam+'</p></td>\n';
			html += '<td class="col2"><input type="checkbox" name="'+naam+'_read" id="'+naam+'_read" '+chkd_rd+' /></td>\n';
			html += '<td class="col3"><input type="checkbox" name="'+naam+'_write" id="'+naam+'_write" '+chkd_wrt+' /></td>\n';
			html += '</tr>\n';
			
			return html;
		}
		
		function selectAllOptions(obj) {
			if (!hasOptions(obj)) { return; }
			for (var i=0; i<obj.options.length; i++) {
				obj.options[i].selected = true;
			}
		}
		
		function hasOptions(obj) {
			if (obj!=null && obj.options!=null) { return true; }
			return false;
		}
