//Código que checa qué tipo de browser es... las variables están disponibles para todas las funciones
var bV=parseInt(navigator.appVersion);
NS4=(document.layers) ? true : false;
IE4=((document.all)&&(bV>=4)) ? true : false;
DOM=(!document.layers && !document.all && bV>=4) ? true : false; // A hack to guess if the browser supports the DOM
capable = (NS4 || IE4 || DOM) ? true : false;

function expandCollapseTable(id, itemCount) {
	//for IE ya está... falta hacer para DOM y NS
	//cambiar la imagen
	
	//oImg = document.all["tbl_img_"+id];
	
	//	Mostrar/esconder las filas
	for (trIndex = 0; trIndex < itemCount; trIndex++) {
		oTR = document.getElementById("tbl_row_"+id+"_"+trIndex);
		//oTR = document.all["tbl_row_"+id+"_"+trIndex];
		if (oTR.style.display == "none") {
			oTR.style.display = "";
		} else {
			oTR.style.display = "none";
		}
	}

	//	Arreglar imagenes
	//tbl_img_
	for (itemIndex = 0; itemIndex < document.images.length ; itemIndex++) {
		//alert("images for "+itemIndex+": id = "+document.images.item(itemIndex).id);
		if ( document.images.item(itemIndex).id.indexOf("tbl_img_"+id) >= 0) {
				if ( oTR.style.display == "" ) {
					document.images.item(itemIndex).src = "imagenes/tree/title_collapse.gif";
				} else {
					document.images.item(itemIndex).src = "imagenes/tree/title_expand.gif";
				}
		} 
	}
	
	//document.links.length
	//window.alert("numLinks: "+ document.links)
	for (itemIndex = 0; itemIndex < document.links.length ; itemIndex++) {
			//window.alert("entramos al for");
			//alert("links for "+itemIndex+": id = "+document.links.item(itemIndex).id);
			if ( document.links.item(itemIndex).id.indexOf("tbl_a_c_"+id) >= 0) {
					if ( oTR.style.display == "" ) {
						document.links.item(itemIndex).style.display = "";
					} else {
						document.links.item(itemIndex).style.display = "none";
					}
			} else if ( document.links.item(itemIndex).id.indexOf("tbl_a_o_"+id) >= 0) {
					if ( oTR.style.display == "" ) {
						document.links.item(itemIndex).style.display = "none";
					} else {
						document.links.item(itemIndex).style.display = "";
					}
			} 
	}
	//window.event.cancelBubble = true;

} //end funtion

function doTableHilight (tableID, hi, doShadow) {
	oTable = document.getElementById("tbl_"+tableID);
	if ( (window.event == null)&&(! hi ) ) {
		oTable.className = "autoTableDim";
		return ;
	}
	//if (oTable.contains( window.event.srcElement )) {
		if (hi) {
			oTable.className = "autoTableHilight";
			if ( (IE4)&&(doShadow) ) {
				if (!oTable.contains(window.event.fromElement)) {
					makeRectangularDropShadow("tbl_"+tableID, 'royalBlue', 5) ;
				}
				event.cancelBuble = true;
			}
			//arreglar las imagenes de abrir/cerrar
		} else {
			oTable.className = "autoTableDim";
			if ( (IE4)&&(doShadow) ) {
				if (!oTable.contains(window.event.toElement)) {
					removeShadow() ;
				}
				event.cancelBuble = true;
			}
			//arreglar las imagenes de abrir/cerrar
		}
	//}
}

window.document.fo_shadows = new Array;		//está afuera de la funcion a propósito
function makeRectangularDropShadow(elStr, color, size) {
	el = document.getElementById(elStr);
	
	var i;
	for (i=size; i>0; i--) {
		var rect = document.createElement('div');
		var rs = rect.style
		//rs.position = 'absolute';
		rs.position = 'absolute';
		//rs.left = (el.style.posLeft + i) + 'px';
		//rs.top = (el.style.posTop + i) + 'px';

		//alert(el.offsetLeft + i) ;
		
		bcr = el.getBoundingClientRect() ;
		
		rs.left = (bcr.left + i -2) + 'px';
		rs.top = (bcr.top + i -2) + 'px';
		//relative->		rs.left = (el.offsetLeft + i) + 'px';
		//relative->		rs.top = (1*el.offsetTop + i - i*el.offsetHeight ) + 'px';
		rs.width = el.offsetWidth + 'px';
		rs.height = el.offsetHeight + 'px';
		
		//rs.zIndex = el.style.zIndex - i;
		
		//rs.backgroundColor = color;
		rs.borderRight = "1px solid "+ color;
		rs.borderBottom = "1px solid "+ color;
		//alert("a");
		//rs.borderColor = color;
		var opacity = 1 - i / (i + 1);
		rs.filter = 'alpha(opacity=' + (100 * opacity) + ')';
		el.insertAdjacentElement('afterEnd', rect);
		window.document.fo_shadows[window.document.fo_shadows.length] = rect;
	}
}

function removeShadow() {
	//if (global.fo_currentMenu){
		global = window.document ;
		var i
		for (i=0; i<global.fo_shadows.length; i++) {
			global.fo_shadows[i].removeNode(true);
		}
		global.fo_shadows = new Array();
		//global.fo_currentMenu.style.display = 'none'
	//}
}

