/**
 * Opens a pop up window
 *
 * @param   string  url
 * @param   integer width
 * @param   integer height
 * @param   string  title
 * @return  boolean
*/
function popup(url) {

  var width = (arguments.length > 1) ? parseInt(arguments[1]) : 620;
  var height = (arguments.length > 2) ? parseInt(arguments[2]) : 380;
  var title = (arguments.length > 3) ? arguments[3] : '';
  var props = "width=" + width + ",height=" + height + ",resizable=yes,menubar=no,locationbar=no,status=no,scrollbars=yes,depend=yes,left=10,top=10";
  var popup;

  if (popup = window.open(url, title, props)) {

    popup.focus();
    return true;
  }

  return false;
} // end function popupwindow

/**
* Ask the user, if he/she wants to delete a record.
*
* @param   string  target_url
* @access  public
*/
function confirmDelete(target_url) {

  var text = (arguments.length > 1) ? parseInt(arguments[1]) : 'Möchten Sie diesen Datensatz wirklich löschen?';
  if(confirm(text))
    window.location.href = target_url;
} // end function confirmDelete


/**
* Handles challenge/response login (CHAP)
*
* Sets the response value of login form and deletes the password entry
* Note: fields must be identified as
*  - username (text input field for username)
*  - password (text input field for password)
*  - response (hidden field for calculated string)
*  - challenge (hidden field for unique seed)
* Note: the form has to be identified as 'login_form'
*
* @access   public
*/
function doChallengeResponse() {

  response = document.getElementById('username').value + ':' +
    hex_md5(document.getElementById('password').value) + ":" +
    document.getElementById('challenge').value;
  // set response
  document.getElementById('response').value = hex_md5(response);
  document.getElementById('password').value = "";
  document.getElementById('login_form').submit();
} // end function doChallengeResponse

/**
* Set bookmark
*
* @param    string    url
* @param    string    title
* @access   public
*/
function setBookmark(url, title) {

  if (document.all)
    window.external.AddFavorite(url, title);
  else if (window.sidebar)
    window.sidebar.addPanel(title, url, '');
} // end function setBookmark


/**
* Go to url which is defined by selector
*
* @param    object    selector
* @access   public
*/
function goTo(selector) {

  if((target = selector.elements['KatOptions'].options[selector.elements['KatOptions'].selectedIndex].value) != '')
    window.location.href = target;

  return false;
}  // end function goTo
