﻿/*-------------------------------------------*\
            BLOC MA LISTE D'ACTIONS
\*-------------------------------------------*/
function printWatchListPF(userid)	{

		watchlist_html = '';

		// ---------------------------------
		// appel du web service pour voir le détail des cotes
		// ---------------------------------
		$.ajax({
			type: "GET",
			url: '/cgi-bin/ws/getPfSymbList.cgi?userid=' + userid,
			dataType: "json",
			async: false,
			success: function(output)	{

				
				x=0;
				watchlist_html='';

				for (var pf in output)	{

					pf_name=pf;
					x++;

					bloc_html_start='<div id="bloc_2_'+x+'" class="maliste"><div class="boiteTitre"><a href="#">'+pf_name+'</a></div><div class="disptable">';
					bloc_html_end='<div id="btebasActions"><a href="/portfolio/" class="modactions">Modify my portfolio</a><a href="/portfolio/" class="voiractions">See my portefolio</a></div></div></div>';
				
					watchlist_html+= bloc_html_start+'<table><tr valign="top"><th class="hsymb">Symbol</th><th class="hcours">Last trade ($)</th><th>Variation</th><th>% Variation</th></tr>';


					for (var i in output[pf])	{

						data=output[pf];

						watchlist_html += '<tr valign="top">';

						var SymbolDisplay='';

						// Symbole
						var Symbol=data[i].Symbol;

						if (Symbol.indexOf(";") > 0)
						{
						  // c'est une action
						  var SymbolA = data[i].Symbol.split(';');
						  var marche  = SymbolA[0];
						  var symbole = SymbolA[1];

						  SymbolDisplay=symbole;

						  watchlist_html += '<td class="tsymb"><a href="/cotes/index.html?marketsymbol='+encodeURIComponent(data[i].Symbol)+'">';
						} else {
						  SymbolDisplay=Symbol;
						  watchlist_html += '<td class="tsymb"><a href="/fonds/details.html?codefonds='+encodeURIComponent(data[i].Symbol)+'">';
						}
						watchlist_html += SymbolDisplay;
						watchlist_html += '</a></td>';

						// Cours ($)
						if (data[i].Last == "")	{
							watchlist_html += '<td>';
							watchlist_html += 'N/D'
						}
						else	{
							var Last = new Number(data[i].Last);
							watchlist_html += '<td class="tcours">';
							watchlist_html += Last.toFixed(3);
						}
						watchlist_html += '</td>';

						// Variation ($)
						if (data[i].DollarChange == "")	{
							watchlist_html += '<td>';
							watchlist_html += 'N/D'
						}
						else	{
							var DollarChange = new Number(data[i].DollarChange);
							watchlist_html += '<td class="tvar'+(DollarChange < 0 ? ' down' : '')+'">';
							watchlist_html += (DollarChange >= 0 ? '+' : '');
							watchlist_html += DollarChange.toFixed(3);
						}
						watchlist_html += '</td>';

						// Variation (%)
						if (data[i].PercentChange == "")	{
							watchlist_html += '<td>';
							watchlist_html += 'N/D'
						}
						else	{
							var PercentChange = new Number(data[i].PercentChange);
							watchlist_html += '<td class="tpvar'+(PercentChange < 0 ? ' down' : '')+'">';
							watchlist_html += (PercentChange >= 0 ? '+' : '');
							watchlist_html += PercentChange.toFixed(3) + '%';
						}
						watchlist_html += '</td>';
						watchlist_html += '</tr>';
					}
					watchlist_html+="</table>"+bloc_html_end;
				}
			}
		});

	
	$("#coteajour2").html(watchlist_html);

}

function loginFromWL() {
  $("#bte_login").css("top","1040px");
  $("#bte_login").css("left","624px");
  $("#bte_login").css("background","#edebe2");
  $("#bte_login").show();
  $("#porteLogin").show();
  $("#porteLogin2").hide();
  document.getElementById('logincmd').value="no_pf_load";  
} 

