// JavaScript Document

// 初期設定
total_cost = 0;				// 現在の価格

car_basic = new Array();	// 車種ごとの法定費用

car_basic[1] = new Array();
car_basic[1][0] = 18980;	// 軽 自賠責保険
car_basic[1][1] = 7600;		// 軽 重量税
car_basic[1][2] = 1100;		// 軽 印紙代

car_basic[2] = new Array();
car_basic[2][0] = 22470;	// 小型 自賠責保険
car_basic[2][1] = 20000;	// 小型 重量税
car_basic[2][2] = 1100;		// 小型 印紙代

car_basic[3] = new Array();
car_basic[3][0] = 22470;	// 中型 自賠責保険
car_basic[3][1] = 30000;	// 中型 重量税
car_basic[3][2] = 1100;		// 中型 印紙代

car_basic[4] = new Array();
car_basic[4][0] = 22470;	// 大型 自賠責保険
car_basic[4][1] = 40000;	// 大型 重量税
car_basic[4][2] = 1100;		// 大型 印紙代

car_basic[5] = new Array();
car_basic[5][0] = 12250;	// バン・トラック 自賠責保険
car_basic[5][1] = 7600;		// バン・トラック 重量税
car_basic[5][2] = 1100;		// バン・トラック 印紙代

option_price = new Array();		// 車種ごとのオプション費用

option_price[1] = new Array();
option_price[1][0] = 1200;		// 軽 エンジンオイル交換
option_price[1][1] = 1890;		// 軽 オイルエレメント交換
option_price[1][2] = 4200;		// 軽 ブレーキオイル交換
option_price[1][3] = 10290;		// 軽 ブレーキパッド交換
option_price[1][4] = 3150;		// 軽 エアーエレメント交換
option_price[1][5] = 6300;		// 軽 バッテリー交換

option_price[2] = new Array();
option_price[2][0] = 1600;		// 小型 エンジンオイル交換
option_price[2][1] = 2100;		// 小型 オイルエレメント交換
option_price[2][2] = 5250;		// 小型 ブレーキオイル交換
option_price[2][3] = 11865;		// 小型 ブレーキパッド交換
option_price[2][4] = 3675;		// 小型 エアーエレメント交換
option_price[2][5] = 6300;		// 小型 バッテリー交換

option_price[3] = new Array();
option_price[3][0] = 1800;		// 中型 エンジンオイル交換
option_price[3][1] = 2625;		// 中型 オイルエレメント交換
option_price[3][2] = 5250;		// 中型 ブレーキオイル交換
option_price[3][3] = 12390;		// 中型 ブレーキパッド交換
option_price[3][4] = 4200;		// 中型 エアーエレメント交換
option_price[3][5] = 12600;		// 中型 バッテリー交換

option_price[4] = new Array();
option_price[4][0] = 2000;		// 大型 エンジンオイル交換
option_price[4][1] = 3150;		// 大型 オイルエレメント交換
option_price[4][2] = 5250;		// 大型 ブレーキオイル交換
option_price[4][3] = 13440;		// 大型 ブレーキパッド交換
option_price[4][4] = 4200;		// 大型 エアーエレメント交換
option_price[4][5] = 15225;		// 大型 バッテリー交換

option_price[5] = new Array();
option_price[5][0] = 1800;		// バン・トラック エンジンオイル交換
option_price[5][1] = 3675;		// バン・トラック オイルエレメント交換
option_price[5][2] = 5250;		// バン・トラック ブレーキオイル交換
option_price[5][3] = 12390;		// バン・トラック ブレーキパッド交換
option_price[5][4] = 4200;		// バン・トラック エアーエレメント交換
option_price[5][5] = 12600;		// バン・トラック バッテリー交換

discount = new Array();		// 各種割引サービス

discount[0] = 3000;			// マッハ会員割引
discount[1] = 500;			// ステッカー割引
discount[2] = 1500;			// リピーター割引
discount[3] = 500;			// ネット割引
discount[4] = 2500;			// ペア割引

current_type = 0;				// 現在の車種（0:選択無し）

current_option = new Array();	// 選択されたオプション項目
current_option[0] = 0;			// エンジンオイル交換
current_option[1] = 0;			// オイルエレメント交換
current_option[2] = 0;			// ブレーキオイル交換
current_option[3] = 0;			// ブレーキパッド交換
current_option[4] = 0;			// エアーエレメント交換
current_option[5] = 0;			// バッテリー交換

current_discount = new Array();		// 選択された割引項目
current_discount[0] = 0;			// マッハ会員割引
current_discount[1] = 0;			// ステッカー割引
current_discount[2] = 0;			// 安全運転割引
current_discount[3] = 0;			// 早期予約割引
current_discount[4] = 0;			// ペア割引

basic_fee = 0;					// 基本料金
option_fee = 0;					// オプション料金
discount_fee = 0;				// 割引料金

function priceSet()			// 金額をセットする
{
	function formatPrice(fee)
	{
		var temp1 = String(fee).match(/./g).reverse().join("");
		temp1 = temp1.replace(/(\d{3})/g,"$1,");
		temp1 = temp1.match(/./g).reverse().join("").replace(/^,/,"");
		return temp1;
	}
	
	// 車種の画像を変更
	var car01img = 'ryokin_img01' + ((current_type == 1) ? 'a' : '') + '.jpg';
	var car02img = 'ryokin_img02' + ((current_type == 2) ? 'a' : '') + '.jpg';
	var car03img = 'ryokin_img03' + ((current_type == 3) ? 'a' : '') + '.jpg';
	var car04img = 'ryokin_img04' + ((current_type == 4) ? 'a' : '') + '.jpg';
	var car05img = 'ryokin_img05' + ((current_type == 5) ? 'a' : '') + '.jpg';
	document.getElementById('car01').src='images/' + car01img;
	document.getElementById('car02').src='images/' + car02img;
	document.getElementById('car03').src='images/' + car03img;
	document.getElementById('car04').src='images/' + car04img;
	document.getElementById('car05').src='images/' + car05img;
	
	// 車種によって基本料金を変更
	if (current_type > 0) {
		basic_fee = car_basic[current_type][1] + car_basic[current_type][0] + car_basic[current_type][2];
		document.getElementById('zyuryo_zei').innerHTML = '\\' + formatPrice(car_basic[current_type][1]);
		document.getElementById('zibaiseki').innerHTML = '\\' + formatPrice(car_basic[current_type][0]);
		document.getElementById('inshidai').innerHTML = '\\' + formatPrice(car_basic[current_type][2]);
		document.getElementById('houtei_hiyou01').innerHTML = '\\' + formatPrice(basic_fee);
		document.getElementById('houtei_hiyou02').innerHTML = '\\' + formatPrice(basic_fee + 13000);
	}
	
	// オプション料金を計算
	if (current_type > 0) {
		option_fee = 0;
		for (i=0; i<=5; i++) {
			if (current_option[i] == 1) {
				document.getElementById('option'+i+'a').style.display = 'block';
				document.getElementById('option'+i+'b').style.display = 'block';
				document.getElementById('option'+i+'c').innerHTML = '\\' + formatPrice(option_price[current_type][i]);
				option_fee = option_fee + option_price[current_type][i];
			} else {
				document.getElementById('option'+i+'a').style.display = 'none';
				document.getElementById('option'+i+'b').style.display = 'none';
			}
		}
	}
	
	// 割引料金を計算
	if (current_type > 0) {
		discount_fee = 0;
		for (i=0; i<=4; i++) {
			if (current_discount[i] == 1) {
				discount_fee = discount_fee + discount[i];
			}
		}
		if (discount_fee > 0) {
			document.getElementById('discount01').style.display = 'block';
			document.getElementById('discount02').style.display = 'block';
			document.getElementById('discount').innerHTML = '\\' + formatPrice(discount_fee);
		} else {
			document.getElementById('discount01').style.display = 'none';
			document.getElementById('discount02').style.display = 'none';
			document.getElementById('discount').innerHTML = '\\' + formatPrice(0);
		}
	}
	
	// 追加料金を計算・表示
	var additonal_fee = option_fee - discount_fee;
	if (additonal_fee < 0) {
		document.getElementById('option_cost').innerHTML = '△\\' + formatPrice(Math.abs(additonal_fee));
	} else {
		document.getElementById('option_cost').innerHTML = '\\' + formatPrice(additonal_fee);
	}
	
	// 総額を計算・表示
	var total_cost = basic_fee + option_fee - discount_fee + ((current_type > 0) ? 13000 : 0);
	document.getElementById('total_cost').innerHTML = '\\' + formatPrice(total_cost);
}

function CarTypeCall(type)
{
	current_type = type;
	return;
}

function OptionCall(option)
{
	if (current_type > 0) {
		if (current_option[option] == 0) {
			current_option[option] = 1;
			document.getElementById('opt0'+option).src='images/ryokin_img' + ((option < 4) ? '0' : '') + (option + 6) + "a.jpg";
		} else {
			current_option[option] = 0;
			document.getElementById('opt0'+option).src='images/ryokin_img' + ((option < 4) ? '0' : '') + (option + 6) + ".jpg";
		}
		return;
	}
}

function DiscountCall(discount)
{
	if (current_type > 0) {
		if (current_discount[discount] == 0) {
			current_discount[discount] = 1;
			document.getElementById('dis0'+discount).src='images/ryokin_img' + (discount + 12) + "a.jpg";
		} else {
			current_discount[discount] = 0;
			document.getElementById('dis0'+discount).src='images/ryokin_img' + (discount + 12) + ".jpg";
		}
		return;
	}
}

function over(img)
{
	if (img < 6) {
		document.getElementById('car0'+img).src='images/ryokin_img0' + img + "a.jpg";
	}
	return;
}
