Best way to get day-of-week occurance
Try the DateTime class.  With this you can use relative formats:

new DateTime('second thu of next month');
new DateTime('second thu of jul');


That should make the code a lot easier.