//料金計算メイン関数
function calc() {

	// 設定開始
	// 一時金(入会金)
	var nlc_FST_REGIST_FEE = 3000;
	var oth_FST_REGIST_FEE = 29250;
	// 月額維持費
	var oth_MONTHLYFEE = 6666 + 280;

	nlcPrice = new Array();
	othPrice = new Array();

	var Nwc = "";
	var Sbj = "";
	var Lvl = "";
	var Trm = "";
	var DueOpt = "";
	var GrpOpt = "";

	// 英語レッスン
	nlcPrice['GL01'] = 3500;
	nlcPrice['GL06'] = 2950;
	nlcPrice['GL18'] = 2700;
	nlcPrice['GL36'] = 2500;
	nlcPrice['GL72'] = 2400;

	// 英会話
	nlcPrice['GC01'] = 3200;
	nlcPrice['GC06'] = 2650;
	nlcPrice['GC18'] = 2400;
	nlcPrice['GC36'] = 2200;
	nlcPrice['GC72'] = 2100;

	// ビジネス英語レッスン
	nlcPrice['BL01'] = 4900;
	nlcPrice['BL06'] = 4130;
	nlcPrice['BL18'] = 3780;
	nlcPrice['BL36'] = 3500;
	nlcPrice['BL72'] = 3360;

	// ビジネス英会話
	nlcPrice['BC01'] = 4480;
	nlcPrice['BC06'] = 3710;
	nlcPrice['BC18'] = 3360;
	nlcPrice['BC36'] = 3080;
	nlcPrice['BC72'] = 2940;

///////////////////////////////////////////////////////
	//レッスン+一般英語+プライベート
	othPrice['GLP01'] = 13000;
	othPrice['GLP06'] = 11700;
	othPrice['GLP18'] = 11057;
	othPrice['GLP36'] = 10341;
	othPrice['GLP72'] = 9691;

	//レッスン+一般英語+セミプライベート
	othPrice['GLS01'] = 6800;
	othPrice['GLS06'] = 5700;
	othPrice['GLS18'] = 5265;
	othPrice['GLS36'] = 4961;
	othPrice['GLS72'] = 4681;

	//レッスン+ビジ英語+プライベート
	othPrice['BLP01'] = 16110;
	othPrice['BLP06'] = 15210;
	othPrice['BLP18'] = 14373;
	othPrice['BLP36'] = 13443;
	othPrice['BLP72'] = 12643;

	//英会話+一般英語+プライベート
	othPrice['GCP01'] = 13000;
	othPrice['GCP06'] = 11700;
	othPrice['GCP18'] = 11057;
	othPrice['GCP36'] = 10341;
	othPrice['GCP72'] = 9741;

	//英会話+一般英語+セミプライベート
	othPrice['GCS01'] = 6800;
	othPrice['GCS06'] = 5700;
	othPrice['GCS18'] = 5265;
	othPrice['GCS36'] = 4961;
	othPrice['GCS72'] = 4681;

	//英会話+ビジ英語+プライベート
	othPrice['BCP01'] = 16110;
	othPrice['BCP06'] = 15210;
	othPrice['BCP18'] = 14373;
	othPrice['BCP36'] = 13443;
	othPrice['BCP72'] = 12643;


///////////////////////////////////////////////////////
	Nwc = getValue(document.getElementById("calcform").nwc);
	Sbj = getValue(document.getElementById("calcform").sbj);
	Lvl = getValue(document.getElementById("calcform").level);
	Trm = getValue(document.getElementById("calcform").term);
	DueOpt = getValue(document.getElementById("calcform").due);
	GrpOpt = getValue(document.getElementById("calcform").form);

	//ビジネス+グループオプションチェック
	if ((Lvl == "B") && (GrpOpt == "S")) {
		alert("ビジネス英語/英会話レッスンは、マンツーマンのみ選択可能です。\n※ペアレッスン割引オプションは、選択出来ません。");
		document.getElementById("calcform").form[0].checked = true;
		Custom.clear();
		GrpOpt = "P";
	}

	//1回+有効期限オプション
	if ((Trm == "01") && (DueOpt == "Y")) {
		alert("レッスンお試し(1回)の場合は、有効期限割引オプションが適用されません。");
		document.getElementById("calcform").due[0].checked = true;
		Custom.clear();
		DueOpt = "N";
	}

	var nlcCRS = Lvl + Sbj + Trm;
	var othCRS = Lvl + Sbj + GrpOpt + Trm;
	OPT = DueOpt + GrpOpt;

	var nlcHrPrice = nlcPrice[nlcCRS];
	var othHrPrice = othPrice[othCRS];
	var nlcAdPrice = 0;
	var othAdPrice = 0;

	// Discounts
	if (OPT == "NP") {
		// No discount
		nlcHrPrice = nlcHrPrice;

	} else if (OPT == "YP") {
		// Due opt (10% discount)
		nlcHrPrice = nlcHrPrice * 0.90;

	} else if (OPT == "NS") {
		// Semi opt (20% discount)
		nlcHrPrice = nlcHrPrice * 0.75;

	} else if (OPT == "YS") {
		// Due + Semi opts (30% discount)
		nlcHrPrice = nlcHrPrice * 0.65;

	} else {
		nlcHrPrice = "N/A";
	}

	// Ope fee
	if (Nwc == "N") {
		// New (+ 3,000yen)
		nlcAdPrice = nlc_FST_REGIST_FEE;
		othAdPrice = oth_FST_REGIST_FEE;

	} else if (Nwc == "_") {
		// Not new
		nlcAdPrice = 0;
		othAdPrice = 0;

	} else {
		nlcAdPrice = "N/A";
		othAdPrice = "N/A";
	}

	// Other companies' price
	othAdPrice += oth_MONTHLYFEE * (Number(Trm) / 3);

	document.getElementById("nlc_pricelesson").value = addFigure(nlcHrPrice * 2);
	document.getElementById("nlc_pricehour").value = addFigure(nlcHrPrice);
	document.getElementById("nlc_othfee").value = addFigure(nlcAdPrice);
	document.getElementById("nlc_priceregist").value = addFigure((nlcHrPrice * 2 * Number(Trm)) + nlcAdPrice);

	document.getElementById("oth_pricelesson").value = addFigure(othHrPrice * (2/3));
	document.getElementById("oth_pricehour").value = addFigure(othHrPrice);
	document.getElementById("oth_othfee").value = addFigure(othAdPrice);
	document.getElementById("oth_priceregist").value = addFigure((othHrPrice * 2 * Number(Trm)) + othAdPrice);

	document.getElementById("off_priceregist").value = addFigure((((othHrPrice * 2 * Number(Trm)) + othAdPrice)-((nlcHrPrice * 2 * Number(Trm)) + nlcAdPrice))/((othHrPrice * 2 * Number(Trm)) + othAdPrice) * 100) + "%";
}

//計算値クリアサブ関数
function clr() {
	document.getElementById("calcform").nwc[0].checked = true;
	document.getElementById("calcform").sbj[0].checked = true;
	document.getElementById("calcform").level[0].checked = true;
	document.getElementById("calcform").term[0].checked = true;
	document.getElementById("calcform").due[0].checked = true;
	document.getElementById("calcform").form[0].checked = true;

	document.getElementById("nlc_pricelesson").value = 0;
	document.getElementById("nlc_pricehour").value = 0;
	document.getElementById("nlc_othfee").value = 0;
	document.getElementById("nlc_priceregist").value = 0;

	document.getElementById("off_priceregist").value = "";

	document.getElementById("oth_pricelesson").value = 0;
	document.getElementById("oth_pricehour").value = 0;
	document.getElementById("oth_othfee").value = 0;
	document.getElementById("oth_priceregist").value = 0;

	window.location.reload();
}

//選択値取得サブ関数
function getValue(radioButtons) {
	var value;

	for( var i = 0; i < radioButtons.length; i++ ) {
		if( radioButtons[i].checked ) {
			value = radioButtons[i].value;
			break;
		}
	}

	return value;
}

//カンマ区切りサブ関数
function addFigure(str) {
	var num = new String(Math.floor(str)).replace(/,/g, "");
	while(num != (num = num.replace(/^(-?\d+)(\d{3})/, "$1,$2")));
	return num;
}


