/**
 * 利用日初期値設定function
 */
$( function(){
	var obj;
	nowDate = new Date();
	nowDate = new Date( nowDate.getFullYear(), parseInt(nowDate.getMonth()) + 1, parseInt(nowDate.getDate()) + 7 );
	
	obj = document.check_form;
	if ( obj == 'undefined' || obj == null || obj == '' ) obj = document.map_form;
	if ( obj == 'undefined' || obj == null || obj == '' ) obj = document.needs_form;
	
	if ( obj != 'undefined'  ){
		for ( i = 0; i < obj.year_loans.length; i++ ) {
			if ( nowDate.getFullYear() == obj.year_loans.options[i].value ) obj.year_loans.options.selectedIndex = i;
		}
		for ( i = 0; i < obj.month_loans.length; i++ ) {
			if ( nowDate.getMonth() == obj.month_loans.options[i].value ) obj.month_loans.options.selectedIndex = i;
		}
		for ( i = 0; i < obj.day_loans.length; i++ ) {
			if ( nowDate.getDate() == obj.day_loans.options[i].value ) obj.day_loans.options.selectedIndex = i;
		}
		for ( i = 0; i < obj.hour_loans.length; i++ ) {
			if ( 10 == obj.hour_loans.options[i].value ) obj.hour_loans.options.selectedIndex = i;
		}
		if ( obj.name == 'check_form' ) {
			for ( i = 0; i < obj.year_return.length; i++ ) {
				if ( nowDate.getFullYear() == obj.year_return.options[i].value ) obj.year_return.options.selectedIndex = i;
			}
			for ( i = 0; i < obj.month_return.length; i++ ) {
				if ( nowDate.getMonth() == obj.month_return.options[i].value ) obj.month_return.options.selectedIndex = i;
			}
			for ( i = 0; i < obj.day_return.length; i++ ) {
				if ( nowDate.getDate() == obj.day_return.options[i].value ) obj.day_return.options.selectedIndex = i;
			}
			for ( i = 0; i < obj.hour_return.length; i++ ) {
				if ( 17 == obj.hour_return.options[i].value ) obj.hour_return.options.selectedIndex = i;
			}
		}
	}
});

/**
 * トップページで使用するファンクション
 */
function JUMP(){
	var url = "http://61.200.34.238/cars/index/00/00/47-47/0-0/";
//	var formobj = document.check_form;

	obj  = document.check_form.year_loans;    // 出発年
	url += setSeparate( obj.options[obj.selectedIndex].value, "-" );
	obj  = document.check_form.month_loans;   // 出発月
	url += setSeparate( obj.options[obj.selectedIndex].value, "-" );
	obj  = document.check_form.day_loans;     // 出発日
	url += setSeparate( obj.options[obj.selectedIndex].value, "/" );
	
	obj  = document.check_form.year_return;   // 返却年
	url += setSeparate( obj.options[obj.selectedIndex].value, "-" );
	obj  = document.check_form.month_return;  // 返却月
	url += setSeparate( obj.options[obj.selectedIndex].value, "-" );
	obj  = document.check_form.day_return;    // 返却日
	url += setSeparate( obj.options[obj.selectedIndex].value, "/" );
	
	obj  = document.check_form.hour_loans;    // 出発時
	url += setSeparate( obj.options[obj.selectedIndex].value, "-" );
	obj  = document.check_form.minutes_loans; // 出発分
	url += setSeparate( obj.options[obj.selectedIndex].value, "/" );
	
	obj  = document.check_form.hour_return;   // 返却時
	url += setSeparate( obj.options[obj.selectedIndex].value, "-" );
	obj  = document.check_form.minutes_return;// 返却分
	url += setSeparate( obj.options[obj.selectedIndex].value, "/" );
/*
	obj  = document.check_form.car_type;
	var temp_checkbox ="";
	for ( i = 0, j= 0; i < obj.length; i++ ) {
		if ( obj[i].checked ) {
			if ( j != 0 ) temp_checkbox += setSeparate( "", "," );
			temp_checkbox += setSeparate( obj[i].value, "" );
			if ( j == 0 ) j++;
		}
	}
	if (temp_checkbox) { url += temp_checkbox; }
	else {
		url += ",";
	}
*/
	obj  = document.check_form.car_type;
	var checkAry = new Array();
	for(i=0; i<obj.length; i++) {
		if (obj[i].checked) checkAry.push(obj[i].value);
	}
	if (!checkAry.length) { url += "," }
	else { url += checkAry.join(","); }
	
	url += "/,/"; //区切り文字追加
	obj  = document.check_form.shopID;    // 店舗ID　
//	url += setSeparate( obj.options[obj.selectedIndex].value, "/" );
	url += setSeparate( obj.value, "" );

	location.href = url;
}

/**
 * 文字列追加ファンクション
 * param  string param    パラメータ
 * param  string separate パラメータを区切る文字
 *                        例：'3/47' や '2010-1'
 * return string url      param + separate
 *                        例：param = '9', separate = '-' なら '9-'
 */
function setSeparate( param, separate ){
	var url  = param;
	    url += separate; // 区切り文字追加
	return url;
}
