var imgLib;
var fileLib;
var uploadFrame;
var imgLibPath		= '';
var imageLibrary		= 'img.library';
var fileLibrary			= 'file.library';
var library;
var library2;

function wysiwygElement(element,resizable,embedded)
{
	var self = this;
	
	this.htmlText;
	
	this.element = element;
	
	this.textCursor;
	this.textPosition;
	
	this.selectionStart;
	this.selectionEnd;
	this.uploadImages = false;
	
	this.picbox;
	this.urlbox;
	this.IEMode;
	this.range;
	this.lastTimeUpdate = new Date();
	
	this.button = new Array();

	// copy element contents
	this.elementContents = element.innerHTML;
	this.content = element.innerHTML;

	elementHeight = this.element.offsetHeight;
	this.element.style.height = elementHeight + 'px';	

	//removing Element Contents
	this.element.innerHTML = '';

	this.expertMode = false;

	this.aBold = false;			this.aItalics = false;		this.aUnderline = false;
	this.aLineThrough = false;	this.aSubScript = false;	this.aSuperScript = false;

	if(this.element.style.position == '' || this.element.style.position == 'static') {
		this.element.style.position = 'relative';
	}

	this.elementBorder = document.createElement('div');
	this.element.appendChild(this.elementBorder);
	this.elementBorder.style.width = this.element.offsetWidth+'px';
	this.elementBorder.style.height = this.element.offsetHeight+'px';
	this.elementBorder.style.position = 'absolute';
	this.elementBorder.className = 'textEditorBorder';
	
	this.init = function() {
		if(pagePrivileges & 16)
			self.uploadImages = true;

		//Open "Editor" in Window..
		if(typeof(embedded) == 'undefined')
		{
			self.rteWindow = new sitePEWin({close: false});
			self.rteWindow.setHeight(250);
			self.rteWindow.setWidth(800);
		}

		self.buttonBar = document.createElement('div');
		if(typeof(embedded) == 'undefined')
			self.rteWindow.content.appendChild(self.buttonBar);
		else
			self.element.appendChild(self.buttonBar);
		self.buttonBar.className = 'wysiwygButtonBar';
		self.reprintButtonBar();

		tempdummy = document.createElement('div');
		if(typeof(embedded) == 'undefined')
			tempdummy.className = 'rTEdiv';
		else
			tempdummy.className = 'rTEdivEmbedded';
		self.richTextEditor = document.createElement('textarea');
		self.richTextEditor.name = self.element.id;
		
		tempdummy.appendChild(self.richTextEditor);
		
		if(typeof(embedded) == 'undefined') {
			self.rteWindow.content.appendChild(tempdummy);
			self.rteWindow.setTitle('Editor');
		} else {
			self.element.appendChild(tempdummy);
			text = document.createElement('div');
			text.innerHTML = 'Vorschau:';
			self.element.appendChild(text);
			self.element.appendChild(document.createElement('hr'));
		}

		self.richTextEditor.value = self.dounhtml(self.elementContents);

		self.resultArea = document.createElement('div');
		self.resultArea.className = 'resultArea';
		self.element.appendChild(self.resultArea);

		self.richTextEditor.className = 'htmlTextEditorField';
		self.richTextEditor.id = 'rTE';
		
		self.doUpdateResult();
		
		self.element.style.height = '';

		self.evalSelection();
		
		self.richTextEditor.onfocus = self.rTEonfocus;
		self.richTextEditor.onblur = self.rTEonblur;
		self.richTextEditor.onmouseup = self.evalSelection;
		
		self.richTextEditor.blur();
		self.richTextEditor.focus();
	}

	this.reprintButtonBar = function() {
		self.buttonBar.innerHTML = '';

		buttonlables = new Array('', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '' );

		buttonToolTips = new Array(
			'Fett',
			'Kursiv',
			'Unterstrichen',
			'Durchgestrichen',
			'Tiefgestellt',
			'Hochgestellt',
			'Linksbündig',
			'Zentriert',
			'Rechtsbündig',
			'Blocksatz',
			'Schrift größer',
			'Schrift kleiner',
			'Hervorheben',
			'Schriftfarbe',
			'Tabelle einfügen',
			'Link einfügen',
			'Bild einfügen',
			'Datei einfügen'
		); 

		buttonfunctions = new Array(
			self.setBold,
			self.setItalic,
			self.setUnderline,
			self.setLineThrough,
			self.setSubscript,
			self.setSuperscript,
			self.setAlignLeft,
			self.setAlignCenter,
			self.setAlignRight,
			self.setAlignJustify,
			self.increaseSize,
			self.decreaseSize,
			self.setMarkColorTarget,
			self.setFontColorTarget,
			self.insertTable,
			self.openLinkInsertDialog,
			self.openImgInsertDialog,
			self.openFileInsertDialog
		); 

		for(i = 0; i< buttonlables.length; i++){
			self.button[i] = document.createElement('div');
			self.button[i].className = 'button buttonNormal'+i;
			self.button[i].title = buttonToolTips[i];
			self.button[i].onmouseout = new Function('','this.className = \'button buttonNormal'+i+'\'');
			self.button[i].innerHTML = buttonlables[i];
			self.button[i].onclick = buttonfunctions[i];
			self.button[i].onmouseover = new Function('','this.className = \'button buttonMouseover'+i+'\'');
		
			self.buttonBar.appendChild(self.button[i]);
		}
		
		self.expertModeButton = document.createElement('div');
		self.expertModeButton.className = 'expertButton buttonNormalHTML';
		self.expertModeButton.onmouseout = self.getExpertMode;
		self.expertModeButton.innerHTML = '';
		self.expertModeButton.onclick = self.setExpertMode;
		self.expertModeButton.onmouseover = function() { this.className = 'expertButton buttonMouseoverHTML' };
		self.buttonBar.appendChild(self.expertModeButton);
	}

	this.setExpertMode = function() {
		self.expertMode = !self.expertMode;
		self.getExpertMode();
	}

	this.getExpertMode = function() {
		if(self.expertMode)
			self.expertModeButton.className = 'expertButton buttonActiveHTML';
		else
			self.expertModeButton.className = 'expertButton buttonNormalHTML';
	}

	this.setFontColorTarget = function(Event){
		if(window.event)
		{
			ypos=window.event.clientY;
			ypos += document.documentElement.scrollTop;
			xpos=window.event.clientX;
			xpos += document.documentElement.scrollLeft;
		}
		else
		{
			ypos=Event.pageY;
			xpos=Event.pageX;
		}
		
		callerCoordX = xpos;
		callerCoordY = ypos;

		rteCaller = self;
		rteCallerType = 'font';
		openColorChanger();
	}
	
	this.setMarkColorTarget = function(Event){
		if(window.event)
		{
			ypos=window.event.clientY;
			ypos += document.documentElement.scrollTop;
			xpos=window.event.clientX;
			xpos += document.documentElement.scrollLeft;
		}
		else
		{
			ypos=Event.pageY;
			xpos=Event.pageX;
		}
		
		callerCoordX = xpos;
		callerCoordY = ypos;

		rteCaller = self;
		rteCallerType = 'mark';
		openColorChanger();
	}

	this.changeSelection = function(start,end) {
		if(typeof(self.IEMode)!='undefined') {

			start -= self.startTxt.split('\n').length-1;
			end -= self.startTxt.split('\n').length-1;
			end -= self.selTxt.split('\n').length-1;

			range2 = range.duplicate();
			range2.moveToElementText( self.richTextEditor );
			range2.collapse(true);
			range2.moveEnd('character',end);
			range2.moveStart('character',start);
			range.setEndPoint('EndToEnd',range2);
			range.setEndPoint('StartToStart',range2);
			if(start-end == 0)
				range.collapse(true);
			range.select();
		} else {
			self.richTextEditor.selectionStart = start;
			self.richTextEditor.selectionEnd = end;
		}
	}

	this.evalSelection = function(keypressed,shiftKey) {
		self.richTextEditor.focus();

		if(typeof(self.richTextEditor.selectionStart)!='undefined') {
			start	= self.richTextEditor.selectionStart;
			end		= self.richTextEditor.selectionEnd;
			oldEnd = end;
			oldStart = start;
		} else {
			self.range = document.selection.createRange();
			range = self.range.duplicate();
			range2 = range.duplicate();
			range2.moveToElementText( self.richTextEditor );
			range2.setEndPoint( 'EndToEnd', range );
			start = range2.text.length - range.text.length;
			end = start + range.text.length;
			self.IEMode = true;
			oldStart = start; oldEnd = end;
		}
		
		selectedText		= self.richTextEditor.value.substring(start, end);
		textBeforeSelection	= self.richTextEditor.value.substring(0,start);
		textAfterSelection	= self.richTextEditor.value.substring(end);

		if(!self.expertMode) {
			if(textBeforeSelection.lastIndexOf('<') > textBeforeSelection.lastIndexOf('>')){
				start = textBeforeSelection.lastIndexOf('<');
			}
			if(textAfterSelection.indexOf('<') > textAfterSelection.indexOf('>') || (textAfterSelection.indexOf('<') == -1 && textAfterSelection.indexOf('>')!=-1)){
				end = end + textAfterSelection.indexOf('>') +1;
			}

			if(textBeforeSelection.lastIndexOf('&') > textBeforeSelection.lastIndexOf(';')){
				start = textBeforeSelection.lastIndexOf('&');
			}
			if((textAfterSelection.indexOf('&') > textAfterSelection.indexOf(';') || (textAfterSelection.indexOf('&') == -1 && textAfterSelection.indexOf(';')!=-1)) && textBeforeSelection.lastIndexOf('&') > textBeforeSelection.lastIndexOf(';')){
				if(textBeforeSelection.lastIndexOf(' ') < textBeforeSelection.lastIndexOf('&'))
					end = end + textAfterSelection.indexOf(';') +1;
			}
			if(typeof(keypressed)!='undefined' && keypressed == 37 && !shiftKey)
				end = start;
			else if(typeof(keypressed)!='undefined' && (keypressed == 38 || keypressed==39 || keypressed ==40) && !shiftKey)
				start = end;
		}

		selectedText		= self.richTextEditor.value.substring(start, end);
		textBeforeSelection	= self.richTextEditor.value.substring(0,start);
		textAfterSelection	= self.richTextEditor.value.substring(end);
		
		self.selTxt = selectedText;
		self.startTxt = textBeforeSelection;
		self.endTxt = textAfterSelection;

		if(start!=oldStart || end!=oldEnd) {
			self.changeSelection(start,end);
		}

		self.start = start;
		self.end = end;

		tests = new Array(
			new Array('<b>','</b>','aBold',self.button[0]),
			new Array('<i>','</i>','aItalics',self.button[1]),
			new Array('<u>','</u>','aUnderline',self.button[2]),
			new Array('<span style="text-decoration:line-through;">','</span>','aLineThrough',self.button[3]),
			new Array('<sub>','</sub>','aSubScript',self.button[4]),
			new Array('<sup>','</sup>','aSuperScript',self.button[5])
		);
		
		for(t in tests){
			if(!self.expertMode) {
				if(!self.find(selectedText,tests[t][0]) && !self.find(selectedText,tests[t][1]) && textBeforeSelection.lastIndexOf(tests[t][0]) > textBeforeSelection.lastIndexOf(tests[t][1])){
					self[tests[t][2]] = true;
					tests[t][3].className = 'button buttonActive'+t;
					tests[t][3].onmouseout = new Function('','this.className = \'button buttonActive'+t+'\'');
				} else {
					self[tests[t][2]] = false;
					tests[t][3].className = 'button buttonNormal'+t;
					tests[t][3].onmouseout = new Function('','this.className = \'button buttonNormal'+t+'\'');
				}
			}
			else {
				self[tests[t][2]] = false;
				tests[t][3].className = 'button buttonNormal'+t;
				tests[t][3].onmouseout = new Function('','this.className = \'button buttonNormal'+t+'\'');
			}
		}
	}

	this.changeColorStyle = function(style,cValue) {
		self.richTextEditor.focus();
		selectedText = self.selTxt;
		textBefore = self.startTxt;
		textAfter = self.endTxt;
		
		start = self.start;
		end = self.end;

		styleRegExp = new RegExp('^((?:\n|\r|\s|.)*?)<span style="'+style+': ([\/a-zA-Z0-9# _.!~*\'(),?:;@&=+$-]*?)">((?:\n|\r|\s|.)*?)</span>((?:\n|\r|\s|.)*?)$');
		if(sizedText = styleRegExp.exec(selectedText))
			selectedText = sizedText[1]+sizedText[3]+sizedText[4];

		if(cValue == null) {
			databefore = '';
			dataafter = '';
		}
		else {
			databefore = '<span style="'+style+': #'+cValue+'">';
			dataafter = '</span>';
		}

		self.richTextEditor.value = textBefore + databefore + selectedText + dataafter + textAfter;
		end = start + databefore.length + selectedText.length + dataafter.length;
		self.changeSelection(start,end);
		self.evalSelection();
		self.richTextEditor.focus();
	}
	
	this.changeFontSize = function(direction){
		self.richTextEditor.focus();
		if (typeof(self.richTextEditor.selectionStart) == 'undefined')
			range = document.selection.createRange();
		selectedText = self.selTxt;
		textBefore = self.startTxt;
		textAfter = self.endTxt;
		
		start = self.start;
		end = self.end;

		fontSizeRegExp = /^((?:\n|\r|\s|.)*?)<span style="font-size: ([0-9]{1,2})px;">((?:\n|\r|\s|.)*?)<\/span>((?:\n|\r|\s|.)*?)$/;

		if(sizedText = fontSizeRegExp.exec(selectedText)) {
			oldSize = sizedText[2];
			selectedText = sizedText[1]+sizedText[3]+sizedText[4];
			if(direction==1)
				newSize = oldSize*1+4;
			else
				newSize = oldSize-4;
		}
		else {
			if(direction==1)
				newSize = 20;
			else
				newSize = 12;
		}

		if(newSize < 0)
			newSize = 0;
		if(newSize > 96)
			newSize = 96;

		if(newSize == 16) {
			databefore = '';
			dataafter = '';
		}
		else {
			databefore = '<span style="font-size: '+newSize+'px;">';
			dataafter = '</span>';
		}

		self.richTextEditor.value = textBefore + databefore + selectedText + dataafter + textAfter;
		end = start + databefore.length + selectedText.length + dataafter.length;
		self.changeSelection(start,end);
		self.richTextEditor.focus();
		self.evalSelection();
	}
	
	/*FormatFunctions*/ {
		this.changeFontColor = function(color){ if(color == 'default')color = null;self.changeColorStyle('color',color);self.updateResult(); }
		this.changeMarkColor = function(color){ if(color == 'default')color = null;self.changeColorStyle('background-color',color);self.updateResult(); }
		this.increaseSize = function(){ self.changeFontSize(1); self.updateResult(); }
		this.decreaseSize = function(){ self.changeFontSize(-1); self.updateResult(); }
		this.insertTable = function(){ self.insertData('[table]','[/table]',-1); self.updateResult(); }
		this.setAlignLeft = function(){ self.insertData('<div style="text-align: left;">','</div>',1); self.updateResult(); }
		this.setAlignCenter = function(){ self.insertData('<div style="text-align: center;">','</div>',1); self.updateResult(); }
		this.setAlignRight = function(){ self.insertData('<div style="text-align: right;">','</div>',1); self.updateResult(); }
		this.setAlignJustify = function(){ self.insertData('<div style="text-align: justify;">','</div>',1); self.updateResult(); }

		this.setBold = function(){ if(self.aBold == false) { self.insertData('<b>','</b>',1); } else { self.insertData('</b>','<b>',1); } self.updateResult(); }
		this.setItalic = function(){ if(self.aItalics == false) { self.insertData('<i>','</i>',1);} else { self.insertData('</i>','<i>',1); } self.updateResult(); }
		this.setUnderline = function(){ if(self.aUnderline == false) {  self.insertData('<u>','</u>',1);} else { self.insertData('</u>','<u>',1); } self.updateResult(); }
		this.setSubscript = function(){ if(self.aSubScript == false) {  self.insertData('<sub>','</sub>',1);} else { self.insertData('</sub>','<sub>',1); } self.updateResult(); }
		this.setSuperscript = function(){ if(self.aSuperScript == false) {  self.insertData('<sup>','</sup>',1);} else { self.insertData('</sup>','<sup>',1); } self.updateResult(); }
		this.setLineThrough = function(){ if(self.aLineThrough == false) {  self.insertData('<span style="text-decoration:line-through;">','</span>',1);} else { self.insertData('</span>','<span style="text-decoration:line-through;">'); } self.updateResult(); }
	}

	this.rTEonfocus = function(){
		document.onkeydown = self.testSpecialKeys;
		document.onkeyup = self.monitorCursorMovement;
		document.onkeypress = self.monitorKeyPress;
	}

	this.rTEonblur = function(){
		document.onkeyup = function () { return; };
		document.onkeypress = function() { return; };
	}
	
	this.monitorKeyPress = function(Ereignis) {
		if(!self.expertMode && window.opera){ // Opera seems to remap keys for this event, thus executing them nonetheless...
			if (!Ereignis)
				Ereignis = window.event;
			if (Ereignis.which)
				key = Ereignis.which;
			else if (Ereignis.keyCode)
				key = Ereignis.keyCode;
				
			if(key == 9)
				return false;

			if((key == 226 && !window.opera) || (window.opera && key == 188))
				return false;

			if(key == 54 || key==38)
				return false;

			if(key==8)	// Backspace
				return self.deletePrevObject(false);
			if(key==46)	// Entf-Taste
				return self.deleteNextObject(false);
			
			if((key==60 || key==62))
				return false;
		}
	}
	
	this.testSpecialKeys = function(Ereignis) {
		if (!Ereignis)
			Ereignis = window.event;
		if (Ereignis.which)
			key = Ereignis.which;
		else if (Ereignis.keyCode)
			key = Ereignis.keyCode;

		if(key == 13 && self.linkInsertDialog.is_closed == false){
			self.insertURL();
			return false;
		}
		if(key == 13 && self.picInsertDialog.is_closed == false){
			self.insertPIC();
			return false;
		}
		if(key == 27 && self.linkInsertDialog.is_closed == false){
			self.urlbox.value='';
			self.insertURL();
			return false;
		}
		if(key == 27 && self.picInsertDialog.is_closed == false){
			self.picbox.value='';
			self.insertPIC();
			return false;
		}

		if(self.picInsertDialog.is_closed == false || self.linkInsertDialog.is_closed == false)
			return;

		if(key == 9) {
			self.insertData("\t");
			return false;
		}

		if(((key == 226 && !window.opera) || (window.opera && key == 188)) && !self.expertMode) {
			if(Ereignis.shiftKey)
				self.insertData("&gt;");
			else if(Ereignis.ctrlKey && Ereignis.altKey)
				self.insertData("|");
			else
				self.insertData("&lt;");
			return false;
		}

		if(key == 109 && !self.expertMode) {
			if(!Ereignis.shiftKey && !Ereignis.ctrlKey && !Ereignis.altKey) {
				self.insertData("-");
				return false;
			}
		}

		if(key == 54 && !self.expertMode) {
			if(Ereignis.shiftKey) {
				self.insertData("&amp;");
				return false;
			}
		}

		if(key==8 && !self.expertMode){		// Backspace
			return self.deletePrevObject();
		}
		if(key==46 && !self.expertMode){	// Entf-Taste
			return self.deleteNextObject();
		}
		
		if(Ereignis.shiftKey && Ereignis.ctrlKey) {
			if(key==70){
				self.setBold();
				return false;
			}
			if(key==85){
				self.setUnderline();
				return false;
			}
			if(key==75){
				self.setItalic();
				return false;
			}
		}
	}
	
	this.deleteEmptyFormats = function() {
		formats = new Array(
			new Array('<b>','</b>'),
			new Array('<i>','</i>'),
			new Array('<u>','</u>'),
			new Array('<span style="text-decoration:line-through;">','</span>'),
			new Array('<sub>','</sub>'),
			new Array('<sup>','</sup>')
		);
		if(typeof(self.richTextEditor.selectionStart)!='undefined') {
			start	= self.richTextEditor.selectionStart;
			end		= self.richTextEditor.selectionEnd;
			oldStart = start; oldEnd = end;
		} else {
			self.range = document.selection.createRange();
			range = self.range.duplicate();
			range2 = range.duplicate();
			range2.moveToElementText( self.richTextEditor );
			range2.setEndPoint( 'EndToEnd', range );
			start = range2.text.length - range.text.length;
			end = start + range.text.length;
			self.IEMode = true;
			oldStart = start; oldEnd = end;
		}

		textbefore = self.richTextEditor.value.substring(0, start);
		textafter = self.richTextEditor.value.substring(end);

		for(f in formats) {
			textbefore = textbefore.replace(new RegExp(formats[f][0]+formats[f][1],'g'),'');
			textafter = textafter.replace(new RegExp(formats[f][0]+formats[f][1],'g'),'');
		}
		
		cleanUpRoutine = true;
		
		while(cleanUpRoutine == true) {
			cleanUpRoutine = false;
			for(f in formats) {
				if(textbefore.search(new RegExp(formats[f][0]+'$'))!=-1 && textafter.search(new RegExp('^'+formats[f][1]))!=-1) {
					textbefore = textbefore.replace(new RegExp(formats[f][0]+'$'),'');
					textafter = textafter.replace(new RegExp('^'+formats[f][1]),'');
					cleanUpRoutine = true;
				}
			}
		}
		
		start = textbefore.length;
		end = start;
		
		if(start==oldStart && end==oldEnd)
			return;
		
		self.richTextEditor.value = textbefore + textafter;
		self.changeSelection(start,end);
		self.evalSelection();
	}
	
	this.deletePrevObject = function(x){
		if(typeof(x)=='undefined')
			doit=true;
		else
			doit=x;
	
		self.evalSelection();
		selectedText = self.selTxt;
		textBefore = self.startTxt;
		textAfter = self.endTxt;
		
		start = self.start;
		end = self.end;

		if(start != end)
			return;
		//Get Last Charachter of Text before the cursor
		lastChar = self.richTextEditor.value.substring(start-1,start);
		if(lastChar == '>') {
			if(self.richTextEditor.value.substring(start-2,start-1) == '/' && doit==true){
				maxExtract = self.richTextEditor.value.substring(0, start).lastIndexOf('<');
				tempstring = self.richTextEditor.value.substring(0, maxExtract);
				self.richTextEditor.value = tempstring + self.richTextEditor.value.substring(start);
				start = tempstring.length;
				end = start;
				self.changeSelection(start,end);
				return false;
			} else
				return false;
		}
		else if(lastChar == ';') {
			if(doit==true) {
				tempstring = self.richTextEditor.value.substring(0, start).replace(/&[#1-9a-zA-Z]+;$/,'');
				self.richTextEditor.value = tempstring + self.richTextEditor.value.substring(start);
				start = tempstring.length;
				end = start;
				self.changeSelection(start,end);
			}
			return false;
		}
		return;
	}
	
	this.deleteNextObject = function(){
		if(typeof(x)=='undefined')
			doit=true;
		else
			doit=x;

		selectedText = self.selTxt;
		textBefore = self.startTxt;
		textAfter = self.endTxt;
		
		start = self.start;
		end = self.end;
		
		if(start != end)
			return;
		
		//Get First Charachter of Text after the cursor
		firstChar = self.richTextEditor.value.substring(end,end+1);
		if(firstChar == '<') {
			if(doit==true) {
				self.richTextEditor.value = self.richTextEditor.value.substring(0, end) + self.richTextEditor.value.substring(end).replace(/^<(.*?)\/>/,'');
				self.changeSelection(start,end);
			}
			return false;
		}
		else if(firstChar == '&') {
			if(doit==true) {
				self.richTextEditor.value = self.richTextEditor.value.substring(0, end) + self.richTextEditor.value.substring(end).replace(/^&[#1-9a-zA-Z]+;/,'');
				self.changeSelection(start,end);
			}
			return false;
		}
		
		return;
	}
	
	this.monitorCursorMovement = function(Ereignis){
		if (!Ereignis)
			Ereignis = window.event;
		if (Ereignis.which)
			key = Ereignis.which;
		else if (Ereignis.keyCode)
			key = Ereignis.keyCode;
		self.evalSelection(key,Ereignis.shiftKey);
			
		if(!self.expertMode){
			if(key==8 || key==46){		// Backspace && Entf
				self.deleteEmptyFormats();
			}
		}

		self.updateResult();
	}
	
	this.find = function(string,data){
		if(string.search(new RegExp(data.replace(/\[/g,'\\[').replace(/\]/g,'\\]'))) != -1)
			return true;
		return false;
	}
	
	this.insertData = function (databefore,dataafter,codeCleanUp) {
		if(typeof(dataafter)=='undefined')
			dataafter = '';
		self.richTextEditor.focus();

		if (typeof(self.richTextEditor.selectionStart) == 'undefined')
			range = document.selection.createRange();
		selectedText = self.selTxt;
		textBefore = self.startTxt;
		textAfter = self.endTxt;
		
		start = self.start;
		end = self.end;

		if(typeof(codeCleanUp)!='undefined' && codeCleanUp == 1) {
			if(self.find(selectedText,databefore) && self.find(selectedText,dataafter)) {
				replace = new RegExp(databefore.replace(/\[/,'\\[').replace(/\]/,'\\]')+"((?:\n|\r|\s|.)*)"+dataafter.replace(/\[/,'\\[').replace(/\]/,'\\]'),"g");
				selectedText = selectedText.replace(replace,'$1');
				databefore = '';
				dataafter = '';
			}
		}
		else if(typeof(codeCleanUp)!='undefined')
		{
			replace1 = new RegExp(databefore.replace(/\[/,'\\[').replace(/\]/,'\\]'),"g");
			replace2 = new RegExp(dataafter.replace(/\[/,'\\[').replace(/\]/,'\\]'),"g");
			selectedText = selectedText.replace(replace1,'');
			selectedText = selectedText.replace(replace2,'');
		}
		
		if(typeof(dataafter)!='undefined' && selectedText.length > 0 && (typeof(codeCleanUp)=='undefined' || codeCleanUp != -1)) {
			selectedText = selectedText.replace(/\t/g,dataafter.replace(/\[/,'\\[').replace(/\]/,'\\]')+"\t"+databefore.replace(/\[/,'\\[').replace(/\]/,'\\]'))
			selectedText.replace(new RegExp(databefore.replace(/\[/,'\\[').replace(/\]/,'\\]')+dataafter.replace(/\[/,'\\[').replace(/\]/,'\\]'),'g'),'');
			selectedText.replace(new RegExp(dataafter.replace(/\[/,'\\[').replace(/\]/,'\\]')+databefore.replace(/\[/,'\\[').replace(/\]/,'\\]'),'g'),'');
		}
		
		if(selectedText.length == 0 && typeof(self.IEMode)!='undefined') {
			self.range.text = databefore+dataafter;
			self.range.collapse(true);
			return;
		}
		
		if(textBefore.match(/--$/) && databefore == '&gt;') {
			databefore = '&rarr;';
			textBefore = textBefore.replace(/--$/,'');
			start -= 2;
		}
		
		if(textBefore.match(/&lt;-$/) && databefore == '-') {
			databefore = '&larr;';
			textBefore = textBefore.replace(/&lt;-$/,'');
			start -= 5;
		}
		
		self.richTextEditor.value = textBefore + databefore + selectedText + dataafter + textAfter;

		

		/* Anpassen der Cursorposition */
		if (selectedText.length == 0) {
			start = start + databefore.length;
			end = start;
		} else {
			end = start + databefore.length + selectedText.length + dataafter.length;
		}

		self.changeSelection(start,end);
		self.richTextEditor.focus();
		self.evalSelection();
		self.doUpdateResult();
	}
	
	this.updateResult = function(Ereignis) {
		window.setTimeout(self.timeUpdateResult,300);
		self.lastTimeUpdate = new Date();
		elementChanges[element.id.replace(/^id/,'')] = self.richTextEditor.value;
	}
	
	this.timeUpdateResult = function() {
		tempTime = new Date();
		if(tempTime.getTime() - self.lastTimeUpdate.getTime() >= 250)
			self.doUpdateResult();
	}

	this.doUpdateResult = function(){
		self.resultArea.innerHTML = self.htmlupdate(self.richTextEditor.value);
		elementChanges[element.id.replace(/^id/,'')] = self.richTextEditor.value;
		//self.updateBorders();
	}
	
	this.htmlupdate = function(text){
		newtext = text;
	
		tablesearch = /\[table([-%:=a-zA-Z0-9\s";]*?)\]((\n|\r|\s|.)*?)\[\/table\]/g;
		while(tables = tablesearch.exec(newtext))
		{
			//TabellenInhalt sollte in Index 2 gespeichert sein
			tables[2] = tables[2].replace(/^\n/,"");
			tables[2] = tables[2].replace(/\n$/,"");
			rows = tables[2].split("\n");
			for(i = 0; i < rows.length; i++)
				rows[i] = rows[i].split("\t");
			maxcols = 0;
			for(i = 0; i < rows.length; i++){
				if(rows[i].length > maxcols)
					maxcols = rows[i].length;
			}
			for(i = 0; i < rows.length; i++){
				if(rows[i].length < maxcols){
					for(e = 0; e < maxcols; e++){
						if(typeof(rows[i][e]) == 'undefined')
							rows[i][e] = '';
					}
				}
			}
			
			for(i = 0; i < rows.length; i++){
				rows[i] = rows[i].join("\t");
				rows[i] = rows[i].replace(/\t/g,'</td><td>');
			}
			table = rows.join("\n");
			table = table.replace(/\n/g,"</td></tr><tr><td>");
			table = '<tr><td>' + table + '</td></tr>';
			newtext = newtext.replace(/\[table([-%:=a-zA-Z0-9\s";]*?)\]((\n|\r|\s|.)*?)\[\/table\]/,'<table'+tables[1]+'>'+table+'</table>');
		}

		newtext = newtext.replace(/\n/g,'<br />');
		newtext = newtext.replace(/\r/g,'');

		do {
			temptext = newtext;
			newtext = newtext.replace(/\[list\](.*?)\[\/list\]/gi,'<ul>$1</ul>');
			newtext = newtext.replace(/\[\*\](.*?)\[\*\]/gi,'<li>$1</li>[*]');
			newtext = newtext.replace(/\[\*\](.*?)<\/ul>/gi,'<li>$1</li></ul>');
			newtext = newtext.replace(/<li>/gi,'</li><li>');
			newtext = newtext.replace(/<\/li><\/li>/gi,'</li>');
			newtext = newtext.replace(/<br \/><\/li>/gi,'</li>');
			newtext = newtext.replace(/<ul><br \/>/gi,'<ul>');
			newtext = newtext.replace(/<ul><\/li>/gi,'<ul>');
		} while (temptext != newtext);
		
		do {
			temptext = newtext;
			newtext = newtext.replace(/\[quote\](.*?)\[\/quote\]/gi,'<blockquote><div>$1</div></blockquote>');
			newtext = newtext.replace(/\[quote=(.*?)\](.*?)\[\/quote\]/gi,'<blockquote><div><cite>$1 schrieb:</cite>$2</div></blockquote>');
		} while (temptext != newtext);

		return newtext;
	}

	this.dounhtml = function(text){
		newtext = text;
		elementsearch = /<((?:\n|\r|\s|.)*?)>/g;
		while(elmnt = elementsearch.exec(newtext)) //Convert Tags to Lower Case (IE)
		{
			elmnt[1] = elmnt[1].toLowerCase();
			newtext = newtext.replace(new RegExp('<'+elmnt[1],'ig'),'<'+elmnt[1]);
		}
		elementsearch = /<\/((?:\n|\r|\s|.)*?)>/g;
		while(elmnt = elementsearch.exec(newtext)) //Convert Tags to Lower Case (IE)
		{
			elmnt[1] = elmnt[1].toLowerCase();
			newtext = newtext.replace(new RegExp('</'+elmnt[1],'ig'),'</'+elmnt[1]);
		}
		newtext = newtext.replace(/<br>\n/g,"<br>");
		newtext = newtext.replace(/\n/g,"");
		newtext = newtext.replace(/\r/g,"");

		// Make Browser-behaviour XHTML-Compatible for empty elements (like <br>)
		newtext = newtext.replace(/<img(.*?)>/g,"<img$1 />");
		
		// UnForm Table
		newtext = newtext.replace(/<table([-%:=a-zA-Z0-9\s";]*?)><tbody><tr><td>((\n|\r|\s|.)*?)<\/td><\/tr><\/tbody><\/table>/g,'[table$1]$2[/table]');
		newtext = newtext.replace(/<\/td><\/tr><tr><td>/g,"\n");
		newtext = newtext.replace(/<\/td><td>/g,'\t');

		do {
			temptext = newtext;
			newtext = newtext.replace(/<\/li><li>/gi,'[*]');
			newtext = newtext.replace(/<li>(.*?)<\/li><\/ul>/gi,'[*]$1</ul>');
			newtext = newtext.replace(/<li>(.*?)<\/li>\[\*\]/gi,'[*]$1[*]');
			newtext = newtext.replace(/<ul>(.*?)<\/ul>/gi,'[list]$1[/list]');
		} while (temptext != newtext);

		do {
			temptext = newtext;
			newtext = newtext.replace(/<blockquote><div><cite>(.*?) schrieb:<\/cite>(.*?)<\/div><\/blockquote>/gi,'[quote=$1]$2[/quote]');
			newtext = newtext.replace(/<blockquote><div>(.*?)<\/div><\/blockquote>/gi,'[quote]$1[/quote]');
		} while (temptext != newtext);

		newtext = newtext.replace(/<br>/g,"\n");

		return newtext;
	}
	
	this.unInit = function(){
		self.rteWindow.closeWin();
		self.rteWindow.destroy();
	}

	this.unWysiwyg = function(){
		content = self.richTextEditor.value;
		self.rteWindow.closeWin();
		self.rteWindow.destroy();
		if(content.length == 0)
			return false;
		else
			self.element.innerHTML = self.htmlupdate(content);
	}

	this.updateBorders = function(){
		height = self.buttonBar.offsetHeight + self.richTextEditor.offsetHeight + self.resultArea.offsetHeight +2;
		width = self.resultArea.offsetWidth +2;
	
		self.elementBorder.style.width = width+'px';
		self.elementBorder.style.height = height+'px';
	}
	//this.debugWindow = new sitePEWin();
	//this.debugWindow.setTitle('Debug');

	this.picInsertDialog = new sitePEWin({resizable: false, minimize: false, setontop: false, enlarge: false});
	this.picInsertDialog.setTitle('Bild einf&uuml;gen');
	this.picInsertDialog.setCSSClass('insertPictureDialog');
	this.picInsertDialog.setWinIcon(pic_path+'add_image.png');
	this.picInsertDialog.closeWin();

	this.fileInsertDialog = new sitePEWin({resizable: false, minimize: false, setontop: false, enlarge: false});
	this.fileInsertDialog.setTitle('Datei einf&uuml;gen');
	this.fileInsertDialog.setCSSClass('insertFileDialog');
	this.fileInsertDialog.setWinIcon(pic_path+'add_file.png');
	this.fileInsertDialog.closeWin();

	this.openFileInsertDialog = function() {
		bodyEle = document.getElementsByTagName('body')[0];
		
		self.richTextEditor.focus();
 		selectedText = self.selTxt;
		textBefore = self.startTxt;
		textAfter = self.endTxt;
		
		start = self.start;
		end = self.end;

		formDialog = '<div><table cellpadding="0" cellspacing="0">';
		formDialog += '<tr><td class="description">Adresse:</td><td><input type="text" value="" onclick="this.focus();" id="filebox" /></td></tr>';
		formDialog += '<tr><td class="description">oder aus Bibliothek</td><td><input type="button" value="Durchsuchen..." id="filelibbutton" onclick="startFileLib();" /></td></tr>';
		formDialog += '</table>';
		
		formDialog += '<div class="filenamediv"><span class="description">Name:</span><input type="text" value="" onclick="this.focus();" id="filenamebox" /></div>';
		formDialog += '<br />';
		formDialog += '<input type="button" value="OK" id="FILEOKB" /></div>';
		
		self.fileInsertDialog.setContent(formDialog);
		self.fileInsertDialog.openWin();
		self.fileInsertDialog.toTop();

		self.okbutton = document.getElementById('FILEOKB');
		self.okbutton.onclick = self.insertFILE;

		rteCaller = self;
		document.onkeydown = self.testSpecialKeys;
	}

	this.openImgInsertDialog = function() {
		bodyEle = document.getElementsByTagName('body')[0];
		
		self.richTextEditor.focus();
		selectedText = self.selTxt;
		textBefore = self.startTxt;
		textAfter = self.endTxt;
		
		start = self.start;
		end = self.end;

		// OK, which styles do we actually need?
		// 1. Float: left/Right
		// 2. Width
		// 3. Height
		// 4. border: width style color
		// 5. margin
		// 6. padding
		// ----
		
		self.styleobj = new JSStyleObject();
		picurl = '';
		
		//Examine Selected Text
		imgselector = /<img src="([\/a-zA-Z0-9_.!~*'(),?:@&=+$-]*?)" alt="([\/a-zA-Z0-9#_.!~*'(),?:@&=+$-]*?)" \/>/;
		imgstyleselector = /<img src="([\/a-zA-Z0-9_.!~*'(),?:@&=+$-]*?)" style="([\/a-zA-Z0-9# _.!~*'(),?:;@&=+$-]*?)" alt="([\/a-zA-Z0-9_.!~*'(),?:@&=+$-]*?)" \/>/;
		if(imgdata = imgselector.exec(selectedText)) {
			picurl = imgdata[1];
		}
		if(imgdata = imgstyleselector.exec(selectedText)) {
			picurl = imgdata[1];
			
			styles = imgdata[2].split(';');
			for(s in styles) {
				if(styles[s]=='') continue; // Skip Empty rules
				rule = styles[s].split(':');
				rule[0] = trim(rule[0]); // Remove Leading/Trailing Spaces
				rule[1] = trim(rule[1]); // Remove Leading/Trailing Spaces
				self.styleobj[rule[0]] = rule[1];
			}
		}
		
		formDialog = '<table cellpadding="0" cellspacing="0">';
		formDialog += '<tr class="picDiag0"><td class="description">Adresse:</td><td><input type="text" value="'+picurl+'" onclick="this.focus();" id="picbox" /></td></tr>';
		formDialog += '<tr class="picDiag1"><td class="description">oder aus Galerie</td><td><input type="button" value="Durchsuchen..." id="imglibbutton" onclick="startImgLib();" /></td></tr>';
		formDialog += '</table>';
		
		// Bild Hoehe
		formDialog += '<table cellpadding="0" cellspacing="0">';
		formDialog += '<tr class="picDiag2"><td class="description">H&ouml;he:</td><td><input type="text" onclick="this.focus();" value="'+(self.styleobj.height == '' ? '' : self.styleobj.height.replace(/px/,''))+'" id="picheight" />px</td></tr>';
		// Bild Breite
		formDialog += '<tr class="picDiag3"><td class="description">Breite:</td><td><input type="text" onclick="this.focus();" value="'+(self.styleobj.width == '' ? '' : self.styleobj.width.replace(/px/,''))+'" id="picwidth" />px</td></tr>';
		formDialog += '</table>';
		// Bild Aussenabstand
		formDialog += '<table cellpadding="0" cellspacing="0">';
		formDialog += '<tr class="picDiag4"><td class="description">Au&szlig;enabstand:</td><td><input type="text" onclick="this.focus();" value="'+(self.styleobj.margin == '' ? '' : self.styleobj.margin.replace(/px/,''))+'" id="picmargin" />px</td></tr>';
		// Bild-Umlauf
		formDialog += '<tr class="picDiag5"><td class="description">Textumlauf:</td><td><select id="picfloat">';
			formDialog += '<option value=""'+(self.styleobj.float == '' ? ' selected="selected"' : '')+'>Kein</option>';
			formDialog += '<option value="left"'+(self.styleobj.float == 'left' ? ' selected="selected"' : '')+'>Rechts (Bild linksb&uuml;ndig)</option>';
			formDialog += '<option value="right"'+(self.styleobj.float == 'right' ? ' selected="selected"' : '')+'>Links (Bild rechtsb&uuml;ndig)</option>';
		formDialog += '</select></td></tr>';
		formDialog += '</table>';
		// Bild-Rahmen
		PicBorder = self.styleobj.border.split(" ");
		borderWidth = PicBorder[0];
		borderType = PicBorder[1];
		delete PicBorder[0];
		delete PicBorder[1];
		borderColor = PicBorder.join(" ");
		formDialog += '<table cellpadding="0" cellspacing="0">';
			formDialog += '<tr class="picDiag6"><td colspan="2" class="description">Rahmen:</td></tr>';
			formDialog += '<tr class="picDiag7"><td class="description">Breite:</td><td><input onclick="this.focus();" type="text" value="'+(borderWidth == '' ? '' : borderWidth.replace(/px/,''))+'" id="picborderwidth" />px</td></tr>';
			formDialog += '<tr class="picDiag8"><td class="description">Typ:</td><td><select id="picbordertype">';
				formDialog +='<option value="solid"'+(borderType=='solid' ? ' selected="selected"' : '')+'>Durchgezogen</option>';
				formDialog +='<option value="dotted"'+(borderType=='dotted' ? ' selected="selected"' : '')+'>Gepunktet</option>';
				formDialog +='<option value="dashed"'+(borderType=='dashed' ? ' selected="selected"' : '')+'>Gestrichelt</option>';
				formDialog +='<option value="double"'+(borderType=='double' ? ' selected="selected"' : '')+'>Doppelt</option>';
				formDialog +='<option value="inset"'+(borderType=='inset' ? ' selected="selected"' : '')+'>Durchgezogen, Tiefergesetzt</option>';
				formDialog +='<option value="outset"'+(borderType=='outset' ? ' selected="selected"' : '')+'>Durchgezogen, H&ouml;hergesetzt</option>';
				formDialog +='<option value="ridge"'+(borderType=='ridge' ? ' selected="selected"' : '')+'>Durchgezogen, Vorstehend</option>';
				formDialog +='<option value="groove"'+(borderType=='groove' ? ' selected="selected"' : '')+'>Durchgezogen, Eingeritzt</option>';
			formDialog += '</select></td></tr>';
			formDialog += '<tr class="picDiag9"><td class="description">Farbe:</td><td><input type="hidden" value="'+(borderWidth == '' ? '' : borderColor)+'" id="picbordercolor" />';
			formDialog += '<div id="bordercolorselector" style="background-color: '+(borderColor ? borderColor : 'transparent')+';">&nbsp;</div></td></tr>';
		formDialog += '</table>';
		
		formDialog += '<input type="button" value="OK" id="PICOKB" /></div>';

		self.picInsertDialog.setContent(formDialog);
		self.picInsertDialog.openWin();
		self.picInsertDialog.toTop();

		self.picbox = document.getElementById('picbox');
		self.picbox.focus();
		self.okbutton = document.getElementById('PICOKB');
		self.okbutton.onclick = self.insertPIC;

		self.bordercolorselector = document.getElementById('bordercolorselector');
		self.bordercolorselector.onclick = function(Event) {
			if(window.event)
			{
				ypos=window.event.clientY;
				ypos += document.documentElement.scrollTop;
				xpos=window.event.clientX;
				xpos += document.documentElement.scrollLeft;
			}
			else
			{
				ypos=Event.pageY;
				xpos=Event.pageX;
			}
			
			callerCoordX = xpos;
			callerCoordY = ypos;

			rteCaller = self;
			rteCallerType = 'border';
			openColorChanger();
		}
		rteCaller = self;
		document.onkeydown = self.testSpecialKeys;
	}
	
	this.setBorderColor = function(color) {
		if(color == 'default')
			color = null;
		if(color == null) {
			self.bordercolorselector.style.backgroundColor = 'transparent';
			document.getElementById('picbordercolor').value = '';
		} else {
			self.bordercolorselector.style.backgroundColor = '#'+color;
			document.getElementById('picbordercolor').value = '#'+color;
		}
	}

	this.linkInsertDialog = new sitePEWin({resizable: false, minimize: false, setontop: false, enlarge: false});
	this.linkInsertDialog.setTitle('Link einf&uuml;gen');
	this.linkInsertDialog.setCSSClass('insertlinkDialog');
	this.linkInsertDialog.closeWin();

	this.openLinkInsertDialog = function() {
		self.richTextEditor.focus();
		selectedText = self.selTxt;
		textBefore = self.startTxt;
		textAfter = self.endTxt;
		
		start = self.start;
		end = self.end;
		
		targetOption = true;
		link = 'http://';
		removeOption = false;

		linkTargetRegExp = /^((?:\n|\r|\s|.)*?)<a href="([\/a-zA-Z0-9_.!~*'(),?:@&=+$-]*?)" target="_blank">((?:\n|\r|\s|.)*?)<\/a>((?:\n|\r|\s|.)*?)$/;
		linkRegExp = /^((?:\n|\r|\s|.)*?)<a href="([\/a-zA-Z0-9_.!~*'(),?:@&=+$-]*?)">((?:\n|\r|\s|.)*?)<\/a>((?:\n|\r|\s|.)*?)$/;
		if(linkText = linkRegExp.exec(selectedText)){
			link = linkText[2];
			targetOption = false;
			removeOption = true;
		}
		if(linkText = linkTargetRegExp.exec(selectedText)){
			link = linkText[2];
			targetOption = true;
			removeOption = true;
		}

		self.linkInsertDialog.openWin();
		self.linkInsertDialog.toTop();

		formDialog = '<div><span class="description">Adresse:</span><br /><input type="text" value="'+link+'" id="urlbox" /><br /><br />';
		formDialog += '<span class="description">In neuem Fenster &ouml;ffnen:</span><input type="checkbox" value="" id="openmNewWin"'+(targetOption==true ? ' checked="checked"' : '')+' /><br />';
		formDialog += '<br />';
		if(removeOption)
			formDialog += '<input type="button" value="L&ouml;schen" id="URLDELB" />';
		formDialog += '<input type="button" value="OK" id="URLOKB" /></div>';

		self.linkInsertDialog.setContent(formDialog);

		self.urlbox = document.getElementById('urlbox');
		if(self.urlbox)
			self.urlbox.focus();
		self.targetbox = document.getElementById('openmNewWin');
		self.okbutton = document.getElementById('URLOKB');
		self.okbutton.onclick = self.insertURL;
		if(removeOption) {
			self.delbutton = document.getElementById('URLDELB');
			self.delbutton.onclick = self.removeURL;
		}

		document.onkeydown = self.testSpecialKeys;
	}

	this.insertURL = function() {
		givenurl = self.urlbox.value;
		self.removeURL();
		if(givenurl!='' && givenurl != 'http://') {
			httpgivenurl = givenurl;
			if(httpgivenurl.match(/^www.([a-zA-Z0-9]+).([a-z]{2,3})/))
				httpgivenurl = 'http://' + encodeURI(givenurl);
			if(self.targetbox.checked == true)
				targetText = ' target="_blank"';
			else
				targetText = '';
			if(selectedText == '')
				self.insertData('<a href="'+httpgivenurl+'"'+targetText+'>'+givenurl+'</a>');
			else
				self.insertData('<a href="'+httpgivenurl+'"'+targetText+'>','</a>');
		}
		self.doUpdateResult();
	}
	
	this.removeURL = function() {
		self.linkInsertDialog.closeWin();

		selectedText = self.selTxt;
		textBefore = self.startTxt;
		textAfter = self.endTxt;

		linkTargetRegExp = /^((?:\n|\r|\s|.)*?)<a href="([\/a-zA-Z0-9_.!~*'(),?:@&=+$-]*?)" target="_blank">((?:\n|\r|\s|.)*?)<\/a>((?:\n|\r|\s|.)*?)$/;
		linkRegExp = /^((?:\n|\r|\s|.)*?)<a href="([\/a-zA-Z0-9_.!~*'(),?:@&=+$-]*?)">((?:\n|\r|\s|.)*?)<\/a>((?:\n|\r|\s|.)*?)$/;
		if(linkText = linkRegExp.exec(selectedText)){
			selectedText = linkText[1]+linkText[3]+linkText[4];
			self.richTextEditor.value = textBefore + selectedText + textAfter;
			end = start + selectedText.length;
			self.changeSelection(start,end);
			self.richTextEditor.focus();
			self.evalSelection();
			self.doUpdateResult();
			return;
		}
		if(linkText = linkTargetRegExp.exec(selectedText)){
			selectedText = linkText[1]+linkText[3]+linkText[4];
			self.richTextEditor.value = textBefore + selectedText + textAfter;
			end = start + selectedText.length;
			self.changeSelection(start,end);
			self.richTextEditor.focus();
			self.evalSelection();
			self.doUpdateResult();
			return;
		}
	}

	this.insertPIC = function() {
		givenurl = self.picbox.value;
	
		self.removePIC();
		if(givenurl!='') {
			httpgivenurl = givenurl;
			if(httpgivenurl.match(/^www.([a-zA-Z0-9]+).([a-z]{2,3})/))
				httpgivenurl = 'http://' + encodeURI(givenurl);
			
			stylestring = '';

			optionMargin = document.getElementById('picmargin');
			if(optionMargin.value != 0 && optionMargin.value.match(/^[0-9]+$/))
				stylestring += 'margin: '+optionMargin.value+'px; ';
			optionHeight = document.getElementById('picheight');
			if(optionHeight.value != 0 && optionHeight.value.match(/^[0-9]+$/))
				stylestring += 'height: '+optionHeight.value+'px; ';
			optionWidth = document.getElementById('picwidth');
			if(optionWidth.value != 0 && optionWidth.value.match(/^[0-9]+$/))
				stylestring += 'width: '+optionWidth.value+'px; ';
			optionFloat = document.getElementById('picfloat');
			if(optionFloat.value!='')
				stylestring += 'float: '+optionFloat.value+'; ';
			optionBorder = document.getElementById('picborderwidth');
			if(optionBorder.value != 0 && optionBorder.value.match(/^[0-9]+$/)) {
				optionBorderType = document.getElementById('picbordertype');
				optionBorderColor = document.getElementById('picbordercolor');
				stylestring += 'border: '+optionBorder.value+'px '+optionBorderType.value+' '+optionBorderColor.value;
			}
			
			stylestring = stylestring.replace(/ $/,'');
			stylestring = ' style="'+stylestring+'"';
			
			self.insertData('<img src="'+httpgivenurl+'"'+stylestring+' alt="" />');
			self.doUpdateResult();
		}
	}

	this.removePIC = function() {
		imgselector = /<img src="([\/a-zA-Z0-9_.!~*'(),?:@&=+$-]*?)" alt="([\/a-zA-Z0-9#_.!~*'(),?:@&=+$-]*?)" \/>/;
		imgstyleselector = /<img src="([\/a-zA-Z0-9_.!~*'(),?:@&=+$-]*?)" style="([\/a-zA-Z0-9# _.!~*'(),?:;@&=+$-]*?)" alt="([\/a-zA-Z0-9_.!~*'(),?:@&=+$-]*?)" \/>/;
		
		self.picInsertDialog.closeWin();
		self.evalSelection();

		selectedText = self.selTxt;
		textBefore = self.startTxt;
		textAfter = self.endTxt;
		
		selectedText = selectedText.replace(imgselector,'');
		selectedText = selectedText.replace(imgstyleselector,'');

		self.richTextEditor.value = textBefore + selectedText + textAfter;
		end = start + selectedText.length;
		self.changeSelection(start,end);
		self.richTextEditor.focus();
		self.evalSelection();
		self.doUpdateResult();
		return;
	}

	this.insertFILE = function() {
		filename = document.getElementById('filenamebox').value;
		fileurl = document.getElementById('filebox').value;
		
		if(filename == '')
			filename = fileurl.replace(/^.*\//,'');
		
		self.insertData('<a href="'+fileurl+'">'+filename+'</a>');
		self.doUpdateResult();
		self.fileInsertDialog.closeWin();
	}

	this.init();
}

var rteCaller = false;
var rteCallerType = false;
var selectorDiv;
var callerCoordX;
var callerCoordY;
var clicknum;

function openColorChanger() {
	if(!rteCaller)
		return false;
	if(selectorDiv)
		return false;

	SelectionWindow = '<table cellpadding="0" cellspacing="0">';
	colors = new Array(
		new Array('000000','222222','444444','666666','888888','AAAAAA','CCCCCC','FFFFFF'),
		new Array('330000','660000','990000','CC0000','FF0000','FF4444','FF8888','FFCCCC'),
		new Array('332000','664000','996000','CC8000','FFA000','FFC044','FFD088','FFE0CC'),
		new Array('333300','666600','999900','CCCC00','FFFF00','FFFF44','FFFF88','FFFFCC'),
		new Array('003300','006600','009900','00CC00','00FF00','44FF44','88FF88','CCFFCC'),
		new Array('003333','006666','009999','00CCCC','00FFFF','44FFFF','88FFFF','CCFFFF'),
		new Array('000033','000066','000099','0000CC','0000FF','4444FF','8888FF','CCCCFF'),
		new Array('330033','660066','990099','CC00CC','FF00FF','FF44FF','FF88FF','FFCCFF')
	);
	
	for(c in colors) {
		SelectionWindow += '<tr>';
		for(co in colors[c]){
			SelectionWindow += '<td style="cursor:pointer; border: 1px solid transparent; background-color: #'+colors[c][co]+'; height: 12px; width: 12px; font-size:12px" onmouseover="this.style.border=\'1px outset black\';" onmouseout="this.style.border=\'1px solid transparent\'" onclick="setSelectedColor(\''+colors[c][co]+'\');">&nbsp;</td>';
		}
		SelectionWindow += '</tr>';
	}
	SelectionWindow += '<tr><td colspan="'+colors[0].length+'" style="cursor:pointer; text-align: center; border: 1px solid transparent; height: 8px; width: 8px; font-size:8px" onmouseover="this.style.border=\'1px outset black\';" onmouseout="this.style.border=\'1px solid transparent\'" onclick="setSelectedColor(\'default\');">Standard</td></tr>';
	
	SelectionWindow += '</table>';
	
	selectorDiv = document.createElement('div');
	document.getElementsByTagName('body')[0].appendChild(selectorDiv);
	selectorDiv.innerHTML = SelectionWindow;
	selectorDiv.style.position = 'absolute';
	selectorDiv.style.top = callerCoordY+'px';
	selectorDiv.style.left = callerCoordX+'px';
	selectorDiv.style.zIndex = 5000000 // Make Sure this Window is ABOVE everything else...
	document.onclick = abortSelectColor;
	clicknum = 0;
}

function setSelectedColor(color) {
	if(rteCallerType == 'font')
		rteCaller.changeFontColor(color);
	else if(rteCallerType == 'mark')
		rteCaller.changeMarkColor(color);
	else
		rteCaller.setBorderColor(color);
}

function abortSelectColor(){
	clicknum++;
	if(clicknum > 1) {
		document.getElementsByTagName('body')[0].removeChild(selectorDiv);
		selectorDiv = false;
		document.onclick = function() { return; }
	}
	return;
}

function JSStyleObject() {
	this['padding'] = '';
	this['margin'] = '';
	this['float'] = '';
	this['border'] = '';
	this['width'] = '';
	this['height'] = '';
}

function trim(str) {
	return str.replace(/^\s\s*/,'').replace(/\s\s*$/,'');
}

function startImgLib() {
	if(typeof(imgLib) == 'undefined') {
		imgLib = new sitePEWin({resizable: true, minimize: true, setontop: false, enlarge: true});
		imgLib.setWinIcon(pic_path+"imgico.png");
		imgLib.setOnTop();
		imgLib.setHeight(400);
		imgLib.setWidth(800);
		imgLib.setTitle('Image Library');
		if(typeof(uploadFrame) == 'undefined') {
			uploadFrame = document.createElement('iframe');
			uploadFrame.style.display = 'none';
			uploadFrame.name = 'uploadFrame';
			bodyEle.appendChild(uploadFrame);
		}
		
		winLayout = '';
		
		if(rteCaller.uploadImages) {
			winLayout += '<div class="imgLibUploadField">';
			winLayout += '<form id="imgUploadForm" target="uploadFrame" method="post" action="'+pre_path+'ajax.php?mode=sd_imglib&path='+imgLibPath+'" enctype="multipart/form-data" onsubmit="updloadFile();">';
			winLayout += 'Datei hochladen: <br /><input type="file" name="imgUpload" id="imgUpload" />';
			winLayout += '<input type="submit" Value="Hochladen" name="doImgUpload" id="doImgUpload" />';
			winLayout += '</form>';
			winLayout += '<div style="float: left; margin: 2px; cursor: pointer;" onmouseover="this.className=\'hover\';" onmouseout="this.className=\'\';" onclick="library.createFolder();"><img src="'+pic_path+'folder.png" style="width: 16px; height: 16px;" alt="" />Ordner erstellen</div>';
			winLayout += '<div id="librarydelbutton" style="visibility:hidden; float: left; margin: 2px; cursor: pointer;" onmouseover="this.className=\'hover\';" onmouseout="this.className=\'\';" onclick="library.deleteMarkedFile();"><img src="'+pic_path+'delete.png" style="width: 16px; height: 16px;" alt="" />Datei L&ouml;schen</div>';
			winLayout += '<br style="clear: both;" />';
			winLayout += '</div>';
		}
		winLayout += '<div class="imgLibBrowser" id="imgLibBrowser">';
		winLayout += '</div>';
		imgLib.setContent(winLayout);
		if(typeof(library) == 'undefined') {
			library = new fileLibraryObject(imageLibrary);
		}
		
		library.loadLibrary();
	}

	imgLib.onResize = false;
	imgLib.openWin();
	imgLib.toTop();
}

function startFileLib() {
	if(typeof(fileLib) == 'undefined') {
		fileLib = new sitePEWin({resizable: true, minimize: true, setontop: false, enlarge: true});
		fileLib.setWinIcon(pic_path+"fileico.png");
		fileLib.setOnTop();

		fileLib.setHeight(400);
		fileLib.setWidth(800);
		fileLib.setTitle('File Library');
		
		winLayout = '';
		
		if(rteCaller.uploadImages) {
			winLayout += '<div class="imgLibUploadField">';
			winLayout += '<form id="imgUploadForm" target="uploadFrame" method="post" action="'+pre_path+'ajax.php?mode=sd_filelib&path='+imgLibPath+'" enctype="multipart/form-data" onsubmit="updloadFile();">';
			winLayout += 'Datei hochladen: <br /><input type="file" name="fileUpload" id="fileUpload" />';
			winLayout += '<input type="submit" Value="Hochladen" name="doFileUpload" id="doFileUpload" />';
			winLayout += '</form>';
			winLayout += '<div style="float: left; margin: 2px; cursor: pointer;" onmouseover="this.className=\'hover\';" onmouseout="this.className=\'\';" onclick="library2.createFolder();"><img src="'+pic_path+'folder.png" style="width: 16px; height: 16px;" alt="" />Ordner erstellen</div>';
			winLayout += '<div id="library2delbutton" style="visibility:hidden; float: left; margin: 2px; cursor: pointer;" onmouseover="this.className=\'hover\';" onmouseout="this.className=\'\';" onclick="library2.deleteMarkedFile();"><img src="'+pic_path+'delete.png" style="width: 16px; height: 16px;" alt="" />Datei L&ouml;schen</div>';
			winLayout += '<br style="clear: both;" />';
			winLayout += '</div>';

		}
		winLayout += '<div class="imgLibBrowser" id="fileLibBrowser">';
		winLayout += '</div>';

		if(typeof(uploadFrame) == 'undefined') {
			uploadFrame = document.createElement('iframe');
			uploadFrame.style.display = 'none';
			uploadFrame.name = 'uploadFrame';
			bodyEle.appendChild(uploadFrame);
		}
		fileLib.setContent(winLayout);
		if(typeof(library2) == 'undefined') {
			library2 = new fileLibraryObject(fileLibrary);
		}
		
		library2.loadLibrary();
	}

	fileLib.onResize = false;
	fileLib.openWin();
	fileLib.toTop();
}

function updloadFile() {
	winInfo = '<img src="'+pic_path+'upload_anim.gif" class="waitAnim" alt="" />';
	if(document.getElementById('imgUpload') && document.getElementById('imgUpload').value != '') {
		imgLib.closeWin();
		library.fileName = document.getElementById('imgUpload').value.replace(/(.*)\\/,''); // Should save Name only ...
	} else if(document.getElementById('fileUpload')) {
		fileLib.closeWin();
		library2.fileName = document.getElementById('fileUpload').value.replace(/(.*)\\/,''); // Should save Name only ...
	}

	setErrorWin(winInfo);
	errorWin.setTitle('Uploading');
	return true;
}

function uploadResult(resultNum) {
	msg = new Array();
	msg[200] = 'Datei erfolgreich hochgeladen!';

	msg[300] = 'Zugriff verweigert!';
	msg[301] = 'Keine Datei angegeben';
	msg[302] = 'Möglicher Angriff (Datei eventuell mit Virus befallen?)';
	msg[303] = 'Die Hochgeladene Datei war leer';
	msg[304] = 'Dateityp nicht erlaubt';
	msg[305] = 'Datei ist zu groß';
	msg[306] = 'Diese Datei existiert bereits auf dem Server';
	msg[307] = 'Die Datei konnte nicht ins Zielverzeichnis verschoben werden';
	msg[308] = 'Hochgeladene Datei ist kein Bild, aber es wurde ein Bild erwartet';
	msg[309] = 'Das Bild ist zu groß';

	msg[321] = 'Zeichenfolge war leer!';	
	msg[322] = 'Name bereits vergeben';
	
	content = '<div class="uploadResult">'+msg[resultNum];
	errorWin.closeWin();
	
	if(document.getElementById('imgUpload') && document.getElementById('imgUpload').value != '') {
		callFunction1 = 'setPicURL';
		callFunction2 = 'startImgLib';
	} else if(document.getElementById('fileUpload')) {
		callFunction1 = 'setFileURL';
		callFunction2 = 'startFileLib';
	}

	if(resultNum == 200) {
		errorWin.setTitle('OK');
		content += '<br /><input type="button" value="OK" onclick="'+callFunction1+'()" />';
	} else if(resultNum >= 301 && resultNum <= 320)  {
		errorWin.setTitle('Fehler');
		content += '<br /><input type="button" value="OK" onclick="'+callFunction2+'(); errorWin.closeWin();" />';
	} else if(resultNum == 300 || resultNum >= 321) {
		errorWin.setTitle('Fehler');
		content += '<br /><input type="button" value="OK" onclick="errorWin.closeWin();" />';
	}
	
	content += '</div>';
	
	setErrorWin(content);
}

function setPicURL() {
	imgLib.closeWin();
	document.getElementById('picbox').value = pre_path + imageLibrary + '/'+imgLibPath+library.fileName;
	library.setFileName('');
	errorWin.closeWin();
	
	library.loadLibrary();
}

function setFileURL() {
	fileLib.closeWin();
	document.getElementById('filebox').value = pre_path + fileLibrary + '/'+imgLibPath+library2.fileName;
	library2.setFileName('');
	errorWin.closeWin();
	
	library2.loadLibrary();
}

function fileLibraryObject(lib_path) {
	var self = this;
	this.images;
	this.directories;
	this.lib_path = lib_path;
	this.printWin;

	this.fileName;

	this.delSecWin = new sitePEWin({resizable: false, setontop: false, minimize: false, enlarge: false});
	this.delSecWin.setTitle('');
	this.delSecWin.setWidth(250);
	this.delSecWin.setHeight(150);
	this.delSecWin.closeWin();
	this.createFolderWin = new sitePEWin({resizable: false, setontop: false, minimize: false, enlarge: false});
	this.createFolderWin.setTitle('Ordner erstellen');
	this.createFolderWin.setHeight(100);
	this.createFolderWin.closeWin();

	this.createFolder = function(){
		content = '<div style="margin: 5px; text-align: left">Name des neuen Ordners:';
		content += '<input type="text" id="'+(self.lib_path == imageLibrary ? 'library' : 'library2')+'cFolderName" value="" style="width: 100%" />';
		content += '<input type="button" value="Ordner erstellen" style="float: right" onclick="'+(self.lib_path == imageLibrary ? 'library' : 'library2')+'.cFolder();" /><br style="clear:both" />';
		content += '</div>';
		
		self.createFolderWin.setContent(content);
		self.createFolderWin.openWin();
		self.createFolderWin.toTop();
	}
	
	this.cFolder = function() {
		newFolderName = document.getElementById((self.lib_path == imageLibrary ? 'library' : 'library2')+'cFolderName').value;
		self.createFolderWin.closeWin();
		self.loadLibrary('&createFolder='+newFolderName);
	}

	this.deleteMarkedFile = function() {
		if(typeof(self.fileName) == 'undefined' || self.fileName == '')
			return false;
		
		content = '<div style="margin: 5px; text-align: center">Soll diese Datei wirklich gel&ouml;scht werden?<br /><br />';
		content += '<input type="button" style="float: left" value="L&ouml;schen" onclick="'+(self.lib_path == imageLibrary ? 'library' : 'library2')+'.delFile();" />';
		content += '<input type="button" style="float: right" value="Abbrechen" onclick="'+(self.lib_path == imageLibrary ? 'library' : 'library2')+'.delSecWin.closeWin();" /><br style="clear:both" /></div>';
		
		self.delSecWin.setContent(content);
		self.delSecWin.openWin();
		self.delSecWin.toTop();
	}
	
	this.delFile = function() {
		self.delSecWin.closeWin();
		self.loadLibrary('&deleteFile='+self.fileName);
	}

	this.parseImages = function(response){
		self.directories	= response.responseXML.getElementsByTagName('dir');
		self.images		= response.responseXML.getElementsByTagName('img');
		
		self.printfileLibrary();
	}
	
	this.setFileName = function(fN) {
		self.fileName = fN;
		if(fN == '') {
			if(self.lib_path == imageLibrary)
				document.getElementById('librarydelbutton').style.visibility = 'hidden';
			else
				document.getElementById('library2delbutton').style.visibility = 'hidden';
		} else {
			if(self.lib_path == imageLibrary)
				document.getElementById('librarydelbutton').style.visibility = 'visible';
			else
				document.getElementById('library2delbutton').style.visibility = 'visible';
		}
	}
	
	this.printfileLibrary = function() {
		if(lib_path == imageLibrary)
			imgLib.onResize = self.printfileLibrary;
		else
			fileLib.onResize = self.printfileLibrary;
	
		if(typeof(self.printWin)=='undefined') {
			if(lib_path == imageLibrary)
				self.printWin = document.getElementById('imgLibBrowser');
			else
				self.printWin = document.getElementById('fileLibBrowser');
		}
		availableWidth = self.printWin.offsetWidth;
		
		colNum = Math.floor(availableWidth/250);
		
		m = 0;
		
		libcontent = '<table cellpadding="0" cellspacing="0">';
		c = 0;
		if(imgLibPath != '') {
			dblclick = ' ondblclick="'+(self.lib_path == imageLibrary ? 'library' : 'library2')+'.folderUp();"';
			libcontent += '<td '+dblclick+' onclick="'+(self.lib_path == imageLibrary ? 'library' : 'library2')+'.setFileName(\'\'); '+(self.lib_path == imageLibrary ? 'library' : 'library2')+'.marker('+m+')" ';
			libcontent +='	onmouseover="'+(self.lib_path == imageLibrary ? 'library' : 'library2')+'.marker('+m+',1)" onmouseout="'+(self.lib_path == imageLibrary ? 'library' : 'library2')+'.marker('+m+',2)"id="sym'+m+'" style="width: 50px; height: 50px;">';
			libcontent += '<img style="width: 50px; height: 50px;" src="'+pic_path+'folder.png" alt="" /></td><td '+dblclick+' onclick="'+(self.lib_path == imageLibrary ? 'library' : 'library2')+'.setFileName(\'\'); '+(self.lib_path == imageLibrary ? 'library' : 'library2')+'.marker('+m+')"';
			libcontent +='	onmouseover="'+(self.lib_path == imageLibrary ? 'library' : 'library2')+'.marker('+m+',1)" onmouseout="'+(self.lib_path == imageLibrary ? 'library' : 'library2')+'.marker('+m+',2)" id="nam'+m+'" style="width: 200px;">..</td>';
			c++;
			m++;
		}
		
		for(d = 0; d < self.directories.length; d++) {
			if(c == colNum) {
				libcontent += '</tr><tr>';
				c = 0;
			}
			folder = getNodeValue(self.directories[d],'name');

			dblclick = ' ondblclick="'+(self.lib_path == imageLibrary ? 'library' : 'library2')+'.appendFolder(\''+folder+'\');"';

			libcontent += '<td '+dblclick+' onclick="'+(self.lib_path == imageLibrary ? 'library' : 'library2')+'.setFileName(\''+folder+'\'); '+(self.lib_path == imageLibrary ? 'library' : 'library2')+'.marker('+m+')" onmouseover="'+(self.lib_path == imageLibrary ? 'library' : 'library2')+'.marker('+m+',1)" onmouseout="'+(self.lib_path == imageLibrary ? 'library' : 'library2')+'.marker('+m+',2)" id="sym'+m+'" style="width: 50px; height: 50px;"><img style="width: 50px; height: 50px;" src="'+pic_path+'folder.png" alt="" /></td>';
			libcontent += '<td '+dblclick+' onclick="'+(self.lib_path == imageLibrary ? 'library' : 'library2')+'.setFileName(\''+folder+'\'); '+(self.lib_path == imageLibrary ? 'library' : 'library2')+'.marker('+m+')" onmouseover="'+(self.lib_path == imageLibrary ? 'library' : 'library2')+'.marker('+m+',1)" onmouseout="'+(self.lib_path == imageLibrary ? 'library' : 'library2')+'.marker('+m+',2)" id="nam'+m+'" style="width: 200px;">'+folder+'</td>';
			c++;
			m++;
		}
		
		for(i=0; i < self.images.length; i++) {
			if(c == colNum) {
				libcontent += '</tr><tr>';
				c = 0;
			}
			
			time = new Date(getNodeValue(self.images[i],'date')*1000);
			
			if(self.lib_path == imageLibrary) {
				picture = pre_path + imageLibrary + '/'+imgLibPath + getNodeValue(self.images[i],'name');
				filename = getNodeValue(self.images[i],'name');
				dblclick = ' ondblclick="setPicURL();"';
				
				imgHeight = getNodeValue(self.images[i],'height')*1;
				imgWidth = getNodeValue(self.images[i],'width')*1;
				
				factor1 = imgHeight / imgWidth;
				factor2 = imgWidth / imgHeight;
				addInfo = '<br /><span>'+imgWidth+' x '+imgHeight+' px</span>';
				
				if(imgHeight > 75 || imgWidth > 75) {
					if(imgHeight > imgWidth) {
						showHeight = 75;
						showWidth = 75*factor2;
					} else {
						showHeight = 75*factor1;
						showWidth = 75;
					}
				} else {
					showHeight = imgHeight;
					showWidth = imgWidth;
				}
			} else {
				picture = pic_path + 'files.png';
				filename = getNodeValue(self.images[i],'name');
				dblclick = ' ondblclick="setFileURL();"';
				showHeight = 48;
				showWidth = 48;
				addInfo = '';
			}
			
			filesize = getNodeValue(self.images[i],'size')*1;
			sizeName = 'B';
			if(filesize > 1024) {
				filesize /= 1024;
				sizeName = 'KB';
				if(filesize > 1024) {
					filesize /= 1024;
					sizeName = 'MB';
				}
				
				filesize *= 100;
				filesize = Math.round(filesize);
				filesize /= 100;
			}
			
			libcontent += '<td '+dblclick+' onclick="'+(self.lib_path == imageLibrary ? 'library' : 'library2')+'.setFileName(\''+filename+'\'); '+(self.lib_path == imageLibrary ? 'library' : 'library2')+'.marker('+m+')" onmouseover="'+(self.lib_path == imageLibrary ? 'library' : 'library2')+'.marker('+m+',1)" onmouseout="'+(self.lib_path == imageLibrary ? 'library' : 'library2')+'.marker('+m+',2)" id="sym'+m+'" style="width: 75px; height: 100px; text-align: center; vertical-align: middle;"><img src="'+picture+'" style="width: '+showWidth+'px; height: '+showHeight+'px;" alt="" /></td>';
			libcontent += '<td '+dblclick+' onclick="'+(self.lib_path == imageLibrary ? 'library' : 'library2')+'.setFileName(\''+filename+'\'); '+(self.lib_path == imageLibrary ? 'library' : 'library2')+'.marker('+m+')" onmouseover="'+(self.lib_path == imageLibrary ? 'library' : 'library2')+'.marker('+m+',1)" onmouseout="'+(self.lib_path == imageLibrary ? 'library' : 'library2')+'.marker('+m+',2)" id="nam'+m+'" style="width: 200px;">'+filename;
			libcontent += '<br /><span>'+filesize+' '+sizeName+'</span>';
			libcontent += '<br /><span>'+time.getDate()+'.'+(time.getMonth()+1)+'.'+time.getFullYear().toString().substring(2)+' '+time.getHours()+':'+time.getMinutes()+':'+time.getSeconds()+'</span>';
			libcontent += addInfo;
			libcontent += '</td>';
			c++;
			m++;
		}
		
		if(c < colNum) {
			for(i = c; i < colNum; i++) {
				libcontent += '<td style="width: 50px;"></td><td style="width: 200px;"></td>';
			}
		}
		
		libcontent += '</table>';
		
		self.printWin.innerHTML = libcontent;
	}
	
	this.loadLibrary = function(addFileOptions){
		if(typeof(addFileOptions) == 'undefined')
			addFileOptions = '';

		self.setFileName('');

		if(self.lib_path == imageLibrary) {
			self.ajax			= new AJAXObj('mode=rd_imglib&path='+imgLibPath+addFileOptions,self.parseImages);
			self.ajax.doRequest();
			
			document.getElementById('imgUploadForm').action = pre_path+'ajax.php?mode=sd_imglib&path='+imgLibPath;
		} else {
			self.ajax			= new AJAXObj('mode=rd_filelib&path='+imgLibPath+addFileOptions,self.parseImages);
			self.ajax.doRequest();
			
			document.getElementById('imgUploadForm').action = pre_path+'ajax.php?mode=sd_filelib&path='+imgLibPath;
		}
	}
	
	this.appendFolder = function(folder) {
		imgLibPath += folder+'/';
		self.setFileName('');
		self.loadLibrary();
	}

	this.folderUp = function() {
		imgLibPath = imgLibPath.replace(/[^\/]+?\/$/,'');
		self.setFileName('');
		self.loadLibrary();
	}

	this.marker = function(m,mouseAction) {
		if(typeof(mouseAction) == 'undefined') {
			tablecells = self.printWin.getElementsByTagName('td');
			for(t = 0; t < tablecells.length; t++)
				tablecells[t].className = '';
				
			document.getElementById('sym'+m).className = 'marked';
			document.getElementById('nam'+m).className = 'marked';
		} else {
			if(mouseAction == 1) {
				document.getElementById('sym'+m).className += ' hover';
				document.getElementById('nam'+m).className += ' hover';
			} else {
				document.getElementById('sym'+m).className = document.getElementById('sym'+m).className.replace(/hover/g,'');
				document.getElementById('nam'+m).className = document.getElementById('nam'+m).className.replace(/hover/g,'');
			}
		}
	}
}
