

/*called from isEnter()*/
function checkForParent(object,parent) {
	while (object != null) {
		if (object == parent) {
			return true;
		}
		object = object.parentNode;
	}
	return false;
}

function isEnter(event,parentId) {
	event = (event) ? event : window.event;
	var charCode = (event.keyCode) ? event.keyCode : event.which;
	if (charCode == 13) {
		var myForm = (parentId) ? document.getElementById(parentId) : document.getElementById('myForm');
		var target = (event.srcElement) ? event.srcElement : event.target;	
		if (checkForParent(target,myForm)) {				
			return true;
		}
	}
	return false;
}


function standardSubmit(myForm, option) {

	/** next two loops change the behavier from sending only the value 'on' if a checkbox is ticked 
		to sending '0' -> not ticked or '1' -> ticked to the persistor.
		this is more convinient to work with in stored procedures since you can use the bit type 
		without converting null to 0 and 'on's to 1 */

	var element;
	var checkboxes = new Array();
	var name = '';
	for (var i = 0;  i < myForm.elements.length; i++ ) {
		var element = myForm.elements[i];

		if (element.nodeName == 'INPUT' && element.type == 'checkbox') {
			name = (element.name != null && element.name != '') ? element.name : element.id;
			checkboxes[name] = element;
		}
	}

	// it is necessary to not append childs to the form within the iteration above (possible endless loop)
	//for (name in checkboxes) {
	//	var hiddenField = document.createElement('input');
	//	hiddenField.setAttribute('name',name);
	//	hiddenField.setAttribute('type','hidden');
	//	hiddenField.setAttribute('value',checkboxes[name].checked ? '1' : '0');
		//checkboxes[name].name = "_" + name;
	//	element.parentNode.appendChild(hiddenField);
	//}

	/** create an inputfield for the option like: <input type="hidden" name="OPTION"/> */
	optionField = document.createElement('input');
	optionField.setAttribute('name', 'OPTION');
	optionField.setAttribute('type', 'hidden');
	optionField.setAttribute('value', option);
	myForm.appendChild(optionField);

	/** final submit */
	myForm.submit();
}
