var RadE_HasRules = false;
if (typeof(RadEditorCommandList) == "undefined")
{
	RadEditorCommandList = new Array();
}

/* 
start UNIBZ custom commands 
=================================================================
*/
// bug fix of "Error while executing filter MakePathsAbsolute - [object error]"
RadEditorNamespace.MakePathsAbsolute.prototype._updateElements = function(contentElement, tagName, attrName)
{
    var tempDiv = contentElement.ownerDocument.createElement("div");
    var elements = this._getElements(contentElement, tagName);
    if (elements)
    {
        for (var i=0;i<elements.length;i++)
        {
            var attrValue = elements[i].getAttribute(attrName, 2);
            if ("href" == attrName && attrValue)
            {
                tempDiv.innerHTML = "<a href=\""+attrValue.replace(/\"/gi,"%22") + "\">test</a>";
                if (window.RadControlsNamespace.Browser.IsIE)
                {
                    var origContent = elements[i].innerHTML;
                }
                elements[i].setAttribute("href", tempDiv.childNodes[0].getAttribute("href", 2));
                if (window.RadControlsNamespace.Browser.IsIE)
                {
                    //IE only issue - when setting the href attribute of a link and the link text also looks
                    //like a link/email then the text is overridden with the new href. We need to restore the 
                    //original content
                    if ((origContent.indexOf("www.") == 0 && elements[i].innerHTML.match("[a-z]+://")) ||
                        (origContent.indexOf("mailto:") == -1 && elements[i].innerHTML.match("mailto:")))
                    {
                        elements[i].innerHTML = origContent;
                    }
                }
            }
            else if ("src" == attrName && attrValue)
            {
                tempDiv.innerHTML = "<img src=\""+attrValue.replace(/\"/gi,"%22") + "\" />";
                elements[i].setAttribute("src", tempDiv.childNodes[0].src);
            }
        }
    }
    tempDiv.innerHTML = "";
    tempDiv = null;
}


// KaL: used for stripping existing html tags from selection
function StripCurrentFormatting(editor)
{
        myTool = new Object();
        
        myTool.GetSelectedValue = function() { return "FONT"; }
        editor.Fire("FormatStripper", myTool); 
}

// KaL: removes css class attribute from a html element
function RemoveClassNameFromElement(elementToChange)
{
    if (elementToChange && elementToChange.tagName && (elementToChange.tagName.toUpperCase() == "SPAN" || elementToChange.tagName.toUpperCase() == "FONT"))
    {               
        if (elementToChange.className != "")
        {
            elementToChange.className = "";
        }
    }  
}

RadEditorCommandList["UnibzTest"] = function(commandName, editor, oTool)
{
    
}

// Clears the whole content area
RadEditorCommandList["UniBzClearStyle"] = function(commandName, editor, oTool)
{	
    var ok = confirm('Are you sure you want to clear the whole content area?\n\nPlease make sure you have copied your text to another location, e.g. Notepad.');
    
    if (ok)
    {
        editor.SetHtml('<font class="ArticleText"> </font>');
    }
//    
//    var html = editor.GetSelectionHtml();
//    
//    if (html != "")    
//    {
//        StripCurrentFormatting(editor);
//    }
//    else
//    {
//        alert('Please select text first.');
//    }
}  

// insert article title
RadEditorCommandList["UniBzArticleTitle"] = function(commandName, editor, oTool)
{    
    var html = editor.GetSelectionHtml();
    
    if (html != "")    
    {      
        var elemToReplace=editor.GetSelectedElement();        
        RemoveClassNameFromElement(elemToReplace);        
        editor.ExecuteApplyCssClassCommand('ArticleTitle', GetSelectedText(editor));           
    }
    else
    {
        editor.PasteHtml ("<font class='ArticleTitle'>&nbsp;");
        var restorePoint = editor.CreateRestorePoint();
        editor.PasteHtml ("</font>");          
        restorePoint.Select(); 
    }        
}

RadEditorCommandList["UniBzArticleHeader"] = function(commandName, editor, oTool)
{	
        var html = editor.GetSelectionHtml();

        if (html != "")    
        {        
                var elemToReplace=editor.GetSelectedElement();        
                RemoveClassNameFromElement(elemToReplace);        
                editor.ExecuteApplyCssClassCommand('ArticleHeader', GetSelectedText(editor));
        }
        else
        {
            editor.PasteHtml ("<font class='ArticleHeader'>&nbsp;");
            var restorePoint = editor.CreateRestorePoint();
            editor.PasteHtml ("</font>");          
            restorePoint.Select(); 
        }	    
}

RadEditorCommandList["UniBzArticleText"] = function(commandName, editor, oTool)
{

        var html = editor.GetSelectionHtml();
        
        if (html != "")    
        {      
                var elemToReplace=editor.GetSelectedElement();        
                RemoveClassNameFromElement(elemToReplace);        
                editor.ExecuteApplyCssClassCommand('ArticleText', GetSelectedText(editor));           
        }
        else
        {
            editor.PasteHtml ("<font class='ArticleText'>&nbsp;");
            var restorePoint = editor.CreateRestorePoint();
            editor.PasteHtml ("</font>");          
            restorePoint.Select(); 
        }	  

}

RadEditorCommandList["UniBzArticleTextOnLinkList"] = function(commandName, editor, oTool)
{

        var html = editor.GetSelectionHtml();
        
        if (html != "")    
        {      
                var elemToReplace=editor.GetSelectedElement();        
                RemoveClassNameFromElement(elemToReplace);        
                editor.ExecuteApplyCssClassCommand('ArticleText', GetSelectedText(editor));           
        }
        else
        {
            editor.PasteHtml ("<font class='ArticleText'>");
            var restorePoint = editor.CreateRestorePoint();
            editor.PasteHtml ("</font>");          
            restorePoint.Select(); 
        }	  

}


RadEditorCommandList["UniBzArticleTitleHeader"] = function(commandName, editor, oTool)
{
    var html = editor.GetSelectionHtml();
    
    if (html != "")    
    {  
        alert('Sorry, but this command is not enabled for text selection.\n\n Please remove the text selection and try again.');
    }
    else
    {
        editor.PasteHtml("<font class='ArticleTitle'>Title |</font> <font class='ArticleHeader'>Subtitle</font>");
    }		
}

RadEditorCommandList["UniBzHorizontalSeparator"] = function(commandName, editor, oTool)
{
    editor.Fire("UniBzArticleTextOnLinkList");	
	editor.PasteHtml("<div class='ArticleDottedLine'></div>");
}

RadEditorCommandList["UniBzArticleList"] = function(commandName, editor, oTool)
{	
	var selectionText = editor.GetSelection();
	var text = selectionText.GetHtmlText();

	var paste = "";
	paste += "<div class='ArticleListDiv'>";
	paste += "<ul class='ArticleListItem'>";	

    paste += "<li>New element</li>";
	paste += "</ul>";
	paste += "</div>";
	editor.PasteHtml(paste);	
}

RadEditorCommandList["UniBzArticleLinkList"] = function(commandName, editor, oTool)
{	
    editor.Fire("UniBzArticleTextOnLinkList");
	var selectionText = editor.GetSelection();
	var text = selectionText.GetHtmlText();
	
	var paste = "";
	paste +=	"<div class='ArticleLinkListMain'>";
	paste +=	"<div class='ArticleDottedLine'></div>";
	paste += "<font class='ArticleHeader'>Overview</font>";
	paste += "<div class='ArticleListDiv'>";
	paste += "<ul class='ArticleListLink'>";
    paste += "<li>New element</li>";
	paste += "</ul>";
	paste += "</div>";
	paste += "<div class='ArticleDottedLine'></div>";
//	paste += "<div class='ArticleListDiv'>";
//	paste += "<ul class='ArticleListLink'>";
//  paste += "<li>New element</li>";
//	paste += "</ul>";
//	paste += "</div>";
//	paste += "<div class='ArticleDottedLine'></div>";
	paste += "</div>";
	editor.PasteHtml(paste);	
}

RadEditorCommandList["UniBzArticleLinkListNoHeader"] = function(commandName, editor, oTool)
{	
    editor.Fire("UniBzArticleTextOnLinkList");
	var selectionText = editor.GetSelection();
	var text = selectionText.GetHtmlText();
	
	var paste = "";
	paste =	"<div class='ArticleDottedLine'></div>";
	paste += "<div class='ArticleListDiv'>";

	paste += "<ul class='ArticleListLink'>";


    paste += "<li>New element</li>";

	paste += "</ul>";
	paste += "</div>";
	paste += "<div class='ArticleDottedLine'></div>";
	editor.PasteHtml(paste);	
}

RadEditorCommandList["UniBzArticleLinkListExtend"] = function(commandName, editor, oTool)
{	
    editor.Fire("UniBzArticleTextOnLinkList");	
	var paste = "";
	paste += "<font class='ArticleHeader'>Overview</font>";
	paste += "<div class='ArticleListDiv'>";
	paste += "<ul class='ArticleListLink'>";
	
	paste += "<li>New element</li>";

	paste += "</ul>";
	paste += "</div>";
	paste += "<div class='ArticleDottedLine'></div>";
	//alert(paste);
	editor.PasteHtml(paste);	
}

RadEditorCommandList["UniBzArticleLinkListExtendWithHeader"] = function(commandName, editor, oTool)
{		
    editor.Fire("UniBzArticleTextOnLinkList");
	var paste = "";
	paste += "<font class='ArticleHeader'>Overview</font>";
	paste += "<div class='ArticleListDiv'>";	
	paste += "<ul class='ArticleListLink'>";
	
	paste += "<li>New element</li>";

	paste += "</ul>";
	paste += "</div>";
	paste += "<div class='ArticleDottedLine'></div>";
	editor.PasteHtml(paste);	
}


RadEditorCommandList["UniBzArticleImagesTable"] = function(commandName, editor, oTool)
{		
    editor.Fire("UniBzArticleTextOnLinkList");
	var paste = "";
	paste += "<table cellspacing='0' cellpadding='0' class='ArticleImagesTable'>";
	paste += "<tr>";
	paste += "<td class='ArticleTableCell1'></td>";
	paste += "<td class='ArticleTableCell2'></td>";
	paste += "<td class='ArticleTableCell3'></td>";
	paste += "<td class='ArticleTableCell4'></td>";
	paste += "</tr>";
	paste += "</table>";
	editor.PasteHtml(paste);	
}

/*
///////////////////// OLDER METHODS //////////////////////

function ApplyCustomSpanTags(editor, oTool, className)
{
    
    var html = editor.GetSelectionHtml();
    if (html != "")
    {
        alert('html: ' + html);
        StripCurrentFormatting(editor, oTool);
        editor.ExecuteApplyCssClassCommand('ArticleTitle', GetSelectedText(editor));
    }
    else
    {
        var restorePoint = editor.CreateRestorePoint();
        editor.PasteHtml ("<span class='" + className + "'></span>");  
        restorePoint.Select(); 
    }	
}

	
	//this is necessary due to firefox :(
//	text = text.replace(/<br>/g, "<BR>");

//	var lines = null;
//	lines = text.split("<BR>");		

//	for (var i = 0; i < lines.length; i++)
//	{
//		paste += "<li>" + lines[i] + "</li>";		
//	}


*/




/* 
end UNIBZ custom commands 
=================================================================
*/

/* 
start EURAC custom commands 
=================================================================
*/


//image on the left - text on the right
RadEditorCommandList["EuracLayoutImgTxt"] = function(commandName, editor, oTool)
{	
	var selectionText = editor.GetSelection();
	var text = selectionText.GetHtmlText();

	var paste = "";
	paste += "<br class='lineBreak'>";
	paste += "<div class='cstLayout'>";
	
	paste += "<div class='cstLayoutImageSx'>";	
    paste += "</div>";
    
	paste += "<div class='cstLayoutContentDx'>";
	paste += "<span class='topic'>[INSERT TOPIC]</span>";
	paste += "<h1>[INSERT TITLE]</h1>";
	paste += "<p>[INSERT TEXT]</p>";
	paste += "</div>";
	
	paste += "</div>";
	
	paste += "<br class='lineBreak'>";
	editor.PasteHtml(paste);	
}

//text on the left - image on the right
RadEditorCommandList["EuracLayoutTxtImg"] = function(commandName, editor, oTool)
{	
	var selectionText = editor.GetSelection();
	var text = selectionText.GetHtmlText();

	var paste = "";
	paste += "<br class='lineBreak'>";
	paste += "<div class='cstLayout'>";
	
	paste += "<div class='cstLayoutContentSx'>";
	paste += "<span class='topic'>[INSERT TOPIC]</span>";
	paste += "<h1>[INSERT TITLE]</h1>";
	paste += "<p>[INSERT TEXT]</p>";
	paste += "</div>";
	
	paste += "<div class='cstLayoutImageDx'>";	
    paste += "</div>";
	
	paste += "</div>";
	
	paste += "<br class='lineBreak'>";
	editor.PasteHtml(paste);	
}

//two images cols on top - to cols text on bottom
RadEditorCommandList["EuracLayoutImgImg_TxtTxt"] = function(commandName, editor, oTool)
{	
	var selectionText = editor.GetSelection();
	var text = selectionText.GetHtmlText();

	var paste = "";
	paste += "<br class='lineBreak'>";
	paste += "<div class='cstLayout'>";
	
	paste += "<div class='cstLayoutImageSx'>";	
    paste += "</div>";
	
	paste += "<div class='cstLayoutImageDx'>";	
    paste += "</div>";
	
	paste += "</div>";
	
	paste += "<br class='lineBreak'>";
	
	paste += "<div class='cstLayout'>";
	
	paste += "<div class='cstLayoutContentSx'>";
	paste += "<span class='topic'>[INSERT TOPIC]</span>";
	paste += "<h1>[INSERT TITLE]</h1>";
	paste += "<p>[INSERT TEXT]</p>";
	paste += "</div>";
	
	paste += "<div class='cstLayoutContentDx'>";
	paste += "<span class='topic'>[INSERT TOPIC]</span>";
	paste += "<h1>[INSERT TITLE]</h1>";
	paste += "<p>[INSERT TEXT]</p>";
	paste += "</div>";
	
	paste += "</div>";
	editor.PasteHtml(paste);	
}

/* 
end EURAC custom commands 
=================================================================
*/
RadEditorCommandList["MOSSRightToLeft"] = function(commandName, editor, oTool)
{
	Telerk_MOSS_SetDirectionOfSelection(editor,"rtl");
}

RadEditorCommandList["MOSSLeftToRight"] = function(commandName, editor, oTool)
{
	Telerk_MOSS_SetDirectionOfSelection(editor,"ltr");
}

RadEditorCommandList["MOSSHelp"] = function(commandName, editor, oTool)
{
	HelpWindowKey('WCMHTMLEditor');
}

RadEditorCommandList["ToggleSource"] = function(commandName, editor, oTool)
{
	//todo: call the source dialog as the MOSS editor does
	editor.SetMode(2);
}

RadEditorCommandList["MOSSInsertTable"] = function(commandName, editor, oTool)
{
	//todo: change the dialog to use the moss default (after firefox is fixed)
	editor.Fire("TableWizard");
}

RadEditorCommandList["MOSSImageManager"] = function(commandName, editor, oTool)
{
	var docEditor = editor.Document;
	var params = editor.GetDialogParameters("MOSSParams");
	var configObj=new AssetPickerConfig("");
	configObj.ClientID=editor.Id;
	configObj.DefaultAssetLocation="";
	configObj.DefaultAssetImageLocation="";
	configObj.CurrentWebBaseUrl=params["CurrentWebBaseUrl"];
	configObj.ManageHyperlink=false;
	configObj.AllowExternalUrls=params["AllowExternalUrls"];
	var bInserting=false;
	var elemToReplace=null;
	var imageAssetObj=new ImageAsset("");

	elemToReplace=editor.GetSelectedElement();
	if (elemToReplace && elemToReplace.tagName && elemToReplace.tagName.toUpperCase() == "BODY")
	{
		//if there is no selection or selection is the whole content body
		elemToReplace = null;
	}
	var elemImage=FormJSRTE_GetNearestContainingParentElementOfTypes(editor.ContentWindow.frameElement.id, elemToReplace, new Array("IMG"));
	if(!elemImage)
	{
		bInserting=true;
		elemImage=docEditor.createElement("IMG");
		elemImage.border=0;
	}
	configObj.ReturnCallback=function(newAssetUrl, newAssetText, currentConfig, dialogReturnedData)
	{
		if (dialogReturnedData)
		{
			if (bInserting)
			{
				var tempDiv = docEditor.createElement("DIV");
				tempDiv.appendChild(elemImage);
				editor.PasteHtml(tempDiv.innerHTML);
				tempDiv = null;
			}
		}
	}
	var dialogReturnedData=imageAssetObj.LaunchModalDialogOnElement(configObj, elemImage, true, !bInserting );
}

RadEditorCommandList["MOSSLinkManager"] = function(commandName, editor, oTool)
{
	var docEditor = editor.Document;
	var params = editor.GetDialogParameters("MOSSParams");
	var configObj=new AssetPickerConfig("");
	configObj.ClientID=editor.Id;
	configObj.DefaultAssetLocation="";
	configObj.DefaultAssetImageLocation="";
	configObj.CurrentWebBaseUrl=params["CurrentWebBaseUrl"];
	configObj.AllowExternalUrls=params["AllowExternalUrls"];
	var bInserting=false;
	var elemToReplace=null;
	var linkAsset=new LinkAsset("");
	var innerLinkHTML=null;
	linkAsset.ManageLinkDisplayText=false;
	var elemLink=FormJSRTE_GetNearestContainingParentElementOfTypes(editor.ContentWindow.frameElement.id, editor.GetSelectedElement(), new Array("A"));
	if(!elemLink)
	{
		bInserting=true;
		elemLink=docEditor.createElement("A");
		if (elemLink==null) return;
		var editorSelection = editor.GetSelection();
		if (editorSelection.IsControl())
		{
			elemToReplace=editor.GetSelectedElement();
		}
		else
		{
			innerLinkHTML = editorSelection.GetHtmlText();
		}
	}
	else
	{
		innerLinkHTML=elemLink.innerHTML;
	}
	configObj.ReturnCallback=function(newAssetUrl, newAssetText, currentConfig, dialogReturnedData)
	{
		if (dialogReturnedData)
		{
			var linkText = "";
			if (editor.IsIE)
				linkText = elemLink.innerText;
			else
				linkText = elemLink.textContent;
			if(innerLinkHTML && innerLinkHTML != "")
			{
				elemLink.innerHTML=innerLinkHTML;
			}
			else if(linkText == "")
			{
				if(linkAsset.AssetText && linkAsset.AssetText !="")
				{
					linkText=linkAsset.AssetText;
				}
				else
				{
					linkText=linkAsset.AssetUrl;
				}
				elemLink.innerHTML += linkText;
			}
			if (elemToReplace !=null)
			{
			    var parentEl = elemToReplace.parentNode;
				elemLink.innerHTML="";
				parentEl.insertBefore(elemLink, elemToReplace);
				elemLink.appendChild(elemToReplace);
				linkAsset.FixupIconsAndEmptyAnchors(elemLink);
				return;
			}
			else if (bInserting)
			{
				var selection=docEditor.selection;
				if (selection !=null)
				{
					var textRange=selection.createRange();
					if (textRange !=null)
					{
						var text=textRange.text;
						if (text && text !="" && !text.match(/^\s+$/))
						{
							textRange.execCommand("Unlink");
							elemLink.innerHTML=textRange.htmlText;
							linkAsset.FixupIconsAndEmptyAnchors(elemLink);
						}
						var tempDiv = docEditor.createElement("DIV");
						tempDiv.appendChild(elemLink);
						textRange.pasteHTML(tempDiv.innerHTML);
					}
				}
				else
				{
					//if we cannot get the selection, use the editor paste function instead
					var tempDiv = docEditor.createElement("DIV");
					tempDiv.appendChild(elemLink);
					editor.PasteHtml(tempDiv.innerHTML);
					tempDiv = null;
				}
			}
			else
			{
				linkAsset.FixupIconsAndEmptyAnchors(elemLink);
			}
		}
	}
	linkAsset.LaunchModalDialogOnElement(configObj, elemLink, true, !bInserting );
}

RadEditorCommandList["MOSSTemplateManager"] = function (commandName, editor, oTool)
{
	if (!RadE_HasRules)
	{
		RTE2_InstantiateStaticSafeHtmlRules();
		RadE_HasRules = true;
	}
	var docEditor = editor.Document;
	var params = editor.GetDialogParameters("MOSSParams");
	var configObj=new AssetPickerConfig("");
	configObj.ClientID=editor.Id;
	configObj.DefaultAssetLocation="";
	configObj.CurrentWebBaseUrl=params["CurrentWebBaseUrl"];
	configObj.AllowExternalUrls=params["AllowExternalUrls"];
	var bInserting=false;
	var elemToReplace=null;
	var fragmentId=null;
	var elemViewToEdit=FormJSRTE_GetNearestContainingParentElementOfTypes(editor.ContentWindow.frameElement.id, editor.GetSelectedElement(), new Array("SPAN"));
	if ((elemViewToEdit !=null) && (elemViewToEdit.id==g_strRTE2ReusableFragmentCommonToken))
	{
		fragmentId=elemViewToEdit.getAttribute("fragmentid");
	}
	var dialogInput=new Object();
	dialogInput.fragmentId=fragmentId;
	var callback=function(dialogOutput)
	{
		if ((dialogOutput !=null) && (dialogOutput.fragmentView !=null))
		{
			var selection=docEditor.selection;
			if (selection !=null)
			{
				if (selection.type=="Control")
				{
					var controlRange=selection.createRange();
					if (controlRange !=null)
					{
						controlRange.execCommand("Delete");
					}
				}
				if (selection.type !="Control")
				{
					var textRange=selection.createRange();
					if (textRange !=null)
					{
						var safeHtmlDocument=RadE_CreateTemporaryDocument();
						safeHtmlDocument.body.innerHTML=dialogOutput.fragmentView;
						var elements=RTE2_GetAllElements(safeHtmlDocument);
						//setting these to hardcoded values since they are not passed in the params[] array yet.
						var instanceVariables = new Object();
						instanceVariables.EditorOpenFromWebPart = false;
						instanceVariables.DisableCustomStyles = false;
						RTE2_ApplyContentFilters(elements, instanceVariables);
						textRange.pasteHTML(dialogOutput.fragmentView);
						RTE2_AlterReusableFragmentHighlights(docEditor.body, "ms-reusableTextView");
					}
				}
			}
			else
			{
				editor.PasteHtml(dialogOutput.fragmentView);
				RTE2_AlterReusableFragmentHighlights(docEditor.body, "ms-reusableTextView");
			}
		}
	};
	var dialogUrl=params["CurrentWebBaseUrl"]+"/_layouts/ReusableTextPicker.aspx";
	commonShowModalDialog(dialogUrl, "dialogHeight:600px; dialogWidth:800px; center:yes; resizable:yes; scroll:no; status:no;", callback, dialogInput);
}

/* support functions */
if (typeof(RadEditor) == "undefined")
{
	RadEditor = function () {};
}

RadEditor.EncodeUrl = function(url)
{
	if (window.encodeURIComponent)
	{
		return encodeURIComponent(url);
	}
	
	if (window.escape)
	{
		return escape(url);	
	}
	
	return url;
}

function GetDialogArguments(editor, commandName)
{
	var args = editor.GetDialogParameters(commandName);
	var argStr = "";
	for (var item in args)
	{
		argStr += "&" + item + "=" + RadEditor.EncodeUrl(args[item]);
	}
	return argStr;
}

function Telerk_MOSS_SetDirectionOfSelection(editor, strDirection)
{
	var rngSelection=editor.GetSelection();
	var strTagNames;
	strTagNames="|H1|H2|H3|H4|H5|H6|P|PRE|TD|DIV|BLOCKQUOTE|DT|DD|TABLE|HR|IMG|BODY|TR|UL|OL|";
	if (rngSelection.GetParentElement())
	{
		var elemSelectionParent=rngSelection.GetParentElement();
		while ((elemSelectionParent !=null) && (strTagNames.indexOf("|"+elemSelectionParent.tagName+"|")==-1))
		{
			elemSelectionParent=elemSelectionParent.parentNode;
		}
		if (elemSelectionParent)
		{
			Telerik_MOSS_SetDirectionOnElement(elemSelectionParent, strDirection);
		}
	}
}

function Telerik_MOSS_SetDirectionOnElement(element, strDirection)
{
	if ("ltr"==strDirection)
	{
		element.dir="ltr";
		element.align="left";
	}
	else if ("rtl"==strDirection)
	{
		element.dir="rtl";
		element.align="right";
	}
}

function RadE_CreateTemporaryDocument()
{
	// creating a temporary document for storing template content
	var iframe = document.createElement('iframe');
	document.body.appendChild(iframe);
	iframe.src = "javascript:'<html></html>'";
	iframe.frameBorder = '0';
	iframe.style.width = "0px";
	iframe.style.height = "0px";
	var doc = iframe.contentWindow.document;
	doc.open();
	doc.writeln('<head><style></style></head><body></body>');
	doc.close();
	if (!doc.body)
	{
		var oBody = doc.createElement("body");
		doc.appendChild(oBody);
	}
	if (doc.getElementsByTagName("head").length < 1)
	{
		var oHead = doc.createElement("head");
		oHead.style.visibility = "hidden";
		doc.body.parentNode.insertBefore(oHead, doc.body);
	}
	return doc;
}


function FormJSRTE_GetNearestContainingParentElementOfTypes(strBaseElementID, elem, aTagNames)
{
//this code belongs in form.js, however it is copied here as well since in some pages form.js is not loaded by default.
	var aTagNames_length=aTagNames.length;
	if (elem==null) return null;
	for (var i=0; i<aTagNames_length; i++)
	{
		if (elem.tagName==aTagNames[i])
		{
			return elem;
		}
	}
	var elemParent=elem.parentNode;
	while (elemParent !=null)
	{
		if (elemParent.id==strBaseElementID)
		{
			return null;
		}
		for (var i=0; i<aTagNames_length; i++)
		{
			if (elemParent.tagName==aTagNames[i])
			{
				return elemParent;
			}
		}
		elemParent=elemParent.parentNode;
	}
	return null;
}


