CRM-15376 - Porting fixes from https://github.com/civicrm/civicrm-core/pull/4233 to 4.5 branch.

----------------------------------------
* CRM-15376:
  https://issues.civicrm.org/jira/browse/CRM-15376
Merge pull request #4329 from davecivicrm/CRM-15376

CRM-15376 - Porting fixes from https://github.com/civicrm/civicrm-core/p...