// JavaScript Document

var obj = {
	flag:{ id:"flag", boxID:"flag_box1" },
	btn_submit:{ id:"btn_submit", boxID:"btn_submit" },
	res:{ id:"res", boxID:"res" },
	res2:{id:"res2",boxID:"res2"},
	money:{id:"money",boxID:"money"}
};

//---のぼり
//[色][枚数]
//色　0:1C 1:2C 2:3C 3:4C 4:FC
//枚数　0:1枚 1:5枚 2:10枚 3:15枚 4:20枚 5:25枚 6:30枚 7:35枚 8:40枚 9:45枚 10:50枚 11:55枚 12:60枚 13:65枚 14:70枚 15:75枚 16:80枚 17:85枚 18:90枚 19:95枚 20:100枚

//テトロンポンジ(通常)
var nobori_60_list = new Array(5);
var nobori_45_list = new Array(5);

nobori_45_list[0] = new Array(4875,3570,2517,2142,1767,1580,1392,1311,1229,1155,1081,1051,1020,990,959,928,897,867,836,799,762);
nobori_45_list[1] = new Array(4875,4770,2947,2486,2025,1795,1564,1464,1363,1269,1174,1149,1124,1099,1073,1048,1022,997,971,930,888);
nobori_45_list[2] = new Array(4875,5985,3578,2974,2370,2097,1824,1709,1593,1478,1362,1333,1304,1275,1245,1216,1187,1158,1128,1071,1014);
nobori_45_list[3] = new Array(4875,7170,3945,3288,2630,2313,1996,1862,1728,1595,1461,1438,1415,1395,1368,1345,1322,1299,1275,1208,1140);
nobori_45_list[4] = new Array(4875,3150,2850,2785,2720,2640,2560,2480,2400,2360,2320,2246,2172,2098,2024,1950,1876,1802,1728,1654,1580);

nobori_60_list[0] = new Array(5680,3957,2629,2284,1939,1752,1564,1465,1365,1271,1177,1150,1122,1095,1067,1039,1011,984,956,927,897);
nobori_60_list[1] = new Array(5680,5157,3072,2635,2198,1968,1737,1626,1515,1397,1278,1255,1232,1209,1185,1162,1139,1116,1092,1069,1045);
nobori_60_list[2] = new Array(5680,6357,3675,3109,2542,2269,1996,1838,1680,1570,1459,1433,1407,1381,1355,1329,1302,1276,1250,1222,1194);
nobori_60_list[3] = new Array(5680,7557,4192,3497,2802,2486,2169,2000,1830,1694,1558,1537,1515,1494,1472,1450,1428,1407,1386,1364,1342);
nobori_60_list[4] = new Array(5680,3750,3300,3225,3150,3098,3045,2940,2835,2678,2520,2466,2412,2358,2304,2250,2196,2142,2088,2034,1980);


//JET便ポンジ
var jet_60_list = new Array(5);
var jet_45_list = new Array(5);

jet_45_list[0] = new Array(5363,4284,2769,2356,1944,1738,1531,1442,1352,1271,1189,1156,1122,1089,1055,1021,987,954,920,879,838);
jet_45_list[1] = new Array(5363,5724,3242,2735,2228,1975,1720,1610,1499,1396,1291,1264,1236,1209,1180,1153,1124,1097,1068,1023,977);
jet_45_list[2] = new Array(5363,7182,3936,3271,2607,2307,2006,1880,1752,1626,1498,1466,1434,1403,1370,1338,1306,1274,1241,1178,1115);
jet_45_list[3] = new Array(5363,8604,4340,3617,2893,2544,2196,2048,1901,1755,1607,1582,1557,1535,1505,1480,1454,1429,1403,1329,1254);
jet_45_list[4] = new Array(5363,3465,3135,3064,2992,2904,2816,2728,2640,2596,2552,2471,2389,2308,2226,2145,2064,1982,1901,1819,1738);

jet_60_list[0] = new Array(6248,4353,2892,2512,2133,1927,1720,1612,1502,1398,1295,1265,1234,1205,1174,1143,1112,1082,1052,1020,987);
jet_60_list[1] = new Array(6248,5673,3379,2899,2418,2165,1911,1789,1667,1537,1406,1381,1355,1330,1304,1278,1253,1228,1201,1176,1150);
jet_60_list[2] = new Array(6248,6993,4043,3420,2796,2496,2196,2022,1848,1727,1605,1576,1548,1519,1491,1462,1432,1404,1375,1344,1313);
jet_60_list[3] = new Array(6248,8313,4611,3847,3082,2735,2386,2200,2013,1863,1714,1691,1667,1643,1619,1595,1571,1548,1525,1500,1476);
jet_60_list[4] = new Array(6248,4125,3630,3548,3465,3408,3350,3235,3119,2946,2773,2714,2654,2595,2535,2476,2416,2357,2297,2337,2376);


//エコポンジ
var eco_60_list = new Array(5);
var eco_45_list = new Array(5);

eco_45_list[0] = new Array(5850,4284,3020,2570,2120,1896,1670,1573,1475,1386,1297,1261,1224,1188,1151,1114,1076,1040,1003,959,914);
eco_45_list[1] = new Array(5850,5724,3536,2983,2430,2154,1877,1757,1636,1523,1409,1379,1349,1319,1288,1258,1226,1196,1165,1116,1066);
eco_45_list[2] = new Array(5850,7182,4294,3569,2844,2516,2189,2051,1912,1774,1634,1600,1565,1530,1494,1459,1424,1390,1354,1285,1217);
eco_45_list[3] = new Array(5850,8604,4734,3946,3156,2776,2395,2234,2074,1914,1753,1726,1698,1674,1642,1614,1586,1559,1530,1450,1368);
eco_45_list[4] = new Array(5850,3780,3420,3342,3264,3168,3072,2976,2880,2832,2784,2695,2606,2518,2429,2340,2251,2162,2074,1985,1896);

eco_60_list[0] = new Array(6816,4748,3155,2741,2327,2102,1877,1758,1638,1525,1412,1380,1346,1314,1280,1247,1213,1181,1147,1112,1076);
eco_60_list[1] = new Array(6816,6188,3686,3162,2638,2362,2084,1951,1818,1676,1534,1506,1478,1451,1422,1394,1367,1339,1310,1283,1254);
eco_60_list[2] = new Array(6816,7628,4410,3731,3050,2723,2395,2206,2016,1884,1751,1720,1688,1657,1626,1595,1562,1531,1500,1466,1433);
eco_60_list[3] = new Array(6816,9068,5030,4196,3362,2983,2603,2400,2196,2033,1870,1844,1818,1793,1766,1740,1714,1688,1663,1637,1610);
eco_60_list[4] = new Array(6816,4500,3960,3870,3780,3713,3645,3524,3402,3214,3024,2959,2894,2830,2765,2700,2635,2570,2506,2441,2376);


function check(){
	var mess = "";
		size = document.f_name.n_size.value;
		if(size == ""){
			mess = "サイズを選択してください。\n";
		}
		color = document.f_name.n_color.value;
		if(color == ""){
			mess += "色を選択してください。\n";
		}
		num = document.f_name.n_num.value;
		if(num == ""){
			mess += "枚数を選択してください。\n";
		}
	return mess;
}

function calc(){
	var type = document.f_name.type.value;
	var base_price = 0;
	var price = 0;
	//のぼり項目
	var nobori_list = "";
	var jet_list = "";
	var eco_list = "";
	var size = 0;//サイズ　1:450*1800 0:600*1800
	var color = 0;//色　0:1C 1:2C 2:3C 3:4C 4:FC
	var num = 0;//枚数　0:1枚 1:5枚 2:10枚 3:15枚 4:20枚 5:25枚 6:30枚 7:35枚 8:40枚 9:45枚 10:50枚 11:55枚 12:60枚 13:65枚 14:70枚 15:75枚 16:80枚 17:85枚 18:90枚 19:95枚 20:100枚

	size = document.f_name.n_size.value;
	color = document.f_name.n_color.value;
	num = document.f_name.n_num.value;
	if(type == "nobori"){
		if(size == 0){
			nobori_list = nobori_60_list;
		}
		else if(size == 1){
			nobori_list = nobori_45_list;
		}
		base_price = nobori_list[color][num];
	}
	else if(type == "jet"){
		if(size == 0){
			jet_list = jet_60_list;
		}
		else if(size == 1){
			jet_list = jet_45_list;
		}
		base_price = jet_list[color][num];
	}
	else if(type == "eco"){
		if(size == 0){
			eco_list = eco_60_list;
		}
		else if(size == 1){
			eco_list = eco_45_list;
		}
		base_price = eco_list[color][num];
	}
	price = base_price;	
	return price;
}

/*
function TypeSelect(type){
	allNone();
	DispBox(obj[type.value].boxID,true);
	DispBox('btn_submit',true);
	DispBox('res',false);
}
*/

function BtnSubmit(){
	var res_obj = document.getElementById("res");
	var res2_obj = document.getElementById("res2");
	var money_obj = document.getElementById("money");
	var err = check();
	if(err != ""){
		alert(err);
	}else{
		var p = calc();
		var n = document.f_name.n_num.value;
		r_num = (n * 5)
		
		if(r_num == 0){
			r_num = 1;
		}
		var sum = (p * r_num);
		
		ps = insertComma1(p);
		sums = insertComma1(sum);
		if (typeof res_obj.textContent != "undefined") {
			res_obj.textContent = "合計："+ps+"円×"+r_num+"枚＝";
		} else {
			res_obj.innerText = "合計："+ps+"円×"+r_num+"枚＝";
		}
		
		if (typeof res2_obj.textContent != "undefined") {
			res2_obj.textContent = sums;
		} else {
			res2_obj.innerText = sums;
		}
		
		if (typeof money_obj.textContent != "undefined") {
			money_obj.textContent = "円";
		} else {
			money_obj.innerText = "円";
		}
		
		
		DispBox('money',true);
		DispBox('res2',true);
		DispBox('res',true);
	}
}

//カンマ挿入関数
function insertComma1(num) {
	num = String( num );
	while( num != ( num = num.replace( /^(\d+)(\d{3})/ , "$1,$2" ) ) ){}
	return num;
}

function DispBox(boxID,flag){
	bElements = document.getElementById(boxID);
	if(bElements != null){
		disp=(flag)?"block":"none";
		bElements.style.display = disp;
	}	
}

/*
function allNone(){
	for (var i in obj) {
		DispBox(obj[i].boxID,false);
	}
}
*/
