var TotalPaymentFactored;
var GRAPH_MAX_HEIGHT = 135

var ns4 = document.layers;
var ns6 = document.getElementById && !document.all;
var ie4 = document.all;


function getObjectByID(Objid) {
    if (ns4) {
        return eval('document.' + Objid)
    }
    if (ns6) {
        return document.getElementById(Objid);
    }
    if (ie4) {
        return document.all(Objid);
    }
    return null
}


function drawGraph(graphID, maxheight) {
    graphObj = getObjectByID(graphID)
    currHeight = graphObj.height
    
    if (typeof currHeight.replace != "undefined")
        currHeight = currHeight.replace(/[p,t,x,\s]/g, '')

    if (isNaN(currHeight) || currHeight == "") {
        graphObj.height = 1
        setTimeout('drawGraph("' + graphID + '","' + maxheight + '")', 55)
    }
    else {
        if (parseInt(currHeight) < parseInt(maxheight)) {
            graphObj.height = parseInt(currHeight) + 1
            setTimeout('drawGraph("' + graphID + '","' + maxheight + '")', 55)
        }
        else if (parseInt(currHeight) > parseInt(maxheight)) {
            if (parseInt(currHeight) - 1 > 1) {
                graphObj.height = parseInt(currHeight) - 1
                setTimeout('drawGraph("' + graphID + '","' + maxheight + '")', 55)
            }
            else
                graphObj.height = 1
        }
    }
}

function SetText(objid, msg, fg, bg) {
    if (!fg) fg = "#ff0000";
    if (!bg) bg = "#FFFFFF";

    var content = msg;
    if (ns4) {
        objItm = eval('document.' + objid)
        objItm.document.write(content);
        objItm.document.close();
        objItm.visibility = "visible";
    }
    if (ns6) {
        document.getElementById(objid).innerHTML = content;        
    }
    if (ie4) {
        document.all(objid).innerHTML = content;        
    }
}


function EREmoneyFormat(mnt) {
    mnt -= 0;
    mnt = (Math.round(mnt * 100)) / 100;
    if (mnt == Math.floor(mnt)) {
        mnt = mnt + '.00'
    }
    else {
        if (mnt * 10 == Math.floor(mnt * 10)) {
            mnt = mnt + '0'
        }
    }
    return '$' + mnt
}

function moneyFormat(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)
}

function fmtMoney(number) {
    floatPoint = 2;
    decimalSep = '.';
    thousandsSep = ',';
    (number + '').match(/(\d+)(?:\.(\d+)|)/);
    with (RegExp) {
        var frac = floatPoint ? decimalSep + Number('.' + $2).toFixed(floatPoint).substr(2) : '';
        alert('$ ' + ((x = $1.length % 3) ? $1.substr(0, x) + thousandsSep : '') + $1.substr(x).replace(/(\d{3})(?=\d)/g, '$1' + thousandsSep) + frac);
        return '$ ' + ((x = $1.length % 3) ? $1.substr(0, x) + thousandsSep : '') + $1.substr(x).replace(/(\d{3})(?=\d)/g, '$1' + thousandsSep) + frac
    }
}

function SetHeight(big, small, element, info) {
    imageHeight = Math.round((small / big) * 100);
    growImage(element, imageHeight);
    $(element).title = info; $(element).alt = info
}

function growImage(element, goal) {
    if (parseInt($(element).style.height) < goal && parseInt($(element).style.height) < 100) {
        $(element).style.height = Number(parseInt($(element).style.height) + 1) + 'px';
        my_timeout = setTimeout('growImage(\'' + element + '\',\'' + goal + '\');', 25)
    }
    if (parseInt($(element).style.height) > goal) {
        $(element).style.height = Number(parseInt($(element).style.height) - 1) + 'px';
        my_timeout = setTimeout('growImage(\'' + element + '\',\'' + goal + '\');', 25)
    }
}

function CalcCycle(debt, interest, min) {
    TotalPaymentFactored = 0; TotalCycles = 0;
    currentDebt = debt;
    monthInterest = interest / 12;
    while (currentDebt > 0) {
        payment = currentDebt * min; 
        if (payment < 25) {
            payment = 25
        }
        TotalPaymentFactored += payment;
        waste = currentDebt * monthInterest;
        currentDebt = currentDebt - (payment - waste);
        TotalCycles++
    }
    return TotalCycles
}

function calcForm() {
    selectedState = $('usState').value
    
    FEE_PERCENT = 0.14; //14 %
    TotalUnsecuredDebt = $('userTotalUnsecuredDebt').value.replace('$', '');
    TotalUnsecuredDebt = TotalUnsecuredDebt.replace(',', '');
    AvgInterestRate = $('userAvgInterestRate').value.replace('%', '') / 100;
    if ($('creditorDuration').value == 1) {
        if (TotalUnsecuredDebt <= 20000) {
            ProgramPeriod = 30
        } 
        else {
            ProgramPeriod = 32
        }
    }
    else {

        if (TotalUnsecuredDebt <= 8999) {
            ProgramPeriod = 21
        }
        else if (TotalUnsecuredDebt <= 9999) {
            ProgramPeriod = 23
        }
        else if (TotalUnsecuredDebt <= 10999) {
            ProgramPeriod = 26
        }
        else if (TotalUnsecuredDebt <= 11999) {
            ProgramPeriod = 28
        }
        else if (TotalUnsecuredDebt <= 20999) {
            ProgramPeriod = 30
        }
        else if (TotalUnsecuredDebt <= 30999) {
            ProgramPeriod = 32
        }
        else if (TotalUnsecuredDebt <= 40999) {
            ProgramPeriod = 34
        }
        else if (TotalUnsecuredDebt <= 70999) {
            ProgramPeriod = 35
        }
        else {
            ProgramPeriod = 36
        }
    }

    
    switch (selectedState) {
        case "CA":
        case "KS":
        case "IA":
        case "MS":
        case "KY":
        case "OH":
        case "WV":
        case "VA":
        case "NJ":
        case "ME":
            FEE_PERCENT = 0.16 // 16%
    }
    
   
    
    $('afsTotalUnsecuredDebt').innerHTML = moneyFormat(TotalUnsecuredDebt);
    $('dcTotalUnsecuredDebt').innerHTML = moneyFormat(TotalUnsecuredDebt);
    $('ccTotalUnsecuredDebt').innerHTML = moneyFormat(TotalUnsecuredDebt);
    $('dnTotalUnsecuredDebt').innerHTML = moneyFormat(TotalUnsecuredDebt);
    $('afsMonthsToPayOff').innerHTML = ProgramPeriod;
    if (AvgInterestRate * 100 == Math.floor(AvgInterestRate * 100)) {
        displayInterestRate = AvgInterestRate * 100 + '.0'
    }
    else {
        displayInterestRate = AvgInterestRate * 100
    }
    $('dnInterestRate').innerHTML = Math.round(displayInterestRate * 100) / 100 + '%';
    nothingDuration = CalcCycle(TotalUnsecuredDebt, AvgInterestRate, 0.025);
    afs_fee = TotalUnsecuredDebt * FEE_PERCENT;
    TotalCost = (TotalUnsecuredDebt * 0.4) + afs_fee;
    TotalMonthlyPayment = TotalCost / ProgramPeriod;
    $('afsYourTotalCost').innerHTML = moneyFormat(TotalCost);
    $('afsMonthlyPayment').innerHTML = moneyFormat(TotalMonthlyPayment);
    MonthlyPayment = (TotalUnsecuredDebt * (AvgInterestRate / 12)) / (1 - Math.pow(1 + (AvgInterestRate / 12), -1 * ProgramPeriod));
    IntrestPaid = (MonthlyPayment * ProgramPeriod) - TotalUnsecuredDebt;
    dccInterestRate = 0.11;
    dccMonthlyPayment = (TotalUnsecuredDebt * (dccInterestRate / 12)) / (1 - Math.pow(1 + (dccInterestRate / 12), -1 * 60));
    $('dcMonthlyPayment').innerHTML = moneyFormat(dccMonthlyPayment);
    dccExtraInterestPaid = (dccMonthlyPayment * 60) - TotalUnsecuredDebt;
    $('dcExtraInterestPaid').innerHTML = moneyFormat(dccExtraInterestPaid);
    dccTotalCost = (dccMonthlyPayment * 60);
    $('dcYourTotalCost').innerHTML = moneyFormat(dccTotalCost);
    dnnMonthlyPayment = TotalUnsecuredDebt * 0.03;
    $('dnMonthlyPayment').innerHTML = moneyFormat(dnnMonthlyPayment);
    dnnExtraInterestPaid = TotalPaymentFactored - TotalUnsecuredDebt;
    $('dnExtraInterestPaid').innerHTML = moneyFormat(dnnExtraInterestPaid);
    dnnTotalCost = TotalPaymentFactored;
    $('dnYourTotalCost').innerHTML = moneyFormat(dnnTotalCost);
    $('dnMonthsToPayOff').innerHTML = nothingDuration;
    cccRate = Math.round((AvgInterestRate * 0.95) * 100) / 100;
    cccMonthlyPayment = dnnMonthlyPayment * 0.95;
    $('ccMonthlyPayment').innerHTML = moneyFormat(cccMonthlyPayment);
    cccExtraInterestPaid = (cccMonthlyPayment * 60) - TotalUnsecuredDebt;
    $('ccExtraInterestPaid').innerHTML = moneyFormat(cccExtraInterestPaid);
    cccTotalCost = (cccMonthlyPayment * 60);
    $('ccYourTotalCost').innerHTML = moneyFormat(cccTotalCost);
    //$('maxmonthly').innerHTML = moneyFormat(dnnMonthlyPayment) + '+';
    //$('medmonthly').innerHTML = moneyFormat(dnnMonthlyPayment / 2);
    //SetHeight(dnnMonthlyPayment, dnnMonthlyPayment, 'Monthlydonothing', 'Do Nothing - ' + moneyFormat(dnnMonthlyPayment));
    //SetHeight(dnnMonthlyPayment, dccMonthlyPayment, 'Monthlydebtcon', 'Debt Consolidation - ' + moneyFormat(dccMonthlyPayment));
    //SetHeight(dnnMonthlyPayment, cccMonthlyPayment, 'Monthlycreditco', 'Credit Counseling - ' + moneyFormat(cccMonthlyPayment));
    //SetHeight(dnnMonthlyPayment, TotalMonthlyPayment, 'Monthlycds', 'Clear Debt Solution - ' + moneyFormat(TotalMonthlyPayment));
    //SetHeight(100, 270, 'Timedonothing', 'Do Nothing - 270 months');
    //SetHeight(100, 60, 'Timedebtcon', 'Debt Consolidation - 60 Months');
    //SetHeight(100, 60, 'Timecreditco', 'Credit Counseling - 60 Months');
    //SetHeight(100, ProgramPeriod, 'Timecds', 'Clear Debt Solution - ' + ProgramPeriod + ' Months');
    TUS = TotalUnsecuredDebt;
    if (TUS < 29999) {
        filter = 50000
    }
    if (TUS >= 30000 && TUS <= 49999) {
        filter = 90000
    }
    if (TUS >= 50000 && TUS <= 99999) {
        filter = 190000
    }
    if (TUS >= 100000 && TUS <= 149999) {
        filter = 300000
    }
    if (TUS >= 150000) {
        filter = TUS * 2 + 100000
    }
    //$('TDtop').innerHTML = moneyFormat(filter) + '+';
    //$('TDmed').innerHTML = moneyFormat(filter / 2);
    //SetHeight(filter, dnnTotalCost, 'donothing', 'Do Nothing - ' + moneyFormat(dnnTotalCost));
    //SetHeight(filter, dccTotalCost, 'debtcon', 'Debt Consolidation - ' + moneyFormat(dccTotalCost));
    //SetHeight(filter, cccTotalCost, 'creditco', 'Credit Counseling - ' + moneyFormat(cccTotalCost));
    //SetHeight(filter, TotalCost, 'cds', 'Clear Debt Solution - ' + moneyFormat(TotalCost))
    
    
    
	drawMonthlyPayment(dccMonthlyPayment,	cccMonthlyPayment,	dnnMonthlyPayment,	TotalMonthlyPayment)
	drawTimeInProgram(60,60,nothingDuration,ProgramPeriod)	
	drawTotProgramCost(dccTotalCost, cccTotalCost, dnnTotalCost, TotalCost)
    
    
}



function doCompare(var1, var2) {
    if (var1 > var2) return -1
    if (var1 < var2) return 1
    return 0
}

function drawMonthlyPayment(conamnt, ccamnt, donamnt, afsamnt) {
    arr = new Array()
    arr.push(conamnt)
    arr.push(ccamnt)
    arr.push(donamnt)
    arr.push(afsamnt)
    arr.sort(doCompare)

    MaxVal = arr[0]

    SetText('max_monthly_mark', formatCurrency(MaxVal))
    SetText('mid_monthly_mark', formatCurrency(MaxVal / 2))
    SetText('min_monthly_mark', formatCurrency(0))

    tud_monp_graph_payperiod = (((conamnt / MaxVal) * 100) * GRAPH_MAX_HEIGHT) / 100
    cc_monp_graph_payperiod = (((ccamnt / MaxVal) * 100) * GRAPH_MAX_HEIGHT) / 100
    don_monp_graph_payperiod = (((donamnt / MaxVal) * 100) * GRAPH_MAX_HEIGHT) / 100
    afs_monp_graph_payperiod = (((afsamnt / MaxVal) * 100) * GRAPH_MAX_HEIGHT) / 100

    drawGraph('tud_monp_graph', isNaN(tud_monp_graph_payperiod) ? 0 : tud_monp_graph_payperiod)
    drawGraph('cc_monp_graph', isNaN(cc_monp_graph_payperiod) ? 0 : cc_monp_graph_payperiod)
    drawGraph('don_monp_graph', isNaN(don_monp_graph_payperiod) ? 0 : don_monp_graph_payperiod)
    drawGraph('afs_monp_graph', isNaN(afs_monp_graph_payperiod) ? 0 : afs_monp_graph_payperiod)
}

function drawTimeInProgram(conamnt, ccamnt, donamnt, afsamnt) {
    arr = new Array()
    arr.push(conamnt)
    arr.push(ccamnt)
    arr.push(donamnt)
    arr.push(afsamnt)
    arr.sort(doCompare)

    MaxVal = arr[0]

    SetText('max_months', MaxVal)
    SetText('mid_months', MaxVal / 2)
    SetText('min_months', 0)
    tud_months_graph_time = (((conamnt / MaxVal) * 100) * GRAPH_MAX_HEIGHT) / 100
    cc_months_graph_time = (((ccamnt / MaxVal) * 100) * GRAPH_MAX_HEIGHT) / 100
    don_months_graph_time = (((donamnt / MaxVal) * 100) * GRAPH_MAX_HEIGHT) / 100
    afs_months_graph_time = (((afsamnt / MaxVal) * 100) * GRAPH_MAX_HEIGHT) / 100
    drawGraph('tud_months_graph', isNaN(tud_months_graph_time) ? 0 : tud_months_graph_time)
    drawGraph('cc_months_graph', isNaN(cc_months_graph_time) ? 0 : cc_months_graph_time)
    drawGraph('don_months_graph', isNaN(don_months_graph_time) ? 0 : don_months_graph_time)
    drawGraph('afs_months_graph', isNaN(afs_months_graph_time) ? 0 : afs_months_graph_time)
}

function drawTotProgramCost(conamnt, ccamnt, donamnt, afsamnt) {
    arr = new Array()
    arr.push(conamnt)
    arr.push(ccamnt)
    arr.push(donamnt)
    arr.push(afsamnt)
    arr.sort(doCompare)

    MaxVal = arr[0]

    SetText('max_totcost', formatCurrency(MaxVal))
    SetText('mid_totcost', formatCurrency(MaxVal / 2))
    SetText('min_totcost', formatCurrency(0))

    tud_tcost_graph_ht = (((conamnt / MaxVal) * 100) * GRAPH_MAX_HEIGHT) / 100
    cc_tcost_graph_ht = (((ccamnt / MaxVal) * 100) * GRAPH_MAX_HEIGHT) / 100
    don_tcost_graph_ht = (((donamnt / MaxVal) * 100) * GRAPH_MAX_HEIGHT) / 100
    afs_tcost_graph_ht = (((afsamnt / MaxVal) * 100) * GRAPH_MAX_HEIGHT) / 100

    drawGraph('tud_tcost_graph', isNaN(tud_tcost_graph_ht) ? 0 : tud_tcost_graph_ht)
    drawGraph('cc_tcost_graph', isNaN(cc_tcost_graph_ht) ? 0 : cc_tcost_graph_ht)
    drawGraph('don_tcost_graph', isNaN(don_tcost_graph_ht) ? 0 : don_tcost_graph_ht)
    drawGraph('afs_tcost_graph', isNaN(afs_tcost_graph_ht) ? 0 : afs_tcost_graph_ht)
}





<!-- Original:  Cyanide_7 (leo7278@hotmail.com) -->
<!-- Web Site:  http://www7.ewebcity.com/cyanide7 -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
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);
}
//  End --> 