﻿//window.onload = prepareLinks;

window.onload = function()
{
	prepareLinks();
	highlightNav();
	highlightRegions();

}

function prepareLinks()
{
	var links = document.getElementsByTagName("a");
	for (var i=0; i<links.length; i++)
	{
		if (links[i].getAttribute("className"))
		{
			if (links[i].getAttribute("classname") == "external") 
			{
				if (links[i].getAttribute('title') == '')
					links[i].setAttribute("title","(opens in a new window)");
				links[i].onclick = function()
				{
					OpenNewWindow(this.getAttribute('href'));
					return false;
				}
			}
			else if (links[i].getAttribute('classname').substring(0,6) == 'popup_')
			{
				links[i].setAttribute('title','this is a popup');
				links[i].onclick = function()
				{
					popup(50,50,this.getAttribute('classname').split('_')[1],this.getAttribute('classname').split('_')[2],this.getAttribute('href'));
					return false;
				}
			}
			else
			{
	//			var linkText  = links[i].firstChild.nodeValue;
	//			links[i].setAttribute('title','this is a link to '+linkText);
			}
		}
		else if (links[i].getAttribute("class"))
		{
			if (links[i].getAttribute("class"))
			{
				if (links[i].getAttribute("class") == "external") 
				{
					if (links[i].getAttribute('title') == '')
						links[i].setAttribute("title","(opens in a new window)");
					links[i].onclick = function()
					{
						OpenNewWindow(this.getAttribute('href'));
						return false;
					}
				}
				else if (links[i].getAttribute('class').substring(0,6) == 'popup_')
				{
					links[i].setAttribute('title','this is a popup');
					links[i].onclick = function()
					{
						popup(50,50,this.getAttribute('class').split('_')[1],this.getAttribute('class').split('_')[2],this.getAttribute('href'));
						return false;
					}
				}
			}
		}
  	}
	//fixIeSubmitImage()
}



function popup(x,y,w,h,fn)
{
	NewWindow = window.open(fn,'descr','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=0,scrollbars=1,resizable=1,copyhistory=no,width='+w+',height='+h+', top='+y+',left='+x)
}


function OpenNewWindow(fn)
{
	NewWindow = window.open(fn)
}


function highlightNav(){
	var nav = document.getElementById('main_nav');
	if (nav == null){
		return;
	}
	
	var elements = nav.getElementsByTagName('li');
	var currentElement;
	var theLink;
	var currentPage = window.location.protocol + '//' + window.location.host + window.location.pathname.toLowerCase();
	for (var i = 0; i < elements.length; i++){
		currentElement = elements[i];
		theLink = currentElement .childNodes[0];
		if (currentPage == theLink.href){
			if (currentElement.className != null && currentElement.className != ''){
				currentElement.className += " onpage";
			} else {
				currentElement.className += "onpage"; //alert(currentElement.className)
			}
		}
	}
	//alert(currentPage)
}



function highlightRegions(){
	var nav = document.getElementById('other_regions');
	if (nav == null){
		return;
	}
	
	var elements = nav.getElementsByTagName('li');
	var currentElement;
	var theLink;
	var currentPage = window.location.protocol + '//' + window.location.host + window.location.pathname.toLowerCase();
	for (var i = 0; i < elements.length; i++){
		currentElement = elements[i];
		theLink = currentElement .childNodes[0];
		if (currentPage == theLink.href){
			if (currentElement.className != null && currentElement.className != ''){
				currentElement.className += " onpage";
			} else {
				currentElement.className += "onpage"; //alert(currentElement.className)
			}
		}
	}
	//alert(currentPage)
}


function showEl(id, visible){
	var theEl = document.getElementById(id);
	if(!theEl){
		return;
	}
	
	if (visible) {
		theEl.style.display = '';
	} else {
		theEl.style.display = 'none';
	}
}
