/**
 * @author ability
 */

function setYproSearch(){

	var nInitDay       = 0;		// 日付(○日後) ※本日の場合は 0
	var nInitYearPlus  = 3;		// 年プルダウンの選択数(○年後まで選択可能)
	var nInitPer       = 2;		// 人数
	var nInitStay      = 1;		// 泊数
	var nInitRoom      = 1;		// 部屋数
	var nInitBudgetMin = 0;		// 料金下限(optionの番号) ※下限なしの場合は 0
	var nInitBudgetMax = 0;		// 料金上限(optionの番号) ※上限なしの場合は 0

	// 料金(下限)
	var arrInitBudgetMin = [
		[0, "下限なし"],
		[1, "5,000円"],
		[2, "6,000円"],
		[3, "7,000円"],
		[4, "8,000円"],
		[5, "9,000円"],
		[6, "10,000円"],
		[7, "12,000円"],
		[8, "14,000円"],
		[9, "16,000円"],
		[10, "18,000円"],
		[11, "20,000円"],
		[12, "30,000円"],
		[13, "40,000円"],
		[14, "50,000円"]
	];

	// 料金(上限)
	var arrInitBudgetMax = [
		[0, "上限なし"],
		[1, "5,000円"],
		[2, "6,000円"],
		[3, "7,000円"],
		[4, "8,000円"],
		[5, "9,000円"],
		[6, "10,000円"],
		[7, "12,000円"],
		[8, "14,000円"],
		[9, "16,000円"],
		[10, "18,000円"],
		[11, "20,000円"],
		[12, "30,000円"],
		[13, "40,000円"],
		[14, "50,000円"]
	];

	// 日付の設定
	var thisDate = new Date();
	thisDate.setTime( thisDate.getTime() + nInitDay * 1000 * 60 * 60 * 24 );

	var thisYear = thisDate.getFullYear();
	var thisMonth = thisDate.getMonth()+1;
	var thisDay = thisDate.getDate();	

	/*
	 * 年のセレクトボックス生成
	 */
	var arrYear = getYproElementsByClass( "obj_year" );
	if( arrYear != undefined && arrYear != null ){

		for( var nCnt = 0; nCnt < arrYear.length; nCnt++ ){

			var objYear = arrYear[ nCnt ];
			if( objYear != undefined ){

				while( objYear.lastChild ){
					objYear.removeChild(objYear.lastChild);
				}
				for(optionYear = thisYear; optionYear < thisYear+nInitYearPlus+1; optionYear++){
					selectLn = objYear.options.length;
					objYear.options[selectLn] = new Option(optionYear, optionYear);

					if( optionYear == thisDay ){
						objYear.options[selectLn].selected = true;
					}

				}

			}

		}

	}

	/*
	 * 月のセレクトボックス生成
	 */
	var arrMonth = getYproElementsByClass( "obj_month" );
	if( arrMonth != undefined && arrMonth != null ){

		for( var nCnt = 0; nCnt < arrMonth.length; nCnt++ ){

			var objMonth = arrMonth[ nCnt ];
			if( objMonth != undefined ){

				while( objMonth.lastChild ){
					objMonth.removeChild(objMonth.lastChild);
				}
				for(var optionMonth = 1; optionMonth < 13; optionMonth++){
					var selectLn = objMonth.options.length;
					objMonth.options[selectLn] = new Option(optionMonth, optionMonth);

					if( optionMonth == thisMonth ){
						objMonth.options[selectLn].selected = true;
					}

				}

			}

		}

	}

	/*
	 * 日のセレクトボックス生成
	 */
	var arrDay = getYproElementsByClass( "obj_day" );
	if( arrDay != undefined && arrDay != null ){

		for( var nCnt = 0; nCnt < arrDay.length; nCnt++ ){

			var objDay = arrDay[ nCnt ];
			if( objDay != undefined ){

				while( objDay.lastChild ){
					objDay.removeChild(objDay.lastChild);
				}
				for(var optionDay = 1; optionDay < 32; optionDay++){
					var selectLn = objDay.options.length;
					objDay.options[selectLn] = new Option(optionDay, optionDay);

					if( optionDay == thisDay ){
						objDay.options[selectLn].selected = true;
					}

				}

			}

		}

	}

	/*
	 * 人数のセレクトボックス生成
	 */
	var arrPerNum = getYproElementsByClass( "obj_per_num" );
	if( arrPerNum != undefined && arrPerNum != null ){

		for( var nCnt = 0; nCnt < arrPerNum.length; nCnt++ ){

			var objPerNum = arrPerNum[ nCnt ];
			if( objPerNum != undefined ){

				while( objPerNum.lastChild ){
					objPerNum.removeChild(objPerNum.lastChild);
				}
				for(var optionPerNum = 1; optionPerNum <= 10; optionPerNum++){
					var selectLn = objPerNum.options.length;
					objPerNum.options[selectLn] = new Option(optionPerNum, optionPerNum);

					if( optionPerNum == nInitPer ){
						objPerNum.options[selectLn].selected = true;
					}

				}

			}

		}

	}

	/*
	 * 泊数のセレクトボックス生成
	 */
	var arrStayNum = getYproElementsByClass( "obj_stay_num" );
	if( arrStayNum != undefined && arrStayNum != null ){

		for( var nCnt = 0; nCnt < arrStayNum.length; nCnt++ ){

			var objStayNum = arrStayNum[ nCnt ];
			if( objStayNum != undefined ){

				while( objStayNum.lastChild ){
					objStayNum.removeChild(objStayNum.lastChild);
				}
				for(optionStayNum = 1; optionStayNum <= 10; optionStayNum++){
					var selectLn = objStayNum.options.length;
					objStayNum.options[selectLn] = new Option(optionStayNum, optionStayNum);

					if( optionStayNum == nInitStay ){
						objStayNum.options[selectLn].selected = true;
					}

				}

			}

		}

	}

	/*
	 * 部屋数のセレクトボックス生成
	 */
	var arrRoomNum = getYproElementsByClass( "obj_room_num" );
	if( arrRoomNum != undefined && arrRoomNum != null ){

		for( var nCnt = 0; nCnt < arrRoomNum.length; nCnt++ ){

			var objRoomNum = arrRoomNum[ nCnt ];
			if( objRoomNum != undefined ){

				while( objRoomNum.lastChild ){
					objRoomNum.removeChild(objRoomNum.lastChild);
				}
				for(optionRoomNum = 1; optionRoomNum <= 10; optionRoomNum++){
					var selectLn = objRoomNum.options.length;
					objRoomNum.options[selectLn] = new Option(optionRoomNum, optionRoomNum);

					if( optionRoomNum == nInitRoom ){
						objRoomNum.options[selectLn].selected = true;
					}

				}

			}

		}

	}

	/*
	 * 料金下限のセレクトボックス生成
	 */
	var arrBudgetMin = getYproElementsByClass( "obj_budget_min" );
	if( arrBudgetMin != undefined && arrBudgetMin != null ){

		for( var nCnt = 0; nCnt < arrBudgetMin.length; nCnt++ ){

			var objBudgetMin = arrBudgetMin[ nCnt ];
			if( objBudgetMin != undefined ){

				while( objBudgetMin.lastChild ){
					objBudgetMin.removeChild(objBudgetMin.lastChild);
				}
				for(optionBudgetMin = 0; optionBudgetMin < arrInitBudgetMin.length; optionBudgetMin++){
					var selectLn = objBudgetMin.options.length;
					objBudgetMin.options[selectLn] = new Option(arrInitBudgetMin[optionBudgetMin][1], arrInitBudgetMin[optionBudgetMin][0]);

					if( arrInitBudgetMin[optionBudgetMin][0] == nInitBudgetMin ){
						objBudgetMin.options[selectLn].selected = true;
					}

				}

			}

		}

	}

	/*
	 * 料金上限のセレクトボックス生成
	 */
	var arrBudgetMax = getYproElementsByClass( "obj_budget_max" );
	if( arrBudgetMax != undefined && arrBudgetMax != null ){

		for( var nCnt = 0; nCnt < arrBudgetMax.length; nCnt++ ){

			var objBudgetMax = arrBudgetMax[ nCnt ];
			if( objBudgetMax != undefined ){

				while( objBudgetMax.lastChild ){
					objBudgetMax.removeChild(objBudgetMax.lastChild);
				}
				for(optionBudgetMax = 0; optionBudgetMax < arrInitBudgetMax.length; optionBudgetMax++){
					var selectLn = objBudgetMax.options.length;
					objBudgetMax.options[selectLn] = new Option(arrInitBudgetMax[optionBudgetMax][1], arrInitBudgetMax[optionBudgetMax][0]);

					if( arrInitBudgetMax[optionBudgetMax][0] == nInitBudgetMax ){
						objBudgetMax.options[selectLn].selected = true;
					}

				}

			}

		}

	}

}

function getYproElementsByClass( sSearchClass ){

	var arrClassElements = new Array();

	if( document.all ){

		var objAllElements = document.all;
		for( ii = 0, jj = 0; ii < objAllElements.length; ii++ ){
			if( objAllElements[ii].className == sSearchClass ){
				arrClassElements[jj] = objAllElements[ii];
				jj++;
			}
		}

	}
	else if( document.getElementsByTagName ){

		var objAllElements = document.getElementsByTagName("*");
		for( ii = 0, jj = 0; ii < objAllElements.length; ii++ ){
			if( objAllElements[ii].className == sSearchClass ){
				arrClassElements[jj] = objAllElements[ii];
				jj++;
			}
		}

	}
	else{

		return null;

	}

	return arrClassElements;

}

function toggleYproDate( objNoDate, objForm ){

	if( objNoDate.checked == true ){

		var objYear = objForm.obj_year;
		if( objYear != undefined && objYear != null ){
			objYear.disabled = true;
		}
		var objMonth = objForm.obj_month;
		if( objMonth != undefined && objMonth != null ){
			objMonth.disabled = true;
		}
		var objDay = objForm.obj_day;
		if( objDay != undefined && objDay != null ){
			objDay.disabled = true;
		}

	}
	else{

		var objYear = objForm.obj_year;
		if( objYear != undefined && objYear != null ){
			objYear.disabled = false;
		}
		var objMonth = objForm.obj_month;
		if( objMonth != undefined && objMonth != null ){
			objMonth.disabled = false;
		}
		var objDay = objForm.obj_day;
		if( objDay != undefined && objDay != null ){
			objDay.disabled = false;
		}

	}

}

if(window.attachEvent){
	window.attachEvent('onload', setYproSearch);
}
else{
	window.addEventListener('load', setYproSearch, false);
}

