///////////////////////////////////////////////////////////////////////////////////////////////////
//
// SELECT DESK PRICE
//
///////////////////////////////////////////////////////////////////////////////////////////////////

var type_item = ["メラミン天板","木天板","シナ合板","ガラス天板"]; 

var color_item =[
				["ブラック","ホワイト","レッド","ブラウンウッド","ホワイト(小口ブナ)","ブラウン(小口ブナ)"], //メラミン
				["ピーチ","チーク","パープルウッド","ウォールナット"], //木
				["ホワイト","ブラウン"], //シナ
				["クリア","フロスシート"] //ガラス
				];

var width_item =[
				["～1200mm","1205～1500mm","1505～1600mm","1605～1700mm","1705～1800mm","1805～2000mm"], //メラミン
				["～1200mm","1205～1500mm","1505～1600mm","1605～1700mm","1705～1800mm","1805～2000mm"], //木
				["～1200mm","1205～1500mm","1505～1600mm","1605～1700mm","1705～1800mm","1805～2000mm"], //シナ
				["～1200mm","～1500mm","～1600mm","～1700mm"], //ガラス 10mm
				["～1500mm","～1600mm","～1700mm","～1800mm"]  //ガラス 12mm
				];

var depth_item =[
				["〜450mm","455〜600mm","605〜700mm","705〜800mm","805〜900mm"], //メラミン
				["〜450mm","455〜600mm","605〜700mm","705〜800mm","805〜900mm"],  //木
				["〜450mm","455〜600mm","605〜700mm","705〜800mm","805〜900mm"], //シナ
				["450〜600mm","〜700mm","〜800mm"], //ガラス 10mm
				["600〜700mm","〜800mm"] //ガラス 12mm
				];

var price_list1=[ //メラミン
				[27300, 29400, 31500, 33600, 35700, 47250],
				[29400, 31500, 33600, 35700, 37800, 52500],
				[31500, 33600, 35700, 37800, 39900, 63500],
				[33600, 35700, 37800, 39900, 42000, 65100],
				[35700, 37800, 39900, 42000, 44100, 67200]
				];

var price_list2=[ //木
				[26250, 29400, 31500, 33600, 35700, 63000],
				[34650, 37800, 39900, 42000, 44100, 65100],
				[36750, 39900, 42000, 44100, 46200, 67200],
				[38850, 42000, 44100, 46200, 48300, 69300],
				[40950, 44100, 46200, 48300, 50400, 71400]
				];

var price_list3=[ //シナ
				[26250, 29400, 31500, 33600, 35700, 63000],
				[34650, 37800, 39900, 42000, 44100, 65100],
				[36750, 39900, 42000, 44100, 46200, 67200],
				[38850, 42000, 44100, 46200, 48300, 69300],
				[40950, 44100, 46200, 48300, 50400, 71400]
				];

var price_list4=[ //ガラス クリア 10mm
				[29400, 31500, 33600, 35700],
				[31500, 33600, 35700, 37800],
				[33600, 35700, 37800, 39900]
				];

var price_list5=[ //ガラス クリア 12mm
				[44100, 46200, 48300, 50400],
				[46200, 48300, 50400, 52500]
				];

var price_list6=[ //ガラス フロス 10mm
				[42000, 44100, 46200, 48300],
				[44100, 46200, 48300, 50400],
				[46200, 48300, 50400, 52500]
				];

var price_list7=[ //ガラス フロス 12mm
				[56700, 58800, 60900, 63000],
				[58800, 60900, 63000, 65100]
				];

var price_list =[price_list1, price_list2, price_list3, price_list4, price_list5, price_list6, price_list7]


var type_num = 0; //今選んでるタイプ
var glass_d  = 0; //ガラスの厚み


var img_src	   =[//画像のパス
				['img/desk1.jpg','img/desk2.jpg','img/desk3.jpg','img/desk4.jpg','img/desk5.jpg','img/desk6.jpg'],//メラミン
				['img/desk7.jpg','img/desk8.jpg','img/desk9.jpg','img/desk10.jpg'],//木
				['img/desk11.jpg','img/desk12.jpg'],//シナ
				['img/desk13.jpg','img/desk14.jpg'],//ガラス
				];


///////////////////////////////////////////////////////////////////////////////////////////////////
// リセット

function selectReset(){
	document.deskForm.type.disabled  = false;
	document.deskForm.color.disabled = true;
	document.deskForm.edge.disabled  = true;
	document.deskForm.height.disabled = true;
	document.deskForm.width.disabled = true;
	document.deskForm.depth.disabled = true;
}



///////////////////////////////////////////////////////////////////////////////////////////////////
// タイプを選択

function typeSelect(index){ 
	
	type_num = index;
	//alert(document.deskForm.color.options.length);
	
	//カラーを変更
	
	var d_color = document.deskForm.color.options.length;
	
	for(var i=0; i<d_color; i++){
		document.deskForm.color.options[0] = null;
	};
	for(var i=0; i<color_item[index].length; i++){
		document.deskForm.color.options[i] = new Option(color_item[index][i],color_item[index][i]);
	};
	
	//エッジを変更
	if(index==1){
		document.deskForm.edge.disabled = false;
	}else{
		document.deskForm.edge.disabled = true;
		document.deskForm.edge.options[0].selected = true;
	};	
	
	//厚さを変更
	if(index==3){
		document.deskForm.height.disabled = false;
	}else{
		document.deskForm.height.disabled = true;
		document.deskForm.height.options[0].selected = true;
	};
	
	//幅を変更
	
	var d_width = document.deskForm.width.options.length;
	
	for(var i=0; i<d_width; i++){
		document.deskForm.width.options[0] = null;
	};
	for(var i=0; i<width_item[index].length; i++){
		document.deskForm.width.options[i] = new Option(width_item[index][i],width_item[index][i]);
	};
	
	//奥行を変更
	
	var d_depth = document.deskForm.depth.options.length;
	
	for(var i=0; i<d_depth; i++){
		document.deskForm.depth.options[0] = null;
	};
	for(var i=0; i<depth_item[index].length; i++){
		document.deskForm.depth.options[i] = new Option(depth_item[index][i],depth_item[index][i]);
	};
	
	//数をリセット
	document.deskForm.num.options[0].selected = true;
	
	resetPhoto();
	calPrice();
};


///////////////////////////////////////////////////////////////////////////////////////////////////
// 厚さを選択

function heightSelect(index){
	
	glass_d　= index;
	
	//幅を変更
	var d_width = document.deskForm.width.options.length;
	
	for(var i=0; i<d_width; i++){
		document.deskForm.width.options[0] = null;
	};
	for(var i=0; i<width_item[type_num+index].length; i++){
		document.deskForm.width.options[i] = new Option(width_item[type_num+index][i],width_item[type_num+index][i]);
	};
	
	//奥行を変更
	var d_depth = document.deskForm.depth.options.length;
	
	for(var i=0; i<d_depth; i++){
		document.deskForm.depth.options[0] = null;
	};
	for(var i=0; i<depth_item[type_num+index].length; i++){
		document.deskForm.depth.options[i] = new Option(depth_item[type_num+index][i],depth_item[type_num+index][i]);
	};
	calPrice();
}


///////////////////////////////////////////////////////////////////////////////////////////////////
// カラーを選択
function colorSelect(index){
	if(type_num==3){
	//厚さを変更
	document.deskForm.height.disabled = false;
	document.deskForm.height.options[0].selected = true;
	/*	
	//幅を変更
	var d_width = document.deskForm.width.options.length;
	
	for(var i=0; i<d_width; i++){
		document.deskForm.width.options[i] = null;
	};
	for(var j=0; j<width_item[index].length; j++){
		document.deskForm.width.options[j] = new Option(width_item[index][j],width_item[index][j]);
	};
	
	//奥行を変更
	var d_depth = document.deskForm.depth.options.length;
	
	for(var i=0; i<d_depth; i++){
		document.deskForm.depth.options[i] = null;
	};
	for(var j=0; j<depth_item[index].length; j++){
		document.deskForm.depth.options[j] = new Option(depth_item[index][j],depth_item[index][j]);
	};
	};
	*/
	//幅を変更
	var d_width = document.deskForm.width.options.length;
	
	for(var i=0; i<d_width; i++){
		document.deskForm.width.options[0] = null;
	};
	for(var i=0; i<width_item[type_num+glass_d].length; i++){
		document.deskForm.width.options[i] = new Option(width_item[type_num+glass_d][i],width_item[type_num+glass_d][i]);
	};
	
	//奥行を変更
	var d_depth = document.deskForm.depth.options.length;
	
	for(var i=0; i<d_depth; i++){
		document.deskForm.depth.options[0] = null;
	};
	for(var i=0; i<depth_item[type_num+glass_d].length; i++){
		document.deskForm.depth.options[i] = new Option(depth_item[type_num+glass_d][i],depth_item[type_num+glass_d][i]);
	};
	
	};
	
	calPrice();
	resetPhoto();
}


///////////////////////////////////////////////////////////////////////////////////////////////////
// 幅を選択
function widthSelect(index){
	calPrice();
}


///////////////////////////////////////////////////////////////////////////////////////////////////
// 奥行を選択
function depthSelect(index){
	calPrice();
}


///////////////////////////////////////////////////////////////////////////////////////////////////
// 数を選択
function numSelect(index){
	calPrice();
}


///////////////////////////////////////////////////////////////////////////////////////////////////
// 金額計算

function calPrice(){
	var type_index	 = document.deskForm.type.selectedIndex;  //タイプ
	var color_index  = document.deskForm.color.selectedIndex;//カラー
	var height_index = document.deskForm.height.selectedIndex;//厚み
	var depth_index  = document.deskForm.depth.selectedIndex; //奥行
	var width_index  = document.deskForm.width.selectedIndex; //幅
	var num_index    = document.deskForm.num.selectedIndex+1; //数
	var glass = 0;
	var price = 0;
	
	if(type_index==3){//ガラスの場合
		if(color_index==0){
			if(height_index==0){
				glass = 0;
			}else{
				glass = 1;
			}
		}else{
			if(height_index==0){
				glass = 2;
			}else{
				glass = 3;
			}
		}
	}
	
	//小口ブナはシナ合板と価格が同じ
	if(type_index==0 && color_index==4){
		type_index = 2;
	}else if(type_index==0 && color_index==5){
		type_index = 2;
	}
	
	
	price = (price_list[type_index+glass][depth_index][width_index])*num_index;
	document.deskForm.pricesum.value = price;
	document.getElementById("detail_price").innerHTML = "￥"+addDot(price)+"&nbsp;<span>（taxin）</span>";
}

function addDot(num){
	return (String(num).substr(0,String(num).length-3)+","+String(num).substr(String(num).length-3,3));
}


///////////////////////////////////////////////////////////////////////////////////////////////////
// サイズチェック

function sizeCheck(){
	if(document.deskForm.size.value==""){
		//document.deskForm.size.value="ご希望サイズを入力してください。"
		alert('備考欄へご希望サイズをご入力ください。\n\n例）W1200×D650mm');
		return false;
	}else{
		return true;
	}
}



///////////////////////////////////////////////////////////////////////////////////////////////////
// 画像の切り替え

function swapPhoto(type,color){
	document.photo.src=img_src[type][color];
}

function resetPhoto(){
	var type_index	= document.deskForm.type.selectedIndex;
	var color_index = document.deskForm.color.selectedIndex;
	document.photo.src=img_src[type_index][color_index];
}

