function Colapse(nombre,x,y,ancho,alto,claseA,claseB,claseC,colorA,colorB,colorBG,imgB,imgC,imgD,imgPC,imgPA,imgPP,niveles,velocidad,resolution,visto){
	this.nombre=nombre;
	this.array= new Array();
	this.claseA=claseA;
	this.claseB=claseB;
	this.claseC=claseC;
	this.colorA=colorA;
	this.colorB=colorB;
	this.colorBG=colorBG;
	this.str='';
	this.imgB=imgB;
	this.imgC=imgC;
	this.imgD=imgD;
	this.imgPC=imgPC;
	this.imgPA=imgPA;
	this.imgPP=imgPP;
	this.visto=visto || new Array(-1,-1,-1,-1);//5niveles esperados
	this.capa='Utopia127'; 
	this.posx=arguments[1];
	this.posy=y;
	this.width=ancho;
	this.height=alto;
	this.velocidad=velocidad || 10;
	this.res=resolution || 4;
	this.maxScDn;
	this.maxScUp;
	this.bool = false;
	this.createColapse=createColapse;
	this.wDivC=wDivC;
	this.refreshC=refreshC;
	this.ponvisto=ponvisto;
	this.calculaH=calculaH;
	this.moveScUp=moveScUp;
	this.moveScDn=moveScDn;
	this.stopMove=stopMove;
	this.reanimate=reanimate;
	this.animate=animate;
	this.delay=delay;
	this.retornaObject=retornaObject;
	this.retornaUndefined=retornaUndefined;
	this.setCadenaHijo=setCadenaHijo;
	this.setCadenaPadre=setCadenaPadre;
	this.z=0;
	this.k=0;
	this.d=0;
	this.tiempo;
	this.tiempo2;
	
	for(var x=0;x<niveles.length;x++){
		this.array[x]=new Array();
		for (var xx=0; xx<niveles[x].length; xx++){
			this.array[x][xx]=niveles[x][xx];//hijos de x
			if(this.retornaObject(this.array[x][xx])){//los hijos de x tienen hijos
				this.array[x][xx]=new Array();
				for (var xxx=0; xxx<niveles[x][xx].length; xxx++){
					this.array[x][xx][xxx]=niveles[x][xx][xxx];//hijos de xx
					if(this.retornaObject(this.array[x][xx][xxx])){//los hijos de xx tienen hijos
						this.array[x][xx][xxx]=new Array();
						for (var xxxx=0; xxxx<niveles[x][xx][xxx].length; xxxx++){//los hijos de xxx
							this.array[x][xx][xxx][xxxx]=niveles[x][xx][xxx][xxxx];
							if(this.retornaObject(this.array[x][xx][xxx][xxxx])){//los hijos de xxx tienen hijos
								this.array[x][xx][xxx][xxxx]=new Array();
								for (var xxxxx=0; xxxxx<niveles[x][xx][xxx][xxxx].length; xxxxx++){//los hijos de xxxx
									this.array[x][xx][xxx][xxxx][xxxxx]=niveles[x][xx][xxx][xxxx][xxxxx];
								}
								this.array[x][xx][xxx][xxxx][(niveles[x][xx][xxx][xxxx].length)]=false;
							}
						}
						this.array[x][xx][xxx][(niveles[x][xx][xxx].length)]=false;
					}
				}
				this.array[x][xx][(niveles[x][xx].length)]=false;
			}
			
		}
		this.array[x][(niveles[x].length)]=false;
	}
	this.createColapse();
}
function retornaObject(o){
	if(typeof(o)=='object')	return true;
	else return false;
}
function retornaUndefined(o){
	if(typeof(o)=='undefined') return true;
	else return false;
}
function stopMove(){
	clearTimeout(this.tiempo);
}
function animate(){
	this.tiempo = setTimeout(this.nombre+'.moveScDn()',this.velocidad);
}

function ponvisto(){

	var nNiveles = 0;
	if((arguments[3]!=null) && (!this.retornaUndefined(arguments[3]))){
		
		if((this.visto[3]!=-1)&&(this.visto[3]!=arguments[3]))
			this.array[arguments[0]][arguments[1]][arguments[2]][this.visto[3]][(this.array[arguments[0]][arguments[1]][arguments[2]][this.visto[3]].length-1)]=!this.array[arguments[0]][arguments[1]][arguments[2]][this.visto[3]][(this.array[arguments[0]][arguments[1]][arguments[2]][this.visto[3]].length-1)];
		
		this.array[arguments[0]][arguments[1]][arguments[2]][arguments[3]][(this.array[arguments[0]][arguments[1]][arguments[2]][arguments[3]].length-1)]=!this.array[arguments[0]][arguments[1]][arguments[2]][arguments[3]][(this.array[arguments[0]][arguments[1]][arguments[2]][arguments[3]].length-1)];
		(this.visto[3]==arguments[3]) ? this.visto[3]=-1 : this.visto[3]=arguments[3];
		nNiveles = 3;
	}else if((arguments[2]!=null) && (!this.retornaUndefined(arguments[2]))){
		
		if((this.visto[2]!=-1)&&(this.visto[2]!=arguments[2])){
			if(typeof(this.array[arguments[0]][arguments[1]][this.visto[2]])!='undefined')
				this.array[arguments[0]][arguments[1]][this.visto[2]][(this.array[arguments[0]][arguments[1]][this.visto[2]].length-1)]=!this.array[arguments[0]][arguments[1]][this.visto[2]][(this.array[arguments[0]][arguments[1]][this.visto[2]].length-1)];
		}
		this.array[arguments[0]][arguments[1]][arguments[2]][(this.array[arguments[0]][arguments[1]][arguments[2]].length-1)]=!this.array[arguments[0]][arguments[1]][arguments[2]][(this.array[arguments[0]][arguments[1]][arguments[2]].length-1)];
		(this.visto[2]==arguments[2]) ? this.visto[2]=-1 : this.visto[2]=arguments[2];
		nNiveles = 2;
		
	}else if((arguments[1]!=null) && (!this.retornaUndefined(arguments[1]))){
		
		if((this.visto[1]!=-1)&&(this.visto[1]!=arguments[1]))
			this.array[arguments[0]][this.visto[1]][(this.array[arguments[0]][this.visto[1]].length-1)]=!this.array[arguments[0]][this.visto[1]][(this.array[arguments[0]][this.visto[1]].length-1)];
		
		this.array[arguments[0]][arguments[1]][(this.array[arguments[0]][arguments[1]].length-1)]=!this.array[arguments[0]][arguments[1]][(this.array[arguments[0]][arguments[1]].length-1)];
		(this.visto[1]==arguments[1]) ? this.visto[1]=-1 : this.visto[1]=arguments[1];
		nNiveles = 1;
	}else{
		if ((arguments[0]!=null) && (!this.retornaUndefined(arguments[0]))) {
				if((this.visto[0]!=-1)&&(this.visto[0]!=arguments[0]))
					this.array[this.visto[0]][(this.array[this.visto[0]].length-1)]=!this.array[this.visto[0]][(this.array[this.visto[0]].length-1)];

				this.array[arguments[0]][(this.array[arguments[0]].length-1)]=!this.array[arguments[0]][(this.array[arguments[0]].length-1)];
				(this.visto[0]==arguments[0]) ? this.visto[0]=-1 : this.visto[0]=arguments[0];
		}
	}
	return true;
    
}
function setCadenaHijo(clase,ancho,color,evaluacion,enlace,colspan1,colspan2,contenido1,contenido2){

	var Str = '<tr>';
	Str += '<td class='+clase+' width='+ancho+'>'+contenido1+'</td>';
	for(var h=0;h<colspan1-1;h++)
		Str += '<td class='+clase+' bgcolor="'+color+'" width='+ancho+'>'+contenido1+'</td>';
	Str += '<td bgcolor="'+color+'" colspan='+colspan2+'>';
	Str += contenido2+'<a class='+clase+' href=javascript:'+evaluacion+'>&nbsp;'+enlace+'</a>';
	Str += '</td></tr>';
	return Str;
}
function setCadenaPadre(clase,ancho,color,evaluacionNivel,evaluacion,enlace,colspan1,colspan2,contenido1,contenido2){
	var Str = '<tr>';
	Str += '<td class='+clase+' width='+ancho+'>'+contenido1+'</td>';
	for(var h=0;h<colspan1-1;h++)
		Str += '<td class='+clase+' bgcolor="'+color+'" width='+ancho+'>'+contenido1+'</td>';
	Str += '<td bgcolor="'+color+'" colspan='+colspan2+'>';
	Str += contenido2+'<a class='+clase;
	if(document.all)
		Str += ' onclick='+evaluacionNivel+';'+evaluacion+' href="javascript:void(null)">&nbsp;'+enlace+'</a>';
	else
		Str += ' href=javascript:'+evaluacionNivel+';'+evaluacion+'>&nbsp;'+enlace+'</a>';
	Str += '</td></tr>';
	return Str;
}
function refreshC(niv,niv2,niv3,niv4){
	this.ponvisto(niv,niv2,niv3,niv4);
	this.str = '<table border=0 cellpadding=0 cellspacing=1 width='+this.width+'>';
	this.str += '<tr><td width=10 class=sp2>&nbsp;</td><td width=10 class=sp2>&nbsp;</td><td width=10 class=sp2>&nbsp;</td><td width=10 class=sp2>&nbsp;</td><td width=120 class=sp2>&nbsp;&nbsp;&nbsp;</td></tr>';
	for(var z=0;z<this.array.length;z++){	
// nivel 1
		if(this.array[z][(this.array[z].length-1)]){ //no estaba desplegado : sumamos su hijo
			evaluacionNivel = this.nombre+'.refreshC('+z+')';
			this.str += setCadenaPadre(this.claseA,10,this.colorA,evaluacionNivel,this.array[z][0].split("|")[1],this.array[z][0].split("|")[0],1,4,this.imgB,this.imgC);
			for (var hijo=1; hijo<(this.array[z].length-1); hijo++) {
				if(!this.retornaObject(this.array[z][hijo])){//no tiene hijos
					this.str += this.setCadenaHijo(this.claseB,10,this.colorB,this.array[z][hijo].split("|")[1],this.array[z][hijo].split("|")[0],1,4,'&nbsp;',this.imgPP)
				}else{//tiene hijos
//nivel 2
					if(this.array[z][hijo][(this.array[z][hijo].length-1)]){//no estaba desplegado : sumamos su hijo
//el padre de 2n
						var evaluacionNivel = this.nombre+'.refreshC('+z+','+hijo+')';
						this.str += setCadenaPadre(this.claseB,10,this.colorB,evaluacionNivel,this.array[z][hijo][0].split("|")[1],this.array[z][hijo][0].split("|")[0],1,4,'&nbsp;',this.imgPA);
//los hijos de 2n
						for(var zz=1;zz<this.array[z][hijo].length-1;zz++){
							if(!this.retornaObject(this.array[z][hijo][zz])){//no tiene hijos
								this.str += this.setCadenaHijo(this.claseB,10,this.colorB,this.array[z][hijo][zz].split("|")[1],this.array[z][hijo][zz].split("|")[0],2,3,'&nbsp;',this.imgPP)
							}else{//tiene hijos
//nivel 3
								if(this.array[z][hijo][zz][(this.array[z][hijo][zz].length-1)]){////no estaba desplegado : sumamos su hijo
//el padre de 3n
									evaluacionNivel = this.nombre+'.refreshC('+z+','+hijo+','+zz+')';
									this.str += setCadenaPadre(this.claseB,10,this.colorB,evaluacionNivel,this.array[z][hijo][zz][0].split("|")[1],this.array[z][hijo][zz][0].split("|")[0],2,3,'&nbsp;',this.imgPA);

//los hijos de 3n
									for(var zzz=1;zzz<this.array[z][hijo][zz].length-1;zzz++){
										if(!this.retornaObject(this.array[z][hijo][zz][zzz])){//no tiene hijos
											
											this.str += this.setCadenaHijo(this.claseB,10,this.colorB,this.array[z][hijo][zz][zzz].split("|")[1],this.array[z][hijo][zz][zzz].split("|")[0],3,2,'&nbsp;',this.imgPP)

										}else{//tiene hijos
//nivel 4
											if(this.array[z][hijo][zz][zzz][(this.array[z][hijo][zz][zzz].length-1)]){////no estaba desplegado : sumamos su hijo
//el padre de 4n
												evaluacionNivel = this.nombre+'.refreshC('+z+','+hijo+','+zz+','+zzz+')';
												this.str += setCadenaPadre(this.claseB,10,this.colorB,evaluacionNivel,this.array[z][hijo][zz][zzz][0].split("|")[1],this.array[z][hijo][zz][zzz][0].split("|")[0],3,2,'&nbsp;',this.imgPA);
//nivel 5 solo hijos que son como padres
												for(var zzzz=1;zzzz<this.array[z][hijo][zz][zzz].length-1;zzzz++)
													this.str += this.setCadenaHijo(this.claseB,10,this.colorB,this.array[z][hijo][zz][zzz][zzzz].split("|")[1],this.array[z][hijo][zz][zzz][zzzz].split("|")[0],4,1,'&nbsp;',this.imgPP)
//cerrando nivel 4	
											}else{//estaba desplegado : restamos al hijo
												
												evaluacionNivel = this.nombre+'.refreshC('+z+','+hijo+','+zz+','+zzz+')';
												this.str += setCadenaPadre(this.claseB,10,this.colorB,evaluacionNivel,this.array[z][hijo][zz][zzz][0].split("|")[1],this.array[z][hijo][zz][zzz][0].split("|")[0],3,2,'&nbsp;',this.imgPC);
											}
										}
									}
//cerrando nivel 3
								}else{//estaba desplegado : restamos al hijo
									evaluacionNivel = this.nombre+'.refreshC('+z+','+hijo+','+zz+')';
									this.str += setCadenaPadre(this.claseB,10,this.colorB,evaluacionNivel,this.array[z][hijo][zz][0].split("|")[1],this.array[z][hijo][zz][0].split("|")[0],2,3,'&nbsp;',this.imgPC);
								}
							}
						}
//cerrando nivel 2
					}else{//estaba desplegado : restamos al hijo
						evaluacionNivel = this.nombre+'.refreshC('+z+','+hijo+')';
						this.str += setCadenaPadre(this.claseB,10,this.colorB,evaluacionNivel,this.array[z][hijo][0].split("|")[1],this.array[z][hijo][0].split("|")[0],1,4,'&nbsp;',this.imgPC);
					}
				}
			}
//cerrando nivel 1
		}else{ //estaba desplegado : restamos al hijo
			evaluacionNivel = this.nombre+'.refreshC('+z+')';
			var contenido1 = (document.all) ? '&nbsp;&nbsp;&nbsp;&nbsp;' : '&nbsp;' ;
			this.str += setCadenaPadre(this.claseA,10,this.colorA,evaluacionNivel,this.array[z][0].split("|")[1],this.array[z][0].split("|")[0],1,4,contenido1,this.imgC);
		}
	}
	this.str += '</table>';
	//alert(this.str)
	this.wDivC();
}
function moveScUp()
{
	if(document.layers)
	{
		var aux = (eval("document.layers['"+this.capa+"'].document.height") - this.height);
		this.maxScUp = this.posy - aux;
		if(eval("document.layers['"+this.capa+"'].top") > this.maxScUp)
		{
			this.z +=this.res;
			this.k = this.z + this.height;
			this.name.top -=this.res;
			this.name.clip.top = this.z;
			this.name.clip.bottom = this.k;
			this.tiempo = setTimeout(this.nombre+'.moveScUp()',this.velocidad)
		}
		else
		{
			if(this.tiempo)
				this.stopMove();
		}
	}
	else
	{
		var aux = (eval('document.all["'+this.capa+'"].offsetHeight') - this.height);
		this.maxScUp = this.posy - aux;
		if(eval('document.all.'+this.capa+'.style.pixelTop') > this.maxScUp)
		{
			this.z +=this.res;
			this.k = this.z + this.height;
			eval('document.all["'+this.capa+'"].style.clip = "rect('+this.z+'px,'+this.width+'px,'+this.k+'px, 0px)"');
			eval('document.all["'+this.capa+'"].style.pixelTop -='+this.res);
			this.tiempo = setTimeout(this.nombre+'.moveScUp()',this.velocidad)
		}
		else
		{
			if(this.tiempo)
				this.stopMove();
		}
	}
}
function moveScDn()
{
	if(document.layers)
	{
		if(eval("document.layers['"+this.capa+"'].top") < this.posy)
		{
			this.z -=this.res;
			this.k = this.z + this.height;
			this.name.top +=this.res;
			this.name.clip.top = this.z;
			this.name.clip.bottom = this.k;
			this.tiempo = setTimeout(this.nombre+'.moveScDn()',this.velocidad)
		}
		else
		{
			if(this.tiempo)
				this.stopMove();
			this.bool=false;
		}
	}
	else
	{
		if(eval('document.all.'+this.capa+'.style.pixelTop') < this.posy)
		{
			this.z -=this.res;
			this.k = this.z + this.height;
			eval('document.all["'+this.capa+'"].style.pixelTop +='+this.res);
			eval('document.all.'+this.capa+'.style.clip = "rect('+this.z+'px,'+this.width+'px,'+this.k+'px,0px)"');
			this.tiempo = setTimeout(this.nombre+'.moveScDn()',this.velocidad)
		}
		else
		{
			if(this.tiempo)
				this.stopMove();
			this.bool=false;
		}
	}
}
function wDivC()
{
	if(document.all){
		this.name.innerHTML = this.str;
	} else {
		this.name.document.open();
		this.name.document.write(this.str);
		this.name.document.close();	
	}
	
	if(document.all) this.delay();
	else this.calculaH();
}
function delay()
{
	if(this.d<50)
	{
		this.d +=10;
		this.tiempo2=setTimeout(this.nombre+'.delay()',10);

	}
	else
	{
		this.calculaH();
		clearTimeout(this.tiempo2);
		this.d=0;
	}
}
function calculaH()
{	
	if(document.all){
		if(eval(this.capa+".offsetHeight")>this.height){
			eval("falsa"+this.capa+".style.visibility = 'visible'")
		}else{
			eval("falsa"+this.capa+".style.visibility = 'hidden'")
			this.animate();
		}
	}else{
		if(eval("document.layers['"+this.capa+"'].document.height")>this.height)
			eval("document.layers['falsa"+this.capa+"'].visibility = 'visible'")
		else{
			eval("document.layers['falsa"+this.capa+"'].visibility = 'hidden'")
			this.animate();
		}
	}
}
function reanimate()
{
	if(document.all)
	{
			this.name.style.clip = "rect(0px,"+this.width+"px,"+this.height+"px,0px)";
			eval('document.all["'+this.capa+'"].style.pixelTop ='+this.posy);
	}
	else
	{
		this.name.clip.bottom = this.height;
		this.name.top = this.posy
	}
}
function createColapse(){
	var lefttit = (document.all) ? 14 : 12;
	eval("Creator('"+this.capa+"',null,"+this.posx+","+this.posy+","+this.width+","+this.height+",'"+this.colorBG+"',null,200,null,null);");
	eval("Creator('"+this.capa+"tit',null,"+(this.posx+lefttit)+","+(this.posy-12)+","+this.width+","+(15)+",'"+this.colorBG+"',null,300,'"+this.imgD+"',null);");
	this.name = (document.all) ? document.all[this.capa] : document.layers[this.capa];	
	this.reanimate();
		
	var scrolstr = '<table border=0 cellspacing=0 cellpadding=0 width=143><tr><td><a href=# onmouseover='+this.nombre+'.moveScDn() onmouseout='+this.nombre+'.stopMove()><img src="../2104/img/scroll1.gif" width=8 height=11 border=0 name=fle0></a></td></tr><tr><td><img src="../2104/img/sp.gif" width=1 height='+(this.height+16)+'></td></tr><tr><td><a href=# onmouseover='+this.nombre+'.moveScUp() onmouseout='+this.nombre+'.stopMove()><img src="../2104/img/scroll3.gif" width=8 height=11 border=0 name=fle1></a></td></tr></table>';
	
	eval("Creator('falsa"+this.capa+"',null,"+(this.posx+this.width -10)+","+(this.posy -20)+",7,null,null,'hide',400,'"+scrolstr+"',null);");	
	
	this.refreshC(null);
}

function redirFramesColapse2(dire){
	parent.mainFrame.document.location=dire; 
}

function redirFramesColapse(dire,soybolsa){
if (typeof(soybolsa)!='undefined' && document.all)
	{
	if (dire.indexOf("#")!=-1)
		{
    	var aux=dire.split("#");
    	dire=aux[0]+"%23"+aux[1];
		}
	}	
	parent.content.location=dire; 
}

if (document.all){
	document.onselectstart=stop;
	document.ondragstart=stop;
}
function stop(){return false;}
