var Styles_       = "";
var Width_        = 70;
var Height_       = 23;
var ButtonType_   = "";
var CloseButton_  = 58;

function browserWindow()
{
   this.getYPos=function(wndHeight)
   {
      var scrollTop = document.body.scrollTop;
      if (window.pageYOffset != 'undefined' && scrollTop == 0)
         scrollTop = document.documentElement.scrollTop;
      else if (document.documentElement && scrollTop == 0)
         scrollTop = document.documentElement.scrollTop;

      if (window.innerWidth)
         return (this.getHeight() - wndHeight) / 2 + scrollTop;
      else
         return (this.getHeight() - wndHeight) / 2 + scrollTop - this.IEoffset;
      /*
      else //IE
         return (this.getHeight() - wndHeight + scrollTop) / 2;
      */
   }

   this.getWidth=function()
   {
	   if(window.innerWidth)
		   return (window.innerWidth);
	   if(document.body.offsetWidth)
		   return (document.body.offsetWidth);
	   return(-1);
   }

   this.getHeight=function()
   {
	   if(window.innerHeight)
		   return (window.innerHeight);

	   if(document.documentElement && document.documentElement.clientHeight)
	      return document.documentElement.clientHeight;

	   if(document.body.offsetHeight)
		   return (document.body.getClientRects(0)[0].bottom);//(document.body.offsetHeight-4);
	   return(-1);
   }

   this.strAgent=String(navigator.userAgent).toLowerCase();
   this.isMac=false;
   this.isOpera=false;
   this.isFirefox=false;
   this.isIE7=false;
   this.isKonqueror=false;
   this.isSeamonkey=false;
   this.Browser=0;
   this.IEoffset = 0;

   if(this.strAgent.indexOf("msie 7.")!=-1)
   {
      Styles_ = "padding-bottom:1px;";
	   this.isIE7=true;
	   return;
   }
   if(this.strAgent.indexOf("macintosh")!=-1||this.strAgent.indexOf("safari")!=-1)
   {
      var Version = this.strAgent.substr (this.strAgent.indexOf("safari") + 7) * 1;
      if (Version < 520)
      {
	      Width_ = Width_ - 5;
         Height_ = Height_ - 7
	      Styles_ = "padding-top:4px; padding-left:3px;";
	   }
	   CloseButton_ = 56;
	   this.isMac=true;
	   this.Browser=1;
	   return;
   }
   if(this.strAgent.indexOf("opera")!=-1)
   {
	   this.isOpera=true;
	   Styles_ = "padding-top:4px; padding-left:3px;";
	   this.Browser=2;
	   return;
   }
   if(this.strAgent.indexOf("firefox")!=-1)
   {
      Styles_ = "padding-bottom:4px; padding-left:5px;";
      CloseButton_ = 56;
	   this.isFirefox=true;
	   this.Browser=3;
	   return;
   }
   if(this.strAgent.indexOf("konqueror")!=-1)
   {
	   this.isKonqueror=true;
	   this.Browser=4;
	   return;
   }
   if(this.strAgent.indexOf("seamonkey")!=-1)
   {
	   this.isSeamonkey=true;
	   this.Browser=5;
	   return;
   }

}

   
var browserWnd = new browserWindow();

wndBox_wnd = null;
wndBox_overlay = null;
wndBox_onKeyPressOld = null;

function wndBox(n, w, h, title, text, txtArr, cbArr, _IMGurl, _debMode)
{
	this.name      = n;
	this.width     = w;
	this.height    = h;
	this.title     = title;
	this.text      = text;
	this.bText     = txtArr;
	this.bCallback = cbArr;
	this.IMGurl    = _IMGurl;
	this.defaultID = 0;
	this.UseDefaultButtons = true;
	this.debugMode = _debMode ? true : false;
	this.IEoffset = 0; //z.B. für Frames, da die bei der body-Höhe mitgezählt werden

   if (wndBox_wnd == null)
   {
      wndBox_wnd                           =  document.createElement("DIV");
      document.body.appendChild (wndBox_wnd);
      wndBox_wnd.id                        = "wnd";
      wndBox_wnd.style.display             = "none";
      wndBox_wnd.style.zIndex              = 56;
      
      wndBox_overlay                       = document.createElement("IFRAME");
      document.body.appendChild (wndBox_overlay);
      wndBox_overlay.id                    = "overlay";
      wndBox_overlay.style.display         = "none";
      wndBox_overlay.style.backgroundColor = "#000000";
      wndBox_overlay.style.backgroundcolor = "#000000";
      wndBox_overlay.style.position        = "absolute";
      wndBox_overlay.style.top             = "0px";
      wndBox_overlay.style.left            = "0px";
      wndBox_overlay.style.width           = "0px";
      wndBox_overlay.style.height          = "0px";
      wndBox_overlay.style.zIndex          = 55;
   }
	this.Show=function()
	{
      wndBox_onKeyPressOld	= document.body.onkeypress;  
      document.body.onkeypress = KeyPress_;
      
	   document.body.focus();
		l = (browserWnd.getWidth()-this.width)/2;
		browserWnd.IEoffset = this.IEoffset;
	   t = browserWnd.getYPos(this.height);
		z = wndBox_wnd;
		z.style.position  = "absolute";
		z.style.left      = l + "px";
		z.style.top       = t + "px";
		z.style.width     = this.width + 20 + "px";
		z.style.height    = this.height + 200 + "px";


      html =
            '<table cellpadding=0 cellspacing=0><tr><td class="msgBoxshadow" style="background-image: url(/graphic/alert/alrt_ul.png); height:7px; width:7px;"></td><td class="msgBoxshadow" style="background-image: url(/graphic/alert/alrt_um.png); height:7px;"></td><td class="msgBoxshadow" style="background-image: url(/graphic/alert/alrt_ur.png); height:7px; width:7px;"></td></tr><tr><td class="msgBoxshadow" style="background-image: url(/graphic/alert/alrt_l.png);"></td><td>\n' +
            '<div id="msgBox" style="width:' + (this.width) + 'px; height:' + (this.height) + 'px;">\n' +
            '  <img class="msgBoxCloseBtn" src="/graphic/design2007/close.png" style="margin-left:' + (this.width - CloseButton_) + 'px;" onclick="wndBox_wnd.alertWindow.destroy();" onmouseover="this.src=\'/graphic/design2007/closered.png\'" onmouseout="this.src=\'/graphic/design2007/close.png\'" />\n' +
            '  <div id="msgBoxContainer" style="width:' + (this.width) + '; height:' + (this.height) + 'px;">\n' +
            '     <div id="msgBoxTitle">\n' +
            '        <span class="msgBoxTitleShadow"><b>' + this.title + '</b></span>\n' +
            '        <span class="msgBoxTitle"><b>' + this.title + '</b></span>\n' +
            '     </div>\n' +
            '     <div id="msgBoxContentBorder" style="width:' + (this.width - 26) + 'px;">\n' +
            '        <div id="msgBoxContent" style="width:' + (this.width - 28) + 'px;">\n' +
            '           <table style="height:' + (this.height - 96) + 'px;" class="msgBoxText">\n' +
            '              <tr>\n' +
            '                 <td class="imgCell">\n' +
            '                    <img src="' + (this.IMGurl ? this.IMGurl : '/graphic/alert/question.gif') + '" />\n' +
            '                 </td>\n' +
            '                 <td class="txtCell">' + this.text + '</td>\n' +
            '              </tr>\n' +
            '           </table>\n' +
            '           <div id="msgBoxButton">\n';

            for(i=0;i<txtArr.length;i++)
            {
               if(txtArr[i].charAt(0) == "!")
               {
                  BGImgUrl       = this.UseDefaultButtons ? "/graphic/buttons/completed/tobitPush_70x23.png" : "/graphic/buttons/completed/tobitPush_70x23.png";
                  ButtonTyp_     = "button";
                  txtArr[i]      = txtArr[i].substr(1);
                  this.defaultID = i;
               }
               else
               {
                  BGImgUrl       = this.UseDefaultButtons ? "/graphic/buttons/completed/tobit_70x23.png" : "/graphic/buttons/completed/tobit_70x23.png";;
                  //BGImgUrl       = "/include/buttons/ButtonImage.aspx?name=tobit&width=70&height=23";
                  ButtonTyp_     = "button";
               
               }
	            html+='<button name="Button" id="Button" type="' + ButtonTyp_ + '" onKeyPress="' + this.name + '.KeyPress_();" onClick="'+this.name+'.bCallback['+i+']();' + this.name + '.destroy();" value="" class="imgButton" style="'+Styles_+' margin-left:9px; background-image: url(' + BGImgUrl + '); height:' + Height_ + 'px; width:' + Width_ + 'px;" onMouseOver="this.className=\'imgButtonHover\';" onMouseOut="this.className=\'imgButton\';">'+txtArr[i]+'</button>'; // Buttons

            }
            html +=
            '           </div>\n' +
            '        </div>\n' +
            '     </div>\n' +
            '  </div>\n' +
            '  <img class="msgBoxAlphaImg" src="/graphic/design2007/captionalphachannel.png" />\n' +
            '</div>\n' +
            '</td><td class="msgBoxshadow" style="background-image: url(/graphic/alert/alrt_r.png);"></td></tr><tr><td class="msgBoxshadow" style="background-image: url(/graphic/alert/alrt_ll.png); height:7px; width:7px;"></td><td class="msgBoxshadow" style="background-image: url(/graphic/alert/alrt_lm.png); height:7px;"></td><td class="msgBoxshadow" style="background-image: url(/graphic/alert/alrt_lr.png); height:7px; width:7px;"></td></tr></table>\n';
                                       
				
		z.innerHTML                      = html;//.replace (/</g, "&lt;").replace (/\n/g, "<br>").replace (/ /g, "&nbsp;&nbsp;&nbsp;");
      wndBox_wnd.alertWindow           = this;

		wndBox_overlay.style.display     = "block";
		z.style.display                  = "block";
	}

	this.destroy=function()
	{
		wndBox_overlay.style.display     = "none";
		wndBox_wnd.innerHTML             = "";
		wndBox_wnd.style.display         = "none";
		document.body.onkeypress = wndBox_onKeyPressOld;
	}
	
	function KeyPress_(Ereignis)
	{
	   if (!Ereignis)
	   {
	      Ereignis                      = window.event;
	      Ereignis.cancelBubble         = true;
	   }

      var Key_ = Ereignis.keyCode;
      if (Key_ == 27)
      {
         wndBox_wnd.alertWindow.destroy();
         return false;
      }
      else if (Key_ == "13")
      {
         wndBox_wnd.alertWindow.bCallback[wndBox_wnd.alertWindow.defaultID]();
         wndBox_wnd.alertWindow.destroy();
         return false;
      }
     
   }

}
