
function Editor_OnClientCommandExecuted(editor, commandName, tool)
{
	if (commandName == "InsertCustomLink" && tool && tool.GetSelectedValue) 
	{
		var html = editor.GetHtml();
		var span = editor.Document.createElement("SPAN");
		span.innerHTML = html;
		var links = span.getElementsByTagName("A");
		for (var i=0; i < links.length; i++)
		{
			var href = links[i].href;
			var idx = href.indexOf("--poll--");
			if (idx >= 0)
			{
				var tmpSpan = editor.Document.createElement("SPAN");
				var id = href.substring(idx+8,href.length); 
				var xmlhttp = new ActiveXObject("MSXML2.XMLHTTP"); 
				xmlhttp.Open("GET","http://" + window.location.hostname + "/ecms/controls/render.aspx?mod=poll&id=" + id,false);
				xmlhttp.Send(null); 
				tmpSpan.innerHTML = xmlhttp.responseText;
				tmpSpan.innerHTML = tmpSpan.getElementsByTagName("form")[0].innerHTML;
				var inputs = tmpSpan.getElementsByTagName("input")
				for (var j=0; j < inputs.length; j++)
				{
					if (inputs[j].type.toLowerCase() == "hidden" && inputs[j].name.toLowerCase() == "__viewstate")
					{
						tmpSpan.removeChild(inputs[j])
					}
				}
				html = ReplaceString(html,links[i].outerHTML,""
					+ '<ecms:div id="--ecmsuserpoll--' + id + '">'
					+ tmpSpan.innerHTML
					+ '</ecms:div>');
			}
		} 
		editor.SetHtml(html);
	}
}

function ReplaceString(fullS,oldS,newS) 
{
	for (var i=0; i<fullS.length; i++) 
	{
		if (fullS.substring(i,i+oldS.length) == oldS)
		{
			fullS = fullS.substring(0,i)+newS+fullS.substring(i+oldS.length,fullS.length)      
		}   
	}   
	return fullS
}

