/*
#######################################

NOTE: This file is protected
Copyright by Entrics 2008-2009

www.entrics.de

#######################################
*/

function confirmDelete(field, id) {
	var check = confirm("Jetzt löschen?");
	
	if (check) {
		field.value = id;
		form = field.form;
		
		if (form.subaction) {
			form.subaction.value = "delete";
		}
		
		form.submit();
	}
}

/**
 * Triggered by onKeyPress event this func checks if content of textarea has reached
 * the given limit (line breaks are counted, too). If so it shortens the content to the limit
 * @param object evt event
 * @param object formField textarea
 * @param int maxSize maximum size of textarea
 */
function limitAreaSize(evt, formField, maxSize) {
	var content = formField.value;
	var size = content.length;
	var lostChars = 0;
	
	// Netscape 6.1 on Win counts line breaks as single chars but actually they consist of two chars when
	// the string is sent to the server
	// This browser gives back the Mozilla version number
	// we have to test Netscape 7
	if (navigator.appName == "Netscape" && navigator.appVersion.substring(0, 3) == "5.0" && navigator.platform == "Win32") {
		for (var i = 0; i < size; i++) {
			if (content.charAt(i) == "\n") {
				lostChars++;
			}
		}
	}
	
	if (size + lostChars >= maxSize) {
		// evt.which is undefined on IE. This browser doesn't trigger onKeyPress on the handled keys anyway
		switch (evt.which) { // prevent warning in these cases because they have no effect on length or even reduce it
			case 0: // cursor, delete. Are these the same on Mac?
			case 8: // backspace
				return;
		}
		
		alert("Die maximale Länge fuer dieses Feld ist %s Zeichen. Sie haben diese Grenze erreicht!".replace("%s", maxSize));
		formField.value = content.substr(0, maxSize - (lostChars + 1)); // -1 because the key press that triggered the event is not yet in the content
	}
}

var wins = new Array();

/**
 * Opens a window or sets focus if it's already open
 * @param string url - URL for win
 * @param string name - Window name
 * @param string look - Attributes for win
 */
function openWin(url, name, look) {
	if (wins[name] && !wins[name].closed) {
		wins[name].location = url;
		wins[name].focus();
	}
	else {
		wins[name] = window.open(url, name, look);
	}
}
