// JavaScript Document
function loan(this_form) {
	if(!(kariirecheck(this_form) && ratecheck(this_form) && yearcheck(this_form))) { return; }

	loan_form = this_form.loan_year.selectedIndex;
	loan_year = this_form.loan_year.options[loan_form].value;
	siharaisu = loan_year * 12;

	kinri = this_form.kinri.value;

	kariirekin = this_form.kariirekin.value;

	rn = this_form.boper.selectedIndex;
	boper = this_form.boper.options[rn].value;

	hhh=1;
	lll=1;
	r=(kinri/100)/12;
	k=loan_year * 12;
	rb=(kinri/100)/2;
	kb=loan_year * 2;
	ka=kariirekin * 10000;

	b=boper/100*ka;

	var count=1;
	while( count <= k){ hhh=hhh*(1+r); count++;}
	var count=1;
	while( count <= kb){ lll=lll*(1+rb); count++;}
	payp= ((ka-b)*hhh*r)/(hhh-1);
	payb=(b*lll*rb)/(lll-1);

	if ( payp > 0 ) {
		this_form.paymonth.value = Math.round(payp);
		this_form.paymonth.value = addcomma(this_form.paymonth.value);
	}
	if ( payb > 0 ) {
		this_form.bonusmonth.value = Math.round(payb);
		this_form.bonusmonth.value = addcomma(this_form.bonusmonth.value);
	}
	this_form.total.value = Math.round(((payp * 12 + payb *2) * loan_year));
	this_form.total.value = addcomma(this_form.total.value);
	this_form.nentotal.value = Math.round(payp * 12 + payb *2);
	this_form.nentotal.value = addcomma(this_form.nentotal.value);
}

function addcomma(number) {
	str = "";
	len = number.length;
	for (i=0 ; i<len ; i++ ) {
		if ((len - i) % 3 == 0 && (i != 0)) { 
			comma = ",";
		} else { 
			comma = "";
		}
		str = str + comma + number.charAt(i);
	}
	return str;
}

function kariirecheck(this_form) {
	kariirekin = parseInt(this_form.kariirekin.value);
	if (kariirekin < 0) { return false; }
	return true;
}
function ratecheck(this_form) {
	kinri = parseInt(this_form.kinri.value);
	if (kinri < 0) { return false; }
	return true;
}
function yearcheck(this_form) {
	loan_form = this_form.loan_year.selectedIndex;
	loan_year = parseInt(this_form.loan_year.options[loan_form].value);
	if (loan_year < 0) { return false; }
	return true;
}
function dataclear(this_form) {
	this_form.total.value = "";
	this_form.nentotal.value = "";
	this_form.paymonth.value = "";
	this_form.bonusmonth.value = "";
}
