﻿var PicUrl='';

if (SysStyle==1)
{
	PicUrl='';
}
else{
	PicUrl=SystemFolder;
}

var TempStr=document.getElementById('xmlArticleList').selectSingleNode("//Content").text;
var TopicList=TempStr.split("{{}}");

function ShowList(StyleId){
	var TempStr,Tmp;

TempStr='<table width="100%" border="0" cellpadding="0" cellspacing="0">';
switch (StyleId)
{
//文本
case 0:
for (i=0;i<=RCount;i++){
Tmp=TopicList[i].split("|");
TempStr+='<tr><td height="25px" style="padding:0px 20px;" onmouseover=this.style.backgroundColor="eef6fe" onmouseout=this.style.backgroundColor="">';
TempStr+='<div style="float:left; line-height:20px;">&nbsp;<a href="'+Tmp[11]+'" rel="external" target="_blank">'+TitleAddColor(Tmp[2],Tmp[1])+'</a></div>';
TempStr+='<div style="float:right; line-height:20px;"><font color="#999999">';
TempStr+='　['+Tmp[3]+']';
TempStr+='</font></div></td></tr>';
}
break;
//标题+摘要
	case 1:
		for (i=0;i<=RCount;i++){
			Tmp=TopicList[i].split("|");

			TempStr+='<tr><td align="left" height="25px">'+CheckTitleTypes(Tmp[8],Tmp[10]);
			TempStr+='<a href="'+Tmp[11]+'" rel="external">'+TitleAddColor(Tmp[2],Tmp[1])+'</a></td>';
		    TempStr+='<td align="right">'+Tmp[3]+'</td>';
		    TempStr+='<td>浏览:'+Tmp[7]+'</td></tr>';
			TempStr+='<tr><td colspan="3">'+cleanHtml(Tmp[5])+'</td></tr>';
			TempStr+='<tr><td align="left" height="25px"><font color=#999999>最新评论:';
			if (Tmp[6]=="")
			{
				TempStr+='暂无评论';
			}
			else{
				TempStr+=Tmp[6];
			}
			TempStr+='</font></td>';
		    TempStr+='<td>评论:'+Tmp[4]+'</td></tr>';
		}
		break;
//纯图片
case 2:
var j=0;
for (i=0;i<=RCount;i++){
Tmp=TopicList[i].split("|");
if ((j % 3)==0)
{
TempStr+='';
}
TempStr+='<td align="center"><br><div style="width:200px; padding:4px; border:1px solid #7f9db9;"  onmouseover=this.style.backgroundColor="eef6fe" onmouseout=this.style.backgroundColor=""><a href="'+Tmp[11]+'" rel="external">';
if (Tmp[9]=="")
{
TempStr+='<img src="'+PicUrl+'images/public/no_picture.gif" alt="'+Tmp[2]+'" border="0">';
}
else{
TempStr+='<img src="'+Tmp[9]+'" alt="'+Tmp[2]+'" style="width:200px; height:130px;" border="0">';
}
TempStr+='<div style="width:200px;text-align:left; line-height:25px; background-color:#eef6fe;">';

var title1;
title1=Tmp[2];
if(title1.length<=8)
{
title1=Tmp[2].substring(0,8);
}
else
{
title1=Tmp[2].substring(0,8)+"..";
}
TempStr+='<a href="'+Tmp[11]+'" rel="external" title="'+Tmp[2]+'"><font color="red">点击进入>></font>'+TitleAddColor(title1,Tmp[1])+'</a></div></div></td>';
if (j==2)
{
TempStr+='</tr>';
j=0;
}
else{
j+=1;
}
}
break;
//图片+摘要
	case 3:
		for (i=0;i<=RCount;i++ )
		{
			Tmp=TopicList[i].split("|");

			TempStr+='<tr><td align="left" valign="top" width="120"><div style="width:120px; padding:4px; border:1px solid #7f9db9;"><a href="'+Tmp[11]+'" rel="external">';
			if (Tmp[9]=="")
			{
				TempStr+='<img src="'+PicUrl+'images/public/no_picture.gif" alt="'+Tmp[2]+'" border="0">';
			}
			else{
				TempStr+='<img src="'+Tmp[9]+'" style="width:120px;" alt="'+Tmp[2]+'" border="0">';
			}
			TempStr+='<br></div><br></td>';
			TempStr+='<td align="left" valign="top">';
			TempStr+=CheckTitleTypes(Tmp[8],Tmp[10]);
			TempStr+='<a href="'+Tmp[11]+'" rel="external">'+TitleAddColor(Tmp[2],Tmp[1])+'</a>';
			TempStr+=cleanHtml(Tmp[5]);
			TempStr+='<br><br>　<font color=#999999>'+Tmp[3]+'</font>';
		}
		break;
	}

	TempStr+='</table>';

	document.getElementById('CommentList').innerHTML=TempStr;

	if (document.location.href.indexOf("#") > 0)
	{
		document.location.href = document.location.href.substring(0,document.location.href.indexOf("#")) + "#";
	}
	else{
		document.location.href+="#";
	}
}

function CheckTitleTypes(vIsImg,vIsTop){
	if (vIsImg=="True")
	{
		return '<img src="'+PicUrl+'images/public/article_img.gif" alt="图片文章" border="0"/>&nbsp;';
	}
	else{
		if (vIsTop=="True")
		{
			return '<img src="'+PicUrl+'images/public/article_top.gif" alt="推荐文章" border="0"/>&nbsp;';
		}
		else{
			return '<img src="'+PicUrl+'images/public/article_normal.gif" alt="普通文章" border="0"/>&nbsp;';
		}
	}
}

function TitleAddColor(vTitle,vTColor){
	switch (vTColor)
	{
	case "1":
		return '<font color="#FF0000">'+vTitle+'</font>';
	case "2":
		return '<font color="#37a61c">'+vTitle+'</font>';
	case "3":
		return '<font color="#0066CC">'+vTitle+'</font>';
	default :
		return vTitle;
	}
}

function cleanHtml(ReContents)
{
	ReContents = ReContents.replace(/<p>&nbsp;<\/p>/gi,"")
	ReContents = ReContents.replace(/<p><\/p>/gi,"<br>")
	ReContents = ReContents.replace(/<p>/,"<br>")
	ReContents = ReContents.replace(/<\/p>/,"<br>")
	ReContents = ReContents.replace(/<li>/,"<br>")
	ReContents = ReContents.replace(/<lu>/,"<br>")
	ReContents = ReContents.replace(/(<(meta|iframe|frame|span|tbody|layer)[^>]*>|<\/(iframe|frame|meta|span|tbody|layer)>)/gi, "");
	ReContents = ReContents.replace(/<\\?\?xml[^>]*>/gi, "") ;
	ReContents = ReContents.replace(/o:/gi, "");
	ReContents = ReContents.replace(/&nbsp;/gi, " ");
	ReContents = ReContents.replace(/(<(style|strong)[^>]*>|<\/(style|strong)>)/gi, "");
	ReContents = ReContents.replace(/^\[ \t]*$/,"")
	ReContents = ReContents.replace(/(<(table|tbody|tr|td|th|)[^>]*>|<\/(table|tbody|tr|td|th|)>)/gi, "");
	ReContents = ReContents.replace(/(<(img)[^>]*>|<\/(img)>)/gi, "");
	ReContents = ReContents.replace(/(<(div|blockquote|fieldset|legend)[^>]*>|<\/(div|blockquote|fieldset|legend)>)/gi, "");
	ReContents = ReContents.replace(/(<(font|i|u|h[1-9]|s)[^>]*>|<\/(font|i|u|h[1-9]|s)>)/gi, "");
	ReContents = ReContents.replace(/(<script[^>]*>|<\/script>)/gi, "");

	RegExp = /<(\w[^>|\s]*)([^>]*)(on(finish|mouse|Exit|error|click|key|load|change|focus|blur))(.[^>]*)/gi;
	ReContents = ReContents.replace(RegExp, "<$1")

	RegExp = /<(\w[^>|\s]*)([^>]*)(&#|window\.|id|javascript:|js:|about:|file:|Document\.|vbs:|cookie| name| id)(.[^>]*)/gi;
	ReContents = ReContents.replace(RegExp, "<$1")
	
	return ReContents;
}

