function editTopic(id,e){
	try{
		if(event!=undefined){
			e=event
		}
	}catch(ex){}
	this.e=e;
	m=getMouseIntXY(e);
	this.x=m[0];
	this.y=m[1];
	
	this.pageContainer=$('body');
	if(window.innerHeight){ 
		this.height=window.innerHeight;
		this.width=window.innerWidth;
		
	}else{
		this.height=document.body.clientHeight;
		this.width=document.body.clientWidth;
	}
	this.id=id;
	this.getTopic();
}

editTopic.prototype.getTopic=function(){
	this.xmlHttp_post = getXML();
	this.xmlHttp_post.obj=this;
	
	this.xmlHttp_post.onreadystatechange = this.handelGetTopic;

	var send=Object();
	send.operation='getTopic';
	send.id=this.id;
	post= escape(prepearVar2(send));
	var string=base+"ajax/cms/forum/common/"+send.operation+"?js="+post;
	this.xmlHttp_post.open("GET",string,true);
	this.xmlHttp_post.send(post);
	return false;
}
editTopic.prototype.handelGetTopic=function(){
	if(this.readyState==4){
		//alert(this.responseText);
		var jsonvar = Object();
		try{jsonvar=eval('(' + this.responseText + ')');
		}catch(ex){alert('Вътрешна грешка: Сървърът не отговаря!'+ex);return;}
		if(jsonvar.status!='ok'){alert('Транспортна грешка: Няма връзка със сървъра!');return;}
		
		if(jsonvar.loged==1){
			this.obj.topic=jsonvar.topic;
			this.obj.win();
		}else{
			//alert(this.obj.e.clientX);
			new loginPan(this.obj.x,this.obj.y);
		}
	}
}
	
editTopic.prototype.win=function(){
	
	if($('over')){
		over=$('over');
		over.innerHTML='';
	}else{
		over=document.createElement('div');
		over.id="over";
		over.style.position	="absolute";
		over.style.top		="0px";
		over.style.left		="0px";
		over.style.width	="100%";
		over.style.height	="100%";
	}
	
	this.pageContainer.appendChild(over);
	backgr=document.createElement('div');
	backgr.style.backgroundColor="#000000";
	backgr.style.position	="absolute";
	backgr.style.zIndex		="9";
	backgr.style.top		="0px";
	backgr.style.left		="0px";
	backgr.style.width		="100%";
	//backgr.style.height	="100%";
	backgr.style.height	=	"100%"; 
	backgr.style.opacity	="0.2";
	backgr.style.filter	="alpha(opacity=20)";
	over.appendChild(backgr);
	
	
	
	pan= document.createElement('div'); 
	over.appendChild(pan);
	pan.style.zIndex		="10";
	pan.style.backgroundColor="#ffffff";
	pan.style.border	="3px solid #888888";
	pan.style.position	="absolute";
	pan.style.top		=(this.y-100)+"px";
	pan.style.left		=(this.width/2-100)+"px";
	pan.style.width		="415px";
	pan.style.height	="150px";
	
	newpostForm= document.createElement('form'); 
	pan.appendChild(newpostForm);
	newpostForm.onupload=function(){return false;}
	newpostFormFieldset=document.createElement('fieldset');
	newpostForm.appendChild(newpostFormFieldset);
	newpostFormFieldset.style.padding="10px";
	newpostFormFieldset.style.margin="10px";
	
	newpostFormFieldsetLegend=document.createElement('legend');
	newpostFormFieldset.appendChild(newpostFormFieldsetLegend);
	newpostFormFieldsetLegend.innerHTML='<img src="'+imgpath+'icon_topicLight_20.png" /> Редакция на темата';
	
	newpostFormFieldsetLable1=newLabel('title','Заглавие:');
	newpostFormFieldset.appendChild(newpostFormFieldsetLable1);
	newpostFormFieldsetInput1=newInput('text','title','title',this.topic.title,'');
	newpostFormFieldset.appendChild(newpostFormFieldsetInput1);
	newpostFormFieldsetInput1.style.width="250px";
	
	ok=document.createElement('button');
	newpostFormFieldset.appendChild(ok);
	ok.style.styleFloat='right';
	ok.style.background="url('"+imgpath+"icon_right_20.png') no-repeat top left #f0fff0";
	ok.style.width='90px';
	ok.style.height='22px';
	ok.style.textAlign='left';
	ok.style.border='1px solid #f0f0f0';
	ok.style.padding='0px 0px 0px 25px';
	ok.style.margin='10px 10px 10px 0px';
	ok.innerHTML="Промени";
	ok.obj=this;
	ok.onclick=this.save;
	
	cancel=document.createElement('button');
	newpostFormFieldset.appendChild(cancel);
	cancel.style.styleFloat='right';
	cancel.style.background="url('"+imgpath+"icon_exit_20.png') no-repeat top left #fff0f0";
	cancel.style.width='90px';
	cancel.style.height='22px';
	cancel.style.textAlign='left';
	cancel.style.border='1px solid #f0f0f0';
	cancel.style.padding='0px 0px 0px 25px';
	cancel.style.margin='10px 10px 10px 0px';
	cancel.innerHTML="Отмени";
	cancel.onclick=this.closeWindow;
}
editTopic.prototype.closeWindow=function(){
	tinyMCE.execCommand('mceRemoveControl',false,'tinyMCE');
	try{
		over=$('over');
		over.parentNode.removeChild(over);
	}catch(ex){
		alert(ex);
	}
	return false;
}

editTopic.prototype.save=function(){
	tinyMCE.triggerSave();
	this.xmlHttp_save = getXML();
	this.xmlHttp_save.obj=this.obj;
	this.xmlHttp_save.onreadystatechange = this.obj.handelSave;

	var send=Object();
	send.operation='updateTopic';
	send.id=this.obj.id;
	send.title=$('title').value;
	send.forum_url=forum_url;
	post= escape(prepearVar2(send));
	var string=base+"ajax/cms/forum/common/"+send.operation+"?js="+post;
	this.xmlHttp_save.open("GET",string,true);
	this.xmlHttp_save.send(post);
	return false;
}
editTopic.prototype.handelSave=function (){
	if(this.readyState==4){
		//alert(this.responseText);
		var jsonvar = Object();
		try{jsonvar=eval('(' + this.responseText + ')');
		}catch(ex){alert('Вътрешна грешка: Сървърът не отговаря!'+ex); this.obj.closeWindow; return;}
		if(jsonvar.status!='ok'){alert('Транспортна грешка: Няма връзка със сървъра!'); this.obj.closeWindow; return;}
		//this.obj.closeWindow();
		//window.location=window.location;
		window.location.reload(true)

	}
}
