You need to put this code into a JScript Web Resource. You then need to load the Web Resource into the Form Properties of the Opportunity entity. Then you need to add the frmOnLoad function to the OnLoad event in the Opportunity.
Not sure what the Opportunity Product Window is. Can you send a screenshot? I assume the Primary Unit is a UoM record...