<!--

function format(num,fstyle)
{


	if(fstyle=='float')
{				
		temp1=num;
		numDec=parseFloat(num)-Math.floor(temp1);
		numDec=parseInt(numDec*100);
		if(numDec)
		{
		
		numDec=""+numDec;
		numFloat=Math.floor(temp1)+"."+numDec;
		}
		else
		{
		numFloat=Math.floor(temp1)+".00";
		}

return numFloat;		

}


	if(fstyle=='currency'||fstyle=='RupeePaise')	
		
{		
		temp1=format(num,'float');
		
		temp1*=1;
		numDec=temp1-parseInt(temp1);
		
		
		temp1=parseInt(temp1);
		temp1=temp1.toString();
		arr="";
		
		if(temp1.length>3)
		{
		inc=3;
		for(i=temp1.length-3;i>0;i-=inc)
		{
		
		arr= ","+temp1.substr(i,inc)+arr;
		
		inc=2;
		}
		
		arr=temp1.substring(0,i+2)+arr;
		}
		else
		{			
		arr=temp1;
		}		
		
		if(fstyle=='RupeePaise')
		{arr=arr+Math.abs(numDec);}
return arr;
}


}


function chk_num(field_obj) {
	if(isNaN(field_obj.value)) {
		field_obj.value = "";
	}
}


// CALCULATION FUNCTIONS : SHOULD MY SPOUSE WORK : START

// calculate annual values
function calculate_annual(field_obj, div_loc) {
	if(field_obj.value == '' || isNaN(field_obj.value)) { 
		field_obj.value = 0;
		document.getElementById(div_loc).innerHTML = 0;
	} 
	else { 
		document.getElementById(div_loc).innerHTML = parseInt(field_obj.value)*12; 
	}
}

function ssw_calculate_netincome(){
		var spouse_monthly_income = document.spouse_work.monthly_income.value;
		var spouse_tax_rate = document.spouse_work.tax_rate.value;
		var sum_tax = (spouse_monthly_income) * ((spouse_tax_rate)/100);
		var net_income_after_tax = (spouse_monthly_income) - (sum_tax);
		document.spouse_work.net_of_tax.value = net_income_after_tax;
		//document.getElementById('annual_net_income').innerHTML = (net_income_after_tax) * 12;
		document.spouse_work.annual_net_income.value = (net_income_after_tax) * 12;
		
}

function calculate_monthly_expense(){
	var doc_child_care =  parseInt(document.spouse_work.child_care.value);
	if(isNaN(doc_child_care)) doc_child_care = 0;

	var doc_work_transport = parseInt(document.spouse_work.work_transport.value);
	if(isNaN(doc_work_transport)) doc_work_transport = 0;

	var doc_related_clothes = parseInt(document.spouse_work.related_clothes.value);
	if(isNaN(doc_related_clothes)) doc_related_clothes = 0;

	var doc_housekeeping = parseInt(document.spouse_work.housekeeping.value);
	if(isNaN(doc_housekeeping)) doc_housekeeping = 0;

	var doc_entertaintment = parseInt(document.spouse_work.entertaintment.value);
	if(isNaN(doc_entertaintment)) doc_entertaintment = 0;

	var doc_eating_out = parseInt(document.spouse_work.eating_out.value);
	if(isNaN(doc_eating_out)) doc_eating_out = 0;

	var doc_other = parseInt(document.spouse_work.other.value);
	if(isNaN(doc_other)) doc_other = 0;

	var total_monthly_expense = (doc_child_care + doc_work_transport + doc_related_clothes + doc_housekeeping + doc_entertaintment + doc_eating_out + doc_other) ;
	document.getElementById('monthly_expense').innerHTML = total_monthly_expense;
	document.getElementById('annual_expense').innerHTML = (total_monthly_expense) * 12;

}


function final_calculate_value(){
		var spouse_monthly_income = document.spouse_work.monthly_income.value;
		var spouse_tax_rate = document.spouse_work.tax_rate.value;
		var sum_tax = (spouse_monthly_income) * ((spouse_tax_rate)/100);
		var net_income_after_tax = (spouse_monthly_income) - (sum_tax);
		var annual_income_after_tax = (net_income_after_tax) * 12;
		

		var doc_child_care =  parseInt(document.spouse_work.child_care.value);
		if(isNaN(doc_child_care)) doc_child_care = 0;

		var doc_work_transport = parseInt(document.spouse_work.work_transport.value);
		if(isNaN(doc_work_transport)) doc_work_transport = 0;

		var doc_related_clothes = parseInt(document.spouse_work.related_clothes.value);
		if(isNaN(doc_related_clothes)) doc_related_clothes = 0;

		var doc_housekeeping = parseInt(document.spouse_work.housekeeping.value);
		if(isNaN(doc_housekeeping)) doc_housekeeping = 0;

		var doc_entertaintment = parseInt(document.spouse_work.entertaintment.value);
		if(isNaN(doc_entertaintment)) doc_entertaintment = 0;

		var doc_eating_out = parseInt(document.spouse_work.eating_out.value);
		if(isNaN(doc_eating_out)) doc_eating_out = 0;

		var doc_other = parseInt(document.spouse_work.other.value);
		if(isNaN(doc_other)) doc_other = 0;

		var total_monthly_expense = (doc_child_care + doc_work_transport + doc_related_clothes + doc_housekeeping + doc_entertaintment + doc_eating_out + doc_other) ;
		var total_annualy_expense = (total_monthly_expense) * 12;
		
		var doc_life_insurance =  parseInt(document.spouse_work.life_insurance.value);
		if(isNaN(doc_life_insurance)) doc_life_insurance = 0;

		var doc_medical_insurance = parseInt(document.spouse_work.medical_insurance.value);
		if(isNaN(doc_medical_insurance)) doc_medical_insurance = 0;

		var total_monthly_insurance_expense = (doc_life_insurance + doc_medical_insurance) ;
		var total_annualy_insurance_expense = (total_monthly_insurance_expense) * 12 ;

		var total_spouse_extra_income = (annual_income_after_tax - total_annualy_expense) + total_annualy_insurance_expense;
		if(total_spouse_extra_income > 0){
			document.getElementById('result').innerHTML = '<table bgColor=\"#E5E5E5\" height=\"100\" width=\"500\" border=\"0\" align=\"center\" cellpadding=\"2\" cellspacing=\"0\"><tr><td align=\"left\">Spouse\'s Annual take home</td><td> : </td><td></td><td><b>Rs ' + format(annual_income_after_tax,'currency') + '</b></td></tr><tr><td>Less - Work related expenses</td><td> : </td><td></td><td><b>Rs ' + format(total_annualy_expense,'currency') + '</b></td></tr><tr><td>Add - Opportunity cost of not working</td><td> : </td><td></td><td><b>Rs '+format(total_annualy_insurance_expense,'currency')+'</b></td></tr><tr> <td>Extra income if spouse works</td><td> : </td><td></td><td><b>Rs '+format(total_spouse_extra_income,'currency')+' </b></td></tr><tr><td colspan=\"4\"> <b><font Color=\"blue\">As you will earn extra household income if your spouse works, it makes sense for her to continue working.</font></b></td></tr></table>';
		}else{
			document.getElementById('result').innerHTML = '<table bgColor=\"#E5E5E5\" height=\"100\" width=\"500\" border=\"0\" align=\"center\" cellpadding=\"2\" cellspacing=\"0\"><tr><td align=\"left\">Spouse\'s Annual take home</td><td> : </td><td></td><td><b>Rs ' + format(annual_income_after_tax,'currency') + ' </b></td></tr><tr><td>Less - Work related expenses</td><td> : </td><td></td><td><b>Rs ' + format(total_annualy_expense,'currency') + '</b></td></tr><tr><td>Add - Opportunity cost of not working</td><td> : </td><td></td><td><b>Rs '+format(total_annualy_insurance_expense,'currency')+'</b></td></tr><tr> <td>Extra income if spouse works</td><td> : </td><td></td><td><b>Rs '+format(total_spouse_extra_income,'currency')+'</b></td></tr><tr><td colspan=\"4\">As <b><font Color=\"red\">you will not earn extra household income if your spouse works</font></b>, it does not make sense for her to continue working.</td></tr></table>';
		}
}

// CALCULATION FUNCTIONS : SHOULD MY SPOUSE WORK : END



// CALCULATION FUNCTIONS : CONTINGENCY FUNDS : START

	function cf_calculate_netincome(){
			var spouse_medical_dental_costs = parseInt(document.fund_frm.medical_dental_costs.value);
			if(isNaN(spouse_medical_dental_costs)) spouse_medical_dental_costs = 0;
			
			var spouse_vehicle_repairs = parseInt(document.fund_frm.vehicle_repairs.value);
			if(isNaN(spouse_vehicle_repairs)) spouse_vehicle_repairs = 0;
			
			var spouse_others = parseInt(document.fund_frm.others.value);
			if(isNaN(spouse_others)) spouse_others = 0;					
	

			sum_spouse = (spouse_medical_dental_costs + spouse_vehicle_repairs + spouse_others);
			
			//document.getElementById('uninsured').innerHTML = sum_spouse;
			document.getElementById('uninsured').innerHTML = format(sum_spouse,'currency');
	}


	function calculate_insurance_expense(){
		var doc_life_insurance_premium =  parseInt(document.fund_frm.life_insurance_premium.value);
		if(isNaN(doc_life_insurance_premium)) doc_life_insurance_premium = 0;

		var doc_medical_insurance_premium = parseInt(document.fund_frm.medical_insurance_premium.value);
		if(isNaN(doc_medical_insurance_premium)) doc_medical_insurance_premium = 0;

		var doc_home_auto_insurance_premium = parseInt(document.fund_frm.home_auto_insurance_premium.value);
				if(isNaN(doc_home_auto_insurance_premium)) doc_home_auto_insurance_premium = 0;

		var total_insurance_expense = (doc_life_insurance_premium + doc_medical_insurance_premium + doc_home_auto_insurance_premium) ;
		
		//document.getElementById('insurance').innerHTML = total_insurance_expense;
		document.getElementById('insurance').innerHTML = format(total_insurance_expense,'currency');
	
	}

	
	function calculate_living_expense(){
		var doc_monthly_living_expenses =  parseInt(document.fund_frm.monthly_living_expenses.value);
		if(isNaN(doc_monthly_living_expenses)) doc_monthly_living_expenses = 0;

		var doc_month_unemployed = parseInt(document.fund_frm.month_unemployed.value);
		if(isNaN(doc_month_unemployed)) doc_month_unemployed = 0;
	
		total_unemploy_expense = (doc_monthly_living_expenses * doc_month_unemployed);
	
		//document.getElementById('unemploy').innerHTML = total_unemploy_expense;
		document.getElementById('unemploy').innerHTML = format(total_unemploy_expense,'currency');
	}


	
	function final_calculate_contingency_value(){
			var spouse_medical_dental_costs = parseInt(document.fund_frm.medical_dental_costs.value);
			if(isNaN(spouse_medical_dental_costs)) spouse_medical_dental_costs = 0;
			
			var spouse_vehicle_repairs = parseInt(document.fund_frm.vehicle_repairs.value);
			if(isNaN(spouse_vehicle_repairs)) spouse_vehicle_repairs = 0;
			
			var spouse_others = parseInt(document.fund_frm.others.value);
			if(isNaN(spouse_others)) spouse_others = 0;					

			var sum_spouse = (spouse_medical_dental_costs + spouse_vehicle_repairs + spouse_others);

			var doc_life_insurance_premium =  parseInt(document.fund_frm.life_insurance_premium.value);
			if(isNaN(doc_life_insurance_premium)) doc_life_insurance_premium = 0;

			var doc_medical_insurance_premium = parseInt(document.fund_frm.medical_insurance_premium.value);
			if(isNaN(doc_medical_insurance_premium)) doc_medical_insurance_premium = 0;

			var doc_home_auto_insurance_premium = parseInt(document.fund_frm.home_auto_insurance_premium.value);
			if(isNaN(doc_home_auto_insurance_premium)) doc_home_auto_insurance_premium = 0;

			var total_insurance_expense = (doc_life_insurance_premium + doc_medical_insurance_premium + doc_home_auto_insurance_premium) ;
			
			var doc_monthly_living_expenses =  parseInt(document.fund_frm.monthly_living_expenses.value);
			if(isNaN(doc_monthly_living_expenses)) doc_monthly_living_expenses = 0;

			var doc_month_unemployed = parseInt(document.fund_frm.month_unemployed.value);
			if(isNaN(doc_month_unemployed)) doc_month_unemployed = 0;
		
			total_unemploy_expense = (doc_monthly_living_expenses * doc_month_unemployed);

			var contingency_fund = (sum_spouse + total_insurance_expense + total_unemploy_expense);
			
			/*
			document.getElementById('result').innerHTML = '<table bgColor=\"#E5E5E5\" height=\"100\" width=\"500\" border=\"0\" align=\"center\" cellpadding=\"2\" cellspacing=\"0\"><tr><td align=\"center\">Total contingency fund you would need this year : <b>Rs.' + contingency_fund + '/-</b></td></tr></table>';
			*/

			document.getElementById('result').innerHTML = 'You would need a total contingency<br /> fund of <span  style="color:#ff6600;">Rs ' + format(contingency_fund,'currency') + '</span> per annum. You can invest<br /> this amount in a liquid mutual fund or a bank deposit.';
			return result;
	}

// CALCULATION FUNCTIONS : CONTINGENCY FUNDS : END



// CALCULATION FUNCTIONS : DEBT REDUCTION PLAN : START

	function calculate_debt_reduction_plan(){
		
		var total_outstanding_debt = parseInt(document.debt_reduction_plan_frm.total_debt_outstanding.value);
		if(isNaN(total_outstanding_debt)) total_outstanding_debt = 0;

		var rate_of_interest_annum = parseInt(document.debt_reduction_plan_frm.rate_of_interest.value);
		if(isNaN(rate_of_interest_annum)) rate_of_interest_annum = 0;

		var EMI_per_month = parseInt(document.debt_reduction_plan_frm.repay_every_month.value);
		if(isNaN(EMI_per_month)) EMI_per_month = 0;

		if(total_outstanding_debt > 0 && rate_of_interest_annum > 0 || EMI_per_month > 0)
		{
			var rate_of_interest_month = (rate_of_interest_annum / 12) / 100;

			var repay_month = 0;
			var end_os = "";
			var loan_repay_flag = 1;

			if(end_os == ""){
				var starting_os = total_outstanding_debt;
			}

			while(starting_os > 0)
			{
				var interest_per_month = starting_os * rate_of_interest_month;
				var current_total_amount = starting_os + interest_per_month;
				var end_os = current_total_amount - EMI_per_month;

				if(repay_month == 360){
					loan_repay_flag = -1;
					break;	// CANNOT REPLAY LOAN WITHIN 20 YEARS
				}

				var starting_os = end_os;
				var repay_month = repay_month + 1;
			}

			//var total_months = repay_month - 1;
			var total_months = repay_month;
			
			if(loan_repay_flag > 0) {
				var loan_repay_msg = "You can repay your loan amount of <span  style=\"color:#ff6600;\"><b>Rs " + format(total_outstanding_debt,'currency') + "</b></span> within <b><span  style=\"color:#ff6600;\">" + total_months + " </span>months.</b>";
			}
			else if(loan_repay_flag == -1) {
				var loan_repay_msg = "<b>Red Alert! <br> <font color='red'>Based on your current details you cannot repay your loan within next 30 years!</font></b>";
			}

			document.getElementById("result").innerHTML = loan_repay_msg;

		}
	}

// CALCULATION FUNCTIONS : DEBT REDUCTION PLAN : END




// CALCULATION FUNCTIONS : BUDGET : START

function calculate_salary(){
			var income_salary = parseInt(document.frm_budget.salary.value);
			if(isNaN(income_salary)) income_salary = 0;

			var income_pension = parseInt(document.frm_budget.pension.value);
			if(isNaN(income_pension)) income_pension = 0;

			var income_rental_income = parseInt(document.frm_budget.rental_income.value);
			if(isNaN(income_rental_income)) income_rental_income = 0;

			var income_interest = parseInt(document.frm_budget.interest.value);
			if(isNaN(income_interest)) income_interest = 0;

			var income_dividends = parseInt(document.frm_budget.dividends.value);
			if(isNaN(income_dividends)) income_dividends = 0;

			var income_others = parseInt(document.frm_budget.salary_others.value);
			if(isNaN(income_others)) income_others = 0;

			var monthly_interest = (income_interest / 12);
			var monthly_dividend = (income_dividends / 12);

			var sum_income_monthly = (income_salary + income_pension + income_rental_income + monthly_interest + monthly_dividend + income_others);
			
			/*
			document.getElementById('salary_monthly').innerHTML = Math.round(sum_income_monthly);
			document.getElementById('salary_annualy').innerHTML = Math.round((sum_income_monthly) * 12);
			*/
			//document.frm_budget.salary_monthly.value = Math.round(sum_income_monthly);
			//document.frm_budget.salary_annualy.value = Math.round((sum_income_monthly) * 12);
			document.frm_budget.salary_monthly.value = format(Math.round(sum_income_monthly),'currency');
			document.frm_budget.salary_annualy.value = format(Math.round((sum_income_monthly) * 12),'currency');
			
	}


function calculate_housing_debt(){

			var income_salary = parseInt(document.frm_budget.salary.value);
			if(isNaN(income_salary)) income_salary = 0;

			var income_pension = parseInt(document.frm_budget.pension.value);
			if(isNaN(income_pension)) income_pension = 0;

			var income_rental_income = parseInt(document.frm_budget.rental_income.value);
			if(isNaN(income_rental_income)) income_rental_income = 0;

			var income_interest = parseInt(document.frm_budget.interest.value);
			if(isNaN(income_interest)) income_interest = 0;

			var income_dividends = parseInt(document.frm_budget.dividends.value);
			if(isNaN(income_dividends)) income_dividends = 0;

			var income_others = parseInt(document.frm_budget.salary_others.value);
			if(isNaN(income_others)) income_others = 0;

			var monthly_interest = (income_interest / 12);
			var monthly_dividend = (income_dividends / 12);

			var sum_income_annualy = ((income_salary + income_pension + income_rental_income + monthly_interest + monthly_dividend + income_others) * 12);




			var housing_loan_emi = parseInt(document.frm_budget.home_loan_emi.value);
			if(isNaN(housing_loan_emi)) housing_loan_emi = 0;

			var housing_car_loan = parseInt(document.frm_budget.car_loan.value);
			if(isNaN(housing_car_loan)) housing_car_loan = 0;

			var housing_personal_loan = parseInt(document.frm_budget.personal_loan.value);
			if(isNaN(housing_personal_loan)) housing_personal_loan = 0;

			var housing_credit_card = parseInt(document.frm_budget.credit_card.value);
			if(isNaN(housing_credit_card)) housing_credit_card = 0;

			var housing_others_val = parseInt(document.frm_budget.housing_others.value);
			if(isNaN(housing_others_val)) housing_others_val = 0;

			
			var sum_housing_debt_monthly = (housing_loan_emi + housing_car_loan + housing_personal_loan + housing_credit_card + housing_others_val);

			var sum_housing_debt_annualy = (sum_housing_debt_monthly) * 12

			var percent_expense = (sum_housing_debt_annualy / sum_income_annualy) * 100;
			if(isNaN(percent_expense)) percent_expense = 0;

			/*
			document.getElementById('housing_monthly').innerHTML = Math.round(sum_housing_debt_monthly);
			document.getElementById('housing_annualy').innerHTML = sum_housing_debt_annualy;
			*/
			document.frm_budget.housing_monthly.value = format(Math.round(sum_housing_debt_monthly),'currency');//Math.round(sum_housing_debt_monthly)
			document.frm_budget.housing_annualy.value = format(sum_housing_debt_annualy,'currency'); //sum_housing_debt_annualy
			
			


			if(percent_expense > 30){
				document.getElementById('hsg_percent').innerHTML = "<font color=\"red\">"+Math.round(percent_expense) +"% <div class=\"red\"><b>Beware! You have take on too many debts. Try to repay them at the earliest</b></div>";			
			}else{
				document.getElementById('hsg_percent').innerHTML = '<font color=\"blue\">Your allocation is '+ Math.round(percent_expense) +'%</font> &nbsp;<div class=\"dblue\"><b>Your debts are well within the limit of 30%</b></div>';
			}
		

}

function calculate_tax(){
			var income_salary = parseInt(document.frm_budget.salary.value);
			if(isNaN(income_salary)) income_salary = 0;

			var income_pension = parseInt(document.frm_budget.pension.value);
			if(isNaN(income_pension)) income_pension = 0;

			var income_rental_income = parseInt(document.frm_budget.rental_income.value);
			if(isNaN(income_rental_income)) income_rental_income = 0;

			var income_interest = parseInt(document.frm_budget.interest.value);
			if(isNaN(income_interest)) income_interest = 0;

			var income_dividends = parseInt(document.frm_budget.dividends.value);
			if(isNaN(income_dividends)) income_dividends = 0;

			var income_others = parseInt(document.frm_budget.salary_others.value);
			if(isNaN(income_others)) income_others = 0;

			var monthly_interest = (income_interest / 12);
			var monthly_dividend = (income_dividends / 12);

			var annual_income_tax = ((income_salary + income_pension + income_rental_income + monthly_interest + monthly_dividend + income_others) * 12);


			var tax_on_rental_income_val = parseInt(document.frm_budget.tax_on_rental_income.value);
			if(isNaN(tax_on_rental_income_val)) tax_on_rental_income_val = 0;

			var debt_income_tax_on_salary_val = parseInt(document.frm_budget.debt_income_tax_on_salary.value);
			if(isNaN(debt_income_tax_on_salary_val)) debt_income_tax_on_salary_val = 0;

			var loan_tax_on_interest_dividends_val = parseInt(document.frm_budget.loan_tax_on_interest_dividends.value);
			if(isNaN(loan_tax_on_interest_dividends_val)) loan_tax_on_interest_dividends_val = 0;

			var sum_tax_monthly = ((tax_on_rental_income_val + loan_tax_on_interest_dividends_val + debt_income_tax_on_salary_val) / 12);
			
			var sum_tax_annum = (tax_on_rental_income_val + loan_tax_on_interest_dividends_val + debt_income_tax_on_salary_val);
			
			var percent_tax = (sum_tax_annum / annual_income_tax) * 100;
			if(isNaN(percent_tax)) percent_tax = 0;

			/*
			document.getElementById('tax_monthly').innerHTML = Math.round(sum_tax_monthly);
			document.getElementById('tax_annualy').innerHTML = Math.round(sum_tax_annum);
			*/
			document.frm_budget.tax_monthly.value = format(Math.round(sum_tax_monthly),'currency'); //Math.round(sum_tax_monthly)
			document.frm_budget.tax_annualy.value = format(Math.round(sum_tax_annum),'currency');//Math.round(sum_tax_annum)
			
			if(percent_tax > 30){
				document.getElementById('tax_percent').innerHTML = "<font color=\"red\">"+Math.round(percent_tax) +"% &nbsp;</font> allocation, <font color=\"red\"><div class=\"red\"><b>Consult your CA, you need help!</b></div></font>";			
			}else{
				document.getElementById('tax_percent').innerHTML = '<font color=\"blue\">Your allocation is '+ Math.round(percent_tax) +'%</font>';
			}

}



function calculate_insurance(){

			var income_salary = parseInt(document.frm_budget.salary.value);
			if(isNaN(income_salary)) income_salary = 0;

			var income_pension = parseInt(document.frm_budget.pension.value);
			if(isNaN(income_pension)) income_pension = 0;

			var income_rental_income = parseInt(document.frm_budget.rental_income.value);
			if(isNaN(income_rental_income)) income_rental_income = 0;

			var income_interest = parseInt(document.frm_budget.interest.value);
			if(isNaN(income_interest)) income_interest = 0;

			var income_dividends = parseInt(document.frm_budget.dividends.value);
			if(isNaN(income_dividends)) income_dividends = 0;

			var income_others = parseInt(document.frm_budget.salary_others.value);
			if(isNaN(income_others)) income_others = 0;

			var monthly_interest = (income_interest / 12);
			var monthly_dividend = (income_dividends / 12);

			var annual_income_ins = ((income_salary + income_pension + income_rental_income + monthly_interest + monthly_dividend + income_others) * 12);

			var ins_life_val = parseInt(document.frm_budget.ins_life.value);
			if(isNaN(ins_life_val)) ins_life_val = 0;

			var ins_medical_val = parseInt(document.frm_budget.ins_medical.value);
			if(isNaN(ins_medical_val)) ins_medical_val = 0;

			var ins_household_val = parseInt(document.frm_budget.ins_household.value);
			if(isNaN(ins_household_val)) ins_household_val = 0;

			var ins_others_val = parseInt(document.frm_budget.ins_others.value);
			if(isNaN(ins_others_val)) ins_others_val = 0;

			var ins_car_val = parseInt(document.frm_budget.ins_car.value);
			if(isNaN(ins_car_val)) ins_car_val = 0;





			var sum_insurance_annualy = (ins_life_val + ins_medical_val + ins_household_val + ins_others_val + ins_car_val);

			var ins_percent = (sum_insurance_annualy / annual_income_ins) * 100;
			if(isNaN(ins_percent)) ins_percent = 0;
			
			document.frm_budget.insurance_monthly.value = format(Math.round(sum_insurance_annualy / 12),'currency');//Math.round(sum_insurance_annualy / 12)
			document.frm_budget.insurance_annualy.value = format(Math.round(sum_insurance_annualy),'currency');//Math.round(sum_insurance_annualy)



			/*
			document.getElementById('insurance_monthly').innerHTML = Math.round(sum_insurance_annualy / 12);
			document.getElementById('insurance_annualy').innerHTML = Math.round(sum_insurance_annualy);
			*/

			if(ins_percent > 4){
				document.getElementById('insur_percent').innerHTML = "<font color=\"red\">"+Math.round(ins_percent) +"% </font> allocation, <div class=\"dblue\"><b>You seems to be sufficiently insured.</b></div>";			
			}else{
				document.getElementById('insur_percent').innerHTML = '<font color=\"blue\">Your allocation is '+ Math.round(ins_percent) +'% &nbsp;<div class=\"red\" nowrap><b>You seem to be underinsured. Consult a financial planner to ensure that you get enough insurance cover.</b></div>';
			}
	
}

// INVESTMENT************
function calculate_investments(){

			var income_salary = parseInt(document.frm_budget.salary.value);
			if(isNaN(income_salary)) income_salary = 0;

			var income_pension = parseInt(document.frm_budget.pension.value);
			if(isNaN(income_pension)) income_pension = 0;

			var income_rental_income = parseInt(document.frm_budget.rental_income.value);
			if(isNaN(income_rental_income)) income_rental_income = 0;

			var income_interest = parseInt(document.frm_budget.interest.value);
			if(isNaN(income_interest)) income_interest = 0;

			var income_dividends = parseInt(document.frm_budget.dividends.value);
			if(isNaN(income_dividends)) income_dividends = 0;

			var income_others = parseInt(document.frm_budget.salary_others.value);
			if(isNaN(income_others)) income_others = 0;

			var monthly_interest = (income_interest / 12);
			var monthly_dividend = (income_dividends / 12);

			var annual_income_invest = ((income_salary + income_pension + income_rental_income + monthly_interest + monthly_dividend + income_others) * 12);
		

	var investment_epf_val = parseInt(document.frm_budget.investment_epf.value);
			if(isNaN(investment_epf_val)) investment_epf_val = 0;

			var investment_ppf_val = parseInt(document.frm_budget.investment_ppf.value);
			if(isNaN(investment_ppf_val)) investment_ppf_val = 0;

			var mutual_funds_val = parseInt(document.frm_budget.mutual_funds.value);
			if(isNaN(mutual_funds_val)) mutual_funds_val = 0;

			var investment_nsc_val = parseInt(document.frm_budget.investment_nsc.value);
			if(isNaN(investment_nsc_val)) investment_nsc_val = 0;

			var investment_deposits_val = parseInt(document.frm_budget.investment_deposits.value);
			if(isNaN(investment_deposits_val)) investment_deposits_val = 0;
	
			
			var investment_others_val = parseInt(document.frm_budget.investment_others.value);
			if(isNaN(investment_others_val)) investment_others_val = 0;
			

			var sum_investment_annualy = (investment_epf_val + investment_ppf_val + mutual_funds_val + investment_nsc_val + investment_deposits_val + investment_others_val);

			var invest_percent = (sum_investment_annualy / annual_income_invest) * 100;
			if(isNaN(invest_percent)) invest_percent = 0;

			/*
			document.getElementById('investment_monthly').innerHTML = Math.round(sum_investment_annualy / 12);
			document.getElementById('investment_annualy').innerHTML = Math.round(sum_investment_annualy);
			*/
			document.frm_budget.investment_monthly.value = format(Math.round(sum_investment_annualy/ 12),'currency');//Math.round(sum_investment_annualy / 12)
			document.frm_budget.investment_annualy.value = format(Math.round(sum_investment_annualy),'currency');//Math.round(sum_investment_annualy)
			
			if(invest_percent > 15){
				document.getElementById('invest_percent').innerHTML = "<font color=\"red\">"+Math.round(invest_percent) +"% </font> allocation, <div class=\"red\" nowrap><b>You are investing enough.</b></div>";			
			}else{
				document.getElementById('invest_percent').innerHTML = '<font color=\"blue\">Your allocation is '+ Math.round(invest_percent) +'%</font> &nbsp; <div class=\"dblue\"><b>You need to invest more.</b></div>';
			}



}

function calculate_living_expenses(){
	var income_salary = parseInt(document.frm_budget.salary.value);
			if(isNaN(income_salary)) income_salary = 0;

			var income_pension = parseInt(document.frm_budget.pension.value);
			if(isNaN(income_pension)) income_pension = 0;

			var income_rental_income = parseInt(document.frm_budget.rental_income.value);
			if(isNaN(income_rental_income)) income_rental_income = 0;

			var income_interest = parseInt(document.frm_budget.interest.value);
			if(isNaN(income_interest)) income_interest = 0;

			var income_dividends = parseInt(document.frm_budget.dividends.value);
			if(isNaN(income_dividends)) income_dividends = 0;

			var income_others = parseInt(document.frm_budget.salary_others.value);
			if(isNaN(income_others)) income_others = 0;

			var monthly_interest = (income_interest / 12);
			var monthly_dividend = (income_dividends / 12);

			var annual_income_living = ((income_salary + income_pension + income_rental_income + monthly_interest + monthly_dividend + income_others) * 12);
	


	var living_food_val = parseInt(document.frm_budget.living_food.value);
	if(isNaN(living_food_val)) living_food_val = 0;

	var living_clothing_val = parseInt(document.frm_budget.living_clothing.value);
	if(isNaN(living_clothing_val)) living_clothing_val = 0;

	var living_electricity_val = parseInt(document.frm_budget.living_electricity.value);
	if(isNaN(living_electricity_val)) living_electricity_val = 0;

	var living_petrol_val = parseInt(document.frm_budget.living_petrol.value);
	if(isNaN(living_petrol_val)) living_petrol_val = 0;

	var living_other_transport_val = parseInt(document.frm_budget.living_other_transport.value);
	if(isNaN(living_other_transport_val)) living_other_transport_val = 0;
	
	var living_cable_val = parseInt(document.frm_budget.living_cable.value);
	if(isNaN(living_cable_val)) living_cable_val = 0;

	var living_newspaper_magazines_val = parseInt(document.frm_budget.living_newspaper_magazines.value);
	if(isNaN(living_newspaper_magazines_val)) living_newspaper_magazines_val = 0;
	
	var living_household_help_val = parseInt(document.frm_budget.living_household_help.value);
	if(isNaN(living_household_help_val)) living_household_help_val = 0;
	
	var living_society_charges_val = parseInt(document.frm_budget.living_society_charges.value);
	if(isNaN(living_society_charges_val)) living_society_charges_val = 0;
	

	var living_milk_val = parseInt(document.frm_budget.living_milk.value);
	if(isNaN(living_milk_val)) living_milk_val = 0;
	
	var living_telephone_val = parseInt(document.frm_budget.living_telephone.value);
	if(isNaN(living_telephone_val)) living_telephone_val = 0;


	var living_water_val = parseInt(document.frm_budget.living_water.value);
	if(isNaN(living_water_val)) living_water_val = 0;
	
	var children_school_fees_val = parseInt(document.frm_budget.children_school_fees.value);
	if(isNaN(children_school_fees_val)) children_school_fees_val = 0;
	
	var tuition_fees_val = parseInt(document.frm_budget.tuition_fees.value);
	if(isNaN(tuition_fees_val)) tuition_fees_val = 0;
	
	var personal_care_val = parseInt(document.frm_budget.personal_care.value);
	if(isNaN(personal_care_val)) personal_care_val = 0;
	
	var living_medicines_val = parseInt(document.frm_budget.living_medicines.value);
	if(isNaN(living_medicines_val)) living_medicines_val = 0;
	
	var hobbies_val = parseInt(document.frm_budget.hobbies.value);
	if(isNaN(hobbies_val)) hobbies_val = 0;
	
	var living_others_val = parseInt(document.frm_budget.living_others.value);
	if(isNaN(living_others_val)) living_others_val = 0;
	
	

	var sum_living_annualy = Math.round((living_water_val + children_school_fees_val + tuition_fees_val + personal_care_val + living_medicines_val + living_others_val + ((living_food_val + living_clothing_val + living_electricity_val + living_petrol_val + living_other_transport_val + living_cable_val + living_newspaper_magazines_val + living_household_help_val + living_society_charges_val + living_milk_val + living_telephone_val) * 12)));
	

	var sum_living_monthly = Math.round((((living_water_val + children_school_fees_val + tuition_fees_val + personal_care_val + living_medicines_val + living_others_val) / 12) + living_food_val + living_clothing_val + living_electricity_val + living_petrol_val + living_other_transport_val + living_cable_val + living_newspaper_magazines_val + living_household_help_val + living_society_charges_val + living_milk_val + living_telephone_val));
	

	var liv_percent = (sum_living_annualy / annual_income_living) * 100;
	if(isNaN(liv_percent)) liv_percent = 0;
	
	/*
	document.getElementById('living_monthly').innerHTML = sum_living_monthly;
	document.getElementById('living_annualy').innerHTML = sum_living_annualy;
	*/
	
	document.frm_budget.living_monthly.value = format(sum_living_monthly,'currency'); //;sum_living_monthly
	document.frm_budget.living_annualy.value = format(sum_living_annualy,'currency'); //sum_living_annualy;
	

	if(liv_percent > 21){
				document.getElementById('living_percent').innerHTML = "<font color=\"red\">"+Math.round(liv_percent) +"% </font> allocation, <div class=\"red\"><b>You are spending much more than you should. Try to cut costs and save the surplus.</b></div>";			
			}else{
				document.getElementById('living_percent').innerHTML = '<font color=\"blue\">Your allocation is '+ Math.round(liv_percent) +'%</font>';
			}



}


// CALCULATION FUNCTIONS : BUDGET : END



// CALCULATION FUNCTIONS : EPF CONTRIBUTIONS : STARTS


	function calculate_epf(){
	
		
		var user_age = parseInt(document.frm_epf.your_age.value);
			if(isNaN(user_age)) user_age = 0;

		var user_basic_sal = parseInt(document.frm_epf.basic_salary_monthly.value);
			if(isNaN(user_basic_sal)) user_basic_sal = 0;
		
		var user_EPF_contri_perc = parseInt(document.frm_epf.your_contribution.value);
			if(isNaN(user_EPF_contri_perc)) user_EPF_contri_perc = 0;
			
		var employeer_EPF_contri_perc = parseInt(document.frm_epf.employers_contribuion.value);
			if(isNaN(employeer_EPF_contri_perc)) employeer_EPF_contri_perc = 0;
	
		var _exp_annual_raise_perc = parseInt(document.frm_epf.annual_increase_in_salary.value);
			if(isNaN(_exp_annual_raise_perc)) _exp_annual_raise_perc = 0;

		var exp_retirement_age = parseInt(document.frm_epf.intend_to_retire.value);
			if(isNaN(exp_retirement_age)) exp_retirement_age = 0;

		var EPF_interest_rate_perc = parseInt(document.frm_epf.current_interest_rate.value);
			if(isNaN(EPF_interest_rate_perc)) EPF_interest_rate_perc = 0;
		
		var past_EPF_balanace = parseInt(document.frm_epf.current_epf_balance.value);
			if(isNaN(past_EPF_balanace)) past_EPF_balanace = 0;
		


		var rem_work_years = exp_retirement_age - user_age;
		var user_basic_sal_annual = user_basic_sal * 12;											// Basic salary


		for(y=1; y<=rem_work_years; y++)
		{	
			// NO raise or hike in 1st year
			if(y ==1 ) { var exp_annual_raise_perc = 0; } else { var exp_annual_raise_perc = _exp_annual_raise_perc; }
			
			var inc_user_basic_sal_annual = (user_basic_sal_annual / 100) * exp_annual_raise_perc;		// annual increment
			var inc_user_basic_sal_annual_total = user_basic_sal_annual + inc_user_basic_sal_annual;	// annualy increment salary

			var annual_user_EPF_contri = (inc_user_basic_sal_annual_total * user_EPF_contri_perc) / 100;			// your ePF for the current year
			var annual_employeer_EPF_contri = (inc_user_basic_sal_annual_total * employeer_EPF_contri_perc) / 100;	// employers ePF contribution for the current year

			var annual_EPF_total = annual_user_EPF_contri + annual_employeer_EPF_contri;				// annual ePF collection

				if(y == 1) {
					// balance funds for 1st year (if no, past ePF balance)
					var balance_funds = annual_EPF_total + ((annual_EPF_total/100) * EPF_interest_rate_perc);
					
					if(past_EPF_balanace > 0 && past_EPF_balanace != "")
					// balance funds for 1st year (if it has past ePF balance)
						var balance_funds = annual_EPF_total + past_EPF_balanace + (((annual_EPF_total + balance_funds) / 100) * EPF_interest_rate_perc);
				}
				else {
					// balance funds for rest of the years
					var balance_funds = annual_EPF_total + last_balance_funds + (((annual_EPF_total + balance_funds) / 100) * EPF_interest_rate_perc);
				}

			var last_balance_funds = balance_funds;
			var annual_EPF_total_interest = (annual_EPF_total / 100) * EPF_interest_rate_perc;			// ePF interest

			
			var user_basic_sal_annual = inc_user_basic_sal_annual_total;
			
			

		} // end of loop

		
		if(rem_work_years == "" || rem_work_years == "0"){
					document.getElementById('result_epf').innerHTML = '<table bgColor=\"#E5E5E5\" height=\"100\" width=\"100%\" border=\"0\" align=\"center\" cellpadding=\"2\" cellspacing=\"0\"><tr><td align=\"center\">Please putin retire age correctly.</b></td></tr></table>';
			}else{
					/*
						<table bgColor=\"#E5E5E5\" height=\"100\" width=\"100%\" border=\"0\" align=\"center\" cellpadding=\"2\" cellspacing=\"0\"><tr><td align=\"center\">Your total EPF on retirement : <b>Rs.'+ Math.round(balance_funds) +'/-</td></tr></table>
					*/
					document.getElementById('result_epf').innerHTML = '<span style=\"color:#2D3C63; font: bold 18px/20px arial;\">You will have accumulated <br /><span  style=\"color:#ff6600;\">Rs '+ format(Math.round(balance_funds),'currency') +'</span> by the time you retire.</span>';
			
			}

	} //eof function calculate_epf()





// CALCULATION FUNCTIONS : EPF CONTRIBUTIONS : END


// CALCULATION FUNCTIONS : HOW TO BE CROREPATI : START


function calculate_crorepati(){

		var current_user_age = parseInt(document.frm_crorepati.current_age.value);
			if(isNaN(current_user_age)) age = 0;

		var crorepati_by_age = parseInt(document.frm_crorepati.crorepati.value);
			if(isNaN(crorepati_by_age)) crorepati_by_age = 0;
		
		var previous_invest_value = parseInt(document.frm_crorepati.amount_invested.value);
			if(isNaN(previous_invest_value)) previous_invest_value = 0;
			
		var amount_you_can_save_value = parseInt(document.frm_crorepati.amount_you_can_save.value);
			if(isNaN(amount_you_can_save_value)) amount_you_can_save_value = 0;

		var rate_of_interest_on_savings = parseInt(document.frm_crorepati.rate_savings.value);
			if(isNaN(rate_of_interest_on_savings)) rate_of_interest_on_savings = 0;
	
		var tax_bracket_percent = parseInt(document.frm_crorepati.tax_bracket.value);
			if(isNaN(tax_bracket_percent)) tax_bracket_percent = 0;

		//var inflation_percent = parseInt(document.frm_crorepati.inflation.value);
		//	if(isNaN(inflation_percent)) inflation_percent = 0;
		var inflation_percent = 0;
		
		var return_less_of_taxes_percent = (rate_of_interest_on_savings - (rate_of_interest_on_savings * tax_bracket_percent)/100);
		//var return_less_of_taxes_percent = 0; 
		//alert(return_less_of_taxes_percent);
		//var return_less_of_inflation_percent = (return_less_of_taxes_percent) - (inflation_percent);
		//var return_less_of_inflation_percent = 1.60;
		
		var return_less_of_inflation_percent = ((((1 + return_less_of_taxes_percent/100) /(1 + inflation_percent/100)) - 1) * 100); //alert(return_less_of_inflation_percent);
		//var return_less_of_inflation_percent = 0;


		var age_differences_crorepati = crorepati_by_age - current_user_age;
		

		var annual_investment = amount_you_can_save_value * 12;	

		//document.write("<table border=\"1\">");
		for(y = 1; y <= age_differences_crorepati; y++){
			
			if(y == 1){
				var investment_return = ((annual_investment + previous_invest_value) * return_less_of_inflation_percent)/100;
				var investment_return_interest = annual_investment + investment_return + previous_invest_value;
				var total_return = investment_return_interest;
				
			}else{
				
				var total_return = Math.round((((total_return + annual_investment) * return_less_of_inflation_percent)/100) + total_return + annual_investment);

			}
			
		}	//eof for loop


	
	var amount_return_on_maturity = total_return;
		
		var one_crore = 10000000;

		var amount_you_can_save_monthly = amount_you_can_save_value;
	
		while(total_return <= one_crore){

			var total_difference = one_crore - total_return;
			var annual_investment = amount_you_can_save_monthly * 12;	
			
			for(j=1;j<= age_differences_crorepati; j++){
				if(j == 1){
				var investment_return = ((annual_investment + previous_invest_value) * return_less_of_inflation_percent)/100;
				var investment_return_interest = annual_investment + investment_return + previous_invest_value;
				var total_return = investment_return_interest;
				
				}else{
					var total_return = Math.round((((total_return + annual_investment) * return_less_of_inflation_percent)/100) + total_return + annual_investment);
				}
			
			
				// FIND MONTHLY AMOUNT SAVE TO BECOME CROREPATI
				
					amount_you_can_save_monthly = amount_you_can_save_monthly + 1;
				
			
			}
			
		}
/*
<table bgColor=\"#FFFFFF\" height=\"100\" width=\"100%\" border=\"0\" align=\"center\" cellpadding=\"2\" cellspacing=\"0\"><tr><td align=\"center\">If you invest <b>Rs.'+ amount_you_can_save_value +'/-</b> every month, you will have <span  style="color:#ff6600;">Rs. '+ (amount_return_on_maturity) +'</span> amount when you are of age <b>'+ crorepati_by_age +' </b><br><b>/-</b></td></tr><tr><td align=\"center\">If you want to be a crorepati by <b>'+ crorepati_by_age +' </b>, then you must invest <b>Rs. '+ amount_you_can_save_monthly +'/- </b>every month.</td></tr></table>
*/

		if(crorepati_by_age == "" ||crorepati_by_age == "0"){
			document.getElementById('result_crorepati').innerHTML = '<span  style=\"color:#ff6600;\">Please enter reasonable values.</span>';
		}else if(age_differences_crorepati == "0"){
			document.getElementById('result_crorepati').innerHTML = '<span  style=\"color:#ff6600;\">Age by when you want to be crorepati should be more than current age.</span>';
		}else{
			if(amount_return_on_maturity < one_crore){
				document.getElementById('result_crorepati').innerHTML = 'If you have invested Rs ' + previous_invest_value + ' till date and Rs '+ format(amount_you_can_save_value,'currency') +' every month,<br /> you will have <span  style=\"color:#ff6600;\">Rs '+ format(amount_return_on_maturity,'currency') +'</span> by the age of '+ crorepati_by_age +'. If you want<br /> to be a crorepati by the age of '+ crorepati_by_age +', you need to invest<br /> <span  style=\"color:#ff6600;\">Rs '+ format(amount_you_can_save_monthly,'currency')+'</span> every month.</div><div style=\"display:none\">Congrats! By investing Rs '+ format(amount_you_can_save_monthly ,'currency')+' every month,<br /> you will become a crorepati by the age of '+ crorepati_by_age +'. In fact,<br /> you will have a kitty of <span style=\"color:#ff6600;\">Rs </span>. ';
			}
			else if(previous_invest_value < one_crore)
			{
				document.getElementById('result_crorepati').innerHTML = 'If you have invested Rs ' + previous_invest_value + ' till date and Rs. '+ format(amount_you_can_save_value,'currency') +' every month, you will have <span  style=\"color:#ff6600;\">Rs '+ format(amount_return_on_maturity,'currency') +'</span> by the age of '+ crorepati_by_age +'.';
			}
			else{
				//document.getElementById('result_crorepati').innerHTML = '<span  style=\"color:#ff6600;\">If you invest Rs '+ format(amount_you_can_save_value,'currency') +' every month, you will have this amount when you are of age '+ crorepati_by_age +' <br>Rs  '+ format(amount_return_on_maturity,'currency') +'</span>';
				document.getElementById('result_crorepati').innerHTML = '<span  style=\"color:#ff6600;\">Congratulations you are already a crorepati</span>';
			}
		}
	
}


// CALCULATION FUNCTIONS : HOW TO BE CROREPATI : END

// CALCULATION FUNCTIONS : GRATUITY : START

function calulate_total_sal_da(){
	var user_basic_sal = parseInt(document.frm_gratuity.grat_basic_sal.value);
	if(isNaN(user_basic_sal)) user_basic_sal = 0;
	
	var user_da = parseInt(document.frm_gratuity.grat_da.value);
	if(isNaN(user_da)) user_da = 0;
	
	var total = parseInt(user_basic_sal) + parseInt(user_da);
	document.frm_gratuity.grat_total.value = total;

}

function round_off_month(){
	
	var year_in_service = parseInt(document.frm_gratuity.grat_year.value);
	if(isNaN(year_in_service)) year_in_service = 0;
	
	var month = parseInt(document.frm_gratuity.grat_month.value);
	if(isNaN(month)) month = 0;
	
	var total_year = Math.round(year_in_service + ("."+month));
	document.frm_gratuity.grat_rounded_off.value = total_year;

}
function check_yr_in_service(){ 
	if(document.frm_gratuity.grat_year.value < 5)
		{ 
			alert('You must be in service for at least 5 years to be eligible for gratuity'); 
			document.frm_gratuity.grat_year.value = 5;
			document.frm_gratuity.grat_year.focus();
			//document.frm_gratuity.grat_year.select();
			return false;
		}else{
			return true;
		}
}

function calculate_gratuity_pay(){
	
	if(document.frm_gratuity.grat_basic_sal.value=='' || document.frm_gratuity.grat_basic_sal.value=='0'){
		alert("Please enter some value");
		return false;
	}else if(document.frm_gratuity.grat_year.value < 5){
		alert('You must be in service for at least 5 years to be eligible for gratuity'); 
			document.frm_gratuity.grat_year.value = 5;
			document.frm_gratuity.grat_year.focus();
		return false;
	}else{
		
	var user_basic_sal_val = parseInt(document.frm_gratuity.grat_basic_sal.value);
	if(isNaN(user_basic_sal_val)) user_basic_sal_val = 0;
	
	var user_da_val = parseInt(document.frm_gratuity.grat_da.value);
	if(isNaN(user_da_val)) user_da_val = 0;
	
	var total_sal_da = parseInt(user_basic_sal_val) + parseInt(user_da_val); //TOTAL OF SALARY AND DA

	
	var years_in_service = parseInt(document.frm_gratuity.grat_year.value);
	if(isNaN(years_in_service)) years_in_service = 0;
	
	var months = parseInt(document.frm_gratuity.grat_month.value);
	if(isNaN(months)) months = 0;


	
	var total_year_service = Math.round(years_in_service + ("."+months)); // TOTAL YEAR IN SERVICES
	
	var total_gratuity_payable = Math.round(((total_sal_da / 26) * 15) * total_year_service);

	document.getElementById('result_gratuity').innerHTML = 'Total gratuity payable to you is <span  style=\"color:#ff6600;\"><b>Rs '+ format(total_gratuity_payable,'currency'); +'/-</b></span>';


	}
	

}



// CALCULATION FUNCTIONS : GRATUITY : END


// CALCULATION FUNCTIONS : DEBT EVALUATION : START

function calculate_salary_debt_eval(){
		var income_salary = parseInt(document.frm_debt_eval.salary.value);
		if(isNaN(income_salary)) income_salary = 0;

		var income_pension = parseInt(document.frm_debt_eval.pension.value);
		if(isNaN(income_pension)) income_pension = 0;

		var income_rental_income = parseInt(document.frm_debt_eval.rental_income.value);
		if(isNaN(income_rental_income)) income_rental_income = 0;

		var income_interest = parseInt(document.frm_debt_eval.interest.value);
		if(isNaN(income_interest)) income_interest = 0;

		var income_dividends = parseInt(document.frm_debt_eval.dividends.value);
		if(isNaN(income_dividends)) income_dividends = 0;

		var income_others = parseInt(document.frm_debt_eval.salary_others.value);
		if(isNaN(income_others)) income_others = 0;

		var monthly_interest = (income_interest / 12);
		var monthly_dividend = (income_dividends / 12);

		var sum_income_monthly = (income_salary + income_pension + income_rental_income + monthly_interest + monthly_dividend + income_others);
		
		document.frm_debt_eval.salary_monthly.value = Math.round(sum_income_monthly);
		document.frm_debt_eval.salary_monthly.value = format(document.frm_debt_eval.salary_monthly.value,'currency');
		
		document.frm_debt_eval.salary_annualy.value = Math.round((sum_income_monthly) * 12);
		document.frm_debt_eval.salary_annualy.value = format(document.frm_debt_eval.salary_annualy.value,'currency');
		//document.getElementById('salary_monthly').innerHTML = Math.round(sum_income_monthly);
		//document.getElementById('salary_annualy').innerHTML = Math.round((sum_income_monthly) * 12);

}

function calculate_debt_evaluation(){

			var income_salary = parseInt(document.frm_debt_eval.salary.value);
			if(isNaN(income_salary)) income_salary = 0;

			var income_pension = parseInt(document.frm_debt_eval.pension.value);
			if(isNaN(income_pension)) income_pension = 0;

			var income_rental_income = parseInt(document.frm_debt_eval.rental_income.value);
			if(isNaN(income_rental_income)) income_rental_income = 0;

			var income_interest = parseInt(document.frm_debt_eval.interest.value);
			if(isNaN(income_interest)) income_interest = 0;

			var income_dividends = parseInt(document.frm_debt_eval.dividends.value);
			if(isNaN(income_dividends)) income_dividends = 0;

			var income_others = parseInt(document.frm_debt_eval.salary_others.value);
			if(isNaN(income_others)) income_others = 0;

			var monthly_interest = (income_interest / 12);
			var monthly_dividend = (income_dividends / 12);

			var sum_income_annualy = ((income_salary + income_pension + income_rental_income + monthly_interest + monthly_dividend + income_others) * 12);




			var housing_loan_emi = parseInt(document.frm_debt_eval.home_loan_emi.value);
			if(isNaN(housing_loan_emi)) housing_loan_emi = 0;

			var housing_car_loan = parseInt(document.frm_debt_eval.car_loan.value);
			if(isNaN(housing_car_loan)) housing_car_loan = 0;

			var housing_personal_loan = parseInt(document.frm_debt_eval.personal_loan.value);
			if(isNaN(housing_personal_loan)) housing_personal_loan = 0;

			var housing_credit_card = parseInt(document.frm_debt_eval.credit_card.value);
			if(isNaN(housing_credit_card)) housing_credit_card = 0;

			var housing_others_val = parseInt(document.frm_debt_eval.housing_others.value);
			if(isNaN(housing_others_val)) housing_others_val = 0;

			
			var sum_housing_debt_monthly = (housing_loan_emi + housing_car_loan + housing_personal_loan + housing_credit_card + housing_others_val);

			var sum_housing_debt_annualy = (sum_housing_debt_monthly) * 12

			var percent_expense = (sum_housing_debt_annualy / sum_income_annualy) * 100;
			if(isNaN(percent_expense)) percent_expense = 0;

			
			document.frm_debt_eval.housing_monthly.value = Math.round(sum_housing_debt_monthly);
			document.frm_debt_eval.housing_monthly.value = format(document.frm_debt_eval.housing_monthly.value,'currency');

			document.frm_debt_eval.housing_annualy.value = sum_housing_debt_annualy;
			document.frm_debt_eval.housing_annualy.value = format(document.frm_debt_eval.housing_annualy.value,'currency');

			/*
			document.getElementById('housing_monthly').innerHTML = Math.round(sum_housing_debt_monthly);
			document.getElementById('housing_annualy').innerHTML = sum_housing_debt_annualy;
			*/

			if(percent_expense > 30){
				document.getElementById('result_debt_eval').innerHTML = '<span  style=\"color:#ff6600;\"><b>'+Math.round(percent_expense) +'% </b></span>, Your debt outflow is not within the limit of 30%';			
			}else{
				document.getElementById('result_debt_eval').innerHTML = '<span  style=\"color:#ff6600;\"><b>'+ Math.round(percent_expense) +'% - </b></span>, Your debt outflow is within the limit of 30%';
			}
		

}



// CALCULATION FUNCTIONS : DEBT EVALUATION : END


// CALCULATION FUNCTIONS : WHATS IT WORTH TO REDUCE SPENDING : START

function calculate_money_save(){

	var ur_current_age_val = parseInt(document.frm_reduce_spending.ur_current_age.value);
		if(isNaN(ur_current_age_val)) ur_current_age_val = 0;

	var retire_age_val = parseInt(document.frm_reduce_spending.retire_age.value);
		if(isNaN(retire_age_val)) retire_age_val = 0;
	
	var savings_rate_val = parseInt(document.frm_reduce_spending.savings_rate.value);
		if(isNaN(savings_rate_val)) savings_rate_val = 0;
	
	var tax_rate_val = parseInt(document.frm_reduce_spending.tax_rate.value);
		if(isNaN(tax_rate_val)) tax_rate_val = 0;

	var inflation_rate_val = parseInt(document.frm_reduce_spending.inflation_rate.value);
		if(isNaN(inflation_rate_val)) inflation_rate_val = 0;

	var saving_rate_post_tax_percent = savings_rate_val - ((tax_rate_val * savings_rate_val)/100)
	
	var savings_rate_post_inflation_percent = ((((1 + saving_rate_post_tax_percent/100) /(1 + inflation_rate_val/100)) - 1) * 100);
	

	var car_purchase_money_save_val = parseInt(document.frm_reduce_spending.car_purchase_money_save.value);
		if(isNaN(car_purchase_money_save_val)) car_purchase_money_save_val = 0;
	
	var eating_less_money_save_val = parseInt(document.frm_reduce_spending.eating_less_money_save.value);
		if(isNaN(eating_less_money_save_val)) eating_less_money_save_val = 0;
	
	var clothes_money_save_val = parseInt(document.frm_reduce_spending.clothes_money_save.value);
		if(isNaN(clothes_money_save_val)) clothes_money_save_val = 0;
	
	var fewer_holidays_money_save_val = parseInt(document.frm_reduce_spending.fewer_holidays_money_save.value);
		if(isNaN(fewer_holidays_money_save_val)) fewer_holidays_money_save_val = 0;

	var public_transport_money_save_val = parseInt(document.frm_reduce_spending.public_transport_money_save.value);
		if(isNaN(public_transport_money_save_val)) public_transport_money_save_val = 0;


	var total_money_save = (car_purchase_money_save_val + eating_less_money_save_val + clothes_money_save_val + fewer_holidays_money_save_val + public_transport_money_save_val);
	
	var age_differences = (retire_age_val - ur_current_age_val);

//	document.write("<table border=\"1\">");
	for(i=1;i<=age_differences;i++){

		if(i == 1){
			var total_save = Math.round(total_money_save * ((savings_rate_post_inflation_percent/100) + 1) * 100)/100;
		//document.write("<tr><td>"+i +"</td><td>"+total_money_save +"</td><td>"+total_save +"</td></tr>");
		
		}else{
			
			var	total_save = Math.round(total_save + ((total_save * savings_rate_post_inflation_percent)/100));
		
			//document.write("<tr><td>"+ i +"</td><td>&nbsp;</td><td>"+total_save +"</td></tr>");
			
		}
		
		
	} //end of for

//	document.write("<table>");


	document.getElementById('result_reduce_spending').innerHTML = 'By reducing your spending you will <br>save this amount each year <span  style=\"color:#ff6600;\"><b>Rs '+ format(total_money_save,'currency') +'</b></span><br><br>If you invest this amount, you will<br> accumulate this amount by the time you retire <span  style=\"color:#ff6600;\"><b> Rs '+ format(total_save,'currency') +' </b></span>';	


}





// CALCULATION FUNCTIONS : WHATS IT WORTH TO REDUCE SPENDING : END


// CALCULATION FUNCTIONS : COMMON FUNCTIONS : START

// For checking age less than 18
function check_current_age(cur_age){
	
	var	curr_age_value = document.getElementById(cur_age).value;
	

	//var	curr_age_value = document.forms[formname].elements[cur_age].value;
	
	if(curr_age_value < 18  || curr_age_value ==""){
			document.getElementById(cur_age).value = 18;
			document.getElementById(cur_age).focus();
			document.getElementById(cur_age).select();

	} 
	
}





// CALCULATION FUNCTIONS : COMMON FUNCTIONS : ENDS

//-->