// Tips boxes handlers

var Tips = new Array();

function OpenTip(id,closeOthers) {
	if (typeof closeOthers != "boolean") {
		var co = true;
	} else {
		var co = closeOthers;
	}
	var tipOpen = document.getElementById("tip"+id+"_Open");
	var tipText = document.getElementById("tip"+id+"_Text");
	var tipHide = document.getElementById("tip"+id+"_Close");
	
	try {
		tipOpen.className = tipOpen.className.replace("Visible","Hidden");
		tipText.className = tipText.className.replace("Hidden","Visible");
		tipHide.className = tipHide.className.replace("Hidden","Visible");
	} catch(e) {
	}
	if (co) {
		for (var i=0;i<Tips.length;i++) {
			var items = GetTipContents(Tips[i]);
			if (items._open != null && items._close != null && items._text != null) {
				if (items._open != tipOpen && items._close != tipHide && items._text != tipText) {
					items._open.className = items._open.className.replace("Hidden","Visible");
					items._close.className = items._close.className.replace("Visible","Hidden");
					items._text.className = items._text.className.replace("Visible","Hidden");
				}
			}
		}
	}
}

function CloseTip(id) {
	var tipOpen = document.getElementById("tip"+id+"_Open");
	var tipText = document.getElementById("tip"+id+"_Text");
	var tipHide = document.getElementById("tip"+id+"_Close");
	
	try {
		tipOpen.className = tipOpen.className.replace("Hidden","Visible");
		tipText.className = tipText.className.replace("Visible","Hidden");
		tipHide.className = tipHide.className.replace("Visible","Hidden");
	} catch(e) {
	}
}

function GetAllTips() {
	var allTips = document.getElementById("_allTips").childNodes;
	for (var i=0;i<allTips.length;i++) {
		if (typeof allTips[i].tagName != "undefined" && allTips[i] != null && allTips[i].tagName.toLowerCase() == "div") {
			// Found a div
			if (allTips[i].className.substr(0,3) == "Tip") Tips.push(allTips[i]);
		}
	}
}

function GetTipContents(tipElement) {
	// Fetches the "open", "text" and "hide" elements
	var ret = {_open:null, _close:null, _text:null};
	if (typeof tipElement != "undefined" && tipElement != null && tipElement.tagName.toLowerCase() == "div" && tipElement.className.substr(0,3) == "Tip") {
		for (var i=0;i<tipElement.childNodes.length;i++) {
			if (typeof tipElement.childNodes[i] != "undefined" && tipElement.childNodes[i] != null && typeof tipElement.childNodes[i].tagName != "undefined" && tipElement.childNodes[i].tagName.toLowerCase() == "div") {
				if (tipElement.childNodes[i].className.indexOf("TipOpen")>-1) {
					ret._open = tipElement.childNodes[i];
				} else if (tipElement.childNodes[i].className.indexOf("TipTextClose")>-1) {
					ret._close = tipElement.childNodes[i];
				} else if (tipElement.childNodes[i].className.indexOf("TipText")>-1) {
					ret._text = tipElement.childNodes[i];
				}
			}
		}
	}
	return ret;
}
