/*
0: id          1 :time        2 :flag        3 :state       4 :score       5 :content     6:userid
7:username     8: zoneroot    9 :zonecity    10:zonename    11:userflag    12:upfilename  13:upfileurl
*/

/* 页面标题 */
if (document.title.substring(0,5)!='手机论坛群'){
	top.document.title = document.title;
}

/* 图片缩放 */
var flag=false; 
function DrawImage(ImgD){ 
var image=new Image(); 
image.src=ImgD.src; 
if(image.width>0 && image.height>0){ 
  flag=true; 
  if(image.width/image.height>= 1){ 
   if(image.width>400){
	ImgD.resized = true; 
    ImgD.width=400; 
    ImgD.height=(image.height*400/image.width); 
   }else{ 
    ImgD.width=image.width;
    ImgD.height=image.height; 
   } 
   /*ImgD.alt="bigpic"  */
  } 
  else{ 
   if(image.height>400){
   	ImgD.resized = true; 
	ImgD.height=400; 
    ImgD.width=(image.width*400)/image.height; 
   }else{ 
    ImgD.width=image.width;
    ImgD.height=image.height; 
   } 
    /*ImgD.alt="bigpic"  */ 
  }
	//是否缩放.
	if(ImgD.resized)
	{
		 ImgD.onmouseover = function(){ show_big(this); }
		 ImgD.onclick = function(){ open_big(this); }
	}
}
}
function show_big(obj)
{
	obj.style.cursor = "hand";
	obj.alt = "点击后可看大图";
}
function open_big(obj)
{
	open(obj.src);
}

/* 开新窗 */
function openwin(openurl,openwidth,openheight) {
	window.open(openurl,'younetalert','width='+openwidth+',height='+openheight+',top=100,left=100,toolbar=no,location=no,directories=no,menubar=no,scrollbars=no,resizable=no,status=no');
}

/* 搜索表单检查 */
function srh_chk(itm){
	if (itm.search_word.value == '') {
		itm.search_word.focus();
		alert('请输入查询关键词！');
		return false;
	}else{
		return true;
	}
}

/** 
 * 公告列表 
 * key=>公告id
 * val0 公告标题
 * val1 公告url
 * val2 是否有公告内容
 * val3 公告颜色
 * val4 公告字号
 * val5 公告滚动否
*/
function bull(b,bp,bt,p,t){
	for (key in b){
		if ((bp[key][p]||bp[key][0]) && (bt[key][t]||bt[key][0])){
//		if ( (bp[key][p]==1||bt[key][t]==1) || (bp[key][0]==1&&bt[key][0]==1) ){
			b1 = b[key];
			//颜色，字体
			style = " style='color:"+b1[3]+"; font-size:"+b1[4]+";'";
			out = '';
			//有链接或内容
			if (b1[1]!=''||b1[2]==1){
				out += "<a href='"+(b1[1]!=''?b1[1]:'bullview.php?id='+key)+"' target='_blank'"+style+">"+b1[0]+"</a><br>";
			//只有标题
			}else {
				out += "<span"+style+">"+b1[0]+"</span><br>";
			}
			//滚动
			if (b1[5]==1){
				out = "<marquee  scrollamount=4 scrolldelay=25 width=100% onmouseover='this.stop();' onmouseout='this.start();'>"+out+"</marquee>";
			}

			document.write(out);
		}
	}
}

/* 用户名，社区*/    
function lu(t1){
	tmp = '';
	
	if(t1[6]==0) {
		tmp+='<font color=blue>'+t1[7]+'</font> ';
	}else {
		tmp+='<a target="_blank" href="'+(t1[6]!=0?'http://user.younet.com/detail.php?id='+t1[6]:'#')+'">'+t1[7]+'</a> ';
	}
	if (t1[10]=='yy') {
		tmp+="<a href='http://player.younet.com/club/yy_intro.php' target=_blank class=silver><img src='http://forum.younet.com/pics/wappost.gif' alt='手机发帖' border='0'></a>";
	}else if (t1[11]==9){
		tmp+='<font color="#666666">('+t1[10]+')</font>';
	//试飞标志  
	}else if (t1[6]==99999){
		tmp+='<font color="#000000">(</font><a href="http://forum.younet.com/22385.html" target="_blank"><img src="http://player.younet.com/images/trade/343.gif" border="0">P51 试飞员</a><font color="#000000">)</font>';
	}else {
		tmp+='<i><a target="_blank" href="http://community.younet.com/main.php?BoardID='+t1[8]+'&AreaID='+t1[9]+'">('+t1[10]+'社区'+')</a> </i>';
	}

	return tmp;
}
/* 发贴时间 */
function lt(t1){
	return ''+t1[1]+'';
}
/* 帖子内容*/
function lc(t1,i,cut,rootid){
	if(t1[6]==6||t1[6]==8){
		t1[5] = '<font color=blue>'+t1[5]+'</font>';
	}
	
	t1[5] = t1[5].replace(/\\n/ig,'\n');
	tmp = '';
	/* 最后编辑正则 */
	//reg = /<div style=\"[^\"]+\">　　用户 .+ 编辑了此帖子。<\/div>$/ig;
	reg = /<div style=\"[^\"]+\">　　用户 .+ 编辑了此帖子。<\/div>$/ig;
	/* 截取最后编辑代码 */
	endfix = t1[5].match(reg);
	if (endfix==null){
		endfix = '';
	}else{
		endfix = endfix[0];
	}
	t1[5] = t1[5].substring(0,t1[5].length-endfix.length);
	/* 高亮搜索关键词 */
	if (search_page){
		/* 内容搜索 */
		if (search_type=='content'){
			reg = 'reg = /('+search_word.replace(/ /ig,'|')+')/ig';
			eval(reg);
			t1[5]=t1[5].replace(reg,' <font color=red>$1</font> ');
		/* 发贴用户搜索 */
		}else if(search_type=='username'){
			if (t1[7]==search_word){
				t1[5] = '<font color=red>'+t1[5]+'</font>';
			}
		/* 发贴时间 */
		}else if(search_type=='date'){
			if (t1[1].substring(0,10)==search_word){
				t1[5] = '<font color=red>'+t1[5]+'</font>';
			}
		}
	}
	/* 帖子超长截短 */
	if (cut>0&&t1[5].length>cut){
		//t1[5] = t1[5].substring(0,cut)+endfix+(endfix.length>0?'':'<em>')+'　　<a href="files/'+rootid+'p'+current_page+current_type+'.html" >更多请进……</a></em>';
		t1[5] = t1[5].substring(0,cut)+endfix+(endfix.length>0?'':'<em>')+'　　<a href="reply_view.php?id='+rootid+'&page='+current_page+'&type='+current_type+'&proid='+proid+'" >更多请进……</a></em>';
	}else{
		t1[5] = t1[5]+endfix;
	}
	/* 内容生成 */
	if (i==0){
		tmp+='<B>[主题]：</B>'+t1[5].replace(/\n/ig,'<br>\n').substring(2);
	}else{
		tmp+=t1[5].replace(/\n/ig,'<br>\n');
	}
	return tmp;
}
/* 直接显示图片 */
function showpic(pic)
{
		if (pic){
		temp='<img src="http://forum.younet.com/upload/'+t1[1].substring(0,10)+'/'+t1[12]+'" onload="javascript:DrawImage(this);" border=1>';
	}else{
		temp='';
		}
		return temp;
}
/* 操作按钮 */
function lb(t1,rootid,rly,flw,edit,flt,pic,mark){
	//tmp = '<div style="position:absolute;"><div style="position:relative;left:'+(t1[0]==rootid&&flt?'310':'270')+'px;top:-3px;">';
	tmp='<span class="ptl">'
	/* 回帖 */
	if (rly){
		//tmp+=(t1[0]==rootid?'<span class="ptl"><a href="http://forum.younet.com/files/'+rootid+'p'+current_page+current_type+'.html">回帖</a></span>':'   ');
		//tmp+='　　';
		//tmp+=(t1[0]==rootid?'<a href="http://forum.younet.com/files/'+rootid+'p'+current_page+current_type+'.html"">回帖</a>':'　　');
		tmp+=(t1[0]==rootid?'<a href="http://forum.younet.com/reply_view.php?id='+rootid+'&page='+current_page+'&type='+current_type+'&proid='+proid+'"">回帖</a>':'　　');
		tmp+='';
	}
	/* 图片 */
	/*if (pic){
		tmp+='<a href="http://forum.younet.com/upload/'+t1[1].substring(0,10)+'/'+t1[12]+'" style="color:red;" target=_blank>图片</a>';
		tmp+='　　';
	}*/
	/* 编辑 */
	tmp+=edit?'<a href="/edit2.php?id='+t1[0]+'&page='+current_page+'" >编辑</a>　':'';
	/* 回收 */
	tmp+=current_admin?'<input type="checkbox" name="rcy['+t1[0]+']" align="absmiddle" value="'+t1[0]+'">回收':'';
	/* 得奖 */
	if (flw&&t1[4]>0){
		tmp+='<i class="fl">';
		for (fi=0; fi<t1[4]; fi++){
			tmp+='<img src="'+current_base+'forum.younet.com/pics/flower1.gif" >\n';
		}
		tmp+='</i>';
	}
	if (mark==1){
			tmp+='<i class="fl" ><img src="'+current_base+'forum.younet.com/pics/ques.gif" alt="" align="absmiddle"> </i> \n';
	}else if(mark==2) {
			tmp+='<img src="'+current_base+'forum.younet.com/pics/smile.gif" alt="" align="absmiddle">\n';
	}
	tmp+='</span>';
	return tmp;
}

function lb2(t1,rootid,rly,flw,edit,flt,pic,mark){
	//tmp = '<div style="position:absolute;"><div style="position:relative;left:'+(t1[0]==rootid&&flt?'310':'270')+'px;top:-3px;">';
	tmp='<span class="ptl">'
	/* 回帖 */
	if (rly){
		//tmp+=(t1[0]==rootid?'<span class="ptl"><a href="http://forum.younet.com/files/'+rootid+'p'+current_page+current_type+'.html">回帖</a></span>':'   ');
		//tmp+='　　';
		//tmp+=(t1[0]==rootid?'<a href="http://forum.younet.com/files/'+rootid+'p'+current_page+current_type+'.html"">回帖</a>':'　　');
		tmp+=(t1[0]==rootid?'<a href="http://forum.younet.com/reply_view.php?id='+rootid+'&page='+current_page+'&type='+current_type+'&proid='+proid+'"">回帖</a>':'　　');
		tmp+='';
	}
	/* 图片 */
	/*if (pic){
		tmp+='<a href="http://forum.younet.com/upload/'+t1[1].substring(0,10)+'/'+t1[12]+'" style="color:red;" target=_blank>图片</a>';
		tmp+='　　';
	}*/
	/* 编辑 */
	tmp+=edit?'<a href="/edit2.php?id='+t1[0]+'&page='+current_page+'" >编辑</a>　':'';
	tmp+='<input type="checkbox" name="wg[]" value='+t1[0]+'>';
	/* 回收 */
	tmp+=current_admin?'<input type="checkbox" name="rcy['+t1[0]+']" align="absmiddle" value="'+t1[0]+'">回收':'';
	/* 得奖 */
	if (flw&&t1[4]>0){
		tmp+='<i class="fl">';
		for (fi=0; fi<t1[4]; fi++){
			tmp+='<img src="'+current_base+'forum.younet.com/pics/flower1.gif" >\n';
		}
		tmp+='</i>';
	}
	if (mark==1){
			tmp+='<img src="'+current_base+'forum.younet.com/pics/ques.gif" alt="" align="absmiddle">\n';
	}else if(mark==2) {
			tmp+='<img src="'+current_base+'forum.younet.com/pics/smile.gif" alt="" align="absmiddle">\n';
	}
	tmp+='</span>';
	return tmp;
}
/* 查看帖子 */
function lv(t){
	for (vi=0;vi<t.length ; vi++){
		t1 = t[vi].split('\n');
		if (vi==0){
			rootid = t1[0];
		}
		tmp = '';
		tmp+='<p>';
		tmp+='<span>'+lu(t1)+lt(t1)+'</span>'+lb2(t1,rootid,false,false,true,false,t1[12]!=0?true:false,t1[14])+'　'+' ';
		//tmp+='<span class="ptl"><input type="checkbox" name="wg[]" value='+t1[0]+'></span>';

		tmp+="</p>";
		tmp+='<p class="mt">'+lc(t1,vi,0,rootid)+showpic(t1[12]!=0?true:false)+'</p><hr />';
		//alert(tmp);
		//tmp+='<p>'+'<span>'+lu(t1)+lt(t1)+'</span>'+' '+lb(t1,rootid,true,true,false,true,t1[12]!=0?true:false,t1[14])+'</p>';//
		//tmp+='<p class="mt">'+lc(t1,1,content_cut,rootid)+showpic(t1[12]!=0?true:false)+'</p><hr />';
		document.write(tmp);
	}
}

/* 帖子列表 */
function ll(t) {
	if (t.length>0){
		document.write(' ');
	}
	for (li=0;li<t.length ; li++) {
		tmp = '';
		t1 = t[li].split('\n');
		if (li>0){
			//tmp+='<ul>';
			//tmp+='xxx';
			tmp+='<p class="ft">'+'<span>'+lu(t1)+lt(t1)+'</span>'+' '+lb(t1,rootid,true,true,false,true,t1[12]!=0?true:false,t1[14])+'</p>';//
			tmp+='<p class="ft_h">'+lc(t1,1,content_cut,rootid)+showpic(t1[12]!=0?true:false)+'</p>';
		}else{
			rootid = t1[0];
			//tmp+='<p class="mt">';
			tmp+='<p>'+'<span>'+lu(t1)+lt(t1)+'</span>'+' '+lb(t1,rootid,true,true,false,true,t1[12]!=0?true:false,t1[14])+'</p>';//
			tmp+='<p class="mt">'+lc(t1,1,content_cut,rootid)+showpic(t1[12]!=0?true:false)+'</p>';
		}

		document.write(tmp);
	}

}
/* 违规贴 */
function wg() {
	var chk = false;
	itm = document.wgt.elements;
	for(i=0;i<itm.length;i++){
		if(itm[i].name=='wg[]'&& itm[i].checked){
			return true;
			break;
		}
	}
	alert('请选择违规贴!');
	return false;
}

/* 发贴检查 */
var sub_state = false;
function sub_chk() {
	if (sub_state == true) {
		alert("您已经提交了请求……");
		return false;
	}else {
		with (document.post){
			if (content.value == '') {
				alert('请您填写帖子内容！');
				content.focus();
				return false;
			}else{
				submit_forum.disabled = true;
				sub_state = true;
				return true;
			}
		}
	}
}

/* 帖子编辑检查 */
function edit_chk(itm){
	if (sub_state == true) {
		alert("您已经提交了请求……");
		return false;
	}else if (itm.content.value==''){
		alert('请您填写帖子内容！');
		itm.content.focus();
		return false;
	}else{
		itm.submit_forum.disabled = true;
		sub_state = true;
		return true;
	}
}

/* 快捷键发贴 */
function key_down() {
	if (((window.event.altKey)&&(window.event.keyCode==83))||((window.event.ctrlKey)&&(window.event.keyCode==13))){
		with (document.post){
			if(content.value==''){
				content.focus();
			}else if (sub_state == true) {
				alert("您已经提交了请求……");
				return false;
			}else{
				sub_state = true;
				submit_forum.disabled = true;
				submit();
				return true;
			}
		}
	}
	if(event.keyCode==27) {
		event.keyCode=0;
		event.returnValue=false;
	}
}

/* 定位至发言框 */
function post(){
	with (document.post){
		submit_forum.focus();
		content.focus();
	}
}

/* 参数配置默认值 */
function conf_def() {
	document.conf.elements[2].checked = true;
	document.conf.elements[4].checked = true;
	document.conf.elements[10].checked = true;
}
function conf_chk() {
	return true;
}
