var lastItemSrcindex=-1;
var curItemClass="ListItem";
var lastItemSelectedSrcindex=-1;
var lastItemSelectedClass="";

var selectedObjClass="";
var selectedObj;
var bObjSelected=false;

//eventhandler for mouseover line item
function over(e){
 eventobj = getElement(e);
 for(var obj=eventobj; ((obj.tagName!="TR")&&(obj.parentNode)); obj=obj.parentNode);
 if(obj.tagName=="TR"){
  curItemClass=obj.className
  obj.className="ListItemHover"
 }
}

function getElement(e){
	if (e) eventobj = e.currentTarget;
	else eventobj = event.srcElement;
	return eventobj;
}
//eventhandler for mouseout for line item
function out(e){
	eventobj = getElement(e);
	for(var obj=eventobj; ((obj.tagName!="TR")&&(obj.parentNode)); obj=obj.parentNode);
	if(obj.tagName=="TR"){
		obj.className=curItemClass
	}
}

//eventhandler for mousedown for line item
//if element does not have an ID we assume the user ment to select the item
function down(e){
	obj = getElement(e);
	if (eventobj.ignore==1) {
		for(; ((obj.tagName!="TR")&&(obj.parentNode)); obj=obj.parentNode);
		obj.className=curItemClass;
		return true;
	}
	if(obj.id==""){
		for(; ((obj.tagName!="TR")&&(obj.parentNode)); obj=obj.parentNode);
		if((obj.tagName=="TR")&&(obj.className.substring(0,8)=="ListItem")){
			itemClick(obj)
			if (document.all){
				for(var i=obj.sourceIndex; (v_id=document.all[i].id)!="i";i++);
				if(document.all[i].href.substring(0,10)=='javascript'){
					eval(document.all[i].href);
				}else if(document.all[i].target=='_self'){
					document.location.href = document.all[i].href;
				}else if(parent){
					var target = eval('parent.' + document.all[i].target);
					target.location.href = document.all[i].href;
				}
			}else{
				obj = obj.childNodes[1]
				for(var i=obj.childNodes.length-1; i>=0; i--){
					if (obj.childNodes[i].id=="i") {
						obj = obj.childNodes[i];
						break
					}
				}
				if(obj.href.substring(0,10)=='javascript'){
					eval(obj.href);
				}else if(obj.target=='_self'){
					document.location.href = obj.href;
				}else if(parent){
					var target = eval('parent.' + obj.target);
					target.location.href = obj.href;
				}
			}
		}
	}
	return false;
}

// function that is called when the page is loaded
function eventhandlers(){
 var i
 //attach eventhandler for mouseclick
 //document.onclick=change;
 //attach eventhandlers to line items (mouseout/in)
 var tr = document.getElementsByTagName("TR")
 for (i=0 ; i < tr.length ; i++){
  if (tr[i].className){
   var className=tr[i].className.substring(0,8);
   if ((className=="ListItem")){
    tr[i].onmouseout = out;
    tr[i].onmouseover = over;
    tr[i].onmousedown = down;
   }
  }
} 

 //scroll selected line item into view
 //if (document.all[i]){
 // lastItemSrcindex=document.all[i].sourceIndex;
 // document.all[i].scrollIntoView(false)
 //}

 //mark chosen line item
 //if (document.all["i"]){
 // document.all["i"].className="ListItemSelected";
 //}
}

function itemClick(obj){
	if (bObjSelected) {
		selectedObj.className=selectedObjClass;
		if (selectedObj!=obj) selectedObjClass=curItemClass;
	}else{ 
		selectedObjClass=curItemClass;
		bObjSelected=true;
	}
	obj.className="ListItemSelected";
	selectedObj=obj;
	curItemClass="ListItemSelected"; //Stop the mouse out resetting selection
}


//eventhandler for mouseclick - Not currently Used
//function change(){
	//if((!document.all)||(!document.all[i])) return;
//	var id=event.srcElement.id,srcIndex = event.srcElement.sourceIndex,i,v_id,subject,src,fw,newSrc,aImgs,aChildren,strTmp;

//	for(i=srcIndex; (v_id=document.all[i].className.substring(0,8))!="ListItem";i--);
//	itemClick(i)
//}

window.onload=eventhandlers
 