function category_changed( cat_obj, role_obj, toggle_visibility ) {
	if( cat_obj.selectedIndex == -1 ) {
		return;
	}

	var cat_id = cat_obj.options[ cat_obj.selectedIndex ].value;

	if( role_obj.options.length != 0 ) {
		for( var i = role_obj.options.length - 1; i >= 0; i-- ) {
			role_obj.options[i] = null;
		}
	}

	var matched = 0;
	for( var n = 0; n < cat_obj.options.length; n++ ) {
		if( cat_obj.options[ n ].selected ) {
			matched += 1;
			if( matched > 4 ) {
				cat_obj.options[ n ].selected = false;
			}
		}
	}

	if( matched > 4 ) {
		alert( 'You can only select up to a maximum of 4 categories' );
		if( toggle_visibility ) {
			role_obj.style.visibility = 'hidden';
		}
		return;
	}

	if( matched > 1 ) {
		if( toggle_visibility ) {
			role_obj.style.visibility = 'hidden';
		}
		return;
	}

	if( ! role_order[ cat_id ] ) {
		if( toggle_visibility ) {
			role_obj.style.visibility = 'hidden';
		}
		return;
	}

	role_obj.options[ 0 ] = new Option( 'Any job type', '', true, false );
	for( var n = 0; n < role_order[ cat_id ].length; n++ ) {
		var role_id = role_order[ cat_id ][ n ];
		role_obj.options[ n + 1 ] = new Option( roles[ role_id ], role_id, false, false );
	}

	if( toggle_visibility ) {
		role_obj.style.visibility = 'visible';
	}
}

function role_changed( role_obj ) {
	if( role_obj.options.length == 0 ) {
		return;
	}

	if( role_obj.selectedIndex == -1 ) {
		return;
	}

	var matched = 0;
	for( var n = 0; n < role_obj.options.length; n++ ) {
		if( role_obj.options[ n ].selected ) {
			matched += 1;
			if( matched > 4 ) {
				role_obj.options[ n ].selected = false;
			}
		}
	}

	if( matched > 4 ) {
		alert( 'You can only select up to a maximum of 4 roles' );
		return;
	}
}

