/*
ewPopup.js
copyright 2005-2007 Wolfgang Wintersteller - w.wintersteller@eWinus.com

Popup Class:
creating registrating and handling popup- windows in this application
*/


function ewPopupHandler(){

	var active=null;
	this.setFocus=function(){
	//alert("focus: "+active);
		if(this.active!=null){
//		alert(this.active.document.write(""));
//			if(this.active.focus()){
//		alert("2");
			try{
				this.active.focus();
				var exc=this.active.document.body;
			}
			catch(e){
			//alert("false");
				return false;
			}
			return true;
		}
//		else{
//		alert("3");
		this.active=null;
//		}
		//}
		return false;
	}
}

function ewPopup(){

//	var active=null;//=new window();
/*	=null;
	this.active=function(setter){
		if(setter!=null)
			win=setter;
		else return win;
		
	}
*/	this.center=function(){
		for(var item in window){
			if(item=="screen"){
				return true; 
				break;
			}
		}
		return false;
	};
	this.scan=function(){
		if(active!=null)
			active.focus();
	};
	this.close=function(){
		if(active!=null){
			active.close();
			active=null;
		}
	};
	this.create=function(file,height,width,resize,statusbar){
	
		var size=resize? "yes":"no";
		var status=statusbar? "yes":"no";
//		if(active==null || active.closed){		//no popup opened
			if(this.center()){
				width=(width=="max")? screen.width : width;
				height=(height=="max")? screen.height : height;
				// if the screen is smaller than the window, override the resize setting
				if(screen.width<width || screen.height<height)
					size="yes";
				var wndTop=(screen.height-height)/2;
				var wndLeft=(screen.width-width)/2;
			}
			else{	//older NN versions
				//use java installation
				if(navigator.appName=="Netscape" && navigator.javaEnabled()){
					/*/ center the window /*/
					var toolkit=java.awt.Toolkit.getDefaultToolkit();
					var screen_size=toolkit.getScreenSize();
					
					width=(width=="max")? screen_size.width : width;
					height=(height=="max")? screen_size.height : height;
					// if the screen is smaller than the window, override the resize setting
					if(screen_size.width<width || screen_size.height<height) 
						size="yes";
					var wndTop=(screen_size.height-height)/2;
					var wndLeft=(screen_size.width-width)/2;
				}
				else{
					/*/ use the default window position /*/
					// override the resize setting
					size="yes";
					var wndTop="";
					var wndLeft="";
				}				
			}

			// collect the attributes
			var attribs="width="+width+",height="+height+",resizable="+size+",scrollbars="+size+","+ 
			"status="+status+",toolbar=no,directories=no,menubar=no,location=no,top="+wndTop+",left="+wndLeft;
			return window.open(file,'',attribs);
			//active.focus();
//		}
//		else{
//			//popup active
//			active.focus();
//		}
	};
}

//CONSTRUCTOR IN MAIN FILE
//var popup=new ewPopup();


