<!--
// 全般の処理
// ローンシミュレーション画面遷移処理
// 引数：押されたボタン
function ch_loan_input() {
	if (!chkval_loan_input()) return false;
	document.getElementById("loan_input").submit();
}

// 借り入れご予定日の初期値をセットする
function set_default_date() {
	if (document.getElementById("set_flg").value == "") {
		var now_date = new Date();
		
		var now_year = now_date.getYear();																	// 年
		var now_month = now_date.getMonth() + 1;															// 月
		var now_day = now_date.getDate();																	// 日
		
		if (now_year < 2000) now_year += 1900;
		
		document.getElementById("borrowing_year").value = now_year;
		document.getElementById("borrowing_month").value = now_month;
		document.getElementById("borrowing_day").value = now_day;
		
		document.getElementById("set_flg").value = "1";
	}
}

// 必須項目と値の入力範囲をチェックする
// ローン計算条件
function chkval_loan_input(){
	var dispstr = "";																					//メッセージ表示文字列
	var errcount = 0;																					//チェックエラーカウント
	var resultflg = false;																				//チェック結果フラグ
	var arremptyitem = new Array();																		//未入力項目名
	var arrngitem = new Array();																		//値が不正な項目
	var checkval;																						//チェック対象の値
	
	
	// 必須項目の未入力チェック
	// カードの種類
	var card_type = document.getElementById("card_type").value;
	checkval = card_type;
	if (checkval == ""){
		arremptyitem.push("[カードの種類]");
		errcount++;
	}
	// 支払方法
	var payment_method = document.getElementById("payment_method").value;
	checkval = payment_method;
	if (checkval == ""){
		arremptyitem.push("[支払方法]");
		errcount++;
	}
	// 融資利率
	var loan_rate = document.getElementById("loan_rate").value;
	checkval = loan_rate;
	if (checkval == ""){
		arremptyitem.push("[融資利率]");
		errcount++;
	}
	// 融資金額
	var loan_amount = document.getElementById("loan_amount").value;
	checkval = loan_amount;
	if (checkval == ""){
		arremptyitem.push("[融資金額]");
		errcount++;
	}
	// 借り入れご予定日(西暦年)
	var borrowing_year = document.getElementById("borrowing_year").value;
	checkval = borrowing_year;
	if (checkval == ""){
		arremptyitem.push("[借り入れご予定日(西暦年)]");
		errcount++;
	}
	// 借り入れご予定日(月)
	var borrowing_month = document.getElementById("borrowing_month").value;
	checkval = borrowing_month;
	if (checkval == ""){
		arremptyitem.push("[借り入れご予定日(月)]");
		errcount++;
	}
	// 借り入れご予定日(日)
	var borrowing_day = document.getElementById("borrowing_day").value;
	checkval = borrowing_day;
	if (checkval == ""){
		arremptyitem.push("[借り入れご予定日(日)]");
		errcount++;
	}
	
	// 未入力項目があった場合
	if (errcount > 0){
		dispstr = "必須項目で未入力の項目があります";
		
		for (index in arremptyitem) {
			dispstr += "\n\n　・" + arremptyitem[index];
		}
		window.alert(dispstr);
		
		return resultflg;
	}
	
	// 正しい値が入力されているかどうかのチェック
	// 数値で入力されていない場合はエラー
	// 融資利率
	if (isNaN(loan_rate)) {
		arrngitem.push("融資利率は数値で入力してください");
		errcount++;
	}
	// 融資金額
	if (isNaN(loan_amount)) {
		arrngitem.push("融資金額は数値で入力してください");
		errcount++;
	} else {
		var loan_amount_num = loan_amount - 0;
		// カードの種類によって入力できる金額の上限が違う
		switch (card_type) {
			// MCカード
			case "1":
				if (loan_amount_num > 200) {
					arrngitem.push("融資金額は200万円までです");
					errcount++;
				}
				break;
			// MC Assist CARD
			case "2":
				if (loan_amount_num > 50) {
					arrngitem.push("融資金額は50万円までです");
					errcount++;
				}
				break;
		}
	}
	// 借り入れご予定日(西暦年)
	if (isNaN(borrowing_year)) {
		arrngitem.push("借り入れご予定日(西暦年)は数値で入力してください");
		errcount++;
	}
	// 借り入れご予定日(月)
	if (isNaN(borrowing_month)) {
		arrngitem.push("借り入れご予定日(月)は数値で入力してください");
		errcount++;
	}
	// 借り入れご予定日(日)
	if (isNaN(borrowing_day)) {
		arrngitem.push("借り入れご予定日(日)は数値で入力してください");
		errcount++;
	}
	// 借り入れご予定日
	if (!check_date(borrowing_month, borrowing_day, borrowing_year)) {
		arrngitem.push("借り入れご予定日を正しく入力してください");
		errcount++;
	}
	
	// 入力エラー項目があった場合
	if (errcount > 0){
		dispstr = "入力エラーの項目があります";
		
		for (index in arrngitem) {
			dispstr += "\n\n　・" + arrngitem[index];
		}
		window.alert(dispstr);
		
		return resultflg;
	}
	
	resultflg = true;
	
	return resultflg;
}

// ローンシミュレーション結果画面の詳細部分を表示する
// 引数：なし
function show_details() {
	document.getElementById("result_details_span").style.display = "block";
	document.getElementById("button_details").style.display = "none";
}

// 指定された日付が正しい日付かどうかをチェックする
// 引数：(I)月, (I)日, (I)年
function check_date(month, day, year) {
	// 数値で入力されていない場合はエラー
	if (isNaN(month) || isNaN(day) || isNaN(year)) {
		return false;
	}
	
	month = Number(month);
	day = Number(day);
	year = Number(year);
	
	// 月が1～12の範囲かどうか
	if (month < 1 || month > 12) {
		return false;
	}
	
	// 月末日を求める
	var endday = 0;
	switch (month) {
		case 1:
		case 3:
		case 5:
		case 7:
		case 8:
		case 10:
		case 12:
			endday = 31;
			break;
		case 4:
		case 6:
		case 9:
		case 11:
			endday = 30;
			break;
		case 2:
			// うるう年の判定
			if (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)) {
				endday = 29;
			} else {
				endday = 28;
			}
			break;
	}
	
	// 日が1～月末日の範囲かどうか
	if (day < 1 || day > endday) {
		return false;
	}
	
	return true;
}
// -->

