function popup(popupID)
{
this.id = popupID;
this.title = "123456789";
this.width = "200";
this.height = "200";
this.top = "10px";
this.left = "100";

this.destroy = function()
  {
    if (self['drag'] = this.id) {self['drag'] = false;}
    top.document.getElementsByTagName("body")[0].removeChild(top.document.getElementById(this.id));
  }

this.seturl = function(url)
  {
    if (this.iframe)
    {
      this.iframe.src = url;
    }
  }

this.refresh = function()
  {
    if (this.iframe)
    {
      top[this.iframe.name].location.reload();
    }
  }

this.setwidth = function(width)
{
  this.container.style.width = width+"px";
}

this.setheight = function(height)
{
  this.container.style.height = height+"px";
  this.contentdiv.style.height = height-25+"px";
}

this.settitle = function(title)
{
  this.titletext.nodeValue = title;
}  

this.createIframe = function(url)
{
   //iframe
  this.iframe = document.createElement("iframe");
  
  with (this.iframe)
  { 
    
    setAttribute("height","100%");
    setAttribute("width","100%");
    src = url;
    frameBorder = 0;
  }
  this.iframe.name = "frame_"+this.id;
  this.iframe.id = "frame_"+this.id;
  this.contentdiv.appendChild(this.iframe);
}

this.createImage = function(url,text)
{
   //image
  this.image = document.createElement("img");
  
  with (this.image)
  { 
    setAttribute("src",url);
    setAttribute("alt","");
    setAttribute("title","text");
  }
  this.contentdiv.appendChild(this.image);
  this.image.onload = new Function ('F',this.id+".resizetoimg()");
  if (this.image.complete) this.resizetoimg(); //IE Bug: onload event is not fired if img already cached
}
  
this.resizetoimg = function()
{
  if (this.image)
  {
    this.setwidth(this.image.width);
    this.setheight(this.image.height +26);
  }
}

this.getScrolly = function()
{
  var x,y;
  if (self.pageYOffset) // all except Explorer
  {
  	x = self.pageXOffset;
  	y = self.pageYOffset;
  }
  else if (document.documentElement && document.documentElement.scrollTop)
  	// Explorer 6 Strict
  {
  	x = document.documentElement.scrollLeft;
  	y = document.documentElement.scrollTop;
  }
  else if (document.body) // all other Explorers
  {
  	x = document.body.scrollLeft;
  	y = document.body.scrollTop;
  }
  return y;
}

/************ BEGIN CONSTRUCTOR ************/
  
  //test if an element with the id already exists, if yes store the reference else create a new popup
  if (!(this.container = document.getElementById(this.id))) 
  {
    //first create container div with properties
    this.container = document.createElement("div");
  
    with (this.container)
    {
      setAttribute("id",this.id); //set ID to popupname
      style.position = "absolute";
      style.zindex = "2";
      style.top = eval(parseInt(this.getScrolly()) + parseInt(this.top))+ "px";
      style.left = this.left+"px";
      style.width = this.width+"px";
      style.height = this.height+"px";
      style.border = "1px solid black";
      style.background = "#ffffff";
    }
    document.getElementsByTagName("body")[0].appendChild(this.container);
    
    //create title bar div
    this.titlediv = document.createElement("div");
    with (this.titlediv)
    {
      setAttribute("id",this.id+"Title"); //set ID to popupnameTitle
      style.height = "25px";
      style.width = "100%";
      style.background = "#dddddd";
      style.borderBottom = "1px solid black";
    }
    this.titlediv.onmouseover = new Function('F',"self['drag'] = '"+this.id+"';");
    this.titlediv.onmouseout = new Function('F',"if (self['drag'] = '"+this.id+"') self['drag'] = false;");
    
    this.container.appendChild(this.titlediv);
    
    //title bar title
    this.titlespan = document.createElement('span');
    
    this.titlespan.style.margin = "5px";
    this.titlediv.appendChild(this.titlespan);
    
    this.titletext = document.createTextNode(this.title);
    this.titlespan.appendChild(this.titletext);
    
    //btn span in top right corner
    this.buttonspan = document.createElement("span");
    with (this.buttonspan)
    {
      style.position = "absolute";
      style.right = "0px";
    }
    this.titlediv.appendChild(this.buttonspan);
    
    //close button
    this.buttonclose = document.createElement("img");
    with (this.buttonclose)
    {
      setAttribute("src","/css/close_cross.gif"); 
      setAttribute("height","10"); 
      setAttribute("width","10");
      setAttribute("title","schliessen"); 
      setAttribute("alt",""); 
        
      style.padding = "3px";
      style.margin = "3px";
      style.cursor = "pointer";
      style.border = "1px solid black";
    }
    this.buttonclose.onclick = new Function ('F',this.id+".destroy();");
    this.buttonspan.appendChild(this.buttonclose);
    
    //div to hold content
    this.contentdiv = document.createElement("div");
    with (this.contentdiv)
    {
      style.width = "100%";
      style.height = this.height-25+"px";
      //setAttribute("width","10");
    }
    this.container.appendChild(this.contentdiv);
  }
/************ END CONSTRUCTOR ************/ 

}

function popupUrl(id,title,url,width,height)
{
  if (!(document.getElementById(id))) 
  {
    self[id] = new popup(id);
    self[id].setwidth(width);
    self[id].setheight(height);
    self[id].settitle(title);
    self[id].createIframe(url);
  }
  else
  {
    window.scrollTo(0, eval(parseInt(self[id].container.style.top)+parseInt(self[id].top)));
  }
}

function popupImg(id,title,url,width,height,text)
{
  if (id == '') return false;
  id = id.replace(/\W/g,'');

  if (!(document.getElementById(id))) 
  {
    self[id] = new popup(id);
    self[id].setwidth(width);
    self[id].setheight(height);
    self[id].settitle(title);
    self[id].createImage(url,text);
  } else
  {self[id].destroy();}
}

function toggleView(mode)
{
  parent.popupUrl('toggleWin','Ansicht wechseln','/intern/index.php?view='+mode+'&inIframe=1',200,100);
  //location.reload();
}

function ddInit(ereignis)
{
  if (ddEnabled) {ddEnabled = false; return}
  if (!self['drag']) return;
  if (!ereignis) ereignis = window.event;

  if (whichDiv = document.getElementById(self['drag']))
  {  
    offsetx=ereignis.clientX;
    offsety=ereignis.clientY;
    nowX=parseInt(whichDiv.style.left);
    nowY=parseInt(whichDiv.style.top);
    ddEnabled=self['drag'];
    document.onmousemove=dd;
  }
}

function dd(ereignis2){
if (!ereignis2)
    ereignis2 = window.event;
  if (!ddEnabled) return;
  document.getElementById(ddEnabled).style.left=parseInt(nowX+ereignis2.clientX-offsetx) + "px"; 
  document.getElementById(ddEnabled).style.top=parseInt(nowY+ereignis2.clientY-offsety) + "px";
  return false;  
}

self['drag']=false;
ddEnabled = false;
document.onmousedown = ddInit;
document.onmouseup = new Function('F',"ddEnabled = false;");
