// Module DDX.JS
// Author: Siegfried Stephan, 56306 Dernbach, Germany
function DDX_setup(did)
{
	if(did!=""){
		div_id = document.getElementById(did);
		if(div_id){
			document.progressID = new InfoBox(did, div_id);
		}
	}
}

function DDX_call(module, fkt, callback)
{
	_ddx = document.ddxf;
	_ddx.module.value = module;
	_ddx.fkt.value = fkt;
	_ddx.callback.value = callback;
	_ddx.parms.value = "";
	for(i=3;i<DDX_call.arguments.length;i++) {
		if(_ddx.parms.value !="")
			_ddx.parms.value += "|";
		_ddx.parms.value += DDX_call.arguments[i];
	}
	_eDDX = document.getElementById("ddxf");
	_eDDX.lStatus = 0;
	_ddx.submit();	
}

function DDX_Progress(dat, msg)
{
	if(typeof(document.progressID)!="undefined"){
		if(typeof(msg)!="undefined" && msg && msg!="" && msg!=-1){
			window.status=msg;
			if(typeof(document.progressID)!="undefined")
				document.progressID.print(msg,dat);
		}
		else if(dat == -1){
			document.progressID.hide();
		}
		else{
			document.progressID.print(0, dat);
			window.status=dat+" %";
		}
	}

}


//erzeugt einen dynamischen Parameter im DDX Form
function DDX_setParameter(pname, pvalue, dSetName)
{
	_ddx = document.getElementById("ddxf");
	if(_ddx.lStatus == 0){
		DDX_reset();
	}
	if(typeof(pname)=="object"){
		DDX_setRecord(pname, pvalue, dSetName);
		return;
	}
		
    var p = document.createElement('input');
	p.type = "hidden";
	if(typeof(dSetName)!="undefined")
	    p.name = dSetName+"["+pname+"]";
	else
		p.name = pname;
	p.value = pvalue;
    _ddx.appendChild(p);
}

function DDX_setFile(pname, pelem, dSetName)
{
	_ddx = document.getElementById("ddxf");
    var p = document.createElement("input");
	p.type = pelem.type;
	p.value = pelem.value;
	p.name = pname;
    _ddx.appendChild(p);
}



function DDX_setRecord(pname, pvalue, dSetName)
{
	_ddx = document.getElementById("ddxf");
	if(typeof(dSetName)!="undefined")
		rn = dSetName;
	else
		rn = "record";

	if(typeof(_ddx.lastRecordCount[rn])!="undefined")
		_ddx.recordCounter=_ddx.lastRecordCount[rn];
	else
		_ddx.recordCounter=0;


	for(var i=0;i<pname.length;i++){
	    var p = document.createElement('input');
		p.type = "hidden";
	    p.name = rn+"["+_ddx.recordCounter+"]["+pname[i]+"]";
		p.value = pvalue[i];
    	_ddx.appendChild(p);
	}
	_ddx.recordCounter++;
	_ddx.lastRecordCount[rn] = _ddx.recordCounter;
}

function DDX_reset()
{
	_ddx = document.getElementById("ddxf");
	_ddx.lStatus = 1;
	_ddx.recordCounter=0;
	_ddx.lastRecordCount = new Array();

	fc = _ddx.firstChild;
	while(fc){
		nc= fc.nextSibling;
		_ddx.removeChild(fc);
		fc = nc;
	}
	defparms=new Array("module","fkt","callback", "parms");
	for(var t=0;t<defparms.length;t++){
		elm = document.createElement('input');
		elm.type = "hidden";
		elm.id = defparms[t];
		elm.name = defparms[t];
	    _ddx.appendChild(elm);
	}
}

	function hideElement( elmID, overDiv ) {
		var obj, i, maxi = 0;
		
		maxi = document.getElementsByTagName(elmID).length;
		for(i = 0; i < maxi; i++) {
			obj = document.getElementsByTagName(elmID)[i];
			if(!obj || !obj.offsetParent) continue;

				 // Find the element's offsetTop and offsetLeft relative to the BODY tag.
			objLeft   = obj.offsetLeft;
			objTop    = obj.offsetTop;
			objParent = obj.offsetParent;

			while(objParent.tagName.toUpperCase() != 'BODY') {
				objLeft  += objParent.offsetLeft;
				objTop   += objParent.offsetTop;
				objParent = objParent.offsetParent;
			}

			objHeight = obj.offsetHeight;
			objWidth  = obj.offsetWidth;

			if((overDiv.offsetLeft + overDiv.offsetWidth) <= objLeft)
				;
			else if((overDiv.offsetTop + overDiv.offsetHeight) <= objTop)
				;
				 /* CHANGE by Charlie Roche for nested TDs*/
			else if(overDiv.offsetTop >= (objTop + objHeight + obj.height))
				;
				 /* END CHANGE */
			else if(overDiv.offsetLeft >= (objLeft + objWidth))
				;
			else {
				obj.style.visibility = 'hidden';
			}
			obj.style.visibility = 'hidden';
		}
	}

	/*
	* unhides <select> and <applet> objects (for IE only)
	*/
	function showElement(elmID) {
		var obj, i, maxi = 0;
		
		maxi = document.getElementsByTagName(elmID).length;

		for(i = 0; i < maxi; i++) {

				obj = document.getElementsByTagName(elmID)[i];
			if(!obj || !obj.offsetParent)
				continue;
			obj.style.visibility = '';
		}
	}


/////////////////////////////////
// Infobox
////////////////////////////////
var _internalInfoBoxCounter=0;
function InfoBox(divname, divid)
{
	this._id = divname;
	this._perc=0;
	this.theDiv = divid;
	this.theElem = 0;
	this.theBar = 0;

	this.create = function()
	{
		dc='<div id="progress"><span id="'+this._id+'_content"></span><br /><div id="'+this._id+'_pbar" style="display:block;background:#2d5166;max-width:300px;width:100px;"></div></div>';
		this.theDiv.innerHTML = dc;
		this.theElem = document.getElementById(this._id+"_content");
		this.theBar = document.getElementById(this._id+"_pbar");
	};

	this.hide = function()
	{
		this._obj.visibility = 'hidden';
		this._obj.zIndex = 2;
		this._visible = false;
		this.theBar.style.visibility='hidden';
		this.theBar.style.width=0;
	};

	this.init = function()
	{
		if(this.theElem){
			this._obj=this.theElem.style;
			this.hide();
		}
	};

	this.construct = function()
	{
	};

	this.print = function(amsg, perc)
	{
		if(typeof(this._obj)=="undefined")
			return;
		if(amsg && amsg != ""){
			this._msg = amsg;
			sHTML = '';
			sHTML += amsg+'';
			this.theElem.innerHTML = sHTML;
		}

		if (this._obj.visibility == 'hidden') {
			this.show();
			this._obj.zIndex = 1000;
			this._obj.visibility = "visible";
			this.theBar.style.visibility='visible';

			this._visible = true;
		}
		if(perc>0){
			perc	= 2* Math.ceil( perc/2 );
			this.theBar.style.width=(perc*2)+"px";
			this.theBar.innerHTML = (perc)+"%";
		}
	};

	this.show = function()
	{
		if (!this._obj) 
			return;

		if (this._obj.visibility == 'hidden') {
			this._obj.visibility =  "visible" ;
			this._visible = true;
			this._obj.zIndex = 2000;
		}
		else{
			this.hide();
			this.show();
		}
	};
	this._width=300;
	this.create();
	this.init();
}



