function bbSetFormValues(action, values) {
	
	var radios = new Array();
	var formElement = $(action);
	if(formElement == null)
		return;
	var elements = Form.getElements(formElement);
	elements.each(function(item) {
		var name = item.readAttribute("name");
		if(!Object.isUndefined(values[name])) {
			var value = values[name];
			// Handle INPUT-Node
			if(item.nodeName == "INPUT") {
				var type = item.readAttribute("type");
				if(type == "checkbox") {
					if(name.indexOf("[]") > 0) {
						var tmpValues = value.split(",");
						for(var j=0; j < tmpValues.length; j++) {
							if(item.getValue() == tmpValues[j]) {
								item.checked = true;
								break;
							}
						}
					} else {
						item.checked = (value=="1" || value=="true");
					}
				} else if(type == "radio") {
					if(radios[name] == null) {
						radios[name] = new Array(item);
					} else {
						radios[name].push(item);
					}
				} else {
					item.value = value;
				}
			} else if(item.nodeName == "SELECT") {
				var options = item.getElementsByTagName("option");
				if(options != null) {
					var tmpValues = new Array(value);
					if(name.indexOf("[]") > 0) {
						tmpValues = value.split(",");
					}
					for(var j=0; j < options.length; j++) {
						for(var k=0; k < tmpValues.length; k++) {
							if(options[j].value == tmpValues[k]) {
								options[j].selected = true;
								break;
							}
						}
					}
				}
			} else if(item.nodeName == "TEXTAREA") {
				item.value = value;
			}
			
			
		}
	});
	for(var radioname in radios) {
		var radioset = radios[radioname];
		for(var i=0; i < radioset.length; i++) {
			radioset[i].checked = (radioset[i].defaultValue == formValues[radioset[i].name]);
		}
	}
}

function bbSetFormErrors(action, errors) {
	var formElement = $(action);
	if(formElement == null)
		return;
	var elements = Form.getElements(formElement);
	var firstErrorItem = null;
	elements.each(function(item) {
		var name = item.readAttribute("name");
		if(Object.isUndefined(errors[name])) {
			name = name.substring(0, name.length-2);
		}
		if(!Object.isUndefined(errors[name])) {
			//alert(name);
			if(firstErrorItem == null)
				firstErrorItem = item;
			item.addClassName("error");
			//Event.observe(item, 'click', function(evt) {resetErrorStyle(Event.element(evt))});
			new Insertion.After(item, "<div class=\"formFieldError\">"+errors[name]+"</div>");
		}
	});
	// Focus first Error Item
	if(firstErrorItem != null)
		firstErrorItem.activate();
}

function bbSetFormBusinessErrors(action, errors) {
	var formElement = $(action);
	if(formElement == null)
		return;
	for(var i=0;i<errors.length;i++) {
		new Insertion.Top(formElement, "<div class=\"businessError\">"+errors[i]+"</div>");
	}
}

/**
 *
 * Prompts a dialog to verify an action on the client-side
 *
 * @author Mischa Trecco (backbone@frontlinemedia.ch)
 * @version 1.1 - 27.05.2005
 * @copyright Copyright by the author. Nobody is allowed to use this Code in any way without the explicit allowance of the author.
 */
function confirmAction(message) {
	if(message == null) {
		message = "Sure you want delete this record?";
	}
	return confirm(message);
}
