function research() {
	if(document.frm.from.value == "") {
		alert("出発駅を指定してください。");
		return false;
	}
	if(document.frm.to.value == "") {
		alert("到着駅を指定してください。");
		return false;
	}
	if(document.frm.from.value == document.frm.to.value) {
		alert("出発駅と到着駅が同じです。異なる駅を指定してください。");
		return false;
	}
	if(!checkDate()){
		return false;
	}
	document.frm.ymd.value = "" + document.frm.ym.value + "/" + document.frm.dy.value;
	document.frm.only.value = "0";
	document.frm.hour.value = "" + document.frm.hour1.value;
	document.frm.submit();
}
function jikan() {
	document.frm.sort[0].checked = true;
	document.frm.only.value = "1";
	document.frm.submit();
}

function norikae() {
	document.frm.sort[2].checked = true;
	document.frm.only.value = "1";
	document.frm.submit();
}

function ryokin() {
	document.frm.sort[1].checked = true;
	document.frm.only.value = "1";
	document.frm.submit();
}

function before10min(fromVal, toVal, viaVal) {
	var hh = eval(document.frm.hour.value);
	var mm = eval(document.frm.minute.value);
	if(mm < 10) {
		if(hh == 0) {
			hh = 23;
		} else {
			hh = hh - 1;
		}
		mm = 60 - (10 - mm);
	} else {
		mm = mm - 10;
	}
	if(hh<10) {
		document.frm.hour.value = "0" + hh;
	}else{
		document.frm.hour.value = "" + hh;
	}
	if(hh < 4) {
		hh = hh + 20;
	} else {
		hh = hh - 4;
	}
	document.frm.hour1.selectedIndex = hh;
	document.frm.minute1.selectedIndex = mm;
	if(mm<10) {
		document.frm.minute.value = "0" + mm;
	}else{
		document.frm.minute.value = "" + mm;
	}
	document.frm.only.value = "1";
	document.frm.from.value = fromVal;
	document.frm.to.value = toVal;
	document.frm.via.value = viaVal;
	document.frm.submit();
}

function after10min(fromVal, toVal, viaVal) {
	var hh = eval(document.frm.hour.value);
	var mm = eval(document.frm.minute.value);
	if(mm >= 50) {
		if(hh == 23) {
			hh = 0;
		} else {
			hh = hh + 1;
		}
		mm = (mm + 10) - 60;
	} else {
		mm = mm + 10;
	}
	if(hh<10) {
		document.frm.hour.value = "0" + hh;
	}else{
		document.frm.hour.value = "" + hh;
	}
	if(hh < 4) {
		hh = hh + 20;
	} else {
		hh = hh - 4;
	}
	document.frm.hour1.selectedIndex = hh;
	document.frm.minute1.selectedIndex = mm;
	if(mm<10) {
		document.frm.minute.value = "0" + mm;
	}else{
		document.frm.minute.value = "" + mm;
	}
	document.frm.only.value = "1";
	document.frm.from.value = fromVal;
	document.frm.to.value = toVal;
	document.frm.via.value = viaVal;
	document.frm.submit();
}

function fukuro(fromVal, toVal, viaVal){
	document.frm.from.value = toVal;
	document.frm.to.value = fromVal;
	document.frm.via.value = viaVal;
	document.frm.only.value = "1";
	document.frm.submit();
}

function dispTeiki(idNo,maxVal) {
	if(document.getElementById('teiki'+idNo).style.display == 'none') {
		document.getElementById('teiki'+idNo).style.display = 'block';
	} else {
		document.getElementById('teiki'+idNo).style.display = 'none';
	}
	var top = eval(maxVal)*30 - 90;
	if(maxVal > 3) {
		document.getElementById('frm').style.padding = "" + top + "px 0px 0px 0px";
	}
}
function send() {
	if(suggest_target<0 || document.getElementById(suggest_selects[suggest_target]) == null || document.getElementById(suggest_selects[suggest_target]).style.visibility=="hidden"){
		if(document.frm.from.value == "") {
			alert("出発駅を指定してください。");
			return false;
		}
		if(document.frm.to.value == "") {
			alert("到着駅を指定してください。");
			return false;
		}
		if(document.frm.from.value == document.frm.to.value) {
			alert("出発駅と到着駅が同じです。異なる駅を指定してください。");
			return false;
		}
		if(!checkDate()){
			return false;
		}
		document.frm.ymd.value = "" + document.frm.ym1.value + "/" + document.frm.dy1.value;
		document.frm.hour.value = "" + document.frm.hour1.value;
		document.frm.minute.value = "" + document.frm.minute1.value;
		document.frm.submit();
	} else {
		setSuggestOut(suggest_selects[suggest_target]);
	}
}

function setHistory(input, list){
	idx = document.getElementById(list).selectedIndex;
	val = document.getElementById(list)[idx].value;
	if(val != ""){
		document.getElementById(input).value = val;
	}
}

function checkDate(){
	var vYm = document.frm.ym1.value;
    var year = vYm.substr(0, 4) - 0;
    var month = eval(vYm.substr(5, 2));
    var day = eval(document.frm.dy1.value);

	if(month == '2'){
		if( ( (year % 4 == 0) && (year % 100 != 0) ) || (year % 400 == 0) ){
			if(day > 29){
				alert(year+"年"+month+"月は29日までです。");
				return false;
			}
		} else {
			if(day > 28){
				alert(year+"年"+month+"月は28日までです。");
				return false;
			}
		}
	} else if(month == '4' || month == '6' || month == '9' || month == '11'){
		if(day > 30){
			alert(year+"年"+month+"月は30日までです。");
			return false;
		}
	}
	return true;
}

function deleteHistorys() {
	deleteCookie('InputHistoryFrom','history_from');
	deleteCookie('InputHistoryTo','history_to');
	deleteCookie('InputHistoryVia','history_via');
}



function createObject() {
	var xmlhttp = false;
	// except IE
	if(window.XMLHttpRequest) {
	  xmlhttp = new XMLHttpRequest();
	// IE
	} else if(window.ActiveXObject) {
	  try {
	    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	  } catch(e) {
	    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	  }
	}

	return xmlhttp;
}

var http = createObject();

function calltop() {

	if (!http) return;

	url = "/map/uc/Top";
	url = url + "?grp=nifty_transit";
	url = url + "&vo=mbml";
	url = url + "&xsl=/nifty_transit/xsl/nifty_TopData";
	url = url + "&xml=0";
	url = url + "&ie=utf-8";
//	url = encodeURI(url);
	http.open('GET', url, false);

	if(window.opera || safari || mozes){
		http.onload = function () {
			callbackTop(http);
		}
	} else {
		http.onreadystatechange=function() {
			if (http.readyState==4 && http.status == 200) {
				callbackTop(http);
			}
		}
	}

	http.send(null);
}

function callbackTop(http){
	var response = http.responseText;
	if(response!=""){
//				document.getElementById("time").innerHTML=response;
		sv_date = response.split("/");
		int_y = parseInt(sv_date[0]);
		int_m = parseInt(sv_date[1]);
		int_d = parseInt(sv_date[2]);
		sv_time = sv_date[3].split(":");
		int_h = parseInt(sv_time[0]);
		int_min = 0;
		int_m1 = 0;
		int_m2 = 0;
		if(sv_time[1].length == 1) {
			int_m2 = parseInt(sv_time[1]);
		} else {
			int_m1 = parseInt(sv_time[1].substr(0,1));
			int_m2 = parseInt(sv_time[1].substr(1,1));
		}

		for(i=0;i<7;i++) {
			str_m = "";
			str_y = int_y + "年";
			if(int_m<10) {
				str_m = "0"+int_m;
			} else {
				str_m = ""+int_m;
			}
			document.frm.ym1.options[i] = new Option(str_y+str_m+"月", int_y+"/"+str_m);
			document.frm.ym2.options[i] = new Option(str_y+str_m+"月", int_y+"/"+str_m);
			int_m++;
			if(int_m>12) {
				int_m=1;
				int_y++;
			}
		}
		document.frm.ym1.selectedIndex = 0;
		document.frm.ym2.selectedIndex = 0;
		document.frm.dy1.selectedIndex = int_d-1;
		document.frm.dy2.selectedIndex = int_d-1;
		int_h = int_h - 4;
		if(int_h<0){
			int_h=int_h+24;
		}
		document.frm.hour1.selectedIndex = int_h;
		document.frm.hour2.selectedIndex = int_h;
		int_min = int_m1*10 + int_m2;
		document.frm.minute1.selectedIndex = int_min;
		document.frm.sv_time.value = response;
	}

}

/**
	駅検索開始処理

	駅名チェック、日付妥当性チェックを行い、初期状態より検索を行う。
*/
function sendTimeTable() {
	if(suggest_target<0 || document.getElementById(suggest_selects[suggest_target]) == null || document.getElementById(suggest_selects[suggest_target]).style.visibility=="hidden"){
		//駅名検索
		if(document.frm.isearchEki.value == ""){
			alert("駅名を入力してください。");
			return false;
		}

		//日付妥当性チェック
		if(!checkDate()){
			return false;
		}

		//検索初期状態に設定
		document.frm.searchEki.value = document.frm.isearchEki.value;
		document.frm.ymd.value = "" + document.frm.ym2.value + "/" + document.frm.dy2.value;
		document.frm.ym.value = "" + document.frm.ym2.value;
		document.frm.dy.value = "" + document.frm.dy2.value;
		document.frm.hour.value = "" + document.frm.hour2.value;
		document.frm.destEki.value = "";
		document.frm.ekiRosen.value = "";
		document.frm.toEki.value = "";
		document.frm.opEki.value = "";
//		document.frm.grp.value = "anethome_transit";
		document.frm.action = "/map/uc/JTimeTable";
		document.frm.submit();
	} else {
		//サジェストリストを閉じる。
		setSuggestOut(suggest_selects[suggest_target]);
	}
}

function writePR(random) {
	document.write('<script language="JavaScript1.1" SRC="http://ad.nttnavi.co.jp/js.ng/site=Nifty&spacedesc=noyaku-txt1&Params.Styles=03_newwindow_JapaneseText_utf8&tocode=UTF-8&transactionID='+random+'?">');
	document.write('<\/script>');
}

function writePR2(random) {
	document.write('<SCRIPT LANGUAGE="JavaScript1.1" SRC="http://ad.nttnavi.co.jp/js.ng/site=Nifty&spacedesc=nrosen-ut&tocode=UTF-8&transactionID='+random+'?">');
	document.write('</SCRIPT>');
}

function dispKeiyu() {
	document.getElementById('keiyu2').style.display = 'block';
	document.getElementById('keiyu1').style.display = 'none';
}

function supportCheck(id) {
	var support = document.getElementById(id).checked;

	if(support){
		document.getElementById('support').checked = true;
		document.getElementById('support2').checked = true;
	} else {
		document.getElementById('support').checked = false;
		document.getElementById('support2').checked = false;
	}
	setSupportCookie('support');
}
