var xmlHttp
var gSpanId="usgs302", gTierId="", gYear,gState,gView, gExpand="", gExpandC, 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 = 'fy12'
	else	
		gFy = elem1.value
	elem1 = document.getElementById('sellocal')
	gLocal = elem1.value
  
	if (x==keyH || x==keyh) getAjaxSpendingC(gSpanId,gTierId,(gYear-5),gState,gView, gExpand, gExpandC, 
						gUnits, gFy, gPie, gLocal)
	if (x==keyJ || x==keyj) getAjaxSpendingC(gSpanId,gTierId,(gYear-1),gState,gView, gExpand, gExpandC, 
						gUnits, gFy, gPie, gLocal)
	if (x==keyK || x==keyk) getAjaxSpendingC(gSpanId,gTierId,(parseInt(gYear)+1),gState,gView, gExpand, gExpandC, 
						gUnits, gFy, gPie, gLocal)
	if (x==keyL || x==keyl) getAjaxSpendingC(gSpanId,gTierId,(parseInt(gYear)+5),gState,gView, gExpand, gExpandC, 
						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)
{
	location ="downloadsrs_gs.php?codes="+codes+"&units="+units+"&group="+group+"&fy="+fy
}
function getDownAddCode(codes, code, group, units, fy)
{
	location ="downloadsrs_gs.php?codes="+codes+"_"+code
		+"&units="+units+"&group="+group+"&fy="+fy
}
function getAjaxSwitch(spanId,tierCode,year,state,view, expand, units, fy,spendRev)
{
	gSpanId = spanId
	gTierId = tierCode
	gView = view
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	} 
	var url="usgs_ajax.php"
	url=url+"?p="+spanId+"&q="+year+"&r="+view+"&u="+units+"&v="+fy+"&w="+state+"&x="+spendRev
	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 getAjaSpendingC(spanId,tierCode, year,state,view, expand, expandCode, units, fy, pie, local)
{
	gSpanId = spanId
	gTierId = tierCode
	gView = view
	gExpand = clean(gExpand)
	var expand2 = clean0(expand)
	gExpand = expand
	gExpandC = expandCode
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request")
		return
	} 
	var url="usgs_ajax.php"
	url=url+"?p="+spanId+"&q="+year+"&r="+view+"&s="+gExpand+"&t="+expandCode+"&u="+units+"&v="+fy+"&w="+state+"&y="+local+"&z="+pie
	xmlHttp.onreadystatechange=stateChanged 
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
} 
function getBudgetSpendingC(spanId,tierCode, year,state, view, expand, expandCode, units, fy, pie, local)
{
	gSpanId = spanId
	gTierId = tierCode
	gExpandC = expandCode
	location = "budget_pie_gs.php?span="+spanId+"&year="+year+"&view="+view
		+"&expand="+expand+"&expandC="+expandCode+"&units="+units+"&fy="+fy+"&local="+local
		+"&state="+state+"#"+spanId+tierCode
} 
function getDown(spanId,tierCode, year,state, view, expand, expandCode, units, fy, pie, local)
{
	gSpanId = spanId
	gTierId = tierCode
	gView = view
	gExpand = clean(gExpand)
	var expand2 = clean0(expand)
	gExpand += expand
	gExpandC = expandCode
	url = "usgs_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, pie, local)
{
	gSpanId = spanId
	gTierId = tierCode
	gView = view
	gExpand = clean(gExpand)
	var expand2 = clean0(expand)
	gExpand += expand
	gExpandC = expandCode
	location = "rev/usgs_down_csv.php?span="+spanId+"&year="+year+"&view="+view
		+"&expand="+gExpand+"&expandC="+expandCode+"&units="+units+"&fy="+fy+"&local="+local
		+"&state="+state
} 
function getPrint(spanId,tierCode, year,state, view, expand, expandCode, units, fy, pie, local)
{
	gSpanId = spanId
	gTierId = tierCode
	gView = view
	gExpand = clean(gExpand)
	var expand2 = clean0(expand)
	gExpand += expand
	gExpandC = expandCode
	url = "usgs_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, local)
{
	gView = view
	location ="downchart_gs.php?chart="+code+"-total&view="+view+"&year="+year+"&state="+state+"&local="+local
} 
*/
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 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 findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {	
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	return [curleft,curtop];
}		
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),'')
	}
}


