// ####################################################
// ############### misc functions : begin
// ####################################################

// ## trim spaces from "response" var
function trim(stringValue){
	return stringValue.replace(/(^\s*|\s*$)/g, "");
}

// ## clear values from an Element (div, span, etc)
function clearValues(id){
	document.getElementById(id).innerHTML = "";
}
// ## after task (submit), update div with info
function afterTask(id,id2){
	document.getElementById(id).innerHTML = id2;
	var t=setTimeout("clearValues('taskInfo');",2500)
}	

// ## div hider - basic version
function hideDiv(div)
{
	var value = "";
	var which = document.getElementById(div).style.display;
	
	if (which == "none"){
		document.getElementById(div).style.display = value;
	} else {
		document.getElementById(div).style.display = "none";
	}
}

// ## div hider - AJAX version
function hideDivAJAX(div)
{
	var value = "";
	var which = document.getElementById(div).style.display;
	
	if (which == "none"){
		//document.getElementById(div).style.display = value;
		Effect.BlindDown(div)
	} else {
		//document.getElementById(div).style.display = "none";
		Effect.BlindUp(div)
	}
}

// ####################################################
// ############### misc functions : end
// ####################################################


// ####################################################
// ############### staff functions : begin
// ####################################################

// ## EDIT STAFF
// ## Open/Close panels, send data, and reload list
function editStaff(staff_id){
			
		var handlerFunc = function(t) {
		
			// when response "staff_updated" is returned, render list
			var theResponse = trim(t.responseText);
			if (theResponse == "staff_edited"){
		   		hideDiv('editStaffDiv_'+staff_id);
				new Ajax.Updater('staffList', '../global/includes/functions.php?task=reloadStaff', {asynchronous:true});
				
			} else if (theResponse == "staff_deleted"){
		   		hideDiv('editStaffDiv_'+staff_id);
				new Ajax.Updater('staffList', '../global/includes/functions.php?task=reloadStaff', {asynchronous:true});
				
			} else {
				//alert('error');
				//document.getElementById('taskStatus').innerHTML = "Something went wrong!";
			}
			
			
		}
		
		var staff_id = document.getElementById('editStaffForm_staff_id').value;
		var name = document.getElementById('editStaffForm_name').value;
		var credentials = document.getElementById('editStaffForm_credentials').value;
		var credentials = credentials.replace(/\r\n|\r|\n/g, '%0D%0A');
		credentials = credentials.replace(/&/g, "%26");
		var bio = document.getElementById('editStaffForm_bio').value;
		var bio = bio.replace(/\r\n|\r|\n/g, '%0D%0A');
		bio = bio.replace(/&/g, "%26");
		var position = document.getElementById('editStaffForm_position').value;
		var position = position.replace(/\r\n|\r|\n/g, '%0D%0A');
		position = position.replace(/&/g, "%26");
		var address = document.getElementById('editStaffForm_address').value;
		var address = address.replace(/\r\n|\r|\n/g, '%0D%0A');
		var infoAnswer_1 = document.getElementById('editStaffForm_info1').value;
		infoAnswer_1 = infoAnswer_1.replace(/&/g, "%26");
		var infoAnswer_2 = document.getElementById('editStaffForm_info2').value;
		infoAnswer_2 = infoAnswer_2.replace(/&/g, "%26");
		var infoAnswer_3 = document.getElementById('editStaffForm_info3').value;
		infoAnswer_3 = infoAnswer_3.replace(/&/g, "%26");
		var infoAnswer_4 = document.getElementById('editStaffForm_info4').value;
		infoAnswer_4 = infoAnswer_4.replace(/&/g, "%26");
		var email = document.getElementById('editStaffForm_email').value;
		var phone = document.getElementById('editStaffForm_phone').value;
		var phone = phone.replace(/\r\n|\r|\n/g, '%0D%0A');
		var pubdesc = document.getElementById('editStaffForm_pubdesc').value;
		var pubdesc = pubdesc.replace(/\r\n|\r|\n/g, '%0D%0A');
		pubdesc = pubdesc.replace(/&/g, "%26");
		var photoId_Main = document.getElementById('editStaffForm_photoIdMain').value;
		var status = document.getElementById('editStaffForm_status').value;
		var people_type = document.getElementById('editStaffForm_peopletype').value;
		var delete_it = document.getElementById('editStaffForm_delete').checked;
		
		new Ajax.Request('../global/includes/functions.php?task=editStaff&staff_id='+staff_id+'&name='+name+'&credentials='+credentials+'&bio='+bio+'&position='+position+'&address='+address+'&infoAnswer_1='+infoAnswer_1+'&infoAnswer_2='+infoAnswer_2+'&infoAnswer_3='+infoAnswer_3+'&infoAnswer_4='+infoAnswer_4+'&email='+email+'&phone='+phone+'&pubdesc='+pubdesc+'&status='+status+'&people_type='+people_type+'&photoId_Main='+photoId_Main+'&delete='+delete_it,{onSuccess:handlerFunc, asynchronous:true});

}

// ## ADD STAFF
// ## Open/Close panels and reload list
function addStaff(){

		var handlerFunc = function(t) {
		
			// when response "contact_added" is returned, render list
			var theResponse = trim(t.responseText);
			if (theResponse == "staff_added"){
		   		//alert(theResponse);
				document.getElementById('taskStatus').innerHTML = "Staff added!";
				var t=setTimeout("clearValues('taskStatus');",2500)
				hideDiv('addStaffDiv');
				new Ajax.Updater('staffList', '../global/includes/functions.php?task=reloadStaff', {asynchronous:true});
				
			} else {
				//alert('error');
				document.getElementById('taskStatus').innerHTML = "Something went wrong!";
			}
			
		}
				
		var name = document.getElementById('addForm_name').value;
		//alert(name);
		
		new Ajax.Request('../global/includes/functions.php?task=addStaff&name='+name,{onSuccess:handlerFunc, asynchronous:true});

}

// ## CHANGE PLACEMENT STAFF
// ## Manipulate Drop downs and Reload List
function changePlacementStaff(id,id2){
	var thePlacement = document.getElementById(id).value;	
	var theStaffId = id2;	
	
	
	var handlerFunc = function(t) {
		
		// when response "placement_updated" is returned, render list
		var theResponse = trim(t.responseText);
		if (theResponse == "placement_updated"){
	   		new Ajax.Updater('staffList', '../global/includes/functions.php?task=reloadStaff', {asynchronous:true});
			
		} else {
			alert('error');
			//document.getElementById('taskStatus').innerHTML = "Something went wrong!";
		}
				
	}
		
	new Ajax.Request('../global/includes/functions.php?task=editStaffPlacement&staff_id='+theStaffId+'&placement='+thePlacement,{onSuccess:handlerFunc, asynchronous:true});
}

// ## EDIT STAFF LINK
// ## Actually Turn on/off 'edit' links
function editStaffLink(id,task){
	if (task == "disable"){
	    $$('a.editStaffLink').each(Element.hide)
		document.getElementById(id).style.display = "";
	} else if (task == "enable"){
		 $$('a.editStaffLink').each(Element.show)
	}
}

// ## EDIT STAFF LOAD
// ## Turn on/off 'edit' links and Loads the Edit Form
function editStaffLoad(id){
	
	var value = "";
	var which = document.getElementById("editStaffDiv_"+id).style.display;
	
	if (which == "none"){
		hideDivAJAX("editStaffDiv_"+id);
		editStaffLink('editStaffLink_'+id,'disable');
	} else {
		//document.getElementById("editStaffDiv_"+id).style.display = "none"; // nonAJAX
		//setTimeout("Effect.BlindUp(editStaffDiv_"+id+");", 1000); // AJAX
		hideDivAJAX("editStaffDiv_"+id);
		editStaffLink('editStaffLink_'+id,'enable');
	}


	new Ajax.Updater('editStaffDiv_'+id, '../global/includes/functions.php?task=load_editStaffForm&staff_id='+id, {asynchronous:true});
}

// ####################################################
// ############### staff functions : end
// ####################################################


// ####################################################
// ############### publication functions : begin
// ####################################################
	
// ## ADD PUB
// ## Turn on/off buttons, send data, and reload list
function addPub(id){
		
		var handlerFunc = function(t) {
		
			// when response "pub_added" is returned, render list
			var theResponse = trim(t.responseText);
			if (theResponse == "publication_added"){
		   		hideDiv('addPubDiv_'+id);
				hideDiv('pubList_'+id);
				new Ajax.Updater('pubList_'+id, '../global/includes/functions.php?task=reloadPubList&staff_id='+id, {asynchronous:true});
				document.getElementById("editButtonSubmit").disabled = false;
				document.getElementById("editButtonCancel").disabled = false;
			} else {
				//alert('error');
				//document.getElementById('taskStatus').innerHTML = "Something went wrong!";
			}
			
		}
		
		var pmid = document.getElementById('addPubForm_pmid').value;
		var year = document.getElementById('addPubForm_year').value;
		var reference = document.getElementById('addPubForm_reference').value;
		reference = reference.replace(/&/g, "%26");
		var staff_id = document.getElementById('addPubForm_staff_id').value;
		var inPress = document.getElementById('addPubForm_inPress').checked;
				
		new Ajax.Request('../global/includes/functions.php?task=addPub&pmid='+pmid+'&year='+year+'&reference='+reference+'&inPress='+inPress+'&staff_id='+staff_id,{onSuccess:handlerFunc, asynchronous:true});

}

// ## EDIT PUB LOAD
// ## Turn on/off buttons and Loads the Edit Form
function editPubLoad(id,staff_id){
	
	hideDiv('pubList_'+staff_id);
	
	var value = "";
	var which = document.getElementById("editPubDiv_"+staff_id).style.display;
	
	if (which == "none"){
		setTimeout("Effect.BlindDown(editPubDiv_"+staff_id+");", 100);
		document.getElementById("editButtonSubmit").disabled = true;
		document.getElementById("editButtonCancel").disabled = true;
				
	} else {
		setTimeout("Effect.BlindUp(editPubDiv_"+staff_id+");", 100); // AJAX
		document.getElementById("editButtonSubmit").disabled = false;
		document.getElementById("editButtonCancel").disabled = false;
				
	}

	new Ajax.Updater('editPubDiv_'+staff_id, '../global/includes/functions.php?task=load_editPubForm&publication_id='+id, {asynchronous:true});
}

// ## ADD PUB LOAD
// ## Turn on/off buttons and Loads the Add Form
function addPubLoad(id){
	
	hideDiv('pubList_'+id);
	var value = "";
	var which = document.getElementById("addPubDiv_"+id).style.display;
	
	if (which == "none"){
		setTimeout("Effect.BlindDown(addPubDiv_"+id+");", 100);
		document.getElementById("editButtonSubmit").disabled = true;
		document.getElementById("editButtonCancel").disabled = true;
		
	} else {
		setTimeout("Effect.BlindUp(addPubDiv_"+id+");", 100); // AJAX
		document.getElementById("editButtonSubmit").disabled = false;
		document.getElementById("editButtonCancel").disabled = false;
	}

	new Ajax.Updater('addPubDiv_'+id, '../global/includes/functions.php?task=load_addPubForm&staff_id='+id, {asynchronous:true});
}

// ## EDIT PUB
// ## Open/Close panels, turn on/off buttons, send edited data, and reload list
function editPub(id,staff_id){
	
		var handlerFunc = function(t) {
		
			// when response "pub_updated" is returned, render list
			var theResponse = trim(t.responseText);
			if (theResponse == "publication_edited"){
		   		hideDiv('editPubDiv_'+staff_id);
				hideDiv('pubList_'+staff_id);
				new Ajax.Updater('pubList_'+staff_id, '../global/includes/functions.php?task=reloadPubList&staff_id='+staff_id, {asynchronous:true});
				
			} else if (theResponse == "publication_deleted"){
		   		hideDiv('editPubDiv_'+staff_id);
				hideDiv('pubList_'+staff_id);
				
				new Ajax.Updater('pubList_'+staff_id, '../global/includes/functions.php?task=reloadPubList&staff_id='+staff_id, {asynchronous:true});
				
			} else {
				//alert('error');
				//document.getElementById('taskStatus').innerHTML = "Something went wrong!";
			}
			
			document.getElementById("editButtonSubmit").disabled = false;
			document.getElementById("editButtonCancel").disabled = false;
			
			
		}
		
		var pmid = document.getElementById('editPubForm_pmid').value;
		var year = document.getElementById('editPubForm_year').value;
		var reference = document.getElementById('editPubForm_reference').value;
		reference = reference.replace(/&/g, "%26");
		var publication_id = document.getElementById('editPubForm_publication_id').value;
		var status = document.getElementById('editPubForm_status').value;
		var inPress = document.getElementById('editPubForm_inPress').checked;
		var delete_it = document.getElementById('editPubForm_delete').checked;
				
		new Ajax.Request('../global/includes/functions.php?task=editPub&pmid='+pmid+'&year='+year+'&reference='+reference+'&publication_id='+publication_id+'&status='+status+'&inPress='+inPress+'&delete='+delete_it,{onSuccess:handlerFunc, asynchronous:true});

}

// ####################################################
// ############### publication functions : end
// ####################################################



// ####################################################
// ############### grant functions : begin
// ####################################################

// ## ADD GRANT
// ## Open/Close panels, turn on/off buttons, send data, and reload list
function addGrant(id){
		
		var handlerFunc = function(t) {
		
			// when response "pub_added" is returned, render list
			var theResponse = trim(t.responseText);
			if (theResponse == "grant_added"){
		   		hideDiv('addGrantDiv_'+id);
				hideDiv('grantList_'+id);
				new Ajax.Updater('grantList_'+id, '../global/includes/functions.php?task=reloadGrantList&staff_id='+id, {asynchronous:true});
				document.getElementById("editButtonSubmit").disabled = false;
				document.getElementById("editButtonCancel").disabled = false;
			} else {
				//alert('error');
				//document.getElementById('taskStatus').innerHTML = "Something went wrong!";
			}
			
		}
		
		var role = document.getElementById('addGrantForm_role').value;
		var year = document.getElementById('addGrantForm_year').value;
		var description = document.getElementById('addGrantForm_description').value;
		description = description.replace(/&/g, "%26");
		description = description.replace(/\r\n|\r|\n/g, '%0D%0A');
		var staff_id = document.getElementById('addGrantForm_staff_id').value;
				
		new Ajax.Request('../global/includes/functions.php?task=addGrant&role='+role+'&year='+year+'&description='+description+'&staff_id='+staff_id,{onSuccess:handlerFunc, asynchronous:true});

}	

// ## EDIT GRANT LOAD
// ## Turn on/off buttons and Loads the Edit Form
function editGrantLoad(id,staff_id){
	hideDiv('grantList_'+staff_id);
	var value = "";
	var which = document.getElementById("editGrantDiv_"+staff_id).style.display;
	
	if (which == "none"){
		setTimeout("Effect.BlindDown(editGrantDiv_"+staff_id+");", 100);
		document.getElementById("editButtonSubmit").disabled = true;
		document.getElementById("editButtonCancel").disabled = true;
				
	} else {
		setTimeout("Effect.BlindUp(editGrantDiv_"+staff_id+");", 100); // AJAX
		document.getElementById("editButtonSubmit").disabled = false;
		document.getElementById("editButtonCancel").disabled = false;
				
	}

	new Ajax.Updater('editGrantDiv_'+staff_id, '../global/includes/functions.php?task=load_editGrantForm&grant_id='+id, {asynchronous:true});
}

// ## ADD GRANT LOAD
// ## Turn on/off buttons and Loads the Add Form
function addGrantLoad(id){
	
	hideDiv('grantList_'+id);
	var value = "";
	var which = document.getElementById("addGrantDiv_"+id).style.display;
	
	if (which == "none"){
		setTimeout("Effect.BlindDown(addGrantDiv_"+id+");", 100);
		document.getElementById("editButtonSubmit").disabled = true;
		document.getElementById("editButtonCancel").disabled = true;
		
	} else {
		setTimeout("Effect.BlindUp(addGrantDiv_"+id+");", 100); // AJAX
		document.getElementById("editButtonSubmit").disabled = false;
		document.getElementById("editButtonCancel").disabled = false;
	}

	new Ajax.Updater('addGrantDiv_'+id, '../global/includes/functions.php?task=load_addGrantForm&staff_id='+id, {asynchronous:true});
}

// ## EDIT GRANT
// ## Open/Close panels, turn on/off buttons, send edited data, and reload list
function editGrant(id,staff_id){
			
		var handlerFunc = function(t) {
		
			// when response "grant_updated" is returned, render list
			var theResponse = trim(t.responseText);
			if (theResponse == "grant_edited"){
		   		hideDiv('editGrantDiv_'+staff_id);
				hideDiv('grantList_'+staff_id);
				new Ajax.Updater('grantList_'+staff_id, '../global/includes/functions.php?task=reloadGrantList&staff_id='+staff_id, {asynchronous:true});
				
			} else if (theResponse == "grant_deleted"){
		   		hideDiv('editGrantDiv_'+staff_id);
				hideDiv('grantList_'+staff_id);
				
				new Ajax.Updater('grantList_'+staff_id, '../global/includes/functions.php?task=reloadGrantList&staff_id='+staff_id, {asynchronous:true});
				
			} else {
				//alert('error');
				//document.getElementById('taskStatus').innerHTML = "Something went wrong!";
			}
			
			document.getElementById("editButtonSubmit").disabled = false;
			document.getElementById("editButtonCancel").disabled = false;
			
			
		}
		
		var role = document.getElementById('editGrantForm_role').value;
		var year = document.getElementById('editGrantForm_year').value;
		var description = document.getElementById('editGrantForm_description').value;
		description = description.replace(/&/g, "%26");
		description = description.replace(/\r\n|\r|\n/g, '%0D%0A');
		var grant_id = document.getElementById('editGrantForm_grant_id').value;
		var status = document.getElementById('editGrantForm_status').value;
		var delete_it = document.getElementById('editGrantForm_delete').checked;
				
		new Ajax.Request('../global/includes/functions.php?task=editGrant&role='+role+'&year='+year+'&description='+description+'&grant_id='+grant_id+'&status='+status+'&delete='+delete_it,{onSuccess:handlerFunc, asynchronous:true});

}

// ####################################################
// ############### grant functions : end
// ####################################################




// ####################################################
// ############### news functions : begin
// ####################################################

// ## EDIT NEWS LINK
// ## Actually Turn on/off 'edit' links
function editNewsLink(id,task){
	if (task == "disable"){
	    $$('a.editNewsLink').each(Element.hide)
		document.getElementById(id).style.display = "";
	} else if (task == "enable"){
		 $$('a.editNewsLink').each(Element.show)
	}
}

// ## EDIT NEWS LOAD
// ## Turn on/off 'edit' links and Loads the Edit Form
function editNewsLoad(id){
	
	var value = "";
	var which = document.getElementById("editNewsDiv_"+id).style.display;
	
	if (which == "none"){
		hideDivAJAX("editNewsDiv_"+id);
		editNewsLink('editNewsLink_'+id,'disable');
	} else {
		//document.getElementById("editStaffDiv_"+id).style.display = "none"; // nonAJAX
		//setTimeout("Effect.BlindUp(editStaffDiv_"+id+");", 1000); // AJAX
		hideDivAJAX("editNewsDiv_"+id);
		editNewsLink('editNewsLink_'+id,'enable');
	}

	new Ajax.Updater('editNewsDiv_'+id, '../global/includes/functions.php?task=load_editNewsForm&news_id='+id, {asynchronous:true});
}

// ## EDIT NEWS
// ## Open/Close panels, turn on/off 'edit' links, and reload list
function editNews(id,id2){
	afterTask('taskInfo',id2);
	hideDivAJAX("editNewsDiv_"+id);
	editNewsLink('editNewsLink_'+id,'enable');

	new Ajax.Updater('newsList', '/global/includes/functions.php?task=reloadNews', {asynchronous:true});
		
}

// ## ADD NEWS
// ## Open/Close panels and reload list
function addNews(){
	afterTask('taskInfo','news added!');
	hideDivAJAX('addNewsDiv');
	
	new Ajax.Updater('newsList', '/global/includes/functions.php?task=reloadNews', {asynchronous:true});
		
}

// ####################################################
// ############### news functions : end
// ####################################################



// ####################################################
// ############### projects functions : begin
// ####################################################

// ## EDIT PROJECT LINK
// ## Actually Turn on/off 'edit' links
function editProjectLink(id,task){
	if (task == "disable"){
	    $$('a.editProjectLink').each(Element.hide)
		document.getElementById(id).style.display = "";
	} else if (task == "enable"){
		 $$('a.editProjectLink').each(Element.show)
	}
}

// ## EDIT PROJECT LOAD
// ## Turn on/off 'edit' links and Loads the Edit Form
function editProjectLoad(id){
	//alert(id);
	var value = "";
	var which = document.getElementById("editProjectDiv_"+id).style.display;
	
	if (which == "none"){
		hideDivAJAX("editProjectDiv_"+id);
		editProjectLink('editProjectLink_'+id,'disable');
	} else {
		hideDivAJAX("editProjectDiv_"+id);
		editProjectLink('editProjectLink_'+id,'enable');
	}

	new Ajax.Updater('editProjectDiv_'+id, '../global/includes/functions.php?task=load_editProjectForm&project_id='+id, {asynchronous:true});
}

// ## EDIT PROJECT
// ## Open/Close panels, turn on/off 'edit' links, and reload list
function editProject(id,id2){
	afterTask('taskInfo',id2);
	hideDivAJAX("editProjectDiv_"+id);
	editProjectLink('editProjectLink_'+id,'enable');

	new Ajax.Updater('projectsList', '/global/includes/functions.php?task=reloadProjects', {asynchronous:true});
		
}

// ## ADD PROJECT
// ## Open/Close panels and reload list
function addProject(){
	afterTask('taskInfo','project added!');
	hideDivAJAX('addProjectDiv');
	
	new Ajax.Updater('projectsList', '/global/includes/functions.php?task=reloadProjects', {asynchronous:true});
		
}

// ## CHANGE PLACEMENT PROJECT
// ## Manipulate Drop downs and Reload List
function changePlacementProject(id,id2){
	var thePlacement = document.getElementById(id).value;	
	var theProjectId = id2;	
	
	
	var handlerFunc = function(t) {
		
		// when response "placement_updated" is returned, render list
		var theResponse = trim(t.responseText);
		if (theResponse == "placement_updated"){
	   		new Ajax.Updater('projectsList', '../global/includes/functions.php?task=reloadProjects', {asynchronous:true});
			
		} else {
			alert('error');
			//document.getElementById('taskStatus').innerHTML = "Something went wrong!";
		}
				
	}
		
	new Ajax.Request('../global/includes/functions.php?task=editProjectPlacement&project_id='+theProjectId+'&placement='+thePlacement,{onSuccess:handlerFunc, asynchronous:true});
}

// ####################################################
// ############### projects functions : end
// ####################################################


// ####################################################
// ############### kgroup functions : begin
// ####################################################



// ## ADD MEETING
// ## Open/Close panels and reload list
function editFile(id){

		var handlerFunc = function(t) {
		
			// when response "contact_added" is returned, render list
			var theResponse = trim(t.responseText);
			if (theResponse == "file_edited"){
		   		//alert(theResponse);
				document.getElementById('taskStatus').innerHTML = "File edited!";
				var t=setTimeout("clearValues('taskInfo');",2500)
				hideDiv(id);
				new Ajax.Updater('fileList', '../global/includes/functions.php?task=reloadFiles', {asynchronous:true});
				
			} else if (theResponse == "file_deleted"){
		   		hideDiv(id);
				new Ajax.Updater('fileList', '../global/includes/functions.php?task=reloadFiles', {asynchronous:true});
				
			} else {
				//alert('error');
				document.getElementById('taskStatus').innerHTML = "Something went wrong!";
			}
			
		}
		
		var description = document.getElementById('editForm_description').value;
		description = description.replace(/&/g, "%26");
		var file_id = document.getElementById('editForm_fileId').value;
		//alert(date);
		//alert(description);
		//alert(file_id);
		var delete_it = document.getElementById('editForm_delete').checked;
		//alert(delete_it);
		
		new Ajax.Request('../global/includes/functions.php?task=editFile&file_id='+file_id+'&description='+description+'&delete='+delete_it,{onSuccess:handlerFunc, asynchronous:true});

}


// ## EDIT FILE LINK
// ## Actually Turn on/off 'edit' links
function editFileLink(id,task){
	if (task == "disable"){
	    $$('a.editFileLink').each(Element.hide)
		document.getElementById(id).style.display = "";
	} else if (task == "enable"){
		 $$('a.editFileLink').each(Element.show)
	}
}

// ## EDIT FILE LOAD
// ## Turn on/off 'edit' links and Loads the Edit Form
function editFileLoad(id){
	
	var value = "";
	var which = document.getElementById("editFileDiv_"+id).style.display;
	
	if (which == "none"){
		hideDivAJAX("editFileDiv_"+id);
		editFileLink('editFileLink_'+id,'disable');
	} else {
		//document.getElementById("editStaffDiv_"+id).style.display = "none"; // nonAJAX
		//setTimeout("Effect.BlindUp(editStaffDiv_"+id+");", 1000); // AJAX
		hideDivAJAX("editFileDiv_"+id);
		editFileLink('editFileLink_'+id,'enable');
	}


	new Ajax.Updater('editFileDiv_'+id, '../global/includes/functions.php?task=load_editFileForm&file_id='+id, {asynchronous:true});
}

// ## ADD FILES LOAD
// ## Loads the Add Files Form
function addFilesLoad(id){
	
	var value = "";
	var which = document.getElementById("addFileDiv").style.display;
	
	if (which == "none"){
		hideDivAJAX("addFileDiv");
		//editMeetingLink('editMeetingLink_'+id,'disable');
	} else {
		//document.getElementById("editStaffDiv_"+id).style.display = "none"; // nonAJAX
		//setTimeout("Effect.BlindUp(editStaffDiv_"+id+");", 1000); // AJAX
		hideDivAJAX("addFileDiv");
		//editMeetingLink('editMeetingLink_'+id,'enable');
	}


	new Ajax.Updater('addFileDiv', '../global/includes/functions.php?task=load_addFilesForm&file_id='+id, {asynchronous:true});
}


function reloadFiles(){

	new Ajax.Updater('fileList', '../global/includes/functions.php?task=reloadFiles', {asynchronous:true});

}

function openFile(id){
	
	// center the popup
	var topUCSC = "500";
	var leftUCSC = "800";
	var browserTopUCSC = (document.body.clientHeight - topUCSC) / 2;
	var browserLeftUCSC = (document.body.clientWidth - leftUCSC) / 2;
	var theLeftUCSC = browserLeftUCSC;
	var theTopUCSC  = browserTopUCSC;
	
	// spawn popup
	//fileWindow=window.open("../kgroup/files/"+id,"openFile",'top=0,left=0,width=500,height=500,resizable=yes,scrollbars=yes,status=no');
	fileWindow=window.open("../kgroup/files/"+id,"openFile","left="+theLeftUCSC+"top="+theTopUCSC+",width=800,height=500,location=yes,resizable=yes,scrollbars=yes,status=yes,menubar=yes,titlebar=yes,toolbar=no");
	fileWindow.focus();

}
// ####################################################
// ############### kgroup functions : end
// ####################################################


// ####################################################
// ############### emp functions : begin
// ####################################################

// ## EDIT Emp LINK
// ## Actually Turn on/off 'edit' links
function editEmpLink(id,task){
	if (task == "disable"){
	    $$('a.editEmpLink').each(Element.hide)
		document.getElementById(id).style.display = "";
	} else if (task == "enable"){
		 $$('a.editEmpLink').each(Element.show)
	}
}

// ## EDIT Emp LOAD
// ## Turn on/off 'edit' links and Loads the Edit Form
function editEmpLoad(id){
	
	var value = "";
	var which = document.getElementById("editEmpDiv_"+id).style.display;
	
	if (which == "none"){
		hideDivAJAX("editEmpDiv_"+id);
		editEmpLink('editEmpLink_'+id,'disable');
	} else {
		//document.getElementById("editStaffDiv_"+id).style.display = "none"; // nonAJAX
		//setTimeout("Effect.BlindUp(editStaffDiv_"+id+");", 1000); // AJAX
		hideDivAJAX("editEmpDiv_"+id);
		editEmpLink('editEmpLink_'+id,'enable');
	}

	new Ajax.Updater('editEmpDiv_'+id, '../global/includes/functions.php?task=load_editEmpForm&emp_id='+id, {asynchronous:true});
}

// ## EDIT EMP
// ## Open/Close panels, turn on/off 'edit' links, and reload list
function editEmp(id,id2){
	afterTask('taskInfo',id2);
	hideDivAJAX("editEmpDiv_"+id);
	editEmpLink('editEmpLink_'+id,'enable');

	new Ajax.Updater('empList', '/global/includes/functions.php?task=reloadEmp', {asynchronous:true});
		
}

// ## ADD EMP
// ## Open/Close panels and reload list
function addEmp(){
	afterTask('taskInfo','emp added!');
	hideDivAJAX('addEmpDiv');
	
	new Ajax.Updater('empList', '/global/includes/functions.php?task=reloadEmp', {asynchronous:true});
		
}

// ####################################################
// ############### emp functions : end
// ####################################################
