function CalculateApr(Principal,Rate,ExtraCost,Months)
{
	
	var r=(Rate/1200);
	if(r!=0)
		{
		var MonthlyPayment=Math.round(((Principal+ExtraCost)*(r)*Math.pow((1+r),Months))/(Math.pow((1+r),Months)-1),2);
		}
		else
		{
		var MonthlyPayment=Math.round(((Principal+ExtraCost)/Months),2);
		}
		TotalPayments = Math.round(MonthlyPayment*Months,2);
        TotalInterest = Math.round(TotalPayments - Principal,2);	
		a=.01;
		difference=a;
		while(difference>.00000001)
		{
	 		oldA=a;
	 		tmpA=Math.pow((1+a),Months);
	 		a=(MonthlyPayment*(tmpA-1))/(Principal*tmpA);
	 		difference=oldA-a; 
	 		if(difference<0)
	  		{
	   			 difference=difference*(-1);
	  		}
	 	}
		
		var APR = Math.round((a*1200),4);
		return APR; 
}
function ShowApr()
{
	var Principal=parseInt(document.frm1.principal.value);
	var Rate=parseInt(document.frm1.rate.value);
	var ExtraCost=parseInt(document.frm1.cost.value);
	var Months=parseInt(document.frm1.months.value);
	var Apr=CalculateApr(Principal,Rate,ExtraCost,Months);
        if(isNaN(Apr))
        {

                var Result='<font color="#FA8080">Please enter number in the calculator</font>';
        }
        else
        {


         var Result='<b>Result Apr:</b>'+Apr+'%';
        }

	document.getElementById('apr').innerHTML = Result;
	
	
}
function RemoveValue()
{
  document.getElementById('apr').innerHTML ='';	
}
function ShowHelpForPointsCalc(divID, desc)
{
        DivObj = document.getElementById(divID);
        DivObj.style.display = 'inline';
        DivObj.style.position = 'absolute';
        DivObj.style.width = '170';
        DivObj.style.backgroundColor = 'lightyellow';
        DivObj.style.border = 'dashed 1px black';
        DivObj.style.padding = '10px';
        DivObj.innerHTML = '<div style="padding: 10px 10px 10px 10px;">' + desc + '</div>';
}
function HideHelpForPointsCalc(divID)
{
        DivObj = document.getElementById(divID);
        DivObj.style.display = 'none';
}
function FnShowInitialTableForAPRCalculator()
{
if(document.getElementById('APRCalculatorLink')=='http://www.debtconsolidationcare.com/')
{
var HtmlForm='<div align="center"><form name="frm1">';
HtmlForm += '<table width="175" border="0"';
HtmlForm += '<tr><td align="center">';
HtmlForm+='<table width="100%" cellspacing="2" cellpadding="0" border="0" style="border:1px solid #006666;"><tbody><tr bgcolor="#006666">';
HtmlForm+='<td align="center" colspan="3"> <font color="#ffffff"><b><font face="Verdana, Arial, Helvetica, sans-serif">APR Calculator<br />';
HtmlForm+='<tr><td class="pointscalctext"><div align="center"><b>Principal</b></div></td><td> <input type="text" size="15" name="principal" class="textbox" /></td><td><span onclick="javascript:ShowHelpForPointsCalc(\'pointhelp0\', \'Amount of money borrowed.\');" onmouseout="javascript:HideHelpForPointsCalc(\'pointhelp0\')" style="font-size: 11px; font-weight: bold; cursor: pointer; color: blue;">?</span><div style="display:none" id="pointhelp0"></div></td></tr>';
HtmlForm+='<tr><td class="pointscalctext"> <div align="center"><b>Additional Cost</b></div></td><td > <input type="text" size="15" name="cost" class="textbox" /></td><td><span onclick="javascript:ShowHelpForPointsCalc(\'pointhelp0\', \'Processing fee, bond fee etc.\');" onmouseout="javascript:HideHelpForPointsCalc(\'pointhelp0\')" style="font-size: 11px; font-weight: bold; cursor: pointer; color: blue;">?</span><div style="display:none" id="pointhelp0"></div></td></tr>';

HtmlForm+='<tr><td class="pointscalctext"> <div align="center"><b>Interest Rate</b></div></td><td ><input type="text" size="15" name="rate" class="textbox" /></td><td><span onclick="javascript:ShowHelpForPointsCalc(\'pointhelp0\', \'Percentage of interest paid annually on principal.\');" onmouseout="javascript:HideHelpForPointsCalc(\'pointhelp0\')" style="font-size: 11px; font-weight: bold; cursor: pointer; color: blue;">?</span><div style="display:none" id="pointhelp0"></div></td></tr>';

HtmlForm+='<tr><td class="pointscalctext"> <div align="center"><b>No of Months</b></div></td><td > <input type="text" size="15" name="months" class="textbox"/></td><td><span onclick="javascript:ShowHelpForPointsCalc(\'pointhelp0\', \'No. of months over which you will repay this loan.\');" onmouseout="javascript:HideHelpForPointsCalc(\'pointhelp0\')" style="font-size: 11px; font-weight: bold; cursor: pointer; color: blue;">?</span><div style="display:none" id="pointhelp0"></div></td></tr>';

HtmlForm+='<tr><td colspan="3"> <div align="center"><input type="button" value="Calculate" name="calculate" class="pointscalcbutton" onclick="javascript:ShowApr();" /><input type="reset" name="Reset" value="Reset" class="pointscalcbutton" onClick="javascript:RemoveValue();"></div></td></tr>';

HtmlForm+='<tr><td colspan="3" ><div id="apr" align="center"></div></td></tr>';

HtmlForm+='</tbody></table></td></tr></table>';

HtmlForm+='</form></div>';

        document.getElementById('APRCalculator').innerHTML = HtmlForm;
}
else
{
        document.getElementById('APRCalculatorMain').innerHTML = 'To enable this Calculator, please paste the full code as described at <a href="http://www.debtconsolidationcare.com/syndicate/">Debt Consolidation Care</a>';
}
}
function FnInitialiseCSSAndShowInitialTableForAPRCalculator()
{
    FnShowInitialTableForAPRCalculator();
}
document.write('<style type="text/css">.pointscalctableformat{ border-color:#666666;}.pointscalctablecellformat{ border:0;}.pointscalctableheading{ color:#000066; font-weight:bold; font-family: Verdana, Tahoma, Arial, Trebuchet MS, Sans-Serif, Georgia, Courier, Times New Roman, Serif;font-size: 14px;}.pointscalcbutton { border: 1px solid white; background-color: #006666; color: white; font-size: 10px; font-weight: bold;}.pointscalctext{font-family: Verdana, Tahoma, Arial, Trebuchet MS, Sans-Serif, Georgia, Courier, Times New Roman, Serif;font-size: 10px;}.pointscalcsyndicate{ text-decoration:none; color:#999; font-family:sans-serif; font-size:11px;}</style>');
FnInitialiseCSSAndShowInitialTableForAPRCalculator()