// JavaScript Document

nextfield = "Cash"; // name of first box on page
netscape = "";
ver = navigator.appVersion; len = ver.length;
for(iln = 0; iln < len; iln++) if (ver.charAt(iln) == "(") break;
netscape = (ver.charAt(iln+1).toUpperCase() != "C");

function keyDown(DnEvents) { // handles keypress
// determines whether Netscape or Internet Explorer
k = (netscape) ? DnEvents.which : window.event.keyCode;
if (k == 13) { // enter key pressed
if (nextfield == 'done') return true; // submit, we finished all fields
else { // we're not done yet, send focus to next box
eval('document.FinancialRatiosForm.' + nextfield + '.focus()');
return false;
      }
   }
}
document.onkeydown = keyDown; // work together to analyze keystrokes
if (netscape) document.captureEvents(Event.KEYDOWN|Event.KEYUP);


function SelectFieldOnFocus(thisfield) { 
	eval('document.FinancialRatiosForm.' + thisfield + '.select()');
	return false;
}


function calculateFR(){

form = document.FinancialRatiosForm;

var content = "";

var wCash = (form.Cash.value != '') ? eval(form.Cash.value) : 0;
var wMarkSec = (form.MarketableSecurities.value != '') ? eval(form.MarketableSecurities.value) : 0;
var wAR = (form.AccountsReceivable.value != '') ? eval(form.AccountsReceivable.value) : 0;
var wInventories = (form.Inventories.value != '') ? eval(form.Inventories.value) : 0;
var wPrepaidExpenses = (form.PrepaidExpenses.value != '') ? eval(form.PrepaidExpenses.value) : 0;
var wCurrentAssets = (form.CurrentAssets.value != '') ? eval(form.CurrentAssets.value) : 0;
var wFixedAssets = (form.FixedAssets.value != '') ? eval(form.FixedAssets.value) : 0;
var wTotalAssets = (form.TotalAssets.value != '') ? eval(form.TotalAssets.value) : 0;


var wCurrLiab = (form.CurrentLiabilities.value != '') ? eval(form.CurrentLiabilities.value) : 0;
var wLTLiab = (form.LongTermLiabilities.value != '') ? eval(form.LongTermLiabilities.value) : 0;
var wTotalLiab = (form.TotalLiabilities.value != '') ? eval(form.TotalLiabilities.value) : 0;
var wCapital = (form.Capital.value != '') ? eval(form.Capital.value) : 0;
var wRE = (form.RetainedEarnings.value != '') ? eval(form.RetainedEarnings.value) : 0;
var wNetIncome = (form.NetIncome.value != '') ? eval(form.NetIncome.value) : 0;
var wTotalEquity = (form.TotalEquity.value != '') ? eval(form.TotalEquity.value) : 0;
var wTotalLiabEquity = (form.TotalLiabilitiesEquity.value != '') ? eval(form.TotalLiabilitiesEquity.value) : 0;


var wSales = (form.Sales.value != '') ? eval(form.Sales.value) : 0;
var wCOGS = (form.COGS.value != '') ? eval(form.COGS.value) : 0;
var wGrossProfit = (form.GrossProfit.value != '') ? eval(form.GrossProfit.value) : 0;
var wOperatingExp = (form.OperatingExpenses.value != '') ? eval(form.OperatingExpenses.value) : 0;
var OperatingIncome = (form.OperatingIncome.value != '') ? eval(form.OperatingIncome.value) : 0;
var wInterestExp = (form.InterestExpenses.value != '') ? eval(form.InterestExpenses.value) : 0;
var wIncomeTaxes = (form.IncomeTaxes.value != '') ? eval(form.IncomeTaxes.value) : 0;
var wNetIncomeIS = (form.NetIncomeIS.value != '') ? eval(form.NetIncomeIS.value) : 0;
var wNoEmployees = (form.NumberOfEmployees.value != '') ? eval(form.NumberOfEmployees.value) : 0;

	
	content = "<strong><u> Financial Ratios </u></strong>";
	content = content + "<br /><br />";

// Liquidity Ratios
	
	content = content + "<strong> Liquidity Ratios </strong>";
	content = content + "<br />";

wWorkingCapitalF = wCurrentAssets-wCurrLiab;

	content = content + "Working Capital: ";
	content = content + "$ " + formatNumber(wWorkingCapitalF,2,',','.','','','-','');
	content = content + "<br />";

wQuickRatioF = (wCash+wMarkSec+wAR)/wCurrLiab;

	content = content + "Quick Ratio: ";
	content = content + formatNumber(wQuickRatioF,2,',','.','','','-','');
	content = content + "<br />";

wAcidTestRatioF = (wCash+wMarkSec)/wCurrLiab;

	content = content + "Acid Test Ratio: ";
	content = content + formatNumber(wAcidTestRatioF,2,',','.','','','-','');
	content = content + "<br />";

wCashRatioF = wCash/wCurrLiab;

	content = content + "Cash Ratio: ";
	content = content + formatNumber(wCashRatioF,2,',','.','','','-','');
	content = content + "<br />";

wCurrentRatioF = wCurrentAssets/wCurrLiab;

	content = content + "Current Ratio: ";
	content = content + formatNumber(wCurrentRatioF,2,',','.','','','-','');
	content = content + "<br />";

// Profitability Ratios
	
	content = content + "<br /><strong> Profitability Ratios </strong>";
	content = content + "<br />";

wGPMarginF = wGrossProfit*100/wSales;

	content = content + "Gross Profit Margin: ";
	content = content + formatNumber(wGPMarginF,2,',','.','','','-','') + " %";
	content = content + "<br />";

wOperatingMarginF = OperatingIncome*100/wSales;

	content = content + "Operating Margin: ";
	content = content + formatNumber(wOperatingMarginF,2,',','.','','','-','') + " %";
	content = content + "<br />";

wNPMarginF = wNetIncomeIS*100/wSales;

	content = content + "Net Profit Margin: ";
	content = content + formatNumber(wNPMarginF,2,',','.','','','-','') + " %";
	content = content + "<br />";

wReturnOnAssetsF = wNetIncome*100/wTotalAssets;

	content = content + "Return on Assets: ";
	content = content + formatNumber(wReturnOnAssetsF,2,',','.','','','-','') + " %";
	content = content + "<br />";

wReturnOnWorkingCapF = wNetIncome*100/(wCurrentAssets-wCurrLiab);

	content = content + "Return on Working Capital: ";
	content = content + formatNumber(wReturnOnWorkingCapF,2,',','.','','','-','') + " %";
	content = content + "<br />";

wReturnOnEquityF = wNetIncome*100/wTotalEquity;

	content = content + "Return on Equity: ";
	content = content + formatNumber(wReturnOnEquityF,2,',','.','','','-','') + " %";
	content = content + "<br />";

wReturnOnInvCapitalF = wNetIncome*100/wCapital;

	content = content + "Return on Invested Capital: ";
	content = content + formatNumber(wReturnOnInvCapitalF,2,',','.','','','-','') + " %";
	content = content + "<br />";

wReturnOnInvF = wNetIncome*100/(wLTLiab+wTotalEquity);

	content = content + "Return on Investment Ratio: ";
	content = content + formatNumber(wReturnOnInvF,2,',','.','','','-','') + " %";
	content = content + "<br />";

// Leverage Ratios
	
	content = content + "<br /><strong> Leverage Ratios </strong>";
	content = content + "<br />";

wDebtToAssetsF = wTotalLiab/wTotalAssets;

	content = content + "Debt to Assets (Debt Ratio): ";
	content = content + formatNumber(wDebtToAssetsF,2,',','.','','','-','');
	content = content + "<br />";

wDebtToEquityF = wTotalLiab/wTotalEquity;

	content = content + "Debt to Equity (Financial Leverage Ratio): ";
	content = content + formatNumber(wDebtToEquityF,2,',','.','','','-','');
	content = content + "<br />";

wCapitalizationRatioF = wLTLiab/(wLTLiab+wTotalEquity);

	content = content + "Capitalization Ratio: ";
	content = content + formatNumber(wCapitalizationRatioF,2,',','.','','','-','');
	content = content + "<br />";

wInterestCovRF = (wNetIncomeIS + wInterestExp)/wInterestExp;

	content = content + "Interest coverage ratio (Times interest earned): ";
	content = content + formatNumber(wInterestCovRF,2,',','.','','','-','');
	content = content + "<br />";

wLTLToWorkingCapF = wLTLiab/(wCurrentAssets-wCurrLiab);

	content = content + "Long-term debt to Working Capital: ";
	content = content + formatNumber(wLTLToWorkingCapF,2,',','.','','','-','');
	content = content + "<br />";

// Efficiency Ratios
	
	content = content + "<br /><strong> Efficiency Ratios </strong>";
	content = content + "<br />";

wSalesToEmployeesF = wSales/wNoEmployees;

	content = content + "Sales per Employee: ";
	content = content + "$ " + formatNumber(wSalesToEmployeesF,2,',','.','','','-','');
	content = content + "<br />";

wCashTurnoverF = wSales/wCash;

	content = content + "Cash Turnover Ratio: ";
	content = content + formatNumber(wCashTurnoverF,2,',','.','','','-','');
	content = content + "<br />";

wSalesToWorkingCapF = wSales/(wCurrentAssets-wCurrLiab);

	content = content + "Sales to Working Capital: ";
	content = content + formatNumber(wSalesToWorkingCapF,2,',','.','','','-','');
	content = content + "<br />";

wSalesToFixedAssetsF = wSales/wFixedAssets;

	content = content + "Sales to Fixed Assets: ";
	content = content + formatNumber(wSalesToFixedAssetsF,2,',','.','','','-','');
	content = content + "<br />";

wSalesToTotalAssetsF = wSales/wTotalAssets;

	content = content + "Sales to Total Assets: ";
	content = content + formatNumber(wSalesToTotalAssetsF,2,',','.','','','-','');
	content = content + "<br />";

// Other Ratios
	
	content = content + "<br /><strong> Other Ratios </strong>";
	content = content + "<br />";

wCurrentLiabToTLF = wCurrLiab/wTotalLiab;

	content = content + "Current Liabilities to Total Liabilities: ";
	content = content + formatNumber(wCurrentLiabToTLF,2,',','.','','','-','');
	content = content + "<br />";

wCurrentLiabToCAF = wCurrLiab/wCurrentAssets;

	content = content + "Current Liabilities to Current Assets: ";
	content = content + formatNumber(wCurrentLiabToCAF,2,',','.','','','-','');
	content = content + "<br />";

wLTLToCLF = wLTLiab/wCurrLiab;

	content = content + "Long-term Debt to Current Liabilities: ";
	content = content + formatNumber(wLTLToCLF,2,',','.','','','-','');
	content = content + "<br />";

wDebtToIncomeF = wTotalLiab/wNetIncome;

	content = content + "Debt to Income Ratio: ";
	content = content + formatNumber(wDebtToIncomeF,2,',','.','','','-','');
	content = content + "<br />";

wCashToCurrentLiabF = wCash/wCurrLiab;

	content = content + "Cash to Current Liabilities: ";
	content = content + formatNumber(wCashToCurrentLiabF,2,',','.','','','-','');


	content = content + "<br /><br />" + "source: www.ccdconsultants.com";
	
	contentfinal = content + "<br /><br />" + "Copyright &copy; 2009 - 2010  C. C. D. Consultants Inc. All rights reserved.";
	
	writeNewPage(contentfinal);


}



function writeNewPage(content) {
 top.pageRef=window.open('','detailspage',
  'width=750,height=500'
   +',menubar=0'
   +',toolbar=1'
   +',status=0'
   +',scrollbars=1'
   +',resizable=1')
 top.pageRef.document.writeln(
  '<html><head><title>Financial Ratios</title></head>'
   +'<body bgcolor="white" style="line-height: 125%">'
   +content
   +'</body></html>'
 )
 top.pageRef.document.close()
}





// number formatting function
// copyright Stephen Chapman 24th March 2006, 22nd August 2008
// permission to use this function is granted provided
// that this copyright notice is retained intact
// num=number; dec=nr of decimals; thou=thousand separator; pnt=decimal separator; curr=currency; n1,n2=the symbols to place around the number when the value is negative.

function formatNumber(num,dec,thou,pnt,curr1,curr2,n1,n2) {
	var x = Math.round(num * Math.pow(10,dec));
	if (x >= 0) n1=n2='';
	var y = (''+Math.abs(x)).split('');
	var z = y.length - dec; 
	
	if (z<0) z--; 
	for(var i = z; i < 0; i++) y.unshift('0'); 
	if (z<0) z = 1; 
	y.splice(z, 0, pnt); 
	if(y[0] == pnt) y.unshift('0'); 
	while (z > 3) {z-=3; y.splice(z,0,thou);}
	var r = curr1+n1+y.join('')+n2+curr2;return r;}



function calculateFRTA(form){

var wCA = (form.CurrentAssets.value != '') ? eval(form.CurrentAssets.value) : 0;
var wFA = (form.FixedAssets.value != '') ? eval(form.FixedAssets.value) : 0;

form.TotalAssets.value = Math.round((wCA + wFA)*100)/100 ; 

}

function calculateFRTL(form){

var wCL = (form.CurrentLiabilities.value != '') ? eval(form.CurrentLiabilities.value) : 0;
var wLTL = (form.LongTermLiabilities.value != '') ? eval(form.LongTermLiabilities.value) : 0;

var wTE = (form.TotalEquity.value != '') ? eval(form.TotalEquity.value) : 0;

form.TotalLiabilities.value = Math.round((wCL + wLTL)*100)/100 ; 

form.TotalLiabilitiesEquity.value = Math.round((wCL + wLTL + wTE)*100)/100 ; 

}

function calculateFRTE(form){

var wCapital = (form.Capital.value != '') ? eval(form.Capital.value) : 0;
var wRE = (form.RetainedEarnings.value != '') ? eval(form.RetainedEarnings.value) : 0;
var wNI = (form.NetIncome.value != '') ? eval(form.NetIncome.value) : 0;

var wTL = (form.TotalLiabilities.value != '') ? eval(form.TotalLiabilities.value) : 0;

form.TotalEquity.value = Math.round((wCapital + wRE + wNI)*100)/100 ; 

form.TotalLiabilitiesEquity.value = Math.round((wCapital + wRE + wNI + wTL)*100)/100 ; 

}

function calculateFRTLE(form){

var wTL = (form.TotalLiabilities.value != '') ? eval(form.TotalLiabilities.value) : 0;
var wTE = (form.TotalEquity.value != '') ? eval(form.TotalEquity.value) : 0;

form.TotalLiabilitiesEquity.value = Math.round((wTL + wTE)*100)/100 ; 

}

function calculateFRGP(form){

var wSales = (form.Sales.value != '') ? eval(form.Sales.value) : 0;
var wCOGS = (form.COGS.value != '') ? eval(form.COGS.value) : 0;

var wOE = (form.OperatingExpenses.value != '') ? eval(form.OperatingExpenses.value) : 0;

var wIT = (form.IncomeTaxes.value != '') ? eval(form.IncomeTaxes.value) : 0;

form.GrossProfit.value = Math.round((wSales - wCOGS)*100)/100 ; 

form.OperatingIncome.value = Math.round((wSales - wCOGS - wOE)*100)/100 ; 

form.NetIncomeIS.value = Math.round((wSales - wCOGS - wOE - wIT)*100)/100 ; 

}

function calculateFROI(form){

var wGP = (form.GrossProfit.value != '') ? eval(form.GrossProfit.value) : 0;
var wOE = (form.OperatingExpenses.value != '') ? eval(form.OperatingExpenses.value) : 0;

var wIT = (form.IncomeTaxes.value != '') ? eval(form.IncomeTaxes.value) : 0;

form.OperatingIncome.value = Math.round((wGP - wOE)*100)/100 ; 

form.NetIncomeIS.value = Math.round((wGP - wOE - wIT)*100)/100 ; 

}

function calculateFRNI(form){

var wOI = (form.OperatingIncome.value != '') ? eval(form.OperatingIncome.value) : 0;
var wIT = (form.IncomeTaxes.value != '') ? eval(form.IncomeTaxes.value) : 0;

form.NetIncomeIS.value = Math.round((wOI - wIT)*100)/100 ; 

}




