// JavaScript Document
var css_name = 'cssname';
var css_active = 'screen';
var css_std = 'screen';

function setCookie(name, wert, domain, expires, path, secure) {
	var cook = name+"="+unescape(wert);
	cook += (domain) ? "; domain="+ domain : "";
	cook += (expires) ? "; expires="+expires : "";
	cook += (path) ? "; path="+path : "";
	cook += (secure) ? "; secure": "";
	document.cookie = cook;
}

function setStyleSheet(title) {
	var i, a;
	this.css_active = title;
	setCookie(this.css_name, this.css_active);
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel") && a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
			a.disabled = true;
			if(a.getAttribute("title") == title) {
				a.disabled = false;
			}
		}
	}
}

function addBookmark(url, title) {
 if (window.sidebar) { // Mozilla Firefox Bookmark
    window.sidebar.addPanel(title, url, '');
 } else if( window.external ) { // IE Favorite
    window.external.AddFavorite( url, title);
 } else if (window.opera && window.print) { // Opera Hotlist
    alert('Bitte Strg+D drücken / Please press Ctrl+D');
    return true;
 }
}
function tuc_change_banner() {
    img = document.getElementById('bi');
    bg = document.getElementById('bibg');
    imgdir = (document.URL.substr(0,5) == 'https' ? 'https' : 'http') +
            '://www.tu-chemnitz.de/tu/tipps/';
    if (img && typeof tuc_b == 'object') {
      max = tuc_b.length;
      if (state == 0) {
        img.style.opacity = '.50';
        img.style.filter = 'alpha(opacity=50)';
        bg.style.opacity = '.50';
        bg.style.filter = 'alpha(opacity=50)';
        state = 1;
        window.setTimeout('tuc_change_banner()', 200); // 200
      } else if (state == 1) {
        var isrc = '';
        var r = 0;
        do {
            r = parseInt(Math.random() * max);
            isrc = imgdir + tuc_b[r][0];
        } while (img.src.indexOf(isrc) != -1);
        img.src = isrc;
        bg.style.background = tuc_b[r][3] ? 
            'url(' + imgdir + tuc_b[r][3] + ') no-repeat 560px 0px' : '';
        img.title = tuc_b[r][2];
        l = document.getElementById('ba');
        if (l) l.href = tuc_b[r][1];
        state = 2;
        window.setTimeout('tuc_change_banner()', 200);
      } else {
        img.style.opacity = '1.0';
        img.style.filter = 'alpha(opacity=100)';
        bg.style.opacity = '1.0';
        bg.style.filter = 'alpha(opacity=100)';
        state = 0;
        window.setTimeout('tuc_change_banner()', 7000);
      }
    }
}

var srchtype_state = 0;
function srchtype(state) {
    var id = document.getElementById('srchtype');
    if (!id) return;
    // console.log('state='+state+', srchtype_state='+srchtype_state);
    if (state == -1) {   // close after delay
        srchtype_state = 0;
        window.setTimeout('srchtype(0)', 1000);
    } else if (state == 1) {
        srchtype_state = 1;
        id.style.display = 'block';
        document.getElementById('suchen').focus();
    } else if (state == 0 && srchtype_state != 1) {
        srchtype_state = 0;
        id.style.display = 'none';
        // console.log('close');
    }
}

function tuc_search(id, qid) {
    // id = id von div mit radio buttons (default: 'srchtype')
    // qid = id von query input (default: 'suchen')
    var suche = document.getElementById(qid ? qid : 'suchen');
    if (! suche) return true;
    if (suche.length <= 0) return false;   // kein Suchwort

    var s_type = 'text';
    var srchtype = document.getElementById(id ? id : 'srchtype');
    if (srchtype) {
        var inputs = srchtype.getElementsByTagName ('input');
        if (inputs) {
            for (var i = 0; i < inputs.length; ++i) {
                if (inputs[i].type == 'radio' && inputs[i].name == 't' && inputs[i].checked) {
                    s_type = inputs[i].value;
                    break;
                }
            }
        }
    }
    var loc = '';
    var query = escape(suche.value);
    switch (s_type) {
    case 'text': loc = 'http://suche.tu-chemnitz.de/search?output=xml_no_dtd&client=tu_frontend&proxystylesheet=tu_frontend&oe=UTF-8&ie=UTF-8&site=default_collection&tuc_ref=' +
                        escape(self.location.href) + '&q=' + encodeURIComponent(suche.value);
                break;
    case 'pers': loc = 'http://www.tu-chemnitz.de/www-index/personen.html?query=' + query;
                break;
    case 'uakt': loc = 'http://www.tu-chemnitz.de/tu/presse/aktuell/index.php?search=' + query;
                break;
    case 'goog': loc = 'http://www.google.de/search?q=' + encodeURIComponent(suche.value) + '&ie=utf-8&oe=utf-8&aq=t';
                break;
    case 'beol': loc = 'http://dict.tu-chemnitz.de/?query=' + query;
                break;
    case 'opac': loc = 'http://opac.bibliothek.tu-chemnitz.de/cgi-bin/opac_search.py?TERM_1=' + query;
                break;
    }
    if (loc)
        document.location.href = loc;

    return false;
}

// IE6 hover
klappOver = function() {
    // if (navigator.appName.indexOf("Explorer") == -1)
    //    return;
    var ids = new Array('links', 'menulinks', 'menurechts');
    for (var k = 0; k < ids.length; k++ ) { 
        if (! document.getElementById(ids[k]))
            continue;
        var klappEl = document.getElementById(ids[k]).getElementsByTagName('li');
        for (var i = 0; i < klappEl.length; i++) {
            var classNames = klappEl[i].className.split(' ');
            for (var j = 0; j < classNames.length; j++) {
                if (classNames[j] == 'klapp') {
                    // alert(klappEl[i].className);
                    klappEl[i].onmouseover=function() {
                        this.className += ' over';
                    }
                    klappEl[i].onmouseout=function() {
                        this.className = this.className.replace(' over', '');
                    }
                    break;
                }
            }
        }
    }
}
if (window.attachEvent) window.attachEvent('onload', klappOver);

/*
document.getElementsByClassName = function(className) {
	var children = document.getElementsByTagName('*') || document.all;
	var elements = new Array();
  
	for (var i = 0; i < children.length; i++) {
		var child = children[i];
		var classNames = child.className.split(' ');
		for (var j = 0; j < classNames.length; j++) {
			if (classNames[j] == className) {
				elements.push(child);
				break;
			}
		}
	}
	return elements;
}
*/

