Problem with "Pick up key" script

I've started Unity and scripting a week ago so please, feel free to treat me like an idiot ^^ I threw a javascript together that's supposed to show a message when you click on a key, and then lets you choose whether to pick it up.

private var gotKey : boolean = false;
private var showMsg : boolean = false;

function OnMouseDown()
{
    showMsg = true;
    function OnGUI () 
{
        if (showMsg = true)
        {
        GUI.skin.box.wordWrap = true;        
        GUI.Box(Rect(100,50,500,200),"It's the key to the door that leads to the mysterious and unknown outside wooooooorld. 
(Press E to pick it up, press R to cancel)");
        }
}
            function Update()
            {
                if (Input.GetButtonDown ("e"))
                {
                    gotKey = true;
                    Destroy (gameObject.Find("key"));   
                }
                if(Input.GetButtonDown ("r"))
                {
                    showMsg = false;
                }
            }

}

It looks fine to me. But I get this error message: Assets/Scripts/getKey.js(8,18): BCE0044: expecting (, found 'OnGUI'. So it expects me to just write function()? Please help...

Your OnGUI() and Update() are inside your OnMouseDown() function. Place each as a class member and you're almost fine. Note that Input.GetButtonDown returns the mouse button, not the keys. You want to use Input.GetKeyDown

showMSG = true; comes up as an error. it wants to change it to showMSG : true;