Variational approach to studying solitary waves in the nonlinear Schrodinger equation with complex potentials