<!--
//
// TEST A WINDOW HANDLE
//
function jsInvalidHandle( pWinHandle ) {
  var pRet = false;
  if( goBrowser.bIE ) {
    if( (typeof(pWinHandle)!="object") || (pWinHandle==0) )
      pRet = true;
  } else {
    if( (typeof(pWinHandle)!="object") )
      pRet = true;
  }
  return pRet;
}

//
// USER INTERFACE
//
function jsOpenWinShips( ) {
  goWinShips = openFlashWin('../../swf/mappa','Navi');
  if( jsInvalidHandle(goWinShips) == true )
    goWinShips = openFlashWin('mappa','Navi');
}

function jsGoToWinShips( pPointNum ) {
  jsGoToPoint('Navi',pPointNum);
}

function jsOpenWinPlani( ) {
  goWinPlani = openFlashWin('../../swf/plani','Planimetria');
  if( jsInvalidHandle(goWinPlani) == true )
    goWinPlani = openFlashWin('plani','Planimetria');
}

function jsGoToWinPlani( pPointNum ) {
  jsGoToPoint('Planimetria',pPointNum);
}

//
// OPEN FLASH WINDOW
//
function openFlashWin( pBaseUrl, pTitle ) {
  var oWin, pCommon, pParams;
  var dMaxW, dMaxH, dW, dH, dX, dY;

  // obtain the screen size
  if( goBrowser.bIE ) {
    dMaxW = screen.availWidth;
    dMaxH = screen.availHeight;
  } else {
    if( typeof(screen) == "undefined" ) {
      dMaxW = 640;// MAX SCREEN SIZE NOT SUPPORTED!
      dMaxH = 480;
    } else {
      dMaxW = screen.availWidth;
      dMaxH = screen.availHeight;
    }
  }
  dMaxW = dMaxW - 10;
  dMaxH = dMaxH - 30;

  // normalize
  dW = dMaxW;
  dH = dMaxH;
  if( dW <= 640 && dH <= 400 ) {
    dW = 390;
    dH = 300;
  } else if( dW <= 640 && dH <= 480 ) {
    dW = 494;
    dH = 380;
  } else if( dW <= 800 && dH <= 600 ) {
    dW = 650;
    dH = 500;
  } else if( dW <= 1024 && dH <= 768 ) {
    dW = 868.4;
    dH = 668;
  } else if( dW <= 1152 && dH <= 864 ) {
    dW = 993.2;
    dH = 764;
  } else if( dW <= 1280 && dH <= 1024 ) {
    dW = 1180;
    dH = 907.69;
  } else {
    dW = 1201.2;
    dH = 924;
  }

  // center the window
  dX = (dMaxW - dW) / 2;
  dY = (dMaxH - dH) / 2;

  // set the window common parameters
  pCommon = 'directories=0,location=0,menubar=0,resizable=0,scrollbars=0,status=0,toolbar=0';

  // customize on the browser
  if( goBrowser.bIE ) {
    var pParamsIE = ',titlebar=0,fullscreen=0,left='+dX+',top='+dY+',width='+dW+',height='+dH;
    pParams = pCommon + pParamsIE;
  }
  else if( goBrowser.bNS ) {
    var pParamsNS = ',hotkeys=0,screenX='+dX+',screenY='+dY+',outerWidth='+dW+',outerHeight='+dH;
    pParams = pCommon + pParamsNS;
  }
  else {
    pParams = pCommon + ',left='+dX+',top='+dY+',width='+dW+',height='+dH;
  }

  // open the window istance
  pUrl = pBaseUrl + ".html";
  oWin = window.open(pUrl,pTitle,pParams);

  // bring to front
  // ATTENZIONE: oWin.focus() NON FUNZIONA! Vedere l'evento onBlur della finestra caricata...

  // return the instance (to keep in a global variable)
  return oWin;
}

//
// GO TO A SPECIFIED FLASH EMBEDDED POINT
//
// Note1: instead of jumping when the window is opened... when handle seems
// to be invalid we can reload the window before the jump!
//
function jsGoToPoint( pWinName, pPointNum ) {
  if( pWinName == "Navi" ) {
    //if( jsInvalidHandle(goWinShips) == true )
      jsOpenWinShips();
    //goWinShips.focus();
    //if( (goBrowser.bIE == true) && (navigator.appVersion.charAt(0)>="4") ) {
    //  goWinShips.jsGoToFlashPoint(pPointNum);
    //} else if( (goBrowser.bNS == true) && (navigator.appVersion.charAt(0)>="4") ) {
    //  goWinShips.jsGoToFlashPoint(pPointNum);
    //} else {
      gpPointNum = pPointNum;
    //}
  } else if( pWinName == "Planimetria" ) {
    //if( jsInvalidHandle(goWinPlani) == true )
      jsOpenWinPlani();
    //goWinPlani.focus();
    //if( (goBrowser.bIE == true) && (navigator.appVersion.charAt(0)>="4") ) {
    //  goWinPlani.jsGoToFlashPoint(pPointNum);
    //} else if( (goBrowser.bNS == true) && (navigator.appVersion.charAt(0)>="4") ) {
    //  goWinPlani.jsGoToFlashPoint(pPointNum);
    //} else {
      gpPointNum = pPointNum;
    //}
  }

  //return 0;
}

goBrowser.jsCheckBrowser();
//-->
