//フォーム初期化
function FormInit()
{
	document.form1.by_word1.selectedIndex = 0;
	document.form1.by_word2.selectedIndex = 0;
	document.form1.by_word3.selectedIndex = 0;
}

// 使用目的選択時
function changeWord1(by_word1)
{
    setW2Option(by_word1.value);
    document.form1.by_word2.disabled = true;

}

// 使用機材選択時
function changeWord2(by_word2)
{
    setW3Option(by_word2.value);
    document.form1.by_word3.disabled = true;

}

// 使用目的選択時（管理用）
function changeWord3(by_mokuteki)
{
    setW4Option(by_mokuteki.value);

}

// （管理用）
function changeWord(by_category1)
{
    setOption(by_category1.value);
    //document.form1.by_category2.disabled = true;

}


// 使用機材オプション設定
function setW2Option(w1)
{
    len = document.form1.by_word2.options.length;
    for (i=len-1; i>=0; i--){
        document.form1.by_word2.options[i] = null;
    }
    var by_word1 = "by_word1=" + w1;

	var myAjax = new Ajax.Request(
		"pull_1.cgi", 
		{
			method: 'post', 
			parameters: by_word1, 
			onComplete: callBack1
		});

    document.form1.by_word2.selectedIndex = 0;
}

function callBack1(xmlhttp)
{
    var result = xmlhttp.responseText;

    var resArray = result.split(",");
    for (i=0; i<resArray.length; i++) {
        var w1Array = resArray[i].split("/");
		
		if (w1Array[1]) {
       		document.form1.by_word2.options[i] = new Option(w1Array[1], w1Array[0]);
    	}
    }
    
    document.form1.by_word2.disabled = false;
}

// 
function setW3Option(ken)
{
    len = document.form1.by_word3.options.length;
    for (i=len-1; i>=0; i--){
        document.form1.by_word3.options[i] = null;
    }

    var data = "by_word2=" + ken + "&by_word1=" + document.form1.by_word1.value;

	var myAjax = new Ajax.Request(
		"pull_2.cgi", 
		{
			method: 'post', 
			parameters: data, 
			onComplete: callBack2
		});

    document.form1.by_word3.selectedIndex = 0;
}

function callBack2(xmlhttp)
{
    var result = xmlhttp.responseText;

    var resArray = result.split(",");
    for (i=0; i<resArray.length; i++) {
        var w2Array = resArray[i].split("/");
		
		if (w2Array[1]) {
        	document.form1.by_word3.options[i] = new Option(w2Array[1], w2Array[0]);
    	}
    	
    }
    
    document.form1.by_word3.disabled = false;
}

function setW4Option(ken)
{
    len = document.form1.by_scnumber.options.length;
    for (i=len-1; i>=0; i--){
        document.form1.by_scnumber.options[i] = null;
    }

    var data = "by_adminword=" + ken;
	
	var myAjax = new Ajax.Request(
		"pull_3.cgi", 
		{
			method: 'post', 
			parameters: data, 
			onComplete: callBack3
		});

    document.form1.by_scnumber.selectedIndex = 0;
}

function callBack3(xmlhttp)
{
    var result = xmlhttp.responseText;
	
    var resArray = result.split(",");
    
    for (i=0; i<resArray.length; i++) {
        var w2Array = resArray[i].split("/");
		
		if (w2Array[1]) {
        	document.form1.by_scnumber.options[i] = new Option(w2Array[1], w2Array[0]);
    	}
    	
    }
}


function setOption(ken, num)
{
	var data = "by_adminword=" + ken + "&by_num=" + num;
	
	var myAjax = new Ajax.Request(
		"pull_4.cgi", 
		{
			method: 'post', 
			parameters: data, 
			onComplete: callBack5
		});
	
}

function callBack5(xmlhttp)
{
    document.getElementById("by_category2").innerHTML = xmlhttp.responseText;
}


