/*-------------------------------------------------------------------------------------------*
 *
 ***** iwscripts.js -- Common JavaScript functions for Intranet Weer
 *
 * Purpose:
 * --------
 *
 * Facilitate various feartures for Intranet Weer through JavaScript.
 *
 *
 * Interface:
 * ----------
 *
 * function printpage()
 * function setscroll()
 *
 *	printpage()	Print pribtable parts of the page, used by the button at the bottom
 *	setscroll()	Determine which content parts to scroll
 *
 * These two functions act upon the elements with the following ids:
 *
 * 	Content<n>P	Page content element which should be printed on request
 *	Content<n>N	Page content element which should be exempt from printing with the special
 *			print-this-page button.
 *
 *
 * Author:
 * -------
 *
 * Hans de Vries		*Copyright © KNMI*		July 25, 2006
 *
 *
 * Modifications:
 * --------------
 *
 * $Log: iwscripts.js,v $
 * Revision 1.1  2007/10/31 17:56:47  jwdv
 * Initial revision
 *
 *===========================================================================================*/

var celts = new Array ("Content1P", "Content1N", "Content2P", "Content2N");

/*-------------------------------------------------------------------------------------------*
 * printpage
 *
 * Taken from KNMI Intranet and adapted for use by WM Intranet
 * Print the elements which id's contain the letter 'P'
 *-------------------------------------------------------------------------------------------*/
function printpage()
{
newwindow = window.open("","Printje","toolbar=0,location=0,status=0,menubar=0,scrollbars=1,width=600,height=600")
newwindow.document.open();
newwindow.focus();
newwindow.document.writeln("<html><head>");
newwindow.document.writeln("<!--#include virtual='/weer/include/stdhead.html'-->");
newwindow.document.write("</head><body onLoad='this.print();'>");

for (i = 0; i < celts.length; i++)
  if (celts[i].indexOf("P") > 0)
    {
    body = document.getElementById(celts[i]);
    if (body != null)
      newwindow.document.write(body.innerHTML);
    }

newwindow.document.write("</body></html>");
newwindow.document.close();
}


/*-------------------------------------------------------------------------------------------*
 * setscroll
 *
 * Determine which parts of the content should scroll.
 * Use the clientHeight property of the different diffs to determine whether it is larger
 * than the innerHeight of the window minus 120 px for the header and footer.
 *
 * This works only with CSS-2 compliant browsers, like Mozilla
 *-------------------------------------------------------------------------------------------*/
function setscroll()
{
if (window.navigator.product == "Gecko")
  for (i = 0; i < celts.length; i++)
    {
    body = document.getElementById(celts[i]);
    if (body != null)
      body.style.position = (body.clientHeight > window.innerHeight - 120) ? "absolute" : "fixed";
    }
foot = document.getElementById("footer");
mbdy = document.getElementById("Content1P");
if (mbdy != null)
  mh = mbdy.clientHeight;
else
  mh = document.body.clientHeight;
if (window.navigator.product == "Gecko")
  {
  if ((mbdy != null) && (foot != null))
    {
    if (mbdy.style.position == "absolute")
      {
      foot.style.top = mh + 115;
      foot.style.position = "absolute";
      }
    else
      {
      foot.style.bottom = 0;
      foot.style.position = "fixed";
      }
    }
  }
else	/* for Windows */
  {
  wrap = document.getElementById("wrap2");
  if (wrap != null)
    wrap.style.height = document.body.clientHeight - 111;
  if (foot != null)
    foot.style.top = mh + 20;
  }
}


/*-------------------------------------------------------------------------------------------*
 * iniscroll
 *
 * Set the scroll heights, but first make sure that the page is fully loaded by waiting a
 * little while (2s).
 *-------------------------------------------------------------------------------------------*/
function iniscroll(kopout)
{
if (window.navigator.product != "Gecko")
  {
  foot = document.getElementById("footer");
  if (foot != null)
    foot.style.top = document.body.clientHeight - 140;
  }
window.setTimeout("setscroll()", 2000);
if (kopout)
  window.setTimeout("kopout()", 3000);
}


/*-------------------------------------------------------------------------------------------*
 * kopout, kopin
 *
 * Move the page header out of the view window to allow more space for graphics, and back
 * in if needed
 *-------------------------------------------------------------------------------------------*/

function kopout()
{
if (window.navigator.product == "Gecko")
  {
  kop = document.getElementById("kopblok");
  if (kop != null)
    kop.style.top = -90;
  kop = document.getElementById("zoekbox");
  if (kop != null)
    kop.style.top = -90;
  kop = document.getElementById("kruimel");
  if (kop != null)
    kop.style.top = 0;
  kop = document.getElementById("Content1P");
  if (kop != null)
    kop.style.top = 20;
  kop = document.getElementById("Content2N");
  if (kop != null)
    kop.style.top = 20;
  }
return true;
}

function kopin()
{
if (window.navigator.product == "Gecko")
  {
  kop = document.getElementById("kopblok");
  if (kop != null)
    kop.style.top = 0;
  kop = document.getElementById("zoekbox");
  if (kop != null)
    kop.style.top = 0;
  kop = document.getElementById("kruimel");
  if (kop != null)
    kop.style.top = 82;
  kop = document.getElementById("Content1P");
  if (kop != null)
    kop.style.top = 102;
  kop = document.getElementById("Content2N");
  if (kop != null)
    kop.style.top = 102;
  }
window.setTimeout("kopout()", 3000);
return true;
}
