function setSelectionRange(selectionEnd) {
input = document.textform.detext;
if (input.createTextRange) {
    var range = input.createTextRange();
    range.collapse(true);
    range.moveEnd('character', selectionEnd);
    range.moveStart('character', 0);
    range.select();
  }
}


function replaceSel(selstring){
    var range = document.selection.createRange();
    if (range.parentElement() == document.textform.detext) {
      var isCollapsed = range.text == '';
      
      if (!isCollapsed)  { // there has been a selection
	  	range.text = selstring;
        range.moveStart('character', -selstring.length);
        range.select();
      }
    }
}

function askLink(lan){
if (document.selection && document.selection.createRange){
var range = document.selection.createRange();
	if (range.parentElement() == document.textform.detext){
		var isCollapsed = range.text == '';
		if (!isCollapsed)  {
			window.open('incs/prompt.php?lan='+lan,'prom','width=260,height=110,tools=no,scrollbars=no,status=no,menu=no');
		}else{
			alert('Selecteer eerst een stukje text in de textbox...');
		}
	}else{
		alert('Selecteer eerst een stukje text in de textbox...');
	}
	
}else{
	alert('Alleen mogelijk met Internet Explorer');
}
}

function makeList(){
if (document.selection && document.selection.createRange){
var range = document.selection.createRange();
	if (range.parentElement() == document.textform.detext){
		var isCollapsed = range.text == '';
		if (!isCollapsed)  {
		var replacer = "";
			vSelection = document.selection.createRange().text;
			repArr = vSelection.split("\n");
			for(i=0;i<repArr.length;i++){
			if(repArr[i].length > 1){
			replacer = replacer + "<li>" + repArr[i];
			}
			}
			replacer = "<ul>"+ replacer +"</ul>";
			replaceSel(replacer);
		}else{
			alert('Selecteer eerst de regels waarvan u een lijst wilt maken...');
		}
	}else{
		alert('Selecteer eerst de regels waarvan u een lijst wilt maken...');
	}
	
}else{
	alert('Alleen mogelijk met Internet Explorer');
}
}


function openIntlink(lan){
	window.open('../incs/intlink.php?lan='+lan,'intwin','width=330,height=410,tools=no,scrollbars=no,status=no,menu=no');
}

function openReplacer(lan,die){
	window.open('incs/replace.php?lan='+lan+'&id='+die,'repwin','width=330,height=410,tools=no,scrollbars=no,status=yes,menu=no');
}

function openExtlink(){
	window.open('../incs/extlinkmaker.php','extwin','width=300,height=140,tools=no,scrollbars=no,status=no,menu=no');
}

function intLink(hid) {
	//intwin.close();
	vSelection = document.selection.createRange().text;
	replacer = "<a href=\"index.php?id="+hid+"\" onmouseover=\"window.status='';return true;\">" + vSelection + "</a>";
	replaceSel(replacer);
}



function extLink(page) {
	//intwin.close();
	vSelection = document.selection.createRange().text;
	replacer = "<a href=\""+page+"\" target=\"_blank\">" + vSelection + "</a>";
	replaceSel(replacer);
}


function underLineIt(){
if (document.selection && document.selection.createRange){
var range = document.selection.createRange().text;
newrange = "<u>"+range+"</u>";
replaceSel(newrange);
}else{
alert('Alleen mogelijk met Internet Explorer');
}
}

function makeBold(){
if (document.selection && document.selection.createRange){
var range = document.selection.createRange().text;
newrange = "<b>"+range+"</b>";
replaceSel(newrange);
}else{
alert('Alleen mogelijk met Internet Explorer');
}
}


function upLoadIt(){
	if(document.upform.userfile.value != ""){
		document.upform.submit();
		document.getElementById("upbuts").style.display = 'none';
		document.getElementById("waitbuts").style.display = 'block';
	}else{
		alert('Selecteer eerst een bestand op uw computer!');
	}
}
function upLoadIt6(){
	if(document.upform.userfile.value != ""){
		document.upform.submit();
		document.getElementById("upbuts").style.display = 'none';
		document.getElementById("upbuts2").style.display = 'none';
		document.getElementById("upbuts3").style.display = 'none';
		document.getElementById("waitbuts").style.display = 'block';
	}else{
		alert('Selecteer eerst een bestand op uw computer!');
	}
}
function upLoadIt2(){

		document.upform.submit();
		document.getElementById("upbuts").style.display = 'none';
		document.getElementById("waitbuts").style.display = 'block';

}

function sendIt(ed,idt){
	pags = document.adform.ad_page.value;
	page = "index.php?id="+idt+"&edit="+ed+"&page="+pags;
	window.location = page;
}

function doAdmin(id){
fun = document.adform.ad_id.value;
//edit menu
if(fun == 1){
sendIt(4,id);
}
//new menu
if(fun == 2){
sendIt(5,id);
}
//new paragraph
if(fun == 3){
sendIt(1,id);
}
//menu order
if(fun == 5){
sendIt(16,id);
}
//submenu order
if(fun == 6){
sendIt(17,id);
}
//content order 2
if(fun == 7){
sendIt(19,id);
}
//content order 2
if(fun == 8){
sendIt(20,id);
}

if(fun == 10){
sendIt(27,id);
}
if(fun == 11){
sendIt(29,id);
}

//place page somewhere else
/*
if(fun == 9){
lan = document.adform.ad_lan.value;
theid = id;
openReplacer(lan,id);
}*/

if(fun == 9){
sendIt(220,id);
}

if(fun == 12){
sendIt(31,id);
}
if(fun == 13){
sendIt(33,id);
}
if(fun == 14){
	page = "index.php?login=2";
	window.location = page;
}

//delete page
if(fun == 4){
boe = confirm('Weet u zeker dat u deze pagina inclusief\nalle (sub)content wilt verwijderen?');
if(boe){
sendIt(8,id);
}
}

//for vacatures
//edit vacature
if(fun == 15){
vac_id = document.adform.ad_vac.value;
pag = "index.php?id="+id+"&vc_id="+vac_id+"&action=8";
window.location = pag;
}
//delete vacature
if(fun == 16){
boe = confirm('Weet u zeker dat u deze vacature inclusief\neventuele reacties wilt verwijderen?\n\n(reacties zonder tweede vac. keus zullen worden verwijderd)');
if(boe){
vac_id = document.adform.ad_vac.value;
pag = "index.php?id="+id+"&vc_id="+vac_id+"&action=10";
window.location = pag;
}
}
//new vacature
if(fun == 17){
pag = "index.php?id="+id+"&action=8";
window.location = pag;
}
//reacties
if(fun == 18){
pag = "index.php?id="+id+"&action=11";
window.location = pag;
}
//vacatures
if(fun == 19){
pag = "index.php?id="+id+"&action=0";
window.location = pag;
}
//delete reactie
if(fun == 20){
boe = confirm('Weet u zeker dat u deze reactie wilt verwijderen?');
if(boe){
vac_id = document.adform.ad_vac.value;
pag = "index.php?id="+id+"&vc_id="+vac_id+"&action=13";
window.location = pag;
}
}

//newsletter
if(fun == 21){
pag = "index.php?id="+id+"&action=14";
window.location = pag;
}

//referenties
if(fun == 22){
sendIt(50,id);
}


}

function intLinks(daaro){
page = ('../index.php?edit=22&id='+theid+'&cn_id='+daaro);
window.location = page;
}



 function saveM(){
	 if(document.textform.mn_name.value != ""){
		  if(document.textform.mn_name.value.length < 30){
			 document.textform.submit();
			 document.getElementById("upbuts").style.display = 'none';
			 document.getElementById("waitbuts").style.display = 'block';
		  }else{
		     alert('De menunaam is te lang!');
		  }
	 }else{
	    alert('De menunaam is te kort!');
	 }
 }
 
function delItem(pa){
boe = confirm('Weet u zeker dat u deze foto wilt verwijderen?');
if(boe){
window.location = pa;
}
}

 function delImg(sid,cid){
	bah = confirm('Weet u zeker dat u deze afbeelding wilt verwijderen?');
	if(bah){
	page = ('index.php?edit=9&id='+sid+'&cn_id='+cid);
	window.location = page;
	}
}
 function delBan(sid,cid){
	bah = confirm('Weet u zeker dat u deze menufoto wilt verwijderen?');
	if(bah){
	page = ('index.php?edit=35&id='+sid+'&cn_id='+cid);
	window.location = page;
	}
}
 function delFile(sid,cid){
	bah = confirm('Weet u zeker dat u dit bestand wilt verwijderen?');
	if(bah){
	page = ('index.php?edit=15&id='+sid+'&cn_id='+cid);
	window.location = page;
	}
}

 function delPar(cid,sid){
	bah = confirm('Weet u zeker dat u deze paragraaf wilt verwijderen?');
	if(bah){
	page = ('index.php?edit=10&id='+sid+'&cn_id='+cid);
	window.location = page;
	}
}

ordercount = 0;
function addOrder(divid,menuid,total){
ordercount++;
document.orderform.orderlist.value = (document.orderform.orderlist.value + menuid);
document.getElementById("div"+divid).innerHTML = ordercount;
if(ordercount == total){
document.orderform.submit();
}else{
document.orderform.orderlist.value = (document.orderform.orderlist.value + "|");
}
}


