
function WaitBox(id,varName,imageCount,imageNamePrefix,imageNameSuffix,imageDelay,width,height,style,url)
{
 this.id=id;
 this.ImageCount=imageCount;
 this.CurrentImageIndex=0;
 this.ImageWidth=0;
 this.ImageHeight=0;
 this.ImageNamePrefix=imageNamePrefix;
 this.ImageNameSuffix=imageNameSuffix;
 this.ImageDelay=imageDelay;
 this.DivID="WaitBoxDiv";
 this.ImgID="WaitBoxImg";
 this.Enabled=true;
 this.Width=width;
 this.Height=height;
 this.Style=style;
 this.VarName=varName;
 this.timeout_id=null;
 this.CacheImages();
 this.WaitBoxUrl=url;
 this.IFrame=document.getElementById(this.id);
 this.Hide();
 if(this.WaitBoxUrl)
  this.LoadUrl(this.WaitBoxUrl);
 else
  this.RenderContent();
 if(!frames[this.id])
  this.Enabled=false;
}

WaitBox.prototype.GetIFrameDocument=function()
{
 var doc;
 if(this.IFrame.contentDocument)
  doc=this.IFrame.contentDocument;
 else if(this.IFrame.contentWindow)
  doc=this.IFrame.contentWindow.document;
 else if(this.IFrame.document)
  doc=this.IFrame.document;
 else
  doc=this.IFrame.document;
 return doc;
}

WaitBox.prototype.LoadUrl=function(url)
{
  var IFrameDoc=this.GetIFrameDocument();
 IFrameDoc.location.replace(url);
}

WaitBox.prototype.RenderContent=function()
{
 var doc=this.GetIFrameDocument();
 doc.open();
 doc.writeln("<body ondragstart='return false;' style='Margin: 0px; Background-Color: white'>");
 doc.writeln("   <div id='"+this.DivID+"' align=center style='position: absolute; "+this.Style+"'>");
 doc.writeln("      <img id='"+this.ImgID+"'>");
 doc.writeln("      <br><h3>Searching...</h3>");
 doc.writeln("   </div>");
 doc.writeln("</body>");
 doc.close();
}

WaitBox.prototype.Resize=function()
{
 if(WaitBox.IsBrowserIE())
 {
  var div=frames[this.id].document.getElementById(this.DivID);
  this.IFrame.style.width=div.offsetWidth;
  this.IFrame.style.height=div.offsetHeight;
 }
 else
 {
  this.IFrame.style.width=this.Width+"px";
  this.IFrame.style.height=this.Height+"px";
 }
}

WaitBox.prototype.Center=function()
{
 if(!this.IFrame)
  return;
 var objLeft=(document.body.clientWidth-this.IFrame.offsetWidth)/2;
 var objTop=(document.body.clientHeight-this.IFrame.offsetHeight)/4;
 objLeft=objLeft+document.body.scrollLeft;
 objTop=objTop+document.body.scrollTop;
 this.IFrame.style.position="absolute";
 this.IFrame.style.top=objTop+"px";
 this.IFrame.style.left=objLeft+"px";
}

WaitBox.prototype.CacheImages=function()
{
 this.Images=new Array(this.ImageCount);
 for(var i=0;i<this.ImageCount;i++)
 {
  this.Images[i]=new Image();
  this.Images[i].src=this.ImageNamePrefix+i+this.ImageNameSuffix;
 }
}

WaitBox.prototype.IsAnimating=function()
{
 if(this.timeout_id==null)
  return false;
 else
  return true;
}

WaitBox.prototype.IsVisible=function()
{
 var ifrm=document.getElementById(this.id);
 if(ifrm.style.visibility=="visible"&&ifrm.style.width>0)
  return true;
 else
  return false;
}

WaitBox.prototype.Animate=function()
{
  if(frames[this.id])
  frames[this.id].document.getElementById(this.ImgID).src=this.Images[this.CurrentImageIndex].src;
 else
  document.getElementById(this.ImgID).src=this.Images[this.CurrentImageIndex].src;
 this.Resize();
 this.Center();
 this.CurrentImageIndex=(this.CurrentImageIndex+1)%this.ImageCount;
 this.timeout_id=setTimeout(this.VarName+".Animate();",this.ImageDelay);
}

WaitBox.prototype.StartAnimate=function()
{
  if(this.IsAnimating())
  return;this.Animate();
}

WaitBox.prototype.StopAnimate=function()
{
 clearTimeout(this.timeout_id);
 this.timeout_id=null;
}

WaitBox.prototype.Hide=function()
{
 this.StopAnimate();
 this.IFrame.style.visibility="hidden";
 this.IFrame.style.width=0;
 this.IFrame.style.height=0;
}

WaitBox.prototype.Show=function()
{
  if(!this.Enabled)
  return;
 if(this.IsAnimating()||this.IsVisible())
  return;
 this.Resize();
 this.Center();
 this.IFrame.style.visibility="visible";
 this.IFrame.style.zIndex="999999";
 this.StartAnimate();
}

WaitBox.IsBrowserIE=function()
{
 try
 {
  return(window.navigator.userAgent.indexOf("MSIE ")>0);
 }
 catch(x)
 {
  return false;
 }
}

WaitBox.IsBrowserNS=function()
{
 try
 {
  return(window.navigator.userAgent.indexOf("Netscape")>0);
 }
 catch(x)
 {
  return false;
 }
}

WaitBox.IsBrowserFirefox=function()
{
 try
 {
  return(window.navigator.userAgent.indexOf("Firefox")>0);
 }
 catch(x)
 {
  return false;
 }
}
