/*************** CHANGE VERSION ***************/
function changeVersion(element){
	if(!window.TEMPLATE_TYPE)return true
	
	if(self.location.href.indexOf("/_temp/") != -1){
		location = element.href // ??? Query + Hash
	} else {
		location = element.href + location.search + location.hash;
	}

	return false;
}

/*************** OPEN LINK ***************/
function openLink(href,target){
	//var href = document.getElementById('a' + ID).href
	if(target == "_blank")
	{
		window.open(href);
	}else{
		location = href
	}
}

/*************** HIDE VISIBLE MENU ***************/
var _visibleMenu
function hideVisibleMenu(){
	if(_visibleMenu)
		_visibleMenu.style.visibility = "hidden"
}

/*************** MOUSE OVER ***************/
function mouseOver(element){
	hideVisibleMenu()

	element.style.backgroundColor = "#F4EBD2"
	//#F4EBD2
	element.style.textDecoration = "underline"

	if(element.id.indexOf("n") == 0)
		showNavigationMenu(element)
	if(element.id.indexOf("u") == 0)
		showUtilityMenu(element)

	return true

	// show utility menu
	function showUtilityMenu(element){
		var menu = document.getElementById("d" + element.id)
		if(!menu) return

		menu.style.top = "108px"
		menu.style.left = getOffsetLeft(element)
		menu.style.visibility = "visible"

		_visibleMenu = menu
	}

	// show navigation menu
	function showNavigationMenu(element){
		var menu = document.getElementById("d" + element.id)
		if(!menu) return

		menu.style.top = getOffsetTop(element)
		menu.style.left = "190px"
		menu.style.visibility = "visible"

		_visibleMenu = menu
	}

}


/*************** MOUSE OVER ***************/
function mouseOverTopNav(element){
	hideVisibleMenu()

	element.style.backgroundColor = "#F0F0F0"
	element.style.textDecoration = "underline"

	if(element.id.indexOf("n") == 0)
		showNavigationMenu(element)
	if(element.id.indexOf("u") == 0)
		showUtilityMenu(element)

	return true

	// show utility menu
	function showUtilityMenu(element){
		var menu = document.getElementById("d" + element.id)
		if(!menu) return

		menu.style.top = "108px"
		menu.style.left = getOffsetLeft(element)
		menu.style.visibility = "visible"

		_visibleMenu = menu
	}

	// show navigation menu
	function showNavigationMenu(element){
		var menu = document.getElementById("d" + element.id)
		if(!menu) return

		menu.style.top = getOffsetTop(element)
		menu.style.left = "190px"
		menu.style.visibility = "visible"

		_visibleMenu = menu
	}

}


/*************** MOUSE OUT ***************/
function mouseOut(element){
	element.style.backgroundColor = "#FFFFFF"
	element.style.textDecoration = "none"
}

/*************** MOUSE OUT ***************/
function mouseOutTopNav(element){
	element.style.backgroundColor = "#E7D7D7"
	element.style.textDecoration = "none"
}

/*************** GET OFFSET LEFT ***************/
function getOffsetLeft(element){
	var offsetLeft = 0
	do {offsetLeft  += element.offsetLeft;}
	while ((element = element.offsetParent));
	return offsetLeft
}

/*************** GET OFFSET TOP ***************/
function getOffsetTop(element){
	var offsetTop = 0
	do {offsetTop  += element.offsetTop;}
	while ((element = element.offsetParent));
	return offsetTop
}

/*************** INIT DHTML MENU ***************/
var _init
function initDhtmlMenu(){
	if(_init) return 
	if(document.body.addEventListener)
		document.body.addEventListener("mousedown", hideVisibleMenu,false)
	else
		document.body.onmousedown = hideVisibleMenu
	_init = true
}

/*************** WRITE DHTML MENU ***************/
function writeDhtmlMenu(items, ID){
	if(!items.length) return

	initDhtmlMenu()
	var text = ''
	text += '<DIV ID="d' + ID + '" STYLE="position:absolute; visibility:hidden;width:175;background-color:red">'
	text += '<TABLE WIDTH="175" BORDER="0" CELLSPACING="0" CELLPADDING="0"><TR><TD BGCOLOR="#999999">'
	text += '<TABLE WIDTH="100%" BORDER="0" CELLSPACING="1" CELLPADDING="4">'
	for(var i=0;i<items.length;i++){
		var linkID = ID + 'i' + i 
		text += '<TR STYLE="cursor:pointer;cursor:hand" ONMOUSEDOWN="openLink(\'' + linkID + '\')" BGCOLOR="#FAF5E6" ONMOUSEOVER="this.style.backgroundColor=\'#F4E9C7\'" ONMOUSEOUT="this.style.backgroundColor=\'#FAF5E6\'">'
		text += '<TD><A HREF="' + items[i].href + '" ID="a' + linkID + '" CLASS="menu">' + items[i].title + '</A></TD>'
		text += '</TR>'
	}
	text += '</TABLE>'
	text += '</TD></TR></TABLE>'
	text += '</DIV>'
	document.write(text)
}