//admin functions


//popup a dialog box to confirm action
function confirmDialogBox(thisTitle, thisAction) {
	confirmWindow = confirm(thisTitle);

	if (confirmWindow == true) {
		if (thisAction) {window.location = thisAction;}
		return true;
	} else {
		return false;
	}
}

//set date to today
function setDateToNow(formName, thisName) {
	if (formName && thisName) {
		var now = new Date();

		var month = now.getMonth();
		var day = now.getDate();
		var year = now.getYear();
		if (year < 2000) {year += 1900;} //for netscape?

		var hour = now.getHours();
		var minute = now.getMinutes();
		var second = now.getSeconds();

		setDate(formName, thisName, month, day, year);
		setTime(formName, thisName, hour, minute, second);
	}

	return false;
}

//set date to null
function setDateToNull(formName, thisName) {
	if (formName && thisName) {
		setDate(formName, thisName, "", "", "");
		setTime(formName, thisName, "", "", "");
	}

	return false;
}

//set date
function setDate(formName, thisName, month, day, year) {
	if (month !== "") {month = month + 1;}

	monthObj = eval("document." + formName + "." + thisName + "_mon");
	setField(monthObj, month);

	dayObj = eval("document." + formName + "." + thisName + "_mday");
	setField(dayObj, day);

	yearObj = eval("document." + formName + "." + thisName + "_year");
	setField(yearObj, year);
}

//set time
function setTime(formName, thisName, hour, minute, second) {
	var ampm = "";

	if (hour != "") {
		var ampm = "am";
		if (hour > 11) {
			if (hour > 12) {hour = hour - 12;}
			ampm = "pm";
		} else {
			if (hour == 0) {hour = 12;}
		}
	
		minute = Math.round(minute / 15) * 15;
		if (minute == 0) {minute = "00";}
	}

	hourObj = eval("document." + formName + "." + thisName + "_hours");
	setField(hourObj, hour);

	minuteObj = eval("document." + formName + "." + thisName + "_minutes");
	setField(minuteObj, minute);

	ampmObj = eval("document." + formName + "." + thisName + "_ampm");
	setField(ampmObj, ampm);
}

//set field value
function setField(fieldObj, newValue) {
	if (fieldObj) {
		if (fieldObj.options) {
			//update pulldown
			for (i=0; i<fieldObj.options.length; i++) {
				if (fieldObj.options[i].value == newValue) {fieldObj.selectedIndex = i;}
			}
		} else {
			//update field
			fieldObj.value = newValue;
		}
	}
}

//set refreshForm value and submit form
function refreshAdminForm(thisForm) {
	if (thisForm) {
		thisForm.refreshForm.value = true;
		thisForm.submit();
	} else {
		alert(thisForm + " is not a valid form object");
	}
}
