//去除两边空格
function Trim(input_blank){
    return input_blank.replace( /(^\s*)|(\s*$)/g, "" );
}

//获取验证码
function rmd(style) {
	document.getElementById('randpic').setAttribute('src',
			'script/sessCode.php?style='+style+'&rand=#%@' + Math.random());
}
 
 function inputs(inputid) {
	var doc = document.all;
	inertContent("[face]"+inputid+"[/face]");
}//end function

function inertContent(val) {
	if(val==''){
		alert('没有需要添加的内容！' );
	return;
	}
	document.formreply.content.value += val;
}


function go_url(fid,arg){
	var url = "/bbs/forum.php?act=index&fid="+fid+"&list=";
	if(arg=='all')  url += "&arg=all";
	url += "&tl="+document.list_form.tl.options[document.list_form.tl.selectedIndex].value;
	url += "&ol="+document.list_form.ol.options[document.list_form.ol.selectedIndex].value;
	url += "&order="+document.list_form.order.options[document.list_form.order.selectedIndex].value;
	window.location.href=url;
}

function sub_form(){
	if( document.post_form.title.value==''||document.post_form.title.value.length>100 ){
		alert( '系统提示 文章的标题不能为空，且不能多于100个字符！' );
		return false;
	}
	if( document.post_form.content.value==''||document.post_form.content.value.length>30000 ){
		alert( '系统提示 ,文章的内容不能为空，且不能多于30000个字符！' );
		return false;
	}
	
	/*
	if( document.post_form.rand.value=='' ){
		alert( '系统提示,请输入验证码！' );
		return false;
	}
	*/
	
	format();
	yanzhen();
}
function yanzhen(){
	document.post_form.submit();return;
	$.get('script/sessCode.php',{act:'verify',id:document.post_form.rand.value},function (data){
	 	 if(data!=1){
		 	alert( '验证码不对 请重新输入！' );
			rmd();
			return false;
		 }else
		 document.post_form.submit();
	 });
}
function format()
{
        var body = document.getElementById("thebody").value;
		body = body.replace(/\r\n/ig,"\n");
		body = body.replace(/\n\n/ig,"\n");
		body = body.replace(/\n/ig,"<br/>");
        /*body = body.replace(/ |　/ig,"");
        body = body.replace(/\r\n/ig,"\n");
        body = body.replace(/\n\n/ig,"\n");
        body = body.replace(/\n\n/ig,"\n");
        body = body.replace(/\n\n/ig,"\n");
        body = body.replace(/\n\n/ig,"\n");
        body = body.replace(/\n/ig,"\n\n");
        body = body.replace("\n\n","");*/
        document.getElementById("thebody").value=body;
}

function ctlent( event ) {
	if( event.ctrlKey && event.keyCode == 13 ){
		sub_form();
	}
}

function quickreplytwo(){
	if( document.formreply.title.value==''||document.formreply.title.value.length>100 ){
		alert( '系统提示 文章的标题不能为空，且不能多于100个字符！' );
		return false;
	}
	if(document.formreply.content.value=='' || document.formreply.content.value.length < 8 ){
		alert( '内容不能小于8个字符，最大30000个字符！' );
		document.getElementById("btnImage").style.visibility ="visible";
		document.formreply.content.focus();
		return false;
	}else{
		var content = document.formreply.content.value;

		var contents = content;
		contents = contents.replace(/\[face\][0-9]{3}\[\/face\]/ig, "");
		var status= (contents.length>0)?true:false;
		if(!status){
			alert('请不要纯表情回复！');
			document.getElementById("btnImage").style.visibility ="visible";
			document.formreply.content.focus();
			return false;
		}
		str=delHtmlTag(content);
		strlen=str.replace(/&nbsp;/g,"a");
		if(strlen.length>20000){
			alert("内容请不要大于20000字！"); 
			return false;
		}
		content = content.replace(/\r\n/ig,"\n");
		content = content.replace(/\n\n/ig,"\n");
		content = content.replace(/\n/ig,"<br>");
		document.formreply.content.value = content;
		return true;
	}
	return false;
}
function sub_form2(){
	if(quickreplytwo())  yanzhen2();
	return false;
}
function yanzhen2(){
	document.formreply.submit();return;
	$.get('script/sessCode.php',{act:'verify',id:document.formreply.rand.value},function (data){
	 	 if(data!=1){
		 	alert( '验证码不对 请重新输入！' );
		 	var img = document.getElementById("btnImage");
		 	if(img) img.style.visibility ="visible";
			rmd();
			return false;
		 }else
		 document.formreply.submit();
	 });
}
function divdisplay(id,st){
	if(st==1){
	document.getElementById(id).style.display='';
	}
	if(st==2)
	document.getElementById(id).style.display="none";
}
function ctlent( event ) {
	if( event.ctrlKey && event.keyCode == 13 ){
		sub_form2();
	}
}

//add edit reply
var attachnum = 0;
var total_attachnum = 3;

function check_post(){
	if( Trim(document.post_form.title.value) =="" ){
		alert( "请认真填写标题，谢谢合作！" );
		document.post_form.title.focus();
		return false;
	}
		var oEditor = FCKeditorAPI.GetInstance("content");
	if( oEditor.GetXHTML(true) =="" ){
		alert( "请认真填写内容，谢谢合作！" );
		return false;
	}

	str=delHtmlTag(oEditor.GetXHTML(true));
	strlen=str.replace(/&nbsp;/g,"a");
	if(strlen.length>20000){
		alert("内容请不要大于20000字！");
		return false;
	}

	var conte = oEditor.GetXHTML(true);
	conte = conte.replace(/\[face\][0-9]{3}\[\/face\]/ig, "");
	conte = conte.replace(/\<p\>\<\/p\>/ig, "");
	var status= (conte.length>0)?true:false;
	if(!status){
		alert('请不要纯表情发帖！');
	return false;
	}
		
	/*
	if( Trim(document.post_form.rand.value) =="" ){
		alert( "请填写验证码，谢谢合作！" );
		return false;
	}
	*/
	yanzhen3();
}//end

function delHtmlTag(str)
{
        return str.replace(/<[^>]+>/g,"");//去掉所有的html标记
}

function yanzhen3(){
	document.post_form.submit();return;
 $.get('script/sessCode.php',{act:'verify',id:document.post_form.rand.value},function (data){
 	 if(data!=1){
	 	alert( '验证码不对 请重新输入！' );
		rmd();
		return false;
	 }else
	 document.post_form.submit();
 });
}

function inputs2(inputid) {
	var doc = document.all;
	InsertHTML("content","[face]"+inputid+"[/face]");
}

//复制链接
function fCopyToClicp(id){
	var a = window.location.href;
	if(navigator.userAgent.toLowerCase().indexOf('ie') > -1) {
		window.clipboardData.setData('text',a );
		alert ("连接已经复制到您的剪贴板中\n您可以使用Ctrl+V快捷键粘贴到需要的地方");
	} else {
		prompt("请复制链接地址:",a );
	}
}

function sfHover() {
	var sfEls = document.getElementById("sort_nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		};
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		};
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

function disatt(id){
	var contentatt=document.getElementById(id+"dimg");
	var attatt=document.getElementById(id+"file");
	if(contentatt){//判断是否插入
	   attatt.style.display="none";
	}else {
	   attatt.style.display="";
	}

}

//判断浏览器
var ie = (navigator.appVersion.indexOf("MSIE")!=-1);//IE
var ff = (navigator.userAgent.indexOf("Firefox")!=-1);//Firefox
var faUrl = "http://www.eefocus.com";
var faTitle = '『与非网——电子专才的职业加油站（提供产业信息，技术资料，方案测评和在线教学）』';
//兼容的加入收藏函数
function addFavorite()
{
if(ie){window.external.AddFavorite(faUrl, faTitle);}
if(ff){window.sidebar.addPanel( faTitle, faUrl, 'Eefocus');}
}

function not_negative_points(id){
	var expstr = /^([0-9]*|0)$/; 
	if(!expstr.test($('#'+id).val())){
		$('#'+id).val('0');
		alert('请填写正整数');
		return false;
	}
}
