A general variational principle and some of its applications