//ROLL OVER FUNCTIONS FOR LIST TABLES
// holder for init state
var inited = 0;
var firstInPeople = 0;
rowColors = new Array();
tables = new Array();
var rowHighlightColor = "#FFFFAA";
var columnHighlightColor = "#EFEAE7";
var cellHighlightColor = "#EAEA9C";
var rowSelectedColor = "#FFFF66";
var columnSelectedColor = "#EDE0C2";
var lightBox;

document.observe('dom:loaded', function () {  lightBox = new Lightbox(); });

// sets the roll off and click off colors to the current background colors of the table, allows you to update style of table without having to worry about roll off color not matching
function init_edit_Colors( originalCellOneColor, originalRowColor ){
	if (inited == 0){
		inited = 1;
		cellonedefColor = originalCellOneColor;
		rowdefaultColor = originalRowColor;
	}
}
// assigns titles to each cell of a table based on the inner text of column header
function init_edit_titles(thisTable){
	this_row = thisTable.rows;
	titles = this_row[0].cells;
	var i = 1;
	while (this_row[i]){
		current_cells = this_row[i].cells;
		j = 0;
		while (current_cells[j]){
			if(titles[j].innerText != ' '){
				current_cells[j].title = titles[j].innerHTML;
			}
			j++;
		}
		i++;
	}
}

function editListBoxClickToggle(myRow, title, cubeid) {
	e = Event;
	var tgt = e.target || e.srcElement;
	var clickedElement;
	if (tgt) {
		clickedElement = tgt.nodeName;
	}
	if ((clickedElement != 'A') && (clickedElement != 'INPUT') && (clickedElement != 'SELECT')) {
		if(myRow.rowIndex != 0){
			alert('Add/edit team members in people tab below');
		} 
	}
}  
	
//add these to cells by doing a javascript add listener event thing
function editListBoxRollOn(myRow){
			myRowCells = myRow.childNodes;
			i=0;
			while(myRowCells[i]){
				if(myRowCells[i].innerHTML != undefined){
					myRowCells[i].style.backgroundColor = rowHighlightColor;
				}
				i++;
			}
			
}
function editListBoxRollOff(myRow){	
			//alert(myRow.parentNode.parentNode.innerHTML);
			myRowCells = myRow.childNodes;
			i=0;			
			while(myRowCells[i]){	
				if(myRowCells[i].innerHTML != undefined){
					myRowCells[i].style.backgroundColor = '#FFFFFF';
				}
				i++;
			}	
}

function init_edit_table(thisTable){
	//init_titles(thisTable);
	var tableRows = thisTable.childNodes;
	i=1;
	while(tableRows[i]){
		rowCells = tableRows[i].childNodes;
		j=0;
		while(rowCells[j]){
			if (navigator.appName == "Microsoft Internet Explorer"){
				rowCells[j].onmouseover = function(){editListBoxRollOn(this)};
				rowCells[j].onmouseout = function(){editListBoxRollOff(this)};
				rowCells[j].onclick = function(){editListBoxClickToggle(this, event)};
			} else {
				rowCells[j].addEventListener('mouseover',function(){editListBoxRollOn(this)},false);
				rowCells[j].addEventListener('mouseout',function(){editListBoxRollOff(this)},false);
				rowCells[j].addEventListener('click',function(event){editListBoxClickToggle(this, event)},false);
			}
			j++;
		}
		i++;
	}
}

var myAjax = '';

	function doSubmit(cube1,cube2){
			var pars='';		
			var checked = false;	
			for(i=0; i<document.editForm.role.length; i++){
	    		if(document.editForm.role[i].checked){
	    			role = document.editForm.role[i].value;
	    			checked = true;
	    			break;
	    		}
	    	}
	    	if(!checked){
	    		alert('Please select a role');
	    		return false;
	    	}else{
	    		if(role == 'no note'){	    			
	    			pars += 'cubeid1='+cube1+'&cubeid2='+cube2+'&action=noNote';
					myAjax = new Ajax.Updater('lightboxImage', 'edit_link.php', {method: 'post', parameters: pars, evalScripts: true, insertion:Insertion.Replace });//this.imageArray[this.activeImage][0];
	    		}else{
		    		if(role == 'Other'){	    	
		    			var role_name = document.editForm.role_name.value;		
		    			if((role_name == 'input person\'s role') || (role_name == '')){
		    				alert('Please enter the other role name in the text field');
		    				return false;
		    			}else{
		    				role = document.editForm.role_name.value;
		    			}
		    		}	 
		    		pars += 'role='+role+'&cubeid1='+cube1+'&cubeid2='+cube2;
					myAjax = new Ajax.Updater('lightboxImage', 'addPeople.php', {method: 'post', parameters: pars, evalScripts: true, insertion:Insertion.Replace });//this.imageArray[this.activeImage][0];
	    		}
	    	}							
	}
	
	function reloadPage(){
		lightBox.end();
		location.reload();	
	}
	
	
	function editPeople(cubeid, parent){
		var pars='cubeid='+cubeid+'&action=editPeople';
		var tab = document.getElementById('linkingtab');
		
		myRowCells = tab.childNodes;
			i=0;			
			while(myRowCells[i]){	
				if(myRowCells[i].innerHTML != undefined){
					myRowCells[i].style.backgroundColor = '#FFFFFF';
				}
				i++;
			}	
				
					tab.onclick = doNothing;
					tab.onmouseover = doNothing;
					tab.onmousemove = doNothing;
					tab.onmouseout = doNothing;	
					
				if (navigator.appName != "Microsoft Internet Explorer"){
					if(firstInPeople == 0){
						tab.removeEventListener('click',editPeople, false);
						tab.removeEventListener('mouseover',editListBoxRollOn, false);
						tab.removeEventListener('mousemove',showTip, false);
						tab.removeEventListener('mouseout',editListBoxRollOff, false);
						firstInPeople = 1;
					}else{
						tab.removeEventListener('click',tabEvent1, false);
						tab.removeEventListener('mouseover',tabEvent2, false);
						tab.removeEventListener('mousemove',tabEvent3, false);
						tab.removeEventListener('mouseout',tabEvent4, false);
					}	
				}
		myAjax = new Ajax.Updater('lightboxImage', 'ajaxedit.php', {method: 'post', parameters: pars, evalScripts: true, onComplete:togglePeopleTab(), insertion: Insertion.Replace });
	}	
	
	function togglePeopleTab(){	
		location.reload();
		/*hideTip();
		var tab = document.getElementById('linkingpeople');
		tab.style.background = '#FFFFFF';
		tab.onclick = "doNothing()";
		tab.onmousemove = "doNothing()";
		tab.onmouseout = "doNothing()";		*/
	}
	
	function hideDiv(){
			document.getElementById('message').style.display = 'none';
		}
		
	function doNothing(){
	
	}
	function confirmRemove(cube1,cube2){
		//LightboxOptions.flowCount = 0;
		lightBox.start('addPeople.php', 'Warning', ['300', '200'], ['cubeid1='+cube1, 'cubeid2='+cube2, 'action=confirmDelete']);			
	}
	
	function doRemove(cube1,cube2){		
		//alert(cube1);
		//alert(cube2);
		var pars='';
		pars += 'cubeid1='+cube1+'&cubeid2='+cube2+'&action=delete';		
		myAjax = new Ajax.Updater('lightboxImage', 'addPeople.php', {method: 'post', parameters: pars, evalScripts: true, onComplete:togglePeopleTab(), insertion: Insertion.Replace });		
	}
	
	function doRemoveSelf(cube1,cube2){
		lightBox.start('addPeople.php', 'Remove self from Project', ['350', '225'], ['cubeid1='+cube1, 'cubeid2='+cube2, 'action=deleteSelf']);
		//myAjax = new Ajax.Updater('linkingpeople', 'addPeople.php', {method: 'post', parameters: pars, evalScripts: true, onComplete:togglePeopleTab(), insertion: Insertion.Replace });		
	}
	
	function doRemoveLast(cube1,cube2){
		lightBox.start('addPeople.php', 'Warning', ['300', '200'], ['cubeid1='+cube1, 'cubeid2='+cube2, 'action=deleteLast']);
		//myAjax = new Ajax.Updater('linkingpeople', 'addPeople.php', {method: 'post', parameters: pars, evalScripts: true, onComplete:togglePeopleTab(), insertion: Insertion.Replace });		
	}
	
	addRole = function(cubeid1, cubeid2, currentrole){
		LightboxOptions.flowCount = 0;
		lightBox.start('addPeople.php', 'Relationship', ['400', '325'], ['cubeid1='+cubeid1, 'cubeid2='+cubeid2, 'action=addRole', 'currentrole='+currentrole]);
	}
	
	addRoleNoSkip = function(cubeid1, cubeid2, start, title){
		if(start == 'start'){
			lightBox.start('addPeople.php', title, ['400', '325'], ['cubeid1='+cubeid1, 'cubeid2='+cubeid2, 'noskip=true', 'action=addRole']);
		}else{
			lightBox.activeImage++;
			lightBox.showBox('addPeople.php', lightBox.activeImage, title, ['400', '325'], ['cubeid1='+cubeid1, 'cubeid2='+cubeid2, 'noskip=true', 'action=addRole']);
		}
	}
	
	function togglecheckbox(obj){   
    	for(i=0; i<document.editForm.role.length; i++){
    		if(document.editForm.role[i] != obj){
    			document.editForm.role[i].checked = false;
    		}
    	}
	}
	
	function doSkip(){
		//pars = 'clear=true&action=end';
		//new Ajax.Request('edit_link.php', {method: 'post', parameters: pars});
		lightBox.end();
	}
	
	function updateHidden(text, li)
	{    
	    document.getElementById('person_id').value = li.id;
	    var cubeid =  document.getElementById('sourcecube').value;
	    document.getElementById('autocomplete').onkeypress = addPeople(cubeid);
	} 	
	
	function startLinking(text, li)
	{    
	    document.getElementById('person_id').value = li.id;
	    var cubeid =  document.getElementById('sourcecube').value;
	    var relation = document.getElementById('relation').value;
	    var type = document.getElementById('type').value;
	    //document.getElementById('autocomplete').onkeypress = 'addRelation(\''+cubeid+'\',\''+ relation+'\',\''+ type+'\')';
	    document.getElementById('autocomplete').onkeypress = addRelation(cubeid, relation, type);
	} 		
	
	function doAutoComplete(){
		
	}
	
	function addPeople(cubeid1){
		name = document.getElementById('autocomplete').value;
		if(name == ''){
			alert('Please enter a valid name');
		}else{
			//LightboxOptions.flowCount = 4;
			lightBox.start('addPeople.php', 'Link People to Project', ['400', '325'],['cubeid1='+cubeid1, 'name='+name, 'action=doConfirm']);
		}
	}
	
	function addRelation(cubeid1, relation, type, fieldname){
		if(fieldname == '' ||fieldname == undefined){
			fieldname = 'autocomplete';
		}
		name = document.getElementById(fieldname).value;
		if(name == ''){
			alert('Please enter a valid name');
		}else{
			if(fieldname != 'cube_search'){
				//LightboxOptions.flowCount = 3;
				lightBox.start('edit_link.php', LightboxOptions.title, ['400', '325'],['cubeid1='+cubeid1, 'name='+name, 'relation='+relation, 'type='+type, 'action=doConfirm']);
			}else{
				lightBox.activeImage++;
				lightBox.showBox('edit_link.php',lightBox.activeImage, LightboxOptions.title, ['400', '325'],['cubeid1='+cubeid1, 'name='+name, 'relation='+relation, 'type='+type, 'action=doConfirm']);
			}
		}
	}
	
	function addProjectToCommunity(cubeid1, relation, type){
		name = "";
		project = document.getElementsByName('project');
		for(i=0;i<project.length;i++){
			if(project[i].checked){
				name = project[i].value;
				break;
			}
		}
		if(name == ""){
			alert('Please select a project');
		}else{			
			lightBox.showBox('edit_link.php',lightBox.activeImage, LightboxOptions.title, ['400', '325'],['cubeid1='+cubeid1, 'name='+name, 'relation='+relation, 'type='+type, 'action=doConfirm']);
		}
		
		
	}
	
	function createRelation(cubeid1, cubeid2, relation){
		lightBox.activeImage++;		
		lightBox.showBox('edit_link.php', lightBox.activeImage , LightboxOptions.title, ['400', '325'],['cubeid1='+cubeid1, 'cubeid2='+cubeid2, 'relation='+relation, 'action=addRelation']);
	}
	
	function editRelation(cubeid1, cubeid2, relation){
		//LightboxOptions.flowCount = 2;
		lightBox.start('edit_link.php', '', ['400', '400'],['cubeid1='+cubeid1, 'cubeid2='+cubeid2, 'relation='+relation, 'action=editRelation']);
	}
	
	function addPeopleOnEnter(cubeid1,event){	
		var keycode = event.keyCode;	
		
		enterKey = 13;
		
        var key = String.fromCharCode(keycode).toLowerCase();
        
        if ((keycode == enterKey)){ // close lightbox
			name = document.getElementById('autocomplete').value;
			if(name == ''){
				alert('Please enter a valid name');
			}else{
				lightBox.start('addPeople.php', 'Add People to Project', ['400', '325'],['cubeid1='+cubeid1, 'name='+name, 'action=addRole']);
			}
        }
	}
	
	function afterConfirmation(cubeid1, relation, type){
		cubeid2 = '';
		cube2 = document.getElementsByName('cube2');
		if(cube2.length == 1){
			cubeid2 = document.relationForm.cube2.value;
		}else{
			for (i=0;i<cube2.length; i++){
					if(cube2[i].checked){
						cubeid2 = cube2[i].value;
						break;
					}
				}
		}
		if(type=='organization'){
			title = 'Add New community to OPDB'
		}else{
			title = 'Add New '+type+' to OPDB';
		}
		if(cubeid2 == ''){
			alert('Please select a cube to be linked!');
		}else{
			if(cubeid2 == 'new'){
				lightBox.activeImage++;
				lightBox.showBox('edit_link.php', lightBox.activeImage, title, ['400', '325'],['cubeid1='+cubeid1,'first_name='+'','relation='+relation, 'type='+type,'action=addCube']);	
				return;
			}else if(relation=='resource'){
				lightBox.activeImage++;
				lightBox.showBox('edit_link.php', lightBox.activeImage, LightboxOptions.title, ['400', '325'],['cubeid1='+cubeid1, 'cubeid2='+cubeid2, 'relation='+relation, 'action=noNote']);
			}else{
				lightBox.activeImage++;
				if(relation == 'author' || (type=='person' && relation == 'affiliated')){
					//lightBox.imageArray.push(['addPeople.php', 'Warning',['375', '250'],['cubeid1='+cubeid1, 'cubeid2='+cubeid2, 'relation='+relation, 'action=relationExists']]);
					lightBox.showBox('addPeople.php', lightBox.activeImage, LightboxOptions.title, ['400', '325'],['cubeid1='+cubeid1, 'cubeid2='+cubeid2, 'relation='+relation, 'action=relationExists']);		
				}else{
					//lightBox.imageArray.push(['edit_link.php', 'Warning',['375', '250'],['cubeid1='+cubeid1, 'cubeid2='+cubeid2, 'relation='+relation, 'action=relationExists']]);
					lightBox.showBox('edit_link.php', lightBox.activeImage, LightboxOptions.title, ['400', '325'],['cubeid1='+cubeid1, 'cubeid2='+cubeid2, 'relation='+relation, 'action=relationExists']);
				}
			}		
		}		
	}
	
	function invitePeople(cubeid1){		
		lightBox.start('addPeople.php', 'Add New Person to OPDB', ['400', '325'], ['cubeid1='+cubeid1, 'action=addPeople']);
	}
	
	function addCube(cubeid1, type, relation){	
		//LightboxOptions.flowCount = 4;
		title = 'Add a linked ';
		if(type == 'organization'){
			title += 'community';
		}else{
			title += type;
		}
		lightBox.start('edit_link.php', title, ['400', '325'], ['cubeid1='+cubeid1, 'type='+type, 'relation='+relation, 'action=searchCube']);
	}
	
	function addNewCube(cubeid1, relation, type,cube_name){			
			if(cube_name == ''|| cube_name == undefined){
				cube_name = document.getElementById('cube_search').value;
			}
			//LightboxOptions.flowCount = 4;
			lightBox.activeImage++;
			if(type=='organization'){
				title = 'Add New community to OPDB';
			}else{
				title = 'Add New '+type+' to OPDB';
			}
			lightBox.showBox('edit_link.php', lightBox.activeImage , title, ['400', '325'],['cubeid1='+cubeid1,'first_name='+cube_name,'relation='+relation, 'type='+type,'action=addCube']);		
	}
	
	function sendInvite(cubeid1, relation){
		var pars='';	
		var flag = true;			
	    var first_name = document.addForm.first_name.value;		
	    if((first_name == 'input person\'s role') || (first_name == '')){
	    	alert('Please enter the first name');
	    	flag = false;
	   }
	    var last_name = document.addForm.last_name.value;	
	    var email = document.addForm.email.value;	
	    emailRe = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.\w+([\.-]?\w+)*$/
	   if(flag && ((email == 'input person\'s role') || (email == '') || (!emailRe.test(email)))){
	    	alert('Please enter a valid email');
	    	flag = false;
	   }
	   if(flag){	    	
    		pars += 'cubeid1='+cubeid1+'&first_name='+first_name+'&last_name='+last_name+'&email='+email+'&action=createEmail&relation='+relation;			
			lightBox.activeImage++;							
			lightBox.showBox('addPeople.php', lightBox.activeImage , LightboxOptions.title, ['400', '325'],['cubeid1='+cubeid1, 'first_name='+first_name, 'last_name='+last_name, 'email='+email, 'relation='+relation, 'action=createEmail']);
			//myAjax = new Ajax.Updater(lightBox.lightboxImage, 'addPeople.php', {method: 'post', parameters: pars, insertion: Insertion.Replace});//this.imageArray[this.activeImage][0];
	   }						
	}
	
	function doSendEmail(cubeid1, cubeid2, relation){
		lightBox.activeImage++;
		cc_me='no';
		msg = '';
		cc_obj = document.getElementById('cc_me');
		if(cc_obj.checked){
			cc_me='yes';
		}
		msg_obj = document.getElementById('personal_msg');
		if(msg_obj != '' && msg_obj != 'Add a personal note (optional)'){
			msg = msg_obj.value;
		}
		lightBox.showBox('addPeople.php', lightBox.activeImage, LightboxOptions.title, ['400', '325'],['cubeid1='+cubeid1,'cubeid2='+cubeid2,'action=sendEmail','relation='+relation, 'cc_me='+cc_me, 'personal_msg='+encodeURIComponent(msg)]);		
	}
	
	function updateViewPermission(cube1, cube2, obj){
		var pars='';
		if(obj.checked){			
			pars += 'cubeid1='+cube1+'&cubeid2='+cube2+'&action=view';		
			myAjax = new Ajax.Updater('lightboxImage', 'addPeople.php', {method: 'post', parameters: pars, evalScripts: true, onComplete:togglePeopleTab(), insertion: Insertion.Replace });	
		}else{
			pars += 'cubeid1='+cube1+'&cubeid2='+cube2+'&action=revokeview';		
			myAjax = new Ajax.Updater('lightboxImage', 'addPeople.php', {method: 'post', parameters: pars, evalScripts: true, onComplete:togglePeopleTab(), insertion: Insertion.Replace });
		}		
	}
	
	function updateEditPermission(cube1, cube2, obj){
		var pars='';
		if(obj.checked){			
			pars += 'cubeid1='+cube1+'&cubeid2='+cube2+'&action=edit';		
			myAjax = new Ajax.Updater('lightboxImage', 'addPeople.php', {method: 'post', parameters: pars, evalScripts: true, onComplete:togglePeopleTab(), insertion: Insertion.Replace });	
		}else{
			pars += 'cubeid1='+cube1+'&cubeid2='+cube2+'&action=revokeedit';		
			myAjax = new Ajax.Updater('lightboxImage', 'addPeople.php', {method: 'post', parameters: pars, evalScripts: true, onComplete:togglePeopleTab(), insertion: Insertion.Replace });
		}	
	}
	
	function doConfirmEdit(cube1, cube2, obj){
		if(confirm('You are about to change your own role')){
			updateEditPermission(cube1, cube2, obj);
		}else{
			if(obj.checked){
				obj.checked = false;
			}else{
				obj.checked = true;
			}	
		}
	}
	
	function doConfirmView(cube1, cube2, obj){
		if(confirm('You are about to change your own role')){
			updateViewPermission(cube1, cube2, obj);
		}else{
			if(obj.checked){
				obj.checked = false;
			}else{
				obj.checked = true;
			}			
		}
	}
	
	function stopEditing(cubeid, parent){
		var pars='cubeid='+cubeid+'&action=stopEdit';		
		myAjax = new Ajax.Updater('lightboxImage', 'ajaxedit.php', {method: 'post', parameters: pars, evalScripts: true, onComplete: toggleNormal(cubeid), insertion: Insertion.Replace });
	}	
	
	function toggleNormal(cubeid){
		var tab = document.getElementById('linkingtab');		
		var tabColumn = document.getElementById('linkingpeople');
		
		myRowCells = tab.childNodes;
			i=0;			
			while(myRowCells[i]){	
				if(myRowCells[i].innerHTML != undefined){
					myRowCells[i].style.backgroundColor = '#FFFFFF';
				}
				i++;
			}	
			if (navigator.appName == "Microsoft Internet Explorer"){
				tab.onmouseover = function(){editListBoxRollOn(this);};
				tab.onmousemove = function(){showTip(event,'Click to add/edit people connected to this project'); };				
				tab.onmouseout = function(){editListBoxRollOff(this);hideTip(); };
				tab.onclick = function(){editPeople(cubeid)};
			} else {
				tab.addEventListener('click',tabEvent1=function(event){ editPeople(cubeid);}, false);
				tab.addEventListener('mouseover',tabEvent2=function(event){ editListBoxRollOn(this);}, false);
				tab.addEventListener('mousemove',tabEvent3=function(event){ showTip(event,'Click to add/edit people connected to this project'); }, false);
				tab.addEventListener('mouseout',tabEvent4=function (event){ editListBoxRollOff(this);hideTip(); }, false);
			}				
	}
	
	function showMore(cubeid){
		var pars='cubeid='+cubeid+'&action=showMore';
		myAjax = new Ajax.Updater('infoTable', 'ajaxedit.php', {method: 'post', parameters: pars, evalScripts: true, insertion: Insertion.Replace });
	}
	
	function hideFields(cubeid){
		var pars='cubeid='+cubeid+'&action=hide';
		myAjax = new Ajax.Updater('infoTable', 'ajaxedit.php', {method: 'post', parameters: pars, evalScripts: true, insertion: Insertion.Replace });
	}
	
	function doEdit(cubeid, id, title, showMore){
		var pars='cubeid='+cubeid+'&action=editMode&id='+id+'&title='+encodeURIComponent(title)+'&showMore='+showMore;
		myAjax = new Ajax.Updater(id,'ajaxedit.php', {method: 'post', parameters: pars, evalScripts: true, insertion: Insertion.Replace });
	}
	
	function doSave(cubeid, editField, title, showMore){
		if (navigator.appName != "Microsoft Internet Explorer"){
			editField = document.getElementById('editField');	
			title = document.getElementById('title').value;
		}		
		paramName =  editField.name;
		paramValue = editField.value;		
		pars = 'cubeid='+cubeid+'&paramName='+encodeURIComponent(paramName)+'&paramValue='+encodeURIComponent(paramValue)+'&title='+encodeURIComponent(title)+'&showMore='+showMore;
		myAjax = new Ajax.Updater(paramName, 'edit_cube.php', {method: 'post', parameters: pars, evalScripts: true, insertion: Insertion.Replace });
	}
	
	/*calendar functions*/
	
	var selectedCell = '';
	
	function highlightCalendarCell(element) {
		element.style.color = '#999999';
	}

	function resetCalendarCell(element) {
		element.style.color = '#000000';
	}
	
	function selectCalendarCell(element, cubeid, showMore) {				
		//alert(selectedCell.id+element.id);
		document.getElementById('editField').value = element.id;
		doSave(cubeid, document.getElementById('editField'), document.getElementById('title').value, showMore);
		if(selectedCell != ''){
			selectedCell.style.color = '#000000';
			if (navigator.appName == "Microsoft Internet Explorer"){
				selectedCell.onmouseover = function(){highlightCalendarCell(this);};
				selectedCell.onmouseout = function(){resetCalendarCell(this);};
				selectedCell.onclick = function(){selectCalendarCell(this);};
			}else{
				selectedCell.addEventListener('mouseover',function(){highlightCalendarCell(this);},false);
				selectedCell.addEventListener('mouseout',function(){resetCalendarCell(this);},false);		
				selectedCell.addEventListener('click',function(){selectCalendarCell(this);},false);
			}
		}
		element.onmouseover = doNothing;
		element.onmouseout = doNothing;
		element.onclick = doNothing;
		if (navigator.appName == "Microsoft Internet Explorer"){
			element.onmouseover = doNothing;
			element.onmouseout = doNothing;
			element.onclick = doNothing;
		}else{
			element.removeEventListener('mouseover',function(){highlightCalendarCell},true);
			element.removeEventListener('mouseout',function(){resetCalendarCell},true);		
			element.removeEventListener('click',function(){selectCalendarCell},true);			
		}
		selectedCell=element;
		element.style.color = '#FF3344';
	}
	
	function startCalendar(cubeid, day, month, year, showMore) {
		var arrayPageSize = getBrowsePageSize();		
		if (navigator.appName == "Microsoft Internet Explorer"){
			document.getElementById('overlay1').style.height = arrayPageSize[1] + 'px';
			document.getElementById('overlay1').style.width = arrayPageSize[0] + 'px';
			document.getElementById('overlay1').style.background = '#FFFFFF';
			document.getElementById('overlay1').onclick = function(){ doSave(cubeid, document.getElementById('editField'), document.getElementById('title').value, eval(showMore));};
		}else{
        	document.getElementById('overlay1').setStyle({ width: arrayPageSize[0] + 'px', height: arrayPageSize[1] + 'px', background: '#FFFFFF' });
			document.getElementById('overlay1').observe('click', (function(){ doSave(cubeid, document.getElementById('editField'), document.getElementById('title').value, eval(showMore));}));
		} 

       // new Effect.Appear('overlay', { duration: 0, from: 0.0, to: 0.0 });
				
		new Ajax.Updater('calendarInternal', 'calendar.php', {method: 'post', evalScripts: true, postBody: 'action=startCalendar&day='+day+'&month='+month+'&year='+year+'&cubeid='+cubeid+'&showMore='+showMore});
	}
	
	function doSaveMulti(cubeid, field1, field2, title, showMore){
		/*if (navigator.appName != "Microsoft Internet Explorer"){
			field1 = document.getElementById('field1');	
			field2 = document.getElementById('field2');	
			title = document.getElementById('title').value;
		}*/
		paramName1=field1.name;
		paramValue1='';
		if(field1.type=='select'){
			paramValue1=field1.options[field1.selectedIndex].value;
		}if(field1.type=='checkbox'){
			if(field1.checked){			
				paramValue1=field1.value;
			}
		}else{
			paramValue1=field1.value;
		}
		paramName2=field2.name;
		if(field2.type=='select'){
			paramValue2=field2.options[field2.selectedIndex].value;
		}else{
			paramValue2=field2.value;
		}
		pars = 'cubeid='+cubeid+'&paramName1='+encodeURIComponent(paramName1)+'&paramValue1='+encodeURIComponent(paramValue1)+'&paramName2='+encodeURIComponent(paramName2)+'&paramValue2='+encodeURIComponent(paramValue2)+'&title='+encodeURIComponent(title)+'&showMore='+showMore+'&action=saveMulti';
		myAjax = new Ajax.Updater(paramName2, 'edit_cube.php', {method: 'post', parameters: pars, evalScripts: true, insertion: Insertion.Replace });
	}
	
	function saveMultiOverlay(cubeid, field1, field2, showMore){
		var arrayPageSize = getBrowsePageSize();
		if (navigator.appName == "Microsoft Internet Explorer"){
			document.getElementById('overlay1').style.height = arrayPageSize[1] + 'px';
			document.getElementById('overlay1').style.width = arrayPageSize[0] + 'px';
			document.getElementById('overlay1').style.background = '#FFFFFF';
			document.getElementById('overlay1').onclick = function(event){ doSaveMulti(cubeid, document.getElementById(field1), document.getElementById(field2), document.getElementById('title').value, showMore);};
		}else{
        	document.getElementById('overlay1').setStyle({ width: arrayPageSize[0] + 'px', height: arrayPageSize[1] + 'px', background: '#FFFFFF' });
			document.getElementById('overlay1').observe('click', (function(event){ doSaveMulti(cubeid, document.getElementById(field1), document.getElementById(field2), document.getElementById('title').value, showMore);}));
		} 
	}
	
	function startOverlay(cubeid, showMore){
		var arrayPageSize = getBrowsePageSize();
		if (navigator.appName == "Microsoft Internet Explorer"){
			document.getElementById('overlay1').style.height = arrayPageSize[1] + 'px';
			document.getElementById('overlay1').style.width = arrayPageSize[0] + 'px';
			document.getElementById('overlay1').style.background = '#FFFFFF';
			document.getElementById('overlay1').onclick = function(event){ doSave(cubeid, document.getElementById('editField'), document.getElementById('title').value, showMore);};
		}else{
        	document.getElementById('overlay1').setStyle({ width: arrayPageSize[0] + 'px', height: arrayPageSize[1] + 'px',background: '#FFFFFF' });
			document.getElementById('overlay1').observe('click', (function(event){ doSave(cubeid, document.getElementById('editField'), document.getElementById('title').value, showMore);}));
		} 
	}
	
	function getBrowsePageSize() {
	        
	     var xScroll, yScroll;
		
		if (window.innerHeight && window.scrollMaxY) {
			xScroll = window.innerWidth + window.scrollMaxX;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		
		var windowWidth, windowHeight;
		
		if (self.innerHeight) {	// all except Explorer
			if(document.documentElement.clientWidth){
				windowWidth = document.documentElement.clientWidth; 
			} else {
				windowWidth = self.innerWidth;
			}
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}	
		
		// for small pages with total height less then height of the viewport
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		} else { 
			pageHeight = yScroll;
		}
	
		// for small pages with total width less then width of the viewport
		if(xScroll < windowWidth){	
			pageWidth = xScroll;		
		} else {
			pageWidth = windowWidth;
		}

		return [pageWidth,pageHeight];
	}
	
	function doSaveFlag(cubeid,obj, parent, title, showMore){
		paramName =  obj.name;
		if(obj.type=='checkbox'){
			if(obj.checked){		
				paramValue = 1;
			}else{
				paramValue = 0;
			}
		}else{
			paramValue = obj.value;
		}
		pars = 'cubeid='+cubeid+'&paramName='+encodeURIComponent(paramName)+'&paramValue='+encodeURIComponent(paramValue)+'&action=showflag&showMore='+showMore+'&parent='+parent+'&title='+encodeURIComponent(title);		
		//myAjax = new Ajax.Updater(parent, 'edit_cube.php', {method: 'post', parameters: pars, evalScripts: true, insertion: Insertion.Replace });
		myAjax = new Ajax.Request('edit_cube.php', {method: 'post', parameters: pars});
	}
	
	function editLicense(cubeid, showMore){
		lightBox.start('edit_license.php','Edit License',['500', '500'],['cubeid='+cubeid,'action=addLicense']);
	}
	
	function doSaveLicense(cubeid){
		license = document.getElementsByName('license_option');
		for(i=0;i<license.length; i++){
			if(license[i].checked){
				value =  license[i].value;
				break;
			}
		}
		pars = 'cubeid='+cubeid+'&license_option='+value+'&action=editLicense';
		myAjax = new Ajax.Updater('license', 'edit_cube.php', {method: 'post', parameters: pars, onComplete:lightBox.end()});			
	}
	
	function showWelcomeBox(){
		//LightboxOptions.flowCount = 3;			
		lightBox.start('welcomeBeta.php','Welcome to Open Project Database Beta',['400', '300'],['action=welcome']);
		lightBox.disableOverlayClick();				
	}
	
	function openFeedback(link){
		if(link){
			//LightboxOptions.flowCount = 2;	
			lightBox.start('welcomeBeta.php','Send Feedback to the OPDB Team',['400', '300'],['action=createEmail']);
		}else{		
		pars = 'action=createEmail';			
		//lightBox.imageArray = [];
		lightBox.activeImage++;
		//lightBox.imageArray.push(['welcomeBeta.php', 'E-Mail',['400', '300'],['action=createEmail']]);				
		lightBox.showBox('welcomeBeta.php',lightBox.activeImage, 'Send Feedback to the OPDB Team', ['400', '300'],['action=createEmail']);
		}			   					
	}
	
	function sendFeedBack(){
		from = document.emailForm.from.value;
		subject = document.emailForm.subject.value;
		message = document.emailForm.message.value;
		if(from == 'Enter your email'){
			from = 'anon-noreply@openprojectDB.org'
		}	
		//lightBox.imageArray = [];
		lightBox.activeImage++;
		//lightBox.imageArray.push(['welcomeBeta.php', 'Confirmation',['300', '150'],['from='+from, 'subject='+encodeURIComponent(subject), 'message='+encodeURIComponent(message), 'action=sendEmail']]);	
		lightBox.showBox('welcomeBeta.php', lightBox.activeImage, 'Confirmation', ['400', '300'],['from='+from, 'subject='+encodeURIComponent(subject), 'message='+encodeURIComponent(message), 'action=sendEmail']);
	}
	
	function doFocus(obj){
		obj.value='';
		obj.onfocus=doNothing();
	}
	
	function doUnFocus(obj,txt){	
		if(obj.value == ''){
			if (window.attachEvent) {
			    obj.attachEvent("onfocus",function(){doFocus(obj);});
			} else if (window.addEventListener) {
			    obj.addEventListener("focus",function(){doFocus(obj);},true);
			}
			obj.value=txt;
		}
	}
	
	function expandEditLine(cubeid1, cubeid2, relationship){
		pars = 'cubeid1='+cubeid1+'&cubeid2='+cubeid2+'&relationship='+relationship+'&action=expandEditLine';
		myAjax = new Ajax.Updater('link_'+cubeid2, 'edit_link.php', {method: 'post', parameters: pars});
	}
	
	function collapseEditLine(cubeid1, cubeid2, relationship, islast){
		pars = 'cubeid1='+cubeid1+'&cubeid2='+cubeid2+'&relationship='+relationship+'&action=collapseEditLine';
		myAjax = new Ajax.Updater('link_'+cubeid2, 'edit_link.php', {method: 'post', parameters: pars});
	}
	
	function expandPeopleEditLine(cubeid1, cubeid2, relationship, islast){
		pars = 'cubeid1='+cubeid1+'&cubeid2='+cubeid2+'&islast='+islast+'&relationship='+relationship+'&action=expandEditLine';
		myAjax = new Ajax.Updater('link_'+cubeid2, 'addPeople.php', {method: 'post', parameters: pars});
	}
	
	function collapsePeopleEditLine(cubeid1, cubeid2, relationship, islast){
		pars = 'cubeid1='+cubeid1+'&cubeid2='+cubeid2+'&islast='+islast+'&relationship='+relationship+'&action=collapseEditLine';
		myAjax = new Ajax.Updater('link_'+cubeid2, 'addPeople.php', {method: 'post', parameters: pars});
	}
	
	function addOrganizationNote(cubeid1, cubeid2, relation, createdas){
		obj = document.getElementsByName('addNote');
		addNote = 'yes';
		checked = false;
		for(i=0;i<obj.length;i++){
			if(obj[i].checked == true){
				addNote = obj[i].value;
				checked = true;
				break;
			}
		}

		if(checked){
		if(addNote == 'other'){
			noteField = document.getElementById('note');
			note = noteField.value;
			
			if(note == ''){
				alert('Please enter a note');
				return;
			}
			
		}else{
			note = addNote;
		}
			
			//lightBox.imageArray = [];
			lightBox.activeImage++;
			//lightBox.imageArray.push(['edit_link.php', 'Confirmation',['300', '150'],['cubeid1='+cubeid1, 'cubeid2='+cubeid2, 'relation='+relation, 'note='+note, 'action=addNote']]);	
			lightBox.showBox('edit_link.php', lightBox.activeImage, LightboxOptions.title, ['400', '325'],['cubeid1='+cubeid1, 'cubeid2='+cubeid2, 'relation='+relation, 'note='+note, 'createdas='+createdas, 'action=addNote']);
		}else{
			alert('Please select a choice'); 
		}
	}

	
	function addRelationNote(cubeid1, cubeid2, relation){
		obj = document.getElementsByName('addNote');
		addNote = 'yes';

		for(i=0;i<obj.length;i++){
			if(obj[i].checked == true){
				addNote = obj[i].value;
				break;
			}
		}

		if(addNote == 'yes'){
			noteField = document.getElementById('note');
			if(noteField.type== 'select'){
				note = noteField.options[noteField.selectedIndex].value;
			}else{
				note = noteField.value;
			}
			if(note == ''){
				alert('Please enter a note');
				return;
			}
			//lightBox.imageArray = [];
			lightBox.activeImage++;
			//lightBox.imageArray.push(['edit_link.php', 'Confirmation',['300', '150'],['cubeid1='+cubeid1, 'cubeid2='+cubeid2, 'relation='+relation, 'note='+note, 'action=addNote']]);	
			lightBox.showBox('edit_link.php', lightBox.activeImage, LightboxOptions.title, ['400', '325'],['cubeid1='+cubeid1, 'cubeid2='+cubeid2, 'relation='+relation, 'note='+note, 'action=addNote']);
		}else{
			lightBox.activeImage++;
			//lightBox.imageArray.push(['edit_link.php', 'Confirmation'], ['300', '150'],['cubeid1='+cubeid1, 'cubeid2='+cubeid2, 'relation='+relation, 'action=noNote']);	
			lightBox.showBox('edit_link.php', lightBox.activeImage, LightboxOptions.title, ['400', '325'],['cubeid1='+cubeid1, 'cubeid2='+cubeid2, 'relation='+relation, 'action=noNote']);
		}
	}
	
	function addRelationNoNote(cubeid1, cubeid2, relation){
		//lightBox.imageArray = [];
		lightBox.activeImage++;
		//lightBox.imageArray.push(['edit_link.php', 'Confirmation'], ['300', '150'],['cubeid1='+cubeid1, 'cubeid2='+cubeid2, 'relation='+relation, 'action=noNote']);	
		lightBox.showBox('edit_link.php', lightBox.activeImage, LightboxOptions.title, ['400', '325'],['cubeid1='+cubeid1, 'cubeid2='+cubeid2, 'relation='+relation, 'action=noNote']);
	}
	
	function doEndLinking(cubeid1, type){
		//lightBox.imageArray = [];
		pars = 'cubeid='+cubeid1+'&action=editLinks&type='+type;
		myAjax = new Ajax.Updater('lightboxImage', 'ajaxedit.php', {method: 'post', parameters: pars, evalScripts: true, onComplete:lightBox.end(), insertion:Insertion.Replace });
	}
	
	function createAndAddLink(cubeid1, relation, type, title){		
		if(document.addForm.name.value.length<3){
			alert("please enter a name of at least 3 characters");
			return false;
		}
		var re = /^[A-z0-9-'.'-','-'-'-' '-'_']*$/;
		if (!re.test(document.addForm.name.value)) {
			alert("Only letters, numbers, space, dots, commas, '_' and '-' characters are allowed!");			
			return false;
		}
		if(document.addForm.short_description.value.length<10){
			alert("please enter a one-line description of at least 10 characters");
			return false;
		}
		
		name = document.addForm.name.value;
		description = document.addForm.short_description.value;
		lightBox.activeImage++;
		lightBox.showBox('edit_link.php',lightBox.activeImage, title,['400', '325'],['cubeid1='+cubeid1,'relation='+relation, 'type='+type, 'name='+name, 'short_description='+encodeURIComponent(description),'action=createAddRelation']);
	}
	
	function confirmRemoveLink(cube1,cube2, relation,title){
		LightboxOptions.flowCount = 0;
		lightBox.start('edit_link.php', title, ['300', '200'], ['cubeid1='+cube1, 'cubeid2='+cube2, 'relation='+relation, 'action=confirmDelete']);			
	}
	
	function removeLink(cube1,cube2, relation){
		var pars='';
		pars += 'cubeid1='+cube1+'&cubeid2='+cube2+'&relation='+relation+'&action=deleteLink';		
		myAjax = new Ajax.Updater('lightboxImage', 'edit_link.php', {method: 'post', parameters: pars, evalScripts: true, onComplete:togglePeopleTab(),insertion: Insertion.Replace });
	}
	
	function expandSearchField(cubeid, type, relation){
		var pars='';
		pars += 'cubeid='+cubeid+'&type='+type+'&relation='+relation+'&action=createSearch';
		myAjax = new Ajax.Updater('searchField', 'ajaxedit.php', {method: 'post', parameters: pars, evalScripts: true, insertion: Insertion.Replace });
	}
	function collapseSearchField(cubeid, type, relation){
		var pars='';
		pars += 'cubeid='+cubeid+'&type='+type+'&relation='+relation+'&action=editLinks';
		myAjax = new Ajax.Updater('lightboxImage', 'ajaxedit.php', {method: 'post', parameters: pars, evalScripts: true, insertion: Insertion.Replace });
	}
	
	function unlockEdit(cubeid){
		LightboxOptions.flowCount = 0;
		lightBox.start('edit_settings.php', 'Log-in', ['400', '300'], ['cubeid='+cubeid, 'action=requestLogin']);
	}
	
	function submitLogin(cubeid){
		var pars='';
		loginuser = document.loginForm.loginuser.value;
		password = document.loginForm.loginpass.value;
		
		if(document.loginForm.rememberme.checked){
			rememberme = 'yes';
			pars = ['cubeid='+cubeid, 'loginuser='+loginuser, 'loginpass='+password, 'rememberme='+rememberme, 'action=verifyLogin'];
		}else{
			pars = ['cubeid='+cubeid, 'loginuser='+loginuser, 'loginpass='+password, 'action=verifyLogin'];
		}
		lightBox.activeImage++;
		lightBox.showBox('edit_settings.php', lightBox.activeImage, 'Log-in', ['375', '250'], pars);
	}
	
	function lockEdit(cubeid){
		pars = 'cubeid='+cubeid+'&action=lockEdit';
 		myAjax = new Ajax.Updater('access_settings', 'edit_settings.php', {method: 'post', parameters: pars, evalScripts: true, insertion: Insertion.Replace });
	}
	
	function getAccessSettings(cubeid, title){		
		lightBox.start('edit_settings.php', 'Access Settings: '+title, ['400', '325'], ['cubeid='+cubeid, 'action=accessSettings']);
	}
	
	function editVisibility(cubeid, obj){
		paramName =  obj.name;
		paramValue =  obj.value;
		pars = 'cubeid='+cubeid+'&paramName='+paramName+'&paramValue='+paramValue+'&action=editVisiblity';		
		myAjax = new Ajax.Request('edit_cube.php', {method: 'post', parameters: pars});
	} 
	
	function editPublish(cubeid, targetid, obj){
		pars = 'cubeid='+cubeid+'&action=editPublish&targetid='+targetid;
		if(obj.checked){
			paramName =  obj.name;
			paramValue =  obj.value;			
		}else{
			paramName =  obj.name;
			paramValue =  'no';
		}				
		pars += '&'+paramName+'='+paramValue;
		myAjax = new Ajax.Request('edit_cube.php', {method: 'post', parameters: pars});
	} 
	
	function aboutPublish(cubeid){
		lightBox.activeImage++;
		lightBox.showBox('edit_settings.php', lightBox.activeImage, 'About Remote Publishing', ['400', '300'], ['cubeid='+cubeid, 'action=aboutPublish']);
	}
	
	function aboutFacebook(cubeid){
		lightBox.activeImage++;
		lightBox.showBox('edit_settings.php', lightBox.activeImage, 'About OPDB Facebook App', ['400', '250'], ['cubeid='+cubeid, 'action=aboutFacebook']);
	}
	
	function selectAll(){
	
	}
	
	function unselectAll(){
	
	}
	
	function checkOnFocus(obj){
		document.getElementById('role_other').checked=true;
		//togglecheckbox(document.getElementById('role_other'));
		if(obj.value == 'input person\'s role'){
			doFocus(obj);		
		}
	}
	
	function editCalendarYear(cubeid, day, month, year, showMore){		
		 pars='action=editYear&day='+day+'&month='+month+'&year='+year+'&cubeid='+cubeid+'&showMore='+showMore;
		 myAjax = new Ajax.Updater('calendarYear', 'calendar.php', {method: 'post', parameters: pars, evalScripts: true, insertion: Insertion.Replace });
	}
	
	function doLogin(){
		//LightboxOptions.flowCount = 0;
		lightBox.start(webRoot+'auth.php', 'Log-in', ['375', '250'], ['action=requestLogin']);
	}
	
	function doVideoAnnouncement(videoId,title){
		lightBox.start('auth.php',title, ['480', '450'],['action=videoAnnouncement','videoId='+videoId]);
	}
	
	function confirmLogout(){
		lightBox.start(webRoot+'auth.php', 'Log-out', ['300', '200'], ['action=confirmLogout']);
	}
	
	function doLogout(){		
		 pars='action=logout&logout=1';
		 myAjax = new Ajax.Updater('auth', webRoot+'auth.php', {method: 'post', parameters: pars, evalScripts: true, insertion: Insertion.Replace });
	}
	
	function doAuthenticate(){
		var pars='';
		loginuser = document.login.loginuser.value;
		password = document.login.loginpass.value;
		
		if(document.login.rememberme.checked){
			rememberme = 'yes';
			pars = ['loginuser='+loginuser, 'loginpass='+password, 'rememberme='+rememberme, 'action=verifyLogin'];
		}else{
			pars = ['loginuser='+loginuser, 'loginpass='+password, 'action=verifyLogin'];
		}
		lightBox.activeImage++;
		lightBox.showBox(webRoot+'auth.php', lightBox.activeImage, 'Log-in', ['375', '250'], pars);
	}
	
	function showLicenseInfo(cubeid){
		//LightboxOptions.flowCount = 2;
		lightBox.activeImage++;
		lightBox.showBox('edit_license.php', lightBox.activeImage, 'Creative Commons Licenses', ['450', '450'], ['cubeid='+cubeid, 'action=showLicenseInfo']);
	}
	
	function showSettings(cubeid, mode){
		if(mode == 'start'){
			lightBox.start('edit_settings.php', 'Community Settings', ['400', '400'], ['cubeid='+cubeid, 'action=communitySettings']);
		}else{
			pars='cubeid='+cubeid+'&action=communitySettings';
		myAjax = new Ajax.Updater('lightboxImage', 'edit_settings.php', {method: 'post', parameters: pars, evalScripts: true, insertion:Insertion.Replace });//this.imageArray[this.activeImage][0];
		}
	}
	
	function assignNames(cubeid, mode){
		if(mode == 'start'){
			lightBox.start('edit_settings.php', 'Community Settings', ['400', '400'], ['cubeid='+cubeid, 'action=assignNames']);
		}else{
			pars='cubeid='+cubeid+'&action=assignNames';
			myAjax = new Ajax.Updater('lightboxImage', 'edit_settings.php', {method: 'post', parameters: pars, evalScripts: true, insertion:Insertion.Replace });//this.imageArray[this.activeImage][0];		
		}
	}
	
	function updateAdminId(text, li)
	{    
	    document.getElementById('admin_id').value = li.id;
	    var cubeid =  document.getElementById('sourcecube').value;
	    document.getElementById('admin_search').onkeypress = addAsAdmin(cubeid, 'admin_search');
	} 	
	
	function addAsAdmin(cubeid1, fieldname){
		cubeid2 = document.getElementById('admin_id').value;
		if(cubeid2 == ''){
			alert('Please select a name');
		}else{
			pars='cubeid='+cubeid1+'&cubeid2='+cubeid2+'&action=communitySettings&mode=addAdmin';
			myAjax = new Ajax.Updater('lightboxImage', 'edit_settings.php', {method: 'post', parameters: pars, evalScripts: true, insertion:Insertion.Replace });
		}
	}
	
	function removeAdmin(cubeid1, cubeid2){
			pars='cubeid='+cubeid1+'&cubeid2='+cubeid2+'&action=communitySettings&mode=removeAdmin';
			myAjax = new Ajax.Updater('lightboxImage', 'edit_settings.php', {method: 'post', parameters: pars, evalScripts: true, insertion:Insertion.Replace });
	}
	
	function addAssignment(cubeid){
		name = document.getElementById('assignmentName').value;	
		if(name.length>35){
			alert('Maximum characters permitted is 35!');
		}else if(name.length==0){
			alert('Please enter an assignment Name!');
		}else{
			pars='cubeid='+cubeid+'&name='+name+'&action=assignNames&mode=addAssignment';
			myAjax = new Ajax.Updater('lightboxImage', 'edit_settings.php', {method: 'post', parameters: pars, evalScripts: true, insertion:Insertion.Replace });
		}
	}
	function removeAssignment(cubeid,id){
		pars='cubeid='+cubeid+'&assignmentid='+id+'&action=assignNames&mode=removeAssignment';
		myAjax = new Ajax.Updater('lightboxImage', 'edit_settings.php', {method: 'post', parameters: pars, evalScripts: true, insertion:Insertion.Replace });
	}
	
	function unLinkPeople(cubeid1, cubeid2, relationship){
		lightBox.start('edit_link.php', 'Confirm', ['300', '200'], ['cubeid1='+cubeid1, 'cubeid2='+cubeid2, 'relationship='+relationship, 'action=confirmUnlink']);
	}
	function doUnlink(cubeid1, cubeid2, relationship){
		pars = 'cubeid1='+cubeid1+'&cubeid2='+cubeid2+'&relationship='+relationship+'&action=unlink';
		myAjax = new Ajax.Updater('lightboxImage', 'edit_link.php', {method: 'post', parameters: pars, evalScripts: true, insertion:Insertion.Replace });
	}
	function unLinkProject(cubeid1, cubeid2, relationship){
		lightBox.start('edit_link.php', 'Confirm', ['300', '200'], ['cubeid1='+cubeid1, 'cubeid2='+cubeid2, 'relationship='+relationship, 'action=confirmUnlinkProject']);
	}
	function doUnlinkProject(cubeid1, cubeid2, relationship){
		pars = 'cubeid1='+cubeid1+'&cubeid2='+cubeid2+'&relationship='+relationship+'&action=unlinkProject';
		myAjax = new Ajax.Updater('lightboxImage', 'edit_link.php', {method: 'post', parameters: pars, evalScripts: true, insertion:Insertion.Replace });
	}
	function checkTheBox(obj){
		if(obj.value != ''){
			document.getElementById('show_description').checked=true;
		}else{
			document.getElementById('show_description').checked=false;
		}
	}
	
	function createProject(){
		//LightboxOptions.flowCount = 5;
		title = "Create a new Project";
		type='project';
		lightBox.start(webRoot+'create_cube.php', title, ['400', '325'],['type='+type,'step=coverlayCreateNewCubeNameAndDescription','action=createNewCube']);
	}
	
	function createResource(){
		//LightboxOptions.flowCount = 5;
		title = "Create a new Resource";
		type='resource';
		lightBox.start(webRoot+'create_cube.php', title, ['400', '325'],['type='+type,'step=coverlayCreateNewCubeNameAndDescription','action=createNewCube']);
	}
	
	function createCommunity(){
		//LightboxOptions.flowCount = 5;
		title = "Create a new Community";
		type='organization';
		lightBox.start(webRoot+'create_cube.php', title, ['400', '325'],['type='+type,'step=coverlayCreateNewCubeNameAndDescription','action=createNewCube']);
	}
	
	function createCubeInDB(type,step){
		if(document.addForm.name.value.length<3){
			alert("please enter a name of at least 3 characters");
			return false;
		}
		/*var re = /^[A-z0-9-'.'-','-'-'-' '-'_']*$/;
		if (!re.test(document.addForm.name.value)) {
			alert("Only letters, numbers, space, dots, commas, '_' and '-' characters are allowed!");			
			return false;
		}*/
		
		if(document.addForm.short_description.type != 'select-one'){
			if(document.addForm.short_description.value.length<10){
				alert("please enter a one-line description of at least 10 characters");
				return false;
			}
		}
		
		name = document.addForm.name.value;
		if(document.addForm.short_description.type != 'select-one'){
			description = document.addForm.short_description.value;
		}else{
			description = document.addForm.short_description[document.addForm.short_description.selectedIndex].text;
		}
		lightBox.activeImage++;
		lightBox.showBox(webRoot+'create_cube.php',lightBox.activeImage, LightboxOptions.title,['400', '325'],['type='+type, 'name='+name, 'short_description='+encodeURIComponent(description),'step='+step, 'action=createNewCube']);		
	}
	
	function addCommunity(cubeid, type, relation, step){		
		lightBox.activeImage++;
		lightBox.showBox('create_cube.php',lightBox.activeImage, LightboxOptions.title, ['400', '325'],['cubeid='+cubeid, 'relation='+relation, 'type='+type, 'step='+step, 'action=createNewCube']);
	}
	
	 function handleEnter(event, cubeid){
	  event = event || window.event;             // gets the event in ie or ns
	  kCode = event.keyCode || event.which;   // gets the keycode in ie or ns

      var enterKey;
	        if (event.DOM_VK_RETURN) {  // mozilla
	           enterKey = event.DOM_VK_RETURN;
	        } else { // ie
	            enterKey = 13;
	        }
			
	        if(kCode == enterKey){
	        	submitLogin(cubeid);
	        }
	}
	
	function handleEnterAuth(event){
	  event = event || window.event;             // gets the event in ie or ns
	  kCode = event.keyCode || event.which;   // gets the keycode in ie or ns

      var enterKey;
	        if (event.DOM_VK_RETURN) {  // mozilla
	           enterKey = event.DOM_VK_RETURN;
	        } else { // ie
	            enterKey = 13;
	        }
			
	        if(kCode == enterKey){
	        	doAuthenticate();
	        }
	}
	
	function uploadCubeImage(cubeid){
		lightBox.start('imageProcessor.php', 'Upload Images', ['450', '425'], ['cubeid='+cubeid, 'action=loadUploadForm']);
	}
	
	function loadImageEditCoverlay(imageid){
		lightBox.start('imageProcessor.php', 'Edit Image', ['550', '525'], ['imageid='+imageid, 'action=loadEditImageCoverlay']);
	}
	
	function countText(obj){
		if(obj.value.length > 100){
			text = obj.value;
			obj.value = text.substr(0,100);
			//alert('You have reached the maximum character limit');			
		}else{
			document.getElementById('count').innerHTML = obj.value.length+' characters entered - 100 max';
		}
	}
	
	function doLoad(url){
		window.location = url;
	}
	
	function callCommunityPeopleTab(cubeid){
		location = 'browse.php?cubeid='+cubeid+'&stabid=1';
	}