// ===========================================================================================================
// ===========================================================================================================
// ===========================================================================================================
function timeformat(object) {
//
//  This will limit, but not prevent, the users ability to enter an invalid time.
//
//
	key = window.event.keyCode;
//  Let the control keys happen.
	if (key == 13 || key == 9 ) return true;
	if (key >= 37 && key <= 40) return true;
//  Reject everything but numbers backspace and delete
	if (key >= 48 && key <= 57 || key == 8 || key == 46){
	}
	else {
		event.returnValue=false;
		return false;
	}
//
//  A time entry can only start with a zero one or two
//
	if (object.value.length == 0){
		if (key!=48 && key!=49 && key!=50 && key != 8 && key != 46){
//  Cancel the key press
			event.returnValue=false;
			return false;
		}
		else {
// Backspace / delete or 
// The proper number is pressed.  We're Ok.
			return true
		}
	}
//
//  This is the second character in a time entry.
//
	if (object.value.length == 1){
		if (key >= 48 && key <= 57 || key == 46) {
// Backspace / delete or
// A number is pressed.  We're Ok so add the colon.
//  To do this we must add the keypress value to the string, then the colon.
//  Since we've already added the value we must cancel the event even though
//  it's Ok.
// 
			object.value = object.value + String.fromCharCode(key) + ":";
			event.returnValue=false;
			return false;
		}
		else {
			if (key == 8) {
// Delete key pressed. Ok.
				return true;
			}
			else {
//  Cancel the key press
				event.returnValue=false;
				return false;
			}
		}
	}
//
//  A time entry cannot be three characters long due to the colon
//
	if (object.value.length == 3){
		if (key == 8) {
//  Backspace.  Remove the colon.
			object.value = object.value.substr(0,2);
			return true;
		}
		else {
			if (key >= 48 && key <= 57 || key == 46) {
// Delete is pressed or 
// A number is pressed.  We're Ok.
				return true;
			}
			else {
//  Cancel the key press
			event.returnValue=false;
			return false;
			}
		}
	}
//
//  This is the last character of the time string
//
	if (object.value.length == 4){
		if (key == 8 || key == 46) {
//  Backspace/ delete.  We're Ok
		}
		else {
			if (key >= 48 && key <= 57) {
// A number is pressed.  We're Ok.
				return true;
			}
			else {
//  Cancel the key press
			event.returnValue=false;
			return false;
			}
		}
	}
//
//  The input box is filled.
//
	if (object.value.length > 4){
//  Cancel the key press unless 
// (a) it's a delete/backspace key
// (b) The user has not selected the current text
// Selected text
		if (document.selection.createRange().text == object.value) {
//  The user must type a zero, one or two.
			if (key!=48 && key!=49 && key!=50 && key != 8 && key != 46){
				//  Cancel the key press
				event.returnValue=false;
				return false;
			}
			else {
				return true;
			}
		}
//  No selected text - only delete and backspace allowed.
		if (key != 8 && key != 46 ) {
			event.returnValue=false;
			return false;
		}
	}
}
// ===========================================================================================================
// ===========================================================================================================
// ===========================================================================================================
function numberformat(object) {
//
//  This will limit the input to numbers
//
//
	key = window.event.keyCode;
//  Let the control keys happen.
	if (key == 13 || key == 9 ) return true;
	if (key >= 37 && key <= 40) return true;
//  Reject everything but numbers, backspace, delete and dash
	if (key >= 48 && key <= 57 || key >= 96 && key <= 105 || key == 8 || key == 46 || key == 189){
	}
	else {
		event.returnValue=false;
		return false;
	}
}
// ===========================================================================================================
// ===========================================================================================================
// ===========================================================================================================

function uppercaseformat(object) {

	object.value = object.value.toUpperCase();

}
// ===========================================================================================================
// ===========================================================================================================
// ===========================================================================================================

function setindex(control,strValue) {
//  This will set the index of a select object to point to the specified value.  This makes it possible
//    to validate the object based on it's default <option selected> item.
	for (var i=0;i<control.options.length;i++) {
		if (control.options[i].value == strValue) {
			control.options[i].selected = true;
			return true;
		}
	}

}