var newMenu = "";
var currentlyRunning = false;

function init(section) {
	if(section != "home") {
		showSubNav(section);
	}
}

function showSubNav(section) {
	//Replace the text on the subnavbar.
	newMenu = document.getElementById('submenu_'+section).innerHTML;
	
	//If the subnavbar is currently showing then hide it.
	if(currentlyRunning == false) {
	    currentlyRunning = true;
		//Collapse this bar
		Effect.SlideUp('subnavbar', { duration: 0.2, queue: { position: 'end', scope: 'menuxscope',
limit: 1 }, afterFinish: updateText});
        Effect.SlideDown('subnavbar', { duration: 0.2, queue: { position: 'end', scope: 'menuxscope',
limit: 2 }, afterFinish: function(){currentlyRunning = false;} });
	}
    else {
        updateText();
    }
}

function updateText() {
	document.getElementById('subnavbarcontent').innerHTML = newMenu;
}

function viewGrant(id) {
    document.location.href="/Grant/View/"+id
}

function editGrant(id) {
    document.location.href="/Grant/Edit/"+id
}

function updateEvents(sport,event) {
	var params = "sport=" + sport;
	new Ajax.Request('/Data/Events', {method: 'post', parameters: params, onSuccess: function(transport) {
        var response = transport.responseText;
		response_array = response.split('|');

		//Remove all options from dropdown.
		document.getElementById(event).options.length = 0
		//Loop through all events and add new options.
        if(response_array.length != 1) {
    		for(i=0;i<=response_array.length-1;i++) {
    		    event_array = response_array[i].split("~");
    		  	document.getElementById(event).options[document.getElementById(event).options.length] = new Option(event_array[1], event_array[0]);
    		}
        }
	}});
}