document.getElementById('frStationBT').onclick = function () {
	if ( document.getElementById('frStationText').style.display === 'none' ) {
		location.href = '/kensaku/sc1/search_results_time.php?f=1&s=' + encodeURIComponent( document.getElementById('frStation2').value ) + '&m=' + document.getElementById('frStationTime').value + '&dm=' + new Date().getTime();
		return;
	}
	var vals = PlsInput.getValue('frStation1');
	if (!vals) return alert('駅名を入力してください');
	var http = new JKL.ParseXML.JSON( '/navi/gxml.php?s=' + encodeURIComponent( vals ) + '&dm=' + new Date().getTime() );
	http.async( function (d) {
		if ( !d || d.length < 1 ) {
			document.getElementById('frStation2').length = 0;
			var m = document.getElementById('frMsg');
			m.innerHTML = '該当の駅はございません';
			m.style.display = '';
			return;
		}
		if ( d.length === 1 ) {
			location.href = '/kensaku/sc1/search_results_time.php?f=1&s=' + encodeURIComponent( d[0].STNAME ) + '&m=' + document.getElementById('frStationTime').value + '&dm=' + new Date().getTime();
			return;
		}
		var c = document.getElementById('frStation2');
		c.length = d.length;
		for ( var i = 0, n = d.length; i < n; ++i ) {
			c.options[i].value = d[i].STNAME;
			c.options[i].text = d[i].STNAME.replace( /（.*/g, '' );
		}
		document.getElementById('frStationText').style.display = 'none';
		document.getElementById('frStationSelect').style.display = '';
		var m = document.getElementById('frMsg');
		m.innerHTML = '複数の駅があるので選んでください';
		m.style.display = '';
	} );
	http.parse();
};
function $EV(e,t,f) {
	if ( e.addEventListener ) return e.addEventListener( t, f, false );
	if ( e.attachEvent ) return e.attachEvent( 'on' + t, f );
	e[ 'on' + t ] = f;
}
function $FB(f,s,a) { s = s || null; a = a || []; return function () { return f.apply(s,a); }; }
function GrayInput( obj ) {
	this.data = obj;
	this.clearValue = function (i) {
		var e = document.getElementById(i);
		e.value = this.data[i];
		e.style.color = '#c0c0c0';
	};
	this.setValue = function (e,v) {
		if ( typeof e === 'string' ) e = document.getElementById(e);
		e.value = v || '';
		e.style.color = '';
	};
	this.getValue = function (e) {
		if ( typeof e === 'string' ) e = document.getElementById(e);
		return e.value === this.data[ e.id ] ? '' : e.value;
	};
	var i, e;
	for ( i in this.data ) {
		e = document.getElementById(i);
		if ( !e.value.length || e.value === this.data[i] ) {
			e.style.color = '#c0c0c0';
			e.value = this.data[i];
		}
		$EV( e, 'focus', $FB( _focus, this, [e] ) );
		$EV( e, 'blur', $FB( _blur, this, [e] ) );
	}
	function _focus(e) {
		if ( e.value === this.data[ e.id ] ) e.value = '';
		e.style.color = '';
	}
	function _blur(e) {
		if ( e.value.length === 0 || e.value === this.data[ e.id ] ) {
			e.style.color = '#c0c0c0';
			e.value = this.data[ e.id ];
		} else {
			e.style.color = '';
		}
	}
}
var PlsInput = new GrayInput( { 'frStation1': '駅名を入力　例）大手町' } );
function timeSearchClick() {
	PlsInput.clearValue('frStation1');
	document.getElementById('frStationSelect').style.display = 'none';
	document.getElementById('frStationText').style.display = '';
	document.getElementById('frMsg').style.display = 'none';
	return false;
}
