

// Jah stuff, just a container for DHTLGoodies' DynamicContent
function jah(url,target) {
	if (typeof showLoading != "undefined")
		document['loading'].src = showLoading.loadingOn.src;
	// native XMLHttpRequest object
	//document.getElementById(target).innerHTML = 'getting data...';
	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
		req.onreadystatechange = function() {jahDone(target);};
		req.open("GET", url, true);
		req.send(null);
	// IE/Windows ActiveX version
	} else if (window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
		if (req) {
			req.onreadystatechange = function() {jahDone(target);};
			req.open("GET", url, true);
			req.send();
		}
	}
}	

function jahDone(target) {
	// only if req is "loaded"
	if (req.readyState == 4) {
		// only if "OK"
		if (req.status == 200) {
			results = req.responseText;
			document.getElementById(target).innerHTML = results;
			if (typeof showLoading != "undefined")
				document['loading'].src = showLoading.loadingOff.src;
		} else {
			document.getElementById(target).innerHTML="jah error:\n" +
				req.statusText;
			if (typeof showLoading != "undefined")
				document['loading'].src = showLoading.loadingOff.src;
		}
		execJS( document.getElementById(target) );
	}
}

// This executes JAVASCRIPT in a JAH call...
var bSaf = (navigator.userAgent.indexOf('Safari') != -1);
var bOpera = (navigator.userAgent.indexOf('Opera') != -1);
var bMoz = (navigator.appName == 'Netscape');
function execJS(node) {
	var st = node.getElementsByTagName('SCRIPT');
	var strExec;
	for(var i=0;i<st.length; i++) {     
		if (bSaf)
			strExec = st[i].innerHTML;
		else if (bOpera)
			strExec = st[i].text;
		else if (bMoz)
			strExec = st[i].textContent;
		else
			strExec = st[i].text;
		try {
			eval(strExec);
		} catch(e) {
 			alert(e);
		}
	}
}

// Cookies stuff

function writeSessionCookie (cookieName, cookieValue, days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
    document.cookie = escape(cookieName) + "=" + escape(cookieValue) + expires + "; path=/";
    return true;
}

function getCookieValue (cookieName) {
  var exp = new RegExp (escape(cookieName) + "=([^;]+)");
  if (exp.test (document.cookie + ";")) {
    exp.exec (document.cookie + ";");
    return unescape(RegExp.$1);
  }
  else return false;
}

// Adds an item to a drop-down list
function AddTo_List(theList, optionValue, optionText) {
//	document.getElementById(theList).options[document.getElementById(theList).options.length] = new Option(optionText, optionValue, true, true );
	var elOptNew = document.createElement('option');
	elOptNew.text = optionText;
	elOptNew.value = optionValue;
	var elSel = document.getElementById(theList);

	try {
		elSel.add(elOptNew, null); // standards compliant; doesn't work in IE
	}
	catch(ex) {
		elSel.add(elOptNew); // IE only
	}
}

// Positioning
function getPosition(item){
	var left = 0;
	var top  = 0;
	var e = document.getElementById(item);

	while (e.offsetParent){
		left += e.offsetLeft;
		top  += e.offsetTop;
		e     = e.offsetParent;
	}

	left += e.offsetLeft;
	top  += e.offsetTop;

	return [top, left];
}

// credit to http://www.13thparallel.org for the following 2 functions
// returns amount of vertical scroll
function getScrollY() {
	var sy = 0;
	if (document.documentElement && document.documentElement.scrollTop)
		sy = document.documentElement.scrollTop;
	else if (document.body && document.body.scrollTop) 
		sy = document.body.scrollTop; 
	else if (window.pageYOffset)
		sy = window.pageYOffset;
	else if (window.scrollY)
		sy = window.scrollY;
	return sy;
}

// returns amount of horizontal scroll
function getScrollX() {
	var sx = 0;
	if (document.documentElement && document.documentElement.scrollLeft)
		sx = document.documentElement.scrollLeft;
	else if (document.body && document.body.scrollLeft) 
		sx = document.body.scrollLeft; 
	else if (window.pageXOffset)
		sx = window.pageXOffset;
	else if (window.scrollX)
		sx = window.scrollX;
	return sx;
}



//******************************************************************************
// roberthilbe.com Basic Javascripts
// Author:   Robert Hilbe
// Version:  9 September 2005
//******************************************************************************/

/******************************************************************************
 showandhide: Shows or Hides an Element
******************************************************************************/

function showandhide(Id) {
	if (document.getElementById) {
		target = document.getElementById(Id);
		if (target.style.display == "none" || target.style.display == "") {
			target.style.display = "block";
		} else {
			target.style.display = "none";
		}
	}
}

/******************************************************************************
 show: Zeigt ein Element
******************************************************************************/

function show(Id) {
	if (document.getElementById) {
		target = document.getElementById(Id);
		target.style.display = "block";
	}
}

/******************************************************************************
 hide: Verbirgt ein Element
******************************************************************************/

function hide(Id) {
	if (document.getElementById) {
		target = document.getElementById(Id);
		target.style.display = "none";
	}
}

/******************************************************************************
 setStyle: Setzt eine bestimmte CSS-Eigenschaft eines Elements fest
******************************************************************************/

function setStyle(id, property, value) {
	var object = document.getElementById(id);
	if(object != null) {
		var styleObject = object.style;
		if(styleObject[property] = value) return true;
	}
	else return false;
}

/******************************************************************************
 move: Positioniert einen div neu
******************************************************************************/

function move(id,top,left) {
	styleObject = document.getElementById(id).style;
	if(styleObject) {
		if (!isNaN(top))
			top = top + 'px';
		styleObject.top = top;
		if (!isNaN(left))
			left = left + 'px';
		styleObject.left = left;
		}
	}

/******************************************************************************
 jumpMenu: Springt mittels Select-Formular auf eine bestimmte Seite
******************************************************************************/

function jumpMenu(selObj) {
	eval("location='"+selObj.options[selObj.selectedIndex].value+"'");
}


/******************************************************************************
 targetId: sends a target div the content to an ID div
******************************************************************************/

function targetId(Target,Id){
	document.getElementById(Target).innerHTML = document.getElementById(Id).innerHTML;
}

/******************************************************************************
 slideElement: Slides an Element by (x) and (y), (inc) defines Speed (from http://adactio.com)
******************************************************************************/

function slideElement(elementId,x,y,inc) {
	if (!document.getElementById) return false;
	if (!document.getElementById(elementId)) return false;
	var element = document.getElementById(elementId);
	if (element.sliding) clearTimeout(element.sliding);
	if (!element.xpos) element.xpos = 0;
	if (!element.ypos) element.ypos = 0;
	if (element.xpos == x && element.ypos == y) return true;
	if (element.xpos > x) {
		var dist = Math.ceil((element.xpos-x)/inc);
		element.xpos = element.xpos - dist;
	}
	if (element.xpos < x) {
		var dist = Math.ceil((x-element.xpos)/inc);
		element.xpos = element.xpos + dist;
	}
	if (element.ypos > y) {
		var dist = Math.ceil((element.ypos-y)/inc);
		element.ypos = element.ypos - dist;
	}
	if (element.ypos < y) {
		var dist = Math.ceil((y-element.ypos)/inc);
		element.ypos = element.ypos + dist;
	}
	element.style.left = element.xpos+'px';
	element.style.top = element.ypos+'px';
	element.sliding = setTimeout('slideElement("'+elementId+'",'+x+','+y+','+inc+')',10);
}


/******************************************************************************
 Fadomatic: Fads Elements in or out (siehe http://chimpen.com/fadomatic/)

 INTERVAL_MILLIS: Fade interval in milliseconds (Make this larger if you experience performance issues
 function Fadomatic creates a fader: element to falde, speed (0-100), minimum opacity (0-100), maximum opacity (0-100)
 function fadeIn: starts fading in 
 function fadeOut: starts fading out:
 function makeVisible: sets opacity to maximum
 function makeTransparent: sets opacity to minimum
******************************************************************************/

// Fade interval in milliseconds
// Make this larger if you experience performance issues
Fadomatic.INTERVAL_MILLIS = 50;

// Creates a fader
// element - The element to fade
// speed - The speed to fade at, from 0.0 to 100.0
// initialOpacity (optional, default 100) - element's starting opacity, 0 to 100
// minOpacity (optional, default 0) - element's minimum opacity, 0 to 100
// maxOpacity (optional, default 0) - element's minimum opacity, 0 to 100
function Fadomatic (element, rate, initialOpacity, minOpacity, maxOpacity) {
  this._element = element;
  this._intervalId = null;
  this._rate = rate;
  this._isFadeOut = true;

  // Set initial opacity and bounds
  // NB use 99 instead of 100 to avoid flicker at start of fade
  this._minOpacity = 0;
  this._maxOpacity = 99;
  this._opacity = 99;

  if (typeof minOpacity != 'undefined') {
    if (minOpacity < 0) {
      this._minOpacity = 0;
    } else if (minOpacity > 99) {
      this._minOpacity = 99;
    } else {
      this._minOpacity = minOpacity;
    }
  }

  if (typeof maxOpacity != 'undefined') {
    if (maxOpacity < 0) {
      this._maxOpacity = 0;
    } else if (maxOpacity > 99) {
      this._maxOpacity = 99;
    } else {
      this._maxOpacity = maxOpacity;
    }

    if (this._maxOpacity < this._minOpacity) {
      this._maxOpacity = this._minOpacity;
    }
  }
  
  if (typeof initialOpacity != 'undefined') {
    if (initialOpacity > this._maxOpacity) {
      this._opacity = this._maxOpacity;
    } else if (initialOpacity < this._minOpacity) {
      this._opacity = this._minOpacity;
    } else {
      this._opacity = initialOpacity;
    }
  }

  // See if we're using W3C opacity, MSIE filter, or just
  // toggling visiblity
  if(typeof element.style.opacity != 'undefined') {

    this._updateOpacity = this._updateOpacityW3c;

  } else if(typeof element.style.filter != 'undefined') {

    // If there's not an alpha filter on the element already,
    // add one
    if (element.style.filter.indexOf("alpha") == -1) {

      // Attempt to preserve existing filters
      var existingFilters="";
      if (element.style.filter) {
        existingFilters = element.style.filter+" ";
      }
      element.style.filter = existingFilters+"alpha(opacity="+this._opacity+")";
    }

    this._updateOpacity = this._updateOpacityMSIE;
    
  } else {

    this._updateOpacity = this._updateVisibility;
  }

  this._updateOpacity();
}

// Initiates a fade out
Fadomatic.prototype.fadeOut = function () {
  this._isFadeOut = true;
  this._beginFade();
}

// Initiates a fade in
Fadomatic.prototype.fadeIn = function () {
  this._isFadeOut = false;
  this._beginFade();
}

// Makes the element completely opaque, stops any fade in progress
Fadomatic.prototype.show = function () {
  this.haltFade();
  this._opacity = this._maxOpacity;
  this._updateOpacity();
}

// Makes the element completely transparent, stops any fade in progress
Fadomatic.prototype.hide = function () {
  this.haltFade();
  this._opacity = 0;
  this._updateOpacity();
}

// Halts any fade in progress
Fadomatic.prototype.haltFade = function () {

  clearInterval(this._intervalId);
}

// Resumes a fade where it was halted
Fadomatic.prototype.resumeFade = function () {

  this._beginFade();
}

// Pseudo-private members

Fadomatic.prototype._beginFade = function () {

  this.haltFade();
  var objref = this;
  this._intervalId = setInterval(function() { objref._tickFade(); },Fadomatic.INTERVAL_MILLIS);
}

Fadomatic.prototype._tickFade = function () {

  if (this._isFadeOut) {
    this._opacity -= this._rate;
    if (this._opacity < this._minOpacity) {
      this._opacity = this._minOpacity;
      this.haltFade();
    }
  } else {
    this._opacity += this._rate;
    if (this._opacity > this._maxOpacity ) {
      this._opacity = this._maxOpacity;
      this.haltFade();
    }
  }

  this._updateOpacity();
}

Fadomatic.prototype._updateVisibility = function () {
  
  if (this._opacity > 0) {
    this._element.style.visibility = 'visible';
  } else {
    this._element.style.visibility = 'hidden';
  }
}

Fadomatic.prototype._updateOpacityW3c = function () {
  
  this._element.style.opacity = this._opacity/100;
  this._updateVisibility();
}

Fadomatic.prototype._updateOpacityMSIE = function () {
  
  this._element.filters.alpha.opacity = this._opacity;
  this._updateVisibility();
}

Fadomatic.prototype._updateOpacity = null;


