/*
連動リスト ver:030822 + load/save
script written by Mugi (mugi@wa2.so-net.ne.jp)
*/
function List(){
this.items=[]
this.defaultSelected=0
return this
}
List.prototype.add=function(text,value,child){
if(text.charAt(0)=="*"){
text=text.substring(1)
this.defaultSelected=this.items.length
}
this.items[this.items.length]={text:text,value:value,child:child}
}
List.add=function(id,text,value,child){
List[id].add(text,value,child)
}
List.prototype.setAsRoot=function(){
this._selectbox=arguments
this._initNest()
}
List.prototype._initNest=function(){
var o=this,x=-1
if(arguments.length==1)x=arguments[0]
for(var i=0,a=this._selectbox;i<a.length;i++){
if(i>x)o.makeList(a[i])
o=List[o.items[a[i].selectedIndex].child]
a[i].onchange=function(o,i){return function(){o._initNest(i)}}(this,i)
}
if(document.layers){
top.resizeBy(-1,-1)
top.resizeBy(1,1)
}
}
List.prototype.makeList=function(s){
s.options.length=0
for(var i=0;i<this.items.length;i++)
s.options[s.options.length]=new Option(this.items[i].text,this.items[i].value)
s.selectedIndex=this.defaultSelected
}
List.prototype.save=function(type){
var o=this,d="",n
for(var i=0,a=this._selectbox;i<a.length;i++){
o=List[o.items[a[i].selectedIndex].child]
d+=(i?"_":"")+a[i].selectedIndex
}
for(n in List)if(List[n]==this)break
switch(type){
case 1:
window.name="list_data_"+d;break
case 2:
if(parent.frames.listdata)
with(parent.frames.listdata.document){open();write('<html><form><input type=text value="'+d+'"></form></body></html>');close()};break
default:
savecookie("list_cookie_"+n,d)
}
}
List.prototype.restore=function(type){
var o=this,d,n
for(n in List)if(List[n]==this)break
switch(type){
case 1:
d=window.name.substring(10);break
case 2:
d=parent.frames.listdata&&parent.frames.listdata.document.forms.length&&parent.frames.listdata.document.forms[0].elements[0].value;break
default:
d=loadcookie("list_cookie_"+n)
}
if(d){
d=d.split("_")
for(var i=0,a=this._selectbox;i<a.length;i++){
o.defaultSelected=d[i]
o.makeList(a[i])
o=List[o.items[a[i].selectedIndex].child]
}
}
}
/*cookie.js*/
function savecookie(name,data,days){
var d=new Date();d.setTime(d.getTime()+1000*60*60*24*days)
var exp=(arguments.length>2?' ; expires='+d.toGMTString():'')
document.cookie=name+"="+escape(data)+exp
}
function loadcookie(name){
var m=(" "+document.cookie).match((new RegExp(" "+name+"=([^\\s;]+)","g")))
return (m==null?null:unescape(RegExp.$1))
}

