	
	DEBUG_FLG = 0;
	
	OPTION_OBJ_MAX      = 50;  // CONST:オプションオブジェクトの数
	option_list_current = 0;   // オプションオブジェクト使用数http://www.google.com/search?hl=ja&rls=com.microsoft:*:IE-SearchBox&rlz=1I7DAJP&q=javascript+%E3%83%89%E3%83%A1%E3%82%A4%E3%83%B3%E5%90%8D+%E5%8F%96%E5%BE%97&revid=397873232&sa=X&oi=revisions_inline&resnum=0&ct=top-revision&cd=1
	option_list         = new Array(OPTION_OBJ_MAX);
	tmp_opt_hid = "";
	tmp_optmain_r = '';
	tmp_optmain_l = '';
	
	domain_name = "";
	domain_name = document.domain;
	domain_name = domain_name.replace(/www./g,"");
	
//	alert(domain_name);
	
	for(i=0;i<50;i++){
		option_list[i] = new Array();
		option_list[i]['key']   = "";
		option_list[i]['name']  = "";
		option_list[i]['price'] = "";
		option_list[i]['use']   = 0;
	}
	
	tmpl_cook_str = "";
	tmpl_cook_str += "<div id='cook_item_box%%CNUM%%'> <table class='slt_box' cellpadding='o' cellspacing='0'>";
	tmpl_cook_str += "<tr>";
	tmpl_cook_str += "<td class='ttl_slt'>%%ITEM_NAME%%</td>";
	tmpl_cook_str += "<td class='price_slt'>%%ITEM_PRICE%%</td>";
	tmpl_cook_str += "</tr>";

	tmpl_cook_str += "%%TMPL_OPT_STR%%";

	tmpl_cook_str += "<tr>";
	tmpl_cook_str += "<td class='bu_slt'></td>";
	tmpl_cook_str += "<td class='num_slt'>× <input type='text' name='order_num%%CNUM%%' id='order_num%%CNUM%%' size='4' value='%%ORDER_NUM_VAL%%' style='background:#FAFAFA;color:#333;text-align:center' /> 件";
	tmpl_cook_str += "<br/><input src='%%BASE_PATH%%img/bu_opt_ch.jpg' type='image' onclick='ChangeOrderNum(%%CNUM%%);' /><input src='%%BASE_PATH%%img/bu_opt_de.jpg' type='image' style='margin-left:5px' onclick='DeleteEdit(%%CNUM%%);' />";
	tmpl_cook_str += "</td>";
	tmpl_cook_str += "</tr>";
	tmpl_cook_str += "<tr>";
	tmpl_cook_str += "<td class='stotal_slt_l'>小計</td>";
	tmpl_cook_str += "<td class='stotal_slt_r'><div id='total_price%%CNUM%%' name='total_price%%CNUM%%' value='%%ITEM_PRICE_TOTAL%%' >%%ITEM_PRICE_TOTAL%%</div></td>";
	tmpl_cook_str += "</tr>";
	tmpl_cook_str += "</table></div>";
	
	tmpl_opt_str  = "";
	tmpl_opt_str += "<tr>";
	tmpl_opt_str += "<td colspan='2' class='optttl_slt'>オプション</td>";
	tmpl_opt_str += "</tr>";
	tmpl_opt_str += "<tr>";
	tmpl_opt_str += "<td class='sopt_slt_l'>";
	tmpl_opt_str += "<div id='option_list_left_cook%%CNUM%%'>%%LEFT_COOK_VAL%%</div>";
	tmpl_opt_str += "</td>";
	tmpl_opt_str += "<td class='sopt_slt_r'>";
	tmpl_opt_str += "<div id='option_list_right_cook%%CNUM%%'>%%RIGHT_COOK_VAL%%</div>";
	tmpl_opt_str += "</td>";
	tmpl_opt_str += "</tr>";
	tmpl_opt_str += "<tr>";
	tmpl_opt_str += "<td class='sopt_slt_l'></td>";
	tmpl_opt_str += "<td class='sopt_slt_r'>";
	tmpl_opt_str += "<input name='option_del%%CNUM%%' id='option_del%%CNUM%%' onclick='OptionDelete(%%CNUM%%);' src='%%BASE_PATH%%img/bu_opt_de.jpg' type='image' style='margin-left:5px' />";
	tmpl_opt_str += "</td></tr>";
	
	tmpl_opt_str_main   = "";
	tmpl_opt_str_main  += "<tr>";
	tmpl_opt_str_main  += "<td colspan='2' class='optttl_slt'>オプション</td>";
	tmpl_opt_str_main  += "</tr><tr>";
	tmpl_opt_str_main  += "<td class='sopt_slt_l'>";
	tmpl_opt_str_main  += "<div id='option_list_left'></div>";
	tmpl_opt_str_main  += "</td>";
	tmpl_opt_str_main  += "<td class='sopt_slt_r'>";
	tmpl_opt_str_main  += "<div id='option_list_right'></div>";
	tmpl_opt_str_main  += "</td></tr><tr>";
	tmpl_opt_str_main  += "<td class='sopt_slt_l'></td>";
	tmpl_opt_str_main  += "<td class='sopt_slt_r'>";
	tmpl_opt_str_main  += "<input name='option_del' id='option_del' onclick='OptionDelete(-1);' src='http://img/bu_opt_de.jpg' type='image' style='margin-left:5px' />";
	tmpl_opt_str_main  += "</td></tr>";
	
	//************************************************
	//adDelCookie()
	//Cookieの削除
	//************************************************
	function adDelCookie(myCookie){
		document.cookie = myCookie + "=;expires=Fri, 31-Dec-1999 23:59:59 GMT;";
	}
	//************************************************
	//adSetCookie()
	//Cookieの設定
	//************************************************
	function adSetCookie(myCookie,myValue,myDay,domain){
		myDay = 60*60*24;
		myExp = new Date();
		myExp.setTime(myExp.getTime()+(myDay));
		myItem = myCookie + "=" + escape(myValue) + ";" + " domain=" + domain + "; path=/;";
		if(DEBUG_FLG)alert(myItem);
		document.cookie =  myItem;
	}
	//************************************************
	//adGetCookie()
	//Cookieの取得
	//************************************************
	function adGetCookie(myCookie){
		 
	   myCookie = myCookie + "=";
	   myValue = null;
	   myStr = document.cookie + ";" ;
	   myOfst = myStr.indexOf(myCookie);
		 
	   if(myOfst != -1){
	      myStart = myOfst + myCookie.length;
	      myEnd   = myStr.indexOf(";" , myStart);
	      myValue = unescape(myStr.substring(myStart,myEnd));
	   }
	   if(DEBUG_FLG)alert(myValue);
	   return myValue;
	   
	}
	
	//************************************************
	//桁数を揃える
	//************************************************
	function addFigure(str){
		var num = new String(str).replace(/,/g, "");
		while(num != (num = num.replace(/^(-?\d+)(\d{3})/, "$1,$2")));
		return num;
	}
	
	//************************************************
	//idの取得
	//************************************************
	function xGetElementById(e){
		if(typeof(e)=='string') {
			if(document.getElementById) e=document.getElementById(e);
			else if(document.all) e=document.all[e];
			else e=null;
		}
		return e;
	}
	
	//************************************************************
	//関数名：CheckTotalPrice
	//機能　：合計金額をチェックする
	//************************************************************
	function CheckTotalPrice(){
		
		var total_price = 0;
		
		total_price = parseInt(xGetElementById('hid_price').value);
		order_nun   = parseInt(xGetElementById('order_num').value);
		
		if(order_nun<1){
			order_nun = 1;
			xGetElementById('order_num').value = "1";
		}
		
		for(i=0;i<OPTION_OBJ_MAX;i++){
			if(option_list[i]['use']==1){
				total_price += parseInt(option_list[i]['price']);
			}
		}
		return(total_price*order_nun);
	}
	
	//************************************************************
	//関数名：PushOptionStr
	//機能　：オプションオブジェクトを配列に登録
	//************************************************************
	function PushOptionStr(obj,id){
		var end_flg = 0; //終了フラグ
		tmp = obj.value.split("#"); //#で分割
		
		//既にデータがあった場合は上書き
		for(i=0;i<option_list_current;i++){
			if(option_list[i]['sel_name'] == id){ 
				option_list[i]['sel_name']   = id;
				option_list[i]['key']        = tmp[0];
				option_list[i]['name']       = tmp[1];
				option_list[i]['price']      = tmp[2];
				option_list[i]['price_num']  = addFigure(tmp[2]);
				option_list[i]['use']        = 1;
				if(tmp.length<3){	option_list[i]['use'] = 0;}
				end_flg = 1;
				break;
			}
		}
		
		//新規作成の場合
		if(end_flg==0){
			option_list[option_list_current]['sel_name']  = id;
			option_list[option_list_current]['key']       = tmp[0];
			option_list[option_list_current]['name']      = tmp[1];
			option_list[option_list_current]['price']     = tmp[2];
			option_list[option_list_current]['use']       = 1;
			option_list[option_list_current]['price_num'] = addFigure(tmp[2]);
			if(tmp.length<3){option_list[option_list_current]['use'] = 0;}
			option_list_current++;
		}
	}
	
	//************************************************************
	//関数名：InitOptionStr
	//機能　：オプションオブジェクトの中身を全てクリア
	//************************************************************
	function InitOptionStr(){
		for(i=0;i<OPTION_OBJ_MAX;i++){
			option_list[i]['sel_name']   = "";
			option_list[i]['key']        = "";
			option_list[i]['name']       = "";
			option_list[i]['price']      = 0;
			option_list[i]['price_num']  = 0;
			option_list[i]['use']        = 0;
		}
	}
	
	//************************************************************
	//関数名：DeleteOptionCookie
	//機能　：クッキーの中から該当する番号のオプションを削除する。
	//************************************************************
	function DeleteOptionCookie(code){
		cook = adGetCookie("ac_item");
		out = "";
		node = cook.split("]["); //一商品
		icnt = 0;
		for(i=0;i<node.length;i++){
			if(icnt>0)out += "][";
			if(i==code){
				
				xGetElementById("option_list_left_cook"  + i).innerHTML = ""; //表示を消去
				xGetElementById("option_list_right_cook" + i).innerHTML = ""; //表示を消去
				
				
				line = node[i].split("%%");
				jcnt = 0;
				total_change_flg = 0;
				for(j=0;j<line.length;j++){
					if('O'!=line[j].charAt(2)){ //オプションだけ削除
						if(jcnt>0)out += "%%";
						
						//アイテム本体の値段をtotalpriceにする
						if(DEBUG_FLG)alert("once_normail_item");
						once = line[j].split("##");
						total = line[j].split("::");
						if(once.length==3){
							//小計の値を変更
							xGetElementById("total_price" + i).innerHTML = addFigure(once[2]) + "円";
							total_change_flg = 1; 
							total_change_pri = once[2];
							//クッキーの中身も変更するため
							out += line[j];
						}else if(total.length==2){
							if(total_change_flg==1){
								total_change_flg = 0;
								price_all = total_change_pri * total[0];
								xGetElementById("total_price" + i).innerHTML = addFigure(price_all) + "円";
								out += total[0] + "::" + price_all;
							}
						}else{
							out += line[j];
						}
						jcnt++;
						icnt++;
					}else{
						
					}
				}
			}else{
				out += node[i];
				icnt++;
			}
		}
		
		if(DEBUG_FLG)alert("output_end");
		
		
		//--------------------------------------
		//結果をcookieに反映
		adSetCookie("ac_item",out,"",domain_name);
		out2 = adGetCookie("ac_item");
	  if(DEBUG_FLG)alert("out2=" + out2);
	  
	}
	
	//************************************************************
	//関数名：DeleteEditCookie
	//機能　：クッキーの中から該当する商品を削除する
	//************************************************************
	function DeleteEditCookie(code){
		cook = adGetCookie("ac_item");
		out = "";
		node = cook.split("]["); //一商品
		icnt = 0;
		for(i=0;i<node.length;i++){
			if(i==code){
				xGetElementById("cook_item_box"  + i).innerHTML = ""; //表示を消去
			}else{
				if(icnt>0)out += "][";
				out += node[i];
				icnt++;
			}
		}
		// 結果をcookieに反映
		adSetCookie("ac_item",out,"",domain_name);
		out2 = adGetCookie("ac_item");
		if(DEBUG_FLG)alert("out2=" + out2);
		//削除は更新が走るようにする
		location.reload(true);
		
	}
	
	//************************************************************
	//関数名：ChangeOrderNumCookie
	//機能　：クッキー内にある注文数量の変更
	//************************************************************
	function ChangeOrderNumCookie(code){
		
		cook = adGetCookie("ac_item");
		out = "";
		node = cook.split("]["); //一商品
		icnt = 0;
		
		for(i=0;i<node.length;i++){
			if(icnt>0)out += "][";
			if(i==code){
				line = node[i].split("%%");
				jcnt = 0;
				
				for(j=0;j<line.length;j++){
					if(jcnt>0){out+="%%";}
					ansval = line[j].split("::");
					if(ansval.length==2){
						num = xGetElementById("order_num"  + code).value;
						//新しい合計金額
						new_total_price = parseInt(ansval[1]) / parseInt(ansval[0]) * num;
						xGetElementById("total_price" + i).innerHTML = addFigure(new_total_price) + "円";
						
						out += num + "::" + new_total_price;
						jcnt++;
					}else{
						out += line[j];
						jcnt++;
					}
				}
			}else{
				out += node[i];
				icnt++;
			}
		}
		// 結果をcookieに反映
		adSetCookie("ac_item",out,"",domain_name);
		out2 = adGetCookie("ac_item");
		if(DEBUG_FLG)alert("out2=" + out2);
	}
	
	//************************************************************
	//関数名：OptionDelete
	//機能　：オプション入力の削除
	//************************************************************
	function OptionDelete(code){
		if(code==-1){
			InitOptionStr();
			CheckTotalPrice();
			UpdateOptionStr();
		}else{
			//cookieの消去
			DeleteOptionCookie(code); //クッキーの消去
		}
	}
	
	//************************************************************
	//関数名：ChangeOrderNum
	//機能　：注文個数の変更
	//************************************************************
	function ChangeOrderNum(code){
		
		if(code==-1){tmp_num = xGetElementById("order_num").value;}
		else{tmp_num = xGetElementById("order_num" + code).value;}
		
		if(tmp_num.match(/[^0-9]/g)){
			alert("数値以外が含まれています");
		}else if(tmp_num<1 || tmp_num>10000){
			alert("数値が正しくありません");
		}else{
			if(code==-1){
				val = CheckTotalPrice();
				xGetElementById('total_price').value     = val;
				xGetElementById('total_price').innerHTML = addFigure(val) + "円";
			}else{
				ChangeOrderNumCookie(code);
			}
		}
	}
	
	//************************************************************
	//関数名：UpdateOptionStr
	//機能　：オプション入力の更新
	//************************************************************
	function UpdateOptionStr(){
		ans_str_l = "";
		ans_str_r = "";
		opt_count = 0;
		
		for(i=0;i<OPTION_OBJ_MAX;i++){
			if(option_list[i]['use'] == 1){
				ans_str_l += option_list[i]['name'] + "<br/>";
				ans_str_r += option_list[i]['price_num'] + "円<br/>";
				opt_count++;
			}
		}
		
		xGetElementById('option_list_left').innerHTML  = ans_str_l;
		xGetElementById('option_list_right').innerHTML = ans_str_r;
		tmp_pri = CheckTotalPrice();
		xGetElementById('total_price').innerHTML       = addFigure(tmp_pri) + "円";
		xGetElementById('total_price').value           = tmp_pri;
		
		if(opt_count==0){
			xGetElementById('optmainttl').innerHTML        = '';
			tmp_optmain_r = xGetElementById('optmaindel_r').innerHTML;
			tmp_optmain_l = xGetElementById('optmaindel_l').innerHTML;
			xGetElementById('optmaindel_r').innerHTML      = '';
			xGetElementById('optmaindel_l').innerHTML      = '';
		}else{
			xGetElementById('optmainttl').innerHTML        = 'オプション';
			if(tmp_optmain_r!=""){
				xGetElementById('optmaindel_r').innerHTML      = tmp_optmain_r;	
			}
			if(tmp_optmain_l!=""){
				xGetElementById('optmaindel_l').innerHTML      = tmp_optmain_l;
			}
		}
	}
	
	//************************************************************
	//関数名：
	//機能　：
	//************************************************************
	function SelectOption(id,no){
		ans_str_l = "";
		ans_str_r = "";
		n      = xGetElementById(id).selectedIndex;
		obj    = xGetElementById(id).options[n];
		PushOptionStr(obj,id);	//　配列にオプションデータを挿入する。
		UpdateOptionStr();
		
		if(n==0){
			xGetElementById(eval('opt_box' + no)).style.backgroundColor = "#FAFAFA";
		}else{
			//値が入っていた場合
			xGetElementById(eval('opt_box' + no)).style.backgroundColor = "#EBF8FB";
		}
  }
	
	function ChangeOptionStatus(id,clo){
/*
		if(0==xGetElementById(id).selectedIndex){
			alert("選択なし");
		}else{
			alert("選択!");
			tmp_num =clo.split(",");
			for(i=0;i<tmp_num.length;i++){
				if(!tmp_num[i].match(/[^0-9]/g)){
					xGetElementById("optsel_" + tmp_num[i]).disabled = 
				}
			}
		}
*/
	}
	
	
	//************************************************************
	//関数名：DeleteEdit
	//機能　：エディット内容の破棄
	//************************************************************
	function DeleteEdit(code){
		if(code==-1){
			xGetElementById('select_all').innerHTML = "商品が選択されていません。";
			xGetElementById('option_all').innerHTML = "";
		}else{
			//DeleteOptionCookie(code); //クッキーの消去
			DeleteEditCookie(code);
		}
	}
	
	//************************************************************
	//関数名：SendItemInfo
	//機能　：商品情報を確定してcookieに溜め、次の画面に送る
	//************************************************************
	function SendItemInfo(){
		
		UpdateOptionStr(); //再度オプションの状態を確定しておく
		
		$cookie_str = "";
		$cookie_cnt = 0;
		
		$cookie_str += xGetElementById('hid_iid').value;
		$cookie_str += "##";
		$cookie_str += xGetElementById('hid_iname').value;
		$cookie_str += "##";
		$cookie_str += xGetElementById('hid_price').value;
		
		$cookie_cnt++;
		
		for(i=0;i<OPTION_OBJ_MAX;i++){
			if(option_list[i]['use']==1){
				if($cookie_cnt>0){$cookie_str += "%%";}
				$cookie_str += option_list[i]['key'];
				$cookie_str += "##";
				$cookie_str += option_list[i]['name'];
				$cookie_str += "##";
				$cookie_str += option_list[i]['price'];
				$cookie_cnt++;
			}
		}
		
		$cookie_str += "%%";
		$cookie_str += xGetElementById('order_num').value;
		$cookie_str += "::";
		$cookie_str += xGetElementById('total_price').value;
		
		//既にcookieがセットされていたら最後尾に追加させる。
		val = adGetCookie("ac_item");
		if(val!=null && val!=''){$cookie_str = val + "][" + $cookie_str;}
		
		adSetCookie("ac_item",$cookie_str,"",domain_name);
		
		//注文フォームに遷移
		location.href = "order.html";
		
	}
	//************************************************************
	//関数名：LoadCookieItem
	//機能　：クッキーデータのロード
	//************************************************************
	function LoadCookieItem(){
		cook_str = adGetCookie('ac_item');
		
		
		if(cook_str!='' && cook_str!=null){
			
			node = cook_str.split("][");
			ans_val = "";
			
			//既にcookieに入っている商品データを表示させる。
			for(i=0;i<node.length;i++){
				ans_tmp = tmpl_cook_str;
				
				tmp_url = "http://www." + domain_name + "/";
				ans_tmp = ans_tmp.replace(/%%BASE_PATH%%/g,tmp_url);
				ans_tmp = ans_tmp.replace(/%%CNUM%%/g,i);
				
				itemnode = node[i].split("%%");
				tmp_r = "";
				tmp_l = "";
				for(j=0;j<itemnode.length;j++){
					total_list = itemnode[j].split("::");
					item_list  = itemnode[j].split("##");
					
					if(total_list.length==1){	//商品 or オプション商品
						
						if(item_list[0].charAt(2)=='O'){ //オプション
							tmp_l += item_list[1] + "<br/>";
							tmp_r += addFigure(item_list[2]) + "円<br/>";
							
							tmpl_opt_str = tmpl_opt_str.replace(/%%BASE_PATH%%/g,tmp_url);
							tmpl_opt_str = tmpl_opt_str.replace(/%%CNUM%%/g,i);

							ans_tmp = ans_tmp.replace(/%%TMPL_OPT_STR%%/g,tmpl_opt_str);
							
						}else{ //
							ans_tmp = ans_tmp.replace(/%%ITEM_NAME%%/g,item_list[1]);
							tmp = addFigure(item_list[2]) + "円";
							ans_tmp = ans_tmp.replace(/%%ITEM_PRICE%%/g,tmp);
						}
					}else{	//小計 and 数量
						ans_tmp = ans_tmp.replace(/%%ORDER_NUM_VAL%%/g,total_list[0]);   // 数量
						tmp = addFigure(total_list[1]) + "円";
						ans_tmp = ans_tmp.replace(/%%ITEM_PRICE_TOTAL%%/g,tmp);   		// 小計
					}
				} // loop_j

				ans_tmp = ans_tmp.replace(/%%TMPL_OPT_STR%%/g,'');

				ans_tmp = ans_tmp.replace(/%%LEFT_COOK_VAL%%/g,tmp_l);   	// テンプレート
				ans_tmp = ans_tmp.replace(/%%RIGHT_COOK_VAL%%/g,tmp_r);   // テンプレート
				
				ans_val += ans_tmp;
			} // loop_i
			
			xGetElementById('select_cookie_item').innerHTML = ans_val;
		}
	}
	
	//オプション項目の削除
	function HidOption(){
		
	}
	

