to answer your original question, you can evaluate an expression (which can be just a variable name) with eval function. e.g.
Code:
a5="hello"
document.write(eval("a1"))
However, for what you are trying to do, there's a method getElementById() in document object. So to access style of something with ID "p2", you can do
Code:
document.getElementById("p2").style
This is a much better way to do things anyways because document.all is non-standard and only supported by IE. getElementById is part of DOM standard and is supported both by IE (>= 5.5) and mozilla.