var TUTBYExporter=function()
{
	this.aData=[];
	this.oTitleStyle={
		fontFamily: "Verdana, Arial,Helvetica, sans-serif",
		fontSize: 12,
		color: "navy",
		style: ''
	};
	this.oTitleStyle.style=this.Style(this.oTitleStyle);
	this.oCategoryStyle={
		visible: false,
		fontFamily: "Verdana, Arial,Helvetica, sans-serif",
		fontSize: 12,
		fontWeight: "normal",
		color: "navy",
		style: ''
	};
	this.oCategoryStyle.style=this.Style(this.oCategoryStyle);
	this.oDateStyle={
		visible: false,
		dateFormat: "dd.mm.yyyy",
		fontFamily: "Verdana, Arial,Helvetica, sans-serif",
		fontSize: 10,
		fontWeight: "normal",
		color: "red",
		style: ''
	};
	this.oDateStyle.style=this.Style(this.oDateStyle);
	this.targetBlank=false;
}
TUTBYExporter.prototype.AddItems=function (sCategoryName,sCargeoryLink,aItems)
{
	this.aData.push({
		name: sCategoryName,
		link: sCargeoryLink,
		items: aItems
	});
}
TUTBYExporter.prototype.SetTitleStyle=function (sFontFamily,sFontSize,sColor)
{
	this.oTitleStyle.fontFamily=sFontFamily;
	this.oTitleStyle.fontSize=Math.max(8,Math.min(23,parseInt(sFontSize)));
	this.oTitleStyle.color=sColor;
	this.oTitleStyle.style=this.Style(this.oTitleStyle);
}
TUTBYExporter.prototype.SetCategoryStyle=function (bShow,sFontFamily,sFontSize,sFontWeight,sColor)
{
	this.oCategoryStyle.visible=bShow;
	this.oCategoryStyle.fontFamily=sFontFamily;
	this.oCategoryStyle.fontSize=Math.max(8,Math.min(23,parseInt(sFontSize)));
	this.oCategoryStyle.fontWeight=sFontWeight;
	this.oCategoryStyle.color=sColor;
	this.oCategoryStyle.style=this.Style(this.oCategoryStyle);
}
TUTBYExporter.prototype.SetDateStyle=function (bShow,sDateFormat,sFontFamily,sFontSize,sFontWeight,sColor)
{
	this.oDateStyle.visible=bShow;
	this.oDateStyle.dateFormat=sDateFormat;
	this.oDateStyle.fontFamily=sFontFamily;
	this.oDateStyle.fontSize=Math.max(8,Math.min(23,parseInt(sFontSize)));
	this.oDateStyle.fontWeight=sFontWeight;
	this.oDateStyle.color=sColor;
	this.oDateStyle.style=this.Style(this.oDateStyle);
}
TUTBYExporter.prototype.SetTargetBlank=function ()
{
	this.targetBlank=true;
}
TUTBYExporter.prototype.Style=function(oStyle)
{
	var sStyle="";
	if(oStyle["fontFamily"])
		sStyle+="font-family: "+oStyle["fontFamily"]+";";
	if(oStyle["fontSize"])
		sStyle+="font-size: "+oStyle["fontSize"]+"px;";
	if(oStyle["fontWeight"])
		sStyle+="font-weight: "+oStyle["fontWeight"]+";";
	if(oStyle["color"])
		sStyle+="color: "+oStyle["color"]+";";
	return sStyle;
}
TUTBYExporter.prototype.ExportDate=function(xDate)
{
	var sDate="";
	if(this.oDateStyle.visible)
	{
		var oDate=new Date(xDate);
		var re=new RegExp(/^([0-9])$/);
		var sValue=this.oDateStyle.dateFormat
			.replace("yyyy",oDate.getFullYear())
			.replace("mm",(oDate.getMonth()+1).toString().replace(re,"0$1"))
			.replace("dd",oDate.getDate().toString().replace(re,"0$1"))
			.replace("h",oDate.getHours())
			.replace("m",oDate.getMinutes().toString().replace(re,"0$1"));
		sDate+='<span class="itemDate">'+sValue+'</span> ';
	}
	return sDate;
}
TUTBYExporter.prototype.ExportItem=function(iCategory,iItem)
{
	var sTarget=this.targetBlank?' target="_blank"':"";
	var sItem=
		'<div>'+this.ExportDate(this.aData[iCategory]["items"][iItem]["time"])+
		'<a href="'+this.aData[iCategory]["items"][iItem]["link"]+'"'+sTarget+'>'+this.aData[iCategory]["items"][iItem]["title"]+'</a>'+
		'</div>';
	return sItem;
}
TUTBYExporter.prototype.ExportCategory=function(iCategory)
{
	var sTarget=this.targetBlank?' target="_blank"':"";
	var sCategory="";
	if(this.aData[iCategory]["items"].length>0)
	{
		sCategory+='<div class="newsSlot">';
		if(this.oCategoryStyle.visible)
			sCategory+=
				'<div class="slotName">'+
				'<a href="'+this.aData[iCategory]["link"]+'"'+sTarget+'>'+this.aData[iCategory]["name"]+'</a>'+
				'</div>';
		for(var i=0;i<this.aData[iCategory]["items"].length;i++)
			sCategory+=this.ExportItem(iCategory,i);
		sCategory+='</div>';
	}
	return sCategory;
}
TUTBYExporter.prototype.ExportNews=function(bHideCopyright,doc)
{
	var sExport='<style type="text/css">'+"\n"+
'div.TUTBYExport div.newsSlot, div.TUTBYExport div.newsSlot a { '+this.oTitleStyle.style+' }'+"\n"+
'div.TUTBYExport div.slotName, div.TUTBYExport div.slotName a { '+this.oCategoryStyle.style+' }'+"\n"+
'div.TUTBYExport div.slotName{margin:4px 0px 2px 0px;}'+
'div.TUTBYExport a { text-decoration: none !important; }'+"\n"+
'div.TUTBYExport span.itemDate { '+this.oDateStyle.style+' }'+"\n"+
'</style>'+"\n"+
'<div class="TUTBYExport">';
	for(var i=0;i<this.aData.length;i++)
		sExport+=this.ExportCategory(i);
	if(!bHideCopyright)
		sExport+=
			'<div align="right" class="newsSlot"><br>Сервис предоставлен <a href="http://news.tut.by/" target="_blank">НОВОСТИ TUT.BY</a> &copy; 2000-'+(new Date().getFullYear()).toString()+'</div>';
	sExport+='</div>';
	if(doc) doc.write(sExport); else document.write(sExport);
}
TUTBY=new TUTBYExporter();

