var morWin;
var objInterval;
var isWindowLock=false;
var Locale = "";

function isWindowOnLock(){
	return isWindowLock;
}

function eventOnFocus(){
	if(isWindowLock) onLockWindowClick();
}

function showFrameSizeableNotLocked(sName,sLocation,nWidth,nHeight){
	var posX = (screen.width/2)-(nWidth/2);
	var posY = (screen.height/2)-(nHeight/2);
	morWin = window.open(sLocation,sName,'screenX='+posX+',screenY='+posY+',top='+posY+',left='+posX+',width='+nWidth+',height='+nHeight+',menubar=no,status=yes,resizable=yes,scrollbars=yes');
	morWin.focus();
	return morWin;
}

function showIFrameSizeableNotLocked(sName,sLocation,nWidth,nHeight){
	var posX = (screen.width/2)-(nWidth/2);
	var posY = (screen.height/2)-(nHeight/2);
	morWin = window.open(sLocation,sName,'screenX='+posX+',screenY='+posY+',top='+posY+',left='+posX+',width='+nWidth+',height='+nHeight+',resizable=no,scrollbars=no,menubar=no,status=yes');
	morWin.focus();
	return morWin;
}

function showIFrameSizeableResize(sName,sLocation,nWidth,nHeight){
	var posX = (screen.width/2)-(nWidth/2);
	var posY = (screen.height/2)-(nHeight/2);
	morWin = window.open(sLocation,sName,'screenX='+posX+',screenY='+posY+',top='+posY+',left='+posX+',width='+nWidth+',height='+nHeight+',resizable=yes,scrollbars=no,menubar=no,status=yes');
	morWin.focus();
	lockWindow();	
	objInterval = window.setInterval('checkWin()',400);
	return morWin;
}


function showIFrameSizeable(sName,sLocation,nWidth,nHeight,sLocale){
   if (sLocale==null)
     sLocale="de_DE";
   Locale = sLocale;
	var posX = (screen.width/2)-(nWidth/2);
	var posY = (screen.height/2)-(nHeight/2);
	morWin = window.open(sLocation,sName,'screenX='+posX+',screenY='+posY+',top='+posY+',left='+posX+',width='+nWidth+',height='+nHeight+',resizable=no,scrollbars=no,menubar=no,status=yes');
	morWin.focus();
	lockWindow();
	objInterval = window.setInterval('checkWin()',400);
	return morWin;
}

function showIFrame(sName,sLocation){
	var posX = (screen.width/2)-(610/2);
	var posY = (screen.height/2)-(630/2);
	morWin = window.open(sLocation,sName,'screenX='+posX+',screenY='+posY+',top='+posY+',left='+posX+',width=610,height=630,resizable=no,scrollbars=no,menubar=no,status=yes');
	morWin.focus();
	lockWindow();	
	objInterval = window.setInterval('checkWin()',400);
	return morWin;
}

function showIFrameScrollbar(sName,sLocation){
	var posX = (screen.width/2)-(860/2);
	var posY = (screen.height/2)-(670/2);
	morWin = window.open(sLocation,sName,'screenX='+posX+',screenY='+posY+',top='+posY+',left='+posX+',width=860,height=670,resizable=yes,scrollbars=yes,menubar=no,status=yes');
	morWin.focus();
	lockWindow();	
	objInterval = window.setInterval('checkWin()',400);
	return morWin;
}

function showIFrameConfirmDialog(sName,sLocation){	
	var posX = (screen.width/2)-(350/2);
	var posY = (screen.height/2)-(160/2);
	morWin = window.open(sLocation,sName,'screenX='+posX+',screenY='+posY+',top='+posY+',left='+posX+',width=350,height=130,resizable=no,scrollbars=no,menubar=no,status=yes');
	morWin.focus();
	lockWindow();	
	objInterval = window.setInterval('checkWin()',400);
}









function lockAndCheckWindow(win){
	morWin = win;
	lockWindow();	
	objInterval = window.setInterval('checkWin()',400);
}


function checkWin(){
   try {
   	if(morWin.closed){
   	   closeIFrame();
   		window.clearInterval(objInterval);
   		window.focus();
   		if(window.reloadWindow)
   			reloadWindow();
   		isWindowLock=false;
   	}
   } catch (E) {}
}



/*function checkWinDialog(){
	if(morWin.closed){
		closeIFrame();
		window.clearInterval(objInterval);
		alert("OK");
		
		window.focus();
		isWindowLock=false;
	}
}
*/

function morphingIFrameToMessageBox(){
	setIFrameSize( 500, 300);
}

//////////////////////////////////////////////////
// Style Setzen
//////////////////////////////////////////////////
function setIFrameSize( nWidth, nHeight){
	setStyleSize("IFrameHeader", nWidth+12, 30      );
	setStyleSize("IFrameFooter", nWidth+12, 6       );
	setStyleSize("IFrameLeft"  , 6        , nHeight );
	setStyleSize("IFrameRight" , 6        , nHeight );
	setStyleSize("IFrameContent" , nWidth , nHeight );
}

function setStyleSize(sName, nWidth, nHeight){
	var objElement = getElem('id',sName,0);
	objElement.style.width  = nWidth +"px";
	objElement.style.height = nHeight+"px";
}

function lockWindow(){
	var elemObj = showDiv("iFrameAC");
	document.onmouseover= returnFalse;
	document.onmouseout = returnFalse;
	//document.onclick    = onLockWindowClick;
	elemObj.innerHTML = '<table cellpadding="0" cellspacing="0" border="0" width="100%" height="100%" onClick="onLockWindowClick()" onContextmenu="onLockWindowClick();"><tr><td>&nbsp;</td></tr></table>';
	isWindowLock=true;
}

function unlockWindow(){
	isWindowLock=false;
	removeObject("iFrameAC");
}


///////////////////////////////////////////////////////////////////////////////////////////////
// Eventhelper 
function returnFalse(){ return false; }
function returnTrue (){ return true; }

function onLockWindowClick(){
   try {
   	if(!morWin.closed) { 
   		morWin.focus();
   		if(morWin.isWindowLock) morWin.onLockWindowClick();
   	}
   	return false;
   } catch (E) {}
	
}

///////////////////////////////////////////////////////////////////////////////////////////////
// IFrame schliessen
function closeIFrame(){
	//document.onclick     = returnTrue;
	document.onmouseover = returnTrue;
	document.onmouseout  = returnTrue;	
	removeObject("iFrameAC");
}

function showDiv(sName){
	var objElement = geIFrameWindowElement(sName);	
	return objElement;
}

function removeObject(sName){	
	var objElement = getElem("id",sName,null);
	if(objElement==null) return;
	objElement.style.top="-10000px";
	document.getElementsByTagName("body")[0].removeChild(objElement);
	
}

function geIFrameWindowElement(sName){
   try {
   	var objElement = getElem("id",sName,null);
   	if(objElement==null) {
   		createDiv(sName);		
   		objElement = getElem("id",sName,null);
   	}
   	return objElement;
   } catch(E){}
}

function createDiv(sName){
	var newDIV = document.createElement("div");
	newDIV.id   = sName;
	newDIV.style.position="absolute";
	newDIV.style.zIndex="50000";
	newDIV.style.border="0px #000000 solid";
	newDIV.style.width ="100%";
	newDIV.style.height="100%";
	newDIV.style.top ="0px";
	newDIV.style.left="0px";
	newDIV.align="center";
	newDIV.valign="middle";
	document.getElementsByTagName("body")[0].appendChild(newDIV);
}

