function classServer() {
	this.qsA = new Array();
	this.qs = false;
	
	if (!self.location.search) return false;
	this.qs = self.location.search.substr(1);
	var p = this.qs.split("&");
	var tmp;
	for (var i=0; i<p.length; i++) {
		tmp = p[i].split("=");
		this.qsA[tmp[0]] = (tmp[1]) ? ((decodeURI) ? decodeURI(tmp[1]) : unescape(tmp[1])) : "";
	}
	
	this.QueryString = function(name) {
		if (!name) return this.qs;
		else return this.qsA[name];
	}
	
	return this;
}
function classBrowser() {
	var tmp = null; //getXmlHttpObject();
	this.DOM = (document.getElementById);
	this.AJAX = (tmp != null);
	this.type = "unknown";
	this.version = 0;
	
	return this;
}

function printDocument() {
	window.print();
}
function printPreview() {
	/*
	var t=50,l=50,h=screen.availheight-100,w=500;
	var printWin = document.open("print.php?"+encodeURI(_SERVER.QueryString()), "printWin", "menubar=no,titlebar=no,top="+t+",left="+l+",width="+w+",height="+h);
	if (!printWin.opener) printWin.opener=self;
	*/
	var href = window.location.href;
	href += ( href.indexOf("?") > -1 ) ? "&print=1" : "?print=1";
	window.location.href = href;
}
function showDocument() {
	var href = window.location.href;
	href = href.replace(/\&print=1/, "");
	href = href.replace(/\?print=1/, "");
	window.location.href = href;
}
//Object constructor
function getObj(obj,pobj){		
	if (_BROWSER.DOM) {
		return document.getElementById(obj);
	} else if (_BROWSER.type == "MSIE") {
		return document.all[obj];
	} else if ((_BROWSER.type == "NS") && (_BROWSER.version < 5)) {
		var result = eval("document."+obj);
		if(!result&&pobj)result = eval("document.pobj.document."+obj);
		return result;
	}
	return false;
}
//Fenster öffnen
function openWindow(file,x,y,w,h) {
	var canPopup = false;
	var scrHeight = ( window.innerHeight ) ? window.innerHeight : ( ( document.body && document.body.offsetHeight ) ? document.body.offsetHeight : 0 );
	var scrWidth = ( window.innerWidth ) ? window.innerWidth : ( ( document.body && document.body.offsetWidth ) ? document.body.offsetWidth : 0 );
	if (_BROWSER.DOM && _BROWSER.AJAX && canPopup) 
	{
		if ( newWin )
		{
			newWin.style.visibility = "hidden";
			newWin.style.left = "-2000px";
		}
		else
			newWin = document.getElementById("popup");

		if ( !x )
		{
			x = 5;
			y = 5;
			w = scrWidth - 5;
			h = scrHeight - 5;
		}
		else
		{
			if ( x > scrWidth )
				x = 5;
			if ( !y )
				y = 5;
			if ( y > scrHeight )
				y = 5;
			if ( w < 0 )
				w = scrWidth + w;
			if ( (x + w) > scrWidth )
				w = scrWidth - x - 5;
			if ( w < 0 )
			{
				x = 5;
				w = scrWidth - 5;
			}
			if ( h < 0 )
				h = scrHeight + h;
			if ( (y + h) > scrHeight )
				h = scrHeight - h - 5;
			if ( h < 0 )
			{
				y = 5;
				h = scrHeight - 5;
			}
		}
		newWin.style.top = y + "px";
		newWin.style.left = x + "px";
		newWin.style.width = w + "px";
		newWin.style.height = h + "px";
		//newWinContent.style.width = w + "px";
		
		
		_HTTP = new clsAJAX();
		_HTTP.init(file, openWindow_Callback, "post");
		_HTTP.add_param("mode", "get_ajax_content");
		_HTTP.send();
	}
	else 
	{
		if(newWin){if(newWin.closed==false)newWin.close();}
		var winType = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,left=' + x + ',top=' + y;
		if ( w )
		{
  		if(w<0)w=screen.availWidth+w;
  		else if(w>screen.availWidth)w=screen.availWidth-30;
  		winType += ',width=' + w;
  	}
  	else
  	{
  	  w = scrWidth;
  	}
  	if ( h )
  	{
  		if(h<0)h=screen.availHeight+h;
  		else if(h>screen.availHeight)h=screen.availHeight-50;
  		winType += ',height=' + h;
  	}
  	else
  	{
  	  h = scrHeight;
  	}
		newWin = window.open(file, "newWin", winType);
		//newWin.resizeTo(w,h);
		if (!newWin.opener) newWin.opener=self;
		newWin.focus();
	}
	return;
}

function openWindow_Callback()
{
	if(_HTTP.ajax.readyState == 4 && _HTTP.ajax.status == 200) {
		var res = _HTTP.getResult();
		var pos = res.indexOf("||");
		document.getElementById("popup_title_content").innerHTML = res.substr(0,pos);
		document.getElementById("popup_content").innerHTML = res.substr(pos + 2);
		document.getElementById("popup_content").style.height = (parseInt(newWin.offsetHeight) - parseInt(document.getElementById("popup_title").offsetHeight) - 12) + "px";
		_HTTP = null;
		newWin.style.visibility = "visible";
	}
}

function closeWindow()
{
	if (_BROWSER.DOM && _BROWSER.AJAX) 
	{
		newWin.style.visibility = "hidden";
		newWin.style.left = "-2000px";
		newWin = false;
	}
}

function resizeWindow()
{
	var scrHeight = ( window.innerHeight ) ? window.innerHeight : ( ( document.body && document.body.offsetHeight ) ? document.body.offsetHeight : 0 );
	if ( parseInt(newWin.offsetHeight) > scrHeight )
	{
		newWin.style.height = (scrHeight - 5) + "px";
		document.getElementById("popup_content").style.height = (parseInt(newWin.offsetHeight) - parseInt(document.getElementById("popup_title").offsetHeight) - 12) + "px";
	}

	var scrWidth = ( window.innerWidth ) ? window.innerWidth : ( ( document.body && document.body.offsetWidth ) ? document.body.offsetWidth : 0 );
	if ( parseInt(newWin.offsetWidth) > scrWidth )
	{
		newWin.style.width = (scrWidth - 5) + "px";
	}
	
}

function adjust_menu()
{
	var scrollHeight = 0;
	if ( window.pageYOffset ) scrollHeight = parseInt(window.pageYOffset);
	else if ( document.documentElement && document.documentElement.scrollTop ) scrollHeight = document.documentElement.scrollTop;
	else if ( document.body && document.body.scrollTop ) scrollHeight = document.body.scrollTop;
	document.getElementById("menu").style.top = (80 + scrollHeight) + "px";
}

function start_search()
{
	if ( document.forms[0].search.value == "" )
		alert("Geben Sie bitte einen Suchbegriff ein.");
	else
		document.forms[0].submit();
}

//******************************************************************
//** AJAX FUNCTIONS
/*
 *  example
 *
function callback_function() {
	if(http.ajax.readyState == 4 && http.ajax.status == 200) {
		showMD5(http.getResult());
	}
}
var http = new clsAJAX();
http.init("url", callback_function, "post");
http.add_param("param1_name", "param1_value");
http.add_param("param2_name", "param2_value");
http.send();
*/

function getXmlHttpObject() {
	var xmlHttp = null;
	try {
	  // Firefox, Opera 8.0+, Safari
	  xmlHttp = new XMLHttpRequest();
	}
	catch (e) {
		// Internet Explorer
		try {
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
		  try {
  			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  		}
  		catch (e) {
  		  xmlHttp = null;
  		}
		}
	}
	return xmlHttp;
}
function clsAJAX() 
{
	this.url = null;
	this.callback = null;
	this.ajax = null;
	this.method = "post";
	this.can_send = false;
	this.params = new Array();
	
	//initialisierung
	this.init = function(url, callback, method) 
	{
		if (!url) 
		{
			alert ("URL is missing!");
			return;
		}
		if (!callback) callback = ajax_callback_do_nothing;
    /*{
			alert ("Callback function is missing!");
			return;
		}*/
		this.ajax = getXmlHttpObject();
		if (this.ajax == null) 
		{
			//alert ("Your browser does not support AJAX!");
			return;
		}
		if (!method) method = "post";
		this.can_send = true;
		this.url = url;
		this.callback = callback;
		this.method = method;
	}
	
	//wertepaare hinzufuegen
	this.add_param = function(pname, pvalue) 
	{
		if (!pname || pname == "") 
		{
			alert ("Error in param-name!");
			return;
		}
		if (!pvalue)
			pvalue = "";
		this.params[pname] = encodeURI(pvalue);
	}
	
	//wertepaare abrufen
	this.get_param = function(pname)
	{
		if ( !pname || !this.params[pname] )
		{
			alert ("Param-name not found!");
			return "";
		}
		
		return decodeURI(this.params[pname]);
	}
	
	//parameter loeschen
	this.clear = function() 
	{
		this.params = new Array();
	}
	
	//senden
	this.send = function() 
	{
		if (!this.can_send) 
		{
			//alert ("Object not initialized or browser does not support AJAX!");
			return;
		}
		var param = "";
		var counter = 0;
		for (var key in this.params) 
		{
			if (counter == 0) 
				param += key + "=" + this.params[key];
			else 
				param += "&" + key + "=" + this.params[key];
			counter++;
		}
		if (counter == 0) 
		{
			alert ("No parameter specified!");
			return;
		}

		if (this.method.toLowerCase() == "get") 
		{
			var con = ( this.url.indexOf("?") > -1 ) ? "&" : "?";
			this.ajax.open("GET", this.url + con + param, true);
			this.ajax.onreadystatechange = this.callback; //xmlHttpObjectResult(this);
			this.ajax.send(null);
		}
		else 
		{
			this.ajax.open("POST", this.url, true);
			this.ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			this.ajax.setRequestHeader("Content-length", param.length);
			this.ajax.setRequestHeader("Connection", "close");
			this.ajax.onreadystatechange = this.callback; //xmlHttpObjectResult(this);
			this.ajax.send(param);
		}
	}
	
	this.getResult = function(status) 
	{
		var back = this.ajax.responseText;
		var text = back.replace(/'/, "\\'");
		return text;
	}		
}
function ajax_callback_do_nothing()
{
  return;
}

var _SERVER = new classServer();
var _BROWSER = new classBrowser();
var _HTTP;
var newWin = false;
var printWin = false;


