//==============================================================================
// イベント
//==============================================================================

detailFlg = false; //商品詳細表示フラグ

//読み込みイベント
function FormLoad(bid, id, color)
{
	//選択されたカテゴリに該当する商品をすべて検索する
	
	// ロード中画像を表示
	showLoadingImg();
	
	xmlHttpLoad = null;
	xmlHttpLoad = createXMLHttpReq();
	
	if(!xmlHttpLoad){
		alert("error!!");
		return;
	}
	
	//商品が指定されたら詳細も表示
	if(id != undefined){
		detailFlg = true;
		DetailClicked(id, bid, color);
	}else{
		detailFlg = false;
	}
	
	xmlHttpLoad.onreadystatechange = searchLoad;
	
	searchUrl = null;
	searchUrl = 'xml/resultListXml.php?bid=' + bid;

	//search.phpで出力したXMLデータを取得する
	xmlHttpLoad.open("get", searchUrl, true);
	xmlHttpLoad.send(null);
}

/*
 * フリーワード検索　読み込みイベント
 *
 * @param string word スペース区切りの検索文字列
 */
function FormLoadFree(word) {

	// ロード中画像を表示
	showLoadingImg();
	
	xmlHttpLoad = null;
	xmlHttpLoad = createXMLHttpReq();
	
	if ( !xmlHttpLoad ) {
		alert("error!!");
		return;
	}
	
	detailFlg = false;
	
	xmlHttpLoad.onreadystatechange = searchLoad;
	
	searchUrl = null;
	searchUrl = 'xml/freewordXml.php?wrd=' + encodeURI(word);
//	searchUrl = 'xml/freewordXml.php?wrd=' + word;

//	alert(searchUrl);	
	// search.phpで出力したXMLデータを取得する
	xmlHttpLoad.open("get", searchUrl, true);
	xmlHttpLoad.send(null);
}

//検索条件変更イベント
function searchItem(cid)
{	
	/*
	xmlHttp = null;
	xmlHttp = createXMLHttpReq();
	
	if(!xmlHttp){
		alert("error!!");
		return;
	}
	
	xmlHttp.onreadystatechange = getItem;
	
	//ページ切り替え用にグローバル変数に保存する
	searchUrl = null;
	searchUrl = "resultListXml.php?" +
				"cid="      + encodeURI(cid) + "&" +
				"s_name1="  + encodeURI(document.getElementById('joken1').name)  + "&" +
				"s_name2="  + encodeURI(document.getElementById('joken2').name)  + "&" +
				"s_name3="  + encodeURI(document.getElementById('joken3').name)  + "&" +
				"s_value1=" + encodeURI(document.getElementById('joken1').value) + "&" +
				"s_value2=" + encodeURI(document.getElementById('joken2').value) + "&" +
				"s_value3=" + encodeURI(document.getElementById('joken3').value);
					
	//search.phpで出力したXMLデータを取得する
	xmlHttp.open("get", searchUrl, true);
	xmlHttp.send(null);
	*/
}

//選択条件リストの変更イベント
//
// 引数
// bid        ブランド略称
// joken1_name  検索するカラム名
// joken2_name  検索するカラム名
// joken3_name  検索するカラム名
// joken1_value 検索する値
// joken2_value 検索する値
// joken3_value 検索する値
//
function ListItemChanged(bid, joken1_name, joken2_name, joken3_name, joken1_value, joken2_value, joken3_value)
{	
	// ロード中画像を表示
	showLoadingImg();
	
	xmlHttp = null;
	xmlHttp = createXMLHttpReq();
	
	if(!xmlHttp){
		alert("error!!");
		return;
	}
	
	xmlHttp.onreadystatechange = getItem;
	
	//ページ切り替え用にグローバル変数に保存する
	searchUrl = null;
	searchUrl = "xml/resultListXml.php?" +
				"bid="      + bid + "&" +
				"s_name1="  + encodeURI(joken1_name)  + "&" +
				"s_name2="  + encodeURI(joken2_name)  + "&" +
				"s_name3="  + encodeURI(joken3_name)  + "&" +
				"s_value1=" + encodeURI(joken1_value) + "&" +
				"s_value2=" + encodeURI(joken2_value) + "&" +
				"s_value3=" + encodeURI(joken3_value);
				
	//alert(searchUrl);
					
	//search.phpで出力したXMLデータを取得する
	xmlHttp.open("get", searchUrl, true);
	xmlHttp.send(null);
}

//検索条件が４つのブランド用
function ListItemChangedForArray(bid, joken_name, joken_value)
{	
	//alert('func');
	
	// ロード中画像を表示
	showLoadingImg();
	
	xmlHttp = null;
	xmlHttp = createXMLHttpReq();
	
	if(!xmlHttp){
		alert("error!!");
		return;
	}
	
	xmlHttp.onreadystatechange = getItem;
	
	//ページ切り替え用にグローバル変数に保存する
	searchUrl = null;
	searchUrl = "xml/resultListXml.php?" +
				"bid="       + bid +
				"&s_name1="  + encodeURI(joken_name[0]) +
				"&s_name2="  + encodeURI(joken_name[1]) +
				"&s_name3="  + encodeURI(joken_name[2]);
				
	if ( joken_name[3] ) {
		searchUrl += "&s_name4="  + encodeURI(joken_name[3]);
	}
				
	searchUrl += "&s_value1=" + encodeURI(joken_value[0]) +
				 "&s_value2=" + encodeURI(joken_value[1]) +
				 "&s_value3=" + encodeURI(joken_value[2]);
	
	if ( joken_value[3] ) {
		searchUrl += "&s_value4="  + encodeURI(joken_value[3]);
	}
					
	//search.phpで出力したXMLデータを取得する
	xmlHttp.open("get", searchUrl, true);
	xmlHttp.send(null);
}

//ページャーのクリックイベント
function PagerClicked(page)
{
	// ロード中画像を表示
	showLoadingImg();
	
	xmlHttpPage = null;
	xmlHttpPage = createXMLHttpReq();
	
	if(!xmlHttpPage){
		alert("error!!");
		return;
	}
	
	xmlHttpPage.onreadystatechange = changePage;

	if(!searchUrl) return;
	
	//ページ情報を付加
	xmlHttpPage.open("get", searchUrl + "&page=" + encodeURI(page), true);
	xmlHttpPage.send(null);
	
}

//商品詳細クリック
function DetailClicked(code, bid, color)
{	
	xmlHttpDetail = null;
	xmlHttpDetail = createXMLHttpReq();
	
	if(!xmlHttpDetail){
		alert("error!!");
		return;
	}
	
	if(color == undefined){
		color = 0;
	}
	
	xmlHttpDetail.onreadystatechange = getDetail;
	
	//商品コードから商品を検索する
	xmlHttpDetail.open("get", 'xml/detailXml.php?bid=' + bid + '&cd=' + code + '&clr=' + encodeURI(color), true);
//	alert( 'xml/detailXml.php?bid=' + bid + '&cd=' + code + '&clr=' + encodeURI(color));
	xmlHttpDetail.send(null);
}

