type == 'B' you are using a numeric comparison as opposed to a string comparison. Try 'eq' instead of '=='.
This would generally mean that it would default to false. If you change the else to an elseif type == 'C' and add another else then im pretty sure it will default to the else and not default to CD all the time. that way u can test to see if any of your comparisons are working or not ^_^