function calc(){
    if (!(Acheck() && Bcheck() && Icheck())){
    return;
    }

    var De = document.hensai.DEBT.value * 10000;		//借入金額
    var Yp = document.hensai.YYpay.value * 10000;		//ボーナス返済額
    var Rr = document.hensai.Rate.value / 100;			//借入利率
    var Rz = document.hensai.Rate.value;				//借入利率(%)
    var Yy = document.hensai.YY.value;			//借入年数
   // var Mm = document.hensai.MM.selectedIndex;			//借入月数
   	var Mm = 0;
    var Np = Math.floor(Yy * 12 + Mm);					//返済回数
    var Hr = 0											//
    var Nn = Math.floor(Np);							//	
    var Bn = Math.floor(Nn / 6);						//
    var Mk = De - Yp;	
    var Pm = Math.floor((Mk * Rr / 12 * Math.pow((1 + Rr /12),Nn))/(Math.pow((1 + Rr / 12),Nn)-1));	
    var Pb = Math.floor((Yp * Rr / 2 * Math.pow((1 + Rr /2),Bn))/(Math.pow((1 + Rr / 2),Bn)-1));	
    var Py = Pm * 12 + Pb * 2;							//年間返済額
    var All = (Pm * Nn + Pb * Bn) / 10000;				//総返済額（万円）
    if (Yp == 0){var Bnk = 0;}
    else {var Bnk = Bn;}

	
    //document.hensai.AmountM1.value = Math.floor(De / 10000);
    //document.hensai.AmountM2.value = Math.floor(Yp / 10000);
    //document.hensai.AmountM3.value =(Rz);	
    //document.hensai.AmountM5.value = Math.floor(Np);
    document.hensai.AmountM.value = Math.floor(Pm);
    document.hensai.AmountB.value = Math.floor(Pb);
	
    //document.hensai.Nos.value = Math.floor(Nn);	
    //document.hensai.NosB.value = Math.floor(Bnk);
	
	//document.hensai.All.value = Math.floor(All);

}

function ClearIP(){
    document.hensai.DEBT.value = "";
    document.hensai.YYpay.value = "";
    document.hensai.Rate.value = "";
    document.hensai.MM.selectedIndex = 0;
    document.hensai.YY.selectedIndex = 0;
    document.hensai.DEBT.focus();
}

function ClearOP(){
    document.hensai.AmountM.value = "";
    document.hensai.AmountB.value = "";
    document.hensai.Nos.value = "";
    document.hensai.NosB.value = "";
	document.hensai.all.value = "";
}

function NumCheck(n){
    var i = 0;
    for (i = 0; i < n.length; i++){
        var s = n.substring(i, i + 1);
        if (s == "0"  ||  s == "1" ||  s == "2" || s == "3" || s == "4" || s == "5" || s == "6" || s == "7" || s == "8" || s == "9" || s == "."){
            continue;
        }
        else{
            return false;
        }
    }
    return true;
}

function Acheck(){
    var gankin = document.hensai.DEBT.value;
    if (gankin == ""){
        alert("借入金額を入力してください");
        document.hensai.DEBT.focus();
        return false;
    }

    if (!NumCheck(gankin) || gankin < 1 || gankin > 99999){
        alert("借入金額には1〜99999までの整数を入力してください");
        document.hensai.DEBT.focus();
        return false;
    }
    return true;
}

function Bcheck(){
    var bonus = document.hensai.YYpay.value;
    var gankin = document.hensai.DEBT.value;
    var bg = bonus / gankin;

    if (bonus == ""){
        alert("ボーナス返済元金を入力してください");
        document.hensai.YYpay.focus();
        return false;
    }

    if (bg > 1){
        alert("ボーナス返済元金は借入れ金額より少なくしてください");
        document.hensai.YYpay.focus();
        return false;
    }

    if (!NumCheck(bonus) || bonus < 0 || bonus > 99999){
        alert("ボーナス返済元金には0〜99999までの整数を入力してください");
        document.hensai.YYpay.focus();
        return false;
    }
    return true;
}    

function Icheck(){
    var Rate = document.hensai.Rate.value;
    if (Rate == ""){
        alert("借入利率を選択してください");
        document.hensai.Rate.focus();
        return false;
    }

    if (!NumCheck(Rate) || Rate < 0.001 || Rate > 18.000){
        alert("借入利率は0.001%〜18%の値を入力してください");
        document.hensai.Rate.focus();
        return false;
    }
    return true;
}

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
//-->
