function CalculateDIR(Principal,Rate,Installment)
{
        var flag = 1;
        var TotalInterest = Months = Year = Month = 0;
        var Result ='<div align=center><table width="175" border="0" cellpadding="3" cellspacing="3" style="border:1px solid #006666;"><tbody><tr><td colspan="4"  height="20" bgcolor="#006666"><center><b><font color="#ffffff">Payment Report<br> (Interest Rate = <b>'+Rate+'%</b> and Installment = <b>$'+Installment+'</b>)</font><hr></font></b></center></td></tr><tr bgcolor="#eeeeee"><td><b>Months</td><td><b>Interest Paid</td><td><b>Principal Paid</td><td><b>Rest Principal </td></tr>';
        while(Principal>0)
        {
                MonthlyInterest = (Principal * (Rate / (100 * 12)));
                TotalInterest = TotalInterest + MonthlyInterest;
                if(MonthlyInterest>Installment)
                {
                        Result +='<tr><td colspan="4" align="center"><b>You will never be able to repay your loan with current interest rate and installment</b><input type="button" value="Back" onClick="RemoveValue();"></td></tr>';
                        flag = 0;
                        break;
                }
                LastPrincipal = Principal;
                RestAfterInterest = Installment - MonthlyInterest;
                Principal = Principal - RestAfterInterest;
                Months++;
                RestAfterInterest = RestAfterInterest;
                Principal = Principal;
                if(MonthlyInterest+LastPrincipal<=Installment)
                {
                        RestAfterInterest="<font color=#BA0B2D>"+Math.round(LastPrincipal)+"</font>";
                        Principal = "<font color=#ff00ff>Paid</font>";
                }

                RoundedMonthlyInterest = Math.round(MonthlyInterest,2);
                RoundedPrincipal = Math.round(Principal,2);
                if(isNaN(RoundedPrincipal))
                {
                        Result +='<tr><td>'+Months+'</td><td>'+RoundedMonthlyInterest+'</td><td>'+RestAfterInterest+'</td><td>'+Principal+'</td></tr>';
                }
                else
                {
                        Result +='<tr><td>'+Months+'</td><td>'+RoundedMonthlyInterest+'</td><td>'+Math.round(RestAfterInterest)+'</td><td>'+RoundedPrincipal+'</td></tr>';
                }
        }
        if(flag == 1)
        {
                Year =parseInt(Months / 12);
                Month = parseInt(Months % 12);
                Result +='<tr><td align=left colspan=4><hr><b>Total Interest Paid <font color="#BA0B2D"><b>  $'+Math.round(TotalInterest,2)+'</b></font> in <font color="#BA0B2D"><b>'+Year+'</b>  </font>Years and <font color="#BA0B2D"><b>'+Month+'</b> </font> Months</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" value="Back" onClick="RemoveValue();"></td></tr></tbody></table></div>';
        }
                return Result;
}
function formatCurrency(num)
{
        num = num.toString().replace(/\$|\,/g,'');
        if(isNaN(num))
        num = "0";
        sign = (num == (num = Math.abs(num)));
        num = Math.floor(num*100+0.50000000001);
        cents = num%100;
        num = Math.floor(num/100).toString();
        if(cents<10)
        cents = "0" + cents;
        for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
        num = num.substring(0,num.length-(4*i+3))+','+
        num.substring(num.length-(4*i+3));
        return (((sign)?'':'-') + '$' + num + '.' + cents);
}
function FnGetFinancialStatus(APRVAL)
{
			if(APRVAL>49000)
	 		{
				message = '<font color="#FF0000">Get professional help to aggressively reduce debt.</font>';

			}
			else if(APRVAL>42000 && APRVAL<=49000)
			{
				message = '<font color="FA8080">Financial difficulties are probably imminent unless you take immediate action.</font>';

			}
			else if(APRVAL>36000 && APRVAL<=42000)
			{
				message = '<font color="#00CC00">Not bad, but start paring debt now before you get in real trouble.</font>';

			}
			else if(APRVAL>0 && APRVAL<=36000)
			{
				message = '<font color="#009900">This is a healthy debt load to carry for most people.</font>';
				
			}
			
			return message;
			
			
}
function ShowDIR()
{
	var principalAmount=parseInt(document.frm1.principalAmount.value);
	var interestRate=parseInt(document.frm1.interestRate.value);
	var monthlyPayment=parseInt(document.frm1.monthlyPayment.value);

        var totalamountowed = 0;

        if((principalAmount <= 0 || isNaN(principalAmount)))
        {
                var Result='<font color="#FA8080">Please enter valid number in the calculator</font>';
                document.getElementById('DIR').innerHTML = Result;
                document.frm1.principalAmount.focus();
        }
        else if((interestRate <= 0 || isNaN(interestRate)))
        {
                var Result='<font color="#FA8080">Please enter valid number in the calculator</font>';
                document.getElementById('DIR').innerHTML = Result;
                document.frm1.interestRate.focus();
        }
        else if((monthlyPayment <= 0 || isNaN(monthlyPayment)))
        {
                var Result='<font color="#FA8080">Please enter valid number in the calculator</font>';
                document.getElementById('DIR').innerHTML = Result;
                document.frm1.monthlyPayment.focus();
        }
        else if(monthlyPayment >= principalAmount)
        {
                var Result='<font color="#FA8080">Monthly payment amount is equal or more then principal amount.</font>';
                document.getElementById('DIR').innerHTML = Result;
                document.frm1.monthlyPayment.focus();
        }
        else if(interestRate > 100)
        {
                var Result='<font color="#FA8080">Interest rate is invalid.</font>';
                document.getElementById('DIR').innerHTML = Result;
                document.frm1.interestRate.focus();
        }
        else
        {
                var DIR=CalculateDIR(principalAmount,interestRate,monthlyPayment);
                document.getElementById('inputForm').style.display="none";
                document.getElementById('OutputForm').innerHTML = DIR;
        }

}
function RemoveValue()
{
  document.getElementById('OutputForm').innerHTML ='';
  document.getElementById('inputForm').style.display='';
  document.getElementById('DIR').innerHTML='';
}
function FnShowInitialTableForCalculator()
{
if(document.getElementById('CreditCardPaymentCalculatorLink')=='http://www.debtconsolidationcare.com/')
{
var HtmlForm='<div align="center"><form name="frm1">';
HtmlForm += '<table width="175" border="0"';
HtmlForm += '<tr><td align="center">';
HtmlForm+='<div id="inputForm" "align="center" style="display:"""><table width="175" cellspacing="3" cellpadding="0" border="0" style="border:1px solid #006666;">';
HtmlForm+='<tbody><tr><td bgcolor="#006666" align="center" colspan="2"><font color="#ffffff"><b>Calculate your Debt for Unsecured Loans</b></font></td></tr>';
HtmlForm+='<tr><td bgcolor="#eeeeee" colspan="4"><div align="center"><b><font color="#ff9900">Calculate </font>how many months it will take to fully pay your loan</b></div></td></tr>';
HtmlForm+='<tr><td width="56%" class="pointscalctext"><b>Principal Amount</b></td><td width="43%"><input type="text" name="principalAmount" size="10"/></td></tr>';
HtmlForm+='<tr><td width="56%" class="pointscalctext"><b>Interest Rate</b></td><td width="43%"><input type="text" name="interestRate" size="10"/></td></tr>';
HtmlForm+='<tr><td width="56%" class="pointscalctext"><b>Monthly Payment</b></td><td width="43%"><input type="text" name="monthlyPayment" size="10"/></td></tr>';
HtmlForm+='<tr><td colspan="4"><div align="center"><input type="button" value="Calculate" name="calculate" class="pointscalcbutton" onclick="javascript:ShowDIR();" /><input type="reset" name="Reset" value="Reset" class="pointscalcbutton" onClick="javascript:RemoveValue();"></div></td></tr>';
HtmlForm+='<tr><td colspan="4" ><div id="DIR" align="center"></div></td></tr>';
HtmlForm+='</tbody></table></div><div id="OutputForm" align="center"></div></td></tr></table></form></div>';

        document.getElementById('CreditCardPaymentCalculator').innerHTML = HtmlForm;
}
else
{
        document.getElementById('CreditCardPaymentCalculatorMain').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 FnInitialiseCSSAndShowInitialTableForCalculator()
{
    FnShowInitialTableForCalculator();
}
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>');
FnInitialiseCSSAndShowInitialTableForCalculator()