addLoadEvent(resizeFiller);
addLoadEvent(flashFix);

function addLoadEvent(oFunction) 
{
  var oPrevOnLoad = window.onload;
  if (typeof(window.onload) != 'function') {
    window.onload = oFunction;
  } 
  else {
    window.onload = function() 
    {
      if (oPrevOnLoad) {
        oPrevOnLoad();
      }
      oFunction();
    }
  }
}

function flashFix()
{
   var theObjects = document.getElementsByTagName("object");
   for (var i = 0; i < theObjects.length; i++) {
      theObjects[i].outerHTML = theObjects[i].outerHTML;
   }
}

function resizeFiller()
{
   var oContentPane = document.getElementById("dnn_ContentPane");
   var oRightPane = document.getElementById("rightPaneContainer");
   var divFiller = document.getElementById("rightPaneFiller");

   if (   oContentPane != null
       && oRightPane != null
       && divFiller != null)
   {
      var nContentHeight = oContentPane.clientHeight;
      var nRightPaneHeight = oRightPane.clientHeight;
      var nFillerHeight = nContentHeight - nRightPaneHeight;
      var sComputedTopMargin = "0px";
      var nTopMargin = 0;
      
      if (nFillerHeight > 0) {
         sComputedTopMargin = getStyleRule(divFiller, "marginTop", "margin-top");
         nTopMargin = getStyleNumericValue(sComputedTopMargin);
         nFillerHeight -= (nTopMargin == null ? 0 : nTopMargin);
         
         if (nFillerHeight > 0) {
            divFiller.style.height = nFillerHeight;
            divFiller.style.display = "block";
         }
         else {
            divFiller.style.display = "none";
         }
      }
      else {
         sComputedTopMargin = getStyleRule(oContentPane, "marginTop", "margin-top");
         nTopMargin = getStyleNumericValue(sComputedTopMargin);
         oContentPane.style.height = nRightPaneHeight;
         divFiller.style.display = "none";
      }      
   }
}

function getStyleRule(oElement, sIEStyleProperty, cComputedStyleProperty)
{
   var oValue = null;
   if (oElement != null) {
      if (oElement.currentStyle != null) {
		   oValue = oElement.currentStyle[sIEStyleProperty];
		}
	   else if (window.getComputedStyle) {
		   oValue = document.defaultView.getComputedStyle(oElement,null).getPropertyValue(cComputedStyleProperty);
		}
	}
   return oValue;
}

function getStyleNumericValue(sValue)
{

   var aValue = sValue.split("em");
   aValue = aValue[0].split("ex");
   aValue = sValue.split("px");
   aValue = aValue[0].split("%");
   aValue = aValue[0].split("in");
   aValue = aValue[0].split("cm");
   aValue = aValue[0].split("mm");
   aValue = aValue[0].split("pt");
   aValue = aValue[0].split("pc");

   var nValue = null;
   try {
      nValue = Number(aValue[0]);
   }
   catch (e){}
   return nValue;
}