/*Funciones de colocación de capas encima de otra capa*/

function coloca()
{
	var divs = document.getElementsByTagName("DIV");

	for(var i=0; i<divs.length;i++)
	{
		if(divs[i].getAttribute("estilo") == "over")
				Posiciona(divs[i]);
		if(divs[i].getAttribute("estilo") == "over1")
				Posiciona1(divs[i]);
	}
	
}

function Posiciona1(t)
{
	var p = t.parentNode;
	t.style.left= Left(p) + Number(t.getAttribute("posX"));
	t.style.top = Top(p) + Number(t.getAttribute("posY"));
}

function Posiciona(t)
{
	var p = t.parentNode;
	t.style.left= Left(p) + Number(t.getAttribute("posX"));
	t.style.top = Top(p) + Number(t.getAttribute("posY"));
}

function Left(t)
{
	var left=0;
	do{
	if(t.tagName == "TD" && window.event){break;}
	left+=t.offsetLeft;t=t.offsetParent;
	}
	while(t!=document && t!=null);
	return left;
}

function Top(t)
{
	var top=0;
	do{
		if(t.tagName == "TD" && window.event){break;}
	top+=t.offsetTop;t=t.offsetParent;}
	while(t!=document && t!=null );
	return top;
}

		
/*Funciones para el manejo del árbol */	

var tr;
var time;
var sel;
var selID=0;
var selSer="";

function ArbolClick(e,t)
{
	var ele = e.srcElement;
	if(!ele) ele = e.target;
	if(ele.tagName=='IMG')
	{
		var exp=t.nextSibling;
		if(exp.style.display!="block")
		{
			ele.src=ele.src.replace("Plus","Minus");
			if(!t.getAttribute("cargado"))
				CargarRamas(t);
			else
				Span(t);
		}
		else 
		{
			ele.src=ele.src.replace("Minus","Plus");
			Span(t);		
		}
	}
	else if(ele.tagName=='B')
	{
		CargarListaProductos(t.getAttribute("idcategory"),"");
		ele.style.backgroundColor="#996";
		ele.style.color="#dddca3";
		if(sel!=null) 
		{
			sel.style.backgroundColor="";
			sel.style.color="";
		}
		sel=ele;
	}
}


function CargarListaProductos(id,sr)
	{
		var url;
	//	var R = NewHttpReq();
		
		if(sr!=null && sr!="")
			{ url = "AxSearch.aspx?txtSearch=" + sr;}
		else
		{if(id==0) 	url = "axOfferList.aspx";else var url = "axProductList.aspx?CategoryId=" + id;}
		top.document.getElementById("Cuerpo").src=url;
/*	
		R.open("get",url,true);
		R.onreadystatechange = function(){
			if(R.readyState != 4) return;
			var text=R.responseText;
			document.getElementById("Cuerpo").innerHTML = text;
			selID=id;
			selSer=sr;
			coloca();};	
		R.send(null);*/
	}


function CargarProducto(t,o)
	{
		var id = t.getAttribute("productID");
		
//		var R = NewHttpReq();
		if(o!=null) o="&o=o"; else o="";
		var url = "axProductDetails.aspx?ProductId="+id+o;
		top.document.getElementById("Cuerpo").src=url;
/*		R.open("get",url,true);
		R.onreadystatechange = function(){
			if(R.readyState != 4) return;
			var text=R.responseText;
			document.getElementById("Cuerpo").innerHTML = text;
			coloca();
		}
		R.send(null);*/
	}
		
function CargarRamas(t)
	{
		var id = t.getAttribute("idcategory");
		var R = NewHttpReq();
		var url = "ucMenuCategorias.aspx?IdPadre=" + id;
		R.open("get",url,true);
		R.onreadystatechange = function(){
			if(R.readyState != 4) return;
			if(R.status == 200)
			{
			var text=R.responseText;
			t.nextSibling.innerHTML = text;
			t.setAttribute("cargado","cargado");
			Span(t);
			}
		}
		R.send(null);
	}

function CargarTexto(id)
	{
		//var id = t.getAttribute("IdTexto");
	//	var R = NewHttpReq();
		var url = "axTexto.aspx?IdTexto=" + id;
		top.document.getElementById("Cuerpo").src=url;
	/*	R.open("get",url,true);
		R.onreadystatechange = function(){
			if(R.readyState != 4) return;
			var text=R.responseText;
			document.getElementById("Cuerpo").innerHTML = text;
			coloca();
		}
		R.send(null);*/
	}

function BuscarTexto(txtSearch)
{
	//var id = t.getAttribute("IdTexto");
	if(txtSearch == "" || txtSearch == null) return;
//	var R = NewHttpReq();
	var url = "AxSearch.aspx?txtSearch=" + txtSearch;
	top.document.getElementById("Cuerpo").src=url;
/*	R.open("get",url,true);
	R.onreadystatechange = function(){
		if(R.readyState != 4) return;
		var text=R.responseText;
		document.getElementById("Cuerpo").innerHTML = text;
		coloca();
	}
	selSer = txtSearch;
	R.send(null);*/
}

		
function NewHttpReq() 
{
    var httpReq = false;
    if (typeof XMLHttpRequest!='undefined') 
		{httpReq = new XMLHttpRequest();}
	else 
		{
		    try {
			    httpReq = new ActiveXObject("Msxml2.XMLHTTP.4.0");
		    } catch (e) {
		    try {
			    httpReq = new ActiveXObject("Msxml2.XMLHTTP");
		    } catch (ee) {
		    try {
			    httpReq = new ActiveXObject("Microsoft.XMLHTTP");
		    } catch (eee) {
			    httpReq = false;
		    }}}
		}
    return httpReq;
}
      
		
function Span(t)
{	
	var o = t.nextSibling;
	if(o.style.display=='none') 
	{
		//Este código consigo ver las  altura real de la capa
		o.style.position="absolute";
		o.style.visibility="hidden";
		o.style.display="block";
		o.style.height="";
		o.h=o.offsetHeight;
		o.style.overflow='hidden';
		o.style.height="10";
		o.style.position="";
		o.style.visibility="";
		tr=o;
		time=window.setInterval(Show,10);
	}else{
		o.style.height=o.offsetHeight;
		o.style.overflow='hidden';
		tr=o;
		time=window.setInterval(Hidden,10);
	}
}	
		
function Show()
{
	tr.style.height= tr.offsetHeight+25;
	if(tr.offsetHeight >= tr.h){
	tr.style.overflow="";window.clearInterval(time);}
}

function Hidden()
{
	tr.style.height= tr.offsetHeight-25;
	if (tr.offsetHeight<=10) {tr.style.display='none';window.clearInterval(time);}
}

function Ini()
{
	coloca();
}	

window.onload = Ini;
window.onresize=coloca;	


