/* =========================================================================
DHTMLDEV.COM SCRIPT
============================================================================
Name: Activate X
Description: Uses the DOM to activate ActiveX objects in an HTML page
Version: 1.0
Copyright: Copyright 2006
Author: Mitch Wilson, mitch@dhtmldev.com
Created: 07/17/2006
Last Modified: 07/17/2006
Terms: This script is free to use and distribute. I would appreciate a link 
to http://dhtmldev.com somewhere on your site. Thanks and enjoy!
Usage: <script type="text/javascript" src="activate_x.js"></script>
============================================================================
==========================================================================*/

function activate_x()
{	if(document.body.outerHTML) // outerHTML is non-W3C compliant, so make sure it's still supported
	{	var objects = document.getElementsByTagName("object"); // get array of object elements as nodes
		for(var i=0;i<objects.length;i++) // iterate over array of object element nodes
		{	var obj = objects[i]; // get reference to current object element node in array
			var clone = obj.cloneNode(true); // clone the object element node, including it's children (true)
			var parent = obj.parentNode; // get parent node of object element node
			var next = obj.nextSibling; // use next sibling to know where to position clone in same spot as original
			var div = document.createElement("div"); // create new div element node to hold HTML of clone later
			parent.removeChild(obj); // use the parent node to remove the object element node
			parent.insertBefore(div,next); // insert the new div node to hold the HTML of the clone node
			// Must use HTML for this trick to work; cannot just append a node to activate ActiveX
			div.innerHTML = clone.outerHTML; // then use the cloned object element node to re-add the object element
		}
	}
}

window.onload = activate_x; // must run function after page has loaded