/*

  popups.js
  Copyright (c) 2007 - Formauri, S.L. - Todos los derechos reservados/All rights reserved
  <http://www.formauri.es/>

*/
/* Functions that haven't been created by Formauri will be clearly detailed */

/* Opens a new window with the desired settings, specifying URL, width, height,
   if it is centered and position in case we don't want it centered */

/* How to use it (examples):
   OpenPopUpWindow("MyDir/MyDoc.html", "scrollbars=1", 400, 500, true);
   OpenPopUpWindow("http://www.my-domain.com/MyDir/MyDoc.html", "", 400, 500, false, 10, 20);
*/

function OpenPopUpWindow(txtURL, windowOptions, Width, Height, centered, posX, posY)
{
  if (centered)
  {
    posX = (screen.availWidth - Width)/2;
    posY = (screen.availHeight - Height)/2;
  }

  if (windowOptions == '')
  {
    windowOptions = 'width=' + Width;
  }
  else
  {
    windowOptions += ',width=' + Width;
  }

  windowOptions += ',height=' + Height + ',left=' + posX + ',top=' + posY;

  window.open(txtURL, "", windowOptions);
}

/* Opens a centered windows with scroll bars */

function OpenPopUpWindowCSB(txtURL, Width, Height)
{
  OpenPopUpWindow(txtURL, "scrollbars=1", Width, Height, true);
}

function OpenPopUpWindowCSBT(txtURL, Width, Height)
{
  OpenPopUpWindow(txtURL, "toolbar=1,scrollbars=1", Width, Height, true);
}


/* Opens a centered windows with scroll bars and given HTML and title */

function OpenPopUpWindowCSB_WithHTML(Width, Height, txt, Title)
{
  posX = (screen.availWidth - Width)/2;
  posY = (screen.availHeight - Height)/2;

  windowOptions = 'width=' + Width
    + ',height=' + Height
    + ',left=' + posX
    + ',top=' + posY
    + ',scrollbars=1'
    ;

  txt =
      "<head>\n"
    + "<title>" + Title + "</title>\n"
    + "<style type=\"text/css\">\n"
    + "<!--\n\n"
    + "  body\n"
    + "  {\n"
    + "    font-family: Verdana, sans-serif;\n"
    + "    font-size: 11pt;\n"
    + "    margin: 10px\n"
    + "  }\n"
    + "\n//-->\n"
    + "</style>"
    + "</head>\n"
    + "<body>\n" + txt + "\n</body>\n"
    ;

  var newWin = window.open("", "", windowOptions);

  newWin.document.open();
  newWin.document.write(txt);
  newWin.document.close();
}



