var navjax;
var navbarel;
function navbarajax() {}

navbarajax.prototype.init = function()
{
	this.request = false;
	if(window.XMLHttpRequest)
	{
		this.request = new XMLHttpRequest();
	}
	else if( window.ActiveXObject )
	{
		try
		{
			this.request = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e)
		{
			try
			{
				this.request = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e) { }
		}
	}
	if( !this.request )
	{
		return false;
	}
}

navbarajax.prototype.get = function(url, func)
{
	this.init();
	this.request.onreadystatechange = func;
	this.request.open('GET', url, true);
	this.request.send(null);
}

function handle_navbarajax()
{
	if (navjax.request.readyState == 4 && navjax.request.status == 200)
	{
		navbarel.innerHTML = navjax.request.responseText;
		pos = parseInt((get_window_width() / 2) - 284.5);
		navbarel.style.left = pos + "px";
	}
}
function select_action(zurl, lurl)
{
	if (!document.search.ts.checked)
	{
		document.search.action = zurl;
		document.search.target = "_blank";
	}
	else
	{
		document.search.action = lurl;
		document.search.target = "";
	}
}


function load_z_navbar(url)
{
	navbarel = document.getElementById("ajaxsearchform");
	if (navbarel.innerHTML != "")
	{
		if (navbarel.style.display == "none")
		{
			navbarel.style.display = "";
		}
		else
		{
			navbarel.style.display = "none";
		}
	}
	else
	{
		navjax = new navbarajax;
		navjax.get(url, handle_navbarajax);
	}
	return false;
}

function get_window_width()
{
	if(typeof(window.innerWidth) == 'number')
	{
		return window.innerWidth;
	}
	else if (document.documentElement && document.documentElement.clientWidth)
	{
		return document.documentElement.clientWidth;
	}
    return document.body.clientWidth;
}

var navon = new Array;
function z_navbar_swap(prefix, id)
{
	img = document.getElementById("nav_" + id);
	navon[id] = img.src;
	img.src = prefix + "images/navbar/" + id + "-hi.png";
}

function z_navbar_restore()
{
	for (id in navon)
	{
		if (id.length)
		{
			if (navon[id].length > 0)
			{
				img = document.getElementById("nav_" + id);
				if (img)
				{
					img.src = navon[id];
					navon[id] = "";
				}
			}
		}
	}
}