/******************************************************************************
Common JavaScript library functions
Copyright (c) 2002 SoftLogic
Version: 1.3
Last modified: 08.09.2009
Hint: All functions starting with sl_ are Copyright (c) 2002 SoftLogic
******************************************************************************/
/******************************************************************************   
DHTML library from DHTMLCentral.com
Copyright (C) 2001 Thomas Brattli 2001
This script was released at DHTMLCentral.com
Visit for more great scripts!
This may be used and changed freely as long as this msg is intact!
We will also appreciate any links you could give us.
Made by Thomas Brattli 2001
Hint: Functions not starting with sl_ are Copyright (C) 2001 Thomas Brattli
******************************************************************************/

// absolutely necessary globals
var bw = new lib_bwcheck(); // check browser
var mDebugging = 2; // general debugging variable, 0 no, 1 alerts, 2 status line
var eHandler = new Array(); // global event handler array
var args = sl_getArguments(); // get arguments
var offlineHost = "www2.ak-funktechnik.de";
var onlineHost = "www.ak-funktechnik.de";
var sitePath = new Array(); // global path array

/*****************************************************************************
function lib_bwcheck()
Default browsercheck
******************************************************************************/
function lib_bwcheck() { //Browsercheck (needed)
	this.ver=navigator.appVersion; this.agent=navigator.userAgent
	this.dom=document.getElementById?1:0
	this.moz=this.agent.indexOf("Gecko") > -1
	this.ie5=(this.ver.indexOf("MSIE 5") > -1 && this.dom) ? 1 : 0;
	this.ie6=((this.ver.indexOf("MSIE 6") > -1 || this.ver.indexOf("MSIE 7") > -1 || this.ver.indexOf("MSIE 8") > -1) && this.dom) ? 1 : 0;
	this.ie4=(document.all && !this.dom)?1:0;
	this.ie=this.ie4||this.ie5||this.ie6
	this.mac=this.agent.indexOf("Mac")>-1
	this.opera5=this.agent.indexOf("Opera 5")>-1
	this.ns6 = (this.dom && parseInt(this.ver) >= 5) ? 1 : 0;
	this.ns4=(document.layers && !this.dom)?1:0;
	if (this.moz) {
	    this.ie6 = 0
	    this.ie = 0
	    this.ns4 = 0
	    this.ns6 = 1
	    this.mac = 0
	    this.opera5 = 0
	}
	this.cuf = (this.ie6 || this.ver.indexOf("MSIE 5.5") > -1) && !this.mac
	this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5 || this.dom)
	return this
}

/*****************************************************************************
function sl_init()
main initialization routine for library, invoked via onload event handler
******************************************************************************/
function sl_init(){
	// activate event handlers
	if (eHandler['onresize'] != null){
		if (bw.ns4 || bw.ns6) {window.captureEvents(Event.RESIZE);}
		window.onresize = eHandler['onresize'];
	}
}

/*****************************************************************************
function sl_getHostURL()
the variables onlineHost und offlineHost must be defined
returns the URL of the host of the current page
******************************************************************************/
function sl_getHostURL(){
	var hname = window.location.host;
	return window.location.protocol+'\/\/'+hname;
}

/*****************************************************************************
function sl_hackNS4ResizeProblem()
Reloads the current page (needed for NS4 layout problem with CSS)
******************************************************************************/
function sl_hackNS4ResizeProblem(){
	// hack for NS 4 resize problem with positioned elements
	if (bw.ns4){window.captureEvents(Event.RESIZE);location.reload();return false;}
}

/*****************************************************************************
function sl_getArguments
parse "&" separated "name=value" argument pairs from the query string of an URL
******************************************************************************/
function sl_getArguments(){
	var args = new Object();
	var aquery = location.search.substring(1);
	var apairs = aquery.split('&');
	for(var i = 0; i < apairs.length; i++){
		var pos = apairs[i].indexOf('=');
		if (pos == -1) continue;
		var aname = apairs[i].substring(0,pos);
		var avalue = apairs[i].substring(pos+1);
		args[aname] = unescape(avalue);
	}
	return args;
}

/*****************************************************************************
function sl_framecheck(strFSFile)
puts frame pages into the correct frameset (based on code from Andrew Daviel)
******************************************************************************/
function sl_framecheck(strFSFile){
	if (typeof strFSFile == "undefined" || args.print) return;
	var FSUrl = sl_getHostURL()+'\/'+strFSFile;
	var ploc = parent.document.location + '';
	if (ploc.indexOf(FSUrl,0) < 0){
		parent.document.location = FSUrl;
	}
}

/*****************************************************************************
function sl_genSitePath
generate HTML site path (start >> level1 >> level2 >> ..) 
from global sitePath array
elemIDs must be a string of nested divs, separated by ","
******************************************************************************/
function sl_genSitePath(elemIDs){
	var d = document;
	if (bw.ns4){
		var arrDivs = elemIDs.split(",");
		var strNDivs = "document";
		for(i=0; i<arrDivs.length; i++) 
			strNDivs = strNDivs + "." + arrDivs[i] + ".document";
		d = eval(strNDivs);
	}
	var hosturl = sl_getHostURL();
	if(sitePath.length < 2) return;
	d.write('<b>Sie sind hier: <\/b>');
	if(sitePath[0].length > 0){
		d.write('<a href="'+hosturl+'\/'+sitePath[0]+
		'" target="_self">');}
	d.write(sitePath[1]);
	if(sitePath[0].length > 0)
		d.write('<\/a>');
	for(var i= 2; i < sitePath.length-1; i=i+2){
		d.write(' &raquo; ');
		if(sitePath[i].length > 0){
			d.write('<a href="'+hosturl+'\/'+sitePath[i]+
			'" target="_self">');}
		d.write(sitePath[i+1]);
		if(sitePath[i].length > 0)
			d.write('<\/a>');
		}
}

/*****************************************************************************
function sl_switchpview
switch between print and normal (framed) view of a page
******************************************************************************/
function sl_switchpview(){
	var strURL="";
	var strSearch="";
	if (args.print){
		window.history.back();
		setTimeout("sl_reload_noargs()",200);
	}
	else{
		window.parent.location=document.location+'?print=true';
	}
}

/*****************************************************************************
function sl_loadnoargs
reloads the page without arguments
******************************************************************************/
function sl_reload_noargs(){
	window.location = sl_urlnoargs();
}

/*****************************************************************************
function sl_urlnoargs
returns the current url without args
******************************************************************************/
function sl_urlnoargs(){
	var strSearch = document.location.search;
	var strURL = window.location.toString();
	return strURL.substr(0,strURL.length-strSearch.length);
}

/*****************************************************************************
function lib_message
Show debug message
******************************************************************************/
function lib_message(txt){alert(txt); return false}

/*****************************************************************************
function lib_obj
Generate library object
******************************************************************************/
function lib_obj(obj,nest){ 
  if(!bw.bw) return lib_message('Old browser')
  nest=(!nest) ? "":'document.'+nest+'.'
  this.evnt=bw.dom? document.getElementById(obj):
    bw.ie4?document.all[obj]:bw.ns4?eval(nest+"document.layers." +obj):0;	
  if(!this.evnt) return lib_message('The layer does not exist ('+obj+')' 
    +'- \nIf your using Netscape please check the nesting of your tags!')
  this.css=bw.dom||bw.ie4?this.evnt.style:this.evnt; 
  this.ref=bw.dom||bw.ie4?document:this.css.document;
  this.x=parseInt(this.css.left)||this.css.pixelLeft||this.evnt.offsetLeft||0;
  this.y=parseInt(this.css.top)||this.css.pixelTop||this.evnt.offsetTop||0
  this.w=this.evnt.offsetWidth||this.css.clip.width||
    this.ref.width||this.css.pixelWidth||0; 
  this.h=this.evnt.offsetHeight||this.css.clip.height||
    this.ref.height||this.css.pixelHeight||0
  this.c=0 //Clip values
  if((bw.dom || bw.ie4) && this.css.clip) {
  this.c=this.css.clip; this.c=this.c.slice(5,this.c.length-1); 
  this.c=this.c.split(' ');
  for(var i=0;i<4;i++){this.c[i]=parseInt(this.c[i])}
  }
  this.ct=this.css.clip.top||this.c[0]||0; 
  this.cr=this.css.clip.right||this.c[1]||this.w||0
  this.cb=this.css.clip.bottom||this.c[2]||this.h||0; 
  this.cl=this.css.clip.left||this.c[3]||0
  this.obj = obj + "Object"; eval(this.obj + "=this")
  return this
}

/*****************************************************************************
function lib_obj
Generate document size object
******************************************************************************/
function lib_doc_size(){ 
  this.x=0;this.x2=bw.ie && document.body.offsetWidth-20||innerWidth||0;
  this.y=0;this.y2=bw.ie && document.body.offsetHeight-5||innerHeight||0;
  if(!this.x2||!this.y2) return message('Document has no width or height') 
  this.x50=this.x2/2;this.y50=this.y2/2;
  return this;
}

/*****************************************************************************
function moveIt
Move the object to
******************************************************************************/
lib_obj.prototype.moveIt = function(x,y){
  this.x=x;this.y=y; this.css.left=x;this.css.top=y;
}

/*****************************************************************************
function showIt
Show the object
******************************************************************************/
lib_obj.prototype.showIt = function(){this.css.visibility="visible"}

/*****************************************************************************
function hideIt
Hide the object
******************************************************************************/
lib_obj.prototype.hideIt = function(){this.css.visibility="hidden"}

/*****************************************************************************
function sl_posFromBottom
Position the object y from document bottom
******************************************************************************/
lib_obj.prototype.sl_posFromBottom = function(y,limit){
	var page=new lib_doc_size();
	var newY = page.y2-this.h-y
	if (newY < limit) newY = limit;
	this.moveIt(this.x,newY);
	this.showIt();
}

/*****************************************************************************
function sl_posCenter
Position the object in the center of the page
*****************************************************************************/
lib_obj.prototype.sl_posCenter = function(limx, limy){
	var page=new lib_doc_size();
	var x = Math.round(page.x50-(this.w/2));
	var y = Math.round(page.y50-(this.h/2));
	if (x < limx) x = limx;
	if (y < limy) y = limy;
	this.moveIt(x,y);
    this.showIt();
}

/*****************************************************************************
function sl_circlePoint
calulate circle point
******************************************************************************/
function sl_circlePoint(xc,yc,rad,a,result){
	result['x'] = xc + rad*Math.cos(a*Math.PI/180)
	result['y'] = yc - rad*Math.sin(a*Math.PI/180)
}

/*****************************************************************************
function sl_fadeDIV
fade a division, IE5.5+ only
******************************************************************************/
function sl_fadeDIV(strDivId,strDuration){
	var elem = document.all[strDivId];
    elem.style.filter = "progid:DXImageTransform.Microsoft.Fade(duration="+strDuration+")";
	elem.filters[0].apply();
	if (elem.style.visibility=="visible")
		elem.style.visibility="hidden";
	else
		elem.style.visibility="visible";
	elem.filters[0].play();
}