//cookie名,有効時間(null=100期限なし),path,secure
function Cookie(name,phours,ppath,psecure){
	this.$name = name;
	if (phours){ this.$expiration = (new Date((new Date()).getTime() + phours * 3600000)).toGMTString();
	}else{ this.$expiration='Sun, 19 Sep 2100 06:45:57 GMT'; }
	if (ppath) this.$path = ppath; else this.$path = null;
	if (psecure) this.$secure=1;
}
function _Cookie_load(){
	var allcookies = document.cookie;
	if (allcookies == "") return false;
	var start = allcookies.indexOf(this.$name + '=');
	if (start == -1) return false;
	start += this.$name.length + 1;
	var end = allcookies.indexOf(';',start);
	if (end == -1) end = allcookies.length;
	var cookieval = allcookies.substring(start,end);
	var a = cookieval.split('&');
	for (var i=0; i < a.length; i++) a[i] = a[i].split(':');
	for (var i=0; i < a.length; i++){ this[a[i][0]] = decodeURI(a[i][1]); }
	return true;
}

function _Cookie_store(){
	var cookieval = "";
	for (var prop in this){
		if ((prop.charAt(0) == '$') || ((typeof this[prop]) == 'function')) continue;
		if (cookieval != "") cookieval += '&';
		cookieval += prop + ':' + encodeURI(this[prop]);//escape(this[prop]);
	}
	var cookie = this.$name + '=' + cookieval;
	if (this.$expiration) cookie += '; expires=' + this.$expiration;
	if (this.$path) cookie += '; path=' + this.$path;
	if (this.$secure) cookie += '; secure';
	document.cookie = cookie;
}

function _Cookie_remove(){
	var cookie = this.$name += '=';
	if (this.$path) cookie += '; path=' + this.$path;
	cookie += '; expires=Fri, 02-Jan-1970 00:00:00 GMT';
	document.cookie = cookie;
}
new Cookie();
Cookie.prototype.load = _Cookie_load;
Cookie.prototype.store = _Cookie_store;
Cookie.prototype.remove = _Cookie_remove;


//------------------------ rec

function Rec(s,pe){
	this.sg_sw=1; // suggest OFF(-1:off,-1以外:on)
	this.eki_max=10;
	this.slc = s;	//select_id list
	this.push_eki = pe; //add eki list
	this.ekis=[];
	this.C= new Cookie("HPnorikae002",null,"/",null);
	var r=this.C.load();
	//if( r==false ) this.sg_sw=1;
	if( r && this.C.sg_sw==-1) this.sg_sw=-1;
}

function _Rec_save(){
	this.C.ekistr=this.ekis.join(',')+',';
	this.C.sg_sw=this.sg_sw;
	this.C.store();
}

//配列検索
function func_aIndexOf(arr,len,str){
	for(var i=0;i<len;i++){ if(arr[i]==str)return i; }
	return -1;
}

//REC selectセット (mode=="del":駅リストを作成しない)
function _Rec_SelectBox(mode){
	var dec;
	this.ekis=[];
	if(mode!='del'){
		var ne_l=this.push_eki.length;
		if( this.C.ekistr ){	//add old
			var eki_ar=this.C.ekistr.split(',');
			for(var ii=0,len=eki_ar.length ;ii<len;ii++){
				if( !eki_ar[ii] )continue;
				dec = decodeURI(eki_ar[ii]);
				if( this.push_eki && func_aIndexOf(this.push_eki,ne_l,dec) > -1)continue;
				this.ekis.push(dec);
			}
		}
		if( this.push_eki ){for(var i=0;i<ne_l;i++){this.ekis.unshift(this.push_eki[i]);}}	//add new
		if( this.ekis.length > this.eki_max ) this.ekis.length=this.eki_max;
	}
	//set select
	var ekis_len=this.ekis.length;
	for( var i=0,l=this.slc.length;i<l;i++ ){
		var o=document.getElementById(this.slc[i]);
		if( !o )continue;
		o.options.length = 1;
		o.options[0]= new Option("▼履歴","-");
		for(var j=0;j<ekis_len;j++ ){ o.options[j+1]= new Option(this.ekis[j],this.ekis[j]);}
	}
}
new Rec();
Rec.prototype.SelectBox = _Rec_SelectBox;
Rec.prototype.save = _Rec_save;

// ekIn tapio Exp ----------------------

// xmlhttp 
function initxml(){
	var xmlhttp;
	try {xmlhttp = new ActiveXObject( "Msxml2.XMLHTTP" );}catch (e){try {xmlhttp = new ActiveXObject( "Microsoft.XMLHTTP" );}catch ( E ){xmlhttp = false;}}
	if ( ! xmlhttp && typeof XMLHttpRequest != 'undefined' ){try {xmlhttp = new XMLHttpRequest();}catch (e){xmlhttp = false;}}
	return xmlhttp;
}
// JSON文字化け対策 for safari
function careResponseText( text ){
	if ( navigator.appVersion.indexOf( "KHTML" ) > -1 ) { var esc = escape( text ); if ( esc.indexOf( "%u" ) < 0 && esc.indexOf( "%" ) > -1 ) {text = decodeURIComponent( esc );} }
	return text;
}

function keyCode(e){
	if(document.all) return  e.keyCode;
	else if(document.getElementById) return (e.keyCode)? e.keyCode: e.charCode;
	else if(document.layers) return  e.which;
}

var cgi_path= '/ekiin/cgi-bin/edicc.cgi';

var r2kTbl = {'a':'あ','ba':'ば','bb': [ 'っ', 'b' ],'be':'べ','bi':'び','bo':'ぼ','bu':'ぶ','bya':'びゃ','bye':'びぇ','byi':'びぃ','byo':'びょ','byu':'びゅ','ca':'か','cc': [ 'っ', 'c' ],'cha':'ちゃ','che':'ちぇ','chi':'ち','cho':'ちょ','chu':'ちゅ','co':'こ','cu':'く','cya':'ちゃ','cye':'ちぇ','cyi':'ちぃ','cyo':'ちょ','cyu':'ちゅ','da':'だ','dd': [ 'っ', 'd' ],'de':'で','dha':'でゃ','dhe':'でぇ','dhi':'でぃ','dho':'でょ','dhu':'でゅ','di':'ぢ','do':'ど','du':'づ','dya':'ぢゃ','dye':'ぢぇ','dyi':'ぢぃ','dyo':'ぢょ','dyu':'ぢゅ','e':'え','fa':'ふぁ','fe':'ふぇ','ff': [ 'っ', 'f' ],'fi':'ふぃ','fo':'ふぉ','fu':'ふ','ga':'が','ge':'げ','gg': [ 'っ', 'g' ],'gi':'ぎ','go':'ご','gu':'ぐ','gwa':'ぐぁ','gwe':'ぐぇ','gwi':'ぐぃ','gwo':'ぐぉ','gwu':'ぐぅ','gya':'ぎゃ','gye':'ぎぇ','gyi':'ぎぃ','gyo':'ぎょ','gyu':'ぎゅ','ha':'は','he':'へ','hh': [ 'っ', 'h' ],'hi':'ひ','ho':'ほ','hu':'ふ','hya':'ひゃ','hye':'ひぇ','hyi':'ひぃ','hyo':'ひょ','hyu':'ひゅ','i':'い','ja':'じゃ','je':'じぇ','ji':'じ','jj': [ 'っ', 'j' ],'jo':'じょ','ju':'じゅ','jya':'じゃ','jye':'じぇ','jyi':'じぃ','jyo':'じょ','jyu':'じゅ','ka':'か','ke':'け','ki':'き','kk': [ 'っ', 'k' ],'ko':'こ','ku':'く','kya':'きゃ','kye':'きぇ','kyi':'きぃ','kyo':'きょ','kyu':'きゅ','la':'ら','le':'れ','li':'り','lo':'ろ','lu':'る','lya':'りゃ','lye':'りぇ','lyi':'りぃ','lyo':'りょ','lyu':'りゅ','ma':'ま','me':'め','mi':'み','mm': [ 'っ', 'm' ],'mn':'ん','mo':'も','mu':'む','mya':'みゃ','mye':'みぇ','myi':'みぃ','myo':'みょ','myu':'みゅ','n':'ん','n':'ん','n':'ん','na':'な','ne':'ね','ni':'に','nn':'ん','no':'の','nu':'ぬ','nya':'にゃ','nye':'にぇ','nyi':'にぃ','nyo':'にょ','nyu':'にゅ','o':'お','oh':'おお','oha':'おは','ohe':'おへ','ohi':'おひ','oho':'おほ','ohu':'おふ','pa':'ぱ','pe':'ぺ','pi':'ぴ','po':'ぽ','pp': [ 'っ', 'p' ],'pu':'ぷ','pya':'ぴゃ','pye':'ぴぇ','pyi':'ぴぃ','pyo':'ぴょ','pyu':'ぴゅ','qa':'くぁ','qe':'くぇ','qi':'くぃ','qo':'くお','qq': [ 'っ', 'q' ],'qu':'くう','ra':'ら','re':'れ','ri':'り','ro':'ろ','rr': [ 'っ', 'r' ],'ru':'る','rya':'りゃ','rye':'りぇ','ryi':'りぃ','ryo':'りょ','ryu':'りゅ','sa':'さ','se':'せ','sha':'しゃ','she':'しぇ','shi':'し','sho':'しょ','shu':'しゅ','si':'し','so':'そ','ss': [ 'っ', 's' ],'su':'す','sya':'しゃ','sye':'しぇ','syi':'しぃ','syo':'しょ','syu':'しゅ','ta':'た','tch': [ 'っ', 'ch' ],'te':'て','tha':'てゃ','the':'てぇ','thi':'てぃ','tho':'てょ','thu':'てゅ','ti':'ち','to':'と','tsa':'つぁ','tse':'つぇ','tsi':'つぃ','tso':'つぉ','tsu':'つ','tt': [ 'っ', 't' ],'tu':'つ','tya':'ちゃ','tye':'ちぇ','tyi':'ちぃ','tyo':'ちょ','tyu':'ちゅ','u':'う','va':'う゛ぁ','ve':'う゛ぇ','vi':'う゛ぃ','vo':'う゛ぉ','vu':'う゛','vv': [ 'っ', 'v' ],'wa':'わ','we':'ゑ','wi':'ゐ','wo':'を','wu':'う','ww': [ 'っ', 'w' ],'xa':'ぁ','xe':'ぇ','xi':'ぃ','xo':'ぉ','xtsu':'っ','xtu':'っ','xu':'ぅ','xwa':'ゎ','xya':'ゃ','xyo':'ょ','xyu':'ゅ','ya':'や','ye':'いぇ','yi':'い','yo':'よ','yu':'ゆ','yy': [ 'っ', 'y' ],'za':'ざ','ze':'ぜ','zi':'じ','zo':'ぞ','zu':'ず','zya':'じゃ','zye':'じぇ','zyi':'じぃ','zyo':'じょ','zyu':'じゅ','zz': [ 'っ', 'z' ],'1':'一','2':'二','3':'三','4':'四','5':'五','6':'六','7':'七','8':'八','9':'九'};
function r2k( str ){
	var i; var val = '';
	for ( i=0; i < str.length; ){
	var c=str.charCodeAt( i );
	if ( c>0x7f ){
		val+=str.charAt( i ); i++;
	}else {
		var j; var f=false;
		for ( j=3; j>0; j-- ){
		c=str.substring( i, i+j );
		var type = typeof( r2kTbl[ ''+c ]);
		if ( type == 'string' ){ val+=r2kTbl[ c ]; f=true; break;
		}else if ( type == 'object' ){ val+=r2kTbl[ c ][ 0 ]; str=str.replace( c, r2kTbl[ c ][ 1 ]); j=0; f=true; break; }
		}
		if ( !f ){ j=1; val+=str.charAt( i );}
		i+=j;
	}
	}
	return val;
}

function mkId( id, type, no ){
	var r = '' + id + '_';
	if ( type == 'input' ){ r += 'i' + ekIn.Num;
	}else if ( type == 'select' ){ r += 'l' + ekIn.Num;
	}else { r += 'e' + no; }
	return r;
}

function doInput( id, e ){ //onkeypress  RET only
	if(ekIn.Num < 1 || ekIn.In_sw<1 || !e ) return;
	if( e.keyCode != 13 ) return;

	ekIn.ByInputId[id].focusFlg = 1;
	var dt = new Date();
	var p = ekIn.ByInputId[ ekIn.nowInputObj.id ];
	if ( p.prevTime > 0 &&( p.prevTime + ekIn.intervalTime ) > dt.getTime()){ return; }

	var l = ekIn.ByInputId[ ekIn.nowInputObj.id ].ekList;
	if ( l != null ){
		var v = l.getSelection();
		if ( v != null ){
			var o = document.getElementById( id );
			o.value = l.getSelection();
			p.keyValue = o.value;
			if ( ekIn.selectedCallBack != null ){ ekIn.selectedCallBack( p.id, l.getSelection()); }
			clearSelect( ekIn.nowInputObj.id );
		}
	}
	return false;	//stop submit
}

function doSelect( id, e ){ //onkeydown
	if(ekIn.Num < 1 || ekIn.In_sw<1 || !e || !ekIn.nowInputObj ) return;
	var key=e.keyCode;
	if( key == 13 )return;  //RET
	
	ekIn.ByInputId[id].focusFlg = 1;

	var dt = new Date();
	var p = ekIn.ByInputId[ ekIn.nowInputObj.id ]; if(!p)return;
	if ( p.prevTime > 0 &&( p.prevTime + ekIn.intervalTime ) > dt.getTime()){ return; }

	switch ( key ){

	case 38:	// up arrow
	var l = ekIn.ByInputId[ ekIn.nowInputObj.id ].ekList;
	if ( l != null ){ l.moveUp(); }
	p.prevTime = dt.getTime();
	break;

	case 40:	// down arrow
	var l =  ekIn.ByInputId[ ekIn.nowInputObj.id ].ekList;
	if ( l != null ){ l.moveDown(); }
	p.prevTime = dt.getTime();
	break;

	case 9:		// tab 
	var l =  ekIn.ByInputId[ ekIn.nowInputObj.id ].ekList;
	if ( l != null ){
		if ( l.getSelection() != null ){
			var o = document.getElementById( id );
			o.value = l.getSelection();
			p.keyValue = o.value;
			if ( ekIn.selectedCallBack != null ){ ekIn.selectedCallBack( p.id, l.getSelection()); }
		}
		ekIn.ByInputId[id].focusFlg = 0;
	}
	break;
	}
}

var chIn_Flg=0;  // checkInput ONOFF flag
function checkInput(){
	if(!chIn_Flg) return;
	setTimeout( "checkInput()", ekIn.intervalTime );
	ekIn.fetch();
}

function doDisp( id ){//onfocus
	if(ekIn.Num < 1 || ekIn.In_sw<1 ) return;
	if(document.activeElement){ if(document.activeElement.id != id) return;} // for IE
	ekIn.nowInputObj = document.getElementById( id );
	ekIn.ByInputId[id].focusFlg = 1;
	chIn_Flg=1; setTimeout( "checkInput()", ekIn.intervalTime ); 
	ekIn.ByInputId[id].ekList.show();
	ekIn.ByInputId[id].eokE.value=0;	//eokOFF
}

function doHide( id ){//onblur
	if(ekIn.Num < 1)return;
	if(ekIn.In_sw<1){
		var x = ekIn.ByInputId[id];
		if( x.eokValue != document.getElementById(id).value){ if(x.eokE) x.eokE.value=0;}	//eokOFF
		return;
	}
	chIn_Flg=0;
	if(ekIn.ByInputId[id].ekList.focus=="off"){ ekIn.ByInputId[id].ekList.hide(); }
}

function clearSelect(){
	if ( ! ekIn.nowInputObj) return;
	var l = ekIn.ByInputId[ekIn.nowInputObj.id].ekList;
	if ( l ){
		l.hide();
		l.focus="off";
		l.selectedIndex = -1;
		l.candidatekList = [];
		l.innerHTML = '';
	}
}

// ---------- ### ekList ###
function ekList( id, w, h, n ,hide_select){

	this.id = id + "_l";
	this.focus = "off";

	var s = '<span class="sg_list" id="' + this.id + '" ' +
		'style="visibility: hidden;' +
		'width:' + w + 'px; ' +
		'height:' + h*n + 'px; ' + '">';
		
	for ( var i = 0;  i < n; i ++ ){
		s += '<span id="' + mkId( this.id, 'element', i ) + '"' +
			'onMouseOver="move(' + i + ')" ' +
			'onMouseOUT="offfocus()" ' +
			'onMouseUp="clicklist(' + i + ')" ' +
			'style="position: absolute; '+
			'left:0px; top:'+ h*i +'px; width:'+ w +'px; height:'+ h + 'px ;'+
			'font-size:13px; '+
			'visibility: inherit; '+
			'"></span>';
	}
	s += '</span>';

	this.selectedIndex = -1;
	this.innerHTML = s;
	
	this.hide_slc=new Array();
	for(var ii=0;ii<hide_select.length;ii++){ this.hide_slc[ii]=document.getElementById(hide_select[ii]); }
}
// color
ekList.FontClr_on	='#000';
ekList.FontClr_off	='#000';
ekList.BgClr_on		='#fee573';
ekList.BgClr_off	='#ffffea';

function move( no ){
	var o = ekIn.ByInputId[ ekIn.nowInputObj.id ].ekList;
	if ( o ){
		o.focus="on";
		o.move( no );
	}
}

function offfocus(){
	var l=ekIn.ByInputId[ ekIn.nowInputObj.id ].ekList;
	l.focus="off";
}

function clicklist( no ){
	var p = ekIn.ByInputId[ ekIn.nowInputObj.id ]; if( !p ) return;
	var l = p.ekList; 
	p.keyValue = l.getSelection(); if( !p.keyValue ) return;
	ekIn.nowInputObj.value = p.keyValue;
	if ( ekIn.selectedCallBack != null ){ ekIn.selectedCallBack( p.id, l.getSelection()); }
	clearSelect( ekIn.nowInputObj.id );
}

function _visibleSelect(hide_slc){ //Select表示
	for(var ii=0;ii<hide_slc.length;ii++) hide_slc[ii].style.visibility='visible';
}
function _hideSelect(hide_slc){ //Select非表示
	for(var ii=0;ii<hide_slc.length;ii++) hide_slc[ii].style.visibility='hidden';
}
function _ekList_getSelection(){
	var c = document.getElementById( mkId( this.id, 'element', this.selectedIndex ));
	if ( c ){ return c.innerHTML; }
	return null;
}
ekList.prototype.getSelection = _ekList_getSelection;

function _ekList_setValue( s ){
	if ( s.length <= 0) return;
	this.candidatekList = s;
	var n = this.candidatekList.length;
	if ( n > ekIn.kouhoNum ){ n = ekIn.kouhoNum;}
	else if ( this.candidatekList[ n -1 ] == undefined ){ n--; }	// for IE aware
	document.getElementById( this.id ).style.visibility = 'visible';
	_hideSelect(this.hide_slc);//Select非表示
	this.listNum = n;
	this.selectedIndex = 0;
	for ( var i = 0; i < ekIn.kouhoNum; i ++ ){
		var c = document.getElementById( mkId( this.id, 'element', i ));
		if ( c ){
			c.innerHTML = i < n ? this.candidatekList[ i ]:'';
			this.showElement( i, i == this.selectedIndex );
		}
	}
}
ekList.prototype.setValue = _ekList_setValue;

function _ekList_show(){
	if ( this.selectedIndex < 0 || this.listNum <= 0 )return;
	document.getElementById( this.id ).style.visibility = 'visible';
	_hideSelect(this.hide_slc); //Select hidden
}
ekList.prototype.show = _ekList_show;

function _ekList_hide(){
	_visibleSelect(this.hide_slc);  //Select disp
	document.getElementById( this.id ).style.visibility = 'hidden';
}
ekList.prototype.hide = _ekList_hide;

function _ekList_showElement( no, focus ){
	var c = document.getElementById( mkId( this.id, 'element', no ));
	if ( !c ) return;
	if ( focus ){
		c.style.backgroundColor = ekList.BgClr_on;
		c.style.color = ekList.FontClr_on;
	}else {
		c.style.backgroundColor = ekList.BgClr_off;
		c.style.color = ekList.FontClr_off;
	}
}
ekList.prototype.showElement = _ekList_showElement;

function _ekList_move( no ){
	if ( no >= this.candidatekList.length ){ return; }
	this.showElement( this.selectedIndex, false );
	this.selectedIndex = no;
	this.showElement( this.selectedIndex, true );
}
ekList.prototype.move = _ekList_move;

function _ekList_moveUp(){ if ( this.selectedIndex > 0 ){this.move( this.selectedIndex -1 );} }
ekList.prototype.moveUp = _ekList_moveUp;

function _ekList_moveDown(){ if ( this.listNum -1 > this.selectedIndex ){this.move( this.selectedIndex +1 );} }
ekList.prototype.moveDown = _ekList_moveDown;

// ---------- ### ekIn ###
function ekIn( name ,eok_name, w, h, n,hide_select){
	ekIn.kouhoNum=n;
	this.input_id = name+'_in';
	var q = document.getElementById( this.input_id );
	if ( !q ) return null;

	q.blur();
	q.setAttribute("autocomplete", "off");
	this.focusFlg = 0;
	
	this.id = name+'_sg' ;	// ListBox
	var o = document.getElementById( this.id );
	if ( !o ) return null;
	
	this.ekList = new ekList( this.id, w, h, n ,hide_select);
	this.keyValue = '';
	this.candidatekList = [];
	this.prevTime = 0;
	this.eokValue = '';
	this.eokE = document.getElementsByName( eok_name )[0];
	if ( !this.eokE ) return null;
	if(this.eokE.value==1)this.eokValue=q.value;
	
	ekIn.Num++;
	ekIn.ByInputId[ this.input_id ] = this;
	o.innerHTML = this.ekList.innerHTML;
	if(!ekIn.sg_btn){ ekIn.sg_btn = document.getElementById('js_sg_btn');}
}

function _ekiInput_received(){
	if ( ekIn.xmlhttp.readyState != 4 ){
		return;
	}else if ( ekIn.xmlhttp.status != 200 ){
		if ( ekIn.notifyCallBack != null ){ ekIn.notifyCallBack( 'HTTP エラー:' + ekIn.xmlhttp.status, ekIn.xmlhttp.status ); }
	}else {
		var o = ekIn.ByInputId[ ekIn.nowInputObj.id ];
		if ( o.ekList != null && o.focusFlg == 1 ){
			o.ekList.setValue( eval( careResponseText( ekIn.xmlhttp.responseText )));
		}
	}
}
ekIn.received = _ekiInput_received;

function _ekiInput_fetch(){
	var o= ekIn.nowInputObj;
	var x= ekIn.ByInputId[ ekIn.nowInputObj.id ];
	if ( o.value != '' && x.keyValue == o.value ){ return; }
	x.keyValue = o.value;
	
	if ( o.value == '' ){
		clearSelect();
	}else {
		ekIn.xmlhttp = initxml();
		if ( ekIn.xmlhttp ){
			ekIn.xmlhttp.onreadystatechange = ekIn.received;
			var str = o.value;
			try { str = r2k( str ); }catch ( ignore ){}
			ekIn.xmlhttp.open( 'GET', cgi_path + '?q=' + encodeURI( str ) + '&k=' + ekIn.kp18sw + '&n=' + ekIn.kouhoNum, true );
			ekIn.xmlhttp.send( null );
		}
	}
}
ekIn.fetch = _ekiInput_fetch;

function _ekiInput_onoff( t ){
	if(!ekIn.sg_btn) return;
	if(t == 'on'){
		ekIn.In_sw = 1;
		ekIn.sg_btn.innerHTML='<input type="checkbox" id="Csg" name="Csg" value="1" tabindex="100" onclick="ekIn.onoff(\'off\')" class="rd" checked /><label for="Csg">駅名予測機能</label>';
	}else{
		ekIn.In_sw = -1;
		ekIn.sg_btn.innerHTML='<input type="checkbox" id="Csg" name="Csg" value="1" tabindex="100" onclick="ekIn.onoff(\'on\')" class="rd" /><label for="Csg">駅名予測機能</label>';
	}
}
ekIn.onoff = _ekiInput_onoff;

function _ekiInput_end(){ var id=''; for( id in ekIn.ByInputId ) document.getElementById(id).setAttribute("autocomplete", "on"); }
ekIn.end = _ekiInput_end;

//------------------
ekIn.nowInputObj = null;
ekIn.selectedCallBack = null;
ekIn.notifyCallBack = null;
ekIn.ByInputId = new Object();
ekIn.Num = 0;
ekIn.inputSize = 10;
ekIn.inputMax = 40;
ekIn.kouhoNum = 10;
ekIn.intervalTime = 100;
ekIn.kp18sw = 0; 
ekIn.In_sw = 1;
ekIn.sg_btn = null;

function _ekiInput_setCallBack( f ){ ekIn.selectedCallBack = f; }
ekIn.setCallBack = _ekiInput_setCallBack;

function _ekiInput_setNotify( f ){ ekIn.notifyCallBack = f; }
ekIn.setNotify = _ekiInput_setNotify;

//---------------------------

function rec_In(f,id,v){
	var o=f[id];
	if(v!='-' && o){
		o.value= v;
		if(ekIn.In_sw<1){
			var x = ekIn.ByInputId[ id+'_in' ]; if(!x)return;
			x.eokValue = v;
			if(x.eokE)x.eokE.value=1;	//eokON
		}
	}
}
var hpRec;
function rec_Del(){
	if (window.confirm("乗換案内・駅情報の履歴を削除します。\nよろしいですか？")) {
		hpRec.SelectBox('del');
		hpRec.sg_sw=ekIn.In_sw;
		hpRec.save();
	}
}

function end_ekIn(){
	if(hpRec.sg_sw){hpRec.sg_sw=ekIn.In_sw; hpRec.save(); ekIn.end();}
}

// --------------------------- for form 
function chngEki(fname){
	var f=document.forms[fname];
	if(!f)return false;
	var t=f.eki1.value;f.eki1.value = f.eki2.value;f.eki2.value = t;
	var x1 = ekIn.ByInputId['eki1_in']; if(!x1)return;
	var x2 = ekIn.ByInputId['eki2_in']; if(!x2)return;
	t=x1.eokValue;x1.eokValue=x2.eokValue;x2.eokValue=t;
	if(x1.eokE && x2.eokE){ t=x1.eokE.value;x1.eokE.value=x2.eokE.value;x2.eokE.value=t;}
}
var FlgChckFm=1;
function noChck(){ FlgChckFm=0; }
function chckFm2(f){
	if(FlgChckFm==0) return true;
	var t='';
	if(f.eki1.value.replace(/ /g,'').replace(/　/g,'') == '') t+='出発駅';
	if(f.eki2.value.replace(/ /g,'').replace(/　/g,'') == '') t+='到着駅';
	if( t!='' ){
		var o=document.getElementById('search_msg');
		o.innerHTML='※'+t+'を入力してください。'; o.style.display='block'; return false;
	}
}
function chckFm1(f){
	if(f.eki1.value.replace(/ /g,'').replace(/　/g,'')=='' ){
		var o=document.getElementById('search_msg');
		o.innerHTML='※駅名を入力してください。'; o.style.display='block'; return false;
	}
}


// --------------------------- MAP
function eId(id) {return document.getElementById(id);}
function dispOn(id) {eId(id).style.display = "block";}
function dispOff(id) {eId(id).style.display = "none";}
function dispONOff(id) {o=eId(id);if(o.style.display=="none"){dispOn(id)}else{dispOff(id)}}
function getRadioV(a){ if(!a)return null; for (var i = 0; i < a.length; i++) { if (a[i].checked) return a[i].value;} return null;}

function AjO(func,missfunc){
	this.setFunc=func;
	if(missfunc){ this.missFunc=missfunc;}else{this.missFunc=null;}
	if(AjO.xmlhttp == null){AjO.xmlhttp = initxml();}
}
AjO.xmlhttp = null;	
AjO.SetFunc = null;
AjO.MissFunc = null;

function _AjO_received(){
	if ( AjO.xmlhttp.readyState != 4 ){ return;}else if ( AjO.xmlhttp.status != 200 ){ if ( AjO.MissFunc != null ){ AjO.MissFunc(); }}else { AjO.SetFunc(AjO.xmlhttp.responseText);}
}
AjO.received = _AjO_received;

function _AjO_fetch(wurl){
	var today=new Date();
	var msec=today.getTime();
	if( AjO.xmlhttp ){
		AjO.SetFunc=this.setFunc;
		AjO.MissFunc=this.missFunc;
		AjO.xmlhttp.open( 'GET',wurl+'&msec='+msec,true );
		AjO.xmlhttp.onreadystatechange = AjO.received;
		AjO.xmlhttp.send( null );
	}else{}
}
AjO.prototype.fetch = _AjO_fetch;


//マップで入力（Ajax）
var MapX1;
var MapX2;

var mFo;
//Map Class
function MapClass(){
	this.cgi='/norikae/cgi/map.cgi'; //CGI
	this.title_id='mapTMsg';
	this.tiki_id='mapArea';
	this.cont_id='mapCont';
	this.cont_select_eki_id='mapSlcEki';
	this.msg_id='mapMsg';
	this.box_id='mapBlk';
	//this.dispnone_id='Boxes';
	this.connect_num=-1; //初回起動flg
	this.form_nm=1;
}
var MapC = new MapClass();
var MapD = null;

//error
function map_Error_act(){
	eId(MapC.title_id).innerHTML="<h4>路線から駅を選択</h4>";
	eId(MapC.tiki_id).innerHTML="";
	eId(MapC.cont_id).innerHTML='ただいま 準備中です';
	dispOff(MapC.msg_id);
	dispOff("FMmap");
}

function map_InputEkiForm(test,test2,eki_nm){
	var id;
	mFo["Cmap1"].value=1;
	if(MapC.form_nm==1){
		mFo["eki1"].value=eki_nm;
		id="eki1";
	}else{
		var rd_obj=document.FMmap.map_rd;
		id = getRadioV(rd_obj);
		mFo[ id ].value=eki_nm;
		if(rd_obj[0].checked==true)rd_obj[1].checked=true; else rd_obj[0].checked=true;
	}
	if(ekIn.In_sw<1){
		var x = ekIn.ByInputId[ id+'_in' ]; if(!x)return;
		x.eokValue = eki_nm;
		if(x.eokE)x.eokE.value=1;	//eokON
	}
}

function map_Set(JsonTxt){
	var txt='';
	try{
		var data = eval ( careResponseText("("+ JsonTxt  +")") );
		var Ret=data.ret;
		if(Ret.status != 0){map_Error_act();return;}
		MapD=data.result;
		eId(MapC.title_id).innerHTML=MapD.title;
		eId(MapC.tiki_id).innerHTML=MapD.tiiki;
		if(MapD.mapflg==1){
			var anum=MapD.areanum;
			var alist=MapD.arealist;
			txt = '<div class="mapImg"><map name="tiikimap" id="tiikimap">';
			for(var i=0;i<anum;i++){ txt+='<area shape="rect" coords="'+alist[i].co+'" href="javascript:map_BlockAj('+alist[i].tno+','+alist[i].bno+')" alt="" />';}
			if(MapD.worldflg==1){ txt+='<area shape="rect" coords="'+MapD.world.co+'"  href="'+MapD.world.url+'" target="_blank" alt="世界" />';}
			var mImg=MapD.mapimg;
			txt+='</map><img src="'+mImg.img+'" alt="" border="0" usemap="#tiikimap" width="'+mImg.width+'" height="'+mImg.height+'" /></div>';
			eId(MapC.cont_id).innerHTML='';
			eId(MapC.cont_id).innerHTML=txt;
			dispOff("FMmap");
		}else{
			eId(MapC.cont_id).innerHTML='';
			eId(MapC.cont_id).innerHTML=MapD.cont;
			if(MapC.form_nm==2)dispOn("FMmap");
		}
		eId(MapC.msg_id).innerHTML=MapD.msg;
		dispOn(MapC.msg_id);
		MapC.connect_num=1;
	}catch(e){ map_Error_act(); }
}

function map_Set_EkiList(JsonTxt){
	var txt='';
	try{
		var data = eval ( careResponseText("("+ JsonTxt  +")") );
		var Ret=data.ret;
		if(Ret.status != 0){ map_Error_act();return; }
		MapD=data.result;
		eId(MapC.cont_select_eki_id).innerHTML=MapD.cont;
		eId(MapC.msg_id).innerHTML=MapD.msg;
		dispOn(MapC.msg_id);
	}catch(e){ map_Error_act(); }
}

function map_Close(){
	dispOff(MapC.box_id);
}

function openMapR(f,nm){
	mFo=f;
	if(nm==2)MapC.form_nm=2;
	MapX1 = new AjO(map_Set,map_Error_act);
	MapX2 = new AjO(map_Set_EkiList,map_Error_act);
	if(MapC.connect_num<0){ map_AreaAj(0); }
	dispONOff(MapC.box_id);
}

function map_AreaAj(tno){MapX1.fetch(MapC.cgi+'?tno='+tno);}
function map_BlockAj(tno,bno){MapX1.fetch(MapC.cgi+'?tno='+tno+'&bno='+bno);}
function map_RosenAj(slcObj){MapX2.fetch(MapC.cgi+'?tno='+MapD.tiiki_no+'&bno='+MapD.block_no+'&rnm='+slcObj.value);}


