// SNF JAVASCRIPT utility_functions.js VERSION 1.2a
// See http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html


// Tue Jul  3 10:49:42 CEST 2007 add wallpaperstuetze by OMS; j.spegel@swp.de
adlWallPaperLeft=786;

// Files and directory structures
var cssDir = "/styles/";
var winNSCSS = "styles_win_ns.css";
var winIECSS = "styles_win_ie.css";
var macCSS = "styles_mac.css";
var unixCSS = "styles_unix.css";
var unixMozCSS = "styles_unix_moz.css";
var TickerContent = "";

// *************************************************************
//  CLIENT_SIDE SNIFFER CODE
// *************************************************************
// convert all characters to lowercase to simplify testing
var agt=navigator.userAgent.toLowerCase();


// *** BROWSER VERSION ***
// Note: On IE5, these return 4, so use is_ie5up to detect IE5.
var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);


// *** BROWSER TYPE ***
var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
            && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
           && (agt.indexOf('webtv') == -1));


var is_nav4up = (is_nav && (is_major >= 4));
var is_nav4   = (is_nav && (is_major == 4));
var is_nav5   = (is_nav && (is_major == 5));
var is_nav6 = (document.getElementById && !document.all); 
var is_ie   = (agt.indexOf("msie") != -1);
var is_ie3  = (is_ie && (is_major < 4));
var is_ie4  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")==-1) );
var is_ie4up  = (is_ie  && (is_major >= 4));
var is_ie5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
var is_ie5up  = (is_ie  && !is_ie3 && !is_ie4);
var is_konq = ((agt.indexOf('mozilla')!=1) && (agt.indexOf('konqueror')!=-1));
var is_dom = (document.getElementById && !document.all);

// *** PLATFORM ***
var is_win   = ( (agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1) );
var is_mac    = (agt.indexOf("mac")!=-1);
var is_sun   = (agt.indexOf("sunos")!=-1);
var is_irix  = (agt.indexOf("irix") !=-1);    // SGI
var is_hpux  = (agt.indexOf("hp-ux")!=-1);
var is_aix   = (agt.indexOf("aix") !=-1);      // IBM
var is_linux = (agt.indexOf("inux")!=-1);
var is_sco   = (agt.indexOf("sco")!=-1) || (agt.indexOf("unix_sv")!=-1);
var is_unixware = (agt.indexOf("unix_system_v")!=-1);
var is_mpras    = (agt.indexOf("ncr")!=-1);
var is_reliant  = (agt.indexOf("reliantunix")!=-1);
var is_dec   = ((agt.indexOf("dec")!=-1) || (agt.indexOf("osf1")!=-1) ||
       (agt.indexOf("dec_alpha")!=-1) || (agt.indexOf("alphaserver")!=-1) ||
       (agt.indexOf("ultrix")!=-1) || (agt.indexOf("alphastation")!=-1));
var is_sinix = (agt.indexOf("sinix")!=-1);
var is_freebsd = (agt.indexOf("freebsd")!=-1);
var is_bsd = (agt.indexOf("bsd")!=-1);
var is_unix  = ((agt.indexOf("x11")!=-1) || is_sun || is_irix || is_hpux ||
             is_sco ||is_unixware || is_mpras || is_reliant ||
             is_dec || is_sinix || is_aix || is_linux || is_bsd || is_freebsd);

var myLayers = new Object();
var resizeDaten = new Object();
resizeDaten.NullPunkt = new Object();
resizeDaten.Groesse = new Object();
var navNestedLayers = false;
var visibleLayers = [];
var preDoneLayers = [];
var initLayersDone = true;
var showroomWin = null;
var MenueUnten = false;


// Define genObj and genStyle in order to handle layer actions
if (is_ie)
  {
    genObj="document.all";
    genStyle=".style";
    genX=".offsetLeft";
    genY=".offsetTop";
  }

if (is_nav)
  {
    genObj="document.layers";
    genStyle="";
    genX=".x";
    genY=".y";
}


// *********************************************************************
//  UTILITY FUNCTIONS
// *********************************************************************
// Function to handle window resizing on Navigator 4
function handleResize() {
   if (((initWidth != window.innerWidth) || (initHeight != window.innerHeight)) && (typeof disableReload == "undefined")) {
     location.reload();
   }
   return false;
}



// preLoad function to preload all the images given by argument
function preLoadImg()
  {
    var imgArray = new Array();
    for (var i = 0; i < preLoadImg.arguments.length; i++)
      {
        imgArray[i] = new Image();
        imgArray[i].src = preLoadImg.arguments[i];
    }
}

// createObj to create an layer-object
function createObj(divName) {
    if(is_dom){
            var stand_obj=document.getElementById(divName);
            if (stand_obj && stand_obj.style) var obj=stand_obj.style;
              else var obj = "";
    }
    else{
            var obj=eval(genObj+"['"+divName+"']"+genStyle);
    }
    return obj;
}


// show a given layer
function showDiv(divName) {
    if (!initLayersDone)
      {
        preDoneLayers = addLayer('s_' + divName, preDoneLayers);
        window.status = preDoneLayers.length + ' Aktionen in der Warteschlange';
        return(1);
    }
  if ((typeof divName == "undefined") || (divName == "")) return (-1);
  var obj = createObj(divName);
  if ((typeof obj == "undefined") || (obj == "")) return (-1);
  obj.visibility='visible';
//  alert(obj.visibility);
//  obj.zIndex = 20;

  return(1);
}

// hide a given layer
function hideDiv(divName) {
    if (!initLayersDone)
      {
        preDoneLayers = addLayer('h_' + divName, preDoneLayers);
        window.status = preDoneLayers.length + ' Aktionen in der Warteschlange';
        return(1);
    }
  if ((typeof divName == "undefined") || (divName == "")) return (-1);
  var obj = createObj(divName);
  if ((typeof obj == "undefined") || (obj == "")) return (-1);
  obj.visibility='hidden';
//  obj.zIndex = 1;

  return(1);
}

function show2(showName, hideArray)
  {
    show(showName);
    if (typeof hideArray == "undefined")  hideArray = hideArrayO;
    for (var i = 0; i < hideArray.length; i++)
      {
        if (showName != hideArray[i]) hide(hideArray[i]);
    }
}

function hide2(hideArray)
  {
    if (typeof hideArray == "undefined")  hideArray = hideArrayO;
    for (var i in hideArray)
      hide(hideArray[i]);
}


function newWin(url, name, props)
  {
    var pos = url.indexOf("#?");
    if (pos != -1)
      {
        var strg1 = url.substring(0, pos);
        var strg2 = url.substring((pos + 1), url.length);
        url = strg1 + strg2;
    }
    var nW = window.open(url, name, props);
}

    
  function showProps(obj)
    {alert("starting to analyze...");
      if (!obj)
        {
          alert("Kein Objekt!");
          return(false);
      }
      
      if (typeof obj != "object")
        {
          alert(obj)
          return(false);
      }
      var count = 0;
      var Text = "";
      for (var i in obj)
        {
//          Text += i + "\n";
          Text += i  + " = " + obj[i] + "\n";
          count++; 
          if (count == 1)
            {
              ok = confirm(Text);
              if (!ok) return(false);
              count = 0;
              Text = "";
          }
      }
//      alert(Text);
  }

function show_erscheinung(name) {
  if (MenueUnten) {
    hide('erscheinung');
  }
  else {
    show('erscheinung');
  }
  MenueUnten = !MenueUnten;
}

function toggle(name) {
  if (MenueUnten) {
    hideDiv(name);
  }
  else {
    showDiv(name);
  }
  MenueUnten = !MenueUnten;
  
  return false;
}


function fenster(ort,w,h)
{
  win = window.open(ort, 'Neues_Fenster', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width='+w+',height='+h+',screenX=20,screenY=20,left=20,top=20');
  win.focus();  
}

// size background to max 
function setBackgoundImage()
{
   var maxHeight = 0;
   var Obj;
   
   Obj = document.getElementById('naviBoxLeft');
   if ( Obj ) { maxHeight = Obj.offsetHeight+5;  }

   Obj = document.getElementById('bannerLeft');
   if ( Obj ) {  maxHeight += Obj.offsetHeight+5;   }
   
   Obj = document.getElementById('contentBox');
   if ( Obj ) { maxHeight = Math.max(maxHeight, (Obj.offsetHeight+5) ); 	}

   Obj = document.getElementById('naviBoxRight');
   if ( Obj ) {  maxHeight = Math.max(maxHeight, (Obj.offsetHeight+5) );   }

   Obj = document.getElementById('SWOblowup');
   if ( Obj ) Obj.height = maxHeight + 10 ;

}


function setRegionLayer()
{
   var ObjPfeil = document.getElementById('naviPfeil');
   var ObjLayer = document.getElementById('naviregion');
   
   if ( ObjPfeil && ObjLayer )
   {
      if ( is_ie ) {
        ObjLayer.style.left = 166 - ObjPfeil.offsetLeft;
      }
      else {
        ObjLayer.style.left = ObjPfeil.x - 114;
        ObjLayer.style.top  = ObjPfeil.y + 13;
      }
   }  
}

function setLoginLayer()
{
   var ObjPfeil = document.getElementById('naviPfeilLogin');
   var ObjLayer = document.getElementById('navilogin');
   
   if ( ObjPfeil && ObjLayer )
   {
      if ( is_ie ) {
        ObjLayer.style.left = (764 - ObjPfeil.offsetLeft);
      }
      else {
        ObjLayer.style.left = ObjPfeil.x - 130;
        ObjLayer.style.top  = ObjPfeil.y + 17;
      }
   }   
}


function setBannerLayer()
{
    var ObjNavi   = document.getElementById('naviBoxLeft');
    var ObjBanner = document.getElementById('bannerLeft');

	if ( ObjNavi && ObjBanner )
	{
		ObjBanner.style.top = ObjNavi.offsetHeight + ObjNavi.offsetTop ;
	}   
}

//initialisierung navi-layer in den seiten:

function initPages()
  { 
    // No inframe presentation
    if ( (top.frames.length > 0) && 
         (top.location.href != document.location.href) 
       )
       top.location.href = document.location.href;

    // search for rollover pictures
    mystic();
    
    // tickermeldung darstellen
    if ( TickerContent )
       populate();

   	// set size of background and navilayers
	
   	setRegionLayer();
   	setLoginLayer();
   	setBackgoundImage();
   	setBannerLayer();
	
	
    if (is_nav)
      {
        window.captureEvents(Event.RESIZE);
        window.onresize = handleResize;
        initWidth = window.innerWidth;
        initHeight = window.innerHeight;
    }

    menuPos = 0;
    bildPos = 0;
    
}


function handleResize() {
   if (((initWidth != window.innerWidth) || (initHeight != window.innerHeight)) && (typeof disableReload == "undefined")) {
     location.reload();
   }
   return false;
}


//initialisierung fuer die layers
function init() 
{
  if(is_ie || is_konq )
  {
	  genObj="document.all"
	  genStyle=".style"
  }

  if(is_nav4up)
  {
	  genObj="document.layers"
	  genStyle=""
  }
}

init();

function bbcode(v,c)
 {
 if (document.selection) // f?r IE
   {
    var str = document.selection.createRange().text;
    document.forms['artikel'].elements['artinput_text'].focus();
    var sel = document.selection.createRange();
    if ( c==false ) {
        sel.text = "<" + v + ">" + str + "</" + v + ">"; }
    else {
        sel.text = "<!--" + v + "-->" + str + "<!--/" + v + "-->"; }
    return;
   }
  else if ((typeof document.forms['artikel'].elements['artinput_text'].selectionStart) != 'undefined') // f?r Mozilla
   {
    var txtarea = document.forms['artikel'].elements['artinput_text'];
    var selLength = txtarea.textLength;
    var selStart = txtarea.selectionStart;
    var selEnd = txtarea.selectionEnd;
    //if (selEnd == 1 || selEnd == 2)
    //selEnd = selLength;
    var s1 = (txtarea.value).substring(0,selStart);
    var s2 = (txtarea.value).substring(selStart, selEnd)
    var s3 = (txtarea.value).substring(selEnd, selLength);
    if ( c==false ) {
        txtarea.value = s1 + '<' + v + '>' + s2 + '</' + v + '>' + s3; }
    else {
        txtarea.value = s1 + '<!--' + v + '-->' + s2 + '<!--/' + v + '-->' + s3; }
    txtarea.selectionStart = s1.length;
    txtarea.selectionEnd = s1.length + 5 + s2.length + v.length * 2;
    return;
   }
  else {
        if ( c==false ) {
                insert('<' + v + '></' + v + '> ');
                }
        else {
                insert('<!--' + v + '--><!--/' + v + '--> ');
                }
        } 
 }
 
function bbcodeimg(v)
 {
 if (document.selection) // f?r IE
   {
    var str = document.selection.createRange().text;
    document.forms['artikel'].elements['artinput_text'].focus();
    var sel = document.selection.createRange();
    sel.text = "<!--bild"+v+"-->";
    return;
   }
  else if ((typeof document.forms['artikel'].elements['artinput_text'].selectionStart) != 'undefined') // f?r Mozilla
   {
    var txtarea = document.forms['artikel'].elements['artinput_text'];
    var selLength = txtarea.textLength;
    var selStart = txtarea.selectionStart;
    var selEnd = txtarea.selectionEnd;
    //if (selEnd == 1 || selEnd == 2)
    //selEnd = selLength;
    var s1 = (txtarea.value).substring(0,selStart);
    var s2 = (txtarea.value).substring(selStart, selEnd)
    var s3 = (txtarea.value).substring(selEnd, selLength);
    txtarea.value = s1 +  s2 + '<!--bild'+v+'-->' + s3;
    txtarea.selectionStart = s1.length;
    txtarea.selectionEnd = s1.length + 5 + s2.length + v.length * 2;
    return;
   }
  else insert('<!--bild'+v+'-->');
 }

function bbcodeurl(v)
 {
 if (document.selection) // f?r IE
   {
    var str = document.selection.createRange().text;
    document.forms['artikel'].elements['artinput_text'].focus();
    var sel = document.selection.createRange();
    sel.text = "<a href=\"http://www. \">" + str + "   </a>";
    return;
   }
  else if ((typeof document.forms['artikel'].elements['artinput_text'].selectionStart) != 'undefined') // f?r Mozilla
   {
    var txtarea = document.forms['artikel'].elements['artinput_text'];
    var selLength = txtarea.textLength;
    var selStart = txtarea.selectionStart;
    var selEnd = txtarea.selectionEnd;
    //if (selEnd == 1 || selEnd == 2)
    //selEnd = selLength;
    var s1 = (txtarea.value).substring(0,selStart);
    var s2 = (txtarea.value).substring(selStart, selEnd)
    var s3 = (txtarea.value).substring(selEnd, selLength);
    txtarea.value = s1 + '<a href=\"http://www.\">' + s2 + '</a>' + s3;
    txtarea.selectionStart = s1.length;
    txtarea.selectionEnd = s1.length + 5 + s2.length + v.length * 2;
    return;
   }
  else insert('<a href=\"http://www.\"></a> ');
 }
 

