function chDisabled(select)
{
	return function()
	{
		var text = $(select.id + 'Other');
		text.disabled = (select.value == '999') ? false : true;
	};
}

function setLine()
{
	return function()
	{
		$('RealEstateLine').value = $('line_0').value;
	};
}

function chSelect()
{
	return function()
	{
		var s = $('line_' + $('RealEstateRailroad').value);
		if (!s) {
			return void(0);
		}

		var es = $('SearchForm').elements;
		for (var i = 0; i < es.length; i++) {
			if (es[i].id.indexOf('line', 0) > -1) {
				var cs = es[i];

				if (cs.id == s.id) {
					var rs = $('line_0');
					var l = rs.options.length;

					for (var j = 1; j < l; j++){
						rs.options[l - j] = null;
					}

					l = cs.options.length;
					if ((s.id != ('line_0')) && (s.id != ('line_999'))) {
						for (var j = 0; j < l; j++) {
							rs.options[j + 1] = new Option(cs.options[j].text, cs.options[j].value);
						}
					}else{
						$('RealEstateLine').value = '';
					}

					addEvent(rs, 'change', setLine());
				}
			}
		}
	};
}

function initLineSelect()
{
	chSelect()();
	var s = $('line_0');
	var v = $('RealEstateLine').value;
	for (var i = 0; i < s.options.length; i++) {
		if (s.options[i].value == v) {
			s.options[i].selected = true;
		}
	}

	addEvent($('RealEstateRailroad'),'change',chSelect());
	addEvent($('RealEstateRailroad'),'focus',chSelect());
}

addEvent($('RealEstateTypeAll'),'click',checkConsecutiveNumbersIds('RealEstateType',checkBoxCount['type']));
addEvent($('RealEstateTokyoAll'),'click',checkConsecutiveNumbersIds('RealEstateTokyoArea',checkBoxCount['tokyo_area']));
addEvent($('RealEstateTokyoSix'),'click',checkConsecutiveNumbersIds('RealEstateTokyoArea',(checkBoxCount['tokyo_area'] < 6) ? checkBoxCount['tokyo_area'] : 6));
addEvent($('RealEstateTokyoAllCity'),'click',checkConsecutiveNumbersIds('RealEstateTokyoCity',checkBoxCount['tokyo_city']));
addEvent($('RealEstateKanagawa'),'click',checkConsecutiveNumbersIds('RealEstateKanagawaCity',checkBoxCount['kanagawa_city']));
addEvent($('RealEstateChiba'),'click',checkConsecutiveNumbersIds('RealEstateChibaCity',checkBoxCount['chiba_city']));
addEvent($('RealEstateSaitama'),'click',checkConsecutiveNumbersIds('RealEstateSaitamaCity',checkBoxCount['saitama_city']));
addEvent(window, 'load', initLineSelect);

