
/*
QXCode Softwareproduction
Copyright 2006, Thomas Tauchner
xq2 verified
---------------------------------------
Team: non
Teamleader: Thomas Tauchner;thomas.tauchner@qxcode.com
Partnerorganization: non
---------------------------------------
Modulame: TOMJS
Developer: Thomas Tauchner;thomas.tauchner@qxcode.com
Filename: /_global/js/qxcProcessHandling.js
Diese Klasse stellt Funktionalit�t f�r die Behandlung von Childprozessen mit JS zur verf�gung.
---------------------------------------
Vers. 00.00; 01.08.2008; TT; Basisfunktionalit�t hergestellt.
Vers. 01.00; 03.10.2008; TT; erweiterte Funktionalit�t: mehdimensionale Chilprozesse.
---------------------------------------
sealed  
in 0.00
by Thomas Tauchner
at 08.01.2008/23:38 
---------------------------------------
*/

var oProc = new qxcProcessHandling ();
oProc.isChildOpen=false;

function qxcProcessHandling () 
{		
	//public proberties
	this.sChildsUrl=new Array();
	this.sChildsModul=new Array();
	this.isChildOpen;
	//<+1.0
	this.iCountChilds=-1;
	//+>
	
	//private proberties
	this.sReturnFunction=new Array();
	
	
	this.openChildProc = function (iSid,sUrl,sModul,sParentname,sReturnFunction,iWidth,iHeight)
	{
		
		//<+1.0
			this.iCountChilds++;
		//+>

		//<x1.0
		this.sChildsModul[this.iCountChilds]=sModul;
		this.sReturnFunction[this.iCountChilds]=sReturnFunction;
		//x>
		
		var iTop=screen.availHeight/2-iHeight/2;
		var iLeft=screen.availWidth/2-iWidth/2;

                iTop=iTop+document.documentElement.scrollTop;

		
		this.deactivateSite();
		
		
		var oBody = document.getElementsByTagName("body");
		oBody=oBody[0];
		
		var oDiv=document.createElement("div");
		//<x1.0
		oDiv.id="qxcProcessHandlingContentLayer"+this.iCountChilds;
		//x>
		oDiv.style.top=iTop+"px";
		oDiv.style.left=iLeft+"px";
		oDiv.style.height=iHeight+"px";
		oDiv.style.width=iWidth+"px";
		oDiv.style.backgroundColor="#ffffff";
		oDiv.style.position="absolute";
		oDiv.style.filter="alpha(opacity=90)";
		oDiv.style.mozOpacity="0.9";
		//<x1.0
		oDiv.style.zIndex=String(9000+(this.iCountChilds*2)+1);
		//x>
		oDiv.style.border="1px solid #000000";
		oDiv.style.overflow="scroll";
		
		
		oBody.appendChild(oDiv);
		
		var oDivInner=document.createElement("div");
		//<x1.0
		oDivInner.id="qxcProcessHandlingContentLayerInner"+this.iCountChilds;
		//x>
		oDivInner.style.left="0px";
		oDivInner.style.width=(iWidth-18-10-10)+"px";
		oDivInner.style.textAlign="left";

		oDivInner.style.padding="10px";
		oDiv.appendChild(oDivInner);
		
		var oImgWaiting=document.createElement("img");
		//oImgWaiting.src="_global/img/waiting.gif";
		oImgWaiting.id="qxcProcessHandlingImgWaiting"
		oDivInner.appendChild(oImgWaiting);
		
		
		//alle ? raus nehmen uns als normalen Parameter schreiben
		//sUrl = sUrl.replace(/\?/g, "&");
		
		//�bergebene GET Paremeter extrahieren
		
		var iPosPar=sUrl.indexOf("?");
		if(iPosPar>-1)
		{
			var sPar=sUrl.substr(iPosPar+1);
			sUrl=sUrl.substr(0,iPosPar);
		}

		//<x1.0
		this.sChildsUrl[this.iCountChilds] = sUrl;
		//x>
		
		qxcAjaxSet("indexAjax.php?child=1&sid="+iSid+"&t="+sParentname+"&f="+sUrl+".php&"+sPar,"oProc.getChildsContent");
		//window.open(sUrl,"qxcTOMProcessHandling"+sParentname,"height="+iHeight+",left="+iWidth+",location=no,menubar=no,resizable=yes,scrollbars=yes,status=yes,toolbar=no,top="+iTop+",width="+iLeft);
		
		this.isChildOpen=true;


		
	}
	
	this.returnToParent = function (returnValue)
	{
		//wenn BOM Bits von UTF8 am Anfang stehen, dann diese entfernen.
        //U+FEFF      
        //returnValue = returnValue.replace(/\uFEFF/g, "");
        

        //<x1.0

                

		this.sChildsUrl[this.iCountChilds]="";
		//x>
		this.callBack(returnValue);
		
	}
	
	//private

	this.getChildsContent= function (sContent)
	{
		var oImgWaiting = document.getElementById("qxcProcessHandlingImgWaiting");
		//<x1.0
		var oDivContentInner = document.getElementById("qxcProcessHandlingContentLayerInner"+this.iCountChilds)
		//x>
		oDivContentInner.removeChild(oImgWaiting);

		
		oDivContentInner.innerHTML=sContent;
		
		var oScript=document.createElement("script");
		
		//<x1.0
		oScript.src= "_mod"+this.sChildsModul[this.iCountChilds]+"mod/gui/js/"+this.getFileName(this.sChildsUrl[this.iCountChilds])+".js";
		
		//x>
		
		document.getElementsByTagName("head")[0].appendChild(oScript);
		this.isChildOpen=true;
	}

        this.getFileName = function (sPath)
        {
            
            var iStart=sPath.lastIndexOf("/");
            if(iStart==-1)
            {
                return sPath;
            }
            return sPath.substring(iStart);


        }

	this.callBack = function (returnValue)
	{
		


		
		this.activateSite();
		
		//<+1.0
			this.iCountChilds--;
            
		//+>
		//<x1.0
		if(this.iCountChilds<0)
		{
			this.isChildOpen=false;
		}
		//x>

                eval(this.sReturnFunction[this.iCountChilds+1]+"(returnValue)");
                
                /*
		if(returnValue==false || returnValue==null || type)
		{
			//<x1.0
            
			eval(this.sReturnFunction[this.iCountChilds+1]+"("+returnValue+")");
			//x>
		}
                else if(returnValue.substring(0,1)=="{")
                {

                    eval("returnValue = "+returnValue);

                    eval(this.sReturnFunction[this.iCountChilds+1]+"(returnValue)");

                }
		else
		{
			//<x1.0
            
			eval(this.sReturnFunction[this.iCountChilds+1]+"('"+returnValue+"')");
			//x>
		}
            */

	}
	
	this.deactivateSite = function ()
	{
		
		var oBody = document.getElementsByTagName("body");
		oBody=oBody[0];
		
		var oDiv=document.createElement("div");
		//<x1.0
		oDiv.id="qxcProcessHandlingControllLayer"+this.iCountChilds;
		//x>
		//var oStyle = document.createAttribute("style");
		//oStyle.nodeValue = "-moz-opacity:0.5; filter:alpha(opacity=50);left:0px;top:0px;width:100%;height:100%;background-color:#000000;";
		//oDiv.setAttributeNode(oStyle);
		
		/*
		oDiv.style['-moz-opacity'] = "0.5";
		oDiv.style['filter'] = "alpha(opacity=50)";
		oDiv.style['left'] = "0px";
		oDiv.style['top'] = "0px";
		oDiv.style['width'] = "100%";
		oDiv.style['height'] = "100%";
		*/
		
		oDiv.style.top="0px";
		oDiv.style.left="0px";
                
		oDiv.style.height=(document.getElementsByTagName("body")[0].offsetHeight+100)+"px";
		oDiv.style.width=(document.getElementsByTagName("body")[0].offsetWidth+100)+"px";
		oDiv.style.backgroundColor="#cccccc";
		oDiv.style.position="absolute";
		oDiv.style.filter="alpha(opacity=50)";
		oDiv.style.mozOpacity="0.5";
		//<x1.0
		oDiv.style.zIndex=String(9000+(this.iCountChilds*2));
		//x>
		
		
		oBody.appendChild(oDiv);
		
	}

	this.activateSite = function ()
	{

        //<x1.0
		var oDivCont = document.getElementById("qxcProcessHandlingContentLayer"+this.iCountChilds);
		var oDivContInner = document.getElementById("qxcProcessHandlingContentLayerInner"+this.iCountChilds);
		var oDivContr = document.getElementById("qxcProcessHandlingControllLayer"+this.iCountChilds);		
		//x>
		var oBody = document.getElementsByTagName("body");
		
                oBody=oBody[0];

		oDivCont.removeChild(oDivContInner);

                
		oBody.removeChild(oDivCont);
		oBody.removeChild(oDivContr);
	}
	
}	
