// List Object
// generic selection widget built primarily to be incorporated into other List-based widgets (MenuList, ScrollList, SelectList)
// 19990410

// Copyright (C) 1999 Dan Steinman
// Distributed under the terms of the GNU Library General Public License
// Available at http://www.dansteinman.com/dynapi/

// Thanks to: Knut Dale <Knut.S.Dale@eto.ericsson.se>

function List(x,y,width,itemH) {	this.isover	= false
	this.name = "List"+(List.count++)
	this.x = x
	this.y = y
	this.w = width
	if (arguments.length==4) {
		this.itemH = itemH
		this.itemHset = true
		this.h = -1
	}
	else {
		this.itemH = null
		this.itemHset = false
		this.h = (is.ns)? -1 : 1000
	}

	this.normalstate			= new Object()
	this.normalstate.fontname	= 'New Time Roman'
	this.normalstate.fontsize	= 8
	this.normalstate.fontstyle	= 'normal'
	this.normalstate.fontweight	= 'normal'
	this.normalstate.fontcolor	= '#000000'
	this.normalstate.bgcolor	= '#E6E6E6'
	this.rollstate				= new Object()
	this.rollstate.fontname		= 'New Time Roman'
	this.rollstate.fontsize		= 8
	this.rollstate.fontstyle	= 'normal'
	this.rollstate.fontweight	= 'normal'
	this.rollstate.fontcolor	= '#000000'
	this.rollstate.bgcolor		= '#AAAAAA'
	this.selectstate			= new Object()
	this.selectstate.fontname	= 'New Time Roman'
	this.selectstate.fontsize	= 8
	this.selectstate.fontstyle	= 'normal'
	this.selectstate.fontweight	= 'normal'
	this.selectstate.fontcolor	= '#FFFFFF'
	this.selectstate.bgcolor	= '#000000'	this.bordercolour			= '#000000'
	this.itemSpacing = 0
	this.visibility = 'inherit'

	this.overOpen = false
	this.menulist = null
	this.indent = 5
	
	this.allowDeselect = false
	this.multiSelect = false
	this.preSelect = null

	this.items = new Array()
	this.selectedIndex = null
	this.obj = this.name + "ListObject"
	eval(this.obj + "=this")

	this.add = ListAdd
	this.build = ListBuild
	this.activate = ListActivate
	this.over = ListOver
	this.out = ListOut
	this.down = ListDown
	this.select = ListSelect
	this.setCols = ListSetCols
	this.image = new Object()
	this.deselect = ListDeselect
	this.onSelect = new Function()	
	this.image.image0 = new Image()
	this.image.image0.src = '/login/images/icons/menunode.gif'
	this.image.image1 = new Image()
	this.image.image1.src = '/login/images/icons/menunode.gif'
	this.image.w = 12
	this.image.h = 18
}
function ListSetCols() {
	this.cols = arguments
	this.multiCol = true
}
function ListAdd(value) {
	var i = this.items.length
	this.items[i] = new Array()
	this.items[i].selected = false
	this.items[i].value = value	this.items[i].text = arguments[1]
	this.items[i].textNormal = arguments[1]
	this.items[i].textSelected = arguments[1]
	this.items[i].textRollover = arguments[1]
	if (arguments[2]) { this.items[i].newWindow = true; } else { this.items[i].newWindow = false; }
	if (this.itemH) {
		this.h += this.itemH+this.itemSpacing
		this.items[i].y = i*this.itemH+i*this.itemSpacing
	}
	else this.items[i].y = 0
}
function ListBuild() {
	this.css = ''
	this.css += css(this.name+'List',this.x,this.y,this.w,this.h,this.bordercolour,(this.itemHset)?this.visibility:'hidden')
	for (var i=0;i<this.items.length;i++) {
		this.css += css(this.name+'ListItem'+i,0,this.items[i].y,this.w,this.itemH,this.normalstate.bgcolor)
		if (this.items[i].hasImage) this.css += css(this.name+'ListItemImgLyr'+i,this.w-this.image.w,this.items[i].y)	}
	this.css += '.'+this.name+'TextNormal {font-weight:"'+this.normalstate.fontweight+'";font-style:"'+this.normalstate.fontstyle+'";font-family:"'+this.normalstate.fontname+'"; font-size:'+this.normalstate.fontsize+'px; color:'+this.normalstate.fontcolor+'; background-color:transparent; margin-left:'+this.indent+'px;}\n'+
	'.'+this.name+'TextSelected {font-weight:"'+this.selectstate.fontweight+'";font-style:"'+this.selectstate.fontstyle+'";font-family:"'+this.selectstate.fontname+'"; font-size:'+this.selectstate.fontsize+'px; color:'+this.selectstate.fontcolor+'; background-color:transparent; margin-left:'+this.indent+'px;}\n'+
	'.'+this.name+'TextRollover {font-weight:"'+this.rollstate.fontweight+'";font-style:"'+this.rollstate.fontstyle+'";font-family:"'+this.rollstate.fontname+'"; font-size:'+this.rollstate.fontsize+'px; color:'+this.rollstate.fontcolor+'; background-color:transparent; margin-left:'+this.indent+'px;}\n'

	this.div = '<div id="'+this.name+'List">\n'
	for (var i=0;i<this.items.length;i++) {		this.items[i].textNormal = '<div class="'+this.name+'TextNormal">'+this.items[i].textNormal + "</div>"		this.items[i].textRollover = '<div class="'+this.name+'TextRollover">'+this.items[i].textRollover + "</div>"		this.items[i].textSelected = '<div class="'+this.name+'TextSelected">'+this.items[i].textSelected + "</div>"
	
		if ((is.ie) && (this.items[i].hasImage)) this.items[i].textNormal = "<table cellpadding=0 cellspacing=0 border=0 width=95%><tr><td align=left valign=middle class="+this.name+"TextNormal>" + this.items[i].textNormal + "</td><td align=right class="+this.name+"TextNormal><img src="+this.image.image0.src+" height="+(this.itemH-2)+" ></td></tr></table>"		if ((is.ie) && (this.items[i].hasImage)) this.items[i].textRollover = "<table cellpadding=0 cellspacing=0 border=0 width=95%><tr><td align=left valign=middle class="+this.name+"TextRollover>" + this.items[i].textRollover + "</td><td align=right class="+this.name+"TextRollover><img src="+this.image.image0.src+" height="+(this.itemH-2)+" ></td></tr></table>"		if ((is.ie) && (this.items[i].hasImage)) this.items[i].textSelected = "<table cellpadding=0 cellspacing=0 border=0 width=95%><tr><td align=left valign=middle class="+this.name+"TextSelected>" + this.items[i].textSelected + "</td><td align=right class="+this.name+"TextSelected><img src="+this.image.image0.src+" height="+(this.itemH-2)+" ></td></tr></table>"				if (is.ie55) {			this.div += '<div id="'+this.name+'ListItem'+i+'" onmouseenter='+this.obj+'.over('+i+'); onmouseleave='+this.obj+'.out('+i+'); onmousedown='+this.obj+'.down('+i+');>'+this.items[i].textNormal+'</div>\n'		} else {			this.div += '<div id="'+this.name+'ListItem'+i+'" onmouseover='+this.obj+'.over('+i+'); onmouseout='+this.obj+'.out('+i+'); onmousedown='+this.obj+'.down('+i+');>'+this.items[i].textNormal+'</div>\n'		}
	}
		this.div += '</div>'
}
function ListActivate() {
	if (is.ie) this.h -= 1001
	this.lyr = new DynLayer(this.name+'List')
	this.lyr.clipInit()

	for (var i=0;i<this.items.length;i++) {
		this.items[i].lyr = new DynLayer(this.name+'ListItem'+i)
		this.items[i].lyr.setbg = DynLayerSetbg		this.items[i].lyr.css.backgroundColor = this.normalstate.bgcolor
	}
	this.lyr.css.visibility = this.visibility
}
function ListOver(i) {	this.isover = true	theParent = (this.menulist.parent)? this.menulist.parent : ""	while(theParent != "") {		theParent.list.isover = true;		theParent = (theParent.list.menulist.parent)? theParent.list.menulist.parent : ""
	}
		if (!this.items[i].selected) {
	   this.items[i].lyr.setbg(this.rollstate.bgcolor)	   this.items[i].lyr.css.color = this.rollstate.fontcolor
	   if (is.ie) this.items[i].lyr.write(this.items[i].textRollover)	   this.items[i].selected = true;
	}
	if (this.overOpen && i!=this.selectedIndex) {
		this.menulist.hideMenu()
		this.deselect(this.selectedIndex)
		if (this.items[i].hasChild) this.select(i)
	}
	this.selectedIndex = i;
}
function ListOut(i) {	this.isover = false
	theParent = (this.menulist.parent)? this.menulist.parent : ""	while(theParent != "") {		theParent.list.isover = false;		theParent = (theParent.list.menulist.parent)? theParent.list.menulist.parent : ""
	}	if (!this.items[i].selected) {	   this.items[i].lyr.setbg(this.normalstate.bgcolor)	   this.items[i].lyr.css.color = this.normalstate.fontcolor
	   if (is.ie) this.items[i].lyr.write(this.items[i].textNormal)	}
}
function ListDown(i) {
	this.select(i)
}
function ListSelect(i) {
	if (this.items[i]!=null) {		this.selectedIndex = i		this.value = this.items[i].value		this.newWindow = this.items[i].newWindow
		this.items[i].lyr.setbg(this.selectstate.bgcolor)	    this.items[i].lyr.css.color = this.selectstate.fontcolor		if (is.ie) this.items[i].lyr.write(this.items[i].textSelected)
		this.items[i].selected = true
		this.onSelect()
	}
}

function ListDeselect(i) {
	if (this.items[i]!=null) {
	   if (this.items[i].selected) {
		//if (this.items[i].hasImage) this.items[i].imagelyr.doc.images[this.name+'ListItemImg'+i].src = this.image.image0.src
		this.items[i].lyr.setbg(this.normalstate.bgcolor)	    this.items[i].lyr.css.color = this.normalstate.fontcolor
		if (is.ie) this.items[i].lyr.write(this.items[i].textNormal)
		this.items[i].selected = false
		if (!this.multiSelect) this.selectedIndex = null
	   }
	}
}
function ListRedirect() {
	location.href = this.value
}
List.count = 0

// Dynlayer setbg() required
function DynLayerSetbg(color) {
	this.css.backgroundColor = color
}

