
  function dialog(id, h, w, t, l, u, cX, cY)
  {
    this.id=id;
    this.height=h;
    this.width=w;
    this.top=t;
    this.left=l;
    this.url=u;
    this.load=loadDialog;
    this.refresh=refresh;
    this.unload=unloadDialog;
    this.show=showDialog;
    this.hide=hideDialog;
    this.isLoaded=false;
    this.isVisible=false;
    this.arguments=new collection();
    this.centerX=cX;
    this.centerY=cY;
    this.iFrame=false;
    this.getArgs=getArgs;
    this.saveArgs=saveArgs;
  }

  function loadDialog()
  {

    if(this.iFrame)
    {
      // don't need to build the iframe again - just refresh the page
      this.refresh()
      return;
    }

    //alert(this.isLoaded)

    // create a table for the iframe
    var d=document.createElement('div');
    d.style.position="absolute";
    d.style.top="0px";
    d.style.left="0px";
    d.style.width="100%";

    if(this.centerX){ d.setAttribute("align","center") } else { d.setAttribute("align","left") }
    if(this.centerY){ d.style.verticalAlign="middle" } else { d.style.verticalAlign="top" }

    // create the iframe
    this.iFrame=document.createElement('iframe');
    this.iFrame.setAttribute('id',this.id);
    this.iFrame.setAttribute('scrolling',"no");
    this.iFrame.setAttribute('noresize','true');
    this.iFrame.frameBorder='0';
    this.iFrame.style.zIndex=999;
    this.iFrame.style.border='0px';
    this.iFrame.style.position="relative";
    this.iFrame.style.top=this.top + "px";
    this.iFrame.style.left=this.left + "px";
    this.iFrame.style.width=this.width + "px";
    this.iFrame.style.height=this.height + "px"
    this.iFrame.style.visibility="hidden"

    document.body.appendChild(d);
    d.appendChild(this.iFrame);
    
    setTimeout('document.dialogs["' + this.id + '"].refresh()',10);
  }

  function refresh()
  {
    if(!this.iFrame) return;
    if(this.iFrame.contentDocument) 
    {
      // NS6
      d = this.iFrame.contentDocument; 
    } 
    else if(this.iFrame.contentWindow) 
    {
      // IE5.5 and IE6
      d = this.iFrame.contentWindow.document;
    } 
    else if(this.iFrame.document) 
    {
      // IE5
      d = this.iFrame.document;
    } 

    d.location.replace(this.url);
  }

  function unloadDialog()
  {
    if(!this.iFrame) return;
    document.body.removeChild(this.iFrame)
    this.isLoaded=false;
  }

  function showDialog()
  {

    this.saveArgs();
    this.getArgs();

    if(document.frames)
    {
      for(var n=0;n<document.frames.length;n++)
      {
        if(document.frames[n].style)
        {
          document.frames[n].style.zIndex=0;
        }
      }
    }    

    // load & show the dialog if it isn't already loaded
    if(!this.iFrame) 
    {
      // load and show
      this.isVisible=true;
      this.load();
      this.iFrame.style.zIndex=999;
      this.iFrame.style.visibility="visible"
    } 
    else
    {
      // show the dialog
      this.iFrame.style.zIndex=999;
      this.isVisible=true;
      this.iFrame.style.visibility="visible"

      if(this.onShow)
      {
        this.onShow();
      }
    }


    setCookie('CurrentDialog', this.id)
  }

  function hideDialog()
  {
    if(!this.iFrame) return;
    this.iFrame.style.visibility="hidden"
    this.isVisible=false;
  }

  function saveArgs()
  {

    if(this.arguments.length > 0)
    {
      var c="";
      for(var n=0;n<this.arguments.length;n++)
      {
        c+=this.arguments.keys[n] + '::' + this.arguments[n];
        if(n<this.arguments.length-1)
        {
          c+=";;";  
        }
      }
      setCookie(this.id, c)
    }

  }

  function getArgs()
  {
    var c=getCookie(this.id)
    if(c)
    {
      var args=String(c).split(";;")
      for(var n=0;n<args.length;n++)
      {
        var a=args[n].split("::")
        this.arguments.add(a[0],a[1])
      }
    }
  }

