﻿function TRTEControl(parameter)
{
    //private
        var self = this;
	var constructorParameter = parameter;

		function toggleLayer(layerID)
		{
			var e = document.getElementById(layerID);
			e.style.display = (e.style.display!='block')?'block':'none';		
		}

		 function toHex(n) 
		{
			var result = n.toString(16);
			if (result.length==1) result = "0"+result;
			return result;
		}
		
		function renderColorSelection(document,complexity,onClickHandler)
		{
		    var sequenceOld, found, p, direction, shiftsteps, sequenceNew;
		    var output = '';
            var c = 0;
            var container = constructorParameter.documentContainer.document.createElement('div');
            
            //farbänderungsschritte für r,g,b festlegen, es darf sich immer nur eine stelle (farbanteil) ändern
            var sequenceList = new Array('000', '100', '110', '010', '011', '001', '101', '100');

            sequenceOld = sequenceList[c++];
            
            var basecolor = new Object();
            basecolor.value = 0;
            
            while (c <= sequenceList.length-1)
            {
                sequenceNew = sequenceList[c];
                
                //stelle finden in der sich farbeanteil ändern soll
                found = false;
                p = -1;
                while (p < sequenceNew.length-1 && !found)
                {
                    p++;
                    found = sequenceNew.substr(p,1) != sequenceOld.substr(p, 1);
                }

                //zählrichtung und startbit im hexcode berechnen
                direction = 0+(sequenceOld.substr(p, 1) == '1' && sequenceNew.substr(p, 1) == '0');
                shiftsteps = (3 - (p+1)) * 8;

                //farbveränderung rendern
                renderColorSegment(constructorParameter.documentContainer.document, container, basecolor, shiftsteps, direction, complexity, onClickHandler);
                
                sequenceOld = sequenceList[c];
                           
                c++;
            }
            
            return container;
        }
        
        function renderColorSegment(document, container, basecolor, shiftsteps, direction, complexity, onClickHandler)
        {
            var rowCount, offset, minPart, rowDifference, maxPart, c, multiplierBase, multiplierDirection, r, g, b, color, colorRed, colorGreen, colorBlue, loopCount, OutputColor, colorRows, colorColsDifference;
            var colorElement = null;
            var a = null;
            var column = null;

            //left shift nachbilden mit mulitplikation von 2
            c = shiftsteps;
            multiplierBase = 1;

            while (c > 0)
            {
                multiplierBase = multiplierBase * 2;
                c--;
            }
            
            //zählrichtung beachten
            multiplierDirection = 1 - 2 * direction;
            
            //für das durchlaufen der farben die nötigen variablen initialisieren
            colorRows = complexity;
            colorColsDifference = 255 / (complexity / 2);
            
            rowCount = Math.round(colorRows / 2);

            //kompletten farbanteil durchlaufen
            c = 0;
            while (c <= 255)
            {
                column = document.createElement('div');
                column.className = 'rteColorSelectionColumn';
                
                color = basecolor.value + (multiplierDirection * Math.round(c) * multiplierBase);

                colorRed = (color & 0xFF0000) / 65536;
                colorGreen = (color & 0x00FF00) / 256;
                colorBlue = (color & 0x0000FF);

                OutputColor = '';

                r = colorRed;
                g = colorGreen;
                b = colorBlue;

                //brighten from white to color
                minPart = r;
                if (minPart > g) { minPart = g; }
                if (minPart > b) { minPart = b; }

                rowDifference = (255 - minPart) / rowCount;
                
                offset = 0+!(container.childNodes.length == 0 && basecolor.value == 0);

                loopCount = 1+offset;
                while (loopCount <= rowCount)
                {
                    if (r + rowDifference < 255) { r = r + rowDifference; } else { r = 255; };
                    if (g + rowDifference < 255) { g = g + rowDifference; } else { g = 255; };
                    if (b + rowDifference < 255) { b = b + rowDifference; } else { b = 255; };
                    
                    //we must include style in createElement because dynamically adding style via jscript is not supported, ie throws error message
                    colorElement = document.createElement('div'); // style="background-color:#' + toHex(Math.round(r)) + toHex(Math.round(g)) + toHex(Math.round(b))+';"></div>');
		colorElement.style.backgroundColor = '#' + toHex(Math.round(r)) + toHex(Math.round(g)) + toHex(Math.round(b));

		self.prototype.registerEvent(colorElement,'mousedown', onClickHandler);

                    colorElement.className = 'rteColorSelectionCell';

			if (colorElement.insertAdjacentElement)
			{                  
		    		column.insertAdjacentElement('afterbegin',colorElement);
			}
			else
			{
				column.insertBefore(colorElement,column.firstChild);
			}

                   
                    loopCount++;
                }
                
                //brighten to color to black
                r = colorRed;
                g = colorGreen;
                b = colorBlue;

                maxPart = r;
                if (maxPart < g) { maxPart = g; }
                if (maxPart < b) { maxPart = b; }

                rowDifference = maxPart / rowCount;

                loopCount = 1;
                while (loopCount <= rowCount+offset)
                {
                    colorElement = document.createElement('div');
			colorElement.style.backgroundColor = '#' + toHex(Math.round(r)) + toHex(Math.round(g)) + toHex(Math.round(b));
		
			self.prototype.registerEvent(colorElement,'mousedown', onClickHandler);

                    colorElement.className = 'rteColorSelectionCell';
                    
                    column.appendChild(colorElement);

                    if (r - rowDifference > 0) { r = r - rowDifference; } else { r = 0; };
                    if (g - rowDifference > 0) { g = g - rowDifference; } else { g = 0; };
                    if (b - rowDifference > 0) { b = b - rowDifference; } else { b = 0; };
                    
                    loopCount++;
                }
                
                container.appendChild(column);

                c = c + colorColsDifference;
            }

            basecolor.value = basecolor.value + (multiplierDirection * 255 * multiplierBase);
        }

	function initialize()
	{
		self.prototype.initialize(constructorParameter.documentContainer.document.getElementById(constructorParameter.editorPlaceHolderID+'IFrame').contentWindow,true,false,0);
	}

	function refreshMenu()
	{
		var c = 0;
		var button;
		var buttonHTML = self.menu.button.findById('HTML');
		
		//process buttons
		while (c <= self.menu.button.count()-1)
		{
			button = self.menu.button.get(c);

			if (button.canModifyContent && button !== buttonHTML)
			{
				button.enabled = self.prototype.selectedObject.isValid() && !buttonHTML.active;
			}

			button.imageObject.parentNode.className = 'rteMenuButton'+(0+button.enabled)+''+(0+(button.active && button.enabled));
			button.imageObject.style.opacity = 1-0.7*(1-button.enabled);
			button.imageObject.style.filter = 'alpha(opacity='+(button.imageObject.style.opacity*100)+')';

			c++;
		}

		//process panels
		var panel;

		c = 0;
		while (c <= self.menu.panel.count()-1)
		{
			panel = self.menu.panel.get(c);

			if (panel.onRefresh && panel.visible)
			{
				panel.onRefresh(panel);
			}

			c++;
		}		
	}

	function menuButtonClicked(e)
	{
		var sender = (e.srcElement)?e.srcElement:e.target;

		//when button has e.g. padding then somethings click goes to link surrounding image, then get image
		if (sender.tagName.toLowerCase() == 'a')
		{
			sender = sender.firstChild;	
		}
		
		//get button object based on image
		var button = self.menu.button.find(sender);

		if (button.enabled)
		{
			//refresh internal selection state
			self.prototype.refreshSelection();

			/* to ensure something is selected 
			if (!self.prototype.selectedObject.isValid())
			{
				var selection = self.prototype.getDocument().selection;
				selection.empty();
			
				var r = self.prototype.getDocument().body.createTextRange();
				r.moveStart('character',0);
				r.moveEnd('character',1);
				r.select();
			}*/

			var selectedObject = self.prototype.selectedObject;
			var c,p;

			if (selectedObject.isValid() || button.id == 'HTML')
			{
				switch (button.id)
				{
						case 'BOLD' : selectedObject.setBold(!selectedObject.getBold());
					break;	case 'ITALIC' :	selectedObject.setItalic(!selectedObject.getItalic());
					break;	case 'UNDERLINE' : selectedObject.setUnderline(!selectedObject.getUnderline());
					break;	case 'LALIGN' : selectedObject.setAlignment('left');
					break;	case 'CALIGN' : selectedObject.setAlignment('center');
					break;	case 'RALIGN' : selectedObject.setAlignment('right');
					break;	case 'UL' : selectedObject.executeCommand('InsertUnorderedList','');
					break;	case 'OL' : selectedObject.executeCommand('InsertOrderedList','');
					break;	case 'INDENT' : selectedObject.executeCommand('Indent',null);
					break;	case 'OUTDENT' : selectedObject.executeCommand('Outdent',null);					
					
					break;	case 'SUB' : selectedObject.setSub(!selectedObject.getSub());
					break;	case 'SUP' : selectedObject.setSup(!selectedObject.getSup());					
					
					break;	case 'FORECOLOR':
						case 'BACKCOLOR' :

							var panel = self.menu.panel.find('COLORSELECTION');

							if (panel.container.style.display != 'block' || panel.data == (button.id == 'FORECOLOR'))
							{
								toggleLayer(panel.container.id);
							}
							
							if (panel.button) { panel.button.active = false; }

							panel.button = button;
							panel.data = (button.id == 'FORECOLOR');
							panel.caption.innerHTML = (panel.data)?'Text color':'Background color';
							panel.visible = panel.container.style.display == 'block';

							button.active = panel.visible;
							refreshMenu();

					break;	case 'REMOVEFORMAT' : selectedObject.removeFormat();
					break;	case 'HTML' : 

						button.active = !button.active;	

						selectedObject.reset();
						refreshMenu();

						self.prototype.setDesignMode(!self.prototype.getDesignMode());

					break;	case 'LINK' : 

						var range = self.prototype.selectedObject.getRange();
						var link = null;
						var modify = false;
						var processText = true;

						//first check wether control is selected that is child of link, propaply an image
						if (self.prototype.selectedObject.isControl())
						{
							var control = self.prototype.selectedObject.getObject();
							if (control.tagName.toLowerCase() == 'img')
							{
								var controlParent = (document.all)?control.parentElement:range.commonAncestorContainer;
								if (controlParent.tagName.toLowerCase() == 'a')
								{
									link = controlParent;
									modify = true;
									processText = false;
								}
							}	
						}

						//if nothing found check wether a link is surrounding the range
						if (!link)
						{
							var element = (document.all)?range.parentElement():range.startContainer.parentNode;
							if (element.tagName.toLowerCase() == 'a')
							{
								link = element;	
								modify = true;
							}
						}

						if (!modify)
						{
							link = self.prototype.getDocument().createElement('a');
							if (document.all)
							{
								link.innerText = range.text;
							}
							else
							{
								link.textContent = range.toString();
							}
						}

						self.showLinkConfigurationDialog(self,link,modify,processText);

					break;	case 'IMAGE' :
							
						var textRange = self.prototype.selectedObject.getObject();
						var image = null;
						var modify = false;

						if (self.prototype.selectedObject.isControl())
						{		
							if (self.prototype.selectedObject.getObject().tagName.toLowerCase() == 'img')
							{
								image = self.prototype.selectedObject.getObject();
								modify = true;
							}
						}
						
						if (!modify)
						{
							image = self.prototype.getDocument().createElement('img');

							var element = (document.all)?textRange.parentElement():textRange.startContainer.parentNode;
							if (element.tagName.toLowerCase() == 'a')
							{
								image.alt = (document.all)?element.innerText:element.textContent;
							}
							else
							{	
								image.alt = (document.all)?textRange.text:textRange.toString();	
							}
						}	

						self.showImageConfigurationDialog(self,image,modify);
				}
			}
		}
	}

	function initializeMenu(container)
	{
		self.menu.button.clear();
		self.menu.panel.clear();

		//define menu buttons
		var button;

		button = new TRTEMenuButton('BOLD');
		button.description = 'fett';
		button.imageFile = 'Bold.gif';
		self.menu.button.add(button);

		button = new TRTEMenuButton('ITALIC');
		button.description = 'kursiv';
		button.imageFile = 'Italic.gif';
		self.menu.button.add(button);

		button = new TRTEMenuButton('UNDERLINE');
		button.description = 'unterstrichen';
		button.imageFile = 'Underline.gif';
		self.menu.button.add(button);

		button = new TRTEMenuButton('LALIGN');
		button.description = 'linksbündig';
		button.imageFile = 'AlignLeft.gif';
		self.menu.button.add(button);

		button = new TRTEMenuButton('CALIGN');
		button.description = 'zentriert';
		button.imageFile = 'AlignCenter.gif';
		self.menu.button.add(button);

		button = new TRTEMenuButton('RALIGN');
		button.description = 'rechtsbündig';
		button.imageFile = 'AlignRight.gif';
		self.menu.button.add(button);

		button = new TRTEMenuButton('UL');
		button.description = 'unsortierte Liste';
		button.imageFile = 'UnorderedList.gif';
		self.menu.button.add(button);

		button = new TRTEMenuButton('OL');
		button.description = 'sortierte Liste';
		button.imageFile = 'OrderedList.gif';
		self.menu.button.add(button);

		button = new TRTEMenuButton('OUTDENT');
		button.description = 'ausrücken';
		button.imageFile = 'Outdent.gif';
		self.menu.button.add(button);

		button = new TRTEMenuButton('INDENT');
		button.description = 'einrücken';
		button.imageFile = 'Indent.gif';
		self.menu.button.add(button);

		button = new TRTEMenuButton('FORECOLOR');
		button.description = 'Textfarbe auswählen';
		button.imageFile = 'ForeColor.gif';
		self.menu.button.add(button);

		button = new TRTEMenuButton('BACKCOLOR');
		button.description = 'Hintergrundfarbe auswählen';
		button.imageFile = 'BackColor.gif';
		self.menu.button.add(button);

		button = new TRTEMenuButton('REMOVEFORMAT');
		button.description = 'Formatierung löschen';
		button.imageFile = 'RemoveFormat.gif';
		self.menu.button.add(button);
		
		button = new TRTEMenuButton('SUB');
		button.description = 'hochgestellt';
		button.imageFile = 'Sub.gif';
		//self.menu.button.add(button);
		
		button = new TRTEMenuButton('SUP');
		button.description = 'tiefgestellt';
		button.imageFile = 'Sup.gif';
		//self.menu.button.add(button);

		// fallls benötigt wieder reinnhemen
		button = new TRTEMenuButton('LINK');
		button.description = 'Link einfügen / ändern';
		button.imageFile = 'Link.gif';
		//self.menu.button.add(button);

		// fallls benötigt wieder reinnhemen
		button = new TRTEMenuButton('IMAGE');
		button.description = 'Bild einfügen / ändern';
		button.imageFile = 'Image.gif';
		//self.menu.button.add(button);

		button = new TRTEMenuButton('HTML');
		button.description = 'HTML Ansicht';
		button.imageFile = 'SourceCode.gif';
		button.canAlterContent = false;
		self.menu.button.add(button);

		//insert menu to DOM
		var menu = constructorParameter.documentContainer.document.createElement('div');
		menu.className = 'rteMenu';

		var c = 0;
		var b;
            
           	while (c <= self.menu.button.count()-1)
           	{
			b = self.menu.button.get(c);
			b.onClick = menuButtonClicked;

               		var link = constructorParameter.documentContainer.document.createElement('a');

			link.className = 'rteMenuButton'+(0+b.active);
			link.href = 'javascript://'; //needs to be assigned for a correctly working css, we cannot set # because this alters the url, so we create a js dummy
        			
			self.prototype.registerEvent(link,'click',b.onClick);

    			var i = constructorParameter.documentContainer.document.createElement('img');
                	i.src = constructorParameter.urlImage+'/Button/'+b.imageFile; 

			if (b.imageWidth) { i.style.width = b.imageWidth; }
			if (b.imageHeight) { i.style.height = b.imageHeight; }
                
                	var a = parameter.documentContainer.document.createAttribute("border");
                	a.value = '0';
                
                	i.attributes.setNamedItem(a);
                
                	a = parameter.documentContainer.document.createAttribute("alt");
                	a.value = b.description;
                
                	i.attributes.setNamedItem(a);
            
                	link.appendChild(i);
                	menu.appendChild(link);

			b.imageObject = i;  

			c++;          
  		}
 
            	container.appendChild(menu);

		//created panels
		var panel;

		panel = new TRTEMenuPanel('COLORSELECTION');

		panel.container = constructorParameter.documentContainer.document.createElement('div');
            	panel.container.id = constructorParameter.editorPlaceHolderID+'_'+panel.id;
            	panel.container.className = 'rtePanel';
		panel.container.style.display = (panel.visible)?'block':'none';
		panel.onRefresh = refreshPanel;
		self.menu.panel.add(panel);
            
		var captionContainer = constructorParameter.documentContainer.document.createElement('div');
		captionContainer.className = 'rtePanelCaption';
            
		panel.caption = constructorParameter.documentContainer.document.createElement('div');
		panel.caption.className = 'rtePanelCaptionText';
		panel.caption.innerHTML = 'Color selection';

		captionContainer.appendChild(panel.caption);
            
            	var captionButton = constructorParameter.documentContainer.document.createElement('a')
            	captionButton.className = 'rtePanelCaptionCloseButton';
            	captionButton.href = 'javascript://';	
		self.prototype.registerEvent(captionButton,'click', hidePanel);	

           	captionContainer.appendChild(captionButton);

            	panel.container.appendChild(captionContainer);
           	panel.container.appendChild(renderColorSelection(constructorParameter.documentContainer.document,9,setColor));
                        
            	container.appendChild(panel.container);

		//refresh menu	
		refreshMenu();
	}

	function refreshPanel(panel)
	{
		var buttonHTML = self.menu.button.findById('HTML');
		var buttonEnabled = (panel.button)?panel.button.enabled:true; //set false branch to true to enable panels visible on page load

		panel.container.style.display = (panel.visible && buttonEnabled && !buttonHTML.active)?'block':'none';
	}

	function hidePanel(e)
	{
		var sender = (e.srcElement)?e.srcElement:e.target;
		var domPanel = sender.parentNode.parentNode;
		var domPanelId = domPanel.id.split('_');

		var objPanel = self.menu.panel.find(domPanelId[domPanelId.length-1]);

		if (objPanel.visible)
		{
			toggleLayer(objPanel.container.id);
		}

		objPanel.button.active = false;
		objPanel.data = '';
		objPanel.visible = false;

		refreshMenu();			
	}

	      function setColor(e)
		{
			var color = (e.srcElement)?e.srcElement.style.backgroundColor:e.target.style.backgroundColor;

			if (self.menu.panel.findById('COLORSELECTION').data)
			{
				self.prototype.selectedObject.setForeColor(color);
			}
			else
			{
				self.prototype.selectedObject.setBackColor(color);
			}
		}

	function filterHTMLCode(value)
	{
	    var HTML = value;
	    
	    if (constructorParameter.urlFilterEnabled) { HTML = self.filterURI(HTML,true); }
	    
		return HTML;
	}

    //public
	this.prototype = new TEditor(); //inheritance is represented by assigning a instance of the base class to "prototype"
	this.menu = new TRTEMenu();

		this.filterURI = function(value,usePrefix)
	{
		var result = value;
		var c = 0;
		var url = '';
		var regularExpression = null;
		var prefix = '';

		while (c <= 1)
		{
			switch (c)
			{
					case 0 : url = constructorParameter.adminURL; 
				break;	case 1 : url = constructorParameter.siteURL;
			}

			//replace href
			prefix = (usePrefix)?' href="':'';
			regularExpression = new RegExp(prefix+url+'/','gi');
			result = result.replace(regularExpression,prefix);

			//replace src
			prefix = (usePrefix)?' src="':'';
			regularExpression = new RegExp(prefix+url+'/','gi');
			result = result.replace(regularExpression,prefix);

			c++;	
		}

		return result;	
	}

	this.applyLinkConfiguration = function(link,modify,processText,href,text,title)
	{
		var range = self.prototype.selectedObject.getObject();

		link.href = href;
		
		if (document.all)
		{
			//todo: opera doesnt want to work at all here
			if (processText) { link.innerText = text; }
		
			if (!modify) 
			{ 
				//ensure that something is selected before execCommand is executed
				if (range.text.length == 0)
				{
					range.text = link.innerText;
					range.moveStart('character', -link.innerText.length);
				}

				range.execCommand('CreateLink',false,link.href);

				link = range.parentElement();

				range.collapse(true);
				range.select();
			}

			link.title = title;
		}
		else
		{
			if (processText) { link.textContent = text; }

			link.title = title;

			range.deleteContents();
			if (!modify) { range.insertNode(link); }
		}
	}

	this.applyImageConfiguration = function(image,modify,src,alt)
	{
		var range = self.prototype.selectedObject.getRange();
		var element = (document.all)?range.parentElement():range.startContainer.parentNode;

		if (!modify) 
		{ 	
			if (element.tagName.toLowerCase() == 'a')
			{
				if (document.all) { element.innerText = ''; } else { element.textContent = ''; }
			}
		}

		var altAttribute = self.prototype.getDocument().createAttribute('alt');
		altAttribute.value = alt;

		var borderAttribute = self.prototype.getDocument().createAttribute('border');
		borderAttribute.value = '0';

		image.src = src;

		if (document.all)
		{
			if (!modify) 
			{ 	
				range.execCommand('InsertImage',false,image.src);

				//now cover image in range to set additional properties later
				range.moveStart('character',-1);

				image = range.parentElement();
			}

			image.attributes.setNamedItem(altAttribute);
			image.attributes.setNamedItem(borderAttribute);
		}
		else
		{
			image.attributes.setNamedItem(altAttribute);
			image.attributes.setNamedItem(borderAttribute);

			range.deleteContents();
			range.insertNode(image)
		}
	}

	this.showLinkConfigurationDialog = function(sender,link,modify,processText)
	{
		//override this function to customize link configuration (to apply link configuration call applyLinkConfiguration())
	}

	this.showImageConfigurationDialog = function(sender,image,modify)
	{
		//override this function to customize image configuration (to apply link configuration call applyImageConfiguration())
	}

	this.saveContent = function(eventObject)
	{
		//if editor is in html mode set editor back to design mode to get html code correctly
		if (!self.prototype.getDesignMode())
		{
			self.prototype.setDesignMode(true);
		}

		var frame = window.frames[constructorParameter.editorPlaceHolderID+'IFrame'];
		//check innerText to have text only, doesnt works on all browsers
		var s = (constructorParameter.documentContainer.document.all)?frame.document.body.innerText:frame.document.body.textContent;

		//trim of leading and trailing spaces
		if (s.length > 0)
		{
			while (s.substr(0,1) == ' ')
			{
				s = s.substr(1,s.length);
			}
		}
		
		if (s.length > 0)
		{
			while (s.substr(s.length-1,1) == ' ')
			{
				s = s.substr(0,s.length-1);
			}
		}

		if (s.length > 0)
		{
			constructorParameter.documentContainer.document.getElementById(constructorParameter.editorPlaceHolderID).value = self.prototype.filterHTMLCode(frame.document.body.innerHTML);	
			
			//alert('ID: '+constructorParameter.editorPlaceHolderID);				
			//alert('Name: '+constructorParameter.documentContainer.document.getElementById(constructorParameter.editorPlaceHolderID).name);
			//alert('Object: '+constructorParameter.documentContainer.document.getElementById(constructorParameter.editorPlaceHolderID));
			//alert('Value: '+constructorParameter.documentContainer.document.getElementById(constructorParameter.editorPlaceHolderID).value);
			//alert('HTML: '+self.prototype.filterHTMLCode(frame.document.body.innerHTML));				
		}
		else
		 {
			constructorParameter.documentContainer.document.getElementById(constructorParameter.editorPlaceHolderID).value = '';
		}
			
	}

this.create = function(parameter)
        {
		self.prototype.htmlCodeEditable = true;
		self.prototype.OnElementSelected = refreshMenu;
		self.prototype.filterHTMLCode = filterHTMLCode;

//we must initialize editor in onload to get mozilla 2 workin, can't call prototype intialization directly
			self.prototype.registerEvent(window,'load', initialize);			
			//alert(parameter.documentForm);
			//alert(self.saveContent);
			// bei click wirds geschrieben			
			// submit geht hier nicht
			self.prototype.registerEvent(parameter.documentForm, 'click', self.saveContent);
			//self.prototype.registerEvent(parameter.documentForm, 'submit', self.saveContent);

            //build editor control on client side to save traffic and to handle events without javascript: or stuff like that
            var textarea = parameter.documentContainer.document.getElementById(parameter.editorPlaceHolderID);
		if (textarea)
	{
           var rteAttribute;
            
            var rteContainer = parameter.documentContainer.document.createElement('div');
            rteContainer.className = 'rteContainer';
		rteContainer.style.width = parameter.editorWidth+'px';

	initializeMenu(rteContainer);
  
            var rteContentContainer = parameter.documentContainer.document.createElement('div');
            
            var rteContent = parameter.documentContainer.document.createElement('iframe');
            rteContent.id = parameter.editorPlaceHolderID+'IFrame';
			rteContent.name = rteContent.id;
			if (parameter.cssstyle.lenght > 0)
			{
				rteContent.style.height = parameter.editorHeight+'px';
			}
            rteContent.className = 'rteContent';
            
			//alert(parameter.cssstyle);
						
            rteAttribute = parameter.documentContainer.document.createAttribute("frameborder");
            rteAttribute.value = '0';
            rteContent.attributes.setNamedItem(rteAttribute);
            rteContentContainer.appendChild(rteContent);
            rteContainer.appendChild(rteContentContainer);
            
            //rteAtrributeStyle = parameter.documentContainer.document.createAttribute("style");
			//rteAtrributeStyle.setAttribute("style",parameter.cssstyle);
			//rteContent.setAttribute("style",parameter.cssstyle);
			//rteContent.attributes.setNamedItem(rteAtrributeStyle);
            //rteContentContainer.appendChild(rteContent);
            //rteContainer.appendChild(rteContentContainer);			
						
			textarea.style.display = 'none';
			textarea.parentNode.insertBefore(rteContainer,textarea);

			iFrame = parameter.documentContainer.document.getElementById(rteContent.id);

            if (iFrame) //when iframe exists then browser handles the iframe internaly as a frame, so continue
            {
			//http://www.mozilla.org/editor/ie2midas.html

			var frame = window.frames[rteContent.id];
			var doc = frame.document.open('text/html', 'replace');
			//iFrame.setAttribute("style",parameter.cssstyle);

			//we can only include one css because ie doesnt end loading document (therefore no raising of onload event) when using more than 1 css, bug?!?
			var html = '<html>\n'+
					'<head>\n'+
						'<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">\n'+
						'<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">\n'+
						'<META HTTP-EQUIV="Expires" CONTENT="-1">\n'+
						'<link type="text/css" rel="stylesheet" href="'+parameter.urlCss+'/Content.css" />\n'+
					'</head>\n'+
					'<body class="bodyEditorDesignMode">'+parameter.documentContainer.document.getElementById(parameter.editorPlaceHolderID).value+'</body>\n</html>';

                	doc.write(html);
	                doc.close();

			
	    }  

	} 


       }

	self.create(parameter);
}


		

		