function popwindow(anid) {
  this.id=anid;
  this.dialogWidth=0;
  this.dialogHeight=0;
  this.onClose=null;
  
  if (!document.getElementById(anid))
    this.build();
    
}

popwindow.prototype.build=function() {
  //mainContainer
  this.popwinmask=document.createElement('DIV');
  this.popwinmask.id = this.id+'Mask';
  //this.popwinmask.className = this.id+'Mask';

  with (this.popwinmask.style) {
	visibility = 'hidden';
  	position = document.all ? 'absolute' : 'fixed';
	top = '0px';
	left = '0px';
	width = '100px';
	height = '100px';
  }
  document.getElementsByTagName('body')[0].appendChild(this.popwinmask);

  this.popwincontainer=document.createElement('DIV');
  this.popwincontainer.id = this.id+'Container';
  //this.popwincontainer.className = this.id+'Container';

  with (this.popwincontainer.style) {
	visibility = 'hidden';
  	position = document.all ? 'absolute' : 'fixed';
	top='0px';
	left='0px';
	width='100px';
	height='100px';
  }
  document.getElementsByTagName('body')[0].appendChild(this.popwincontainer);
  
  //Inner Container
  this.popwin=document.createElement('DIV');
  this.popwin.id = this.id+'Window';
  with (this.popwin.style) {
  	position = 'absolute';
  }  
  this.popwincontainer.appendChild(this.popwin);
  
  this.popwintitlebar=document.createElement('DIV');
  this.popwintitlebar.id=this.id+'Titlebar';
  this.popwintitlebar.style.position='relative';
  this.popwin.appendChild(this.popwintitlebar);

  this.popwindoc=document.createElement('iframe');
  this.popwindoc.id=this.id+'Document';
  this.popwindoc.style.position='relative';
  this.popwindoc.style.border='0px none white';
  this.popwindoc.setAttribute('frameborder',0);
  this.popwindoc.setAttribute('marginwidth',4);
  this.popwindoc.setAttribute('marginheight',0);
  this.popwin.appendChild(this.popwindoc);
  
  this.popwinstatusbar=document.createElement('DIV');
  this.popwinstatusbar.id=this.id+'Statusbar';
  this.popwinstatusbar.style.position='relative';
  this.popwin.appendChild(this.popwinstatusbar);
  
}

popwindow.prototype.setTitlebar=function (htmlcode) {
  this.popwintitlebar.innerHTML=htmlcode;
}
popwindow.prototype.setStatusbar=function (htmlcode) {
  this.popwinstatusbar.innerHTML=htmlcode;
}


popwindow.prototype.resize=function() {
  if (document.all) { // MSIE
    if (document.body.parentNode.scrollWidth) {
      var ww=parseInt(document.body.parentNode.scrollWidth);
      var hh=parseInt(document.body.parentNode.scrollHeight);
    } else {
      var ww=parseInt(document.body.scrollWidth);
      var hh=parseInt(document.body.scrollHeight);
    }
    this.popwinmask.style.width=(ww-22)+'px';
    this.popwinmask.style.height=hh+'px';
    this.popwincontainer.style.width=(ww-22)+'px';
    this.popwincontainer.style.height=hh+'px';
    this.reposition();
    //var w=parseInt(document.body.parentNode.offsetWidth);
    //var h=parseInt(document.body.parentNode.offsetHeight);    

    this.popwindoc.style.width=(this.dialogWidth-2)+'px';

  } else {
    //set position other browsers
    this.popwinmask.style.width = window.innerWidth + 'px';
    this.popwinmask.style.height = window.innerHeight + 'px';
    this.popwincontainer.style.width = window.innerWidth + 'px';
    this.popwincontainer.style.height = window.innerHeight + 'px';
    this.popwin.style.left = (window.innerWidth-this.dialogWidth)/2 + 'px';
    this.popwin.style.top = (window.innerHeight-this.dialogHeight)/2 + 'px';
    
    this.popwindoc.style.width=(this.dialogWidth)+'px';
  }
  
  this.popwin.style.width = this.dialogWidth + 'px';
  this.popwin.style.height = this.dialogHeight + 'px';
  
  this.popwindoc.style.height=(this.dialogHeight-(this.popwintitlebar.offsetHeight+this.popwinstatusbar.offsetHeight))+'px';
}
popwindow.prototype.reposition=function() {
    if (document.body.parentNode.scrollWidth) {
      var w=parseInt(document.body.parentNode.offsetWidth);
      var h=parseInt(document.body.parentNode.offsetHeight);  
      var dh=parseInt(document.body.parentNode.scrollTop);
    } else {
      var w=parseInt(document.body.offsetWidth);
      var h=parseInt(document.body.offsetHeight);  
      var dh=parseInt(document.body.scrollTop);
    }
    this.popwin.style.left = (w-this.dialogWidth)/2 + 'px';
    this.popwin.style.top = (h-this.dialogHeight)/2 + dh + 'px';
}
popwindow.prototype.open=function(url,width,height,title) {
  this.dialogWidth=width;
  this.dialogHeight=height;
  this.resize();
  this.popwindoc.src=url;
  this.popwinmask.style.visibility = '';
  this.popwincontainer.style.visibility = '';
  if (document.all) {
    window.attachEvent('onresize',popwindowOnResize);
    window.attachEvent('onscroll',popwindowOnScroll);
  } else {
    window.addEventListener('resize',popwindowOnResize,true);
  }
}
popwindow.prototype.close=function() {
  this.popwinmask.style.visibility = 'hidden';
  this.popwincontainer.style.visibility = 'hidden';
  this.popwindoc.src='blank.html';
  if (document.all) {
    window.detachEvent('onresize',popwindowOnResize);
    window.detachEvent('onscroll',popwindowOnResize);
  } else {
    window.removeEventListener('resize',popwindowOnResize,true);
  }
  if (this.onClose) this.onClose();
}

function popwindowOnResize() {
  popwin.resize();
}
function popwindowOnScroll() {
  popwin.reposition();
}
