
	// Split theValue and set the second split string as unit
function tx_order_pi1_setUnit(theSource, theField) {
	if (document.getElementById(theSource) && document.getElementById(theField)) {
		theValue = document.getElementById(theSource).options[document.getElementById(theSource).selectedIndex].value;
		if (theValue && theValue.indexOf('|') != -1) {
			theValue = theValue.split('|', 2);
			theValue = theValue[1];
		} else {
			theValue = '';
		}
		document.getElementById(theField).value = theValue;
	}
}

	// Delete a row and submit the formular
function tx_order_pi1_deleteRow(theRow) {
	var theNames = ['amount', 'material', 'material_other', 'products', 'products_other', 'unit', 'other'];
	var theField = 'tx_order_pi1[orders][' + theRow+ ']';
	var rowDeleted = false;
	for (var i = 0; i < theNames.length; i++) {
		if (document.getElementById(theField + '[' + theNames[i] + ']')) {
			if (document.getElementById(theField + '[' + theNames[i] + ']').type == 'text') {
				if (document.getElementById(theField + '[' + theNames[i] + ']').value) {
					rowDeleted = true;
				}
				document.getElementById(theField + '[' + theNames[i] + ']').value = '';
			} else if (document.getElementById(theField + '[' + theNames[i] + ']').type.indexOf('select') != -1) {
				if (document.getElementById(theField + '[' + theNames[i] + ']').selectedIndex > 0) {
					rowDeleted = true;
				}
				document.getElementById(theField + '[' + theNames[i] + ']').selectedIndex = 0;
			}
		}
	}
	if (rowDeleted) {
		document.getElementById('tx_order_pi1').submit();
	}
}

	// Set the value of theField from other chars than [0-9,.]
function tx_order_pi1_doubleField(theField) {
	if (document.getElementById(theField) && document.getElementById(theField).value != '0') {
		var theVal = '' + document.getElementById(theField).value;
		var newVal = '';
		for (var i = 0; i < theVal.length; i++)	{
			if (theVal.substr(i, 1).match(/^[0-9]$/)) {
				newVal += '' + theVal.substr(i, 1);
			} else if (i + 1 < theVal.length && theVal.substr(i, 1).match(/^[,\.]$/)) {
				newVal += '' + theVal.substr(i, 1);
			}
		}
		document.getElementById(theField).value = newVal;
	}
}

	// Set the value of theField from other chars than [0-9]
function tx_order_pi1_intField(theField) {
	if (document.getElementById(theField) && document.getElementById(theField).value != '0') {
		var theVal = '' + document.getElementById(theField).value;
		var newVal = '';
		for (var i = 0; i < theVal.length; i++)	{
			if (theVal.substr(i, 1).match(/^[0-9]$/)) {
				newVal += '' + theVal.substr(i, 1);
			}
		}
		document.getElementById(theField).value = newVal;
	}
}

	// Hide or show theField by passing theCheckbox
function tx_order_pi1_hideShow(theField, theCheckbox) {
	if (document.getElementById(theField) && document.getElementById(theCheckbox)) {
		document.getElementById(theField).style.display = (document.getElementById(theCheckbox).checked) ? 'block' : 'none';
	}
}