Knee bones are twisting my rig

Hello community

I am currently modeling a character for the BG contest. I have modeled and rigged the character however after applying the armature it has gone berserk. After some fiddling I have found out that it is my knee bone that is affecting it. Despite knowing the problem I have no idea on how to fix it. Please indulge me with you vast pool of knowledge to help me with my experienced inexperience;).

Before


After

Can you attached the .blend?

I do not know how to attach a blend file. Also I figured out it had something to do with the knee bones and the leg turning -345 degrees instead of 15 or it has something to do with my IK’s. How can you prevent the leg from turning the wrong way?

Alright I figured out how to attach the file. Here it is
http://www.pasteall.org/blend/34939