// Please leave this comment in place
// Created by: Randy Drisgill (The Mossman)
// August 17, 2007
//
// THIS OVERRIDES THE OOTB SHAREPOINT FUNCTION WHICH CAUSES ACTIVEX INSTALL ISSUES
//
// Essentially it overrides the ootb sharepoint function which calls the activex object
// See http://support.microsoft.com/default.aspx/kb/931509 for info on the issue
//
// To use in masterpage use this syntax in the <head>:
//  	<asp:ContentPlaceHolder id="PlaceHolderAdditionalPageHead" runat="server"/>
//   	<script type="text/javascript" src="/_catalogs/masterpage/custom_activex_override.js"></script>


	function ProcessDefaultOnLoad(onLoadFunctionNames)
	{
		//** Uncomment this to see when this runs
		//alert('Fixing the Issue');
		
		ProcessPNGImages();
		UpdateAccessibilityUI();
		
		//** We comment out the offending ootb function
		//** and leave the rest of the functions as they were
		//ProcessImn();
		for (var i=0; i < onLoadFunctionNames.length; i++)
		{
			var expr="if(typeof("+onLoadFunctionNames[i]+")=='function'){"+onLoadFunctionNames[i]+"();}";
			eval(expr);
		}
		if (typeof(_spUseDefaultFocus)!="undefined")
			DefaultFocus();
	}	



function ExpGroupBy(formObj)
{
	//alert('Hei');
	
	if ((browseris.w3c) && (!browseris.ie)) {
		document.all=document.getElementsByTagName("*");
	}
	
	docElts=document.all;
	numElts=docElts.length;
	images=formObj.getElementsByTagName("IMG");
	img=images[0];
	srcPath=img.src;
	index=srcPath.lastIndexOf("/");
	imgName=srcPath.slice(index+1);
	if (imgName=='plus.gif')
	{
		fOpen=true;
		displayStr="";
		img.src='/_layouts/images/minus.gif';
	}
	else
	{
		fOpen=false;
		displayStr="none";
		img.src='/_layouts/images/plus.gif';
	}
	
	oldName=img.name;
	img.name=img.alt;
	img.alt=oldName;
	spanNode=img;
	while(spanNode !=null)
	{
		spanNode=spanNode.parentNode;
		if (spanNode !=null && spanNode.id !=null && spanNode.id.length > 5 && spanNode.id.substr(0, 5)=="group") break;
	}
	
	parentNode=spanNode;
	while(parentNode !=null)
	{
		parentNode=parentNode.parentNode;
		if (parentNode !=null && parentNode.tagName=="TABLE") break;
	}
	lastNode=null;
	if (parentNode !=null)
	{
		lastNode=parentNode.lastChild;
	 	if (lastNode !=null && lastNode.tagName=="TBODY") lastNode=lastNode.lastChild;
		if (lastNode !=null && lastNode.tagName=="TR" && lastNode.lastChild !=null) lastNode=lastNode.lastChild;
	}
	for(var i=0;i<numElts;i++)
	{
		var childObj=docElts[i];
		if (childObj==spanNode) break;
	}
	ID=spanNode.id.slice(5);
	
	for(var j=i+1; j<numElts; j++)
	{
		
		var childObj=docElts[j];
		if (childObj.id.length > 5 && childObj.id.substr(0, 5)=="group")
		{
			curID=childObj.id.slice(5);
			if (curID <=ID) return;
		}
		parentNode=childObj;
		while(parentNode !=null)
		{
			parentNode=parentNode.parentElement;
			if (parentNode==spanNode) break;
		}
		if (parentNode==spanNode) continue;
		
		/*
		if (childObj !=img && childObj.tagName=="IMG" && childObj.src && childObj.src.slice(childObj.src.length – 25)=='/_layouts/images/plus.gif')
		{	
			childObj.src='/_layouts/images/minus.gif';
			oldName=childObj.name;
			childObj.name=childObj.alt;
			childObj.alt=oldName;
		}
		*/
		
		if (childObj.tagName==spanNode.tagName && childObj.id !="footer")
		{
			childObj.style.display=displayStr;
		}
		if ((childObj.tagName=="TABLE" && lastNode==null) || childObj==lastNode) break;
		
	}
}
