function clientSize() {
      var w, h;
      w = (window.innerWidth ? window.innerWidth : (document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.offsetWidth));
      h = (window.innerHeight ? window.innerHeight : (document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.offsetHeight));
      return {width:w, height:h};
}
function move_topic_to_part(id)
{
    var scroll = document.documentElement.scrollTop || document.body.scrollTop;

    var sz = $(document.body).size();
    var size = clientSize();
	var wnd_bl=$().create('div')
		.style({overflow:'hidden',position:'absolute',width:px(sz.width),height:px(sz.height),top:px(0),left:px(0),backgroundColor:'#999'})
		.opacity(60)
		.appendTo(document.body).el;
	var wnd=$().create('div')
		.style({overflow:'hidden',border:'solid 1px rgb(0,0,0)',position:'absolute',width:px(400),height:px(300),top:px(scroll+100),left:px(size.width/2-200),backgroundColor:'#999'})
		.param({id:'move_wnd_topic'})
		.appendTo(document.body).el;
	$(wnd_bl).param({onclick:function(){$(wnd).drop(); $(wnd_bl).drop();}});

	var hd=$().create('div').style({height:px(25)}).appendTo(wnd).el;
	$().create('span').style({cursor:'pointer'})
		.param({className:'fl_Right_js',innerHTML:'[x]&nbsp;',onclick:function(){$(wnd).drop(); $(wnd_bl).drop();}})
		.appendTo(hd);
	$().create('span').style({color:'#FFF',fontWeight:'bold'})
		.param({innerHTML:'&nbsp;Перемещение темы'})
		.appendTo(hd);

	var cwnd=$().create('div')
		.style({overflow:'auto',borderTop:'solid 1px rgb(0,0,0)',width:'100%',height:px(273),backgroundColor:'rgb(250,250,250)'})
		.param({innerHTML:'Loading...'})
		.appendTo(wnd).el;
    var mid=id;
        	o = {};
            Ajax.post('/'+Lang+'/forum/topics/move',o,{
            	onSuccess : function (req)
            	{
            		if (req.responseXML)
            		{
            			if(req.responseXML.getElementsByTagName('root').item(0))
            			{            				$(cwnd).empty();
            				$(makeTreeParts(mid,req.responseXML.getElementsByTagName('root').item(0))).appendTo(cwnd);
            			}
            			else
            				cwnd.innerHTML='Load bad data!';
            		}
            		else cwnd.innerHTML='loading was falled!';
            	}
            });
}

function makeTreeParts(mid,xml)
{	var ul=$().create('ul').style({listStyleType:'none',margin:0,paddingLeft:px(15)}).el;
	var it=xml.firstChild;
	if(!it) return ul;
	do
	{
		if(it.nodeType==1)
        {			var id=it.getAttribute('id');
			var title=it.getAttribute('title');
			var is_pot=parseInt(it.getAttribute('is_pot'));
			if(!is_pot)
			{
				$().create('li').param({innerHTML:title}).appendTo(ul);
				$(makeTreeParts(mid,it)).appendTo(ul);
			}
			else
			{
			 	var li=$().create('li').appendTo(ul).el;
			 	$().create('a').param({href:'/'+Lang+'/forum/topics/move?pid='+id+'&mid='+mid,innerHTML:title}).appendTo(li);
			}
		}
	} while(it=it.nextSibling)

	return ul;}

function editTopic(id,name)
{
	$('ed_object_id').param({value:id});
	$('ed_subject_name_id').param({value:name});
	$('ed_hidden_text_edit_id').param({value:''});
	$('editor').param({className:'subject_editing',action:'/'+Lang+'/forum/topics/edit'});
	$('editor').el.onsubmit=function() {
		s=$('ed_subject_name_id').el.value;
		if(!(s.replace(' ','').replace('\r','').replace('\n','').replace('\t','').length))
		{
			$('ed_subject_name_id')
				.style({backgroundColor:'rgb(255,150,150)'})
				.param({onkeydown:function(){this.style.backgroundColor='rgb(255,255,255)'; this.onkeydown='';}});
			return false;
		}
		else return true;
	};

	window.onresize = function(){
		var sEl=$('statistics').el;
		sEl.style.width='850px';
		setTimeout(function(){sEl.style.width='';},0);
	};
    moveSiteForIE6();
	window.location='#editor';
}

function addTopic()
{	$('ed_object_id').param({value:''});
	$('ed_subject_name_id').param({value:''});
	$('ed_hidden_text_edit_id').param({value:''});
	$('editor').param({className:'subject_create',action:'/'+Lang+'/forum/topics/add'});
	$('editor').el.onsubmit=function() {		$('ed_hidden_text_edit_id').el.value = window.elTextEdit.getData();
		s=$('ed_subject_name_id').el.value;
		if(!(s.replace(' ','').replace('\r','').replace('\n','').replace('\t','').length))
		{
			$('ed_subject_name_id')
				.style({backgroundColor:'rgb(255,150,150)'})
				.param({onkeydown:function(){this.style.backgroundColor='rgb(255,255,255)'; this.onkeydown='';}});
			return false;
		}
		else return true;
	};
	createTextEditor();
	moveSiteForIE6();
	window.location='#editor';
}

function delTopic(id){
	if(confirm('Действительно удалить?'))
	{
		var form=$('id_act_frm_sub').empty().param({method:'get',action:'/'+Lang+'/forum/topics/del',onsubmit:function(){return true;}}).el;
		$().create('input').param({type:'hidden',name:'pid',value:id}).appendTo(form);
		form.submit();
	}
}

function closeTopic(id){
	if(confirm('Действительно закрыть?'))
	{
		var form=$('id_act_frm_sub').empty().param({method:'get',action:'/'+Lang+'/forum/topics/close',onsubmit:function(){return true;}}).el;
		$().create('input').param({type:'hidden',name:'pid',value:id}).appendTo(form);
		form.submit();
	}
}
