Using global vars in JavaScript
You can use Variables that area usable in every subfunction of a JavaScript area by using the "var" operator.
example:
<script language="JavaScript">
var PopupText="Hello World!";
function PopMeUp()
{
alert ( PopupText );
}
PopMeUp();
</script>
If you would load a site containing this script - the script would pop up a message to you, that shows "hello world!"
JavaScript FAQ