/******************************************************************************/
/*関数名：cart_search                                                         */
/*概要  ：カートに入っている商品の画像変更                                    */
/*引数  ：無し                                                                */
/*戻り値：無し                                                                */
/*作成：2009/08/26    succeed    usami                                        */
/******************************************************************************/
function cart_search()
{
	//XMLHttpオブジェクト作成
	xml_http_obj = create_xmlhttp();
	if(xml_http_obj == false)
	{
		//alert("create xml_http_obj false");
	}
	url = "./get_pro_id.php";
	
	//phpを呼び出し(GETで値渡し)
	xml_http_obj.open("GET",url,true);
	
	//コールバック関数定義
	xml_http_obj.onreadystatechange = callback_search;
	//ヘッダー定義
	xml_http_obj.setRequestHeader("If-Modified-Since", "Thu, 01 Jun 1970 00:00:00 GMT");
	//送信
	xml_http_obj.send(null);
}

/******************************************************************************/
/*関数名：callback_search                                                     */
/*概要  ：コールバック関数                                                    */
/*引数  ：無し                                                                */
/*戻り値：無し                                                                */
/*作成：2009/08/28    succeed    usami                                        */
/******************************************************************************/
function callback_search()
{
	//個数用テキストボックスのID
	//var quantity_id = "";
	
	
	if( (xml_http_obj.readyState == 4) && (xml_http_obj.status == 200))
	{
		//戻ってきたXMLを取得
		var response = xml_http_obj.responseXML;
		//データが空かPHP側でエラーが出てたら処理なし
		if(response == null)
		{
			//alert("null");
			return;
		}
		
		
		//xmlを取り出し
		var pro_id = response.documentElement.getElementsByTagName("pro_id");
		var quantity = response.documentElement.getElementsByTagName("quantity");
		
		for(count=0;count < pro_id.length;count++)
		{
			//カートにある商品の画像変更
			if(document.getElementById(pro_id[count].getAttribute("VALUE")))
			{
				var temp = document.getElementById(pro_id[count].getAttribute("VALUE"));
				document.getElementById(pro_id[count].getAttribute("VALUE")).innerHTML = '<img src="./img/image_id_'+pro_id[count].getAttribute("VALUE")+'.jpg"  class="item" onclick="get_num('+pro_id[count].getAttribute("VALUE")+');" onmouseover="this.src=\'./img/image_id_'+pro_id[count].getAttribute("VALUE")+'ov.jpg\'" onmouseout="this.src=\'./img/image_id_'+pro_id[count].getAttribute("VALUE")+'.jpg\'" />';
			}
				
			/*個数用テキストボックスに現在のカート内の個数を表示(別機能で実装)
			quantity_id = "p_id_" + pro_id[count].getAttribute("VALUE");
			document.getElementById(quantity_id).value = quantity[count];*/
		}
	}
}

function get_num(id)
{
/*	var menu_map =	{
						// ----------------------------------
						// Desiner's Foods
						// ----------------------------------
						"16" : "0",		// スモ・ビオ
						"20" : "1",		// スモ・ビオ
						"18" : "2",		// スモ・ビオ
						"19" : "3",		// スモ・ビオ
						"15" : "4",		// スモ・ビオ
						"17" : "5",		// スモ・ビオ
						"14" : "6",		// スモ・ビオ
						"8"  : "7",		// スモ・ビオ
						"9"  : "8",		// スモ・ビオ
						"10" : "9",		// スモ・ビオ
						"11" : "10",	// スモ・ビオ
						"12" : "11",	// スモ・ビオ
						"13" : "12", 	// スモ・ビオ
						"3"  : "13", 	// スモ・ビオ
						"4"  : "14", 	// スモ・ビオ
						"5"  : "15", 	// スモ・ビオ
						"6"  : "16", 	// スモ・ビオ
						"7"  : "17", 	// スモ・ビオ


						// -----------------------------------
						// Natural Beauty
						// -----------------------------------
						"21"  : "20",	 // スモ・ビオ
						"22"  : "21",	 // スモ・ビオ
						"23"  : "22",	 // スモ・ビオ
						"25"  : "23",	 // スモ・ビオ
						"24"  : "24",	 // スモ・ビオ
						"30"  : "25",	 // スモ・ビオ
						"29"  : "26",	 // スモ・ビオ
						"26"  : "27",	 // スモ・ビオ
						"27"  : "28",	 // スモ・ビオ
						"28"  : "29",	 // スモ・ビオ
						"31"  : "30",	 // スモ・ビオ
						"32"  : "31",	 // スモ・ビオ
						"33"  : "32",	 // スモ・ビオ
						"34"  : "33",	 // スモ・ビオ

						// -------------------------------------
						// PET関連シリーズ
						// -------------------------------------
						"35"  :  "18", // バウワウ
						"36"  :  "19" // バウワウ
					};
*/
	var obj = document.getElementById('p_id_' + id);
	up_num(obj);
}




/******************************************************************************/
/*関数名：create_xmlhttp                                                      */
/*概要  ：非同期通信用オブジェクト生成                                        */
/*引数  ：無し                                                                */
/*戻り値：xmlhttpobj              非同期通信用オブジェクト                    */
/*作成  ：2008/12/17 succeed  y-usami                                         */
/******************************************************************************/
function create_xmlhttp()
{
	//XMLHttpオブジェクト作成
	if(window.XMLHttpRequest)
	{
		xmlhttpobj = new XMLHttpRequest();
	}
	else
	{
		if(window.ActiveXObject)
		{
			xmlhttpobj = new ActiveXObject("Microsoft.XMLHTTP");
		}
		else
		{
			xmlhttpobj = false;
			document.write("XMLHttpオブジェクト作成に失敗しました\n");
		}
	}
	return xmlhttpobj;
}

/******************************************************************************/
/*関数名：up_num                                                              */
/*概要：テキストエリアの個数を１増やす                                        */
/*引数：text_name    テキストエリアの名前(document.form.text_area_name)       */
/*戻り値：無し                                                                */
/*作成：2009/08/24    succeed    usami                                        */
/******************************************************************************/
function up_num(text_name)
{

	if(text_name.value != "")
	{
		if(text_name.value < 99)
		{
			text_name.value++;
		}
	}
	else
	{
		text_name.value = 1;
	}
}

/******************************************************************************/
/*関数名：down_num                                                            */
/*概要：テキストエリアの個数を１減らす                                        */
/*引数：text_name    テキストエリアの名前(document.form.text_area_name)       */
/*戻り値：無し                                                                */
/*作成：2009/08/24    succeed    usami                                        */
/******************************************************************************/
function down_num(text_name)
{
	if(text_name.value != "")
	{
		if(text_name.value > 0)
		{
			text_name.value--;
		}
		else
		{
			text_name.value = 0;
		}
	}
	else
	{
		text_name.value = 0;
	}
}

/******************************************************************************/
/*関数名：key_check                                                           */
/*概要：半角数字,←→,Insert,Delete,Home,End以外の入力結果を消す              */
/*引数：text_name    テキストエリアの名前(document.form.text_area_name)       */
/*戻り値：無し                                                                */
/*作成：2009/08/24    succeed    usami                                        */
/******************************************************************************/
function key_check(text_name)
{
	if (window.event)
	{
		//押されたキーのキーコード取得
		var press_keycode = window.event.keyCode;
		
		//keyup時のキーコードと判定(48～57→半角数字0～9),(96～105→テンキーの数字0～9),(37,39)→(左右ボタン),(8→BackSpace),(45→Insert),(46→Delete),(35→End),(36→Home)
		//半角数字,←→,Insert,Delete,Home,Endのみ許可
		if ( 48<=press_keycode&&press_keycode<=57 || 96<=press_keycode&&press_keycode<=105 || press_keycode==37 || press_keycode==39 || press_keycode==8 || press_keycode==45 || press_keycode==46 || press_keycode==36 || press_keycode==35 ) 
		{
			return;
		}
	}
	
	//半角数字以外の文字を消す
	var text_value=text_name.value;
	text_value=text_value.replace(/[^0-9]/g,'');
	text_name.value=text_value;
}


/******************************************************************************/
/*関数名：num_check                                                           */
/*概要：半角整数で入力されているかチェック                                    */
/*引数：無し                                                                  */
/*戻り値：無し                                                                */
/*作成：2009/08/25    succeed    usami                                        */
/******************************************************************************/
function num_check()
{
	//alert(document.form1.elements['product_id[0]'].value);
	/*var obj_form = document.getElementsByTagName("input");
	if(obj_form.length != 0)
	{
		for(count=1;count <= obj_form.length;count++)
		{
			//数字かチェック
			if(obj_form[count] != "")
			{
				if(isNaN(obj_form[count].value))
				{
					window.alert("半角の整数で入力して下さい");
					obj_form[count].focus();
					return;
				}
			}
		}*/
		document.menu_form.submit();
	//}
}


