function open_new_project() {
	var i;
	var winname = "project_0";
	var winoptions = "width=980,height=500,resizable=yes,scrollbars=yes,left=0,top=0";
	var ds = top.frame_sess;
	var uniqueid = ds.uniqueid.value;
	var myelem;

	for (i=1;i<=6;i++) {
		myelem = eval("top.frame_sess.project" + i);
		if (myelem.value == "") {
			window.open("",uniqueid + "project_0",winoptions);
			myelem.value = uniqueid + "project_0";
			return uniqueid + "project_0";
		}
	}
	alert("You already have the maximum allowed project windows open.");
	return 0;
}

function open_project(project_id) {
	var i;
	var winname = "project_" + project_id;
	var winhtml = "/project_" + project_id + "/project_frame.htm";
	var winoptions = "width=980,height=500,resizable=yes,scrollbars=yes,left=0,top=0";
	var ds = top.frame_sess;
	var uniqueid = ds.uniqueid.value;
	var myelem;
	var mywin;

	for (i=1;i<=6;i++) {
		myelem = eval("top.frame_sess.project" + i);
		if (myelem.value == uniqueid + "project_" + project_id) {
			mywin = window.open("",uniqueid + "project_"+project_id);
			if (mywin.top.frame_data) {
				mywin.focus();
				return;
			}
			else {
				mywin.close();
				window.open(winhtml,uniqueid + "project_"+project_id,winoptions);
				myelem.value = uniqueid + "project_" + project_id;
				return;
			}
		}
	}
	for (i=1;i<=6;i++) {
		myelem = eval("top.frame_sess.project" + i);
		if (myelem.value == "") {
			window.open(winhtml,uniqueid + "project_"+project_id,winoptions);
			myelem.value = uniqueid + "project_" + project_id;
			return;
		}
	}
	alert("You already have the maximum allowed project windows open.");
	return;
}

function set_edit_status() {
	var i;
	var myelem;
	var mywin;

	top.frame_body.set_edit_status();
	for (i=1;i<=6;i++) {
		myelem = eval("top.frame_sess.project" + i);
		if (myelem.value != "") {
			mywin = window.open("",myelem.value);
			if (! mywin.set_edit_status) {
				mywin.close();
				myelem.value = "";
				continue;
			}
			mywin.set_edit_status();
		}
	}
	for (i=0;i<top.proj_windows.length;i++) {
		mywin = top.proj_windows[i].winobj;
		if (mywin && mywin.closed == false && mywin.set_edit_status) mywin.set_edit_status();
	}
}

function tidy_project(project_id,edit_status) {
	var i;
	var myelem;
	var uniqueid = top.frame_sess.uniqueid.value;
	var dh = top.frame_hid.document;
	var myid = top.get_session_id();
	var myloc = escape(dh.location);

	for (i=1;i<=6;i++) {
		myelem = eval("top.frame_sess.project" + i);
		if (myelem.value == uniqueid + "project_" + project_id) {
			myelem.value = "";
			if (edit_status != true) return;
			dh.open();
			dh.write("<html>");
			dh.write('<head>');
			dh.write('<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">');
			dh.write('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">');
			dh.write('</head>');
			dh.write("<body>");
			dh.write('<form name = "edit_project" method="POST" action="/cgi-bin/tidy_project.cgi">');
			dh.write('<input type="hidden" id="proj_id" name="proj_id" value = "' + project_id + '">');
			dh.write('<input type="hidden" id= "session_id" name="session_id" value = "'+ myid + '">');
			dh.write("</form>");
			dh.write("</body>");
			dh.write("</html>");
			dh.close();
			dh.edit_project.submit();
			setTimeout("window.load_dummy()",1000);
			return;
		}
	}
}

function load_dummy() {
	var dh = top.frame_hid.document;
	dh.location = "../fixed/dummy.htm";
}

function undelete_project (project_id,status) {
	var dh = top.frame_hid.document;
	dh.open();
	dh.write('<html>');
	dh.write('<head>');
	dh.write('<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">');
	dh.write('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">');
	dh.write('</head>');
	dh.write('<body>');
	dh.write('<form ID="delete_project" name="delete_project" method="POST" action="/cgi-bin/undelete_project.cgi">');
	dh.write('<input type="hidden" id="session_id" name="session_id" value="'+top.get_session_id()+'">');
	dh.write('<input type="hidden" id="proj_id" name="proj_id" value="'+project_id+'">');
	dh.write('<input type="hidden" id="status" name="status" value="'+status+'">');
	dh.write('</form>');
	dh.write('</body>');
	dh.write('</html>');
	dh.close();
	top.set_submit();
	dh.delete_project.submit();
}

function delete_project (project_id,status) {
	var i;
	var myelem;
	var uniqueid = top.frame_sess.uniqueid.value;

	if (status == "N") {
		if (!confirm("You are about to delete a new project.  Once done it will be completely removed from the system.  Are you sure you want to continue?")) {
			return;
		}
	}
	else if (status == "A") {
		if (!confirm("You are about to delete a project awaiting approval.  Once done it will be marked for deletion and in one week will be automatically deleted from the system. Are you sure you want to continue?")) {
			return;
		}
	}
	else {
		if (!confirm("You are about to delete a project.  Once done it will be marked for deletion and in four weeks will be automatically deleted from the system. Are you sure you want to continue?")) {
			return;
		}
	}
	for (i=1;i<=6;i++) {
		myelem = eval("top.frame_sess.project" + i);
		if (myelem.value == uniqueid + "project_" + project_id) {
			mywin = window.open("",myelem.value);
			mywin.close();
			myelem.value = "";
		}
	}
	var dh = top.frame_hid.document;
	dh.open();
	dh.write('<html>');
	dh.write('<head>');
	dh.write('<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">');
	dh.write('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">');
	dh.write('</head>');
	dh.write('<body>');
	dh.write('<form ID="delete_project" name="delete_project" method="POST" action="/cgi-bin/delete_project.cgi">');
	dh.write('<input type="hidden" id="session_id" name="session_id" value="'+top.get_session_id()+'">');
	dh.write('<input type="hidden" id="proj_id" name="proj_id" value="'+project_id+'">');
	dh.write('<input type="hidden" id="status" name="status" value="'+status+'">');
	dh.write('</form>');
	dh.write('</body>');
	dh.write('</html>');
	dh.close();
	top.set_submit();
	dh.delete_project.submit();
}

function delete_project_response (mynum,msg_text) {
	var dh = top.frame_hid.document;
	var mywin;
	msg_text = unescape(msg_text);
	if (top.check_session(mynum,msg_text) == false) {
		dh.location = "../fixed/dummy.htm";
		return;
	}

	top.open_window("edit",msg_text);
	top.close_window("edit",top.window_tout);
	dh.location = "../fixed/dummy.htm";
	mywin = top.get_window("search_results");
	if (mywin && mywin.old_search) {
		mywin.old_search();
	}
}

function clear_edit_allowed(proj_id) {
	if (proj_id == "all") top.edit_status.length = 0;
	else top.edit_status[proj_id] = 0;
}

function set_edit_allowed(proj_id) {
	top.edit_status[proj_id] = 1;
}

function test_edit_allowed (proj_id) {
	if (top.get_group_id() == top.DA) return 1;
	else return top.edit_status[proj_id];
}

