Knowing if you are running in CRM 3.0 or CRM 4.0

It's fairly easy to differentiate if your code is running on CRM 4.0 or not. Just pick a method or variable that did not exist in CRM 3.0 and check if it is available:

if (typeof(GenerateAuthenticationHeader) == "undefined") {
alert("Version 3");
}