function valueCheck() {
	var chk = false;
	if ( document.search_fm.m1.value != "" ) { chk = true; }
	if ( document.search_fm.m2.value != "" ) { chk = true; }
	if ( document.search_fm.p.options.length > 0 && document.search_fm.p.options[document.search_fm.p.selectedIndex].value != "" ) { chk = true; }
	if ( document.search_fm.a.options.length > 0 && document.search_fm.a.options[document.search_fm.a.selectedIndex].value != "" ) { chk = true; }
	if ( document.search_fm.l.options.length > 0 && document.search_fm.l.options[document.search_fm.l.selectedIndex].value != "" ) { chk = true; }
	if ( document.search_fm.s.options.length > 0 && document.search_fm.s.options[document.search_fm.s.selectedIndex].value != "" ) { chk = true; }
	if ( document.search_fm.y.options.length > 0 && document.search_fm.y.options[document.search_fm.y.selectedIndex].value != "" ) { chk = true; }
	if ( document.search_fm.m.options.length > 0 && document.search_fm.m.options[document.search_fm.m.selectedIndex].value != "" ) { chk = true; }
	if ( document.search_fm.d.options.length > 0 && document.search_fm.d.options[document.search_fm.d.selectedIndex].value != "" ) { chk = true; }
	if ( ! chk ) {
		alert( "検索条件を指定してください。" );
		return false;
	}
	if ( document.search_fm.m1.value != "" && ! ( document.search_fm.m1.value.match(/[0-9]+/g) == document.search_fm.m1.value ) ) {
		alert( "月額賃料には数値を入力してください。" );
		document.search_fm.m1.focus();
		return false;
	}
	if ( document.search_fm.m2.value != "" && ! ( document.search_fm.m2.value.match(/[0-9]+/g) == document.search_fm.m2.value ) ) {
		alert( "月額賃料には数値を入力してください。" );
		document.search_fm.m2.focus();
		return false;
	}
	if ( document.search_fm.y.options.length > 0 && document.search_fm.m.options.length > 0 && document.search_fm.d.options.length > 0 && ( document.search_fm.y.options[document.search_fm.y.selectedIndex].value != "" || document.search_fm.m.options[document.search_fm.m.selectedIndex].value != "" || document.search_fm.d.options[document.search_fm.d.selectedIndex].value != "" ) ) {
		tmpDate = document.search_fm.y.options[document.search_fm.y.selectedIndex].value + "/" + ( "00" + document.search_fm.m.options[document.search_fm.m.selectedIndex].value ).slice( -2 ) + "/" + ( "00" + document.search_fm.d.options[document.search_fm.d.selectedIndex].value ).slice( -2 );
		 //形式チェック
		if ( ! tmpDate.match(/^(\d{4})\/(\d{2})\/(\d{2})$/) ) {
			alert( "入居希望日が不正です。" );
			document.search_fm.y.focus();
			return false;
		}
		 //年月日を取り出し
		sYear = parseInt(document.search_fm.y.options[document.search_fm.y.selectedIndex].value);
		sMonth = parseInt(document.search_fm.m.options[document.search_fm.m.selectedIndex].value);
		sDay = parseInt(document.search_fm.d.options[document.search_fm.d.selectedIndex].value);
		 //月/日の個別のチェック
		 if( sMonth < 1 || sMonth > 12 || sDay < 1 || sDay > 31 ) {
			alert( "入居希望日が不正です。" );
			document.search_fm.y.focus();
			return false;
		 }
		 //日付の厳密な妥当性チェック
		daysArray = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
		endDay = daysArray[ sMonth - 1 ];
		//うるう年の調整
		if ( sMonth == 2 ) {
			if ( sYear % 400 == 0) {
				endDay = 29;
			} else if ( sYear % 4 == 0 && sYear % 100 != 0 ) {
				endDay = 29;
			}
		}
		if ( sDay < 1 || endDay < sDay) {
			alert( "入居希望日が不正です。" );
			document.search_fm.y.focus();
			return false;
		}
	}
}

function changePrefecture() {
	if ( document.search_fm.p.options[document.search_fm.p.selectedIndex].value != "" ) {
		data = "prefecture=" + document.search_fm.p.options[document.search_fm.p.selectedIndex].value;
		data += "&type=1";
		sendRequest("POST", "check_pulldown.php", data, false, changePrefecture_result );
	}
}

function changePrefecture_result( xmlhttp ) {
	document.search_fm.a.options.length=0;
	document.search_fm.a.options[0] = new Option( "- 市区町村 -", "" );
	document.search_fm.l.options.length=0;
	document.search_fm.l.options[0] = new Option( "- 路線 -", "" );
	document.getElementById("area_space").style.display = "inline";
	document.getElementById("line_space").style.display = "inline";
	document.getElementById("station_space").style.display = "none";
	document.search_fm.s.options.length=0;
	document.search_fm.s.options[0] = new Option( "- 駅 -", "" );
	var txt = xmlhttp.responseText.split( "\n" );
	var txt2;
	mode = 1;
	for ( i=2; i<=txt.length; i++ ) {
		if ( txt[i-1] != "" && mode == 1 ) {
			if ( txt[i-1] == "----------" ) {
				mode = 2;
			} else {
				txt2 = txt[i-1].split( "\t" );
				document.search_fm.a.options[document.search_fm.a.options.length] = new Option( txt2[1], txt2[0] );
			}
		} else if ( txt[i-1] != "" && mode == 2 ) {
			txt2 = txt[i-1].split( "\t" );
			document.search_fm.l.options[document.search_fm.l.options.length] = new Option( txt2[1], txt2[0] );
		}
	}
	document.getElementById("search_comment").style.display = "inline";
}

function changeArea() {
	if ( document.search_fm.p.options[document.search_fm.p.selectedIndex].value != "" && ( document.search_fm.a.options[document.search_fm.a.selectedIndex].value != "" || document.search_fm.l.options[document.search_fm.l.selectedIndex].value != "" ) ) {
		data = "prefecture=" + document.search_fm.p.options[document.search_fm.p.selectedIndex].value;
		data += "&area=" + document.search_fm.a.options[document.search_fm.a.selectedIndex].value;
		data += "&line=" + document.search_fm.l.options[document.search_fm.l.selectedIndex].value;
		data += "&type=2";
		sendRequest("POST", "check_pulldown.php", data, false, changeArea_result );
	}
}

function changeArea_result( xmlhttp ) {
	var saveData = document.search_fm.l.options[document.search_fm.l.selectedIndex].value;
	var saveData2 = document.search_fm.s.options[document.search_fm.s.selectedIndex].value;
	document.search_fm.l.options.length=0;
	document.search_fm.l.options[0] = new Option( "- 路線 -", "" );
	document.getElementById("line_space").style.display = "inline";
	document.search_fm.s.options.length=0;
	document.search_fm.s.options[0] = new Option( "- 駅 -", "" );
	var txt = xmlhttp.responseText.split( "\n" );
	var txt2;
	mode = 1;
	for ( i=2; i<=txt.length; i++ ) {
		if ( txt[i-1] != "" && mode == 1 ) {
			if ( txt[i-1] == "----------" ) {
				mode = 2;
			} else {
				txt2 = txt[i-1].split( "\t" );
				document.search_fm.l.options[document.search_fm.l.options.length] = new Option( txt2[1], txt2[0] );
				if ( txt2[0] == saveData ) document.search_fm.l.selectedIndex = ( document.search_fm.l.options.length - 1 );
			}
		} else if ( txt[i-1] != "" && mode == 2 ) {
			txt2 = txt[i-1].split( "\t" );
			document.search_fm.s.options[document.search_fm.s.options.length] = new Option( txt2[1], txt2[0] );
			if ( txt2[0] == saveData2 ) document.search_fm.s.selectedIndex = ( document.search_fm.s.options.length - 1 );
		}
	}
}

function changeLine() {
	if ( document.search_fm.p.options[document.search_fm.p.selectedIndex].value != "" && ( document.search_fm.a.options[document.search_fm.a.selectedIndex].value != "" || document.search_fm.l.options[document.search_fm.l.selectedIndex].value != "" ) ) {
		data = "prefecture=" + document.search_fm.p.options[document.search_fm.p.selectedIndex].value;
		data += "&area=" + document.search_fm.a.options[document.search_fm.a.selectedIndex].value;
		data += "&line=" + document.search_fm.l.options[document.search_fm.l.selectedIndex].value;
		data += "&type=3";
		sendRequest("POST", "check_pulldown.php", data, false, changeLine_result );
	}
}

function changeLine_result( xmlhttp ) {
	var saveData = document.search_fm.a.options[document.search_fm.a.selectedIndex].value;
	var saveData2 = document.search_fm.s.options[document.search_fm.s.selectedIndex].value;
	document.search_fm.a.options.length=0;
	document.search_fm.a.options[0] = new Option( "- 市区町村 -", "" );
	document.search_fm.s.options.length=0;
	document.search_fm.s.options[0] = new Option( "- 駅 -", "" );
	document.getElementById("area_space").style.display = "inline";
	document.getElementById("line_space").style.display = "inline";
	document.getElementById("station_space").style.display = "inline";
	var txt = xmlhttp.responseText.split( "\n" );
	var txt2;
	mode = 1;
	for ( i=2; i<=txt.length; i++ ) {
		if ( txt[i-1] != "" && mode == 1 ) {
			if ( txt[i-1] == "----------" ) {
				mode = 2;
			} else {
				txt2 = txt[i-1].split( "\t" );
				document.search_fm.a.options[document.search_fm.a.options.length] = new Option( txt2[1], txt2[0] );
				if ( txt2[0] == saveData ) document.search_fm.a.selectedIndex = ( document.search_fm.a.options.length - 1 );
			}
		} else if ( txt[i-1] != "" && mode == 2 ) {
			txt2 = txt[i-1].split( "\t" );
			document.search_fm.s.options[document.search_fm.s.options.length] = new Option( txt2[1], txt2[0] );
			if ( txt2[0] == saveData2 ) document.search_fm.s.selectedIndex = ( document.search_fm.s.options.length - 1 );
		}
	}
}
