// BASIC FUNCTIONS *************************************************;
//Browsercheck

function browser() {
  var ua = navigator.userAgent.toLowerCase();
  if (ua.indexOf("mozilla") != -1
      && ua.indexOf("compatible") == -1
      && ua.indexOf("opera") == -1
	  && ua.indexOf("firefox") == -1 
	  && ua.indexOf("netscape") == -1) {
    return "Mozilla";
  } else if (ua.indexOf("mozilla") != -1
      && ua.indexOf("firefox") != -1) {
    return "Firefox";
  } else if (ua.indexOf("msie") != -1
             && ua.indexOf("opera") == -1) {
    return "Internet Explorer";
  } else if (ua.indexOf("opera") != -1) {
    return "Opera";
  } else if (ua.indexOf("mozilla") != -1
      && ua.indexOf("netscape") != -1) {
    return "Netscape";
  }

}
  
function versionsnummer() {
  var av = navigator.appVersion;
  var version2 = parseFloat(av.substr(0, av.indexOf(".")));
  var browsername = browser();
  if (browsername == "Mozilla") {
    return version2;
  }
  var ua = navigator.userAgent.toLowerCase();
  if (browsername == "Internet Explorer" && version2 < 4) {
    return 3;
  } else if (browsername == "Internet Explorer" && version2 == 4) {
    if (ua.indexOf("msie 4") > -1) {
      return 4;
    } else if (ua.indexOf("msie 5") > -1) {
      return 5;
    } else if (ua.indexOf("msie 6") > -1) {
      return 6;
    } else if (ua.indexOf("msie 7") > -1) {
      return 7;
    }
  } else if (browsername == "Firefox") {
    var position = ua.indexOf("firefox");
    return ua.substr(position + 8, 7);
  } else if (browsername == "Opera") {
    var position = ua.indexOf("opera");
    return ua.substr(position + 6, 4);
  } else if (browsername == "Netscape") {
    var position = ua.indexOf("netscape");
    return ua.substr(position + 9, 4);
  } else if (browsername == "Mozilla") {
    var position = ua.indexOf("rv:");
    return ua.substr(position + 3, 5);
  }
}

var useragent = browser() + versionsnummer();
var useragentname = browser();
var useragentversion = versionsnummer();

// WINDOW SIZE ; Required for windowFit()
function windowSize() 
{
    // Netscape
    if (window && window.innerHeight) 
	{
        windowH = parseInt(window.innerHeight);
		windowW = parseInt(window.innerWidth);
    } // Internet-Explorer
	else if (document && document.body && document.body.offsetHeight) 
	{
        windowH = ( parseInt(document.body.offsetHeight) - 0 );
		windowW = ( parseInt(document.body.offsetWidth) - 0 );
		
    }
}
// GET OBJEKT ; Required for tooltip: show(), hide() ; windowFit()
function getObj(name) 
{
	if (document.getElementById) 
	{
	   this.obj = document.getElementById(name);
	   this.style = document.getElementById(name).style;
	}
	else if (document.all) 
	{
	   this.obj = document.all[name];
	   this.style = document.all[name].style;
	}
	else if (document.layers) 
	{
		if (document.layers[name]) 
		{
		   	this.obj = document.layers[name];
		   	this.style = document.layers[name];
		}
	}
}

// FIND POS X Y ; Required for tooltip: show()
function findPosX(obj) 
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj) 
{
	var curtop = 0;
	if (obj.offsetParent) 
	{
		while (obj.offsetParent && obj.offsetParent.style.position != "absolute") 
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

// unready
function getMouseXY(e) {
document.onmousemove = getMouseXY;
	 x = (document.all) ? window.event.x + document.body.scrollLeft : e.pageX;
	 y = (document.all) ? window.event.y + document.body.scrollTop  : e.pageY;
	
	mousePos = new Array();
	mousePos[0] = x;
	mousePos[1] = y;
	
	return mousePos;
	//
}

// COMMON FUCTIONS *****************************************************;


// WINDOW FIT **********************************************************; 
// required: getObj(), windowSize() ; 
// Aufruf: <body onLoad="windowFit();" onResize="windowFit();">

// Setzt die Hoehe von DIV id="body" auf Fensterhoehe - Hoehe der DIVs id="header", id="footer"
// Setzt die Breite und Position von DIV id="main" auf Fensterbreite - Breite der DIVs id="left", id="right"

function windowFit() 
{
	head = new getObj('box_head');
	//var headloc = new getObj('headloc');
	bod = new getObj('box_body');
	lef = new getObj('box_left');
	//var lef_sp = new getObj('left_space');
	//var main = new getObj('main');
	var right = new getObj('box_right');
	var foot = new getObj('box_foot');

	windowSize();
	
	//ie scrollbar unterdruecken
	document.body.scroll = "no";
	
bod.style.height = ( windowH - parseInt(head.obj.offsetHeight) - parseInt(foot.obj.offsetHeight));
//bod.style.left = parseInt(lef.obj.offsetWidth);

//bod.style.width = ( windowW - parseInt(lef.obj.offsetWidth)- parseInt(right.obj.offsetWidth) );
//alert(( windowH - parseInt(head.obj.offsetHeight) - parseInt(foot.obj.offsetHeight))); 
}
// ENDE WINDOW FIT ***********************************************;


// TOOLTIP *******************************************************;
// required: getObj(), findPosX(), findPosY() ; 

// Aufruf: z.B. OBJEKT onMouseMove="show(this,'ToolTipLayer',190,0,-9,0,'l','')" onMouseOut="hideout('ToolTipLayer',200)"
// Tooltip: <div onMouseOut="hideout(this.id,500)" id="ToolTipLayer">


// tooltip hideout ; required: hide();
function hideout(lyr,timeout) 
{ 
	tohide = setTimeout('hide("'+lyr+'")', timeout);
}

function stophideout() 
{ 
	window.clearTimeout(tohide);
}

// tooltip hide ; required: getObj();
function hide(lyr) 
{
	var x = new getObj(lyr);
	x.style.visibility = 'hidden';
	M = null;
}
M = null;
Mx = null;
My = null;

function updateM(e) {

	Mx = (document.all) ? window.event.x + document.body.scrollLeft : e.pageX;
	My = (document.all) ? window.event.y + document.body.scrollTop + parseInt(head.obj.offsetHeight)  : e.pageY;
}

// tooltip show ;  required: getObj(), findPosX(), findPosY(), stophideout(), updateM(), windowSize(); 
function show(obj,lyr,width,height,xoff,yoff,posv,posh,typ) 
{   
	
	var w,h;
	var x = new getObj(lyr);
	
	if (width == 0){w = x.obj.offsetWidth;}
	else{w = width;}
	
	if (height == 0){h = x.obj.offsetHeight}
	else{h = height;}
		x.style.width = w + 'px';
		x.style.height = h + 'px';
	

	
	if (typ == 'mouse') 
	{ 
	M = new getObj(lyr);
	document.onmousemove = updateM;
		if ((Mx + w + xoff) >= windowW && posv != "l")
		{
			posv = 'l';
			xoff = - xoff;
		}
		if ((Mx - w + xoff) <= 0 && posv != "r")
		{
			posv = 'r';
			xoff = - xoff;
		}
		if ((My + h + yoff) >= windowH && posh != "o")
		{
			posh = 'o';
			yoff = - yoff;
		}
		if ((My - h + yoff) <= 0 && posh != "u")
		{
			posh = 'u';
			yoff = - yoff;
		}

		if (posv == 'l') 
		{
			var xoff = xoff - w;
			//var yoff = newY + yoff;	
			//alert(baseX +"    "+ baseY);
		}
		if (posv == 'r') 
		{
			//var xoff = xoff + obj.offsetWidth + xoff;
			//var xtop = newY + yoff;	
		}
		if (posh == 'o') 
		{
			//var xleft = newX + xoff;
			var yoff = yoff - h;	
		}
		if (posh == 'u') 
		{
			//var xleft = newX + xoff;
			//var xtop = newY + obj.offsetHeight + yoff;	
		}
		
		
		M.style.top = My + yoff + 'px';
		M.style.left = Mx + xoff + 'px';
		M.style.width = w + 'px';
		M.style.height = h + 'px';
		M.style.position = "absolute";
		M.style.visibility = "visible";
	}
	else
	{
	
		var newX = findPosX(obj);
		var newY = findPosY(obj);
	
		if (posv == 'l') 
		{
			var xleft = newX - w + xoff;
		}
		if (posv == 'r') 
		{
			var xleft = newX + obj.offsetWidth + xoff;
			var xtop = newY + yoff;	
		}
		if (posv == 'no') 
		{
			var xleft = newX + xoff;
		}
		if (posh == 'o') 
		{
			var xtop = newY - h + yoff;	
		}
		if (posh == 'u') 
		{
			var xtop = newY + obj.offsetHeight + yoff;	
		}
		if (posh == 'no') 
		{
			var xtop = newY + yoff;	
		}
		//alert(newY+" "+h+" "+x.obj.offsetHeight+" "+xtop);
		
		x.style.top = xtop + 'px';
		x.style.left = xleft + 'px';

		x.style.visibility = 'visible';
		x.style.position = 'absolute';
		x.obj.onmouseover = stophideout;
	}
}

// ENDE TOOLTIP ***************************************************;


// POPUP **********************************************************;
// Aufruf: <a href="javascript:NewWindow('../bsp.htm','popup','660','600','center','front');">popup</a>


var win = null;

function NewWindow(mypage,myname,w,h,pos,infocus)
{
	if (pos == "random")
	{
		myleft = (screen.width)?Math.floor(Math.random()*(screen.width-w)):100;
		mytop = (screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;
	}
	if (pos == "center")
	{
		myleft = (screen.width )? (screen.width-w) / 2 : 100;
		mytop = (screen.height) ? (screen.height-h) / 2 : 100;
	}
	else if ((pos != 'center' && pos != "random") || pos == null)
	{
		myleft = 20;
		mytop = 20
	}
	
	settings = "width=" + w + ",height=" + h + ",top=" + mytop + ",left=" + myleft + ",scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=yes,dependent=no";

	win = window.open(mypage,myname,settings);
	win.focus();
}

// ENDE POPUP **********************************************************;
