Utilities.Selection = function(args){
	
	var element = args.Element;
	var start = args.Start;
	var end = args.End;
	var length = args.Length;
	
	if(typeof(element) == 'string'){
		element = document.getElementById(element);
		}
	
	
	if(start == null && end == null && length == null){
		if(element.selectionStart && element.selectionEnd){
			start = element.selectionStart;
			end = element.selectionEnd;
			length = end - start;
			}
		}
	else{
		if(start == null && (end != null && length != null)){
			start = end - length;
			}
		else if(end == null && (start !=  null && length !=  null)){
			end = start + length;
			}
		else if(length == null && (start != null && end != null)){
			length = start - end;
			}
		else{
			return false;
			}
		
		if(element.setSelectionRange){
			element.setSelectionRange(start, end);
			}
		
		element.focus();
		}
	
	this.Element = element;
	this.Start = start;
	this.Length = length;
	this.End = end;
	}

Utilities.Selection.prototype.InsertText = function(args){
	
	var el = this.Element;
	var start = this.Start;
	var end = this.End;
	var text = args.Text;

	if(args.Overwrite){
		el.value = el.value.substring(0, start) + text + el.value.substring(end);
		}
	else{
		el.value = el.value.substring(0, start) + text + el.value.substring(start);
		}
	}