CRM 2011 SDK 5.0.13 has just been released. It includes quite a few goodies. One of them is a new method to get the correct url of the server. Old method “getServerUrl” has been deprecated and has been replaced with “getClientUrl”
To use this new method simply call: Xrm.Page.context.getClientUrl();