var DEBUG = true;
window.onload = jWndInit;
//=====================================
function jWndInit()
{
// restore Sroll-Position
if(gScrollpos)
	window.scrollTo(0,gScrollpos);

pomInitOnLoad();
}
//=====================================
var iPomCount = 0;
var pomMenuTimeout = 500;
pomMEntry = new Array();
var pomImgPath = "image/";
//-------------------------------------
function getObjectRect(o)
{
var obj = o;
o.top = obj.offsetTop;
o.left = obj.offsetLeft;
o.bottom = obj.offsetHeight;
o.right = obj.offsetWidth;
while((obj=obj.offsetParent)!=null)
	{
	o.top += obj.offsetTop;
	o.left += obj.offsetLeft;
	}
o.bottom += o.top;
o.right += o.left;
}
//-------------------------------------
function pomInitOnLoad()
{
var ne;
ne = document.createElement("div");
ne.id = 'popupmenu';
ne.unselectable = 'on';
ne.style.position = 'absolute';
ne.style.visibility = 'hidden';
ne.style.border = '1px solid #002d96';
ne.style.backgroundColor = '#f6f6f6';
ne.style.width = '80px';
ne.style.fontFamily = 'Arial, Helvetica, sans-serif';
ne.style.fontSize = '11px';
ne.oncontextmenu = new Function("event.returnValue=false");
ne.onmousedown =  new Function("event.cancelBubble = true;");
ne.onmouseover = new Function("pomMouseOver(this)");
ne.onmouseout = new Function("pomMouseOut(this)");
ne.timeOut = null;
document.body.appendChild(ne);
}
//-------------------------------------
function pomMouseOver(menu)
{
if(menu.timeOut)
	{
	clearTimeout(menu.timeOut);
	menu.timeOut = null;
	}
}
//-------------------------------------
function pomMouseOut(menu)
{
if(!menu.timeOut)
	menu.timeOut = setTimeout("pomMopen(this,null)",pomMenuTimeout);
}
//-------------------------------------
function pomMopenId(imageid)
{
pomMopen(document.getElementById(imageid),imageid);
}
//-------------------------------------
function pomMopen(image,menu)
{
var cntx = document.getElementById('popupmenu');
if(!cntx)
	{
	alert("Can't find the menu-DIV");
	return;
	}

var menuWidth = 100;
if(cntx.style.visibility=="hidden" && menu)
	{
	for(var i=0 ;i<pomMEntry.length; i++)
		{
		if( pomMEntry[i].menu == menu )
			menuWidth = Math.max(menuWidth,pomMAddEntry(cntx,pomMEntry[i]));
		}
	cntx.style.width = menuWidth;
	getObjectRect(image);
	if((image.right+menuWidth)>document.body.clientWidth)
		cntx.style.left = image.right - menuWidth;
	else
		cntx.style.left = image.left - 2;
	cntx.style.top = image.bottom - 3;
	cntx.style.zIndex = 4;
	cntx.style.visibility="visible";
	}
else
	{
	var divs = cntx.getElementsByTagName("div");
	for(var i=0; i<divs.length; ++i)
		{
		if(divs[i].isDynamic)
			{
			divs[i].parentNode.removeChild(divs[i]);
			--i;
			}
		}
	cntx.style.visibility = "hidden";
	}
}
//-------------------------------------
function pomMAddEntry(cntx,mEntry)
{
if(mEntry.id=='@@')
	/*document.all.popupmenu*/cntx.appendChild(pomContextLine());
else
	/*document.all.popupmenu*/cntx.appendChild(pomContextItem(mEntry,false,false));
return mEntry.mwidth;
}
//-------------------------------------
function pomContextItem(mEntry,isHead,clickFunc,isSelected)
{
var ne = document.createElement("DIV");
ne.id = mEntry.id;

var txt = '<table class="poMenu" border="0" cellpadding="0" cellspacing="0" width="100%">';
txt += '<tr><td class="poMenu" align="center" width="' + (mEntry.b+4) + '" height="' + (mEntry.h+4) + '" nowrap>';
txt += '<img src="' + pomImgPath + mEntry.img + '.gif" width="' + mEntry.b + '" height="' + mEntry.h + '" border="0" alt="" />';
txt += '</td><td class="poMenu" align="left" valign="middle" UNSELECTABLE="on" nowrap>&nbsp;' + mEntry.text + '</td></tr></table>';
ne.innerHTML = txt;

ne.isDynamic = true;
ne.unselectable = 'on';
ne.style.width = '100%';
  if (isHead)
		{
    ne.style.fontWeight = '700';
    ne.style.backgroundColor = '#E4E4E4';
		}
	else
		{
    ne.onmouseover = new Function("pomCtItemOver(this);");
    ne.onmouseout = new Function("pomCtItemOut(this);");
		}
if(mEntry.fn)
	ne.onmousedown = new Function("pomMopen(null,null);"+mEntry.fn);

return ne;
}
//-------------------------------------
function pomContextLine()
{
var ne = document.createElement("DIV");
ne.id = "L" + Math.random();
var txt = '<table class="poMenu" border="0" cellpadding="0" cellspacing="0" width="100%">';
txt += '<tr><td class="poMenu" height="3">';
txt += '<img src="' + pomImgPath + 'pomline.gif" width="100%" height="3" border="0" alt="" />';
txt += '</td></tr></table>';

ne.innerHTML = txt;
ne.isDynamic = true;
ne.unselectable = 'on';
ne.style.width = '100%';
return ne;
}
//=====================================
function pomCtItemOver(item)
{
item.style.backgroundColor='#ffeec2'; 
item.style.cursor = 'hand';
}
//-------------------------------------
function pomCtItemOut(item)
{
item.style.backgroundColor='#ffffff'; 
}
//=====================================
function pomEntry(menu,img,b,h,text,fn,mwidth)
{
pomMEntry[iPomCount++] = new PomEntryObj(menu,'pom'+iPomCount,img,b,h,text,fn,mwidth);
}
//-------------------------------------
function pomLine(menu)
{
pomMEntry[iPomCount++] = new PomEntryObj(menu,'@@',null,0,0,'',null,80);
}
//-------------------------------------
function PomEntryObj(menu,id,img,b,h,txt,fn,mwidth)
{
this.menu = menu;
this.id = id;
this.img = img;
this.b = b;
this.h = h;
this.text = txt;
this.fn = fn;
this.mwidth = mwidth;
}
//-------------------------------------
function pomClose()
{}
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
function qSearch(what)
{
var form = document.getElementById('ftransfer');
var inp = document.getElementById('quickText');
if(form && inp)
	{
	form.formaction.value = 'qFind';
	form.menu.value = 'H';
	form.mode.value = 'S';
	form.submode.value = what;
	form.submit();
	}
}
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
function jPostAction(action,vparam,fsA,fvA,fsB,fvB,fsC,fvC)
{
var form = document.getElementById('ftransfer');
if(form)
	{
	if(fsA)
		{
		var f = document.getElementById(fsA);
		if(f)
			f.value = fvA;
else alert("1.form-feld '"+fsA+"' nicht gefunden");
		}
	if(fsB)
		{
		var f = document.getElementById(fsB);
		if(f)
			f.value = fvB;
else alert("2.form-feld '"+fsB+"' nicht gefunden");
		}
	if(fsC)
		{
		var f = document.getElementById(fsC);
		if(f)
			f.value = fvC;
else alert("3.form-feld '"+fsC+"' nicht gefunden");
		}
	form.formaction.value = action;
	form.formvparam.value = vparam;
	form.submit();
	}
}
//=====================================
function jAction(menu,mode,action,vparam)
{
var form = document.getElementById('ftransfer');
if(form)
	{
	form.menu.value = menu;
	form.mode.value = mode;
	form.formaction.value = action;
	form.formvparam.value = vparam;
	form.submit();
	}
}
//=====================================
function goTransfer(action,vparam,fset,fval)
{
var form = document.getElementById('ftransfer');
if(form)
	{
	if(fset)
		{
		var f = document.getElementById(fset);
		if(f)
{
			f.value = fval;
}
else
{
form.action += "?"+fset+"="+fval;
}
		}
	form.formaction.value = action;
	form.formvparam.value = vparam;
	form.submit();
	}
}
//=====================================
//=====================================
//=====================================
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
function jStat(text)
{
window.status = text ? text : document.title;
}
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
function PgPos()
{
var ScWidth = 1024;
var ScHeight = 768;//((screen.height)-(screen.height/16));
var ScLeft = (screen.width-ScWidth);
window.top.resizeTo(ScWidth,ScHeight);
window.top.moveTo(ScLeft-1280,0);
}
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
function trOver(theRow,oldClass,newClass)
{
var theCells = null;
if(typeof(theRow.style)=='undefined')
	return false;

if(typeof(document.getElementsByTagName)!='undefined')
	theCells = theRow.getElementsByTagName('td');
else if (typeof(theRow.cells)!='undefined')
	theCells = theRow.cells;
else
	return false;

// get the current cell-class
var rowCellsCnt = theCells.length;
for(var c=0; c<rowCellsCnt; c++)
	if( theCells[c].className == oldClass )
		theCells[c].className = newClass;

return true;
}
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
var request = null;
function htcallback()
{
// 1 lade
// 2 geladen
// 3 interaktiv
// 4 vollständig
if(request.readyState == 4)
	{
	if(request.status==200)
		{
		if(request.responseText.substr(0,4)=='err:')
			alert(request.responseText.substr(4));
		else if(request.responseText=='ok')
			alert("Kommando erfolgreich ausgeführt");
		else
			{
			var xmldoc = request.responseXML;
			if(xmldoc && xmldoc.childNodes && xmldoc.childNodes[0].nodeName=='yadd')
				return(xmldoc);
else
		alert("IRGENDWIE FALSCH:\n"+request.responseText);
//			return true;
			}
		}
	else
		{
		alert("request.status: "+request.status);
		}
	}
return null;
}
//=====================================
function httpRequest(callback,params)
{
if(!request)
{
if(window.XMLHttpRequest)
	{ // Mozilla, Safari, ...
	request = new XMLHttpRequest();
	if(request)
		request.overrideMimeType('text/xml');
	}
else if(window.ActiveXObject)
	{ // IE
	request = new ActiveXObject("Microsoft.XMLHTTP");
	}
else
	{
	alert("Your browser doen't support Ajax.\nPlease buy another one...");
	return false;
	}
if(!request)
	{
	alert("Failed to send asynchronus request.\nPlease check your browser settings...");
	return false;
	}
}
request.onreadystatechange = callback;
request.open('GET',encodeURI('request.php?'+gRequestID+'&yadd='+params),true);
request.send(null);
}
//=====================================

