//
// Popup
//
function PopupNoScroll(url, name, width, height) {
  newWindow = window.open(url, name, 'width=' + width + ',height=' + height + ',status=no toolbar=no, location=no, directories=no, menubar=no, scrollbars=yes, resizable=no');
}

//
// Restiruisce il browser
//
function browserWeb() {
  if (document.layers) //Netscape 4.x 
    return "NS4"
  else if (document.all)  //explorer
    return "IE";
  else if (document.getElementById) // Netscape 6.x
    return "NS6";

  return NULL;
}


//
// controlla dimensioni video PC e ridimensiona per apertura popup
//
function ShowReg(url, resX, resY, delta_x, delta_y, width_adv) {
  var altezza = window.screen.height; // altezza schermo
  var larghezza = window.screen.width; //larghezza schermo

  var widthPopup = resX + delta_x + width_adv;
  var heightPopup = resY +  delta_y;
  var setRatio = 1;

  var minWidth = 500; // larghezzza minima per popup

  var tipoBrowser = browserWeb();

  //ingombri browser
  var hPadd = 90;
  var wPadd = 50;
  altezza -= hPadd;
  larghezza -= wPadd;

  // controllo se ridimensionare popup
  if (altezza < heightPopup || larghezza < widthPopup) {
    //maxWidth = larghezza*0.85;
    maxWidth = larghezza*0.90;
    //maxHeight = altezza*0.80;
    maxHeight = altezza*0.85;
    widthRatio = (maxWidth - delta_x - width_adv) / resX;
    heightRatio = (maxHeight - delta_y) / resY;
    setRatio = Math.min(widthRatio, heightRatio);
  }
  widthPopup = Math.floor(setRatio * resX) + delta_x + width_adv;
  heightPopup = Math.floor(setRatio * resY) + delta_y;
  objX = Math.floor(resX * setRatio) +  delta_x;
  objY = Math.floor(resY  * setRatio) +  delta_y;

  if (tipoBrowser == "IE") {
    widthPopup += 35;
    heightPopup += 15;
  } else {
    widthPopup += 25;
    heightPopup += 10;
  }

  widthPopup = (widthPopup < minWidth) ? minWidth : widthPopup;

  url += "&widthPopup="+widthPopup+"&heightPopup="+heightPopup+"&objX="+objX+"&objY="+objY;
  PopupNoScroll(url, 'registrazione', widthPopup, heightPopup);
}

