
function confirmNav(nav) {
	if (document.edit && document.edit.changed) {
		if (document.edit.changed.value == 1) {
			if (confirm("Leave without saving your changes?")) {
				eval(nav);
			}
		}
		else {
			eval(nav);
		}
	}
	else {
		eval(nav);
	}
}

function setConfirmNav() {
	if (document.edit && document.edit.changed) {
		document.edit.changed.value = 1;
	}
}

function uRailLoad(loadTaskId) {
	parent.document.getElementById('task_children_' + loadTaskId).innerHTML = document.body.innerHTML;
}

function annotate() {
	now = new Date;
	var month = now.getMonth() + 1;
	if (month < 10) { 
		month = "0" + month;
	}
	if (now.getDate() < 10) { 
		var day = "0" + now.getDate();
	}
	else {
		var day = now.getDate();
	}
	if (now.getMinutes() < 10) { 
		var minutes = "0" + now.getMinutes();
	}
	else {
		var minutes = now.getMinutes();
	}
	if (now.getHours() < 10) { 
		var hours = "0" + now.getHours();
	}
	else {
		var hours = now.getHours();
	}
	var add = "-----  " + month + "-" + day + "-" + now.getFullYear() + " @ " + hours + ":" + minutes + 
	          "  ---------------------\n\n\n\n----------------------------------------------------\n\n";
	document.edit.task_notes.value = add + document.edit.task_notes.value;
}


function showPicker(type, target, date, g_path) {
// date is expected in YYYY-MM-DD format
	var URL;
	var stats;
	
	URL = g_path+"picker.php?type=" + type + "&target=" + target + "&date=" + date;

	if (type.indexOf("parent") != -1) {
		stats = "height=500, width=450, scrollbars=yes, toolbar=no, location=no, status=yes";
	}
	else if (type.indexOf("date") != -1) {
		stats = "height=275, width=315, scrollbars=yes, toolbar=no, location=no, status=yes";
	}
	else {
		stats = "height=500, width=500, scrollbars=yes, toolbar=no, location=no, status=yes";
	}
	window.open(URL, "calendar", stats);
}

function pickDate(thisYear, thisMonth, thisDay, target) {
	if (target == "edit") {
		setSelectToValue(window.opener.document.edit.task_month, thisMonth);
		setSelectToValue(window.opener.document.edit.task_day, thisDay);
		setSelectToValue(window.opener.document.edit.task_year, thisYear);
		window.opener.setConfirmNav();
		window.close();
	}
	else 	if (target == "edit2") {
		setSelectToValue(window.opener.document.edit.task_month2, thisMonth);
		setSelectToValue(window.opener.document.edit.task_day2, thisDay);
		setSelectToValue(window.opener.document.edit.task_year2, thisYear);
		window.opener.setConfirmNav();
		window.close();
	}
	else 	if (target == "edit3") {
		setSelectToValue(window.opener.document.edit.task_month3, thisMonth);
		setSelectToValue(window.opener.document.edit.task_day3, thisDay);
		setSelectToValue(window.opener.document.edit.task_year3, thisYear);
		window.opener.setConfirmNav();
		window.close();
	}
	else 	if (target == "edit4") {
		setSelectToValue(window.opener.document.edit.task_month4, thisMonth);
		setSelectToValue(window.opener.document.edit.task_day4, thisDay);
		setSelectToValue(window.opener.document.edit.task_year4, thisYear);
		window.opener.setConfirmNav();
		window.close();
	}
}

function selectedDate(formName, prefix) {
	var selectedYear;
	var selectedMonth;
	var selectedDay;
	eval("selectedYear = document." + formName + "." + prefix + "_year.options[document." + formName + "." + prefix + "_year.selectedIndex].value;");
	eval("selectedMonth = document." + formName + "." + prefix + "_month.options[document." + formName + "." + prefix + "_month.selectedIndex].value;");
	eval("selectedDay = document." + formName + "." + prefix + "_day.options[document." + formName + "." + prefix + "_day.selectedIndex].value;");
	return selectedYear + "-" + selectedMonth + "-" + selectedDay;
}

function toggleGroupBackground(thisDiv, prefix) {
	var i;
	for (i = 0; document.getElementById(prefix + i); i++) {
		document.getElementById(prefix + i).className = "group";
	}
	thisDiv.className = "groupActive";
}

function validateEditData() {
	var day = document.edit.task_day[document.edit.task_day.selectedIndex].value;
	var month = document.edit.task_month[document.edit.task_month.selectedIndex].value;
	var year = document.edit.task_year[document.edit.task_year.selectedIndex].value;
	if (day != "" || month != "" || year != "") {
		var editDate = new Date(parseFloat(year), parseFloat(month)-1, parseFloat(day));
// editDate = new Date(parseFloat(document.edit.task_year[document.edit.task_year.selectedIndex].value), parseFloat(document.edit.task_month[document.edit.task_month.selectedIndex].value)-1, parseFloat(document.edit.task_day[document.edit.task_day.selectedIndex].value));alert(editDate.getDate());
		if (editDate.getDate() != day || editDate.getMonth() != (month - 1) || editDate.getFullYear() != year) {
			return "The current value in the Date Due field is not a valid date. Change or clear this value before Saving.";
		}
		else {
			return true;
		}
	}
	else {
		return true;
	}
}

