<%@ Page Language="C#" EnableEventValidation="false" EnableViewState="false" EnableViewStateMac="false" Inherits="Bitrix.UI.BXPage" ValidateRequest="False"%>

<%@ Import Namespace="Bitrix.Common" %>
<%@ Import Namespace="System.Text" %>
<%@ Import Namespace="Bitrix.Services" %>
<%@ Import Namespace="System.Collections" %>
<%@ Import Namespace="System.Collections.Generic" %>
<%@ Import Namespace="System.Text.RegularExpressions" %>

<script runat="server" type="text/C#">
	string DialogName;
	bool show_controls;
	HtmlTextWriter w;
	protected override void OnInit(EventArgs e)
	{
		base.OnInit(e);
		DialogName = Bitrix.Services.Text.BXTextEncoder.HtmlTextEncoder.Encode(Request.QueryString["name"]);
		show_controls = Request.QueryString["not_use_default"] == "Y" ? false : true;
	}

	protected override void Render(HtmlTextWriter writer)
	{
		w = writer;
		base.Render(writer);
	}
</script>
<form id="Form1" runat="server">

<script>
window.__OnLoad = function()
{
	try{	
	if (OnLoad)
		OnLoad();
	jsFloatDiv.AdjustShadow(document.getElementById('BX_editor_dialog'));
	
	window.JSName = window[window._fileDialog.JSName];
	window.ExtraJSName = window[window._fileDialog.ExtraJSName];
	}catch(e){}
}

//var iNoOnSelectionChange = 1;
//var iNoOnChange = 2;

window.__OnSave = function()
{	
	//try{
	var r = typeof(OnSave) == "function" ? OnSave() : false;
	if((r & 'NoOnSelectionChange') != 0)
	{
		pObj.pMainObj.OnEvent("OnSelectionChange", ["always"]);
	}
	pObj.Close();
	//}catch(e){}
}

window.__OpenDialog = function(oParams, callBack)
{
	ExtraJSName.Properties = oParams || {ShowFiles: true, ItemsToSelect: 2, ExtensionsList: 'aspx,html'};
	ExtraJSName.SaveEvent = function(){callBack(ExtraJSName.GetTargetValue());};
	JSName.ShowPopupDialog();
	ExtraJSName.Reset();
	ExtraJSName.CollapseToRoot();
	return false;
}

function OnLoad(){}
function OnSave(){}
</script>

<table border = "0" style="width: 100%; height: 100%;"><tr><td style="vertical-align: top !important;">
<%
// * * * * * * * * *  DIALOGS  * * * * * * * * * * * *
if (DialogName == "anchor") { %>
<script>
var pElement = null;
function OnLoad()
{
	pElement = pObj.pMainObj.GetSelectionObject();
	var el = document.getElementById("anchor_value");
	if(pElement && pElement.getAttribute("__bxtagname")=="anchor")
	{
		oDialogTitle.innerHTML = '<%= GetMessage("Anchor.WindowTitle.Edit") %>';
		var val = BXUnSerialize(pElement.getAttribute("__bxcontainer"));
		el.value = val.name;
	}
	else
	{
		oDialogTitle.innerHTML = '<%= GetMessage("Anchor.WindowTitle.New") %>';
		el.value = "";
	}
	
	el.focus();
}

function OnSave()
{
	BXSelectRange(oPrevRange, pObj.pMainObj.pEditorDocument, pObj.pMainObj.pEditorWindow);
	pElement = pObj.pMainObj.GetSelectionObject();
	pObj.pMainObj.bSkipChanges = true;
	var anchor_value = document.getElementById("anchor_value");
	if(pElement && pElement.getAttribute && pElement.getAttribute("__bxtagname")=="anchor")
	{
		if(anchor_value.value.length <= 0)
			pObj.pMainObj.executeCommand('Delete');
		else
			pElement.setAttribute("__bxcontainer", BXSerialize({"name":anchor_value.value}));
	}
	else
	{
		if(anchor_value.value.length > 0)
		{
			var tmp_id = Math.random().toString().substring(2);
			pObj.pMainObj.insertHTML('<img id="'+tmp_id+'" src="' + one_gif_src + '" style="background-image: url(' + global_iconkit_path + '); background-position: -260px 0; height: 20px; width: 20px"  __bxtagname="anchor" __bxcontainer="'+bxhtmlspecialchars(BXSerialize({name : anchor_value.value}))+'" />');
			var pComponent = pObj.pMainObj.pEditorDocument.getElementById(tmp_id);
			pComponent.removeAttribute('id');
			if(pObj.pMainObj.pEditorWindow.getSelection)
				pObj.pMainObj.pEditorWindow.getSelection().selectAllChildren(pComponent);
		}
	}
	pObj.pMainObj.bSkipChanges = false;
	pObj.pMainObj.OnChange("anchor");
}
</script>
<div class="inner_content">
<%= GetMessage("Anchor.Name")+ ":" %>
<input type="text" size="30" value="" id="anchor_value" style="width: 180px;" />
</div>
<% } else if (DialogName == "link") { %>
<script>
function OnLoad()
{
	pElement = window.BXFindParentByTagName(pObj.pMainObj.GetSelectionObject(), 'A');
	window.oDialogTitle.innerHTML = pElement ? '<%= GetMessage("Link.WindowTitle.Edit") %>' : '<%= GetMessage("Link.WindowTitle.New") %>';
	
	// Set CSS Styles
	var arStFilter = ['A', 'DEFAULT'], i;
	var elStyles = document.getElementById("bx_link_classname");
	var oOption = new Option("", "", false, false);
	elStyles.options.add(oOption);
	var arStyles;
	for(i = 0; i < arStFilter.length; i++)
	{
		arStyles = pObj.pMainObj.oStyles.GetStyles(arStFilter[i]);
		for(var j=0; j<arStyles.length; j++)
		{
			if(arStyles[j].className.length<=0)
				continue;
			oOption = new Option(arStyles[j].className, arStyles[j].className, false, false);
			elStyles.options.add(oOption);
		}
	}

	// Get array of anchors
	var arAnchs = [], anc;
	var arImgs = pObj.pMainObj.pEditorDocument.getElementsByTagName('IMG');
	for(i=0; i<arImgs.length; i++)
	{
		if(arImgs[i].getAttribute("__bxtagname") && arImgs[i].getAttribute("__bxtagname")=="anchor")
		{
			anc = BXUnSerialize(arImgs[i].getAttribute("__bxcontainer"));
			arAnchs.push(anc.name);
		}
	}
	
	el = document.getElementById('bx_link_url3');
	for(i = 0; i < arAnchs.length; i++)
	{
		oOption = new Option(arAnchs[i], '#'+arAnchs[i], false, false);
		el.options.add(oOption);
	}

	var tip = 1;

	if(pElement)
	{
		if(pElement.tagName.toLowerCase() == 'a')
		{
			oPrevRange = pObj.pMainObj.SelectElement(pElement);
			var href = pElement.getAttribute("href", 2), el, tip;
			if(href.substring(0, 7).toLowerCase() == 'mailto:')
			{
				tip = 4;
				document.getElementById("bx_link_url4").value = href.substring(7);
			}
			else if(href.substr(0, 1) == '#')
			{
				tip = 3;
				el = document.getElementById("bx_link_url3");
				var bF = false;
				for(i=0; i<el.options.length; i++)
				{
					if(el.options[i].value == href)
					{
						el.selectedIndex = i;
						bF = true;
						break;
					}
				}

				 if(!bF)
				 {
				 	tip = 1;
					document.getElementById("bx_link_url1").value = href;
				 }
			}
			else if(href.substring(0, 7) == 'http://')
			{
				tip = 2;
				document.getElementById("bx_link_url2").value = href.substring(7);
				document.getElementById("bx_link_url_type").selectedIndex = 0;
			}
			else if(href.substring(0, 6) == 'ftp://')
			{
				tip = 2;
				document.getElementById("bx_link_url2").value = href.substring(6);
				document.getElementById("bx_link_url_type").selectedIndex = 1;
			}
			else if(href.substring(0, 8) == 'https://')
			{
				tip = 2;
				document.getElementById("bx_link_url2").value = href.substring(8);
				document.getElementById("bx_link_url_type").selectedIndex = 2;
			}
			else
			{
				document.getElementById("bx_link_url1").value = href;
			}
			if(pElement.className)
			{
				el = document.getElementById("bx_link_classname");
				for(i=0; i<el.length; i++)
				{
					if(el[i].value==pElement.className)
					{
						el.selectedIndex = i;
						break;
					}
				}
			}
			if(pElement.target)
			{
				el = document.getElementById("bx_target");
				var el2 = document.getElementById("bx_targ_list");
				switch(pElement.target.toLowerCase())
				{
				case '_blank':
					el2.selectedIndex = 1;
					break;
				case '_parent':
					el2.selectedIndex = 2;
					break;
				case '_self':
					el2.selectedIndex = 3;
					break;
				case '_top':
					el2.selectedIndex = 4;
					break;
				}
				_ChTargL();
				el.value = pElement.target;
			}

			document.getElementById("bx_link_id").value = pElement.id;
			document.getElementById("bx_link_title").value = pElement.title;

			el = document.getElementById('bx_link_type');
			el.selectedIndex = tip-1;
		}
	}
	
	_Ch();
	
	if(el = document.getElementById('bx_link_url'+tip))
		el.focus();
	
	
	//document.getElementById("bx_link_type").onchange = function(){ alert("_Ch"); _Ch(); };
	jsUtils.addEvent(document.getElementById("bx_link_type"), "change", _Ch);
	document.getElementById("bx_file_dialog_button").onclick = function()
	{
		__OpenDialog(
			{
				ShowFiles: true,
				ItemsToSelect: 2,
				ExtensionsList: '',
				EnableExtras: true,
				DefaultUploadDirectory: ""
			},
			function(val)
			{
				document.getElementById("bx_link_url1").value = val;
			}
		);
	};
}

function OnSave()
{
	var href = '', target = '', h;
	switch(document.getElementById('bx_link_type').selectedIndex)
	{
		case 0:
			href = document.getElementById('bx_link_url1').value;
			break;
		case 1:
			href = document.getElementById('bx_link_url2').value;
			h = document.getElementById("bx_link_url_type").value;
			if(h.length > 0)
				href = h + href;
			break;
		case 2:
			href = document.getElementById('bx_link_url3').value;
			break;
		case 3:
			h = document.getElementById('bx_link_url4').value;
			if(h.length > 0)
				href = 'mailto:' + h;
			break;
	}
	
	BXSelectRange(oPrevRange, pObj.pMainObj.pEditorDocument, pObj.pMainObj.pEditorWindow);
	pObj.pMainObj.bSkipChanges = true;
	
	if(href.length>0)
	{
		if (window.pElement)
		{
			var link = pElement;
		}
		else
		{	
			var link = false;
			var sRand = '#'+Math.random().toString().substring(2);
			pObj.pMainObj.pEditorDocument.execCommand('CreateLink', false, sRand);
            
			if(document.evaluate)
			{
				link = pObj.pMainObj.pEditorDocument.evaluate("//a[@href='"+sRand+"']", pObj.pMainObj.pEditorDocument.body, null, 9, null).singleNodeValue;
			}
			else
			{
				var arLinks = pObj.pMainObj.pEditorDocument.getElementsByTagName('A');
				for(var i = 0; i < arLinks.length; i++)
				{
					if(arLinks[i].getAttribute('href', 2) == sRand)
					{
						link = arLinks[i];
						break;
					}
				}
			}
		}

		if(link)
		{
			SAttr(link, 'href', href);
			SAttr(link, '__bxhref', href);
			SAttr(link, 'target', document.getElementById("bx_target").value);
			SAttr(link, 'id', document.getElementById("bx_link_id").value);
			SAttr(link, 'title', document.getElementById("bx_link_title").value);
			SAttr(link, 'className',  document.getElementById("bx_link_classname").value);
		}
	}
	pObj.pMainObj.bSkipChanges = false;
	pObj.pMainObj.OnChange("link");
}

var pT = null;
function _Ch()
{	
	var t = document.getElementById('bx_link_type');
	if(pT)
		pT.style.display = 'none';
	pT = document.getElementById('bx_' + t.value);
	pT.style.display = "block";
	var tr = document.getElementById('bx_link_target_row');

	if(t.value=='t1' || t.value=='t2')
	{
		tr.style.display = GetDisplStr(1);
	}
	else
	{
		tr.style.display = GetDisplStr(0);
	}		
}

window._ChTargL = function()
{
	var t = document.getElementById('bx_targ_list');
	var o = document.getElementById('bx_target');
	if(t.value.length > 0)
	{
		o.disabled = true;
		o.value = t.value;
	}
	else
	{
		o.value = '';
		o.disabled = false;
	}
}
</script>
<div class="inner_content"  style="height: 240px;">
<table class="inner_content_table" cellPadding="2" cellSpacing="2" style="width: 100%;">
<tr><td colspan="2">
	<%= GetMessage("Link.Type")%>
	<select id='bx_link_type'>
		<option value='t1'><%= GetMessage("Link.Type.Internal")%></option>
		<option value='t2'><%= GetMessage("Link.Type.External")%></option>
		<option value='t3'><%= GetMessage("Link.Type.Document")%></option>
		<option value='t4'><%= GetMessage("Link.Type.MailTo")%></option>
	</select>
</td></tr>
<tr class="heading"><td colspan="2"><%= GetMessage("Link.Settings")%></td></tr>

<tr><td colspan="2">
<table width="100%" id="bx_t1" style="display:none;" border="0">
	<tr>
		<td width="50%" align="right"><%= GetMessage("Link.Document")+ ":" %></td>
		<td width="250">
			<input type="text" size="25" value="" id="bx_link_url1">
			<input type="button" id="bx_file_dialog_button" value="...">
		</td>
	</tr>
</table>

<table width="100%"  id="bx_t2" style="display:none;" border="0">
	<tr>
		<td align="right" width="50%"><%= GetMessage("Link.URL")+ ":" %></td>
		<td width="250" >
			<table cellpadding="0" cellspacing="0" width="100%">
				<tr>
					<td>
						<select id='bx_link_url_type'>
							<option value="http://">http://</option>
							<option value="ftp://">ftp://</option>
							<option value="https://">https://</option>
							<option value=""></option>
						</select>
					</td>
					<td>
						<input type="text" size="20" value="" id="bx_link_url2">
					</td>
				</tr>
			</table>
		</td>
</tr>
</table>

<table width="100%"  id="bx_t3" style="display:none;" border="0">
	<tr>
		<td align="right" width="211px"><%= GetMessage("Link.Anchor")+ ":" %></td>
		<td>
			<select id="bx_link_url3"></select>
		</td>
	</tr>
</table>

<table width="100%" id="bx_t4" style="display:none;" border="0">
<tr>
	<td align="right" width="211px"><%= GetMessage("Link.Email")+ ":" %></td>
	<td>
		<input type="text" size="25" value="" id="bx_link_url4">
	</td>
</tr>
</table>

</td></tr>

<tr id="bx_link_target_row">
	<td align="right"><%= GetMessage("Link.Target")+ ":" %></td>	
	<td>
		<table cellpadding="0" cellspacing="0">
			<tr>
				<td>
					<select onchange="_ChTargL()" id='bx_targ_list'>
						<option value=""></option>
						<option value="_blank"><%= GetMessage("Link.Target.Blank")%></option>
						<option value="_parent"><%= GetMessage("Link.Target.Parent")%></option>
						<option value="_self"><%= GetMessage("Link.Target.Self")%></option>
						<option value="_top"><%= GetMessage("Link.Target.Top")%></option>
					</select>
				</td>
				<td><input type="text" size="7" id="bx_target" value=""></td>
			</tr>
		</table>
	</td>
</tr>
<tr class="heading"><td colspan="2"><%= GetMessage("Link.Appearance")%></td></tr>
<tr>
	<td align="right"><%= GetMessage("Link.ToolTip")+ ":" %></td>
	<td><input type="text" size="30" id="bx_link_title"></td>
</tr>
<tr >
	<td align="right"><%= GetMessage("Link.CssClass")+ ":" %></td>
	<td><select id="bx_link_classname"></select></td>
</tr>
<tr>
	<td align="right"><%= GetMessage("Link.ID")+ ":" %></td>
	<td><input type="text" size="30" value="" id="bx_link_id"></td>
</tr>


<tr><td colspan="2"></td></tr>
</table>
</div>
<% } else if (DialogName == "image") { %>
<script>
var pElement = null;
var prevsrc = '';
function OnLoad()
{
	pElement = pObj.pMainObj.GetSelectionObject();
	var preview = document.getElementById("bx_img_preview");

	if(!pElement || pElement.nodeName.toUpperCase() != 'IMG' || pElement.getAttribute("__bxtagname"))
	{
		window.oDialogTitle.innerHTML = '<%= GetMessage("Image.WindowTitle.New") %>';
		pElement = false;
	}
	else
	{
		window.oDialogTitle.innerHTML = '<%= GetMessage("Image.WindowTitle.Edit") %>';
		
		document.getElementById("bx_img_width").value = GAttr(pElement, "width");
		document.getElementById("bx_img_height").value = GAttr(pElement, "height");
		document.getElementById("bx_img_src").value = GAttr(pElement, "src");
		document.getElementById("bx_img_title").value = GAttr(pElement, "title");
		document.getElementById("bx_img_alt").value = GAttr(pElement, "alt");
		document.getElementById("bx_img_border").value = GAttr(pElement, "border");
		document.getElementById("bx_img_align").value = GAttr(pElement, "align");
		document.getElementById("bx_img_hspace").value = GAttr(pElement, "hspace");
		document.getElementById("bx_img_vspace").value = GAttr(pElement, "vspace");

		prevsrc = "";
		_Reload();
	}
	
	preview.onload = _LPreview;
	document.getElementById("bx_img_src").onchange = _Reload;
	document.getElementById("bx_img_file_dialog_button").onclick = function()
	{
		__OpenDialog(
			{	
				ShowFiles: true,
				ItemsToSelect: 2,
				ExtensionsList: "jpg,bmp,png,gif",
				ShowExtras: true,
				EnableExtras: true,
				DefaultUploadDirectory: "upload"
			},
			function(val)
			{
				val = val.replace(/\\/g, '/');
				val = val.replace(/~/g, '');
				var oSrc = document.getElementById("bx_img_src");
				oSrc.value = APPPath + val;
				if(oSrc.onchange)
					oSrc.onchange();
			}
		);
	};
}

function OnSave()
{
	pObj.pMainObj.bSkipChanges = true;
	var _src = document.getElementById("bx_img_src").value;
	if (!_src)
		return;
	if(!pElement)
	{
		var tmpid = Math.random().toString().substring(2);
		var str = '<img id="'+tmpid+'"/>';
		BXSelectRange(oPrevRange,pObj.pMainObj.pEditorDocument,pObj.pMainObj.pEditorWindow);
		pObj.pMainObj.insertHTML(str);
		pElement = pObj.pMainObj.pEditorDocument.getElementById(tmpid);
		pElement.removeAttribute("id");
	}

	SAttr(pElement, "width", document.getElementById("bx_img_width").value);
	SAttr(pElement, "height", document.getElementById("bx_img_height").value);
	SAttr(pElement, "hspace", document.getElementById("bx_img_hspace").value);
	SAttr(pElement, "vspace", document.getElementById("bx_img_vspace").value);
	SAttr(pElement, "border", document.getElementById("bx_img_border").value);
	SAttr(pElement, "align", document.getElementById("bx_img_align").value);
	SAttr(pElement, "src", _src);
	SAttr(pElement, "__bxsrc", _src);
	SAttr(pElement, "alt", document.getElementById("bx_img_alt").value);
	SAttr(pElement, "title", document.getElementById("bx_img_title").value);
	pObj.pMainObj.bSkipChanges = false;
	pObj.pMainObj.OnChange("image");
}

function _CHSize()
{
	var el = document.getElementById("bx_img_preview");
	SAttr(el, "width", document.getElementById("bx_img_width").value);
	SAttr(el, "height", document.getElementById("bx_img_height").value);
}

function _Reload()
{
	var el = document.getElementById("bx_img_preview");
	var src = document.getElementById("bx_img_src").value;
	if(prevsrc != src)
	{
		el.style.display="";
		el.removeAttribute("width");
		el.removeAttribute("height");
		el.src = prevsrc = src;
	}

	el.alt = document.getElementById("bx_img_alt").value;
	el.title = document.getElementById("bx_img_title").value;
	el.border = document.getElementById("bx_img_border").value;
	el.align = document.getElementById("bx_img_align").value;
	el.hspace = document.getElementById("bx_img_hspace").value;
	el.vspace = document.getElementById("bx_img_vspace").value;
}

function _LPreview()
{
	var w = this.getAttribute('width');
	if (!w) w = parseInt(this.offsetWidth);

	var h = this.getAttribute('height');
	if (!h) h = parseInt(this.offsetHeight);

	document.getElementById("bx_img_width").value = w;
	document.getElementById("bx_img_height").value = h;
}

</script>
<div class="inner_content"  style="height: 300px;">
<table class="inner_content_table" cellPadding="2" cellSpacing="2" style="width: 100%;">
	<tr>
		<td align="right"><%= GetMessage("Image.Path")+ ":" %></td>
		<td>
			<table cellpadding="0" cellspacing="0">
				<tr>
					<td><input type="text" size="25" value="" id="bx_img_src"></td>
					<td><input type="button" value="..." id="bx_img_file_dialog_button" onclick=""></td>
				</tr>
			</table>
		</td>
	</tr>
	<tr>
		<td align="right"><%= GetMessage("Image.Title")+ ":" %></td>
		<td><input type="text" size="30" value="" id="bx_img_title"></td>
	</tr>
	<tr>
		<td align="right"><%= GetMessage("Image.Alt")+ ":" %></td>
		<td><input type="text" size="30" value="" id="bx_img_alt"></td>
	</tr>
	<tr><td colspan="2">&nbsp;</td></tr>
	<tr>
		<td align="right" valign="top">
			<table width="100%">
				<tr><td align="right"><%= GetMessage("Image.Width")+ ":" %></td><td><input type="text" id="bx_img_width" size="3"></td></tr>
				<tr><td align="right"><%= GetMessage("Image.Height")+ ":" %></td><td><input type="text" id="bx_img_height" size="3"></td></tr>
				<tr><td align="right"><%= GetMessage("Image.HSpace")+ ":" %></td><td><input type="text" id="bx_img_hspace" size="3"></td></tr>
				<tr><td align="right"><%= GetMessage("Image.VSpace")+ ":" %></td><td><input type="text" id="bx_img_vspace" size="3"></td></tr>
				<tr><td align="right"><%= GetMessage("Image.Border")+ ":" %></td><td><input type="text" id="bx_img_border" size="3"></td></tr>
				<tr><td align="right"><%= GetMessage("Image.Align")+ ":" %></td><td>
					<select id="bx_img_align">
						<option value=""></option>
						<option value="bottom">bottom</option>
						<option value="left">left</option>
						<option value="middle">middle</option>
						<option value="right">right</option>
						<option value="top">top</option>
					</select>
				</td></tr>
			</table>
		</td>
		<td><%= GetMessage("Image.Preview")+ ":" %>
		<div style="height:140px; width:200px; overflow: hidden; border: 1px #999999 solid; overflow-y: scroll; overflow-x: auto; color: #999999; background-color: #FFFFFF; padding: 3px">
			<img id="bx_img_preview" style="display:none"/>
			<%for (int i = 0; i < 160; i++) { w.Write("text ");};%>
		</div>
		</td>
	</tr>
</table>
</div>
<% } else if (DialogName == "table") { %>
<script>
var pElement = null;
function OnLoad()
{
	if(pObj.params.check_exists)
		pElement = BXFindParentByTagName(pObj.pMainObj.GetSelectionObject(), 'TABLE');
	
	window.oDialogTitle.innerHTML = pElement ? '<%= GetMessage("Table.WindowTitle.Edit") %>' : '<%= GetMessage("Table.WindowTitle.New") %>';
	
	// Build CSS styles - select
	var arStFilter = ['TABLE', 'DEFAULT'], i;
	var elStyles = document.getElementById("bx_table_classname");
	var oOption = new Option("", "", false, false);
	elStyles.options.add(oOption);
	var arStyles;
	for(i = 0; i < arStFilter.length; i++)
	{
		arStyles = pObj.pMainObj.oStyles.GetStyles(arStFilter[i]);
		for(var j = 0; j < arStyles.length; j++)
		{
			if(arStyles[j].className.length <= 0)
				continue;
			oOption = new Option(arStyles[j].className, arStyles[j].className, false, false);
			elStyles.options.add(oOption);
		}
	}

	var pRows = document.getElementById("bx_table_rows");
	var pCols = document.getElementById("bx_table_cols");
	var pCellSpacing = document.getElementById("bx_table_cellspacing");
	var pCellPadding = document.getElementById("bx_table_cellpadding");
	var pBorder = document.getElementById("bx_table_border");
	var pWidth = document.getElementById("bx_table_width");
	var pHeight = document.getElementById("bx_table_height");
	
	if(pElement)
	{
		pRows.value=pElement.rows.length;
		pRows.disabled = true;
		pCols.value = pElement.rows[0].cells.length;
		pCols.disabled = true;
		pCellPadding.value = GAttr(pElement, "cellPadding");
		pCellSpacing.value = GAttr(pElement, "cellSpacing");
		pBorder.value = GAttr(pElement, "border");
		document.getElementById("bx_table_align").value = GAttr(pElement, "align");
		document.getElementById("bx_table_classname").value = GAttr(pElement, "className");
		var v = GAttr(pElement, "width");

		if(v.substr(-1, 1) == "%")
		{
			pWidth.value = v.substr(0, v.length-1);
			document.getElementById("bx_table_width_unit").value = "%";
		}
		else
		{
			if(v.substr(-2, 2) == "px")
				v = v.substr(0, v.length-2);
		 	pWidth.value = v;
		}

		v = GAttr(pElement, "height");
		if(v.substr(-1, 1) == "%")
		{
			pHeight.value = v.substr(0, v.length-1);
			document.getElementById("bx_table_height_unit").value = "%";
		}
		else
		{
			if(v.substr(-1, 2) == "px")
				v = v.substr(0, v.length-2);
			pHeight.value = v;
		}
	}
	else
	{
		pRows.value = "2";
		pCols.value = "3";
		pCellPadding.value = "1";
		pCellSpacing.value = "1";
		pBorder.value = "0";
	}
}

function OnSave()
{
	pObj.pMainObj.bSkipChanges = true;
	if(!pElement)
	{
		var tmpid = Math.random().toString().substring(2);
		var str = '<table id="' + tmpid + '"/>';
		BXSelectRange(oPrevRange, pObj.pMainObj.pEditorDocument,pObj.pMainObj.pEditorWindow);
		pObj.pMainObj.insertHTML(str);

		pElement = pObj.pMainObj.pEditorDocument.getElementById(tmpid);
		pElement.removeAttribute("id");

		var i, j, row, cell;
		for(i = 0; i < document.getElementById("bx_table_rows").value; i++)
		{
			row = pElement.insertRow(-1);
			for(j = 0; j < document.getElementById("bx_table_cols").value; j++)
			{
				cell = row.insertCell(-1);
				cell.innerHTML = '<br _moz_editor_bogus_node="on">';
			}
		}
	}
	else
	{
		if(pObj.pMainObj.bTableBorder)
			pObj.pMainObj.__ShowTableBorder(pElement, false);
	}
	
	var pWidth = document.getElementById("bx_table_width");
	var pHeight = document.getElementById("bx_table_height");	
	SAttr(pElement, "width", (pWidth.value.length > 0 ? pWidth.value + document.getElementById("bx_table_width_unit").value : ''));
	SAttr(pElement, "height", (pHeight.value.length > 0 ? pHeight.value + document.getElementById("bx_table_height_unit").value : ''));
	SAttr(pElement, "border", document.getElementById("bx_table_border").value);
	SAttr(pElement, "cellPadding", document.getElementById("bx_table_cellpadding").value);
	SAttr(pElement, "cellSpacing", document.getElementById("bx_table_cellspacing").value);
	SAttr(pElement, "align", document.getElementById("bx_table_align").value);
	SAttr(pElement, "className", document.getElementById("bx_table_classname").value);

	pObj.pMainObj.OnChange("table");

	if(pObj.pMainObj.bTableBorder)
		pObj.pMainObj.__ShowTableBorder(pElement, true);
}

</script>

<div class="inner_content"  style="height: 170px;">
<table class="inner_content_table" cellPadding="2" cellSpacing="2" style="width: 100%;">
	<tr>
		<td align="right"><%= GetMessage("Table.RowCount")+ ":" %></td>
		<td><input type="text" size="3" id="bx_table_rows"></td>
		<td>&nbsp;</td>
		<td align="right"><%= GetMessage("Table.Width")+ ":" %></td>
		<td nowrap><input type="text" size="3" id="bx_table_width">
			<select id="bx_table_width_unit">
				<option value=""><%= GetMessage("Table.Pixels")%></option>
				<option value="%"><%= GetMessage("Table.Percent")%></option>
			</select>
		</td>
	</tr>
	<tr>
		<td align="right"><%= GetMessage("Table.ColumnCount")+ ":" %></td>
		<td><input type="text" size="3" id="bx_table_cols"></td>
		<td>&nbsp;</td>
		<td align="right"><%= GetMessage("Table.Height")+ ":" %></td>
		<td nowrap><input type="text" size="3" id="bx_table_height">
			<select id="bx_table_height_unit">
				<option value=""><%= GetMessage("Table.Pixels")%></option>
				<option value="%"><%= GetMessage("Table.Percent")%></option>
			</select>
		</td>
	</tr>
	
	<tr><td colspan="5">&nbsp;</td></tr>
	
	<tr>
		<td align="right" nowrap><%= GetMessage("Table.Border")+ ":" %></td>
		<td><input type="text" id="bx_table_border" size="3"></td>
		<td>&nbsp;</td>
		<td align="right" nowrap><%= GetMessage("Table.CellPadding")+ ":" %></td>
		<td><input type="text" id="bx_table_cellpadding" size="3"></td>
	</tr>
	<tr>
		<td align="right"><%= GetMessage("Table.Align")+ ":" %></td>
		<td>
			<select id="bx_table_align">
				<option value=""></option>
				<option value="left">left</option>
				<option value="center">center</option>
				<option value="right">right</option>
			</select>
		</td>
		<td>&nbsp;</td>
		<td align="right" nowrap><%= GetMessage("Table.CellSpacing")+ ":" %></td>
		<td><input type="text" id="bx_table_cellspacing" size="3"></td>
	</tr>
	<tr>
		<td align="right"><%= GetMessage("Table.CssClass")+ ":" %></td>
		<td colspan="4"><select id="bx_table_classname"></select></td>
	</tr>
</table>
</div>
<% } else if (DialogName == "pasteastext") { %>
<script>
function OnLoad()
{
	oDialogTitle.innerHTML = '<%= GetMessage("PasteText.WindowTitle")%>';
	document.getElementById("BXInsertAsText").focus();
}

function OnSave()
{
	BXSelectRange(oPrevRange,pObj.pMainObj.pEditorDocument,pObj.pMainObj.pEditorWindow);
	pObj.pMainObj.PasteAsText(document.getElementById("BXInsertAsText").value);
}
</script>

<div class="inner_content">
<table width="100%" id="Table1">
	<tr>
		<td><%= GetMessage("PasteText.FFFix") %></td>
	</tr>
	<tr><td>
		<textarea id="BXInsertAsText" style="width:100%; height:200px"></textarea>
	</td></tr>
</table>
</div>
<% } else if (DialogName == "pasteword") { %>


<script>
var pFrame = null;
function OnLoad()
{
	oDialogTitle.innerHTML = '<%= GetMessage("PasteWord.WindowTitle") %>';
	pFrame = document.getElementById("BXPasteAsWordNode_text");
	pFrame.pDocument = pFrame.contentDocument || pFrame.contentWindow.document;
	pFrame.pWindow = pFrame.contentWindow;

	pFrame.pDocument.open();
	pFrame.pDocument.write('<html><head><style>BODY{margin:0px; padding:0px; border:0px;}</style></head><body></body></html>');
	pFrame.pDocument.close();

	if(pFrame.pDocument.addEventListener)
		pFrame.pDocument.addEventListener('keydown', dialog_OnKeyDown, false);
	else if (pFrame.pDocument.attachEvent)
		pFrame.pDocument.body.attachEvent('onpaste', dialog_OnPaste);

	if(jsUtils.IsIE())
	{
		document.getElementById("BXPasteAsWordNode_ff").style.display = 'none';
		pFrame.pDocument.body.contentEditable = true;
		pFrame.pDocument.body.innerHTML = pObj.pMainObj.GetClipboardHTML();
		dialog_OnPaste();
	}
	else
		pFrame.pDocument.designMode='on';
		
	document.getElementById("BXPasteAsWordNode_removeFonts").onclick = dialog_cleanAndShow;
	document.getElementById("BXPasteAsWordNode_removeStyles").onclick = dialog_cleanAndShow;
	document.getElementById("BXPasteAsWordNode_removeIndents").onclick = dialog_cleanAndShow;
}

function dialog_OnKeyDown(e)
{
	if (e.ctrlKey && !e.shiftKey && !e.altKey)
	{
		if (!jsUtils.IsIE())
		{
			switch (e.which)
			{
				case 86: // "V" and "v"
				case 118:
					dialog_OnPaste(e);
					break ;
			}
		}
	}
}

function dialog_OnPaste(e)
{
	this.pOnChangeTimer = setTimeout(dialog_cleanAndShow, 10);
}

function dialog_cleanAndShow()
{
	var removeFonts = document.getElementById('BXPasteAsWordNode_removeFonts').checked;
	var removeStyles = document.getElementById('BXPasteAsWordNode_removeStyles').checked;
	var removeIndents = document.getElementById('BXPasteAsWordNode_removeIndents').checked;
	clenedHtml = pObj.pMainObj.CleanWordText(pFrame.pDocument.body.innerHTML,[removeFonts,removeStyles,removeIndents]);
	dialog_showClenedHtml(clenedHtml);
}

function dialog_showClenedHtml(html)
{
	taSourse = document.getElementById('BXPasteAsWordNode_sourse');
	taSourse.value = html;
}

function OnSave()
{
	var removeFonts = document.getElementById('BXPasteAsWordNode_removeFonts').checked;
	var removeStyles = document.getElementById('BXPasteAsWordNode_removeStyles').checked;
	var removeIndents = document.getElementById('BXPasteAsWordNode_removeIndents').checked;
	BXSelectRange(oPrevRange,pObj.pMainObj.pEditorDocument,pObj.pMainObj.pEditorWindow);
	pObj.pMainObj.PasteWord(pFrame.pDocument.body.innerHTML,[removeFonts,removeStyles,removeIndents]);
}
</script>
<div class="inner_content">
<table id="BXPasteAsWordNode_t1" style="width:476px;">
	<tr id="BXPasteAsWordNode_ff">
		<td><%= GetMessage("PasteWord.FFFix") %></td>
	</tr>
	<tr>
		<td><iframe id="BXPasteAsWordNode_text" src="javascript:''" style="width:100%; height:150px; border:1px solid #CCCCCC;"></iframe></td>
	</tr>
	<tr>
		<td><%= GetMessage("PasteWord.HTMLAfterClear")%></td>
	</tr>
	<tr>
		<td><textarea id="BXPasteAsWordNode_sourse" style="width:100%; height:100px; border:1px solid #CCCCCC;" disabled="disabled"></textarea></td>
	</tr>
	<tr>
		<td>
			<input id="BXPasteAsWordNode_removeFonts" type="checkbox" checked="checked"><label for="BXPasteAsWordNode_removeFonts"><%= GetMessage("PasteWord.DeleteFonts")%></label><br>
			<input id="BXPasteAsWordNode_removeStyles" type="checkbox" checked="checked"> <label for="BXPasteAsWordNode_removeStyles"><%= GetMessage("PasteWord.RemoveStyles")%></label><br>
			<input id="BXPasteAsWordNode_removeIndents" type="checkbox" checked="checked"> <label for="BXPasteAsWordNode_removeIndents"><%= GetMessage("PasteWord.RemoveIndents")%></label>
		</td>
	</tr>
</table>
</div>
<% } else if (DialogName == "asksave") { %>
<b> asksave </b>
<% } else if (DialogName == "pageprops") { %>
<b> pageprops </b>
<% } else if (DialogName == "specialchar") { %>
<script>
function OnLoad()
{
	oDialogTitle.innerHTML = '<%= GetMessage("Char.WindowTitle")%>';
	var cancelBut = document.getElementById("cancelBut");
	cancelBut.style.display = "none";
	var saveBut = document.getElementById("saveBut");
	saveBut.style.display = "none";

	arEntities_dialog = ['&iexcl;','&cent;','&pound;','&curren;','&yen;','&brvbar;','&sect;','&uml;','&copy;','&ordf;','&laquo;','&not;','&reg;','&macr;','&deg;','&plusmn;','&sup2;','&sup3;','&acute;','&micro;','&para;','&middot;','&cedil;','&sup1;','&ordm;','&raquo;','&frac14;','&frac12;','&frac34;','&iquest;','&Agrave;','&Aacute;','&Acirc;','&Atilde;','&Auml;','&Aring;','&AElig;','&Ccedil;','&Egrave;','&Eacute;','&Ecirc;','&Euml;','&Igrave;','&Iacute;','&Icirc;','&Iuml;','&ETH;','&Ntilde;','&Ograve;','&Oacute;','&Ocirc;','&Otilde;','&Ouml;','&times;','&Oslash;','&Ugrave;','&Uacute;','&Ucirc;','&Uuml;','&Yacute;','&THORN;','&szlig;','&agrave;','&aacute;','&acirc;','&atilde;','&auml;','&aring;','&aelig;','&ccedil;','&egrave;','&eacute;','&ecirc;','&euml;','&igrave;','&iacute;','&icirc;','&iuml;','&eth;','&ntilde;','&ograve;','&oacute;','&ocirc;','&otilde;','&ouml;','&divide;','&oslash;','&ugrave;','&uacute;','&ucirc;','&uuml;','&yacute;','&thorn;','&yuml;','&OElig;','&oelig;','&Scaron;','&scaron;','&Yuml;','&circ;','&tilde;','&ndash;','&mdash;','&lsquo;','&rsquo;','&sbquo;','&ldquo;','&rdquo;','&bdquo;','&dagger;','&Dagger;','&permil;','&lsaquo;','&rsaquo;','&euro;','&Alpha;','&Beta;','&Gamma;','&Delta;','&Epsilon;','&Zeta;','&Eta;','&Theta;','&Iota;','&Kappa;','&Lambda;','&Mu;','&Nu;','&Xi;','&Omicron;','&Pi;','&Rho;','&Sigma;','&Tau;','&Upsilon;','&Phi;','&Chi;','&Psi;','&Omega;','&alpha;','&beta;','&gamma;','&delta;','&epsilon;','&zeta;','&eta;','&theta;','&iota;','&kappa;','&lambda;','&mu;','&nu;','&xi;','&omicron;','&pi;','&rho;','&sigmaf;','&sigma;','&tau;','&upsilon;','&phi;','&chi;','&psi;','&omega;','&bull;','&hellip;','&prime;','&Prime;','&oline;','&frasl;','&trade;','&larr;','&uarr;','&rarr;','&darr;','&harr;','&part;','&sum;','&minus;','&radic;','&infin;','&int;','&asymp;','&ne;','&equiv;','&le;','&ge;','&loz;','&spades;','&clubs;','&hearts;'];	
	if(!jsUtils.IsIE())
		arEntities_dialog = arEntities_dialog.concat('&thetasym;','&upsih;','&piv;','&weierp;','&image;','&real;','&alefsym;','&crarr;','&lArr;','&uArr;','&rArr;','&dArr;','&hArr;','&forall;','&exist;','&empty;','&nabla;','&isin;','&notin;','&ni;','&prod;','&lowast;','&prop;','&ang;','&and;','&or;','&cap;','&cup;','&there4;','&sim;','&cong;','&sub;','&sup;','&nsub;','&sube;','&supe;','&oplus;','&otimes;','&perp;','&sdot;','&lceil;','&rceil;','&lfloor;','&rfloor;','&lang;','&rang;','&diams;');
	
	drawTable();
}

function drawTable()
{
	var charCont = document.getElementById("bx_charCont");
	var chTable = document.createElement("TABLE");
	var tBody = document.createElement("TBODY");
	chTable.appendChild(tBody);
	charCont.appendChild(chTable);

	var r,c,lEn = arEntities_dialog.length;
	var elEntity = document.createElement("span");
	var elEmpty = document.createElement("span");

	for(var i=0; i<lEn; i++)
	{
		if (i%19 == 0)
		{
			r = document.createElement("TR");
			tBody.appendChild(r);
		}
		elEntity.innerHTML = arEntities_dialog[i];
		c = document.createElement("TD");
		c.id = 'e_'+i;
		c.innerHTML = elEntity.innerHTML;
		setCellstyle(c,'normal');
		setCellEvents(c);
		r.appendChild(c);
	}
}

function setCellstyle(cellObj,mode){
	switch (mode)
	{
		case 'normal':
			cellObj.style.width = "17px";
			cellObj.style.height = "17px";
			cellObj.style.fontSize = "12px";
			cellObj.style.textAlign = "center";
			cellObj.style.verticalAlign = "middle";
			cellObj.style.border = "1px solid #ffffff";
			cellObj.style.backgroundColor = "#FFFFFF";
			break;
		case 'over':
			cellObj.style.width = "17px";
			cellObj.style.height = "17px";
			cellObj.style.fontSize = "12px";
			cellObj.style.textAlign = "center";
			cellObj.style.verticalAlign = "middle";
			cellObj.style.border = "#4B4B6F 1px solid";
			cellObj.style.backgroundColor = "#BFC6B8";
			break;
	}
}

function setCellEvents(cellObj){
	cellObj.onmouseover = function(){
		setCellstyle(this,'over');
		prevChar(this);
	}
	cellObj.onmouseout = function(){
		setCellstyle(this,'normal');
	}
	cellObj.onclick = function(){
		var entInd = cellObj.id.substring(2);
		BXSelectRange(oPrevRange,pObj.pMainObj.pEditorDocument,pObj.pMainObj.pEditorWindow);
		pObj.pMainObj.insertHTML(arEntities_dialog[entInd]);
		pObj.Close();
	}
}

function prevChar(cellObj)
{
	var charPrev = document.getElementById('bx_charPrev');
	charPrev.innerHTML = cellObj.innerHTML;
	charPrev.style.fontSize = "80px";
	charPrev.style.textAlign = "center";
	charPrev.style.verticalAlign = "middle";

	var charPrev = document.getElementById('bx_entityName');
	var entInd = cellObj.id.substring(2);
	charPrev.innerHTML = arEntities_dialog[entInd].substr(1,arEntities_dialog[entInd].length-2);
}

</script>
<div class="inner_content" style="height: 275px;"></div>
<div id="bx_charCont" style="width: 455px; position: absolute; top: 30px; left: 5px"></div>
<div id="bx_charPrev" style="background-color: #F4F4F4; width: 120px; height: 120px; position: absolute; top: 35px; left: 465px"></div>
<div id="bx_entityName" style="font-size: 14; text-align: center; background-color: #F4F4F4; width: 120px; height: 20px; position: absolute; top: 130px; left: 465px"></div>
<div style="width: 120px; height: 20px; position: absolute; top: 250px; left: 465px; text-align: right;">
<input type="button" value="<%= GetMessage("Dialog.Cancel") %>" onclick="pObj.Close();"></div>
<% } else if (DialogName == "settings") { %>
<script>
function OnLoad()
{
	oDialogTitle.innerHTML = '<%= GetMessage("Settings.WindowTitle")%>';
	if (!pObj.params.lightMode)
	{
		// ************************ TAB #1: Toolbar settings ***********************************
		var oDiv = document.getElementById("__bx_set_1_toolbar");
		oDiv.style.height = '250px';
		oDiv.innerHTML = '';
		window.temp_arToolbarSettings = copyObj(SETTINGS[pObj.pMainObj.name].arToolbarSettings);
		_displayToolbarList(oDiv);
		oDiv = null;
	}
	// ************************ TAB #2: Taskbar settings ***********************************
	oDiv = document.getElementById("__bx_set_2_taskbar");
	oDiv.style.height = '250px';
	oDiv.innerHTML = '';
	window.temp_arTaskbarSettings = copyObj(SETTINGS[pObj.pMainObj.name].arTaskbarSettings);
	_displayTaskbarList(oDiv);

	// ************************ TAB #3: Additional Properties ***********************************
	oDiv = document.getElementById("__bx_set_3_add_props");
	oDiv.style.height = '250px';
	oDiv.innerHTML = '';
	_displayAdditionalProps(oDiv);

	document.getElementById("restoreDefault").onclick = function(e){restoreSettings()};
}

function _displayToolbarList(oCont)
{
	var oTable = document.createElement("TABLE");
	oTable.width = "100%";
	_displayTitle(oTable,'<%= GetMessage("Settings.ITab.TBAppearance")%>');
	var _show;
	for(var sToolBarId in arToolbars)
		_displayToolbarRow(oTable, sToolBarId,SETTINGS[pObj.pMainObj.name].arToolbarSettings[sToolBarId].show);

	_displayTitle(oTable,'<%= GetMessage("Settings.ITab.AppearanceSettings")%>');
	oTr = oTable.insertRow(-1);
	oTr.className = "bxpropertysell";
	oTd = oTr.insertCell(-1);
	oTd.innerHTML = '<%= GetMessage("Settings.ITab.STBPos")%>';
	oTd.align = "right";
	oTd = oTr.insertCell(-1);
	pCheckbox = pObj.pMainObj.CreateElement("INPUT", {type:'checkbox', id: '__bx_rs_tlbrs'});
	oTd.appendChild(pCheckbox);
	oBXEditorUtils.setCheckbox(pCheckbox,pObj.pMainObj.RS_toolbars);
	oTd.align = "left";
	oCont.appendChild(oTable);
}

function _displayToolbarRow(oTb,toolbarId,_show)
{
	var oTr = oTb.insertRow(-1);
	oTr.className = "bxpropertysell";
	var oTd = oTr.insertCell(-1);
	oTd.innerHTML = arToolbars[toolbarId][0];
	oTd.align = "right";
	oTd.width = "60%";

	oTd = oTr.insertCell(-1);
	pCheckbox = pObj.pMainObj.CreateElement("INPUT", {type:'checkbox', id: '__bx_'+toolbarId, '__bxid' : toolbarId});
	oTd.appendChild(pCheckbox);
	oBXEditorUtils.setCheckbox(pCheckbox,_show);
	if (toolbarId=="standart")
		pCheckbox.disabled = "disabled";

	pCheckbox.onchange = function(e) {window.temp_arToolbarSettings[this.getAttribute("__bxid")].show = this.checked;}
	oTd.align = "left"
	oTd.width = "40%";
}

function _displayTaskbarList(oCont)
{
	var oTable = document.createElement("TABLE");
	oTable.width = "100%";
	_displayTitle(oTable,'<%= GetMessage("Settings.ITab.TsBAppearance")%>');
	var _show;

	for(var k in ar_BXTaskbarS)
	{
		if (ar_BXTaskbarS[k].pMainObj.name == pObj.pMainObj.name)
			_displayTaskbarRow(oTable, ar_BXTaskbarS[k], SETTINGS[pObj.pMainObj.name].arTaskbarSettings[ar_BXTaskbarS[k].name]);
	}

	_displayTitle(oTable,'<%= GetMessage("Settings.ITab.AppearanceSettings")%>');
	oTr = oTable.insertRow(-1);
	oTr.className = "bxpropertysell";
	oTd = oTr.insertCell(-1);
	oTd.innerHTML = '<%= GetMessage("Settings.TTab.STBPos")%>';
	oTd.align = "right";
	oTd = oTr.insertCell(-1);
	pCheckbox = pObj.pMainObj.CreateElement("INPUT", {type: 'checkbox', id: '__bx_rs_tskbrs'});
	oTd.appendChild(pCheckbox);
	oBXEditorUtils.setCheckbox(pCheckbox,pObj.pMainObj.RS_taskbars);
	oTd.align = "left";
	oCont.appendChild(oTable);
}

function _displayTaskbarRow(oTb, oTaskbar, arSettings)
{	
	var _show = arSettings.show;
	var taskbarId = oTaskbar.name;
	var oTr = oTb.insertRow(-1);
	oTr.className = "bxpropertysell";
	var oTd = oTr.insertCell(-1);
	oTd.innerHTML = oTaskbar.title;
	oTd.align = "right";
	oTd.width = "60%";
	oTd = oTr.insertCell(-1);

	var pCheckbox = oTd.appendChild(pObj.pMainObj.CreateElement("INPUT", {type: 'checkbox', id: '__bx_' + taskbarId, __bxid : taskbarId}));
	if (taskbarId == "ASPXComponentsTaskbar")
	{
		pCheckbox.disabled = "true";
	}
	oBXEditorUtils.setCheckbox(pCheckbox,_show);
	pCheckbox.onchange = function(e) {window.temp_arTaskbarSettings[this.getAttribute("__bxid")].show = this.checked;}
	
	oTd.align = "left"
	oTd.width = "40%";
}


function _displayTitle(oTb, sTitle)
{
	var oTr = oTb.insertRow(-1);
	oTr.className = "heading_dialog";
	var oTd = oTr.insertCell(-1);
	oTd.colSpan = 2;
	oTd.innerHTML = sTitle;
}

function _displayAdditionalProps(oCont)
{
	var oTable = pObj.pMainObj.CreateElement('TABLE', {width: '100%'});
	var oTd = oTable.insertRow(-1).insertCell(-1);
	oTd.style.height = '10px';

	var oTr = oTable.insertRow(-1);
	oTr.className = "bxpropertysell";
	oTd = oTr.insertCell(-1);
	oTd.innerHTML = '<%= GetMessage("Settings.AddTab.ShowTooltips")%>';
	oTd.align = "right";
	oTd.width = "70%";
	oTd = oTr.insertCell(-1);
	var pCheckbox = oTd.appendChild(pObj.pMainObj.CreateElement("INPUT", {type: 'checkbox', id: '__bx_show_tooltips'}));
	oBXEditorUtils.setCheckbox(pCheckbox, pObj.pMainObj.showTooltips4Components);
	oTd.align = "left";
	oTd.width = "30%";

	var oTr = oTable.insertRow(-1);
	oTr.className = "bxpropertysell";
	oTd = oTr.insertCell(-1);
	oTd.innerHTML = '<%= GetMessage("Settings.AddTab.VisualEffects")%>';
	oTd.align = "right";
	oTd = oTr.insertCell(-1);
	var pCheckbox = oTd.appendChild(pObj.pMainObj.CreateElement("INPUT", {type: 'checkbox', id: '__bx_visual_effects'}));
	oBXEditorUtils.setCheckbox(pCheckbox, pObj.pMainObj.visualEffects);
	oTd.align = "left";

	oCont.appendChild(oTable);
}


function restoreSettings()
{
	BXUnsetConfiguration(pObj.pMainObj);
	var RSPreloader = new BXPreloader(
		[{func: BXGetConfiguration, params: ['get_all', pObj.pMainObj]}],
		{
			func: function()
			{
				if (!lightMode)
					BXRefreshToolbars(pObj.pMainObj);
				BXRefreshTaskbars(pObj.pMainObj);
				pObj.Close();
			}
		}
	);
	RSPreloader.LoadStep();
}


function OnSave()
{
	if (!document.getElementById("__bx_rs_tskbrs").checked)
		temp_arTaskbarSettings = arTaskbarSettings_default;

	var showTooltips = (document.getElementById("__bx_show_tooltips").checked);
	if (showTooltips != pObj.pMainObj.showTooltips4Components)
	{
		pObj.pMainObj.showTooltips4Components = showTooltips;
		BXSetConfiguration(pObj.pMainObj,"tooltips","GET");
	}

	var visEff = (document.getElementById("__bx_visual_effects").checked);
	if (visEff != pObj.pMainObj.visualEffects)
	{
		pObj.pMainObj.visualEffects = visEff;
		BXSetConfiguration(pObj.pMainObj, "visual_effects", "GET");
	}

	if (!lightMode)
	{
		if (!document.getElementById("__bx_rs_tlbrs").checked)
			temp_arToolbarSettings = arToolbarSettings_default;

		if (!compareObj(SETTINGS[pObj.pMainObj.name].arToolbarSettings,window.temp_arToolbarSettings) ||
			(document.getElementById("__bx_rs_tlbrs").checked != pObj.pMainObj.RS_toolbars))
		{
			pObj.pMainObj.RS_toolbars = document.getElementById("__bx_rs_tlbrs").checked;
			SETTINGS[pObj.pMainObj.name].arToolbarSettings = temp_arToolbarSettings;
			var postData = oBXEditorUtils.ConvertArray2Post(temp_arToolbarSettings,'tlbrset');
			BXSetConfiguration(pObj.pMainObj,"toolbars","POST",postData);
			BXRefreshToolbars(pObj.pMainObj);
		}
	}


	if (!compareObj(SETTINGS[pObj.pMainObj.name].arTaskbarSettings, window.temp_arTaskbarSettings) ||
		(document.getElementById("__bx_rs_tskbrs").checked != pObj.pMainObj.RS_taskbars))
	{
		pObj.pMainObj.RS_taskbars = document.getElementById("__bx_rs_tskbrs").checked;
		SETTINGS[pObj.pMainObj.name].arTaskbarSettings = temp_arTaskbarSettings;
		recreateTaskbars(pObj.pMainObj);
		
		var postData = oBXEditorUtils.ConvertArray2Post(temp_arTaskbarSettings, 'tskbrset');
		BXSetConfiguration(pObj.pMainObj, "taskbars", "POST", postData);
	}
}

function recreateTaskbars(pMainObj)
{
	setTimeout(function () {
			BXCreateTaskbars(pMainObj, false);
			BXRefreshTaskbars(pMainObj);
		}
	, 50);
}

window.BXEdTabControlOptions = new BXTabControl('BXTabControl', 'BXEdTabControlOptions_selected', 
	[
		'BXEdTabControlOptions_strip_tab0_container', 
		'BXEdTabControlOptions_strip_tab1_container',
		'BXEdTabControlOptions_strip_tab2_container'
	]);
</script>
<div style="height: 300px;">
<bx:BXTabControl ID="BXEdTabControlOptions" runat="server" ButtonsMode="Hidden">
<bx:BXTabControlTab ID="BXEdTabsOptions1" runat="server" Text="<%$ Loc:Settings.TabText.InstrumentPanel %>" Selected="true">
	<div id="__bx_set_1_toolbar">&nbsp;</div>
</bx:BXTabControlTab>
<bx:BXTabControlTab ID="BXEdTabsOptions2" runat="server" Text="<%$ Loc:Settings.TabText.TaskPanel %>">
	<div id="__bx_set_2_taskbar">&nbsp;</div>
</bx:BXTabControlTab>
<bx:BXTabControlTab ID="BXEdTabsOptions3" runat="server" Text="<%$ Loc:Settings.TabText.Additional %>">
	<div id="__bx_set_3_add_props">&nbsp;</div>
</bx:BXTabControlTab>
</bx:BXTabControl>
</div>

<% } else if (DialogName == "flash") { %>
<script>
function OnLoad()
{
	//Attaching Events
	var oPreviewCont = document.getElementById("bx_flash_preview_cont");
	document.getElementById("bx_flash_src").onchange = function(){Flash_Reload(oPreviewCont, document.getElementById("bx_flash_src").value, 150, 150)};
	document.getElementById("bx_flash_file_dialog_button").onclick = function()
	{
		__OpenDialog(
			{	
				ShowFiles: true,
				ItemsToSelect: 2,
				ExtensionsList: "swf",
				ShowExtras: true,
				EnableExtras: true,
				DefaultUploadDirectory: "upload"
			},
			function(val)
			{
				val = val.replace(/\\/g, '/');
				val = val.replace(/~/g, '');
				var oSrc = document.getElementById("bx_flash_src");
				oSrc.value = APPPath + val;
				if(oSrc.onchange)
					oSrc.onchange();
			}
		);
	};
	
	
	
	var applyParams = function(arParams)
	{
		var re, _p, i, l;
		for(var i in pObj.bx_swf_arParams)
		{
			_p = pObj.bx_swf_arParams[i].p;
			if (!_p) continue;

			if (_p.type.toLowerCase() == 'checkbox')
				_p.checked = (arParams[i]);
			else
				_p.value = arParams[i] || '';
		}
	};
	
	pObj.bx_swf_source = document.getElementById("bx_flash_html_code");
	pObj.bx_swf_source.onblur = function()
	{
		var s = this.value;
		if (s.length <= 0)
			return;
		var flash_parser = function(str, attr)
		{
			if (attr.indexOf('.swf') === false || attr.indexOf('flash') === false) // not a flash
				return;

			attr = attr.replace(/[\r\n]+/ig, ' ');
			attr = attr.replace(/\s+/ig, ' ');
			attr = attr.trim();

			var _params = ['src', 'width', 'height', 'id', 'title', 'class', 'style', 'quality', 'wmode', 'scale', 'salign', 'autoplay', 'loop', 'showmenu' ];
			var arParams = {};
			var re, _p, i, l;
			for (i = 0, l = _params.length; i < l; i++)
			{
				_p = _params[i];
				re = new RegExp(_p+'\\s*=\\s*("|\')([^\\1]+?)\\1', "ig");
				attr = attr.replace(re, function(s, b1, value){arParams[_p] = value;});
			}
			applyParams(arParams);
		};
		s = s.replace(/<embed([^>]*?)>[^>]*?<\/embed>/ig, flash_parser);
		Flash_Reload(oPreviewCont, document.getElementById("bx_flash_src").value, 150, 150);
	};

	pObj.bx_swf_arParams = {
		src : {p : document.getElementById("bx_flash_src")},
		width : {p : document.getElementById("bx_flash_width")},
		height : {p : document.getElementById("bx_flash_height")},
		id : {p : document.getElementById("bx_flash_id")},
		title : {p : document.getElementById("bx_flash_title")},
		classname : {p : document.getElementById("bx_flash_classname")},
		style : {p : document.getElementById("bx_flash_style")},
		quality : {p : document.getElementById("bx_flash_quality")},
		wmode : {p : document.getElementById("bx_flash_wmode")},
		scale : {p : document.getElementById("bx_flash_scale")},
		salign : {p : document.getElementById("bx_flash_salign")},
		autoplay : {p : document.getElementById("bx_flash_autoplay")},
		loop : {p : document.getElementById("bx_flash_loop")},
		showmenu : {p : document.getElementById("bx_flash_showmenu")}
	};
	
	
	
	
	pElement = pObj.pMainObj.GetSelectionObject();
	if(pElement && pElement.getAttribute && pElement.getAttribute("__bxtagname") == "flash") // Edit flash
	{
		pObj.bEdit = true;
		var id  = pElement.id;
		var id  = pElement.id;
		pObj.bx_swf_source.disabled = true;
		oDialogTitle.innerHTML = '<%= GetMessage("Flash.WindowTitle.Edit")%>';
		applyParams(pObj.pMainObj.arFlashParams[id]);
		Flash_Reload(oPreviewCont, document.getElementById("bx_flash_src").value, 150, 150);
	}
	else // insert flash
	{
		pObj.bEdit = false;
		oDialogTitle.innerHTML = '<%= GetMessage("Flash.WindowTitle.New")%>';
	}
}

function OnSave()
{
	if (!pObj.bx_swf_arParams.src.p.value)
		return;
	pObj.pMainObj.bSkipChanges = true;
	BXSelectRange(oPrevRange, pObj.pMainObj.pEditorDocument, pObj.pMainObj.pEditorWindow);
	var html;
	if (pObj.bEdit)
	{
		var id = pElement.id;
		var ar = pObj.pMainObj.arFlashParams[id];
		for(var i in pObj.bx_swf_arParams)
		{
			_p = pObj.bx_swf_arParams[i].p;
			if (!_p) continue;
			if (_p.type.toLowerCase() == 'checkbox' && _p.checked)
				ar[i] = true;
			else if(_p.type.toLowerCase() != 'checkbox' && _p.value.length > 0)
				ar[i] = _p.value;
		}
		
		pElement.style.width = (parseInt(ar.width) || 50) + 'px';
		pElement.style.height = (parseInt(ar.height) || 25) + 'px';
		pObj.pMainObj.bSkipChanges = false;
		return;
	}
	
	
	if (pObj.bx_swf_source.value.length > 0)
	{
		html = pObj.bx_swf_source.value;
	}
	else
	{
		html = '<EMBED ';
		for(var i in pObj.bx_swf_arParams)
		{
			_p = pObj.bx_swf_arParams[i].p;
			if (!_p) continue;

			if (_p.type.toLowerCase() == 'checkbox' && _p.checked)
				html += i + '="true" ';
			else if(_p.type.toLowerCase() != 'checkbox' && _p.value.length > 0)
				html += i + '="' + _p.value + '" ';
		}
		html += 'type = "application/x-shockwave-flash" '+
		'pluginspage = "http://www.macromedia.com/go/getflashplayer" '+
		'></EMBED>';
	}
	
	html = _ContentParser(html, pObj.pMainObj);
	pObj.pMainObj.insertHTML(html);
	pObj.pMainObj.bSkipChanges = false;
}


window.BXEdTabControlFlash = new BXTabControl('BXTabControl', 'BXEdTabControlFlash_selected', 
	[
		'BXEdTabControlFlash_strip_tab0_container', 
		'BXEdTabControlFlash_strip_tab1_container',
		'BXEdTabControlFlash_strip_tab2_container'
	]);
</script>
<div style="height: 330px;">
<bx:BXTabControl ID="BXEdTabControlFlash" runat="server" ButtonsMode="Hidden" >
<bx:BXTabControlTab ID="BXEdTabsFlash1" runat="server" Text="<%$ Loc:Flash.TabText.General %>" Selected="true">
	<table width="100%" border="0" height="280">
		<tr>
			<td align="right" width="40%"><%= GetMessage("Flash.Path")+ ":" %></td>
			<td width="60%" colspan="3">
				<input type="text" size="30" value="" id="bx_flash_src">
				<input type="button" value="..." id="bx_flash_file_dialog_button">
			</td>
		</tr>
		<tr>
			<td align="right"><%= GetMessage("Flash.Width")+ ":" %></td>
			<td width="60px"><input type="text" size="3" id="bx_flash_width"></td>
			<td width="80px"align="right"><%= GetMessage("Flash.Height")+ ":" %></td>
			<td width="130px"><input type="text" size="3" id="bx_flash_height"></td>
		</tr>
		<tr>
			<td align="right" valign="top"><%= GetMessage("Flash.Preview")+ ":" %></td>
			<td colspan="3">
				<div id="bx_flash_preview_cont" style="height:200px; width:95%; overflow: hidden; border: 1px #999999 solid; overflow-y: auto; overflow-x: auto;">
				</div>
			</td>
		</tr>
	</table>
</bx:BXTabControlTab>
<bx:BXTabControlTab ID="BXEdTabsFlash2" runat="server" Text="<%$ Loc:Flash.TabText.Additional %>">
	<table width="100%" border="0" height="280">
		<tr>
			<td align="right" width="40%" colspan="2"><%= GetMessage("Flash.ID")+ ":" %></td>
			<td width="60%" colspan="2">
				<input type="text" size="30" value="" id="bx_flash_id">
			</td>
		</tr>
		<tr>
			<td align="right" colspan="2"><%= GetMessage("Flash.Title")+ ":" %></td>
			<td colspan="2">
				<input type="text" size="30" value="" id="bx_flash_title">
			</td>
		</tr>
		<tr>
			<td align="right" colspan="2"><%= GetMessage("Flash.ClassName")+ ":" %></td>
			<td colspan="2">
				<input type="text" size="30" value="" id="bx_flash_classname">
			</td>
		</tr>
		<tr>
			<td align="right" colspan="2"><%= GetMessage("Flash.Style")+ ":" %></td>
			<td colspan="2">
				<input type="text" size="30" value="" id="bx_flash_style">
			</td>
		</tr>
		<tr>
			<td align="right" colspan="2"><%= GetMessage("Flash.Quality")+ ":" %></td>
			<td colspan="2">
				<select id="bx_flash_quality" style="width:100px">
					<option value=""></option>
					<option value="low">low</option>
					<option value="medium">medium</option>
					<option value="high">high</option>
					<option value="autolow">autolow</option>
					<option value="autohigh">autohigh</option>
					<option value="best">best</option>
				</select>
			</td>
		</tr>
		<tr>
			<td align="right" colspan="2"><%= GetMessage("Flash.WindowMode")+ ":" %></td>
			<td colspan="2">
				<select id="bx_flash_wmode" style="width:100px">
					<option value=""></option>
					<option value="window">window</option>
					<option value="opaque">opaque</option>
					<option value="transparent">transparent</option>
				</select>
			</td>
		</tr>
		<tr>
			<td align="right" colspan="2"><%= GetMessage("Flash.Scale")+ ":" %></td>
			<td colspan="2">
				<select id="bx_flash_scale"style="width:100px">
					<option value=""></option>
					<option value="showall">showall</option>
					<option value="noborder">noborder</option>
					<option value="exactfit">exactfit</option>
				</select>
			</td>
		</tr>
		<tr>
			<td align="right" colspan="2"><%= GetMessage("Flash.SAlign")+ ":" %></td>
			<td colspan="2">
				<select id="bx_flash_salign" style="width:100px">
					<option value=""></option> 
					<option value="left">left</option> 
					<option value="top">top</option> 
					<option value="right">right</option> 
					<option value="bottom">bottom</option> 
					<option value="top left">top left</option>
					<option value="top right">top right</option>
					<option value="bottom left">bottom left</option>
					<option value="bottom right">bottom right</option>
				</select>
			</td>
		</tr>
		<tr>
			<td align="right" colspan="2"><%= GetMessage("Flash.AutoPlay")+ ":" %></td>
			<td colspan="2">
				<input type="checkbox" value="" id="bx_flash_autoplay">
			</td>
		</tr>
		<tr>
			<td align="right" colspan="2"><%= GetMessage("Flash.Loop")+ ":" %></td>
			<td colspan="2">
				<input type="checkbox" value="" id="bx_flash_loop">
			</td>
		</tr>
		<tr>
			<td align="right" colspan="2"><%= GetMessage("Flash.ShowMenu")+ ":" %></td>
			<td colspan="2">
				<input type="checkbox" value="" id="bx_flash_showmenu">
			</td>
		</tr>
	</table>
</bx:BXTabControlTab>
<bx:BXTabControlTab ID="BXEdTabsFlash3" runat="server" Text="<%$ Loc:Flash.TabText.HTMLCode %>">
	<table width="100%" border="0" height="280">
		<tr>
			<td align="left" width="100%"><%= GetMessage("Flash.HTMLCode")+ ":" %><br />
				<textarea id="bx_flash_html_code" cols="53" rows="14"></textarea>
			</td>
		</tr>
	</table>
</bx:BXTabControlTab>
</bx:BXTabControl>
</div>

<% } else if (DialogName == "edit_hbf") { %>
<script>
function OnLoad()
{	
	oDialogTitle.innerHTML = TE_MESS.FILEMAN_EDIT_HBF;
	document.getElementById("__bx_head_ta").value = pObj.pMainObj._head + pObj.pMainObj._body;
	document.getElementById("__bx_footer_ta").value = pObj.pMainObj._footer;
}

function OnSave()
{
	document.getElementById("__bx_head_ta").value.replace(/(^[\s\S]*?)(<body.*?>)/i, "");
	pObj.pMainObj._head = RegExp.$1;
	pObj.pMainObj._body = RegExp.$2;
	pObj.pMainObj._footer = document.getElementById("__bx_footer_ta").value;
	pObj.pMainObj.updateBody();
}

function insertDefault_head()
{
	if (!confirm('<%= GetMessage("CONFIRM_HEAD")%>'))
		return;
	var oTA = document.getElementById("__bx_head_ta");
	var s60 = String.fromCharCode(60);
	var s62 = String.fromCharCode(62);
	oTA.value = s60 + '%@ Master Language="C#" Inherits="Bitrix.UI.BXMasterPage" %' + s62 + "\n" +
		'<html>' + "\n" +
		s60 + 'head runat="server"' + s62 + "\n" + 
		'<meta http-equiv="Content-Type" content="text/html;" />' + 
		'<title>Company name</title>' + 
		"</head>\n" + 
		'<body>';
}

function insertDefault_footer()
{
	if (!confirm('<%= GetMessage("CONFIRM_FOOTER")%>'))
		return;
	document.getElementById("__bx_footer_ta").value = "</body>\n</html>";
}

window.BXEdTabControlHBF = new BXTabControl('BXTabControl', 'BXEdTabControlHBF_selected', 
	[
		'BXEdTabControlHBF_strip_tab0_container', 
		'BXEdTabControlHBF_strip_tab1_container',
		'BXEdTabControlHBF_strip_tab2_container'
	]);
</script>
<div style="height: 330px;">
<bx:BXTabControl ID="BXEdTabControlHBF" runat="server" ButtonsMode="Hidden">
<bx:BXTabControlTab ID="BXTabHBFHead" runat="server" Text="<%$ Loc:TOP_AREA %>" Selected="true">
	<table width="100%" border="0" height="260">
		<tr>
			<td width="90%" style="font-size: 13px !important; color: #494949 !important; font-weight: bold !important; padding-left: 5px !important;"><%= GetMessage("EDIT_HEAD")%></td>
			<td width="10%" align="right">
				<div title="<%= GetMessage("INSERT_DEFAULT")%>" class="iconkit_c" onclick="insertDefault_head()" style="background-position: -162px -43px; width: 16px; height: 16px;"></div>
			</td>
		</tr>
		<tr>
			<td colSpan="2">
				<textarea id="__bx_head_ta" rows="14" style="width: 100%;"></textarea>
			</td>
		</tr>
	</table>
</bx:BXTabControlTab>
<bx:BXTabControlTab ID="BXTabHBFFooter" runat="server" Text="<%$ Loc:BOTTOM_AREA %>">
	<table width="100%" border="0" height="260">
		<tr>
			<td width="90%" style="font-size: 13px !important; color: #494949 !important; font-weight: bold !important; padding-left: 5px !important;"><%= GetMessage("EDIT_FOOTER")%></td>
			<td width="10%" align="right">
				<div title="<%= GetMessage("INSERT_DEFAULT")%>" class="iconkit_c" onclick="insertDefault_footer()" style="background-position: -162px -43px; width: 16px; height: 16px;"></div>
			</td>
		</tr>
		<tr>
			<td colSpan="2">
				<textarea id="__bx_footer_ta" rows="14" style="width: 100%;"></textarea>
			</td>
		</tr>
	</table>
</bx:BXTabControlTab>
</bx:BXTabControl>
</div>

<% }
   else { w.WriteLine("Dialog for \"{0}\" is not defined!", DialogName); }
// * * * * * * * * *  END DIALOGS  * * * * * * * * * * * *	
%>


<% if(show_controls){%>
</td></tr>	
<tr><td align="center" valign="top">
	<input id="saveBut" type="button" value="<%= GetMessage("Dialog.Save") %>" onclick="__OnSave();">
	<input id="cancelBut" type="button" value="<%= GetMessage("Dialog.Cancel") %>" onclick="pObj.Close();">
	<% if(DialogName == "settings"){ %>
		<input id="restoreDefault" type="button" value="<%= GetMessage("Dialog.Restore") %>">
	<%} %>
<% } %>
</td></tr></table>
<script>__OnLoad();</script>
</form>