function divisionSet(idName,v){
	document[idName].division.value = v;
}
function setStationVal(v){
	document.railform['stationArray[]'].value = v;
}
function chkStation(){
	if(document.railform['stationArray[]'].value==''){	alert('最寄駅を選択してください');return false;}
}

function setStationVal2(v){
	document.railform2['stationArray[]'].value = v;
}
function chkStation2(){
	if(document.railform2['stationArray[]'].value==''){	alert('最寄駅を選択してください');return false;}
}

function getStation(path,sub) 
{
	if(path.indexOf('tokyo_', 0) != -1)
	{
		path =path.replace('tokyo_','');
		var area = 'tokyo';
	}
	if(path.indexOf('osaka_', 0) != -1)
	{
		path =path.replace('osaka_','');
		var area = 'osaka';
	}
  //path = path.replace('../../','');
  path = 'http://'+location.hostname+'/php_lib/resource/xml_open/'+area+'_line/'+area+'_station/'+path+'.xml';
  //path = 'http://localhost/works/office-navi.jp/html/php_lib/resource/xml_open/'+area+'_line/'+area+'_station/'+path+'.xml';
  if(sub=='tokyo'){
	  sendRequest(on_loadedXML,'','GET',path,true,true);
  }else if(sub=='osaka'){
	  sendRequest(on_loadedXML3,'','GET',path,true,true);
  }else{
	  if(area=='tokyo'){
		  sendRequest(on_loadedXML,'','GET',path,true,true);
	  }else if(area=='osaka'){
		  sendRequest(on_loadedXML2,'','GET',path,true,true);
	  }
	}
}


  
function on_loadedXML(oj)
{
  var res  =  oj.responseXML;

  resOj = new chgXMLtoHTMLOptions(res,document.railform.stationArray);
  
  resOj.addOptions();
}
function on_loadedXML2(oj)
{
  var res  =  oj.responseXML;

  resOj = new chgXMLtoHTMLOptions(res,document.railform.stationArray2);
  
  resOj.addOptions();
}
function on_loadedXML3(oj)
{
  var res  =  oj.responseXML;

  resOj = new chgXMLtoHTMLOptions(res,document.railform2.stationArray2);
  
  resOj.addOptions();
}


function chgXMLtoHTMLOptions(xdoc,oj){

  return {
  
    setItems : function (){
   
      var items = xdoc.getElementsByTagName("items");
      var text = xdoc.getElementsByTagName("text");
      var value = xdoc.getElementsByTagName("value");

			return { 'items':items,'values':value ,'texts':text };
    
    },

    addOptions : function (){
    
      this.delAllOptions(oj)
      var data = this.setItems()
		oj.options[0]=new Option('▽最寄駅を選択','')
      for( i = 0 ; i < data.items.length ; i++ ){
        var text  = data.texts[i].firstChild.nodeValue 
        var value = data.values[i].firstChild.nodeValue
				value = value.substr(0,5);
        oj.options[oj.length]=new Option(text,value)
      }
      
    },
    
    delAllOptions : function (oj){
      var optionIndex = oj.options.length  
      for ( i=0 ; i <= optionIndex ; i++ ){
        oj.options[0]=null
      }
    }
  };
}


function createHttpRequest()
{
	if(window.ActiveXObject){
		try {
			return new ActiveXObject("Msxml2.XMLHTTP") ;
		} catch (e) {
			try {
				return new ActiveXObject("Microsoft.XMLHTTP") ;
			} catch (e2) {
				return null ;
 			}
 		}
	} else if(window.XMLHttpRequest){
		return new XMLHttpRequest() ;
	} else {
		return null ;
	}
}


function sendRequest(callback,data,method,url,async,sload,user,password)
{
	var oj = createHttpRequest();
	if( oj == null ) return null;
	
	var sload = (!!sendRequest.arguments[5])?sload:false;
	if(sload)url=url+"?t="+(new Date()).getTime();

	var ua = navigator.userAgent;
	var safari	= ua.indexOf("Safari")!=-1;
	var konqueror = ua.indexOf("Konqueror")!=-1;
	var mozes	 = ((a=navigator.userAgent.split("Gecko/")[1] )
			?a.split(" ")[0]:0) >= 20011128 ;
	if(window.opera || safari || mozes){
		oj.onload = function () { callback(oj); }
	} else {
	
		oj.onreadystatechange =function () 
		{
			if ( oj.readyState == 4 ){
				callback(oj);
			}
		}
	}
	if(method == 'GET') {
		if(data!=""){
			var encdata = '';
			var datas = data.split('&');
			for(i=0;i<datas.length;i++)
			{
				var dataq = datas[i].split('=');
				encdata += '&'+encodeURIComponent(dataq[0])+'='+encodeURIComponent(dataq[1]);
			}
			url=url + encdata;
		}
	}
	
	oj.open(method,url,async,user,password);

	if(method == 'POST') {
		if(!window.opera){
			oj.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
		} else {
			if((typeof oj.setRequestHeader) == 'function')
				oj.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
		}
	} 

	oj.send(data);

}


function offradio() {
   var ElementsCount = document.areaform.tsubo.length;
   var ElementsCount2 = document.railform.tsubo.length;
   for( i=0 ; i<ElementsCount ; i++ ) {
      document.areaform.tsubo[i].checked = false;
   }
   for( i=0 ; i<ElementsCount2 ; i++ ) {
      document.railform.tsubo[i].checked = false;
   }
}