var xmlHttp
var gSpanId="usgs302", gTierId="", gYear,gState,gView, gExpand='', gExpandCode, gUnits, gFy, gPie, gLocal

var dsi=13;
var keyH="72",keyh="104"
var keyJ="74",keyj="106";
var keyK="75",keyk="107";
var keyL="76",keyl="108";
var x='';
function handler(e) 
{
	if (document.all) {
		var evnt = window.event; 
		x=evnt.keyCode;
	}
	else 
		x=e.charCode;
	var elem1 = document.getElementById('selyear')
	gYear = elem1.value
	elem1 = document.getElementById('selstate')
	gState = elem1.value
	elem1 = document.getElementById('selunits')
	gUnits = elem1.value
	elem1 = document.getElementById('selpie')
	gPie = elem1.value
	elem1 = document.getElementById('selfy')
	if(elem1 == null)
		gFy = 'fy11'
	else	
		gFy = elem1.value
	elem1 = document.getElementById('sellocal')
	gLocal = elem1.value
  
	if (x==keyH || x==keyh) getAjaxSpendingC(gSpanId,gTierId,(gYear-5),gState,gView, gExpand, gExpandCode, 
									gUnits, gFy, gPie, gLocal)
	if (x==keyJ || x==keyj) getAjaxSpendingC(gSpanId,gTierId,(gYear-1),gState,gView, gExpand, gExpandCode, 
									gUnits, gFy, gPie, gLocal)
	if (x==keyK || x==keyk) getAjaxSpendingC(gSpanId,gTierId,(parseInt(gYear)+1),gState,gView, gExpand, gExpandCode,
									gUnits, gFy, gPie, gLocal)
	if (x==keyL || x==keyl) getAjaxSpendingC(gSpanId,gTierId,(parseInt(gYear)+5),gState,gView, gExpand, gExpandCode, 
									gUnits, gFy, gPie, gLocal)
}
/* if (!document.all){
	window.captureEvents(Event.KEYPRESS);
	window.onkeypress=handler;
}
else {
	document.onkeypress = handler;
} */
function incFontSize(p) {
	if (p == "grow") {
		dsi++;
	}
	else {
		dsi--;
	}
	document.getElementById('usgs303').style.fontSize=dsi+"px";
	document.getElementById('usgs342').style.fontSize=dsi+"px";
}
function getQik(spanId)
{
	gSpanId = spanId
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	} 
	var url="usgs_ajax.php"
	url=url+"?p="+spanId
	xmlHttp.onreadystatechange=stateChanged 
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
} 
function getDownAll(codes, group, units, fy, local)
{
	location ="downloadsrs_gr.php?codes="+codes+"&units="+units+"&group="+group+"&fy="+fy
}
function getDownAddCode(codes, code, group, units, fy, local)
{
	location ="downloadsrs_gr.php?codes="+codes+"_"+code
		+"&units="+units+"&group="+group+"&fy="+fy
}
function getAjaxSwitch(spanId,tierCode,year,state,view, expand, units, fy, spendRev, local)
{
	gSpanId = spanId
	gTierId = tierCode
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	} 
	var url="usgr_ajax.php"
	url=url+"?p="+spanId+"&q="+year+"&r="+view+"&s="+expand+"&u="+units+"&v="+fy+"&w="+state+"&x="+spendRev+"&y="+local
	xmlHttp.onreadystatechange=stateChanged 
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
} 
function clean(list1)
{
	var listRtn = '';
	for (var i=0; i < list1.length; i=i+2) {
		if (list1.charAt(i+1) == '0')
			listRtn += list1.slice(i,i+2)
	}
	return listRtn
}
function clean0(list1)
{
	var listRtn = '';
	for (var i=0; i < list1.length; i=i+2) {
		if (list1.charAt(i+1) != '0')
			listRtn += list1.slice(i,i+2)
	}
	return listRtn
}
function getDown(spanId,tierCode, year,state, view, expand, expandCode, units, fy, pie, local)
{
	gSpanId = spanId
	gTierId = tierCode
	gExpand = clean(gExpand)
	var expand2 = clean0(expand)
	gExpand += expand
	gExpandC = expandCode
	url = "usgr_down.php?span="+spanId+"&year="+year+"&view="+view
		+"&expand="+gExpand+"&expandC="+expandCode+"&units="+units+"&fy="+fy+"&local="+local
		+"&state="+state
	window.open(url,'printfriendly','scrollbars=yes,width=600,height=400')
} 
function getDownCsv(spanId,tierCode, year,state, view, expand, expandCode, units, fy, local)
{
	gSpanId = spanId
	gTierId = tierCode
	gExpand = clean(gExpand)
	var expand2 = clean0(expand)
	gExpand += expand
	gExpandC = expandCode
	location = "usgs_down_csv.php?span="+spanId+"&year="+year+"&view="+view
		+"&expand="+gExpand+"&expandC="+expandCode+"&units="+units+"&fy="+fy+"&local="+local
		+"&state="+state+"&spendRev=r"
} 
function getPrint(spanId,tierCode, year,state, view, expand, expandCode, units, fy, pie, local)
{
	gSpanId = spanId
	gTierId = tierCode
	gExpand = clean(gExpand)
	var expand2 = clean0(expand)
	gExpand += expand
	gExpandC = expandCode
	url = "usgr_print.php?span="+spanId+"&year="+year+"&view="+view
		+"&expand="+gExpand+"&expandC="+expandCode+"&units="+units+"&fy="+fy+"&local="+local
		+"&state="+state+"&pie="+pie
	window.open(url,'printfriendly','scrollbars=yes,width=600,height=400')
} 
function getChart(code,view,state,year,units)
{
	location ="downchart_gr.php?chart="+code+"-total&view="+view+"&year="+year+"&state="+state+"&units="+units
} 

function stateChanged() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{ 
	var idCode = gSpanId
	var elem = document.getElementById(idCode+"s")
	var newSpan = document.createElement('span')
	newSpan.id = elem.id
	newSpan.innerHTML = xmlHttp.responseText
	for (var i = 0; i < document.getElementById(idCode).childNodes.length; i++) {
		var n = document.getElementById(idCode).childNodes[i]
		n.parentNode.removeChild(n)
	}
	document.getElementById(idCode).appendChild(newSpan) 
	location.hash = gSpanId + gTierId 
} 
} 
function recordAd(adId) {
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	} 
	var url="recordAd_"+adId
	xmlHttp.onreadystatechange=dummyReturn
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)

} 
function dummyReturn() {
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{ 
	var elem = document.getElementById("loggs")
	var newSpan = document.createElement('span')
	newSpan.id = elem.id
	newSpan.innerHTML = xmlHttp.responseText
	for (var i = 0; i < document.getElementById("logga").childNodes.length; i++) {
		var n = document.getElementById("logga").childNodes[i]
		n.parentNode.removeChild(n)
	}
	document.getElementById("logga").appendChild(newSpan) 
}
}

function GetXmlHttpObject()
{ 
var objXMLHttp=null
if (window.XMLHttpRequest)
{
objXMLHttp=new XMLHttpRequest()
}
else if (window.ActiveXObject)
{
objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
}
return objXMLHttp
}
function show_box1(ani) {
 boxdiv = document.getElementById(ani);
 boxdiv.style.display='block';
 document.body.style.cursor='pointer'
}
function hide_box1(ani) {
 boxdiv = document.getElementById(ani);
 boxdiv.style.display='none';
 document.body.style.cursor='auto'
}
function ToggleDetail(eid)
{
	var r = document.getElementById(eid);
	var q = document.getElementById('detail00');
	var visible = 'table-row';
	if (navigator.appName == 'Microsoft Internet Explorer') visible = 'block'; 
	if(r.style.display != visible) {
		r.style.display = visible;
		gExpand += eid.slice(6,8)
	} else {
		r.style.display = 'none';
		gExpand.replace(eid.slice(6,8),'')
	}
}


