dl = document.layers;
da = document.all;
ge = document.getElementById;
ws = window.sidebar;
var msg='';

function nem(){
alert('er is iets fout gegaan!');
return false;
}
window.onerror = nem;
var w85;	

function makeEditable() {
//alert('makeEditable');
///Wordt alleen binnen js gebrruikt maakt de content schrijfbaar
		allElem =  foo.document.getElementsByName("webedit")
		for (a=0; a < allElem.length; a++) {
			allElem[a].contentEditable = "true"
			if (allElem[a].comment != null)
			{
				allElem[a].alt="Comment: " + allElem[a].comment
			}
		}
}

function revertEditable() {
//alert('revertEditable');
//Wordt alleen binnen js gebruikt maakt de content schrijfbaar
		allElem =  foo.document.getElementsByName("webedit")
		for (a=0; a < allElem.length; a++) {
			allElem[a].removeAttribute("contentEditable")
			if (allElem[a].comment != "")
			{
				allElem[a].removeAttribute("title")
			}
		}
}

function replaceIncludes(code) {
///alert('replaceIncludes');
///Gebruikt in de functie SaveHtml om onnodige code te filteren
		var re = /<WEP\:INC\s*(.*?)>((\n|.)*?)<\/WEP\:INC>/igm
		code = code.replace(re,"\n<WEP:INC $1>\n<!--#include $1-->\n</WEP:INC>\n")
		return code
}

function isAllowed() {
//Wordt in bijna alle functies gebruikt
//Omvat de selectie en kijkt of je die kan wijzigen
		var sel
		var obj
		if (editDefault != 1) {
			return true
		} else {
			sel = foo.document.selection
			if (sel.type != "Control")
			{
				obj = sel.createRange().parentElement()
			} else {
				obj = sel.createRange()(0)
			}
			
			if (obj.isContentEditable) {
				return true
			} else {
				return false
			}
		}
	}


	
function applyStyle(styleValue) {
//alert('applyStyle');
	//Geeft de style SPAN Class aan een bepaalde selectie
		if (isAllowed())
		{

		var done
		var selectedArea = foo.document.selection.createRange()
		if (styleValue != "") {
			styleValue = styleValue.substring(1, styleValue.length)
		}
		if (foo.document.selection.type == "Control") {
			applyStyleTo = selectedArea.commonParentElement()
		}  else {
			if (foo.document.selection.createRange().htmlText == "") {
				applyStyleTo = selectedArea.parentElement()
			} else {
				if ((selectedArea.parentElement().tagName.toUpperCase() == "SPAN") || (selectedArea.parentElement().tagName.toUpperCase() == "A")) {
					applyStyleTo = selectedArea.parentElement()
					if ((styleValue == "") && (selectedArea.parentElement().tagName.toUpperCase() == "SPAN")) {
						applyStyleTo.removeNode(false);
						done = true
					}
				} else {
					if (styleValue != "") {
						selectedArea.pasteHTML("<span class=" + styleValue + ">" + selectedArea.htmlText + "</span>")
					}
					done = true
				}
			}
		}
		if (done != true) {
			applyStyleTo.className = styleValue
		}
		}
	}
	
function displayUserStyles() {
// Vul de dropdown met de Stylesheets die de gebruiker kan kiezne
		var theStyle = new Array();
		var theStyleText = new Array();
		var styleExists
		noOfSheets = top.foo.document.styleSheets.length
		if (noOfSheets > 0) {
			for (i=1;i<=noOfSheets;i++) {
				noOfStyles =  top.foo.document.styleSheets(noOfSheets-1).rules.length
					for (x=0;x<noOfStyles;x++){
						styleValue =  top.foo.document.styleSheets(noOfSheets-1).rules(x).selectorText

						// stylesheet rule contains a . (ignore any styles that dont contain a . they are NOT user styles)
						if (styleValue.indexOf(".") >= 0) {

							// stylesheet rule doesnt contain :
							if (styleValue.indexOf(":") < 0) {

								// style contains a . at beginning
								if (styleValue.indexOf(".") == 0) {
									styleText = styleValue.substring(1,styleValue.length)
									theStyle[theStyle.length] = styleValue
									theStyleText[theStyleText.length] = styleText

								} else {
									// style contains a . not at beginning
									if (styleValue.indexOf(".") > 0) {
										styleText = styleValue.substring(styleValue.indexOf(".")+1,styleValue.length)
										styleValue = styleValue.substring(styleValue.indexOf("."),styleValue.length)

										theStyleText[theStyleText.length] = styleText									
										theStyle[theStyle.length] = styleValue
									}						
								}

							// contains BOTH a . and a :
							} else {
								styleValue = styleValue.substring(styleValue.indexOf("."),styleValue.indexOf(":"))
							
								for (i=0;i<theStyle.length;i++) {
									if (styleValue == theStyle[i]) {
										styleExists = true
									}
								}
							
								if (styleExists != true) {
									theStyle[theStyle.length] = styleValue

									styleText = styleValue.substring(styleValue.indexOf(".")+1,styleValue.length)
									theStyleText[theStyleText.length] = styleText
								}

								styleExists = false
							}

						}

					} // End for

					for (z=0; z <= theStyle.length-1; z++) {						
						newOption = document.createElement("option");
			  			newOption.value = theStyle[z];
						newOption.text = theStyleText[z];
						sStyles.add(newOption)
					} 

			} // End For
		} // End if
} // End function


function showStatus() {
//Status bar vulling
		editMode = "Item: "
		itemNaam = window.opener.Composeform.body2.value
		if(itemNaam==''){itemNaam = 'Nieuw' } 
		else { itemNaam = 'Bewerken' } 
		if (Mode == "2") {
			statusMode = "Mode: CODE       "
		} else {
			statusMode = "Mode: WYSIWYG"
		}

		if (borderShown == "yes") {
			statusBorders = "Hulplijnen: AAN  "
		} else {
			statusBorders = "Hulplijnen: UIT"
		}

		if (editDefault == 1) {
			plugPlay = "Rol: " 
		} else {
			plugPlay = "Rol: " 
		}

		window.status = editMode + itemNaam + "   |   " + statusMode + "   |   " +  statusBorders + "   |   " +  plugPlay + window.opener.Composeform.Rol.value;
}

function cleanCode() {
// alert('cleanCode');
// DE CODE REINIGEN
if (confirm("Weet u zeker dat u de code wilt opschonen?")){
var borderwason
if (borderShown == "yes") {
				toggleBorders()
				borderwason = true
			}

			if (editDefault == 1) {
				allElem =  foo.document.getElementsByName("webedit")
				for (a=0; a < allElem.length; a++) {
					allElem[a].innerHTML = doCleanCode(allElem[a].innerHTML)
				}
			} else {
				foo.document.body.innerHTML = doCleanCode(foo.document.body.innerHTML)
			}

			if (borderwason) {
				toggleBorders()
			}
		}
	}

function doCleanCode(code) { 
// alert('doCleanCode');  
// DIT ZIJN DE REPLACES
code = code.replace(/<o:[pP]>&nbsp;<\/o:[pP]>/g, ""); 
code = code.replace(/o:/g, ""); 
code = code.replace(/<st1:.*?>/g, ""); 
code = code.replace(/<[pP]><\/[pP]>/g, ""); 
code = code.replace(/<[pP]>&nbsp;<\/[pP]>/g, ""); 
code = code.replace(/(style="([^"]+)>)/ig,""); //style eruit halen
code = code.replace(/(<[bB] style([^>]+)>)/ig,"<b>"); // b style eruit halen
code = code.replace(/(<[iI] style([^>]+)>)/ig,"<i>"); // i style eruit halen
code = code.replace(/(<[pP] class([^>]+)>)/ig,"<p>"); // p class  eruit halen
code = code.replace(/(<[sS][pP][aA][nN]([^>]+)>)/ig,""); // <span*> eruit halen
code = code.replace(/(<\/[sS][pP][aA][nN]([^>]+)>)/ig,""); // </span*> eruit halen
code = code.replace(/(<[fF][oO][nN][tT]([^>]+)>)/ig,""); // <font*> eruit halen
code = code.replace(/(<\/[fF][oO][nN][tT]([^>]+)>)/ig,""); // </font*> eruit halen
code = code.replace(/(<TBODY>)/ig,""); // <TBODY*> eruithalen
code = code.replace(/(<\/TBODY>)/ig,""); // </TBODY*> eruithalen
code = code.replace(/(<\/SPAN>)/ig,""); // </TBODY*> eruithalen
code = code.replace(/(<?xml:([^>]+)>)/ig,""); // <?xml: eruit halen
code = code.replace(/<p([^>])*>(&nbsp;)*\s*<\/p>/gi,"") // removes all empty <p> tags
code = code.replace(/<span([^>])*>(&nbsp;)*\s*<\/span>/gi,"")// removes all empty span tags
code = code.replace(/<SPAN([^>])*>(&nbsp;)*\s*<\/SPAN>/gi,"")// removes all empty span tags, maar dan met hoofdletters
code = code.replace(/<([\w]+) class=([^ |>]*)([^>]*)/gi, "<$1$3")// removes all Class attributes on a tag eg. '<p class=asdasd>xxx</p>' returns '<p>xxx</p>'
code = code.replace(/<([\w]+) style="([^"]*)"([^>]*)/gi, "<$1$3")// removes all style attributes eg. '<tag style="asd asdfa aasdfasdf" something else>' returns '<tag something else>'   
code = code.replace(/<\\?\??xml[^>]>/gi, "")// gets rid of all xml stuff... <xml>,<\xml>,<?xml> or <\?xml>
//code = code.replace(/<\\?\??font[^>]>/gi, "")// HAALT ALLE font DINGEN WEG
//code = code.replace(/<\\?\??FONT[^>]>/gi, "")// HAALT ALLE FONT DINGEN WEG
code = code.replace(/<\/?\w+:[^>]*>/gi, "")// get rid of ugly colon tags <a:b> or </a:b>
code = code.replace(/(<\/FONT>)/ig,""); // </FONT> eruithalen
code = code.replace("<?",""); // <? eruithalen
return code
}

function stripTags(){
// DE TAGS ERUIT HALEN
if (confirm("Weet u zeker dat u opmaak wilt verwijderen?")){
var borderwason
if (borderShown == "yes") {
				toggleBorders()
				borderwason = true
			}

			if (editDefault == 1) {
				allElem =  foo.document.getElementsByName("webedit")
				for (a=0; a < allElem.length; a++) {
					allElem[a].innerHTML = doStripTags(allElem[a].innerHTML)
				}
			} else {
				foo.document.body.innerHTML = doStripTags(foo.document.body.innerHTML)
			}

			if (borderwason) {
				toggleBorders()
			}
		}
}

function doStripTags(code){
// DEZE FUNCTIE HAALT ALLE HTML TAGS ERUIT
code = code.replace(/(<([^>]+)>)/ig,"");
return code
}

function toggleBorders() {
// Geef randen weer rond forms, inputs, tables en links
		var allForms = foo.document.body.getElementsByTagName("FORM");
		var allInputs = foo.document.body.getElementsByTagName("INPUT");
		var allTables = foo.document.body.getElementsByTagName("TABLE");
		var allLinks = foo.document.body.getElementsByTagName("A");
		
		if (borderShown == "no") {
			toggle = "off" 
		} else { 
			toggle = "on" 
		}

// Do forms
for (a=0; a < allForms.length; a++) {
			if (toggle == "off") {
				allForms[a].style.border = "1px dotted #FF0000"
			} else {
				allForms[a].removeAttribute("style")
			}
		}

// Do hidden fields
for (b=0; b < allInputs.length; b++) {
			if (toggle == "off") {
				if (allInputs[b].type.toUpperCase() == "HIDDEN") {
					allInputs[b].style.border = "1px dashed #000000"
					allInputs[b].style.width = "15px"
					allInputs[b].style.height = "15px"
					allInputs[b].style.backgroundColor = "#FDADAD"
					allInputs[b].style.color = "#FDADAD"
				}
			} else {
				if (allInputs[b].type.toUpperCase() == "HIDDEN")
					allInputs[b].removeAttribute("style")
			}
		}

// Do tables
for (i=0; i < allTables.length; i++) {
				if (toggle == "off") {
					allTables[i].style.border = "1px dotted #BFBFBF"
				} else {
					allTables[i].removeAttribute("style")
				}
				allRows = allTables[i].rows
				for (y=0; y < allRows.length; y++) {
				 	allCellsInRow = allRows[y].cells
						for (x=0; x < allCellsInRow.length; x++) {
							if (toggle == "off") {
								allCellsInRow[x].style.border = "1px dotted #BFBFBF"
							} else {
								allCellsInRow[x].removeAttribute("style")
							}
						}
				}
		}

// Do anchors
for (a=0; a < allLinks.length; a++) {
			if (toggle == "off") {
				if (allLinks[a].href.toUpperCase() == "") {
					allLinks[a].style.border = "1px dashed #000000"
					allLinks[a].style.width = "20px"
					allLinks[a].style.height = "16px"
					allLinks[a].style.backgroundColor = "#FFFFCC"
					allLinks[a].style.color = "#FFFFCC"					
				}
			} else {
				allLinks[a].removeAttribute("style")
			}
		}

// Do Editable Content
if (editDefault == 1)
		{
			allElem =  foo.document.getElementsByName("webedit")
			for (a=0; a < allElem.length; a++) {
				if (toggle == "off") {
					allElem[a].style.backgroundColor = "#FFF4FF"
				} else {
					allElem[a].removeAttribute("style")
				}
			}
		}
		

		if (toggle == "off") {
			borderShown = "yes"
		} else {
			borderShown = "no"
		}

		foo.document.body.innerHTML = foo.document.body.innerHTML
		scrollUp()
		showStatus()
	}

function doFormat(fType) {
// alert('doFormat');
	//Maak er het type tekst van dat in de select box wordt gekozen
		if ((fType != "SuperScript") && (fType != "SubScript")) {
			foo.document.execCommand('formatBlock',false,fType)
		} else {
			foo.document.execCommand(fType)
		}
	}

function InsertRowAbove() {
// alert('InsertRowAbove');
//Voer rij in de tabel in boven de huidige
		if (isCursorInTableCell()){
			var numCols = 0

			allCells = selectedTR.cells
			for (var i=0;i<allCells.length;i++) {
			 	numCols = numCols + allCells[i].getAttribute('colSpan')
			}

			var newTR = selectedTable.insertRow(selectedTR.rowIndex)
	
			for (i = 0; i < numCols; i++) {
			 	newTD = newTR.insertCell()
				newTD.innerHTML = "&nbsp;"
			}
		}	
		
	} // End function

function InsertRowBelow() {
// alert('InsertRowBelow');
//Voer rij in de tabel in onder de huidige
		if (isCursorInTableCell()){
		
			var numCols = 0

			allCells = selectedTR.cells
			for (var i=0;i<allCells.length;i++) {
			 	numCols = numCols + allCells[i].getAttribute('colSpan')
			}

			var newTR = selectedTable.insertRow(selectedTR.rowIndex+1)

			for (i = 0; i < numCols; i++) {
			 	newTD = newTR.insertCell()
				newTD.innerHTML = "&nbsp;"
			}
		}

	} // End function

function IncreaseColspan() {
// alert('IncreaseColspan');
//Vergroot de Colspan
		if (isCursorInTableCell()) {

			var colSpanTD = selectedTD.getAttribute('colSpan')
			allCells = selectedTR.cells

			if (selectedTD.cellIndex + 1 != selectedTR.cells.length) {
				var addColspan = allCells[selectedTD.cellIndex+1].getAttribute('colSpan')
				selectedTD.colSpan = colSpanTD + addColspan
				selectedTR.deleteCell(selectedTD.cellIndex+1)
			}	
		}

	} // End function

function IncreaseRowspan() {
// alert('IncreaseRowspan');
//Vergroot de Rowspan
		if (isCursorInTableCell()) {

			var rowSpanTD = selectedTD.getAttribute('rowSpan')
			allRows = selectedTable.rows
			if (selectedTR.rowIndex +1 != allRows.length) {

				var allCellsInNextRow = allRows[selectedTR.rowIndex+selectedTD.rowSpan].cells
				var addRowSpan = allCellsInNextRow[selectedTD.cellIndex].getAttribute('rowSpan')
				var moveTo = selectedTD.rowSpan

				if (!addRowSpan) addRowSpan = 1;

				selectedTD.rowSpan = selectedTD.rowSpan + addRowSpan
				allRows[selectedTR.rowIndex + moveTo].deleteCell(selectedTD.cellIndex)
			}
		}

	} // End function

function DecreaseColspan() {
// alert('DecreaseColspan');
//Verklein de Colspan

		if (isCursorInTableCell()) {
			if (selectedTD.colSpan != 1) {
				selectedTR.insertCell(selectedTD.cellIndex+1)
				selectedTD.colSpan = selectedTD.colSpan - 1	
			}
		}

	} // End function

function DecreaseRowspan() {
// alert('DecreaseRowspan');
//Verklein de Rowspan WAARSCHIJNLIJK NOG NIET AF
		if (isCursorInTableCell()) {
		
			alert("To Do")
		}

	} // End function

function DeleteRow() {
// alert('DeleteRow');
//Verwijder huidige Table row
		if (isCursorInTableCell()) {
			selectedTable.deleteRow(selectedTR.rowIndex)
		}
	}

function DeleteCol() {
	
        	if (isCursorInTableCell()) {
			moveFromEnd = (selectedTR.cells.length-1) - (selectedTD.cellIndex)
			allRows = selectedTable.rows
			for (var i=0;i<allRows.length;i++) {
				endOfRow = allRows[i].cells.length - 1
				position = endOfRow - moveFromEnd
				if (position < 0) {
					position = 0
				} // End If
				

				allCellsInRow = allRows[i].cells
				
				if (allCellsInRow[position].colSpan > 1) {
					allCellsInRow[position].colSpan = allCellsInRow[position].colSpan - 1
				} else { 
					allRows[i].deleteCell(position)
				}

			} // End For	

        	} // End If

	} // End Function

function InsertColAfter() {
	
        	if (isCursorInTableCell()) {
			moveFromEnd = (selectedTR.cells.length-1) - (selectedTD.cellIndex)
			allRows = selectedTable.rows
			for (i=0;i<allRows.length;i++) {
			rowCount = allRows[i].cells.length - 1
			position = rowCount - moveFromEnd
			if (position < 0) {
				position = 0
			}
				newCell = allRows[i].insertCell(position+1)
				newCell.innerHTML = "&nbsp;"
			}	
        	}
	} // End Function


function InsertColBefore() {
	
        	if (isCursorInTableCell()) {
			moveFromEnd = (selectedTR.cells.length-1) - (selectedTD.cellIndex)
			allRows = selectedTable.rows
			for (i=0;i<allRows.length;i++) {
				rowCount = allRows[i].cells.length - 1
				position = rowCount - moveFromEnd
				if (position < 0) {
					position = 0
				}
				newCell = allRows[i].insertCell(position)
				newCell.innerHTML = "&nbsp;"
			}	
        	}
	}

function isImageSelected() {
// alert('isImageSelected');
//Check of er een IMG geselecteerd is
		if (foo.document.selection.type == "Control") {
			var oControlRange = foo.document.selection.createRange();
			if (oControlRange(0).tagName.toUpperCase() == "IMG") {
				selectedImage = foo.document.selection.createRange()(0);
				return true;
			}	
		}
	}

function isTableSelected() {
// alert('isTableSelected');
//Check of er een TABLE geselecteerd is
		if (foo.document.selection.type == "Control") {
			var oControlRange = foo.document.selection.createRange();
			if (oControlRange(0).tagName.toUpperCase() == "TABLE") {
				selectedTable = foo.document.selection.createRange()(0);
				return true;
			}	
		}
	} // End Function

function isCursorInTableCell() {
// alert('isCursorInTableCell');
//Check of de cursor zich in een tabel cel bevind
		if (document.selection.type != "Control") {
                          var elem = document.selection.createRange().parentElement()
                          while (elem.tagName.toUpperCase() != "TD" && elem.tagName.toUpperCase() != "TH")
                          {
                            elem = elem.parentElement
                            if (elem == null)
                              break
                          }
				if (elem) {
					selectedTD = elem
					selectedTR = selectedTD.parentElement
					selectedTBODY =  selectedTR.parentElement
					selectedTable = selectedTBODY.parentElement
					return true
				}
		}
	} // End function

function isCursorInForm() {
// alert('isCursorInForm');
// Check of de cursor in een form staat

		if (document.selection.type != "Control") {
                          var elem = document.selection.createRange().parentElement()
                          while (elem.tagName != "FORM")
                          {
                            elem = elem.parentElement
                            if (elem == null)
                              break
                          }
				if (elem) {
					selectedForm = elem
					return true
				}
		}
	} // End function

function InsertParagraph() {
	foo.document.body.focus();
		if (document.selection.type != "Control") {
			var sel = document.selection.createRange()
			sel.pasteHTML("<p>")
			foo.focus()
		}
	}	
	
// DIVERSE VARIABELEN
	
var imageWin
var propWin
var inserttableWin
var previewWin
var modifytableWin
var insertFormWin
var textFieldWin
var hiddenWin
var buttonWin
var checkboxWin
var radioWin
var charWin
var linkWin
var emailWin
var anchorWin
var selectedTD
var selectedTR
var selectedTBODY
var selectedTable
var selectedImage
var selectedForm
var selectedTextField
var selectedTextArea
var selectedHidden
var selectedbutton
var selectedCheckbox
var selectedRadio
var tableDefault
tableDefault = 1
var editDefault
editDefault = 0
var fileCache
fileCache = 0
var statusMode = ""
var statusBorders = ""
var toggle = "off"
var borderShown = "no"
var fooURL
var reloaded
var justSwitched = false
reloaded = 0

window.onload = doLoad
window.onresize = resizeWin
window.onerror = stopError
var loaded = false

function stopError() {
// alert('stopError');
		return true;
}

function doLoad() {
//Laad het uiteindelijke bestand
		if (editDefault != 1)
			foo.document.designMode = 'On';

		resizeWin()
		if (fileCache == 1) {
			foo.document.location.reload(true)
		}
		
}

function fooLoad() {
//Laad het Iframe
		if (!justSwitched)
		{

		if ((fileCache != 1) && (editDefault == 1)) {
			loaded = true
		}

		if (loaded == true) {
			if (tableDefault != 0) {
				toggleBorders()
			}
			displayUserStyles()
			
			showStatus()
			fooURL = foo.location.href
		}

		if (editDefault == 1) {
			makeEditable()
		}

		loaded = true

		}
		
// NU EVEN DE KLOTE FOUT ER UIT HALEN

foo.document.body.innerHTML = opschonen(foo.document.body.innerHTML);
foo.document.body.focus();		
}

function opschonen(code){
// DOOR SJOERD VAN OOSTEN.
// DIT HAALT DIE RARE CODE VOOR DE LINKS EN PLAATJES WEG. WERKT NOG NIET HELEMAAL FLEX
// alert(code)
code = code.replace('\'http://www.e-sites.nl/','');
code = code.replace('?>','>');
return code
}


function doCommand(cmd) {
//Verkort commando om de exexCommand uit te voeren
		if (isAllowed())
		{
			document.execCommand(cmd)
		}
}

function scrollUp() {
//Script om naar de top van de IFRAME te Scrollen
top.foo.scrollBy(0,0);
}


function resizeWin() {
//Bepaal de hoogte van de IFRAME
		height = 102
		if (Mode == 2)
		{ height = 71
		}
		document.all.foo.height = document.body.clientHeight-height + "px"
		document.all.foo.focus();
	}

	var Mode = "1";

	var toggleWasOn
	var fontChange
	
function SwitchMode() {
// alert('switchMode');
//GA over van WYSIWYG naar Platte HTML
		 if (Mode == "1") {
			if (borderShown == "yes") {
				toggleBorders()
				toggleWasOn = "yes"
			} else {
				toggleWasOn = "no"
			}

			toolbar_full.className = "hide";
			toolbar_code.className = "bevel3";

			// get details to replace back when done
			fontFamily = foo.document.body.style.fontFamily
			fontSize = foo.document.body.style.fontSize
			text = foo.document.body.text
			bgColor = foo.document.body.bgcolor
			background = foo.document.body.background

			// Put HTML in editor
			code = foo.document.documentElement.outerHTML

			re = /&amp;/g
			re2 = /href="http:\/\/www.e-sites.nl/g
			re3 = /src="http:\/\/www.e-sites.nl/g

			replaceHref = 'href="'
			replaceImage = 'src="'
			
			code = code.replace(re,'&')
			code = code.replace(re2,replaceHref)
			code= code.replace(re3,replaceImage)

			foo.document.body.innerText = code

			// nice looking source editor
			foo.document.body.style.fontFamily = "Courier"
			foo.document.body.style.fontSize = "10pt"
			foo.document.body.bgColor = '#FFFFFF';
			foo.document.body.text = '#000000';
			foo.document.body.background = '';
			fontChange = true	
			
			Mode = "2";
		} else {

			loaded = false;
			justSwitched = true
			foo.document.write(foo.document.body.innerText);
			foo.document.close()

			if (fontChange == true) {

				if (fontFamily != "") {
					foo.document.style.fontFamily = fontFamily
				} else {
					foo.document.body.style.removeAttribute("fontFamily")
				}
	
				if (fontSize != "") {
					foo.document.style.fontSize = fontSize
				} else {
					foo.document.body.style.fontSize = ""
				}

				if (bgColor != "")
				{
					foo.document.bgColor = bgColor
				} else {
					foo.document.body.removeAttribute("bgColor")
				}
				
				if (text != "")
				{
					foo.document.text = text
				} else {
					foo.document.body.removeAttribute("text")
				}
				
				if (background != "")
				{
					foo.document.body.background = background
				} else {
					foo.document.body.removeAttribute("background")
				}
			}

			toolbar_full.className = "bevel3";
			toolbar_code.className = "hide";

			Mode = "1";

			if (toggleWasOn == "yes") {
				toggleBorders()
				toggleWasOn = "no"
			}
		}
		resizeWin()
		showStatus()
	}

function SaveHTMLPage() {
alert('Dit venster wordt gesloten');
//Bestand om het uiteindelijk op te slaan en dus alle onnodige code weghalen
		if (Mode == "2") { 
			SwitchMode()
		}
		
		if (borderShown == "yes") {
			toggleBorders()
		}
		
		if (editDefault == 1)
		{
			revertEditable()
		}
		
		var filename = EditorForm.FileName.value
		var incext = EditorForm.FileExt.value
		var position
		var fileext
	

		position = filename.lastIndexOf(".")
		fileext = filename.substring(position+1, filename.length)

		// Check if file type is an include file
		if (fileext == incext) {

		// if it is, then only add the insides cause iframe automatically adds <head><body> tags
		document.EditorForm.EditorHTML.value = foo.document.body.innerHTML
	
		} else {

		// else save the entire doc
		document.EditorForm.EditorHTML.value = foo.document.documentElement.outerHTML;

		}

		window.opener.Composeform.body2.value = foo.document.documentElement.outerHTML;

		// re = /&amp;/g
		// re2 = /href="http:\/\/www.e-sites.nl/g
		//re3 = /src="http:\/\/www.e-sites.nl/g

		//replaceHref = 'href="'
		//replaceImage = 'src="'

		//document.EditorForm.EditorHTML.value = document.EditorForm.EditorHTML.value.replace(re,'&')
		//document.EditorForm.EditorHTML.value = document.EditorForm.EditorHTML.value.replace(re2,replaceHref)
		//document.EditorForm.EditorHTML.value = document.EditorForm.EditorHTML.value.replace(re3,replaceImage)
		//document.EditorForm.EditorHTML.value = replaceIncludes(document.EditorForm.EditorHTML.value)

		// document.EditorForm.submit(); 


		closePopups();
		window.close();
}

function doLink() {
	foo.document.body.focus();
		if (isAllowed())
		{
			if (isSelection()) { 
				var leftPos = (screen.availWidth-700) / 2
				var topPos = (screen.availHeight-500) / 2 
		 		linkWin = window.open('popuplink.php','','width=700,height=500,scrollbars=yes,resizable=yes,titlebar=0,top=' + topPos + ',left=' + leftPos);
			} else
				return
		}
}

function doImage() {
	foo.document.body.focus();
		if (isAllowed())
		{

		if (isImageSelected()) {	 
			var leftPos = (screen.availWidth-500) / 2
			var topPos = (screen.availHeight-400) / 2 
			imageWin = window.open('popupfoto.php','','width=700,height=500,scrollbars=no,resizable=no,titlebar=0,top=' + topPos + ',left=' + leftPos);
		} else {
			var leftPos = (screen.availWidth-700) / 2
			var topPos = (screen.availHeight-500) / 2 
			imageWin = window.open('popupfotoinsert.php','','width=700,height=500,scrollbars=yes,resizable=yes,titlebar=0,top=' + topPos + ',left=' + leftPos);
		}

		}
}

function selectImage(image) {
// alert('selectImage');
//Image functie Selecteer een foto
			document.execCommand("InsertImage",false,image);
}

function setBackgd(image) {
	foo.document.body.focus();
	foo.document.body.background = image
}

function ModifyProperties() {
	foo.document.body.focus();
		var leftPos = (screen.availWidth-500) / 2
		var topPos = (screen.availHeight-550) / 2 
	 	propWin = window.open('popupproperties.php','','width=500,height=550,scrollbars=no,resizable=yes,titlebar=0,top=' + topPos + ',left=' + leftPos);
}

function ShowInsertTable() {
	foo.document.body.focus();
		if (isAllowed())
		{

		var leftPos = (screen.availWidth-500) / 2
		var topPos = (screen.availHeight-400) / 2 
 		inserttableWin = window.open('popuptable.php','','width=500,height=400,scrollbars=no,resizable=no,titlebar=0,top=' + topPos + ',left=' + leftPos);

		}
}

function ShowPreview(source) {
//alert('ShowPreview');
//Open Pop-up met de preview erin

		baseRef = foo.location.href
		ax=baseRef.lastIndexOf('\/')+1;
		if(ax!=-1) baseRef=baseRef.substring(0,ax);

		if (borderShown == "yes") {
			toggleBorders()
			toggleWasOn = "yes"
		} else {
			toggleWasOn = "no"
		}

		if (editDefault ==1)
		{
			revertEditable()
		}

		var previewHTML
		if (source == 1)
		{
			previewHTML = foo.document.body.innerText
		} else {
			previewHTML = foo.document.documentElement.outerHTML
		}

		if (editDefault ==1)
		{
			makeEditable()
		}
		
		if (toggleWasOn == "yes") {
			toggleBorders()
			toggleWasOn = "no"
		}

		var leftPos = (screen.availWidth-780) / 2
		var topPos = (screen.availHeight-580) / 2 
 		previewWin = window.open('','','width=780,height=580,scrollbars=yes,resizable=yes,titlebar=0,top=' + topPos + ',left=' + leftPos);

		previewWin.document.write("<Base href=" + baseRef + ">")
		previewWin.document.write(previewHTML)
		previewWin.document.close()
		
	}

function ModifyTable() {
foo.document.body.focus();
		if (isAllowed())
		{

		if (isTableSelected() || isCursorInTableCell()) {
			var leftPos = (screen.availWidth-500) / 2
			var topPos = (screen.availHeight-400) / 2 
	 		modifytableWin = window.open('popupmodifytable.php','','width=500,height=400,scrollbars=no,resizable=no,titlebar=0,top=' + topPos + ',left=' + leftPos);
		}

		}
}

function ModifyCell() {
foo.document.body.focus();
		if (isAllowed())
		{

		if (isCursorInTableCell()) {
			var leftPos = (screen.availWidth-500) / 2
			var topPos = (screen.availHeight-400) / 2 
	 		modifytableWin = window.open('popupmodifycell.php','','width=500,height=400,scrollbars=no,resizable=no,titlebar=0,top=' + topPos + ',left=' + leftPos);
		}

		}
}

function modifyForm() {
foo.document.body.focus();
		if (isAllowed)
		{

		if (isCursorInForm()) {
			var leftPos = (screen.availWidth-500) / 2
			var topPos = (screen.availHeight-400) / 2 
	 		modifyFormWin = window.open('popupmodifyform.php','','width=500,height=400,scrollbars=no,resizable=no,titlebar=0,top=' + topPos + ',left=' + leftPos);
		}

		}
}

function insertForm() {
foo.document.body.focus();
		if (isAllowed())
		{
			var leftPos = (screen.availWidth-500) / 2
			var topPos = (screen.availHeight-400) / 2 
	 		insertFormWin = window.open('popupform.php','','width=500,height=400,scrollbars=no,resizable=no,titlebar=0,top=' + topPos + ',left=' + leftPos);
		}
}

function InsertChars() {
foo.document.body.focus();
		if (isAllowed())
		{
			var leftPos = (screen.availWidth-500) / 2
			var topPos = (screen.availHeight-400) / 2 
	 		charWin = window.open('popupspecialchar.php','','width=500,height=400,scrollbars=no,resizable=no,titlebar=0,top=' + topPos + ',left=' + leftPos);
		}
}

function doAnchor() {
foo.document.body.focus();
			if (isAllowed())
			{

			var leftPos = (screen.availWidth-500) / 2
			var topPos = (screen.availHeight-400) / 2 
		
			if ((foo.document.selection.type == "Control") && (foo.document.selection.createRange()(0).tagName == "A") && (foo.document.selection.createRange()(0).href == ""))
			{
				anchorWin = window.open('popuparchor.php','','width=500,height=400,scrollbars=no,resizable=no,titlebar=0,top=' + topPos + ',left=' + leftPos);
			} else {
	 			anchorWin = window.open('popuparchor.php','','width=500,height=400,scrollbars=no,resizable=no,titlebar=0,top=' + topPos + ',left=' + leftPos);
			}

			}
}

function isSelection() {
//alert('isSelection');
//Check het type selectie
			if ((foo.document.selection.type == "Text") || (foo.document.selection.type == "Control")) {
				return true;
			} else {
				return false;
			}
	}

function doEmail() {
foo.document.body.focus();
		if (isAllowed())
		{
			if (isSelection()) { 
				var leftPos = (screen.availWidth-500) / 2
				var topPos = (screen.availHeight-400) / 2 
	 			emailWin = window.open('popupemail.php','','width=500,height=400,scrollbars=no,resizable=no,titlebar=0,top=' + topPos + ',left=' + leftPos);
			} else
				return
		}
}

function doTextField() {
foo.document.body.focus();
		if (isAllowed())
		{

		var leftPos = (screen.availWidth-500) / 2
		var topPos = (screen.availHeight-400) / 2 

		if (foo.document.selection.type == "Control") {
			var oControlRange = foo.document.selection.createRange();
			if (oControlRange(0).tagName.toUpperCase() == "INPUT") {
				if ((oControlRange(0).type.toUpperCase() == "TEXT") || (oControlRange(0).type.toUpperCase() == "PASSWORD")) {
					selectedTextField = foo.document.selection.createRange()(0);
					textFieldWin = window.open('popupformtextfield.php','','width=500,height=400,scrollbars=no,resizable=no,titlebar=0,top=' + topPos + ',left=' + leftPos);
				}
				return true;
			}	
		} else {
			textFieldWin = window.open('popupformtextfield.php','','width=500,height=400,scrollbars=no,resizable=no,titlebar=0,top=' + topPos + ',left=' + leftPos);
		}

		}
}

function doHidden() {
foo.document.body.focus();
		if (isAllowed())
		{

		var leftPos = (screen.availWidth-500) / 2
		var topPos = (screen.availHeight-400) / 2 

		if (foo.document.selection.type == "Control") {
			var oControlRange = foo.document.selection.createRange();
			if (oControlRange(0).tagName.toUpperCase() == "INPUT") {
				if (oControlRange(0).type.toUpperCase() == "HIDDEN") {
					selectedHidden = foo.document.selection.createRange()(0);
					hiddenWin = window.open('popupformthidden.php','','width=500,height=400,scrollbars=no,resizable=no,titlebar=0,top=' + topPos + ',left=' + leftPos);
				}
				return true;
			}	
		} else {
			hiddenWin = window.open('popupformhidden.php','','width=500,height=400,scrollbars=no,resizable=no,titlebar=0,top=' + topPos + ',left=' + leftPos);
		}

		}
}

function doTextArea() {
foo.document.body.focus();
		if (isAllowed())
		{

		var leftPos = (screen.availWidth-500) / 2
		var topPos = (screen.availHeight-400) / 2 

		if (foo.document.selection.type == "Control") {
			var oControlRange = foo.document.selection.createRange();
			if (oControlRange(0).tagName.toUpperCase() == "TEXTAREA") {
					selectedTextArea = foo.document.selection.createRange()(0);
					textFieldWin = window.open('popupformtextarea.php','','width=500,height=400,scrollbars=no,resizable=no,titlebar=0,top=' + topPos + ',left=' + leftPos);
				return true;
			}	
		} else {
			textFieldWin = window.open('popupformtextarea.php','','width=500,height=400,scrollbars=no,resizable=no,titlebar=0,top=' + topPos + ',left=' + leftPos);
		}

		}
}

function doButton() {
foo.document.body.focus();
		if (isAllowed())
		{

		var leftPos = (screen.availWidth-500) / 2
		var topPos = (screen.availHeight-400) / 2 

		if (foo.document.selection.type == "Control") {
			var oControlRange = foo.document.selection.createRange();
			if (oControlRange(0).tagName.toUpperCase() == "INPUT") {
				if ((oControlRange(0).type.toUpperCase() == "RESET") || (oControlRange(0).type.toUpperCase() == "SUBMIT") || (oControlRange(0).type.toUpperCase() == "BUTTON")) {
					selectedButton = foo.document.selection.createRange()(0);
					buttonWin = window.open('popupformbutton.php','','width=500,height=400,scrollbars=no,resizable=no,titlebar=0,top=' + topPos + ',left=' + leftPos);
				}
				return true;
			}	
		} else {
			buttonWin = window.open('popupformbutton.php','','width=500,height=400,scrollbars=no,resizable=no,titlebar=0,top=' + topPos + ',left=' + leftPos);
		}

		}
	}

function doCheckbox() {
foo.document.body.focus();
		if (isAllowed())
		{

		var leftPos = (screen.availWidth-500) / 2
		var topPos = (screen.availHeight-400) / 2 

		if (foo.document.selection.type == "Control") {
			var oControlRange = foo.document.selection.createRange();
			if (oControlRange(0).tagName.toUpperCase() == "INPUT") {
				if (oControlRange(0).type.toUpperCase() == "CHECKBOX") {
					selectedCheckbox = foo.document.selection.createRange()(0);
					checkboxWin = window.open('popupformcheckbox.php','','width=500,height=400,scrollbars=no,resizable=no,titlebar=0,top=' + topPos + ',left=' + leftPos);
				}
				return true;
			}	
		} else {
			checkboxWin = window.open('popupformcheckbox.php','','width=500,height=400,scrollbars=no,resizable=no,titlebar=0,top=' + topPos + ',left=' + leftPos);
		}

		}
	}

function doRadio() {
foo.document.body.focus();
		if (isAllowed()) {

		var leftPos = (screen.availWidth-500) / 2
		var topPos = (screen.availHeight-400) / 2 

		if (foo.document.selection.type == "Control") {
			var oControlRange = foo.document.selection.createRange();
			if (oControlRange(0).tagName.toUpperCase() == "INPUT") {
				if (oControlRange(0).type.toUpperCase() == "RADIO") {
					selectedRadio = foo.document.selection.createRange()(0);
					radioWin = window.open('popupformradio.php','','width=500,height=400,scrollbars=no,resizable=no,titlebar=0,top=' + topPos + ',left=' + leftPos);
				}
				return true;
			}	
		} else {
			radioWin = window.open('popupformradio.php','','width=500,height=400,scrollbars=no,resizable=no,titlebar=0,top=' + topPos + ',left=' + leftPos);
		}

		}
}

	
function cancelSave() {
//alert('cancelSave');
//Check bij het stoppen zonder saven
		var saveFile = confirm("Weet u zeker dat u wilt stoppen zonder op te slaan?");
		if (saveFile) {
			closePopups();
			window.close();
		}
		
}

function doTemplate() {
	foo.document.body.focus();
			if (isAllowed())
			{

			var leftPos = (screen.availWidth-500) / 2
			var topPos = (screen.availHeight-400) / 2 
		
			if ((foo.document.selection.type == "Control") && (foo.document.selection.createRange()(0).tagName == "A") && (foo.document.selection.createRange()(0).href == ""))
			{
				anchorWin = window.open('popuptemplate.php','','width=500,height=400,scrollbars=no,resizable=no,titlebar=0,top=' + topPos + ',left=' + leftPos);
			} else {
	 			anchorWin = window.open('popuptemplate','','width=500,height=400,scrollbars=no,resizable=no,titlebar=0,top=' + topPos + ',left=' + leftPos);
			}

			}
}


function closePopups() {
//alert('closePopups');
//Functie om alle pop-ups te sluiten
		if (imageWin) imageWin.close()
		if (propWin) propWin.close()
		if (inserttableWin) inserttableWin.close()
		if (previewWin) previewWin.close()
		if (modifytableWin) modifytableWin.close()
		if (insertFormWin) insertFormWin.close()
		if (textFieldWin) textFieldWin.close()
		if (hiddenWin) hiddenWin.close()
		if (buttonWin) buttonWin.close()
		if (checkboxWin) checkboxWin.close()
		if (radioWin) radioWin.close()
		if (charWin) charWin.close()
		if (linkWin) linkWin.close()
		if (emailWin) emailWin.close()
		if (anchorWin) anchorWin.close()
	}	

function selOn(ctrl){
//XP Style
	ctrl.style.borderColor = '#000000';
	ctrl.style.backgroundColor = '#B5BED6';
	// ctrl.style.cursor = 'mouse';	
}
  
function selOff(ctrl){
	//XP Style
	ctrl.style.borderColor = '#D6D3CE';  
	ctrl.style.backgroundColor = '#D6D3CE';
}
  
function selDown(ctrl){
	//XP Style
	ctrl.style.backgroundColor = '#8492B5';
}
  
function selUp(ctrl){
//XP Style
    ctrl.style.backgroundColor = '#B5BED6';
}
    
function doBold(){
	foo.document.body.focus();
	foo.document.execCommand('bold', false, null);
}

function doItalic(){
	foo.document.body.focus();
	foo.document.execCommand('italic', false, null);
}

function doUnderline(){
	foo.document.body.focus();
	foo.document.execCommand('underline', false, null);
}
  
function doLeft(){
	foo.document.body.focus();
    foo.document.execCommand('justifyleft', false, null);
}

function doCenter(){
	foo.document.body.focus();
	foo.document.execCommand('justifycenter', false, null);
}

function doRight(){
	foo.document.body.focus();
    foo.document.execCommand('justifyright', false, null);
}

function doOrdList(){
	foo.document.body.focus();	
    foo.document.execCommand('insertorderedlist', false, null);
}

function doBulList(){
	foo.document.body.focus();
    foo.document.execCommand('insertunorderedlist', false, null);
}
  
function doForeCol(){
//alert('doForeCol');
//Zet de tekstkleur AANPASSEN!!!!!
    var fCol = prompt('Enter foreground color', '');
    
    if(fCol != null)
      foo.document.execCommand('forecolor', false, fCol);
}

function doBackCol(){
//alert('doBackCol');
//Zet de achtergrond kleur OF WEGHALEN OF AANPASSEN
    var bCol = prompt('Enter background color', '');
    
    if(bCol != null)
      foo.document.execCommand('backcolor', false, bCol);
  }
  
function doRule(){
//alert('doRule');
//WEGHALEN !!!!!
foo.document.body.focus();
foo.document.execCommand('inserthorizontalrule', false, null);
}
