Mesh deforms like crazy when i position/rotate

Okay so i have this mesh. im trying to rig it. the mesh goes crazy when im trying to rotate the limbs in this image

ive just gotten started with rigging.
if anyone can help me with this i would appreciate it.