// Converts the results of jQuery's serializeArray into an object, consolidating duplicate entries into arrays
// of values (i.e. allow multiple selection check boxes)
function jquery_serialized_array_to_object(vals) {
	var vals_object = {};
	
	for (var i = 0; i < vals.length; i++) {
		if (vals_object[vals[i].name] == undefined) {
			// Value has not been set on the object yet
			vals_object[vals[i].name] = vals[i].value;
		} else {
			if (vals_object[vals[i].name].constructor.toString().indexOf("Array") == -1) {
				// The value has been set, the key has been found again, but the value is not an array yet
				vals_object[vals[i].name] = [vals_object[vals[i].name], vals[i].value];
			} else {
				// The value has been set, the key has been found again, and the value is already an array
				vals_object[vals[i].name].push(vals[i].value);
			}
		}
	}
	
	return vals_object;
}

// Tries to reformat a MySQL datetime field into something more readable
function fix_date(date) {
	date = date.substr(0, 10);
	date_pieces = date.split('-');
	
	return date_pieces[1] + '/' + date_pieces[2] + '/' + date_pieces[0].substr(2, 3);
}
