function fncCommon_Select_Append_Selected(fromElement, toElement){
	var fromOptions = $(fromElement).getElementsBySelector('option');
	var toOptions   = $(toElement).getElementsBySelector('option');
	
	fromOptions = fromOptions.reject(function(fromOption){
		return !fromOption.selected || toOptions.any(function(toOption){return toOption.value == fromOption.value;});
	});
	
	fromOptions.each(function(fromOption){
		$(toElement).options[$(toElement).options.length] = new Option(fromOption.text, fromOption.value);
	});
}

function fncCommon_Select_Remove_Selected(sourceElement){
	var sourceOptions = $(sourceElement).getElementsBySelector('option');
	sourceOptions.reject(function(sourceOption){
		return !sourceOption.selected;
	}).each(function(sourceOption){
		sourceOption.remove();
	});
}

function fncCommon_Update_Select_Option_ByValue(sourceElement, optionNeedle, optionValue, optionName){
	var sourceOptions = $(sourceElement).getElementsBySelector('option');
	sourceOptions.reject(function(sourceOption){
		return sourceOption.value != optionNeedle;
	}).each(function(sourceOption){
		sourceOption.value = optionValue;
		sourceOption.innerHTML = optionName;
	});
}

function fncCommon_Update_Select_Option(sourceElement, optionValue, optionName){
	var sourceOptions = $(sourceElement).getElementsBySelector('option');
	var rejection = sourceOptions.reject(function(sourceOption){
		return sourceOption.value != optionValue;
	}).each(function(sourceOption){
		sourceOption.value     = optionValue;
		sourceOption.innerHTML = optionName;
	});
		
	if(rejection.length == "0"){
		$(sourceElement).options[$(sourceElement).options.length] = new Option(optionName, optionValue, false);
	}
}

/**
 * Searchs for the needle in a select list.
 * if optionValue && optionName are undefined, it removes the option element
 * if optionValue && optionName are NOT undefined, it updates the option element
 *   and if it does not find the needle it creates a new option
 *
 * @param select sourceElement
 * @param string optionNeedle
 * @param string optionValue
 * @param string optionName
 */
function fncCommon_Alter_Select(sourceElement, optionNeedle, optionValue, optionName){
	var sourceOptions = $(sourceElement).getElementsBySelector('option');
	var rejection = sourceOptions.reject(function(sourceOption){
		return sourceOption.value != optionNeedle;
	}).each(function(sourceOption){
		if (typeof(optionValue) != "undefined" && typeof(optionName) != "undefined"){
			sourceOption.value     = optionValue;
			sourceOption.innerHTML = optionName;
		} else {
			$(sourceOption).remove();
		}
		
	});
		
	if(rejection.length == "0"){
		$(sourceElement).options[$(sourceElement).options.length] = new Option(optionName, optionValue, false);
	}
}



function fncCommon_OnEnterPress(event, callback){
	if(event.keyCode == Event.KEY_RETURN) {
		try {
			eval(callback + '();');
		} catch(ex){
			throw(ex);
		}
	}
}

/*
Clears the default text from an input field
Usage on html input: onfocus="clear_input(this);"
Sept 09 by Yaz
*/
function clear_input(theText) {
	if (theText.value == theText.defaultValue) {
		theText.value = ""
	}
}