// Pers-DB Ergebnisse in neuem Fenster

function win(number,name) {
    if ( name == 'PERS') {
       url = "http://online.univie.ac.at/pers.html?pkey="+number;
       xxx  = 400;
       yyy = 280;
       scr = "yes";
    }
    if ( name == 'INT') {
       url = "https://cti.univie.ac.at/internal.html";
       xxx =  250;
       yyy =  120;
       scr = "yes";
    }
    var w = window.open(url,
        name,
        "width="+xxx+
        ",height="+yyy+",screenX=200,screenY=200,scrollbars="
        +scr+",menubar=no,resizable="+scr);
    w.focus();
    return false;
}


// Stylesheet setzen inkl. Cookie

function setActiveStyleSheet(title) {
  var i, a, main;
  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 null;
}

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 null;
}

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 "standard";
}

window.onload = function(e) {
  var cookie = readCookie("ZIDweb_style");
  var title = (cookie != "null" && cookie != null && cookie != "") ? cookie : "standard"; 

  setActiveStyleSheet(title);
  createCookie("ZIDweb_style", title, 365);
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("ZIDweb_style", title, 365);
}

// Capslock check

function capsDetect( e ) {
	if( !e ) { e = window.event; } if( !e ) { MWJ_say_Caps( false ); return; }
	//what (case sensitive in good browsers) key was pressed
	var theKey = e.which ? e.which : ( e.keyCode ? e.keyCode : ( e.charCode ? e.charCode : 0 ) );
	//was the shift key was pressed
	var theShift = e.shiftKey || ( e.modifiers && ( e.modifiers & 4 ) ); //bitWise AND
	//if upper case, check if shift is not pressed. if lower case, check if shift is pressed
	MWJ_say_Caps( ( theKey > 64 && theKey < 91 && !theShift ) || ( theKey > 96 && theKey < 123 && theShift ) );
}
function MWJ_say_Caps( oC ) {
	if( typeof( capsError ) == 'string' ) { if( oC ) { alert( capsError ); } } else { capsError( oC ); }
}
