HRESULT vmsDomHelper::InjectJSCode(IHTMLDocument2 *pDoc, BSTR bsCode)
{
	IHTMLElementPtr spBody;
	HRESULT hr = pDoc->get_body (&spBody);
	if (spBody == NULL)
		return hr;

	IHTMLElementPtr spScript;
	hr = pDoc->createElement (CComBSTR (L"script"), &spScript);
	if (spScript == NULL)
		return hr;

	spScript->setAttribute (CComBSTR (L"type"), CComVariant (L"text/javascript"));
	IHTMLScriptElementPtr spScriptEl (spScript);
	ATLASSERT (spScriptEl != NULL);
	spScriptEl->put_text (bsCode);

	IHTMLElement2Ptr spBodyEl (spBody);
	IHTMLElementPtr spTmp1;
	
	return spBodyEl->insertAdjacentElement (L"beforeEnd", spScript, &spTmp1);
}