/**
 * The popup window is 60% x 60% of the screen resolution.
 * Minimum width is 600. The popup window is centered on the screen 
 */
function openWin(url)
{
  clientWidth = screen.width * 0.6;
  clientHeight = screen.height * 0.6;
  if (clientWidth < 600) clientWidth = 600;
  posX = (screen.width - clientWidth) * 0.5;
  posY = (screen.height - clientHeight) * 0.5;

  /**
   * The width and height of the popup window applies to the client area!
   * Because a popup window also has a title bar and a frame the total
   * width and total height is bigger than the client area! Therefor we
   * assume the total hight being about 40 pixel more than the client height.
   * When we center the popup on the screen we get a better result. 
   */
  posY -= 20;
  if (posX < 6) posX = 6;
  if (posY < 6) posY = 6;

  /* debug
  document.write("clientWidth=" + clientWidth + " clientHeight=" + clientHeight + "<br>");
  document.write("screen.width=" + screen.width + " posX=" + posX + "<br>");
  document.write("screen.height=" + screen.height + " posY=" + posY + "<br>");
  */

  winProps='width='+clientWidth+', height='+clientHeight+', left='+posX+', screenX='+posX+', top='+posY+', screenY='+posY+', toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=1, resizable=1';
  win1 = window.open(url, 'info_popup', winProps);
  win1.focus();
}

/**
 * This popup shall be called from another popup. While the above 
 * openWin() popup  is centered on the screen, this openChildWin()
 * popup is located in the top left corner of the screen. Example:
 * While the openWin() popup may contain a form, the openChildWin()
 * popup may be used to display a help text.
 */
function openChildWin(url)
{ 
  clientWidth = 600;
  clientHeight = 400;
  posX = 20;
  posY = 20;

  winProps = 'width='+clientWidth+', height='+clientHeight+', left='+posX+', screenX='+posX+', top='+posY+', screenY='+posY+', location=0, status=0, toolbar=0, menubar=0, scrollbars=1, resizable=1';
  win = window.open(url, 'info_child_popup', winProps);
  win.focus();
}

function confirmSubmit(text)
{
  var result = false;
  var agree = confirm(text);

  var objTimeout = null;
  var objWaitForFlash = null;
  var timeout = '';
  var waitforflash = '';
  var arr = null;
  var count = 0;
  var i = 0;
  var newurl = '';

  if (agree == true) {
    result = true;
    // inject e.g. '/timeout/12/' into the url string for website screenshot
    objTimeout = document.getElementById('timeoutinputfield'); // input field
    objWaitForFlash = document.getElementById('waitforflashcheckbox'); // checkbox
    if ((objTimeout != null) && (objWaitForFlash != null)) {
      if ((timeout = objTimeout.value) != '') { // get timeout value in seconds as a string
        waitforflash = (objWaitForFlash.checked == true) ? '1' : '0';
        arr = document.getElementsByName('BtnLinkConfirmJsTimeout'); // create array
        // if no elements found the array is empty and arr.length is 0
        if ((count = arr.length) > 0) { // loop through array
          for (i=0; i<count; i++) { // inject params e.g. '/timeout/12/waitforflash/0/' in front of '?url='
            newurl = arr[i].action.replace('?url=', '/timeout/'+timeout+'/waitforflash/'+waitforflash+'?url=');
            // alert(newurl); // debug
            arr[i].action = newurl;
          }
        }
      }
    }
  }
  return(result);
}

/**
 * This function needs to be called every 1.0 second by a timer.
 */
function jsClock()
{
  var oDate = new Date();
  var yyyy = oDate.getFullYear();
  var mo = oDate.getMonth() + 1;
  var dd = oDate.getDate();
  var hh = oDate.getHours();
  var mm = oDate.getMinutes();
  var ss = oDate.getSeconds();
  var clockDiv = null;

  if (mo < 10) mo = '0' + mo;
  if (dd < 10) dd = '0' + dd;
  if (hh < 10) hh = '0' + hh;
  if (mm < 10) mm = '0' + mm;
  if (ss < 10) ss = '0' + ss;

  clockDiv = document.getElementById('jsClock');
  clockDiv.innerHTML = yyyy+'.'+mo+'.'+dd+' - '+hh+':'+mm+':'+ss;
  // +' <small>(in Berlin)</small>'
}
