TreeListControlHandler={
nextID	: 0,
getUniqueID	: function(){return this.nextID++;},
allTrees	: new Array(),
preventRowClick	: false,
callExpand	: function(treeID,nodeID){this.allTrees[treeID].allNodes[nodeID].expand();},
callCollapse	: function(treeID,nodeID){this.allTrees[treeID].allNodes[nodeID].collapse();},
callRowClick	: function(treeID,nodeID){this.allTrees[treeID].allNodes[nodeID].click();},
imgConnectMore	: 'connect.more20.gif',
imgConnectEnd	: 'connect.end20.gif',
imgConnectBridge	: 'connect.bridge20.gif',
imgHandleCollapseMore	: 'handle.collapse.more20.gif',
imgHandleCollapseEnd	: 'handle.collapse.end20.gif',
imgHandleExpandMore	: 'handle.expand.more20.gif',
imgHandleExpandEnd	: 'handle.expand.end20.gif',
imgEmpty	: 'empty20.gif',
imgIconDefault	: 'cd.png',
imgLoading	: 'loading.gif',
xmlHTTPStateChange	: function(treeID,nodeID,xmlhttp){this.allTrees[treeID].allNodes[nodeID].xmlCallback(xmlhttp);}}
function TreeListControl(sRootLabel,sIconSrc,hideColumnHeadings,hideRootNode,iframe,roll){
var ecadprint='document.print();'
this.ID=TreeListControlHandler.getUniqueID()
TreeListControlHandler.allTrees[this.ID]=this
this.all=new Array()
this.allNodes=new Array()
this.columns=new Array()
this.rootNode=new TreeListControlNode(true,sIconSrc,null,1)
this.rootNode.columnText[0]='<a href="#" onclick="tree.printSpecial()">'+sRootLabel+'</a>'
this.rootNode.depth=0
this.rootNode.bShowHandle=false
this.rootNode.oTree=this
this.allNodes[this.rootNode.ID]=this.rootNode
this.rendered=false
this.nLabelColumn=0
this.iconPath='/images/tree/20/'
this.showColumnHeadings=hideColumnHeadings ? false : true
this.showRootNode=hideRootNode ? false : true
this.disableRecalc=false
this.roll=roll
this.tiempo=null
this.tiempofinal=null
this.tiempocarga=null}
TreeListControl.prototype.printSpecial=function(){
if(confirm('¿Desea imprimir el Listado?')){
window.print()}}
TreeListControl.prototype.toString=function(){
var str,x
str=''
x=0
for(var i=0;i<this.columns.length;i++){
str+='<div class="tlc_columnheading" style="width:'+this.columns[i].width+'px; left:'+x+'px; '+
'">'+this.columns[i].name+"</div>"
x+=this.columns[i].width}
str='<div id="treelistcontrol'+this.ID+'" class="treelistcontrol" style="width:'+(x+4)+
'px;"><div class="tlc_headings" style="display:expression(TreeListControlHandler.allTrees['+this.ID+
'].showColumnHeadings ? \'block\' : \'none\');">'+str+'</div>'+this.rootNode+'</div>'
this.rendered=true
return str}
TreeListControl.prototype.redraw=function(){}
TreeListControl.prototype.add=function(oNode){
this.rootNode.add(oNode)}
TreeListControl.prototype.addColumn=function(oColumn){
this.columns[this.columns.length]=oColumn}
function TreeListControlColumn(width,name,onclickdisabled){
this.name=name
this.width=width ? width : '100'
this.onclickdisabled=onclickdisabled ? true : false}
function TreeListControlNode(bShowChildren,sIconSrc,sXMLSrc,refKey){
this.columnText=new Array()
this.bShowChildren=bShowChildren ? true : false
this.sIconSrc=sIconSrc ? sIconSrc : null
this.sXMLSrc=(typeof(sXMLSrc)=='string')? sXMLSrc : ''
this.bDynamicNode=this.sXMLSrc.length>0 ? true : false
this.bShowHandle=true
this.refKey=(refKey || refKey==0)? refKey : null
this.ID=TreeListControlHandler.getUniqueID()
this.sImages=''
this.sHandle=''
this.onclick=''
this.useIcon=true
this.nextSibling=null
this.previousSibling=null
this.firstChild=null
this.lastChild=null
this.parentNode=null
this.oTree=null
this.rendered=false
this.pixelh=20}
TreeListControlNode.prototype.toString=function(){
var str='<div class="tlc_node" id="tlcnode'+this.ID+'">'
str+='<div class="tlc_node_row" onmouseenter="this.className=\'tlc_node_row_hover\'"'+
' onmouseleave="this.className=\'tlc_node_row\';" style="cursor:default;'+
(this.parentNode==null ? 'display:expression(TreeListControlHandler.allTrees['+this.oTree.ID+
'].showRootNode ? \'block\' : \'none\');' : '')+'" onclick="if(!TreeListControlHandler.preventRowClick) { '+this.onclick+' }"'+
' onmousedown="if(!TreeListControlHandler.preventRowClick) this.className=\'tlc_node_row_click\';" onmouseup="this.className=\'tlc_node_row_hover\';">'
var c=this.oTree.columns
var x=0
for(var i=0;i<c.length;i++){
str+='<div class="tlc_node_text" style="width:'+c[i].width+'px; left:'+x+'px;"'+
(c[i].onclickdisabled ? ' onmouseenter="TreeListControlHandler.preventRowClick=true;" onmouseleave="TreeListControlHandler.preventRowClick=false;"' : '')+'>'
if(this.oTree.nLabelColumn==i){
if(!this.oTree.disableRecalc)this.recalcImages()
str+='<span>'
str+=this.sImages+this.sHandle+'<img src="'+(this.sIconSrc ? this.sIconSrc : this.oTree.iconPath+TreeListControlHandler.imgIconDefault)+'" width="'+this.pixelh+'" height="'+this.pixelh+'" align="absmiddle">'
str+='</span>&nbsp;'}
if(this.parentNode==null&&this.columnText[i]&&this.oTree.roll<2){
str+='<span><a href="#main" onclick="tree.printSpecial()">'+(this.columnText[i] ? this.columnText[i] : '&nbsp;')+'</a></span></div>'
}else{
str+='<span>'+(this.columnText[i] ? this.columnText[i] : '&nbsp;')+'</span></div>'}
x+=c[i].width}
str+='</div><div id="children'+this.ID+'" class="tlc_node_children" style="display:'+((this.bShowChildren&&this.firstChild)? 'block' : 'none')+'">'
var node=this.firstChild
while(node){
str+=node
node=node.nextSibling}
str+="</div></div>"
this.rendered=true
return str}
TreeListControlNode.prototype.recalcImages=function(){
var h=TreeListControlHandler
this.sImages=''
if(this.parentNode){
if(this.parentNode.parentNode){
this.sImages=this.parentNode.sImages
this.sImages+='<img src="'+this.oTree.iconPath+
(this.parentNode.nextSibling ? h.imgConnectBridge : h.imgEmpty)+
'" width="'+this.pixelh+'" height="'+this.pixelh+'" align="absmiddle">'}
if(this.firstChild || this.bDynamicNode){
if(this.bShowChildren&&!this.bDynamicNode){
this.sHandle='<img src="'+this.oTree.iconPath+
(this.nextSibling ? h.imgHandleCollapseMore : h.imgHandleCollapseEnd)+
'" style="cursor:pointer;"'+
' width="'+this.pixelh+'" height="'+this.pixelh+'" align="absmiddle" onmouseenter="TreeListControlHandler.preventRowClick=true;" onmouseleave="TreeListControlHandler.preventRowClick=false;"'+
' onclick="TreeListControlHandler.callCollapse('+
this.oTree.ID+','+this.ID+');">'
}else{
this.sHandle='<img src="'+this.oTree.iconPath+
(this.nextSibling ? h.imgHandleExpandMore : h.imgHandleExpandEnd)+
'" style="cursor:pointer;"'+
' width="'+this.pixelh+'" height="'+this.pixelh+'" align="absmiddle"'+
' onmouseenter="TreeListControlHandler.preventRowClick=true;"'+
' onmouseleave="TreeListControlHandler.preventRowClick=false;"'+
' onclick="TreeListControlHandler.callExpand('+
this.oTree.ID+','+this.ID+');">'}
}else{
this.sHandle='<img src="'+this.oTree.iconPath+
(this.nextSibling ? h.imgConnectMore : h.imgConnectEnd)+
'" width="'+this.pixelh+'" height="'+this.pixelh+'" align="absmiddle">'}}
if(this.rendered){
var o=document.getElementById('tlcnode'+this.ID).firstChild.childNodes[this.oTree.nLabelColumn].firstChild
o.innerHTML=this.sImages+this.sHandle+(this.useIcon ? '<img src="'+(this.sIconSrc ? this.sIconSrc : this.oTree.iconPath+TreeListControlHandler.imgIconDefault)+'" width="'+this.pixelh+'" height="'+this.pixelh+'" align="absmiddle">' : '')}}
TreeListControlNode.prototype.recalcChildImages=function(){
var node=this.firstChild
while(node){
node.recalcImages()
node.recalcChildImages()
node=node.nextSibling}}
TreeListControlNode.prototype.expand=function(){
var h=TreeListControlHandler
this.bShowChildren=true
var o=document.getElementById('tlcnode'+this.ID)
o.lastChild.style.display='block'
var id1=this.oTree.ID
var id2=this.ID
if(!this.oTree.disableRecalc)this.recalcImages()
//parent.document.getElementById("h_liveclock").value=0
if(this.bDynamicNode){
document.getElementById('tlcnode'+this.ID).firstChild.className='tlc_node_row'
this.bDynamicNode=false
var tempnode=new TreeListControlNode(false,this.oTree.iconPath+'icon.arrow20.gif')
this.oTree.tiempo=new Date()
tempnode.setColumnText(this.oTree.nLabelColumn,'<span style="color:#FF6600"><img src="'+this.oTree.iconPath+h.imgLoading+'"></span>')
this.add(tempnode)
this.xmlhttp=parent.GetXmlHttp()
var treeid=this.oTree.ID
var nodeid=this.ID
this.xmlhttp.onreadystatechange=function(){TreeListControlHandler.xmlHTTPStateChange(treeid,nodeid,this.xmlhttp);}
try{
this.xmlhttp.open("GET",this.sXMLSrc,true)
this.xmlhttp.send(null)
}catch(ex){}}}
TreeListControlNode.prototype.collapse=function(){
this.bShowChildren=false
var o=document.getElementById('tlcnode'+this.ID)
o.lastChild.style.display='none'
var img=o.childNodes[0].childNodes[this.oTree.nLabelColumn].firstChild.lastChild.previousSibling
var id1=this.oTree.ID
var id2=this.ID
img.onclick=function(){TreeListControlHandler.callExpand(id1,id2);return false;}
img.src=this.oTree.iconPath+(this.nextSibling ? TreeListControlHandler.imgHandleExpandMore : TreeListControlHandler.imgHandleExpandEnd)}
TreeListControlNode.prototype.click=function(){}
TreeListControlNode.prototype.setText=function(){
for(var i=0;i<arguments.length;i++)
this.setColumnText(i,arguments[i])}
TreeListControlNode.prototype.setColumnText=function(nColumn,sText){
this.columnText[nColumn]=(sText ? parent.dencodeiso(sText): '')
if(this.rendered){
var o=document.getElementById('tlcnode'+this.ID)
//alert(o)
o.firstChild.childNodes[nColumn].lastChild.innerHTML=this.columnText[nColumn]}}
TreeListControlNode.prototype.add=function(oNode,bNoRedraw,oSibling,bInsertAfter){
if(bNoRedraw)this.oTree.disableRecalc=true
this.bDynamicNode=false
oNode.oTree=this.oTree
oNode.parentNode=this
this.oTree.allNodes[oNode.ID]=oNode
if(!this.firstChild){
this.firstChild=oNode
this.lastChild=oNode
}else{
var node1,node2
if(oSibling){
if(bInsertAfter){
node1=oSibling
node2=oSibling.nextSibling
}else{
node1=oSibling.previousSibling
node2=oSibling}
}else{
node1=this.lastChild
node2=null}
if(node1){
oNode.previousSibling=node1
node1.nextSibling=oNode
}else{
this.firstChild=oNode}
if(node2){
oNode.nextSibling=node2
node2.previousSibling=oNode
}else{
this.lastChild=oNode}}
if(this.oTree.rendered){
var oSib
var html=oNode+''
var oParent=document.getElementById('tlcnode'+this.ID)
if(node1){
oSib=document.getElementById('tlcnode'+node1.ID)
if(window.ActiveXObject){
oSib.insertAdjacentHTML('afterEnd',html)
}else{
var r=document.createRange()
r.setStartBefore(oSib)
var parsedHTML=r.createContextualFragment(html)
if(oSib.nextSibling){
oSib.parentNode.insertBefore(parsedHTML,oSib.nextSibling)
}else{
oSib.parentNode.appendChild(parsedHTML)}}
}else{
if(node2){
oSib=document.getElementById('tlcnode'+node2.ID)
if(window.ActiveXObject){
oSib.insertAdjacentHTML('beforeBegin',html)
}else{
var r=document.createRange()
r.setStartBefore(oSib)
var parsedHTML=r.createContextualFragment(html)
oSib.parentNode.insertBefore(parsedHTML,oSib)}
}else{
oParent.lastChild.innerHTML=html}}
if(this.parentNode)this.expand()
if(!node2&&node1){
node1.recalcImages()
node1.recalcChildImages()}}
if(bNoRedraw)this.oTree.disableRecalc=false}
TreeListControlNode.prototype.insertBefore=function(oNode,bNoRedraw){
this.parentNode.add(oNode,bNoRedraw,this,false)}
TreeListControlNode.prototype.insertAfter=function(oNode,bNoRedraw){
this.parentNode.add(oNode,bNoRedraw,this,true)}
TreeListControlNode.prototype.remove=function(){
this.removeChildren()
var node1=this.previousSibling
var node2=this.nextSibling
if(node1)
node1.nextSibling=node2
else
this.parentNode.firstChild=node2
if(node2)
node2.previousSibling=node1
else
this.parentNode.lastChild=node1
this.oTree.allNodes[this.ID]=null
if(this.refKey !=null)this.oTree.all[this.refKey]=null
if(this.rendered&&this.previousSibling&&!this.nextSibling){
this.previousSibling.recalcImages()
this.previousSibling.recalcChildImages()}
if(!this.parentNode.firstChild){
this.parentNode.recalcImages()}
this.rendered=false
this.parentNode=null
this.nextSibling=null
this.previousSibling=null
this.firstChild=null
this.lastChild=null
return this}
TreeListControlNode.prototype.removeChildren=function(){
var node=this.firstChild
while(node){
node.removeChildren()
this.oTree.allNodes[node.ID]=null
var dead=node
node=node.nextSibling
delete dead}}
TreeListControlNode.prototype.xmlCallback=function(xmlhttp){
var failed
if(this.xmlhttp.readyState==4){
this.oTree.tiempocarga=new Date()
if(this.xmlhttp.status==200){
var xml=parent.GetXmlDom()
if(window.ActiveXObject){
if(xml.loadXML(this.xmlhttp.responseText)){
failed=false
this.firstChild.remove()
if(xml.documentElement){
this.addXMLChildNodes(xml.documentElement,this)}
this.recalcImages()
}else{
failed=true}
}else{
parser=new DOMParser()
var xmltext=this.xmlhttp.responseText
xmlDoc=parser.parseFromString(parent.removeSpacesXML(xmltext),"text/xml")
this.firstChild.remove()
this.addXMLChildNodes(xmlDoc.firstChild,this)
this.recalcImages()
failed=false}
var xml=null
}else{
failed=true}
var xmlhttp=null
if(failed){
this.firstChild.setColumnText(this.oTree.nLabelColumn,'<span style="color:red">Unavailable - '+this.xmlhttp.status+'</span>')
this.firstChild.useIcon=false
this.firstChild.recalcImages()}
this.oTree.tiempofinal=new Date()
parent.putTiempos(this.oTree.tiempo,this.oTree.tiempocarga,this.oTree.tiempofinal)}}
TreeListControlNode.prototype.addXMLChildNodes=function(xml,oParent){
var showchildren,refkey,xmlsrc,onclick,iconsrc,type,field,value,vCData,vCNData
if(xml.childNodes.length>0){
var x=xml.lastChild
while(x){
type=x.getAttribute('type')
if(!type){
showchildren=x.getAttribute('showchildren')
if(!showchildren)showchildren=false
else showchildren=(showchildren=='yes' ? true : false)
refkey=x.getAttribute('refkey')
if(!refkey)refkey=null
xmlsrc=parent.dencodeURL(x.getAttribute('xmlsrc'))
if(!xmlsrc)xmlsrc=null
onclick=parent.dencodeiso(x.getAttribute('onclick'))
if(!onclick)onclick=null
iconsrc=x.getAttribute('iconsrc')
if(!iconsrc)iconsrc=null
var node=new TreeListControlNode(showchildren,iconsrc,xmlsrc,refkey)
node.onclick=onclick
for(var i=0;i<x.childNodes.length-1;i++){
vCData=''
vCNData=x.childNodes[i].firstChild
if(vCNData!=null){
vCData=vCNData.nodeValue}
node.setColumnText(i,parent.dencodeiso(vCData))}
if(oParent.firstChild){
oParent.firstChild.insertBefore(node)
}else{
oParent.add(node)
if(x.lastChild.childNodes.length>0){
this.addXMLChildNodes(x.lastChild,node)}}}
if(type=='TIMER'){
field=x.getAttribute('field')
parent.document.getElementById(field).innerHTML=x.childNodes[0].firstChild.nodeValue}
x=x.previousSibling}}}
