/*******************************************************************
* IFrame SSI script II
* Dynamic Drive DHTML code library (http://www.dynamicdrive.com)
* Visit DynamicDrive.com for hundreds of original DHTML scripts
* This notice must stay intact for legal use
********************************************************************
* THIS SCRIPT ONLY SUPPORTS: 
* 		IE5+, NS6+, Firefox 1.x
********************************************************************/
//Input the Array of IDs of the IFRAMES you wish to dynamically resize to match its content height:
var iframeids=[];
var FFextraHeight=0; //extra height in px to add to iframe in FireFox browsers

// emergency activation/resizing, if content can not be loaded in time ...
var initialResizer    = window.setTimeout (resizeCallerInitial, 3000);
var periodicalResizer = null;

function resizeCallerInitial() {
	resizeCaller();	
	// now call the resizing periodically until the page is completly loaded, i.e. the "onLoad"-event is triggered ...
	periodicalResizer = window.setInterval(resizeCaller, 1000);
}

function resizeCallerOnLoad() {
	if (initialResizer != null)
	{
		window.clearTimeout(initialResizer);
	}
	if (periodicalResizer != null)
	{
		window.clearInterval(periodicalResizer);
	}	
	resizeCaller();	
}

function resizeCaller() {
  for (var i=0; i<iframeids.length; i++){
    if (document.getElementById) { 
	  try {
	    resizeIframe(iframeids[i]);
	  } catch (e) {
	  } finally {
	  }
   }
  }
  activateContentArea();
  disableBackground();
}

function resizeIframe(frameid){
  var currentfr=document.getElementById(frameid);
  if (currentfr){
    if (currentfr.contentDocument && (currentfr.contentDocument.body.offsetHeight != null)) //ns6 + FF syntax
    {
      currentfr.height = currentfr.contentDocument.body.offsetHeight + FFextraHeight; 
  	  //hide a module if there is a "emptyContent" <div>-ID  - a little hackish - Infobolsa could call this JS-Method themselves ;-)
  	  if (currentfr.contentDocument.getElementById("emptyContent") != null)
  	  {
		//do not hide module if we are in debug mode
	    if (this.top.location.href.indexOf("/debug/") == -1)
		{
		  hideModule(frameid);
		}
	  }
    }
    else if (currentfr.Document && (currentfr.Document.body.scrollHeight != null)) //ie5+ syntax 
    {
      currentfr.height = currentfr.Document.body.scrollHeight;
  	  //hide a module if there is a "emptyContent" <div>-ID  - a little hackish - Infobolsa could call this JS-Method themselves ;-)
  	  if (currentfr.Document.getElementById("emptyContent") != null)
  	  {
		//do not hide module if we are in debug mode
	    if (this.top.location.href.indexOf("/debug/") == -1)
		{
		  hideModule(frameid);
		}
	  }
    }
	if (currentfr.addEventListener)
	{
	  currentfr.addEventListener("load", readjustIframe, false);
	}	
	else if (currentfr.attachEvent)
	{
	  currentfr.detachEvent("onload", readjustIframe); // Bug fix line
	  currentfr.attachEvent("onload", readjustIframe);
	}	
  }
}

function readjustIframe(loadevt) {
  var crossevt=(window.event)? event : loadevt;
  var iframeroot=(crossevt.currentTarget)? crossevt.currentTarget : crossevt.srcElement;
  if (iframeroot) {
   resizeIframe(iframeroot.id);
  }
}

function loadintoIframe(iframeid, url){
  if (document.getElementById) {
    document.getElementById(iframeid).src=url;
  }
}

function activateContentArea() 
{
  var element;
  element =  document.getElementById("content");
  if (element != null) {
  	element.style.visibility="visible";
  	element.style.cursor="auto";
  }	
  element =  document.getElementById("footer");
  if (element != null) {
  	element.style.visibility="visible";
  	element.style.cursor="auto";
  }	  
  element =  document.getElementById("loading");
  if (element != null) {
 	element.style.display="none";
  }	
}

function disableBackground() 
{
  var element;
  element =  document.getElementById("content");
  if (element != null) {
  	element.style.background="transparent";
  }	
}

function registerIframe(iframeID)
{ 
  iframeids.push(iframeID);
}	
