function openWindow(winUrl, name, winWidth, winHeight, winLeft, winTop ) {
	openWindowBase(',scrollbars=yes,resizable=yes,toolbar=yes,location=yes,menubar=yes,status=yes', winUrl, name, winWidth, winHeight, winLeft, winTop );	
}; 

function openInsert(winUrl, name, winWidth, winHeight, winLeft, winTop ) {
	openWindowBase('', winUrl, name, winWidth, winHeight, winLeft, winTop );
}; 

function openInsertFin(winUrl, name, winWidth, winHeight, winLeft, winTop ) {
	openWindowBase('', winUrl, name, winWidth, winHeight, winLeft, winTop );
}; 

function openInsertScroll(winUrl, name, winWidth, winHeight, winLeft, winTop ) {
	openWindowBase(',scrollbars=yes', winUrl, name, winWidth, winHeight, winLeft, winTop );
}; 

function openInsertMenuScroll(winUrl, name, winWidth, winHeight, winLeft, winTop,deltaX,deltaY ) {
	openWindowBase(',scrollbars=yes,resizable=yes,menubar=yes', winUrl, name, winWidth, winHeight, winLeft, winTop,deltaX,deltaY  );	
}; 
function openInsertMenu(winUrl, name, winWidth, winHeight, winLeft, winTop,deltaX,deltaY ) {
	openWindowBase(',resizable=yes,menubar=yes', winUrl, name, winWidth, winHeight, winLeft, winTop,deltaX,deltaY  );	
}; 


var openWin = new Array();
var numOpenWin =0;

function closeOldWin( nameFin ){ 
	if (numOpenWin>0) {
  		for (i=0; i<numOpenWin; i++) {
			if (openWin[i].closed) {
				for (j=i; j<numOpenWin;j++) {
					openWin[j]=openWin[j+1];
				} 
				numOpenWin-=1;
				i--; //attenzione occorre :-)
			};

		};  
		for (i=0; i<numOpenWin; i++) {
    		 	if(openWin[i].name == nameFin) {
				openWin[i].close();
				for (j=i; j<numOpenWin-1;j++) {
					openWin[j]=openWin[j+1];
				} 
				numOpenWin-=1;					 
          		}
    		}
    }
}

var versione = parseInt(navigator.appVersion);
function openWindowBase(feature, winUrl, name, winWidth, winHeight, winLeft, winTop ) {
	closeOldWin(name);  // Per chiudere finestra quando già aperta   
	if (openWindowBase.arguments.length <= 4) { // any additional features? 
		winLeft='center';
		winTop='center';
	};
	posy=0;
	posx=0;
     if(winLeft==null){
        winLeft="center";
        }
     if(winTop==null){
        winTop="center";
        }


	switch(winLeft) {
		case 'left': 	posx=0;
				break;
		case 'right': 	posx=screen.width - winWidth-10;
		         	    break; 
		case 'center':
        case 'middle':  posx=(screen.width - winWidth)/2;
    				    break;	
		default	 :      posx=winLeft  
		
	};
	
	switch(winTop) {
		case 'top': 	posy=0;
				break;
		case 'bottom': 	posy=(screen.height - winHeight)-56;//pixel occupati della barra di stato di Windows
                       	        break; 
	    case 'center':
		case 'middle':  posy=(screen.height - winHeight)/2;
                           
				break;
		default:	posy=winTop;			
	};
	
	leftSt="left";
	topSt="top";
	if (navigator.appName=="Netscape") {
		leftSt="screenX";
		topSt="screenY";
	}; 
	if (feature ==',scrollbars=yes,resizable=yes,toolbar=yes,location=yes,menubar=yes,status=yes') {
         if(winTop=='center'|| winTop=='middle'){
   
        	posy-=110;
             }	
                if(winTop=='bottom'){
                  if (navigator.appName.indexOf("Netscape") != -1){
                      if(versione >= 4 && versione < 5){
                            posy-=105;  //105 pixel per la barra di stato
                                                       }
                           if(versione >=5){
                          posy-=108 ; //108 pixel per la barra di stato
                                           }          
                                                                  }
                   else if (navigator.appName.indexOf("Microsoft") != -1){
        	        posy-=110+40;//110+40 pixel per la barra di stato
                                                                        }
                                     }	        
 	};
	openWin[numOpenWin++]=window.open(winUrl,name,'width='+winWidth+',height='+winHeight+','+topSt+'='+posy+','+leftSt+'='+posx+feature);
}; 
