var newwindow = '';
function popWindow(theURL,winname,width,height, winfeatures) {
    x = (640 - width)/2, y = (480 - height)/2;

    if (screen) {
        y = (screen.availHeight - height)/2;
        x = (screen.availWidth - width)/2;
    }
		if(winfeatures.indexOf("maxscreen=yes")==-1){
			winfeatures += ',width='+width+',height='+height;
		}else{
				if(screen.availWidth > width){
					width = screen.availWidth - 10;
					x = 0;
				}
				if(screen.availHeight > height){
					height = screen.availHeight - 10;
					y = 0;
				}
			winfeatures += ',width='+width+',height='+height;
		}
		
   	if(!newwindow.closed && newwindow.location) {
			 newwindow.location.href = theURL;
		}
		else {
			newwindow=window.open(theURL,winname,'screenX='+x+',screenY='+y+',top='+y+',left='+x+',' + winfeatures + ',status=no,resizable=yes');
			if (!newwindow.opener) newwindow.opener = self;
		}
		if (window.focus) {newwindow.focus()}
}
