 window.defaultStatus="MSS Elektronik";
 var Root_Dir = "/";
 var ThemeImg = "/Theme/";
 var ImageDir = "/Images/";

 var ClientPC  = navigator.userAgent.toLowerCase();
 var ClientVer = parseInt(navigator.appVersion);

 var Is_Ie  = ((ClientPC.indexOf('msie') != -1) && (ClientPC.indexOf('opera') == -1));
 var Is_Win = ((ClientPC.indexOf('win')  != -1) || (ClientPC.indexOf('16bit') != -1));

 if(top != self)
  {top.location = self.location;}

 function MozWrap(TextArea, Open, Close)
  {
   var SelLength = TextArea.textLength;
   var SelStart  = TextArea.selectionStart;
   var SelEnd    = TextArea.selectionEnd;
   var ScrollTop = TextArea.scrollTop;

   if(SelEnd == 1 || SelEnd == 2)
    {SelEnd = SelLength;}

   var S1 = (TextArea.value).substring(0,SelStart);
   var S2 = (TextArea.value).substring(SelStart, SelEnd)
   var S3 = (TextArea.value).substring(SelEnd, SelLength);

   TextArea.value          = S1 + Open + S2 + Close + S3;
   TextArea.selectionStart = SelEnd + Open.length + Close.length;
   TextArea.selectionEnd   = TextArea.selectionStart;
   TextArea.focus();
   TextArea.scrollTop      = ScrollTop;

   return;
  }

 function CaretPosition()
  {
   var start = null;
   var end   = null;
  }

 function GetCaretPosition(TextArea)
  {
   var CaretPos = new CaretPosition();

   // simple Gecko/Opera way
   if(TextArea.selectionStart || TextArea.selectionStart == 0)
    {
     CaretPos.start = TextArea.selectionStart;
     CaretPos.end   = TextArea.selectionEnd;
    }else
   // dirty and slow IE way
   if(document.selection)
    {
     // get current selection
     var Range = document.selection.createRange();

     // a new selection of the whole textarea
     var Range_All = document.body.createTextRange();
     Range_All.moveToElementText(TextArea);

     // calculate selection start point by moving beginning of range_all to beginning of range
     var Sel_Start;
     for (Sel_Start = 0; Range_All.compareEndPoints('StartToStart', Range) < 0; Sel_Start++)
      {Range_All.moveStart('character', 1);}

     TextArea.sel_start = Sel_Start;

     // we ignore the end value for IE, this is already dirty enough and we don't need it
     CaretPos.start = TextArea.sel_start;
     CaretPos.end   = TextArea.sel_start;
    }
   return CaretPos;
  }

 function StoreCaret(Text)
  {
   if(Text.createTextRange)
    {Text.caretPos = document.selection.createRange().duplicate();}
  }


 function Insert_Text(TextArea,Text)
  {
   if(!isNaN(TextArea.selectionStart))
    {
     var Sel_Start = TextArea.selectionStart;
     var Sel_End   = TextArea.selectionEnd;

     MozWrap(TextArea, Text, '')
     TextArea.selectionStart = Sel_Start + Text.length;
     TextArea.selectionEnd   = Sel_End   + Text.length;
    }else
   if(TextArea.createTextRange && TextArea.caretPos)
    {
     var Caret_Pos  = TextArea.caretPos;
     Caret_Pos.text = Caret_Pos.text.charAt(Caret_Pos.text.length - 1) == ' ' ? Caret_Pos.text + Text + ' ' : Caret_Pos.text + Text;
    }
    else
    {
     TextArea.value = TextArea.value + Text;
    }

   TextArea.focus();
  }

 function InsertText(TextArea,AddTextOpen,AddTextClose)
  {
   if(!AddTextOpen) {AddTextOpen  = "";}
   if(!AddTextClose){AddTextClose = "";}

   TextArea.focus();

   if ((ClientVer >= 4) && Is_Ie && Is_Win)
    {
     var TheSelection = document.selection.createRange().text;
     if(TheSelection)
      {
       document.selection.createRange().text = AddTextOpen + TheSelection + AddTextClose;
       TextArea.focus();
       return;
      }
    }else
   if(TextArea.selectionEnd && (TextArea.selectionEnd - TextArea.selectionStart > 0))
    {
     MozWrap(TextArea, AddTextOpen, AddTextClose);
     TextArea.focus();
     return;
    }


   var Caret_Pos = GetCaretPosition(TextArea).start;
   var New_Pos   = Caret_Pos + AddTextOpen.length;

   Insert_Text(TextArea,AddTextOpen + AddTextClose);

   if (!isNaN(TextArea.selectionStart))
    {
     TextArea.selectionStart = New_Pos;
     TextArea.selectionEnd   = New_Pos;
    }
    else if (document.selection)
    {
     var Range = TextArea.createTextRange();
     Range.move("character", New_Pos);
     Range.select();
     StoreCaret(TextArea);
    }

   TextArea.focus();
   return;
  }

 function PreloadImages()
  {
   var D = document;
   if(D.images)
    {
     if(!D.PreP)
      {D.PreP = new Array();}

     var I;
     var J = D.PreP.length;
     var A = PreloadImages.arguments;

     for(I=0; I<A.length; I++)
      if (A[I].indexOf("#") != 0)
       {
        D.PreP[J]        = new Image;
        D.PreP[J++].src  = A[I];
       }
    }
  }

 function ButtonFindObj(Name, Doc)
  {
   var p,i,x;
   if(!Doc)
    {Doc = document;}
   if((p = Name.indexOf("?")) > 0 && parent.frames.length)
    {
     Doc  = parent.frames[Name.substring(p+1)].document;
     Name = Name.substring(0,p);
    }

   if(!(x = Doc[Name]) && Doc.all)
    {x = Doc.all[Name];}

   for(i=0;!x&&i < Doc.forms.length;i++)
    {x = Doc.forms[i][Name];}

   for(i=0;!x&&d.layers&&i < Doc.layers.length;i++)
    {x = findObj(Name,Doc.layers[i].document);}

   if(!x && document.getElementById)
    {x = document.getElementById(Name);}
   return x;
  }

 function Button_Hover(Event,BtnName)
  {
   var i, img, ButtArr,args = Button_Hover.arguments;

   if(Event == "over")
    {
     document.ButonOver = ButtArr = new Array();
     for (i=1; i < args.length-1; i+=3)
      {
       if((img = ButtonFindObj(args[i])) != null)
        {
         if (!img.ImgUp)
          {img.ImgUp = img.src;}
         img.src = (img.ImgDn && args[i+2]) ? args[i+2] : args[i+1];
         ButtArr[ButtArr.length] = img;
        }
      }
    } else
   if(Event == "out" )
    {
     for (i=0; i < document.ButonOver.length; i++)
      {
       img = document.ButonOver[i];
       img.src = (img.ImgDn) ? img.ImgDn : img.ImgUp;
      }
    }
  }

 function SetPointer(theRow, theRowNum, theAction, theStyle, asHeader)
  {
   var thePointerColor = "#FFF9BB";
   var theCells        = null;
   var theDefaultColor = "#808080";
   if(theStyle == 1){theDefaultColor = "#DDDDDD";}// DDDDDD
   if(theStyle == 2){theDefaultColor = "#CCCCCC";}// CCCCCC

   var domDetect    = null;
   var currentColor = null;
   var newColor     = null;
   if(typeof(window.opera) == 'undefined' && typeof(theRow.getAttribute) != 'undefined')
    {domDetect = true;}
    else
    {domDetect = false;}

   if(asHeader)
    {
     if(theAction == 1){newColor = thePointerColor;}
                   else{newColor = theDefaultColor;}
    }
    else
    {
     if(typeof(theRow.style) == 'undefined')
      {return false;} // Auf Style kann nicht zugegriffen werden => Exit

    if(domDetect)
     {currentColor = theRow.getAttribute('bgcolor');}
     else
     {currentColor = theRow.style.backgroundColor;}

     if((currentColor.toLowerCase() == theDefaultColor.toLowerCase()) && (theAction == 1)){newColor = thePointerColor;}
     else
     if((currentColor.toLowerCase() == thePointerColor.toLowerCase()) && (theAction == 0)){newColor = theDefaultColor;}
    }

   if(typeof(theRowNum) == 'object')
    {
     for(var Count=0;Count<theRowNum.length;Count++)
      {
       if(newColor)
        {
         if(domDetect)
          {theRow.parentNode.rows[theRowNum[Count]].setAttribute('bgcolor', newColor, 0);}
          else
          {theRow.parentNode.rows[theRowNum[Count]].style.backgroundColor = newColor;}
        }
      }
    }
    else
    {
     if(newColor)
      {
       if(domDetect)
        {theRow.setAttribute('bgcolor', newColor, 0);}
        else
        {theRow.style.backgroundColor = newColor;}
      }
    }
   return true;
  }

 function PopUp(site,name,width,height)
 {
  var Left = (screen.width  / 2)-(width  / 2);
  var Top  = (screen.height / 2)-(height / 2);
  Fenster = window.open(site,name,"width="+width+",height="+height+",left="+Left+",top="+Top+",scrollbars=yes,resizable=yes,menubar=no,status=yes,toolbar=no,location=no,dependent=no");
 }

 function LogOn(Type)
  {
   if(!Root_Dir){Root_Dir="";}
   if(Type)
    {PopUp(Root_Dir+"LogOn.php","LogOnPopUp",400,280);}
    else
    {PopUp(Root_Dir+"LogOn.php","LogOnPopUp",400,50);}
  }

 function SelectClock(Id,Code)
  {
   document.getElementsByName("ClockNr")[0].value   = "Uhr Nummer "+Id;
   document.getElementsByName("ClockCode")[0].value = Code;
  }

 function OpenImage(File,Width,Height,Title)
 {
  var Url = "";
  if(Title){Url = "&Title="+Title;}
  PopUp(Root_Dir+"OpenImg.php?File="+File+Url,"OpenImg",parseInt(Width)+40,parseInt(Height)+40);
 }
