var portal = new Object();

//封装门户数据单条记录的对象
portal.Entry = function()
{
	this.unid;				//文章的unid编号
	this.username;			//用户名称
	this.title;				//文章标题
	this.photopath;			//如果是图片类型的文章，获取图片的地址
	this.publishdate;		//发布的日期
	this.unitname;			//单位的名称
	this.toplevel;			//文章至定标记
	this.docwordsequence;	//文章的文件编号
	this.content;			//标签的内容
	this.url;				//用于存放一些链接相关信息
}
//生成 一行显示一则新闻标题这种最基本的样式   style td 的样式
portal.Entry.prototype.outEntry = function(objTable,style,oConfig)
{
	if(objTable!=null&&objTable!=undefined&&objTable!="")
	{
		//生成表格的tr
		var objTr = htmlCreator.creatorTr(objTable,"","");
		objTr.style.cursor="hand";
		//生成每一个td
		var colconfig = oConfig.colconfig;
		if(colconfig==undefined||colconfig.name==undefined||colconfig.name.length==0)
		{
			colconfig.name = new Array("title");
		}

		for(var i=0;i<colconfig.name.length;i++)
		{
			var objTd = htmlCreator.creatorTd(objTr,"",style);
			if(colconfig.colwidth!=undefined&&colconfig.colwidth[i]!=undefined&&colconfig.colwidth[i]!="")
			{
				objTd.width=colconfig.colwidth[i]
			}
			objTd.align = "left";
			if(oConfig.linehight!=undefined)
			{
				objTd.height = oConfig.linehight;
			}
			var arTitle = " ";
			//创建一行内容前的图片
			var oImg = "";
			if(oConfig.titleImg!=undefined&&oConfig.titleImg!=""&&i==0)
			{
				oImg = "<img src=\""+ oConfig.titleImg +"\" width=\"10\" height=\"10\" /> ";
			}
			else
			{
				if(i==0)
					oImg = "·";
			}
			
			if(this[colconfig.name[i]]!=undefined&&this[colconfig.name[i]]!="")
			{
				arTitle = this[colconfig.name[i]];
				if(colconfig.name[i]=="title")
				{
					objTr.title = this[colconfig.name[i]];
				}
			}
			if(oConfig!=undefined&&oConfig.maxcount!=undefined
					&&arTitle.length>oConfig.maxcount&&colconfig.name[i]=="title")
			{
			    var reg = new RegExp("&[^>]+;");
				arTitle = arTitle.replace(reg,"");
				var reg1 = new RegExp("#[^>]+;");
				arTitle = arTitle.replace(reg1,"");
				arTitle = arTitle.substring(0,oConfig.maxcount);//&amp;#8226;
				arTitle = arTitle + "...";
			}
			//给标题增加链接
			if(arTitle!=undefined&&arTitle!=""&&colconfig.name[i]=="title")
			{
				var pp = "";
				if(oConfig.previewPage!=undefined)
					pp = oConfig.previewPage;
				else
					pp = config.previewPage;
				
				if( pp=="#" )
				{
				   arTitle = arTitle;
				}
				else
				{
				 var datet="";
				  if( this.publishdate!=undefined )
					datet=this.publishdate.split(" ")[0];
				 
				  arTitle = "<a href=\""+config.serverPath + pp + "?date="+datet+"&unid="+this.unid+"&cateunid="+oConfig.cateunid+"\" target=\"_blank\">"+arTitle+"</a>";
				}
				//for(var newimg = 0;newimg<colconfig.name.length;newimg++)
				//{
					//处理时间类型
					//if(colconfig.name[newimg].indexOf("publishdate")>-1)
					if( this["publishdate"]!=undefined )
					{
					    var arTime = this["publishdate"];
						if( arTime!=undefined && arTime.length>10 )
						{
							arTime = arTime.substring(0,10);	
							var s;
							var d = new Date();                           // 创建 Date 对象。
							var reg = new RegExp("[\u4e00-\u9fa5]");
							s = d.toLocaleString().substring(5,9).replace(reg,"-");
							if( arTime.indexOf(s)>-1)
							{
							   arTitle += "&nbsp;&nbsp;&nbsp;<img src=\""+ config.imagePath + config.newImagePath +"\" /> ";
							}
						}
						//break;
					}
				//}
			}
			//处理时间类型
			if(colconfig.name[i]=="publishdate")
			{
				if(arTitle!=undefined&&arTitle.length>10)
					arTitle=arTitle.substring(0,10);	
			}

			//处理时间类型
			if(colconfig.name[i]=="publishdate_year")
			{
			   	var arTime = this["publishdate"];
				if( arTime!=undefined&&arTime.length>10)
					arTitle=arTime.substring(5,10);	
			}
			//处理部门
			if(colconfig.name[i]=="unitname")
			{
				if(arTitle!=undefined&&arTitle!=""&&arTitle!=" ")
					arTitle="["+arTitle+"]"	
			}
			//设置文字样式
			if(colconfig.colfontstyle!=undefined&&colconfig.colfontstyle[i]!=undefined
													&&colconfig.colfontstyle[i]!=null
													&&colconfig.colfontstyle[i]!="")
			{
				arTitle = "<span class=\""+colconfig.colfontstyle[i]+"\">"+arTitle+"</span>";
			}
			objTd.innerHTML = oImg + arTitle;
		}	
		/*
		var objEntry = this;
		objEntry.config = oConfig;
		if(this.unid!=undefined&&this.unid!="")
		{
			objTr.onclick = function()
			{
				entryOnclik.call(objEntry)
			}
		}*/
		return objTr;
	}
}
//生成滚动图片样式
portal.Entry.prototype.outScrollEntry = function(oTr1,oTr2,style,oConfig)
{
	//生成方图片的td
	var oTd1 = htmlCreator.creatorTd(oTr1,"","");
	oTd1.align="center";
	var oImg = htmlCreator.creatorHtmlObj("img",oTd1,"","");
	oImg.width="142";
	oImg.height="102";
	if(this.photopath!=undefined)
	{
		oImg.src = config.cmsPath+this.photopath;
	}
	var oTd2 = htmlCreator.creatorTd(oTr2,"","");
	oTd2.align="center";
	var arTitle = " ";
	if(this.title!=undefined)
	{
		arTitle = this.title;
	}
	if(oConfig!=undefined&&oConfig.maxcount!=undefined
					&&arTitle.length>oConfig.maxcount)
	{
		arTitle = arTitle.substring(0,oConfig.maxcount);
		arTitle = arTitle + "...";
	}
	oTd2.innerText = arTitle;
	var objEntry = this;
	objEntry.config  = oConfig;
	if(this.unid!=undefined&&this.unid!="")
	{
		oTd1.onclick = function()
		{
			entryOnclik.call(objEntry)
		}
		oTd2.onclick = function()
		{
			entryOnclik.call(objEntry)
		}
	}
}

//封装门户数据对象
portal.Entrys = function()
{
	this.entryList; //存放每一条记录的数组;
	this.config;
}
//生成一行显示一则新闻标题的表格样式  style--表格的样式，tdStyle -- td的样式
portal.Entrys.prototype.outEntrys = function(style,tdStyle)
{
	//if(this.entryList!=null&&this.entryList!=undefined&&this.entryList.length>0)
	//{
		var objTable = htmlCreator.creatorHtmlObj("table","","",style);
		objTable.cellSpacing=0;
		if(this.config!=undefined)
		{
			if(this.config.linepad!=undefined)
				objTable.cellPadding = this.config.linepad;
		}
		var count=0;
		if(this.entryList!=undefined&&this.entryList.length>0)
		{
			if(this.entryList.length>=this.config.rowcount)
			{
				count = this.config.rowcount;
			}
			else
			{
				count = this.entryList.length;
			}
		}
		for(var i=0;i<count;i++)
		{
			if(this.entryList[i]!=undefined)
			{
				var objtr = this.entryList[i].outEntry(objTable,tdStyle,this.config);
			}
		}
		for(var n=0;n<(this.config.rowcount-count);n++)
		{
			var entry = new portal.Entry();
			var objtr = entry.outEntry(objTable,tdStyle,this.config); 
		}
		return objTable;
	//}
}
//style--表格的样式，tdStyle -- td的样式
portal.Entrys.prototype.outScrollEntrys = function(style,tdStyle)
{
	var oDiv = htmlCreator.createDiv("",this.config.areamain,"c_scrollpic");
	
	var oTable = htmlCreator.creatorHtmlObj("table",oDiv,"",style);
	oTable.align="center";
	oTable.cellPadding=0;
	oTable.cellSpacing=0;
	var oTr=htmlCreator.creatorTr(oTable,"","");
	var oTd= htmlCreator.creatorTd(oTr,this.config.area,"");
	var oTd2= htmlCreator.creatorTd(oTr,this.config.areacopy,"");
	var oTable2 = htmlCreator.creatorHtmlObj("table",oTd,"",style);
	oTable2.align="center";
	oTable2.cellPadding=0;
	oTable2.cellSpacing=5;
	var oTr1 = htmlCreator.creatorTr(oTable2,"","");
	var oTr2 = htmlCreator.creatorTr(oTable2,"","");
	oTr1.style.cursor="hand";
	oTr2.style.cursor="hand";
	if(this.entryList!=undefined&&this.entryList.length>0)
	{
		for(var i=0;i<this.entryList.length;i++)
		{
			if(this.entryList[i]!=undefined)
			{
				var objtr = this.entryList[i].outScrollEntry(oTr1,oTr2,tdStyle,this.config);
			}
		}
	}
	return oDiv;
}
//生成子站统计的文章数目
portal.Entrys.prototype.outSiteTotal = function()
{
	var tag = this.config.frameid;
	if(this.entryList!=undefined&&this.entryList.length>0)
	{
		for(var i=0;i<this.entryList.length;i++)
		{
			var oEntry = this.entryList[i];
			oEntry.config = this.config;
			var id = tag+i;
			var pObj = document.getElementById(id);
			var content = oEntry.unitname;
			//var content = oEntry.unitname + " <span class=\"red_12\">"+oEntry.content+" </span>条"; //屏蔽子站统计
			if(pObj!=undefined&&pObj!=null)
			{
				pObj.innerHTML = content;    
				pObj.style.cursor = "hand";
				pObj.entry = oEntry;
				pObj.onclick  = function()
				{
					totalEntryOnclick.call(this.entry);
				}
			}
			var sid = tag+"n_"+i;
			var oSpan = document.getElementById(sid);
			var unit = "[<a href=\""+ config.serverPathOnlyKs + oEntry.url +"\" target=\"_blank\">"+ oEntry.unitname +"</a>]";
			
			if(oSpan!=undefined&&oSpan!=null)
			{
				oSpan.innerHTML = unit;
				oSpan.style.cursor = "hand";
				oSpan.tmpUnitName = oEntry.unitname;
			}
		}
	}
}
//生成子站的头一篇文章
portal.Entrys.prototype.outSiteArticle = function()
{
	var tag = this.config.frameid;     //取装载内容的框架的id
	if(this.entryList!=undefined&&this.entryList.length>0)
	{
		for(var i=0;i<this.entryList.length;i++)   //遍历所有的entry
		{
			var oEntry = this.entryList[i];
			oEntry.config = this.config;			//传入配置信息
			//组合id
			var id = tag+"t_"+i;		    //放置子站文章标题的区域id		
			var uid = tag+"n_"+i;			//放置子站标识的区域id	
			var timeId = tag+"time_"+i;		//放置文章发布时间的区域id
			//获取文章的标题并处理
			var content = oEntry.title; 
			var createTime = oEntry.publishdate;
			if(createTime!=undefined&&createTime!=null&&createTime!="")
			{
				createTime = createTime.substring(0,10);
			}                 
			//内容截断
			if(this.config!=undefined&&this.config.maxcount!=undefined
					&&content.length>this.config.maxcount)
			{
				content = content.substring(0,this.config.maxcount);
				content = content + "...";
			}
			if(content!=undefined&&content!="")//生成标题的超链接
			{
				
				content = "<a href=\""+config.serverPath + config.previewPage + "?unid="+oEntry.unid+"&cateunid="+this.config.cateunid+"\" target=\"_blank\">"+content+"</a>";
			}
			var ou = document.getElementById(uid);
			if(ou.tmpUnitName==oEntry.unitname)
			{
				var pObj = document.getElementById(id);//设置标题
				if(pObj!=undefined&&pObj!=null)
				{
					pObj.innerHTML = content;
					pObj.title = oEntry.title;
					pObj.style.cursor = "hand";
					/*pObj.onclick = function()
					{
						entryOnclik.call(oEntry);
					}*/
				}
				var pTimeObj = document.getElementById(timeId);//设置创建时间
				if(pTimeObj!=undefined&&pTimeObj!=null)
				{
					pTimeObj.innerHTML = createTime;
					//pObj.style.cursor = "hand";
					/*pObj.onclick = function()
					{
						entryOnclik.call(oEntry);
					}*/
				}
			}
		}
	}
}
portal.Entrys.prototype.outPicMovie = function()
{
	var pics="";
	var links="";
	var texts="";
	if(this.entryList!=undefined&&this.entryList.length>0)
	{
		var count=0;
		if(this.config.rowcount<this.entryList.length)
			count = this.config.rowcount;
		else
			count = this.entryList.length
		for(var i=0;i<count;i++)
		{
			var oEntry = this.entryList[i];
			oEntry.config = this.config;
						
			var arTitle = oEntry.title;
			var imgPath = config.cmsPath + oEntry.photopath;
			var arLink = config.serverPath + config.previewPage + "?unid="+oEntry.unid+"&cateunid="+this.config.cateunid
			if(this.config!=undefined&&this.config.maxcount!=undefined
					&&arTitle.length>this.config.maxcount)
			{
				arTitle = arTitle.substring(0,this.config.maxcount);
				arTitle = arTitle + "...";
			}
			if(i!=0)
			{
				arTitle = "|"+arTitle;
				imgPath = "|"+imgPath;
				arLink  = "|"+arLink;
			}
			texts = texts + arTitle;
			pics = pics + imgPath;
			links = links + arLink;
		}
		var pObj = document.getElementById(this.config.frameid);
		if(pObj!=undefined&&pObj!=null)
		{
			oScroll.outPicMovie(pObj,pics,links,texts);  
			//picmove_content(pics,links,texts);
		}
	}
	
}
//begin zes 生成用户待办事项
portal.Entrys.prototype.outToDoThings = function() 
{
   	var tag = this.config.frameid;
   	var path = config.oaPath;
   	var pObj = document.getElementById(tag);
   	var content = "";
	if(this.entryList!=undefined&&this.entryList.length>0)
	{
		for(var i=0;i<this.entryList.length;i++)
		{
			var oEntry = this.entryList[i];
			if(oEntry.title!="协同办公平台"&&oEntry.title!="项目管理"&&oEntry.title!="未读邮件")  //待修改
			{
			    var arTitle = oEntry.title;
				if(arTitle!=undefined&&arTitle!="")
				{
				    if( oEntry.url.indexOf("oaapp")>-1)
				    {
				       arTitle = "<a href=\""+path +oEntry.url+"\" target=\"_blank\">"+arTitle+"</a>";          //给标题增加链接
				    }
				    else
				    {
				       arTitle = "<a href=\""+ config.pmPath +oEntry.url+"\" target=\"_blank\">"+arTitle+"</a>";          //给标题增加链接
				    }
					
				}
				content += arTitle + "(" + oEntry.content + ")"+"&nbsp;&nbsp;";
			}
			if(oEntry.title!="协同办公平台"&&oEntry.title!="项目管理"&&oEntry.title=="未读邮件")  //2007-11-29 新增加
			{
			    var arTitle = oEntry.title;
				if(arTitle!=undefined&&arTitle!="")
				{
					arTitle = "<a href=\""+oEntry.url+"\" target=\"_blank\">"+arTitle+"</a>";          //给标题增加链接
				}
				content += arTitle + "(" + oEntry.content + ")"+"&nbsp;&nbsp;";
			}
		}				
		if(pObj!=undefined&&pObj!=null)
		{
			pObj.innerHTML = content;
		}
	}
}
//end zes

//把服务器端传过来的xml对象生成entrys对象
function getEntrysFromServer(el)
{
	var entrys = new portal.Entrys();
	if(el!=null&&el!=undefined)
	{
		var xmldoc = el;
		var entryObjs = el.getElementsByTagName("entry");
		if(entryObjs!=null&&entryObjs!=undefined&&entryObjs.length>0)
		{
			entrys.entryList = new Array();
			for(var i=0;i<entryObjs.length;i++)
			{
				var entry = new portal.Entry();
				if(entryObjs[i].getAttribute("unid")!=undefined)
					entry.unid = entryObjs[i].getAttribute("unid");
					
				if(entryObjs[i].getAttribute("username")!=undefined)
					entry.username = entryObjs[i].getAttribute("username");
					
				if(entryObjs[i].getAttribute("title")!=undefined)
					entry.title = entryObjs[i].getAttribute("title");
				
				if(entryObjs[i].getAttribute("photopath")!=undefined)
					entry.photopath = entryObjs[i].getAttribute("photopath");
					
				if(entryObjs[i].getAttribute("publishdate")!=undefined)
					entry.publishdate = entryObjs[i].getAttribute("publishdate");
				
				if(entryObjs[i].getAttribute("unitname")!=undefined)
					entry.unitname = entryObjs[i].getAttribute("unitname");
					
				if(entryObjs[i].getAttribute("toplevel")!=undefined)
					entry.toplevel = entryObjs[i].getAttribute("toplevel");
				
				if(entryObjs[i].getAttribute("docwordsequence")!=undefined)
					entry.docwordsequence = entryObjs[i].getAttribute("docwordsequence");
					
				if(entryObjs[i].text!=undefined)
					entry.content = entryObjs[i].text;
				
				if(entryObjs[i].getAttribute("url")!=undefined)
					entry.url = entryObjs[i].getAttribute("url");
				
				entrys.entryList[i] = entry;
			}
			
		}		
	}
	return entrys;
}

//每一个新闻条目的单击事件
function entryOnclik()
{
	var url = config.serverPath + config.previewPage + "?unid="+this.unid+"&cateunid="+this.config.cateunid;
	window.open(url);
}

function totalEntryOnclick()
{
	var url = config.serverPathOnlyKs + this.url;
	window.open(url);
}