/**
 * Opens a pop up window
 *
 * @param string url
 * @param int width
 * @param int 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;
}

/**
 * Asks the user whether she wants to delete a record.
 *
 * @param string target_url
 */
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;
	}
}

/**
 * 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'
 */
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();
}

/**
 * Opens the bookmark-prompt.
 *
 * @param string url
 * @param string title
 */
function setBookmark(url, title)
{
	if (document.all) {
		window.external.AddFavorite(url, title);
	} else if (window.sidebar) {
		window.sidebar.addPanel(title, url, '');
	}
}

/**
 * Go to URL which is defined by selector.
 *
 * @param object selector
 */
function goTo(selector)
{
	var target = selector.elements['KatOptions'].options[selector.elements['KatOptions'].selectedIndex].value;
	if (target != '') {
		window.location.href = target;
	}
	return false;
}
