var isNN = (navigator.appName.indexOf("Netscape")!=-1);

function updateList(listId, json) {
    for (var key in json ) {
        addOption(listId, json[key], key);
    }
}

function updateProgramList(request, json) {
    var listId = $('course');
    listId.length = 0;
    
    if ( $('campus').value == 0 || $('campus').value == "undefined" ) {
        addOption(listId, '-- Select a Campus first --');
    } else {
        addOption(listId, ' -- Select a Program -- ');
        addOption(listId, 'Not Sure', 'NS');
        updateList(listId, json);
    }
    $('course-loading').style.display = 'none';
}

function showLoading(el)
{
	el.style.display = 'inline';
}

function addOption(list, text, value) {
    //alert (text + " -- " + value);
    
    option = document.createElement('option');
    option.text = text;
    if ( value != "undefined" ) {
        option.value = value;
    }

    try {
        list.add(option, null); // Standards compliant
    }
    catch (ex) {
        list.add(option); // IE isn't compliant
    }
}
Event.observe(window, 'load', function()
{
	new Form.Element.EventObserver("campus", function(element, value)
	{
		new Ajax.Request('/contact/program_search', {asynchronous:true, evalScripts:false, onCreate:function(request, json)
		{
			showLoading($('course-loading'));
		}, onComplete:function(request, json)
		{
			updateProgramList(request, json);
		}, parameters:'campus=' + $F('campus'), method: 'GET'})
	});
});
