var uagent   = navigator.userAgent ;
var uAppType = 0 ;
var uAppVer  = 0 ;

nStrOffs = uagent.indexOf( 'MSIE ' ) ;
if( nStrOffs >= 0 ) {    // Microsoft IE
  uAppType = 2 ;
  nStrOffs += 5 ;
  uAppVer = parseFloat( uagent.substring( nStrOffs, uagent.length ) ) ;
}
else {
  nStrOffs = uagent.indexOf( 'Mozilla/' ) ;
  if( nStrOffs >= 0 ) {  // Netscape
    uAppType = 1 ;
    nStrOffs += 8 ;
    uAppVer = parseFloat( uagent.substring( nStrOffs, uagent.length ) ) ;
  }
}

var winSubWindow = "" ;
var winURL = "" ;

function openSubWindow(event, url, width, height) {
  if((winURL != "") && (winURL != url)){
    if(!winSubWindow.closed) {
      winSubWindow.close() ;
    }
  }
  if((uAppType == 2) && (uAppVer >= 4)) {
    x = window.event.screenX + 50 ; //- width ;
    y = window.event.screenY - height - 50 ;
  }
  else if((uAppType == 1) && (uAppVer >= 4)) {
    x = event.screenX + 50 ; //- width ;
    y = event.screenY - height - 50 ;
  }
  else {
    x = screen.availWidth / 2 - width / 2 ;
    y = screen.availHeight / 2 - height / 2 ;
  }
  if(x < 0) {
    x = 0 ;
  }
  if(y < 0) {
    y = 0 ;
  }
  if(x > screen.availWidth - width) {
    x = screen.availWidth - width ;
  }
  if(y > screen.availHeight - height) {
    y = screen.availHeight - height ;
  }
  winSubWindow = w_open(url, "winSubWindow", x, y, width, height,
    false, false, false, false, false, false, false) ;
  winURL = url ;
  return false ;
}
