
function IFrameBox(id, boxStyle)
{
	this.ID = id;
	this.BoxDivID = id + "BoxDiv";
	this.BoxBodyID = id + "BoxBody";
	this.BoxDivStyle = boxStyle;
	this.IFrame = this.CreateIFrame();
	this.DelayTmr = null;
	this.DelayMsg = null;
	
	//this.SetIFrameLayout(this.IFrame);
	this.RenderContent();
	this.InternalShow();
	this.Hide();
}

IFrameBox.prototype.GetIFrameDocument = function()
{
	var doc;
	
	if( this.IFrame.contentDocument )
		// For NS6
		doc = this.IFrame.contentDocument; 
	else if( this.IFrame.contentWindow ) 
		// For IE5.5 and IE6
		doc = this.IFrame.contentWindow.document;
	else if( this.IFrame.document )
		// For IE5
		doc = this.IFrame.document;
	else //other browser
		doc = this.IFrame.document;
	
	return doc;
}

IFrameBox.prototype.RenderContent = function(msg)
{
	var doc = this.GetIFrameDocument();
	
	var style = (this.BoxDivStyle) ?"class=\"" + this.BoxDivStyle + "\"" :"";
	
	doc.open();
	doc.writeln("<head>");
	doc.writeln("<link href=\"CSS/Style.css\" type=\"text/css\" media=\"all\" rel=\"Stylesheet\" />");
	doc.writeln("</head>");
	doc.writeln("<body id='" + this.BoxBodyID + "' style='border: none; overflow: hidden; margin: 0px; background-color:transparent'>");
	doc.writeln(" <div style=\"position:absolute;margin:0px;padding:0px\">");
	doc.writeln("   <div id='" + this.BoxDivID + "' " + style + "></div>");
	doc.writeln(" </div>");
	doc.writeln("</body>");
	doc.close();
}

IFrameBox.prototype.PlaceAt = function(x, y)
{
		this.IFrame.style.position = "absolute";
		this.IFrame.style.left = x + 'px';
		this.IFrame.style.top = y + 'px';
}

IFrameBox.prototype.IsVisible = function()
{
	var ifrm = CustomGetElementById(this.ID);
	
	if( ifrm.style.display == "none" )
		return false;
	else
		return true;
}

IFrameBox.prototype.Hide = function()
{	
  Hide(this.IFrame.id);  
  this.StopDelay();
}

IFrameBox.prototype.Show = function(msg, delay)
{
  if(this.IsVisible() && this.DelayMsg != msg){
    this.DelayMsg = msg;
    this.InternalShow(msg);    
  }
  else if(!this.DelayTmr || this.DelayMsg != msg){ 
    this.StopDelay(); 
    
    this.DelayMsg = msg;
    this.DelayTmr = setTimeout(this.InternalShow.bind(this), delay);
  }
}

IFrameBox.prototype.InternalShow = function()
{  
  this.PlaceAt(MouseX +10, MouseY +10);

	if( !this.IsVisible() )
	{	
	  var div = this.GetIFrameDocument().getElementById(this.BoxDivID);
	  div.innerHTML=this.DelayMsg;	
	  
	  Show(this.IFrame.id);	
	  this.ResizeIframe();	  	   
	}
	
	this.StopDelay();
}

IFrameBox.prototype.StopDelay = function()
{      
  if(this.DelayTmr){
	  clearTimeout(this.DelayTmr);
    this.DelayTmr = null;
    this.DelayMsg = null;
  }   
}

IFrameBox.prototype.ResizeIframe = function()
{      
  this.IFrame.width = "";
  this.IFrame.height = "";  
  var body = this.GetIFrameDocument().getElementById(this.BoxBodyID);          
  this.IFrame.height = body.scrollHeight;
  this.IFrame.width = body.scrollWidth;    
}

IFrameBox.prototype.CreateIFrame = function(){

  var frm = CustomGetElementById(this.ID);  
  if(frm) return frm;
 
  var body = document.getElementsByTagName('body')[0];
  frm = document.createElement('iframe');
  frm.id = this.ID;
  body.appendChild(frm);
      
  frm = CustomGetElementById(this.ID);
  this.SetIFrameLayout(frm);
  
  return frm;
}

IFrameBox.prototype.SetIFrameLayout = function(frm)
{  
  frm.width = 0;
  frm.height = 0;
	frm.frameBorder = 0;
	frm.border = 0;
  frm.scrolling = "no";
  frm.style.zIndex = "999999";
  frm.allowtransparency = "true";
}

