// Forex Routines

function printmonthtotals()
{
	var Profits = 0;
	var PrintTotal;
	var TotalProfits = 0;
	var dollar_value = 0;

	document.write( "<tr><td colspan='6' align='center'>Monthly Totals ");
	document.write("</td><td width='15%' align='right'>");
	document.write("</td></tr>");

	
	//Euro Totals

	dollar_value = foreur.pointvalue;
	TotalProfits = foreur.cumulative * dollar_value;

	PrintTotal = TotalProfits.toFixed(2);
	document.write( "<tr><td colspan='6' align='right'>Euro ");
	document.write("</td><td width='15%' align='right'>$");
	document.write(PrintTotal);
	document.write("</td></tr>");
	Profits += TotalProfits;

	//Yen Totals

	dollar_value = foryen.pointvalue;
	TotalProfits = foryen.cumulative * dollar_value;

	PrintTotal = TotalProfits.toFixed(2);
	document.write( "<tr><td colspan='6' align='right'>Yen ");
	document.write("</td><td width='15%' align='right'>$");
	document.write(PrintTotal);
	document.write("</td></tr>");
	Profits += TotalProfits;

	//Pound Totals

	dollar_value = forpd.pointvalue;
	TotalProfits = forpd.cumulative * dollar_value;

	PrintTotal = TotalProfits.toFixed(2);
	document.write( "<tr><td colspan='6' align='right'>Pound ");
	document.write("</td><td width='15%' align='right'>$");
	document.write(PrintTotal);
	document.write("</td></tr>");
	Profits += TotalProfits;

	//Swiss Totals

	dollar_value = forsf.pointvalue;
	TotalProfits = forsf.cumulative * dollar_value;

	PrintTotal = TotalProfits.toFixed(2);
	document.write( "<tr><td colspan='6' align='right'>Swiss ");
	document.write("</td><td width='15%' align='right'>$");
	document.write(PrintTotal);
	document.write("</td></tr>");
	Profits += TotalProfits;

	PrintTotal = Profits.toFixed(2);
	document.write( "<tr><td colspan='6' align='right'>Cumulative Totals for the month ");
	document.write("</td><td width='15%' align='right'>$");
	document.write(PrintTotal);
	document.write("</td></tr>");
	return Profits;

}



function printcurrentmarket(which)
{
var buffer = "";
var direction = "";
var potential = "";
var Profit = 0;
if (which.direction) 
  {direction = "Bought"; potential = "Sell"} 
else 
  {direction = "Sold"; potential = "Buy"};
Profit = DoCalc(which, which.stopprice);
buffer += "<tr><td width='24%'>"
buffer += which.name;
buffer += "</td><td width ='38%'>";
buffer += direction;
buffer += " @ "
buffer += which.startprice;
buffer += "</td><td width='38%'>&nbsp;</td></tr>"
buffer += "<tr><td width='24%'>&nbsp;"
buffer += "</td><td width='38%'>"
buffer += potential;
buffer += " Stop @ ";
buffer += which.stopprice;
buffer += "</td><td width='38%' align='right'>$ ";
var PrintProfit = Profit.toFixed(2);
buffer += PrintProfit;
buffer += "</td></tr>";
document.write(buffer);
return Profit;
}

function printcurrentforex(which)
{

	var Profits      = 0;
	var buffer = "";

document.write("<table border='0' cellpadding='0' cellspacing='8' width='95%'>");
document.write("<tr><th width='24%'>Market</th><th width='38%'>Price</th><th width='38%'>Profit</th></tr>");
for( i = 0; which[i] != null; i++)
	{
	Profits += printcurrentmarket(which[i]);
	}
buffer += "<tr><td width='24%'>&nbsp;</td><td width='38%' align='right'>Total</td><td width='38%' align='right'>$ ";
var PrintProfit = Profits.toFixed(2);
buffer += PrintProfit;
buffer += "</td></tr></table>";
document.write(buffer);
}


function printforexpositions(which)
{
var tradedata = "";
var direction = "";
var Profit = 0;
var profittrades = 0;
var CloseProfit = 0;
var month = month_name(which.month);
if (which.direction) {direction = "Bought"} else {direction = "Sold"};
Profit = DoCalc( which, which.stopprice );
//Profit -= 0; //CommissionRate; // open trades. There is only one
tradedata += "<tr><td width='20%'>";
tradedata += month;
tradedata += " ";
tradedata += which.name;
tradedata += "</td><td width='10%'>";
tradedata += direction;
tradedata += "</td><td width='10%' align='right'>";
tradedata += which.startprice;
tradedata += "</td><td width='10%' align='right'>";
tradedata += which.stopprice;
tradedata += "</td><td width='10%' align='right'>";
tradedata += which.reverse;
tradedata += "</td><td width='10%' align='right'> ";
tradedata += which.cumulative;   //pointvalue;
tradedata += "</td><td width='15%' align='right'>$ ";
ProfitTotal -= 0;  //CommissionRate;
var printprofit = ProfitTotal.toFixed(2);
tradedata += printprofit;
tradedata += "</td><td width='15%' align='right'>$ ";
DoCumulative(which);
var positioncomm = which.numtrades * CommissionRate;
GrandTotal -= 0; //positioncomm;
printprofit = GrandTotal.toFixed(2);
tradedata += printprofit;
tradedata += "</td></tr>";
document.write(tradedata);
return Profit;
}



function print_forex_profile(which)
{
	var TotalProfits = 0;
	var dollar_value = 0;
	var Profits      = 0;
	var ProfileTrades = 0;
	var PrintTotal;
	var Name = which.name;

	
	for( i = 0; which[i] != null; i++)
		{
			dollar_value = which[i].pointvalue;
			TotalProfits += which[i].cumulative * dollar_value;
			ProfileTrades = which[i].numtrades * CommissionRate;
//			TotalProfits -= ProfileTrades;
			Profits += printforexpositions(which[i]);
		}
	PrintTotal = Profits.toFixed(2);
	document.write( "<tr><td colspan='6' align='right'>Totals ");
	document.write("</td><td width='15%' align='right'> ");
	document.write(PrintTotal);
	document.write("</td><td width='15%' align='right'>$ ");
	PrintTotal = TotalProfits.toFixed(2);
	document.write(PrintTotal);
	document.write("</td></tr>");
	document.write( "<tr><td colspan='7' align='right'>Total for Both ");
	document.write("</td><td width='15%' align='right'>$ ");
	TotalProfits += Profits;
	PrintTotal = TotalProfits.toFixed(2);
	document.write(PrintTotal);
	document.write("</td></tr>");

}





function fprinttrade(which, buy, startprice, tradeprice)
{
var tradedata = "";
var direction = "";
var Profit = 0;
var tempc = 0;
var x, y;
var sellprice = 0;
var buyprice  = 0;
var ProfitPoints = 0;


which.numtrades++;
var dollar_value = which.pointvalue;
var price = tradeprice;


if (buy) {direction = "Bought"} else {direction = "Sold"};


tradedata += "<tr><td width='20%'>";

tradedata += which.name;
tradedata += "</td><td width='10%'>";
tradedata += direction;
tradedata += "</td><td width='15%'>";
if (buy) //we're long
	{
		x = startprice;
		y = price;
	}
	else
	{
		x = price;
		y = startprice;
	}
buyprice = x;
sellprice = y;
Profit = sellprice - buyprice;
ProfitPoints = Profit;
Profit = Profit * dollar_value;

tradedata += startprice;
tradedata += "</td><td width='15%'>";
tradedata += tradeprice;
tradedata += "</td><td width='15%'><p align='right'>";
tradedata += which.numtrades;
tradedata += " / ";
tradedata += ProfitPoints;
tempc = ProfitPoints + which.cumulative;
tradedata += " / ";
tradedata += tempc;
tradedata += "</td><td width='10%'><p align='right'>$";
tradedata += which.pointvalue;
tradedata += "</td><td width='15%'><p align='right'>$";
//Profit = ProfitTotal - 0; //CommissionRate;
tradedata += Profit.toFixed(2);
tradedata += "</td></tr>";
document.write(tradedata);
which.cumulative += ProfitPoints;

return Profit;
}

function forex_market_profits(which)
{
	var TotalProfits = 0;
	var dollar_value = 0;


	for ( i = 0; which[i] != null; i++)
	{
		dollar_value =  which[i].pointvalue;
		TotalProfits += which[i].cumulative * dollar_value;
	}

	return TotalProfits;
}



function forexteaserprofile( which )
{
	var ProfileTotal = 0;
	var display = "";
	var PipTotal = 0;

	for (i=0; which[i] != null; i++)
	{	
		var temp = 0;
		document.write("<tr>");
		document.write("<td width='40%'>");
		document.write(which[i].name);
		document.write("</td><td width='20%' align='right'>");
		document.write(which[i].cumulative);
		document.write("</td><td width='30%' align='right'>$ ");
		var dollar_value = which[i].pointvalue;
		temp = which[i].cumulative * dollar_value; //forex_market_profits(which[i]);
		display = temp.toFixed(0);
		document.write(display);
		document.write("</td></tr>");
		ProfileTotal += temp;
		PipTotal += which[i].cumulative;
	}
	display = ProfileTotal.toFixed(0);
	document.write("<tr><td width='40%'>");
	document.write("</td><td width='20%'>");
	document.write("======");
	document.write("</td><td width='30%' align='right'>");
	document.write("=====");
	document.write("</td></tr>");
	document.write("<tr>");
	document.write("<td width='40%'>");
	document.write("Total");
	document.write("</td><td width='20%' align='right'>");
	document.write(PipTotal);
	document.write("</td><td width='30%' align='right'>$ ");
	document.write(display);
	document.write("</td></tr>");
}

function forexprofitbox( which )
{
	var ProfileTotal = 0;
	var display = "";
	var PipTotal = 0;

	document.write("<table border='1' cellspacing='1' width='179' bordercolor='#800000' cellpadding='3' bgcolor='#FFFF00' style='font-size: 10'>");
	document.write("<tr><td width='169'>");
	document.write("<p align='left'><strong>Hypothetical</strong> results for this month</p>");
	document.write("<div align='center'><center>");
	document.write("<table border='0' cellpadding='0' cellspacing='0' width='90%' style='font-size: 10'>");
	document.write("<tr>");
	document.write("<th width='40%' align='left'>Market</th>");
	document.write("<th width='20%' align='right'>Pips</th>");
	document.write("<th width='30%' align='right'>Gain</th></tr>");

	for (i=0; which[i] != null; i++)
	{
		document.write("<tr>");
		document.write("<td width='40%' align='left'>");
		document.write(which[i].name);
		document.write("</td><td width='20%' align='right'>");
		var lot_size = which[i].cumulative * 5;
		document.write(lot_size);  //(which[i].cumulative);
		document.write("</td><td width='30%' align='right'>$ ");
		var dollar_value = which[i].pointvalue;
		var temp = lot_size * dollar_value; //which[i].cumulative * dollar_value;
		display = temp.toFixed(0);
		document.write(display);
		document.write("</td></tr>");
		ProfileTotal += temp;
		PipTotal += lot_size; //which[i].cumulative;
	}
	display = ProfileTotal.toFixed(0);
	document.write("<tr><td width='40%'>");
	document.write("</td><td width='20%'>");
	document.write("======");
	document.write("</td><td width='30%' align='right'>");
	document.write("=====");
	document.write("</td></tr>");
	document.write("<tr>");
	document.write("<td width='40%'>");
	document.write("Total");
	document.write("</td><td width='20%' align='right'>");
	document.write(PipTotal);
	document.write("</td><td width='30%' align='right'>$ ");
	document.write(display);
	document.write("</td></tr>");
	
	document.write("</table>");
	document.write("</center></div>");
	document.write("<p align='center'>Past results do not guarantee<br> future profits.</td>");
	document.write("</tr></table>");
}

