var news_limit		= 10;
var news_target_url 	= 'http://www.pro-portfel.pl/news/newsForm.aspx?id=';

function financialnews_parseXml(xml)
{
	var json	= $.xml2json(xml);
	var news_i	= 0;
	var html	= '';
	
	html 	+=	'<h2 class="content_box_head">Wiadomości finansowe</h2>' 
		+	'<ul class="menu events_menu">';
	
	$.each(json.news,function() {
		news_i++;
		if (news_i > news_limit) {
			return;
		}
		
		html 	+=	'<li class="menu_pos">'
			+	'<span class="arr">&raquo;</span>'
			+		'<a href="' + news_target_url + this.id + '" class="menu_link">' + this.title  + '</a>'
			+		'<span class="date">' + this.data.substr(0, 10)  + '</span>'
			+		'<div class="separator"></div>'
			+	'</li>';
	});
	
	html 	+=	'</ul>';
	
	document.getElementById("financialnews_content").innerHTML = html;

/*		
		period							= this.period;
		currencies_rates[id][period]				= new Object();
		currencies_rates[id][period]['change_percentage']	= myRound(parseFloat(this.change_percentage.replace(',','.')),2);
		currencies_rates[id][period]['change_value']		= this.change_value;
		
		if (currencies_i > currencies_limit_urls) {
			return;
		}
		
		currencies_urls[id][period]				= new Object();
		
		var factor_min	= 1;
		var factor_max	= 1;
		
		var width	= 270;
		var height	= 190;
		
		var precision	= 2;
		
		var min 	= 0;
		var min 	= 0;
		var max 	= 0;
		var top 	= 0;
		var bottom 	= 0;
		var range	= 0;
		var floor	= 0;
		var bottom	= 0;
		var sum 	= 0;
		var avg		= 0;
		var count	= 0;
		
		var chl		= '';
		var chd		= '';
		var chd_min	= '';
		var chd_max	= '';
		var chd_avg	= '';
		var url		= '';
		
		$.each(this.rate, function() {
			value	= parseFloat(this.value.replace(',','.'));
			date	= this.date;
			sum	+= value;
			count++;
			
			if (count == 1) {
				max = value;
				min = value;
			} else {
				if (value > max) max = value;
				if (value < min) min = value;
			}
			
			chd = value + "," + chd;
			if (period == "1m" || period == "5d") {
				chl = date.substr(8,2) + '.' + date.substr(5,2) + '|' + chl;
			} else {
				chl = date.substr(5,2) + '.' + date.substr(2,2) + 'r.|' + chl;
			}
		});
		
		chl = chl.substr(0, chl.length-1);
		
		top	= myRound(factor_max * max, precision);
		bottom	= myRound(factor_min * min, precision);
		
		avg	= myRound(sum / count, 4);
		floor	= Math.floor((factor_min * min) * Math.pow(10, precision)) / Math.pow(10, precision);
		ceil	= Math.ceil((factor_max * max) * Math.pow(10, precision)) / Math.pow(10, precision);
		range	= myRound(ceil - floor, precision) * Math.pow(10,precision);
		
		while (range > 9) {
			precision--;
			floor	= Math.floor((factor_min * min) * Math.pow(10, precision)) / Math.pow(10, precision);
			ceil	= Math.ceil((factor_max * max) * Math.pow(10, precision)) / Math.pow(10, precision);
			range	= myRound(ceil - floor, precision) * Math.pow(10,precision);
		}
		if (range < 2) {
			precision++;
			floor	= Math.floor((factor_min * min) * Math.pow(10, precision)) / Math.pow(10, precision);
			ceil	= Math.ceil((factor_max * max) * Math.pow(10, precision)) / Math.pow(10, precision);
			range	= myRound(ceil - floor, precision) * Math.pow(10,precision);
		}
		
		for (i = 0; i < count; i++) {
			chd_avg = avg + "," + chd_avg;
			chd_min = min + "," + chd_min;
			chd_max = max + "," + chd_max;
		}		
		
		chd =	chd.substr(0, chd.length - 1) + '|' +
			chd_avg.substr(0, chd_avg.length - 1) + '|' +
			chd_min.substr(0, chd_min.length - 1) + '|' +
			chd_max.substr(0, chd_max.length - 1);

				
		url = 	"http://chart.apis.google.com/chart"
			+ "?chs=" + width + "x" + height	// wymiary
			+ "&cht=lc"				// typ wykresu
			+ "&chd=t:" + chd			// dane
			+ "&chds=" + floor + "," + ceil + "," + floor + "," + ceil + "," + floor + "," + ceil + "," + floor + "," + ceil	// skala
			+ "&chl=" + chl				// etykiety
			+ "&chxt=y,r" 				// osie
			//+ "&chxl=1:|" + myRound(min, precision + 1) + "|" + myRound(avg, precision + 1) + "|" + myRound(max, precision + 1)	// labele na osi r
			+ "&chxl=1:|min|avg|max"	// labele na osi r
			+ "&chxp=1," + ((min - floor) * (100 / (ceil - floor))) + "," + ((avg - floor) * (100 / (ceil - floor))) + "," + ((max - floor) * (100 / (ceil - floor))) // pozycje na osi r
			+ "&chxr=0," + floor + "," + ceil + "," + (1 / Math.pow(10, precision))	// zasięg osi
			+ "&chf=c,lg,90,EFB168,0,FAFAF6,0.6"	// wypełnienie - gradient
			+ "&chg=" + myRound(100 / (count - 1),0 ) + "," + (100 / ((ceil - floor) * Math.pow(10, precision))) + ",1,0"	// siatka
			+ "&chls=3,0,0|2,3,3|2,3,3|2,3,3"	// style linii
			+ "&chm=b,FFE2BF,0,1,0|o,F8981D,0,-1,7,0"	// wypełnienia
			+ "&chco=F8981D,F8981D,EF2C2C,0CCF4B"	// kolory linii
			;//+ "&chma=10,10,10,10";	// marginesy
			
		currencies_urls[id][period] = url;
	*/	
//	});
	//currencies_load_rates();
	
}

function financialnews_load_data(url) {
	if (!url) {
		url = "http://localhost/praca/portal/html/pl/index/ajaxproxy/url/financialnews";
	}
	$.ajax({
		type: "GET",
		url: url,
		dataType: "xml",
		beforeSend : function() {
			document.getElementById("financialnews_content").innerHTML = "<br />&nbsp;&nbsp;&nbsp;Ładowanie danych...";
		},
		success: financialnews_parseXml
	});
}
/*
				<h2 class="content_box_head">Wiadomości financowe</h2>
				<ul class="menu events_menu">
					<? foreach ($this->debates as $debate) : ?>
					<li class="menu_pos">
						<span class="arr">&raquo;</span>
						<a href="<?= $debate['url'] ?>" class="menu_link"><?= $this->MySecureString($debate['title']) ?></a>
						<span class="date"><?= $this->MySecureString($debate['date']) ?></span>
						<div class="separator"></div>
					</li>
					<? endforeach; ?>
				</ul>
*/

