/******************************************************************************************
 * 
 * fixActiveX.js
 * 
 * A. Kevin Baynes
 * 
 * February 2, 2008
 * 
 * BlueZone Software
 *
 ******************************************************************************************
 * 
 * This scripts functions by finding the <div id="BlueZoneLaunchTag" > tag and parsing 
 * its contents to extract the <object> tag wrapped in an HTML comment tag. It then 
 * replaces the contents of the <div> with the uncommented <object> tag.
 * This copied tag is not HTML interpreted by the browser, but a new tag inserted 
 * by JavaScript. For whatever reason, this satisfies the frivolous IP patent lawsuit 
 * brought by Eolas against Microsoft. http://en.wikipedia.org/wiki/Eolas
 *
 * This fix only needs to be implemented for MS IE 6+. However, as this file is intended 
 * for use only by the BlueZone system, which checks the browser type by another method 
 * there is no browser type check needed or included in this script.
 *
 ******************************************************************************************
 */
 
function fixActiveX() {

	if (!document) {
		alert("Script cannot find the Document object.");
		return;
	}
 
	var elements = document.getElementsByTagName("div");
 	
	if (elements.length<1) {
	    // no elements by this ID on this page, exit
	    alert("Script cannot find and div tags within the document.");
	    return;
	}
	
	var element = elements[0]; // usually there is only one, take the first as a default
	
	for (e in elements) {
		if (e.id=="BlueZoneLaunchTag") {
			element = e; // this is definitely the one
		}
	}
 	
	var html = element.innerHTML; // capture text of node

	var object = parseObject(html);
	
	if (object==null) {
		alert("Script cannot find the BlueZone object tag");
		return;
	}
 	
	element.innerHTML = object; // force browser to re-parse HTML containing tag, to create a new DOM object for the control
 	
}

function parseObject(html) {

	var startIndex = html.indexOf("<object");
	
	if (startIndex==-1) return null; 

	var endIndex = html.indexOf("object>") + 7;
	
	if (endIndex==6) return null;

	return html.substring(startIndex,endIndex);

}

// run the fix here
fixActiveX();