// Zuerst definieren wir den Styleswitcher und die Box-an/ausblenderei
// This script based on Paul Snowden's work described on A List Apart
//  <http://www.alistapart.com/stories/alternate/>
// Certain modifications (setFontSize and related) by Eric Meyer
//  <http://www.meyerweb.com/eric/>
// Weitere Modifikationen von Wolfgang Wiese
// <http://www.xwolf.de>

function setActiveStyleSheet(title) {
  var i, a, main, current;
  if (title) {
    current = getActiveStyleSheet();
    if (title == current) {
       return;
    }
    if (title == 'activateleftbox') {
      if (current == 'noleft') {
        title = 'default';
      } else {
        if (current == 'noboxes') {
          title = 'noright';
        }
      }
    } else {
      if (title == 'activaterightbox') {
        if (current == 'noright') {
          title = 'default';
        } else {
          if (current == 'noboxes') {
            title = 'noleft';
          }
        }
      } else {
        if (title == 'noright') {
          if (current == 'noleft') {
            title = 'noboxes';
          } else {
            if (current == 'default') {
              title = 'noright';
            } else {
              title = 'default';
            }
          }
        } else {
          if (title == 'noleft') {
            if (current == 'noright') {
              title = 'noboxes';
            } else {
              if (current == 'default') {
                title = 'noleft';
              } else {
                title = 'default';
              }
            }
          }
        }
      }
    }


    for(i=0; (a = document.getElementsByTagName('link')[i]); i++) {
      if(a.getAttribute('rel').indexOf('style') != -1 && a.getAttribute('title')) {
        a.disabled = true;
        if(a.getAttribute('title') == title) {
          a.disabled = false;
        }
      }
    }
  }
}

function getActiveStyleSheet() {
    var i, a;
    for(i=0; (a = document.getElementsByTagName('link')[i]); i++) {
      if(a.getAttribute('rel').indexOf('style') != -1 && a.getAttribute('title') && !a.disabled) return a.getAttribute('title');
    }
    return 'default';
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName('link')[i]); i++) {
    if(a.getAttribute('rel').indexOf('style') != -1
       && a.getAttribute('rel').indexOf('alt') == -1
       && a.getAttribute('title')
       )
       return a.getAttribute('title');
  }
  return 'default';
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = '; expires='+date.toGMTString();
  }
  else expires = '';
  document.cookie = name+'='+value+expires+'; path=/';
}

function readCookie(name) {
  var nameEQ = name + '=';
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

function eraseCookie(name) {
        createCookie(name,'',-1);
}

function setFontSize(fontVal) {
        var fontSet = document.getElementById('fontSet');
        var docBase = new Array(); docBase = document.getElementsByTagName('body');
        if (!fontVal) {fontVal = document.getElementById('fontSet').value;}
        var docSize = fontVal+'px';
        createCookie('rrze-size', fontVal, 365);
        docBase[0].style.fontSize = docSize;
        if (fontSet) {fontSet.value = fontVal;}
}

window.onload = function(e) {
  var cookie = readCookie('rrze-style');
  var title = cookie ? cookie : getPreferredStyleSheet();
 // var title = 'default';
  setActiveStyleSheet(title);
 // alert(title);

//  var cookie2 = readCookie('rrze-size');
//  if (cookie2) {setFontSize(cookie2);}
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie('rrze-style', title, 14);
}


// Ab hier eigene Skripte fuer verschiedene Zwecke
function openScreenshot(url,name,width,height) {
   var privateSite;
   var params;
   width=width+20;
   height=height+20;
   params = 'width='+width+',height='+height+'menubar=0,toolbar=0,resizable=1,scrollbars=0';
   privateSite = window.open(url,name,params);
}

// Die folgenden Codes kommen aus der DIskussion ueber benutzerfreundlichere
// Bildschirmfotos, die in UseDes und CSS-design-Listen gefuehrt wurde.
// Die URL des Skriptes mit Erklaerung:
// http://cookiecrook.com/AIR/2003/train/jsexamples.php
// Author: James Craig
//  Modifikationen von Wolfgang Wiese
//      - Properties beim Aufruf der Funktion
//  (27.03.2004)

// Aufruf in HTML:
//         <a href="BILDURL" onclick="return pop(this,420,550,'scrollbars,resizable,location','Img');" onkeypress="verifyKey(this,event);">TITEL</a>
// Wobei 420 = Fensterbreite
//       550 = Fensterhoehe

// a few browser sniffs to account for known bugs
var sUserAgent = navigator.userAgent.toLowerCase();
var isIE = document.all?true:false;
var isOp = (sUserAgent.indexOf('opera')!=-1)?true:false;

// make new popup window
function pop(oAnchor,width,height,sProps,sWindow){
   var sUrl = '';
   var params;
   var defaultparams = 'scrollbars,resizable,toolbar,status,menubar,location';

        // get URL from calling link oAnchor
        if(oAnchor.getAttribute) sUrl = oAnchor.getAttribute('href');
        if(sUrl=='') sUrl = oAnchor.href;

        // if still no URL, return true and let the regular link take over
        if(sUrl=='') return true;

        // set window name ('_blank' for new window each time)
        var sWindowName = sWindow?sWindow:'reusedWindow';

        // sets default properties if none are defined in the function call optional variable 'sProps'
        if(!sProps) sProps = defaultparams;

    if(!width) {
          width = 640;
        } else {
          width=width+20;
        }
    if(!height) {
          height = 480;
        } else {
          height=height+20;
        }


    params = 'width='+width+',height='+height+','+sProps;


        // assign the popup to this variable so we can verify it exists
        if(sUrl) var oPopup = window.open(sUrl,sWindowName,params);

        // An Opera bug returns too early if you focus the window, so we don't focus it in that browser.
        // Only a noticable defect if a window is already open and hidden.
        if(oPopup && !isOp) oPopup.focus();

        // If popup was created successfully, cancel link in calling window.
        // Acts as regular link in browser that has popup blocking enabled or JavaScript turned off.
        return (oPopup)?false:true;

}

// switch an image src without preloading and leave it
// Wird f&uuml;r Bildkataloge verwendet, wie im Beispiel
// auf http://cookiecrook.com/AIR/2003/train/xmp/popup/imgview.php?img=img4.gif
function switchImg(sImg,sSrc){
        oImg = document.images[sImg];
        // return true or false based on assignment
        return !(oImg.src = 'img/' + sSrc);
}

// With onkeypress event, this verifies 'Enter' key
function verifyKey(oElement,oEvent){
        if(oEvent.keyCode==13 && oElement.onclick) oElement.onclick();
}

// Die folgende Funktion dient dazu, die SIdebar f&uuml;r Mozilla und Netscape zu oeffnen.
// Das haette auch nach validen XHTML im SOurcecode gepasst, aber der
// CSS-Validator war strenger als der HTML-Validator und hat es nicht gemocht...
function mozsidebar() {
    if ((typeof window.sidebar == "object") && (typeof window.sidebar.addPanel == "function")) {
          window.sidebar.addPanel ("RRZE",
          "http://www.rrze.uni-erlangen.de/navigation/sidebar.shtml","");
       }
       else {
          var rv = window.confirm ("Diese Funktion steht nur für Netscape 6.x oder Mozilla zur Verfügung. " + "Möchten Sie zu www.mozilla.org wechseln?");
          if (rv)
             document.location.href = "http://www.mozilla.org/";
       }
    }
