//=====================================================================
//===                 株式会社フジカーズジャパン                    ===
//===                   車名リスト取得Ａｊａｘ                      ===
//===                                                               ===
//===  Copyright 2007,Programming by Studio iNDEX Yoshinori Komuro. ===
//===                                          Date 2007 / 05 / 30  ===
//=====================================================================
//どのような用途であっても,本プログラム中の一部または全部の流用を禁ずる
//また弊社の許可無く、改変することを堅く禁ずる。                       
//=====================================================================
HTML_AJAX.defaultServerUrl = './php/CarName_Ajax.php';

//---------------------------------------------------------------------
// Ａｊａｘで車名を取得してプルダウンフォームに配置する
//---------------------------------------------------------------------
function MakerSelect(select) {
	obj = document.form.maker;

    index = obj.selectedIndex;
    if (index != 0){
		HTML_AJAX.call('carname_server', 'carnamelist', function(data)
		{
			var CarNamePD = document.getElementById("name");

			CarNamePD.length = 0;

			var CarText		= new Array();
			var CarValue	= new Array();

			Cnt = 0;								// 要素の数のカウンター
			for(var key in data) {
				if (key.match(/NAME/)) {
					CarText.push(data[key]);
					Cnt++;
				} else if (key.match(/VALUE/)) {
					CarValue.push(data[key]);
				}
			}

			var option = document.createElement("option");
			if (Cnt) {
				option.text		= "車名を選択してください。";
				option.value	= "";
			} else {
				option.text		= "このメーカーの車は未登録です。";
				option.value	= "";
			}
			try {
				CarNamePD.add(option, null);
			} catch(e) {
				CarNamePD.add(option);
			}

			for(var i = 0; i < Cnt; i++) {
				var option = document.createElement("option");
				if (select == CarValue[i]) var selnum= i + 1;
				option.text		= CarText[i];
				option.value	= CarValue[i];
				try {
					CarNamePD.add(option, null);
				} catch(e) {
					CarNamePD.add(option);
				}
			}
			if (selnum) fobj.name.selectedIndex = selnum;
		},
		obj.options[obj.selectedIndex].value);
    }
}
//---------------------------------------------------------------------
// デフォルトでメーカーが選択されていたら車名プルダウンも自動取得
//---------------------------------------------------------------------
function selectMakerCheck(select) {

	if (!select) return;

	fobj = document.form;

	if (fobj.maker.value) MakerSelect(select);
}
//---------------------------------------------------------------------
// フォームのリセット
//---------------------------------------------------------------------
function FormReset() {
	fobj = document.form;

	// メーカーフォームの初期化
	fobj.maker.selectedIndex = 0;

	// 車名フォームの初期化
	CarNameElement = fobj.elements['name'];
	CarNameElement.length = 1;
	CarNameElement.options[0].text  = "車名を選択してください。";

	// 価格の初期化
	fobj.priceL.selectedIndex = 0;
	fobj.priceH.selectedIndex = 0;

	// ミッションの初期化
	fobj.mission[0].checked = true;

	// 年式の初期化
	fobj.nenshikiL.selectedIndex = 0;
	fobj.nenshikiH.selectedIndex = 0;

	// 色の初期化
	fobj.color.selectedIndex = 0;

	// 燃料タイプの初期化
	fobj.oil.selectedIndex = 0;

	//駆動タイプの初期化
	fobj.motor.selectedIndex = 0;

	//キーワードの初期化
	fobj.keyword.value = "";
}
