// johnny cison
// www.ans.org

var menu_last=null, menu_open=null, menu_close=null;

function menu(cat)
{
	if (document.getElementById)
	{
		var other;
		if (cat == menu_last) { other=null; } else { other=menu_last; }
		menu_last=cat;

		if (menu_close) { menu_ka(); menu_op(); }
		else { menu_open=setTimeout('menu_op()', 70); }

		if (other) { document.getElementById('d_xmenu_'+other).style.visibility='hidden'; document.getElementById('l_menu_'+other).className=null; }
	}
}

function menu_op() { document.getElementById('d_xmenu_'+menu_last).style.visibility='visible'; document.getElementById('l_menu_'+menu_last).className='hl'; menu_open=null; }

function menu_ka() { clearTimeout(menu_close); menu_close=null; }

function menu_dn()
{
	if (menu_open) { clearTimeout(menu_open); menu_open=null; } else { menu_close=setTimeout('menu_h()', 500); }
}

function menu_h()
{
	if (document.getElementById) { document.getElementById('d_xmenu_'+menu_last).style.visibility='hidden'; document.getElementById('l_menu_'+menu_last).className=null; menu_close=null; }
}

function menu_li(o) { var matches=o.innerHTML.match(/href="([^"]+)"/); document.location=matches[1]; }

function qsearch_focus() { if (document.f_qsearch['q'].value == 'Search') { document.f_qsearch['q'].value=''; } }
function qsearch_blur() { if (document.f_qsearch['q'].value.length == 0) { document.f_qsearch['q'].value='Search'; } }

function refreshto(url, sec) { setTimeout("document.location='"+url+"'", (sec*1000)); }

function submitting(o) { o.disable=true; o.style.background='#999'; }

function browseto(url, q)
{
	var pgcode, suffix='';

	if (q)
	{
		if (url.search(/\?/) == -1) { pgcode='?pg='; } else { pgcode='&pg='; }
	}
	else
	{
		pgcode='pg_';
		if (url.substr(url.length-1,1) != '/') { suffix='/'; }
	}

	var fptr=document.getElementById('f_browse');
	var pg=fptr.pg.options[fptr.pg.selectedIndex].value;
	if (pg == 1) { document.location=url; } else { document.location=url+suffix+pgcode+pg; }
}

function req_init()
{
	var req;

	if (window.XMLHttpRequest && (! window.ActiveXObject))
	{
		try { req=new XMLHttpRequest(); }
		catch (e) { req=false; }
	}
	else if (window.ActiveXObject)
	{
		try { req=new ActiveXObject("Msxml2.XMLHTTP"); }
		catch (e)
		{
			try { req=new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { req=false; }
		}
	}

	return req;
}

function req_send(url)
{
	var req=req_init();

	if (req)
	{
		var lt=new Date();
		if (url.indexOf('?') == -1) { url += '?'; } else { url += '&'; }
		url += 'rqt='+lt.getTime();

		req.open('GET', url, true);
		req.onreadystatechange=function() { if (req.readyState == 4) { req_process(req.responseText); } }
		req.send(null);
	}
}

function req_post(url, params)
{
	var req=req_init();

	if (req)
	{
		req.open('POST', url, true);
		req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		req.setRequestHeader("Content-Length", params.length);
		req.setRequestHeader("Connection", "close");
		req.onreadystatechange=function() { if (req.readyState == 4) { req_process(req.responseText); } }
		req.send(params);
	}
}

function req_process(text) { eval(text); }
