var locations = new Hash();
locations.setItem('alabama', ['fort_rucker', 'maxwell_gunter' ]);
locations.setItem('florida', ['eglin','hurlburt','patrick','tyndall']);
locations.setItem('georgia', ['fort_benning','fort_gordon','fort_stewart','hunter']);
locations.setItem('kentucky', ['fort_campbell','fort_knox']);
locations.setItem('maryland', ['andrews']);
locations.setItem('missouri', ['fort_leonard_wood']);
locations.setItem('newjersey', ['fort_dix']);
locations.setItem('northcarolina', ['camp_lejeune']);
locations.setItem('southcarolina', ['fort_jackson']);
locations.setItem('tennessee', ['fort_campbell']);
locations.setItem('texas', ['fort_bliss']);

var installations = new Hash();
installations.setItem('fort_rucker', 		"Fort Rucker");
installations.setItem('maxwell_gunter',	"Maxwell-Gunter Air Force Base");
installations.setItem('eglin',				"Eglin Air Force Base");
installations.setItem('hurlburt',			"Hurlburt Field");
installations.setItem('patrick',				"Patrick Air Force Base");
installations.setItem('tyndall',				"Tyndall Air Force Base");
installations.setItem('fort_benning',		"Fort Benning");
installations.setItem('fort_gordon', 		"Fort Gordon");
installations.setItem('fort_stewart',		"Fort Stewart");
installations.setItem('hunter',				"Hunter Army Airfield");
installations.setItem('fort_campbell',		"Fort Campbell");
installations.setItem('fort_knox',			"Fort Knox");
installations.setItem('andrews',				"Andrews Air Force Base");
installations.setItem('fort_leonard_wood',"Fort Leonard Wood");
installations.setItem('fort_dix',			"Fort Dix");
installations.setItem('camp_lejeune',		"Camp Lejeune");
installations.setItem('fort_jackson',		"Fort Jackson");
installations.setItem('fort_bliss',			"Fort Bliss");


function filter_installations( location, installation_id ) { 
	
	var ddl_installations = document.getElementById( installation_id );
	ddl_installations.options.length = 0;
									
	if( location == "" ) { 
		ddl_installations.style.visibility = 'hidden';		
		ddl_installations.style.display = 'none';		
		
		var content_div = document.getElementById( 'installation_content' );
		content_div.innerHTML = "";
		
	} else {
		ddl_installations.style.visibility = 'visible';		
		ddl_installations.style.display = '';		
		
		var installations_array = locations.getItem( location );
		for( var i = 0; i < installations_array.length; i++ ) { 
			ddl_installations.options[i] = new Option(
				installations.getItem( installations_array[i] ),
				installations_array[i]
			);
		}
		
		display_installation( document.getElementById('installations').value, 'installation_content');
	}
}

function display_installation( installation, div_id ) {

	var ajaxRequest = buildAjaxRequest( div_id );	

	var queryString = "?installation=" + installation;
	ajaxRequest.open("GET", "/installation_info" + queryString, true);
	ajaxRequest.send(null); 	

}

function Hash()
{
	this.length = 0;
	this.items = new Array();
	for (var i = 0; i < arguments.length; i += 2) {
		if (typeof(arguments[i + 1]) != 'undefined') {
			this.items[arguments[i]] = arguments[i + 1];
			this.length++;
		}
	}
   
	this.removeItem = function(in_key)
	{
		var tmp_value;
		if (typeof(this.items[in_key]) != 'undefined') {
			this.length--;
			var tmp_value = this.items[in_key];
			delete this.items[in_key];
		}
	   
		return tmp_value;
	}

	this.getItem = function(in_key) {
		return this.items[in_key];
	}

	this.setItem = function(in_key, in_value)
	{
		if (typeof(in_value) != 'undefined') {
			if (typeof(this.items[in_key]) == 'undefined') {
				this.length++;
			}

			this.items[in_key] = in_value;
		}
	   
		return in_value;
	}

	this.hasItem = function(in_key)
	{
		return typeof(this.items[in_key]) != 'undefined';
	}
	
	this.keys = function() 
	{
		var keys = new Array();
		for (var i in this.items) {			
			keys.push(i);
		}			
		return keys;
	}
	
	this.values = function() 
	{
		var values = new Array();
		for (var i in this.items) {			
			values.push(this.items[i]);
		}	
		return values;
	}
	
}