Structural, electronic and magnetic properties of Ti-doped polar and nonpolar GaN surfaces