CRM-14798 - CiviCase - Fix max_instances check

This code was using the ambiguous generic variable names ("$key", "$val")
and confusing the content of "$val" (e.g.  confusing caseId with
caseTypeName).
Merge pull request #3571 from totten/master-casetype-maxinst

CRM-14798 - CiviCase - Fix max_instances check