
function radio_get_checked_value( form_name, input_name ) {

	return radio_button_get_checked_value( form_name, input_name );

}

function radio_button_get_checked_value( form_name, input_name ) {

	try {

		var j;
		var form = eval('document.' + form_name);

		if ( form && (typeof(form) != 'undefined') ) {
			var input = eval('form.' + input_name);

			if ( input && (typeof(input) != 'undefined') ) {
				for ( j =0; j < input.length; j++ ) {
					if ( input[j].checked == true ) {
						return input[j].value;
					}
				}

				return null;
			}
		}
		return false;

	}
	catch(e) {
		_Form_handle_error( e );
	}


}

function radio_check_by_dom_id ( which_id ) {

	return radio_button_check_by_dom_id( which_id );
}

function radio_button_check_by_dom_id ( which_id ) {

	try {
		
		var obj;

		if ( obj = dom_get_object_by_id(which_id) ) {
			return radio_check_by_dom_obj(obj);
		}

		return false;

	}
	catch(e) {
		_Form_handle_error( e );
	}

}

function radio_button_uncheck_all( form_name, input_name ) {

	try {

		var j;
		var form = eval('document.' + form_name);

		if ( form && (typeof(form) != 'undefined') ) {
			var input = eval('form.' + input_name);

			if ( input && (typeof(input) != 'undefined') ) {
				if ( typeof(input.length) == 'undefined' || input.length == 0 ) {
					input.checked = false;
				}
				else {
					for ( j =0; j < input.length; j++ ) {
						if ( input[j].checked == true ) {
							input[j].checked = false;
						}
					}
				}

			}
		}

		return true;	
		

	}
	catch(e) {
		_Form_handle_error( e );
	}


}

function radio_check_by_dom_obj ( obj ) {

	try {

		obj.checked = true;
		
	}
	catch(e) {
		_Form_handle_error( e );
	}

}

function checkbox_check_by_dom_id ( which_id ) {

	try {
		
		var obj;

		if ( obj = dom_get_object_by_id(which_id) ) {
			return input_check_by_dom_obj(obj);
		}

		return false;

	}
	catch(e) {
		_Form_handle_error( e );
	}

}

function checkbox_uncheck_by_dom_id ( which_id ) {

	try {
		
		var obj;

		if ( obj = dom_get_object_by_id(which_id) ) {
			return input_uncheck_by_dom_obj(obj);
		}

		return false;

	}
	catch(e) {
		_Form_handle_error( e );
	}

}

function input_check_by_dom_obj ( obj ) {

	try {
		obj.checked = true;

	}
	catch(e) {
		_Form_handle_error( e );
	}

}

function input_uncheck_by_dom_obj ( obj ) {

	try {
		obj.checked = false;

	}
	catch(e) {
		_Form_handle_error( e );
	}

}

function radio_check_by_dom_obj ( obj ) {

	try {

		obj.checked = true;
		
	}
	catch(e) {
		_Form_handle_error( e );
	}

}

function is_radio_checked_by_dom_id( which_id ) {

	return is_input_checked_by_dom_id ( which_id );

}

function is_checkbox_checked_by_dom_id( which_id ) {

	return is_input_checked_by_dom_id ( which_id );

}

function is_radio_checked_by_dom_obj( which_obj ) {

	return is_input_checked_by_dom_obj ( which_obj );

}

function is_checkbox_checked_by_dom_obj( which_obj ) {

	return is_input_checked_by_dom_obj ( which_obj );

}

function is_input_checked_by_dom_id( which_id ) {

	try {
		
		var obj;

		if ( obj = dom_get_object_by_id(which_id) ) {
			return is_input_checked_by_dom_obj(obj);
		}

		return false;

	}
	catch(e) {
		_Form_handle_error( e );
	}

}

function is_input_checked_by_dom_obj( obj ) {

	try {
		
		if ( obj.checked ) {
			return true;
		}
	
		return 0;

	}
	catch(e) {
		_Form_handle_error( e );
	}

}




function radio_select_option_value( radio_obj, value ) {

	try {

		var j;
		
		for ( j = 0; j < radio_obj.length; j++ ) {
			alert( j );
		}

	}
	catch(e) {
		_Form_handle_error( e );
	}


}

function numeric_date_parts_to_hash( date, format, delimiter, prepend_zeros ) {

	try {
		var j;
		var date_parts = new Array();
		var format_char;	
		var cur_format_len;
		var cur_format_str;
		var cur_format_char;
		var format_split;
		var date_string   = new String(date);
		var format_index = 0;
		var cur_char;
		var cur_part = '';

		if ( !format ) {
			format = 'mm/dd/yyyy';
		}

		var format_string = new String(format);

		if ( !delimiter ) {
			delimiter = '/';
		}

		if ( typeof(prepend_zeros) == 'undefined' ) {
			prepend_zeros = true;
		}

		format_split = format_string.split(delimiter);
		
		for ( j = 0; j < date_string.length; j++ ) {
			cur_format_str  = format_split[format_index];
			cur_format_len  = cur_format_str.length;
			cur_format_char = cur_format_str.charAt(0).toLowerCase();

			cur_char = date_string.charAt(j);

			if ( !isNaN(cur_char) ) {
				cur_part = cur_part + cur_char;
			}

			if ( (cur_char == delimiter) || (j == (date_string.length - 1)) ) {
				if ( cur_part.length < cur_format_len ) {
					if ( prepend_zeros ) {
						if ( cur_format_char == 'm' || cur_format_char == 'd' ) {
							while ( cur_part.length < cur_format_len ) {
								cur_part = '0' + cur_part;
							}
						}
						else {
							throw 'Invalid Date';
						}
					}
				}
							
				date_parts[cur_format_char] = cur_part;
				cur_part = '';

				format_index++;

			}		


		}
		
		return date_parts;

	}
	catch(e) {
		_Form_handle_error( e );
	}

}

function numeric_date_parts_to_date_obj( date, format, delimiter, prepend_zeros ) {

	try { 
		var date_hash = numeric_date_parts_to_hash(date, format, delimiter, prepend_zeros);

		var date_obj = new Date();

		date_obj.setMonth( date_hash['m'] );
		date_obj.setDate( date_hash['d'] );
		date_obj.setFullYear( date_hash['y'] );

		return date_obj;
		
	}
	catch(e) {
		alert( e.message );
	}

}

function add_days_to_date_object( date_obj, num_days ) {

	try {
		var new_ms;
		var orig_ms = date_obj.getTime();
		
		new_ms = orig_ms + (num_days * (24 * 60 * 60 * 1000));
		
		date_obj.setTime( new_ms );

		return date_obj;
	}
	catch(e) {
		alert( e.message );
	}

}

function dropdown_select_item_by_option_value( dropdown_id, value ) {

	try {
		var dropdown_obj;

		if ( !(dropdown_obj = dom_get_object_by_id(dropdown_id)) ) {
			return false;
		}
		else {
			for ( j = 0; j < dropdown_obj.options.length; j++ ) {
				if ( dropdown_obj.options[j].value == value ) {
					dropdown_obj.selectedIndex = j;
					break;
				}
			}
		}

		return true;

	}
	catch(e) {
		alert( e.message );
	}
	
}

function dropdown_select_item_by_index( dropdown_id, index ) {

	try {
		var dropdown_obj;

		if ( !(dropdown_obj = dom_get_object_by_id(dropdown_id)) ) {
			return false;
		}
		else {
			dropdown_obj.selectedIndex = index;
		}

		return true;

	}
	catch(e) {
		alert( e.message );
	}
	
}

function dropdown_get_selected_value_by_dom_id( dropdown_id ) {

	try {
		var dropdown_obj;

		if ( !(dropdown_obj = dom_get_object_by_id(dropdown_id)) ) {
			return false;
		}
		else {
			return dropdown_get_selected_value_by_dom_obj(dropdown_obj);
		}

		return true;

	}
	catch(e) {
		alert( e.message );
	}

}

function dropdown_get_selected_value_by_dom_obj( dropdown_obj ) {

	try {
		var index;

		if ( dropdown_obj ) {
			if ( typeof(dropdown_obj.selectedIndex) != 'undefined' ) {
			
				index = dropdown_obj.selectedIndex;
				if ( index !== null ) {
					if ( typeof(dropdown_obj.options) != 'undefined' ) {
						if ( dropdown_obj.options.length > 0 ) {
							return dropdown_obj.options[index].value;
						}
					}
				}
			}
		}

		return '';
	}
	catch(e) {
		alert( e.message );
	}
}

function dropdown_add_option_by_dom_id ( dropdown_id, option_text, option_val ) {

	try {
		var dropdown_obj;

		if ( !(dropdown_obj = dom_get_object_by_id(dropdown_id)) ) {
			return false;
		}
		else {
			return dropdown_add_option_by_dom_obj(dropdown_obj, option_text, option_val);
		}

		return true;

	}
	catch(e) {
		alert( e.message );
	}


}

function dropdown_add_option_by_dom_obj ( dropdown_obj, option_text, option_val ) {

	try {
		var option_obj = new Option( option_text, option_val );

		dropdown_obj.options[dropdown_obj.options.length] = option_obj;

		// below here doesn't work right in FF :(
		//
		//var option_obj = __create_option_obj( option_text, option_val );
		//dropdown_obj.options.appendChild(option_obj);

		return option_obj;
	}
	catch(e) {
		alert( e.message );
	}


}

function __create_option_obj( option_text, option_val ) {

	try {

		var option_obj = document.createElement('option');

		option_obj.label     = option_text;
		option_obj.value     = option_val;

		if ( typeof(option_obj.innerText) != 'undefined' ) {
			try {
				option_obj.innerText = option_text;
			}
			catch(e) {
			}
		}
		else {
			option_obj.text = option_text;
		}

		return option_obj
	}
	catch(e) {
		alert( e.message );
	}

}

function dropdown_clear_options_by_dom_id( dropdown_id ) {

	try {
		var dropdown_obj;

		if ( !(dropdown_obj = dom_get_object_by_id(dropdown_id)) ) {
			return false;
		}
		else {
			return dropdown_clear_options_by_dom_obj(dropdown_obj);
		}

		return true;

	}
	catch(e) {
		alert( e.message );
	}

}

function dropdown_clear_options_by_dom_obj( dropdown_obj ) {

	try {
		var dropdown_obj;

		if ( dropdown_obj ) {
			if ( typeof(dropdown_obj.options) != 'undefined' ) {
				dropdown_obj.options.length = 0;
				return true;
			}
		}

		return null;

	}
	catch(e) {
		alert( e.message );
	}

}


function dropdown_add_optgroup_by_dom_id( dropdown_id, optgroup_label ) {

	try {

		if ( dropdown_obj = dom_get_object_by_id(dropdown_id) ) {
			return dropdown_add_optgroup_by_dom_obj(dropdown_obj, optgroup_label);
		}

		return null;

	}
	catch(e) {
		alert( e.message );
	}

}

function dropdown_add_optgroup_by_dom_obj( dropdown_obj, optgroup_label ) {

	try {
		if ( dropdown_obj ) {

                	var optgroup = document.createElement('optgroup');
                        optgroup.label = optgroup_label;

			//dropdown_obj.appendChild(optgroup);

			return optgroup;
		}

		return null;
	}
	catch(e) {
		alert( e.message );
	}


}

function dropdown_add_optgroup_option_by_dom_obj ( optgroup_obj, option_text, option_val ) {

	try {

		//var option = new Option(option_text, option_val);

		var option_obj = __create_option_obj( option_text, option_val );

		if ( optgroup_obj && (typeof(optgroup_obj) != 'undefined') ) {
			optgroup_obj.appendChild(option_obj);
		}

		return option_obj;

	}
	catch(e) {
		alert( e.message );
	}


}

function dropdown_close_optgroup_by_dom_id( dropdown_id, optgroup_obj ) {

	try {

		if ( dropdown_obj = dom_get_object_by_id(dropdown_id) ) {
			return dropdown_close_optgroup_by_dom_obj( dropdown_obj, optgroup_obj )
		}

		return null;

	}
	catch(e) {
		alert( e.message );
	}
}

function dropdown_close_optgroup_by_dom_obj( dropdown_obj, optgroup_obj ) {

	try {
		if ( dropdown_obj && optgroup_obj ) {

			dropdown_obj.appendChild(optgroup_obj);

		}
	}
	catch(e) {
		alert( e.message );
	}

}

function dropdown_clear_optgroups_by_dom_id( dropdown_id ) {

	try {

		if ( dropdown_obj = dom_get_object_by_id(dropdown_id) ) {
			return dropdown_clear_optgroups_by_dom_obj(dropdown_obj);
		}

		return null;

	}
	catch(e) {
		alert( e.message );
	}

}

//
// optgroup clearing doesn't seem to work. Leaves first child. not sure why
//
function dropdown_clear_optgroups_by_dom_obj( dropdown_obj ) {

	try {

		if ( dropdown_obj ) {

			var next_child;
			var cur_child = dropdown_obj.firstChild;
	
			while ( cur_child ) {

				next_child = cur_child.nextSibling;

				if ( cur_child.tagName && (cur_child.tagName.toLowerCase() == 'optgroup') ) {
					dropdown_obj.removeChild(cur_child);
				}

				cur_child = next_child;
			}
		}

	}
	catch(e) {
		alert( e.message );
	}

}

function dropdown_clear_all_by_dom_id( dropdown_id ) {

	try {
		if ( dropdown_obj = dom_get_object_by_id(dropdown_id) ) {
			return dropdown_clear_all_by_dom_obj(dropdown_obj);
		}

		return null;

	}
	catch(e) {
		alert( e.message );
	}

}

function dropdown_clear_all_by_dom_obj( dropdown_obj ) {

	try {

		return dom_obj_remove_children( dropdown_obj );

	}
	catch(e) {
		alert( e.message );
	}

}

function dom_obj_remove_children( dom_obj ) {

	try {
		if ( dom_obj ) {
			if ( dom_obj.firstChild ) {
				var cur_child = dom_obj.firstChild;
				var next_child;	

				while ( cur_child ) {

					if ( typeof(cur_child.firstChild) != 'undefined' ) {
						if ( cur_child.firstChild ) {
							dom_obj_remove_children(cur_child.firstChild);
						}
					}

					next_child = cur_child.nextSibling;

					dom_obj.removeChild(cur_child);

					cur_child = next_child;
				}
			}
		}
				

	}
	catch(e) {
		alert( e.message );
	}

}

function ucfirst( strval ) {

	try {

		if ( strval ) {
			var first_letter;

			strval 	     = strval.toLowerCase()
			first_letter = strval.substring(0,1);
		
			first_letter = first_letter.toUpperCase();

			return first_letter + strval.substring( 1 );
		}
		else {
			return '';	
		}

	}
	catch(e) {
		alert( e.message );
	}
	
}

function _Form_handle_error( e ) {

	alert( e.message );

}

