var FCK;
function insertAllnightUser(login,shortcut,instance)
{
	if(!instance||instance=="false")
	{
			var FCK= window.opener.FCK;

			FCK.Focus();
			FCK.InsertHtml('<a class="all_user" href="/users/'+shortcut+'"><img src="/img/icons/user.gif" hspace="3" align="absmiddle" border="0">'+login+'</a>');
	} else window.opener.insertText('<all_user" user="'+shortcut+'">'+login+'</all_user>',instance);
			window.close();
}

function upload_picture()
{
	var req = new JsHttpRequest();
	req.onreadystatechange = function() {if (req.readyState == 4) {
			if(req.responseJS.message) alert(req.responseJS.message); else
			{
				if(!req.responseJS.instance||req.responseJS.instance=='false')
				{

				var FCK=window.opener.FCK;
				FCK.Focus();
//				FCK.InsertHtml('');
				FCK.InsertHtml('<img class="ufoto" src="/'+req.responseJS.thumb+'?picture='+req.responseJS.picture+'?zoom='+req.responseJS.zoom+'" border=0 />');
				}
				else window.opener.insertText('<all_img thumb="'+req.responseJS.thumb+'" picture="'+req.responseJS.picture+'" zoom="'+req.responseJS.zoom+'">',req.responseJS.instance);

				window.close();
			}
			document.getElementById('uppic').subm.disabled=false;
	        }}
    req.open(null, '/ajax.php5?a=upload_picture', true);
    req.send( { 'form': document.getElementById('uppic') } );

}

function show_smiley(obj,instance)
{
	FCK=obj;
	sPop2=true;
//	sPop1=!sPop1;
	iPopMenu2('/ajax.php5?a=get_smiley&instance='+instance,400,300,true);
}

function insert_smiley(smiley,instance)
{
	if(!instance||instance=='false')
	{
	sPop1=false;
	sPop2=false;
	FCK.Focus();
	FCK.InsertHtml('<img class="smiley" src="/img/smile/'+smiley+'.gif" />');
	}
	else
	{
		insertText('[s:'+smiley+']',instance);
	}

	if(document.getElementById('andclose').checked) hide_popup2();

}

function switch_editor(instance,mode,dv)
{

	if(mode==0)
	{

    if (! FCKeditorAPI) return;
    var oEditor = FCKeditorAPI.GetInstance(instance);
    if (! oEditor) return;
    var editor_frame = document.getElementById(instance+ '___Frame');
    var editor_source = editor_frame.contentWindow.document.getElementById('eEditorArea');

	var Html = '';

			Html = Html + "<input type=hidden name=\"tlb"+dv+"\" id=\"tlb"+dv+"\" value=\""+document.getElementById('tlb'+dv).value+"\">";

			Html = Html + "<table width=500 height=26 cellpadding=0 cellspacing=0 border=0 style=\"background: #EFEFDE url('/img/panel.gif') no-repeat left top;\">";
			Html = Html + "<tr>";
			Html = Html + "<td style=\"padding-left:24px;\" valign=middle>";
			Html = Html + "<button class=opb onclick=\"tagme('b','ed_"+instance+"'); return false;\"><img src=\"/img/buttons/bold.gif\" width=22 height=22></button>";
			Html = Html + "<button class=opb onclick=\"tagme('i','ed_"+instance+"'); return false;\"><img src=\"/img/buttons/italic.gif\" width=22 height=22></button>";
			Html = Html + "<button class=opb onclick=\"tagme('u','ed_"+instance+"'); return false;\"><img src=\"/img/buttons/underline.gif\" width=22 height=22></button>";
			Html = Html + "<button class=opb onclick=\"tagme('li','ed_"+instance+"'); return false;\"><img src=\"/img/buttons/list.gif\" width=22 height=22></button>";
			Html = Html + "<button class=opb onclick=\"blink('ed_"+instance+"'); return false;\"><img src=\"/img/buttons/link.gif\" width=22 height=22></button>";
			Html = Html + "<button class=opb onclick=\"buser('ed_"+instance+"'); return false;\"><img src=\"/img/buttons/user.gif\" width=22 height=22></button>";
			Html = Html + "<button class=opb onclick=\"bquote('ed_"+instance+"'); return false;\"><img src=\"/img/buttons/quote.gif\" width=22 height=22></button>";
			Html = Html + "<button class=opb onclick=\"bcut('ed_"+instance+"'); return false;\"><img src=\"/img/buttons/cut.gif\" width=22 height=22></button>";
			Html = Html + "<button class=opb onclick=\"bimg('ed_"+instance+"'); return false;\"><img src=\"/img/buttons/image.gif\" width=22 height=22></button>";
			Html = Html + "<button class=opb onclick=\"bvideo('ed_"+instance+"'); return false;\"><img src=\"/img/buttons/video.gif\" width=22 height=22></button>";
			Html = Html + "<button class=opb onclick=\"bsmile('ed_"+instance+"'); return false;\"><img src=\"/img/buttons/smile.gif\" width=22 height=22></button>";
			Html = Html + "</td>";
			Html = Html + "</tr>";
			Html = Html + "</table>";

	
		iFrameHeight = oEditor.EditorWindow.frameElement.offsetHeight ;
		iFrameWidth = oEditor.EditorWindow.frameElement.offsetWidth ;

    HtmlValue = oEditor.GetXHTML(false);

	Html = Html + "<textarea id=\"ed_"+instance+"\" name=\""+instance+"\" rows=\"4\" cols=\"40\" style=\"width:500px; height:"+iFrameHeight+";\">"+HtmlValue+"</textarea>" ;
	}
	else
	{
		var Value=document.getElementById(instance).value;
		Value=Value.replace(/\"/g,"&quot;");
		Value=Value.replace(/</g,"&lt;");
		Value=Value.replace(/>/g,"&gt;");
		var Html = '';
		var configValue='';
		var tlb=document.getElementById('tlb'+dv).value;

		hgt=parseInt(document.getElementById(instance).style.height)+30;

		Html = Html + "<input type=hidden name=\"tlb"+dv+"\" id=\"tlb"+dv+"\" value='"+document.getElementById('tlb'+dv).value+"'>";

		Html = Html + "<input type=\"hidden\" id=\""+instance+"\" name=\""+instance+"\" value=\""+Value+"\" style=\"display:none\" />" ;
		Html = Html + "<input type=\"hidden\" id=\""+instance+"___Config\" value=\""+configValue+"\" style=\"display:none\" />" ;
		Html = Html + "<iframe id=\""+instance+"___Frame\" src=\"/fckeditor/editor/fckeditor.html?InstanceName="+instance+"&Toolbar="+tlb+"\" width=\"500\" height=\""+hgt+"\" frameborder=\"0\" scrolling=\"no\"></iframe>" ;

		
	}

    eddv=document.getElementById(dv);
    eddv.innerHTML=Html;
}

