
function showCountyExtLink(theText) {
	var theForestLink = theText.split("|")[0];
	theForestLink = 'javascript:openLink("' + theForestLink + '")';

	var theCoopLink = theText.split("|")[1];
	theCoopLink = 'javascript:openLink("' + theCoopLink + '")';

	var theState = theText.split("|")[2];
	var theText = "For the county-level threat distribution in " + theState + " contact the <a href='" + theForestLink + "'> state forestry agency</a> or the <a href='" + theCoopLink + "'> cooperative extension agency</a>."; + theCoopLink;
	document.getElementById("mapText").innerHTML = theText;	
}

function hideCountyExtLink() {
	document.getElementById("mapText").innerHTML = "&nbsp;<br>&nbsp;";	
}

function openLink(linkURL) {
	var newwin = window.open(linkURL,'newwin','menubar=0,resizable=0,scrollbars=1,status=0,location=0,width=801,height=656');
}

function showCounties() {
	var stateID = document.getElementById('stateLinks').value;
	DWREngine._execute('ThreatSummaryViewer_ThreatAjaxFunctions.cfm', null, 'GetCounties', stateID, listCounties);
}

function listCounties(Counties) {
	theCountyList = document.getElementById('countyLinks');

	DWRUtil.removeAllOptions("countyLinks");			

	for (var i=0;i<Counties.length;i++) { 
		var valText = Counties[i]["FIPSCODE"];
		var nameText = Counties[i]["NAME"].replace(/\s+$/,"");
		
		//replace unit names
		nameText = nameText.replace(/County/g, "");
		nameText = nameText.replace(/Parish/g, "");
		nameText = nameText.replace(/City and Borough/g, "");
		nameText = nameText.replace(/Borough/g, "");
		nameText = nameText.replace(/Census Area/g, "");
		nameText = nameText.replace(/Municipality/g, "");
		nameText = nameText.replace(/Municipio/g, "");
		nameText = nameText.replace("Prince of Wales-Outer Ketchikan", "Prince of Wales-OK");
		nameText = nameText.replace("Skagway-Hoonah-Angoon", "Skagway-Hoonah-Ang.");

		theCountyList.options[theCountyList.options.length] = new Option(nameText, valText);
	}

	//also update the links on the page
	getStateLinks();
	updateCountyLinks()
}

function getStateLinks() {
	var stateID = document.getElementById('stateLinks').value;
	DWREngine._execute('ThreatSummaryViewer_ThreatAjaxFunctions.cfm', null, 'GetStateLinks', stateID, setStateLinks);
}

function setStateLinks(Links) {
	document.getElementById('anchorStateForestLink').href = Links[0]["STATEFORESTSERVICEWEBLINK"];
	document.getElementById('anchorStateCoopExtLink').href = Links[0]["STATECOUNTYEXTENSIONOFFICEWEBLINK"];
}

function updateCountyLinks() {
	var fips = document.getElementById('countyLinks').value;
	var stateID = document.getElementById('stateLinks').value;
	var url = 'http://www.forestasyst.org/county.cfm?id=us_' + stateID.replace(/\s+$/,"") + '_' + fips;

	document.getElementById('anchorCountyForestASystLink').href = url;

}

