// --------------------------------
// 店舗在庫一覧・店舗ショールーム Jsファイル
// 車種のajax
// /cgi-bin/search/zaiko_bike.cgi
// /cgi-bin/search/zaiko_cassette.cgi
//
// 2009/11/12
// -------------------------------

//===========================================
// 車種選択用ドロップダウンリストをセット
//===========================================
function setSyasyuId( maker_id_data, client_id_data, grp_data, syasyu_id_data ){
//alert( maker_id_data );
    //XMLHttpRequestオブジェクト生成
    var httpoj = createHttpRequest();
    var method = "GET";
    var fileName = "/web/search/ajax_zaikosyasyu_select.php?maker_id=" + maker_id_data + "&client_id=" + client_id_data + "&grp_id=" + grp_data;
    var async = true;
    //open メソッド
    httpoj.open( method , fileName , async );
    httpoj.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
    httpoj.setRequestHeader("Cache-Control", "no-cache");


    var frm = document.form1;
    var now_count = document.getElementById("select_syasyu_id").length;
    for(var counter=now_count-1; counter>=0; counter--){
        document.getElementById("select_syasyu_id").options[counter] = null;
    }
    document.getElementById("select_syasyu_id").options[0] = new Option("指定無し","");


    //受信時に起動するイベント
    httpoj.onreadystatechange = function(){
        //readyState値は4で受信完了
        if (httpoj.readyState == 4){
            //コールバック
            if( httpoj.status == 200 ) {
                var responseText = httpoj.responseText;
                if( responseText != '' ) {
                    var data = eval(responseText);
                    j=1;
                    for(i=0; i<data.length; i++){
                        if ( data[i].syasyu_id == syasyu_id_data  ){
                            document.getElementById("select_syasyu_id").options[j++] = new Option(data[i].syasyu_nm,data[i].syasyu_id,1,1);
                        } else {
                            document.getElementById("select_syasyu_id").options[j++] = new Option(data[i].syasyu_nm,data[i].syasyu_id);
                        }

                    }
                } else {
                    document.getElementById("select_syasyu_id").options[0] = null;
                    document.getElementById("select_syasyu_id").options[0] = new Option("指定無し","");
                }
            }
            httpoj = null;
        }
    }
    httpoj.send( null );
}



//XMLHttpRequestオブジェクト生成
function createHttpRequest(){
	try {
		netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
	} catch (e) {
	}
	//Win ie用
	if(window.ActiveXObject){
		try {
			//MSXML2以降用
			return new ActiveXObject("Msxml2.XMLHTTP") //[1]'
		} catch (e) {
			try {
				//旧MSXML用
				return new ActiveXObject("Microsoft.XMLHTTP") //[1]'
			} catch (e2) {
				return null
			}
		}
	} else if(window.XMLHttpRequest){
		//Win ie以外のXMLHttpRequestオブジェクト実装ブラウザ用
	return new XMLHttpRequest() //[1]'
	} else {
		return null
	}
}

