// Left trimming of whitespace
function ltrim( strValue ) { return strValue.replace( /^\s*/, "" ); }

// Right trimming of whitespace
function rtrim( strValue ) { return strValue.replace( /\s*$/, "" ); }

// Left and richt trimming of whitespace
function trim( strValue )  { return rtrim( ltrim( strValue ) ); }

// Retrieve an element value
// Any element that is an input element will autodetect and return it's
// value as you would usually do manually.
//  * checkbox & radiobuttons returned either true (checked) or false (unchecked)
//  * text, textarea, password, file and single-selects return there entered or selected value
//  * multi-selects return an array of selected values
function getElementVal( strElementId ) {
 	var mixValue = null;
 	var objElement = document.getElementById( strElementId );
 	
 	if( !objElement ) {
		alert( 'The given elementid: [' + strElementId + '] is non-existent' );
		return mixValue;
 	}

	switch( objElement.type ) {
		case 'radio':
			mixValue = false;
			objElement = document.getElementsByName( strElementId );
			for( var intCounter = 0; intCounter < objElement.length; intCounter++ ) {
				if( objElement[intCounter].checked == true ) {
					mixValue = true;
				}
			}
			break;
		case 'checkbox':
			mixValue = objElement.checked;
			break;
		case 'text':
		case 'textarea':
		case 'password':
		case 'file':
		case 'select-one':
			mixValue = objElement.value;
			mixValue = trim( mixValue );
			break;
		case 'select-multiple':
			mixValue = new Array();
			for( var intCounter = 0; intCounter < objElement.length; intCounter++ ) {
				if( objElement[intCounter].selected == true ) {
					mixValue[mixValue.length] = trim( objElement[intCounter].value );
				}
			}
			break;
		default:
			alert( 'The given elementid: [' + strElementId + '] is not a valid input-element' );
	}

	return mixValue; 	
}
