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

/*
function drawGraph(graphID,maxheight){
	
	if(ns4){
	 graphObj = eval('document.' + graphID)
    }
    if(ns6){
     graphObj = document.getElementById(graphID);
    }
    if(ie4){
      graphObj = document.all(graphID);      
    }  
	
	currHeight = graphObj.style.height	
	//alert( " Height " + currHeight	+ " maxheight: " + maxheight)
	currHeight = currHeight.replace(/[p,t,x,\s]/g,'')
	//currHeight = isNaN(currHeight) || currHeight==""?"":parseInt(currHeight)
	
	
	
	if(isNaN(currHeight) || currHeight==""){
		graphObj.style.height = 0
		setTimeout('drawGraph("' + graphID + '","' + maxheight + '")',55)
	}
	else{
		//alert( " Height " + currHeight	+ " maxheight: " + maxheight)
		if(parseInt(currHeight) < parseInt(maxheight)){						
			graphObj.style.height = parseInt(currHeight) + 1
			setTimeout('drawGraph("' + graphID + '","' + maxheight + '")',55)
		}
	}
	
}
*/

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){
	
	if(ns4){
	 graphObj = eval('document.' + graphID)
    }
    if(ns6){
     graphObj = document.getElementById(graphID);
    }
    if(ie4){
      graphObj = document.all(graphID);      
    }  
	
	currHeight = graphObj.height	
	//alert( " Height " + currHeight	+ " maxheight: " + maxheight)
	if(typeof currHeight.replace != "undefined")
		currHeight = currHeight.replace(/[p,t,x,\s]/g,'')
	
	//currHeight = isNaN(currHeight) || currHeight==""?"":parseInt(currHeight)
	//alert(isNaN(currHeight) + " // " + (currHeight==""))
	
	
	if(isNaN(currHeight) || currHeight==""){		
		
		graphObj.height = 1		
		setTimeout('drawGraph("' + graphID + '","' + maxheight + '")',55)
	}
	else{
		//alert( " Height " + currHeight	+ " maxheight: " + maxheight)
		//alert(currHeight)
		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;
      //toolTipSTYLE.display='block'
    }
    if(ie4){
      document.all(objid).innerHTML=content;
      //toolTipSTYLE.display='block'
    }  
}

// Example: obj = findObj("image1");
function findObj(theObj, theDoc)
{
  var p, i, foundObj;
  
  if(!theDoc) theDoc = document;
  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
  {
    theDoc = parent.frames[theObj.substring(p+1)].document;
    theObj = theObj.substring(0,p);
  }
  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
  for (i=0; !foundObj && i < theDoc.forms.length; i++) 
    foundObj = theDoc.forms[i][theObj];
  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
    foundObj = findObj(theObj,theDoc.layers[i].document);
  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
  
  return foundObj;
}



var payedout = 0;
var GRAPH_MAX_HEIGHT = 140

function monthsToPay(baseamount,annualInterest,minimumPayement){
	
	
	payedout = 0;
	payedinmonths = 0;
	remainingdebt = baseamount;
	monthlyInterest = annualInterest/12;
	while(remainingdebt > 0){
		monthpayement = remainingdebt * minimumPayement;
		if(monthpayement < 25){
			monthpayement = 25;
		}
		payedout += monthpayement;
		interestamount = remainingdebt * monthlyInterest;
		remainingdebt  = remainingdebt - (monthpayement - interestamount);
		payedinmonths++;		
	
	}
	
	return payedinmonths;
}





function calculate(){
	MINIMUM_PAYMENT_PERCENT = 0.025
	AFS_FEE_PERCENT = 0.15
	AFS_FEE_MISC_PERCENT = 0.4
	loanamount = document.dataForm.loanamount.value
	
	count_creditors = document.dataForm.creditors.value
	
	interest = document.dataForm.interest.value

	clearingDuration = document.dataForm.monthstopaypoff.value

	//clearingDuration = 0
	
	loanamount = loanamount.replace(/\$/g,'');
	loanamount = loanamount.replace(/,/g,'');
	loanamount = isNaN(loanamount)?0:parseInt(loanamount)
	interest = interest.replace(/\%/g,'') / 100;
	interest = isNaN(interest)?0:interest
	//alert(interest)
	//interest = formatCurrency(interest)
	
	//interest = interest.replace(/\$/g,'');
	/*
	if(count_creditors == 1){
		if(loanamount <= 20000){
			clearingDuration = 30;
		} else {
			clearingDuration = 32;
		}
	} else {
		if(loanamount <= 8000){
			clearingDuration = 21;
		}
		if(loanamount <= 9000 && loanamount > 8000){
			clearingDuration = 23;
		}
		if(loanamount <= 10000 && loanamount > 9000){
			clearingDuration = 26;
		}
		if(loanamount <= 11999 && loanamount > 10000){
			clearingDuration = 28;
		}
		if(loanamount <= 20999 && loanamount >= 12000){
			clearingDuration = 30;
		}
		if(loanamount <= 30999 && loanamount >=21000){
			clearingDuration = 32;
		}
		if(loanamount <= 40999 && loanamount >= 31000){
			clearingDuration = 34;
		}
		if(loanamount >= 41000){
			clearingDuration = 36;
		}
	}
	*/

	SetText('tud_loan',formatCurrency(loanamount) )
	SetText('cc_loan',formatCurrency(loanamount))
	SetText('don_loan', formatCurrency(loanamount) )
	SetText('FCDR_loan',"<b class='highlight'>" + formatCurrency(loanamount) + "</b>")
	doNothingClearingDuration = monthsToPay(loanamount,interest,MINIMUM_PAYMENT_PERCENT)
	
	SetText('FCDR_dura',"<b class='highlight'>" +clearingDuration+ "</b>")
	

	afs_fee = loanamount * AFS_FEE_PERCENT;
	afs_totcost = (loanamount * AFS_FEE_MISC_PERCENT) + afs_fee;
	afs_TotalMonthlyPayment = afs_totcost/clearingDuration;
	SetText('FCDR_TotalCost',"<b class='highlight'>" +formatCurrency(afs_totcost)+ "</b>")
	SetText('FCDR_monthPay',"<b class='highlight'>" +formatCurrency(afs_TotalMonthlyPayment)+ "</b>")
	SetText('FCDR_inter',"<b class='highlight'>" +"None"+ "</b>")
	SetText('FCDR_exp_inter',"<b class='highlight'>" +"None"+ "</b>")
	monthlypayout = (loanamount * (interest/12)) / (1 - Math.pow(1 + (interest/12),-1 * clearingDuration));
	interestpayout = (monthlypayout * clearingDuration) - loanamount;
	
	
	//Consolidated Loan

	consolidatedLoanInterestRate = 0.12;
		
	consolidatedLoanMonthlyPayment = (loanamount * (consolidatedLoanInterestRate/12))/(1 - Math.pow(1 + (consolidatedLoanInterestRate/12),-1 * 60));	
	SetText('tud_monthPay',formatCurrency(consolidatedLoanMonthlyPayment))
	
	
	consolidatedLoanExtraInterestPaid = (consolidatedLoanMonthlyPayment * 60) - loanamount;	
	SetText('tud_exp_inter',formatCurrency(consolidatedLoanExtraInterestPaid))
	
	consolidatedLoanTotalCost = (consolidatedLoanMonthlyPayment * 60);	
	SetText('tud_TotalCost',formatCurrency(consolidatedLoanTotalCost))
	
	SetText('tud_inter',(consolidatedLoanInterestRate * 100) + " %")
	SetText('tud_dura',60)
	
	//Do Nothing
	
	doNothingMonthlyPayment = loanamount*0.03;
	
	SetText('don_monthPay',formatCurrency(doNothingMonthlyPayment))
	
	doNothingExtraInterestPaid = payedout - loanamount;	
	
	SetText('don_exp_inter',formatCurrency(doNothingExtraInterestPaid))	
	
	doNothingTotalCost = payedout;
	
	SetText('don_TotalCost',formatCurrency(doNothingTotalCost))
	
	SetText('don_dura',doNothingClearingDuration)
	don_disp_interest = (interest * 100)
	SetText('don_inter',don_disp_interest + ' %')

	//CreditCounselling

	CreditCounsellingRate = Math.round((interest * 0.95)*100)/100;
	CreditCounsellingMonthlyPayment = doNothingMonthlyPayment * 0.95;
	SetText('cc_monthPay',formatCurrency(CreditCounsellingMonthlyPayment))
	
	CreditCounsellingExtraInterestPaid = (CreditCounsellingMonthlyPayment * 60) - loanamount;
	SetText('cc_exp_inter',formatCurrency(CreditCounsellingExtraInterestPaid))
	
	CreditCounsellingTotalCost = (CreditCounsellingMonthlyPayment * 60);	
	SetText('cc_TotalCost',formatCurrency(CreditCounsellingTotalCost))
	SetText('cc_inter',"Variable")
	SetText('cc_dura',60)


	drawMonthlyPayment(consolidatedLoanMonthlyPayment,	CreditCounsellingMonthlyPayment,	doNothingMonthlyPayment,	afs_TotalMonthlyPayment)
	drawTimeInProgram(60,60,doNothingClearingDuration,clearingDuration)	
	drawTotProgramCost(consolidatedLoanTotalCost,CreditCounsellingTotalCost,doNothingTotalCost,afs_totcost)
	
}

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('FCDR_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('FCDR_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('FCDR_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 -->