Moved user agent detection into a shared file. Fixed a bug in x-domain communication