values_changed = false;

// CSS images preload
var cssPreloadImages = new Array();
var cssPreloadImagesSrc = new Array(
	'/img/nav_aktuelles_a.gif',
	'/img/nav_neuerscheinungen_a.gif',
	'/img/nav_programm_a.gif',
	'/img/nav_presse_a.gif',
	'/img/nav_buchhaendler_a.gif',
	'/img/nav_verlag_a.gif',
	'/img/nav_kontakt_a.gif',
	'/img/nav_warenkorb_a.gif',
	'/img/nav_impressum_a.gif'
);
for (i = 0, ii = cssPreloadImagesSrc.length; i < ii; i ++) {
	cssPreloadImages[0] = new Image;
	cssPreloadImages[0].src = cssPreloadImagesSrc[i];
}

/*
 Initiates vertical growing of a single element by 40px
*/
function grow(id) {

	resize(id, 6);

} // function grow()


/*
 Initiates vertical shrinking of a single element by 40px
*/
function shrink(id) {

	resize(id, -6);

} // function grow()


/*
 Grows or shrinks an element vertically. If ID is invalid, it's
 assumed its the IDth textarea on the page, if the ID is missing
 at all, the first textarea is used.
*/
function resize(id, value) {

	if (id) {
		if (document.getElementById(id)) {
			el = document.getElementById(id);
		}
		else {
			el = document.getElementsByTagName('textarea')[id];
		}
	}
	else {
		el = document.getElementsByTagName('textarea')[0];
	}

	if (parseInt(el.style.height) + value < 3) {
		el.style.height = '3em';
	}
	else {
		el.style.height = parseInt(el.style.height) + value + 'em';
	}

} // function resize(id, value)

/**
 * If the "form value(s) changed" flag is set, asks the user for confirmation
 * and either redirects him / her to the path given as argument (if confirmed)
 * or returns false (ont confirmed)
 * @param {String} Path to send the client to
 * @return {Boolean}
 */
function cancel_form(path) {

	if (values_changed) {
		if (!confirm("Zur\374ck, ohne zu speichern?")) {
			return false;
		}
	}

	top.location.href = path;
	return true;

} // function cancel_form()

/**
 * Function for saving a form's "changed" state; should be called by
 * any form elements using onchange / onclick
 */
function track_changes() {

	if (document.getElementById('link_reset')) {
		document.getElementById('link_reset').style.visibility = 'visible';
	}

	values_changed = true;

} // function track_changes()

/**
 * Displays a centered popup window
 *
 * @param {String} path URL or path to display, or <a> element
 * @param {Number} width Popup window's width
 * @param {Number} height Popup window's height
 * @param {Boolean} fixed If set to true, the window will neither have a
                          statusbar or scrollbars nor will it be resizable,
                          otherwise both will be available
 * @author CB
 * @version 2006-09-09
 */
function popup(path, width, height, fixed) {

	if (!height || !width) {
		// Width and/or height missing, set window width to
		// default value and set fixed to false
		width = 350;
		height = 250;
		fixed = false;
	}

	if (screen.availWidth) {
		position = 'left=' + (Math.floor(screen.availWidth / 2 - width / 2)) +
		           ',top=' + (Math.floor(screen.availHeight / 2 - height / 2));
	}
	else if (window.screenX) {
		position = 'screenX=' + (window.screenX + 50) + ',screenY=' + (window.screenY + 50);
	}
	else {
		position = 'left=120,top=120';
	}

	if (fixed) {
		attrs = 'status=no,resizable=no,scrollbars=no';
	}
	else {
		attrs = 'status=yes,resizable=yes,scrollbars=yes';
	}

	pp = window.open(path, 'Popup', 'width=' + width + ',height=' + height +
	                 ',' + position + attrs);

	pp.focus();

} // function popup(path, width, height, fixed)

