var uA= navigator.userAgent;
var ua= navigator.userAgent.toLowerCase();
var mozvs = parseInt(navigator.appVersion); // mozilla version
var OP = (uA.indexOf('Opera')!=-1);
if (OP) {
	var OPvs=parseFloat(uA.substring(uA.indexOf('Opera')+5, uA.length));
}
var OP6minus=(OP && (OPvs<7));
var OP7plus=(OP && (OPvs>=7));
var KONQ = (uA.indexOf('Konqueror')!=-1);
var SAF = (uA.indexOf('Safari')!=-1);
var WEBKIT = (uA.indexOf('WebKit')!=-1);
var FFOX = (ua.indexOf('firefox')!=-1);
var ES = (uA.indexOf('Escape')!=-1);
var NS = ((uA.indexOf('Mozilla')!=-1) 
          && (uA.indexOf('compatible')==-1)
          && !OP && !ES); //Opera may also call itself MSIE
var NS4 = (NS && (mozvs==4));
var NS4minus = (NS && (mozvs<=4));
var NS6 = (NS && (mozvs==5)); // Netscape6Preview reports version 5. with love from directx...
var NS6plus = (NS && (mozvs>=5)); // Netscape6Preview reports version 5. with love from directx...
if (NS6plus) {
	var mozsubvs=parseFloat(uA.substring(uA.indexOf('; rv:')+5, uA.length));
	// example: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.6) Gecko/20040113
}
var MOZv16plus = (NS6 && (mozsubvs>=1.6)); // Mozilla version 1.6 and up
/* Note that opera may call itself MSIE as well. Generally, this is not
   a problem regarding the features of both browsers. But in cases of workarounds
   for bugs specific to the MS Internet Explorer, be sure to test for
   absence of opera: if (IE && !OP) { workaround... } else { feature }
*/
var IE = (uA.indexOf('MSIE')!=-1); 
var IE3 = (uA.indexOf('MSIE 3')!=-1)  
          || (uA.indexOf('MSIE3')!=-1);
var IE4 = (uA.indexOf('MSIE 4')!=-1) 
          || (uA.indexOf('MSIE4')!=-1);
var IE4plus = (IE && (mozvs>=4));
var IE5 = (uA.indexOf('MSIE 5')!=-1) 
          || (uA.indexOf('MSIE5')!=-1);
var IE6 = (uA.indexOf('MSIE 6')!=-1) 
          || (uA.indexOf('MSIE6')!=-1);
var IE6plus = IE6;
var isMac = (uA.indexOf('Mac') != -1);
var isWin = ((uA.indexOf('Windows')!=-1) 
          || (uA.indexOf('Win32')!=-1));
var isLinux = (ua.indexOf('linux') != -1);
var isUnix = (ua.indexOf('x11') != -1);
var IE5mac = (isMac && IE5);
// hasReplace is true if the browser implements location.replace() 
if ((uA.indexOf('MSIE3.02')!=-1)
  || (uA.indexOf('MSIE 3.02')!=-1)
  || IE4)
{ var hasReplace = true;}
else { hasReplace=(typeof(location.replace)!='undefined');}
if ((IE) && (mozvs<3)) {hasFuncFocus=false;} else {var hasFuncFocus=true;}

var DHTMLCAP=(document.styleSheets) || (document.documentElement);

var lokal=((location.href.indexOf('file:\/\/')==0));
var fremd=(!lokal 
&& (location.href.indexOf('.hmt.edu')==-1)
&& (location.href.indexOf('.hmt.unizh.ch')==-1)
&& (location.href.indexOf('.hmtzh.ch')==-1) 
&& !(location.href.indexOf('http:\/\/192.168.1.')==0)
&& !(location.href.indexOf('http:\/\/127.0.0.1')==0)
&& !(location.href.indexOf('http:\/\/localhost')==0)
);
var cached=(location.href.indexOf('.google.')!=-1);
// var fremd=((location.href.indexOf('www.zfh')!=-1) || (location.href.indexOf('atomz.com')!=-1));
var localpath='/hmt-website/hs-projekt/root';
var Domains=new Array('www.hmt.unizh.ch','www.hmt.edu');
var webpath='http:\/\/www.hmt.edu';

OSVersion= '';
if (isMac) {
	if (ua.indexOf('mac os x')!=-1) {
		// FIXME: this doesn't work for IE on Mac, because 'Mac OS X' doesn't show in the userAgent string.
		OSVersion= 'X';
	} 
}
if (isWin) {
	if (ua.indexOf('Windows 98')!=-1) {
		OSVersion= '98';
	} else if (ua.indexOf('Windows NT 5.0')!=-1) {
		OSVersion= '2000';
	} else if (ua.indexOf('Windows NT 5.1')!=-1) {
		OSVersion= 'XP';
	}
}

function check(eingabe)
{
  var nur_das ="0123456789-[]/";
  for (a = 0; a < eingabe.length; a++)
   {if (nur_das.indexOf(eingabe.charAt(a))<0 ) return false;}
  return true;
}

function SucheErsetze(Text,Suche,Ersetze)
  {
   var Neutext = "";
   var i = 0;
   while(i < Text.length)
    {
     if(Text.substring(i,i + Suche.length) == Suche)
      {
        Neutext = Neutext + Ersetze;
        i = i + Suche.length - 1;
      }
      else
        Neutext = Neutext + Text.substring(i,i + 1);
     i++;
    }
   return Neutext;
  }

/* some ready-to-use code */
function MM_swapImgRestore() { // v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { // v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { // v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}
 
function MM_swapImage() { // v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

// 1k DHTML API - standards version. thanks to Chris Nott.
// doc: http://www.dithered.com/experiments/1kdhtml/5kentry.html
var d=document;
var l=d.layers;
var op=uA.indexOf('Opera')!=-1;
var px='px';
// get element ( element id, frame (opt)) returns element object
function gE(e,f){if(l){f=(f)?f:self;var V=f.document.layers;if(V[e])return V[e];for(var W=0;W<V.length;)t=gE(e,V[W++]);return t;}if(d.all)return d.all[e];return d.getElementById(e);}
// show element ( element object ) makes the element visible
function sE(e){l?e.visibility='show':e.style.visibility='visible';}
// hide element ( element object ) renders the element invisible
function hE(e){l?e.visibility='hide':e.style.visibility='hidden';}
// set z-index ( element object, z-index ) sets the z-index of the element
function sZ(e,z){l?e.zIndex=z:e.style.zIndex=z;}
// set left coordinate ( element object, left )
function sX(e,x){l?e.left=x:op?e.style.pixelLeft=x:e.style.left=x+px;}
// set right coordinate ( element object, right )
function sY(e,y){l?e.top=y:op?e.style.pixelTop=y:e.style.top=y+px;}
// set width ( element object, width )
function sW(e,w){l?e.clip.width=w:op?e.style.pixelWidth=w:e.style.width=w+px;}
// set height ( element object, height )
function sH(e,h){l?e.clip.height=h:op?e.style.pixelHeight=h:e.style.height=h+px;}
// get height ( element object )
function gH(e){if(l){return e.clip.height;}else{if(op){return e.style.pixelHeight;}else{return e.style.height;}}}
// set clip rectangle ( element object, top, right, bottom, left )
function sC(e,t,r,b,x){l?(X=e.clip,X.top=t,X.right=r,X.bottom=b,X.left=x):e.style.clip='rect('+t+px+' '+r+px+' '+b+px+' '+x+px+')';}
// write html ( element object, html )
function wH(e,h){if(l){Y=e.document;Y.open();Y.write(h);Y.close();}if(e.innerHTML)e.innerHTML=h;}
// create element ( id )
function cE(i){
	if(l){
		d.layers[i]=new Layer(0);
		eval("document."+i+"=d.layers[i]");
	}else{
		if(typeof d.createElement!='undefined'){
			X="<div id='"+i+"' style=\"position:absolute\">&nbsp;</div>";
			Y=d.createElement("DIV");
			if(Y){
				Y.innerHTML=X;d.body.appendChild(Y);
			}else 
				if(typeof d.body.insertAdjacentHTML!='undefined')
					d.body.insertAdjacentHTML("BeforeEnd",X);
		}
	}
}
// MB: get html
function gHTML(e) { if(e.innerHTML)return e.innerHTML; }

// MB: toggle visibility for element by id
function tE(id) {
	o=gE(id);if (!o) return;
	if (isElementVisible(o)) { hE(o); } else { sE(o); }
}

// MB: toggle visibility for object
function tObj(e) {
	if (!e) return; if (isElementVisible(e)) { hE(e); } else { sE(e); }
}

// display row element ( element object ). returns true on success, false otherwise
function drE(e){
	if (NS4minus || IE3 || IE4 || OP6minus) return false;
	if (IE && !OP) { e.style.display='block'; }
	else { e.style.display='table-row'; }
	return true;
}
// display element ( element object ). returns true on success, false otherwise
function dE(e){
	if (NS4minus || IE3 || IE4 || OP6minus) return false;
	e.style.display='block';return true;
}
// un-display element ( element object ). returns true on success, false otherwise
function nE(e){
	if (NS4minus || IE3 || IE4 || OP6minus) return false;
	e.style.display='none';return true; 
}

// toggle display between "block" and "none". returns true on success, false otherwise
function tdE(id) {
	o=gE(id);if (!o) return false;
	if (isElementDisplayed(o)) { return nE(o); } else { return dE(o); }
}

// toggle display for table rows. returns true on success, false otherwise
function tdrE(id) {
	o=gE(id);if (!o) return false;
	if (isElementDisplayed(o)) { return nE(o); } else { return drE(o); }
}

// get z-index ( element object )
function gZ(e){if (l) return e.zIndex; else return e.style.zIndex;}

// is visible ( element object )
function isElementVisible(e) {
	if (l) return e.visibility!='hide'; else return e.style.visibility!='hidden';
}

// is displayed ( element object )
function isElementDisplayed(e) {
	if (l) return e.display!='none'; else return e.style.display!='none';
}

// get element by tag
function gEbyTag(tag) {
	if (IE3 || NS4minus) return null;
	if (document.all) { return document.all.tags(tag); } else { return document.getElementsByTagName(tag); }
}

function fillCtrl(elem, filling) {
	tn= elem.tagName;
	if (tn == 'DIV' || tn == 'SPAN') {
		elem.innerHTML= filling;
	} else {
		elem.value= filling;
	}
}

// MB: hide windowed elements with a z-index of zidx
// MB: this requires IE5
function toggleSomeWindowedElements(zidx) {
	if (IE3 || NS4minus) return;
	var objs;
	objs=gEbyTag("SELECT");if (!objs) return;
	for (var i=0; i<objs.length; i++) { if (gZ(objs[i])==zidx) { tObj(objs[i]); } }
	objs=gEbyTag("OBJECT");if (!objs) return;
	for (i=0; i<objs.length; i++) { if (gZ(objs[i])==zidx) { tObj(objs[i]); } }
	objs=gEbyTag("EMBED");if (!objs) return;
	for (i=0; i<objs.length; i++) { if (gZ(objs[i])==zidx) { tObj(objs[i]); } }
	objs=gEbyTag("IFRAME");if (!objs) return;
	for (i=0; i<objs.length; i++) { if (gZ(objs[i])==zidx) { tObj(objs[i]); } }
}

/* legacy functions not supported any more */
function ckparams() {}
function buildfs(menufile, navbarfile, mainfile) {}

function show(obj,altlink)
{
  if (document.styleSheets && !KONQ && !SAF)
  {
    if ((document.implementation) && (document.implementation.hasFeature("CSS","2.0")))
    { //for W3C DOM compliant browsers (p.e. NS6)
      SLcount=document.styleSheets.length;
      SL=document.styleSheets[SLcount-1];
      Rcount=SL.cssRules.length;
      SL.insertRule(obj+" { display:block } ",Rcount); 
    }
    else
    { //for IE browsers
      eval('document.styleSheets[document.styleSheets.length-1].addRule("'+obj+'","display:block");'); 
    }
  } else {
		idonly=(obj.charAt(0)=='#'); // first char is either # or .
		if (idonly) {
			// toggle single element only
			objelem=gE(obj.substr(1, obj.length-1));
			if (objelem)  {
				dE(objelem);
			} else if (altlink) { location.href=altlink; }
		} else {
			// toggle all tags of one class
			clsname=obj.substr(1, obj.length-1);
		  if (document.documentElement && document.documentElement.firstChild) {
		    elem=document.documentElement.firstChild;
		    traverse_tree(elem, clsname, 'block');
		  }
		  else if (altlink) { location.href=altlink; }
		}
  }
}

function traverse_tree(start, clsname, display) {
	while (start) {
		if (start.className==clsname) start.style.display=display;
		// descend
		if (start.hasChildNodes()>0) traverse_tree(start.firstChild, clsname, display);
		start=start.nextSibling;
	}
}

// show table row
function rshow(obj,altlink)
{
  if (document.styleSheets && !KONQ && !SAF)
  {
    if ((document.implementation) && (document.implementation.hasFeature("CSS","2.0")))
    { //for W3C DOM compliant browsers (p.e. NS6)
      SLcount=document.styleSheets.length;
      SL=document.styleSheets[SLcount-1];
      Rcount=SL.cssRules.length;
      SL.insertRule(obj+" { display:table-row } ",Rcount); 
    }
    else
    { //for IE browsers
      eval('document.styleSheets[document.styleSheets.length-1].addRule("'+obj+'","display:block");'); 
    }
  } else {
		idonly=(obj.charAt(0)=='#'); // first char is either # or .
		if (idonly) {
			// toggle single element only
			objelem=gE(obj.substr(1, obj.length-1));
			if (objelem)  {
				drE(objelem);
			} else if (altlink) { location.href=altlink; }
		} else {
			// toggle all tags of one class
			clsname=obj.substr(1, obj.length-1);
		  if (document.documentElement && document.documentElement.firstChild) {
		    elem=document.documentElement.firstChild;
		    traverse_tree(elem, clsname, 'table-row');
		  }
		  else if (altlink) { location.href=altlink; }
		}
  }
}

// obj is a string: either '#someid' or '.someclass'
function hide(obj,altlink)
{
  if (document.styleSheets && !KONQ && !SAF)
  {
    if ((document.implementation) && (document.implementation.hasFeature("CSS","2.0")))
    { //for W3C DOM compliant browsers (p.e. NS6)
      SLcount=document.styleSheets.length;
      SL=document.styleSheets[SLcount-1];
      Rcount=SL.cssRules.length;
      SL.insertRule(obj+" { display:none } ",Rcount); 
    }
    else
    { //for IE browsers
      eval('document.styleSheets[document.styleSheets.length-1].addRule("'+obj+'","display:none");'); 
    }
  } else {
		idonly=(obj.charAt(0)=='#'); // first char is either # or .
		if (idonly) {
			// toggle single element only
			objelem=gE(obj.substr(1, obj.length-1));
			if (objelem)  {
				nE(objelem);
			} else if (altlink) { location.href=altlink; }
		} else {
			// toggle all tags of one class
			clsname=obj.substr(1, obj.length-1);
		  if (document.documentElement && document.documentElement.firstChild) {
		    elem=document.documentElement.firstChild;
		    traverse_tree(elem, clsname, 'none');
		  }
		  else if (altlink) { location.href=altlink; }
		}
  }
}

function toggle(clssorid, inp) {
	if (inp && inp.checked) show(clssorid, ''); else hide(clssorid);
}

// row toggle
function rtoggle(clssorid, inp) {
	if (inp && inp.checked) rshow(clssorid, ''); else hide(clssorid);
}

function hidebc() {
	var e= gE('breadcrumbparts');
	if (e) hE(e);
	e= gE('breadcrumbbgparts');
	if (e) hE(e);
}

function showbc() {
	var e= gE('breadcrumbparts');
	if (e) sE(e);
	e= gE('breadcrumbbgparts');
	if (e) sE(e);
}

// case sensitive
function is_string_in_array(str, ar) {
	for (var idx in ar) {
		if (str == ar[idx]) return true;
	}
	return false;
}

function img_toggle_src(elem, src_a, src_b, loading_img) {
	if (elem.src.indexOf(src_a) >= 0) {
		if (loading_img) {
			elem.src= loading_img;
		}
		elem.src= src_b;
	} else {
		if (loading_img) {
			elem.src= loading_img;
		}
		elem.src= src_a;
	}
}

var pers_separator= ","; // must have length 1

// persistence functions

// hide element by id 'id' if id is not in persistence list
function pers_cond_hide_elem_by_id(id) {
	if (pers_is_in_list(id, pers_hash_to_list(location.hash))) return true;
	o=  gE(id);
	if (!o) return false;
	nE(o);
}

function pers_hash_to_list(hash) {
	return pers_separator + hash.substring(1) + pers_separator;
}

function pers_is_in_list(entry, list) {
	return list.indexOf(pers_separator + entry + pers_separator) >= 0;
}

function pers_list_to_hash(list) {
	return "#" + list.substring(1, list.length - 1);
}

function pers_remove_from_list(entry, list) {
	var startpos= list.indexOf(pers_separator + entry + pers_separator);
	if (startpos < 0) return list;
	var endpos= startpos + entry.length + 1;
	var res= list.substring(0, startpos) + list.substring(endpos);
	return pers_is_list_empty(res) ? pers_separator + pers_separator : res;
}

function pers_is_list_empty(list) {
	return list.length <= 2;
}

function pers_add_to_list(entry, list) {
	if (pers_is_list_empty(list)) {
		return pers_separator + entry + pers_separator;
	} else {
		if (!pers_is_in_list(entry, list)) {
			return list + entry + pers_separator;
		} else {
			return list;
		}
	}
}

function pers_add_id(id) {
	var list= pers_hash_to_list(location.hash);
	var newHash= pers_list_to_hash(pers_add_to_list(id, list));
	if (WEBKIT) {
		location.hash= newHash.substring(1);
	} else {
		location.hash= newHash;
	}
//	if (location.hash.indexOf('#%23') == 0) {
//	}
}

function pers_remove_id(id) {
	var list= pers_hash_to_list(location.hash);
	var newHash= pers_list_to_hash(pers_remove_from_list(id, list));
	if (WEBKIT) {
		location.hash= newHash.substring(1);
	} else {
		location.hash= newHash;
	}
}

// toggle element by id and add/remove it to/from persistence list
function pers_cond_toggle_elem_by_id(id) {
	o= gE(id);
	if (!o) return false;
	if (isElementDisplayed(o)) { 
		// remove element from persistence list
		pers_remove_id(id);
		return nE(o); 
	} else { 
		// add element to persistence list
		pers_add_id(id);
		return dE(o); 
	}
}

function onload_handler() {
	for (var i=0; i<olScriptIdx; i++) eval(olScripts[i]);
}
function add_onload_script(scrp) {
	olScripts[olScriptIdx++]=scrp;
}
var olScripts=new Array();
var olScriptIdx=0;



