var myedit;
var useredit;
var bkLib;
 function setnicEditor(){
 
myedit= new nicEditor({iconsPath : '/images/nicEditorIcons.gif',maxWidth : 680,maxHeight : 210,buttonList :['save','bold','italic','underline','left','center','right','justify','ol','ul','fontSize','fontFamily','fontFormat','indent','outdent','image','upload','link','unlink','forecolor']}).panelInstance('content1');
 
 }
 function setmyedit(id){
	useredit = new nicEditor(); 
	 
	var myid='post'+id;
    useredit.addInstance(myid); 
	var obj=document.getElementById(myid);
	obj.className="borderd";
	var bottom=document.getElementById('bottom_'+id);
	bottom.innerHTML='<input name="edit_ok" type="button" value="提交" onclick="edit_submit('+id+')" /> <input type="button" value="取消"  onclick="removemyid('+id+')" />';
 				
				
 }
window.onload(function() {
	// setnicEditor();	
});
/**/
 function addArea2() {
	  setnicEditor();
}
function removemyid(id) {
	var myid='post'+id;
	 useredit.removeInstance(myid);
var obj=document.getElementById(myid);
obj.className="moveborderd";
var bottom=document.getElementById('bottom_'+id);
bottom.innerHTML='';
}
function edit_submit(id){
	var myid='post'+id;
	var obj=document.getElementById(myid);	 
	var bottom=document.getElementById('bottom_'+id);
	bottom.innerHTML='';	
	obj.className="moveborderd";
	var str=obj.innerHTML;		
	var url="/posts/editpost/";
	$.post(url,{ pid: id, content: str } );
	
	}



function removeArea2() {
	myedit.removeInstance('content1');
}

function showcode(obj){
var chk=obj.checked;
	if(chk){
	 removeArea2();
	}else{
	addArea2();
	}
}
function addsubmit(){
	var from=document.getElementById('pub');
	var text=document.getElementById('content1');
	var checkbox=document.getElementById('checkbox');
	if(checkbox.checked){
	addArea2();
	}
	
	var str= myedit.nicInstances[0].getContent(); 
	 
	 
	if(str.length<8){
		alert('回复内容需大于5个字符');
		return false;
	}else{
		text.value=str;
		from.submit();
	}

}
function myjquery(ids,los){
var lo;
	if(los<1){
		lo='楼主';
	}else{
	lo=los+'楼';
	}
	var post= delHtmlTag($('#post'+ids).html());
	 
	 var html='<div class="block_div"><p  class="block_p">引用第'+lo+'&nbsp; </p>'+post.substr(0,100)+'....</div><br />';
	 
	  insertHtml(html); 
}
function jubao(tid,login){//举报
	if(login==''){
		
		PleaseLogin();
	}else{
		$.get('/tpl/implead.html',null,function(date){
		//	offset()						   
	 $('#UserLoginXml').html(date); 
	 var offset =250+document.documentElement.scrollTop; 
	 $('#UserLoginXml').css("top",offset); 	 
	$('#UserLoginXml').fadeIn("fast"); 
	$('body').addClass("html"); 
	$('#thrid').val(tid);
 	
	});
		
		
		//implead.html
	;
	
	
	
		}
}

function implead(){
	var ra=$('input:checked').val();
	var other=$('#other').val();
	var tid=$('#thrid').val();
	var str;
	 if(other.length<5){
		 	str=ra ;
	 }else{
		str=other ;
	 }
	// alert(tid);
	$('#UserLoginXml').fadeOut("fast"); 	 
	$('body').removeClass("html"); 
 	$.get('/therads/implead/',{ imid: tid, cont: str } ,function(date){alert('谢谢您举报,我们会尽快审核处理!');}) 
	 
	
	}
function deletepost(url,id){
	if(confirm('确定删除吗?')){
	 var ids='tposts'+id;
	$.get(url,null,function(date){
	if(id==1){
	//	alert('删除成功');
		//$("#"+ids).remove(); 
	window.opener=null;
    window.open('','_self');
    window.close(); 
	}else{
	$("#"+ids).remove(); 
	}
	
	
	}); 
	}
}

function delHtmlTag(str) 
{ 
   return str.replace(/<[^>]+>/g,"");//去掉所有的html标记 
} 
 function addcolle(url){
 	$.get(url,null,function(date){if(date=='ok'){alert('收藏成功!');}else{alert('此帖已存在收藏夹中,无需重复加入!');}});
 
 }
 
 function CheckSubmit(form){
				publish_article();

			 	//var str=document.getElementById("Content1_textarea").innerHTML;
				var from=document.getElementById("Content1_area");
				 var str=from.document.getElementById("Content1_textarea").innerHTML;
				 
				if(str.length <4)
				{
					alert('请输入内容，内容字符不能少于四个!');
					return false;

				}else{
					 
					return true;
					
				}
}
