var prevOnLoad = window.onload;
	
window.onload = function ( e ) {

	if ( prevOnLoad ) prevOnLoad( e );

	if ( document.getElementById && document.getElementById('moduleSelectForm') ) {
	
		var campus = document.getElementById('selCampus'),
			faculty = document.getElementById('selFaculty'),
			topic = document.getElementById('selTopic'),
			programme = document.getElementById( 'selProgramme' ),
			form = document.getElementById('moduleSelectForm'),
			submitButton = document.getElementById( 'modulesSubmit' ),
			resetButton = document.getElementById( 'modulesReset' ),
			results = document.getElementById( 'moduleResults' );
		
		var submitForm = function ( ) {
			if ( results ) results.innerHTML = '<div class="loading">Loading, please wait...</div>';
			form.submit();
		}
			
		if ( campus ) campus.onchange = function ( ) {
			if ( topic ) topic.options[0].selected = true;
			if ( programme ) programme.options[0].selected = true;
			submitForm();
		}
		if ( faculty ) faculty.onchange = function ( ) {
			if ( topic ) topic.options[0].selected = true;
			if ( programme ) programme.options[0].selected = true;
			submitForm();
		};
		if ( topic ) topic.onchange = function ( ) {
			if ( programme ) programme.options[0].selected = true;
			submitForm();
		};
		if ( programme ) programme.onchange = function ( ) {
			if ( topic ) topic.options[0].selected = true;
			submitForm();
		};
		
		if ( submitButton) submitButton.style.display = 'none';
		if ( resetButton ) resetButton.onclick = function ( e ) {
			if ( campus ) campus.options[0].selected = true;
			if ( faculty ) faculty.options[0].selected = true;
			if ( topic ) topic.options[0].selected = true;
			if ( programme ) programme.options[0].selected = true;
			
			submitForm();
			return false;
		};
	}
};