
//var _ajaxConfig = {'_cfscriptLocation':'_code/_note/_notewrapper.cfc', '_jsscriptFolder':'_scripts/core/js'};

var _cfscriptLocation = '_code/_note/_notewrapper.cfc';
var displayPoint = '';
var processingPoint = '';
var imgProcessingPoint = '';

var called = 0;
var displayPointArray = new Array();

var k_PRIORITY_DEFAULT = 3;
	
/* GETNOTES() */
function getNotes(record, system, listName, listNameView, numberNotes, noteType, sortOrder, popUp, filterType)
{
	if (popUp == undefined)
		popUp = false;

	if (filterType == undefined || filterType == '')
		filterType = 0;
/*	
	alert('readNotes()' + '\n' +
		'record -> ' + record + '\n' +
		'system -> ' + system  + '\n' +
		'listName -> ' + listName + '\n' +
		'listNameView -> ' + listNameView + '\n' +
		'displayAmount -> ' + numberNotes + '\n' +
		'noteType -> ' + noteType + '\n' + 
		'sortOrder -> ' + sortOrder + '\n' +
		'popUp -> ' + popUp + '\n' +
		'filterType -> ' + filterType
	);
*/
	
	showWait();
	called++;

	DWREngine._execute(_cfscriptLocation, null, 'readNotes', {'record':parseInt(record), 'system':parseInt(system), 'listName':listName, 'listNameView':listNameView, 'displayAmount':numberNotes, 'popUp':popUp, 'filterType':filterType, 'number':called, 'orderBy':sortOrder}, showNotes);	
	
}		

/* ADDNOTE() */
function addNote(record, system, listName, listNameView, noteTypeEl, noteType, theNote, el, createdIn, remind, remindDate, task, taskDate, extraEl, sticky, priority, displayAmount, popUp, filterType, extraEmail)
{
	var oEditor = FCKeditorAPI.GetInstance(el);
	theNote = oEditor.GetXHTML();
	
/*	
		alert('save' + '\n' +
			'record: ' + record + '\n' +
			'system: ' + system + '\n' +
			'listName: ' + listName + '\n' +
			'noteType: ' + noteType + '\n' +
			'theNote: ' + theNote + '\n' +
			'theField: ' + el + '\n' +
			'createdIn: ' + createdIn + '\n' +
//			'extraCol: ' + extraCol + '\n' +
//			'cc: ' + cc + '\n' +
			'remind: ' + remind + '\n' +
			'remindDate: ' + remindDate + '\n' +
			'task: ' + task + '\n' +
			'taskDate: ' + taskDate + '\n' +
			'extraEl: ' + extraEl + '\n' +
			'extraContent: ' + extVal + '\n' +
			'sticky: ' + stickyVal + '\n' +
			'priority: ' + priority + '\n' +
			'displayAmount: ' + displayAmount + '\n' +
			'popUp: ' + popUp + '\n' +
			'extraEmail: ' + extraEmail
		);
*/		
	
	//check if things are blank that can't be
	//errMsg = getErrorMsg(theNote, noteType);
	errMsg = getErrorMsg(theNote, noteTypeEl);
	
	if(errMsg == '')
	{
		//theNote = theNote.replace(/<[pP][^>]*>/g, '');
		//theNote = theNote.replace(/<[pP\/][^>]*>/g, '<br />');
		theNote = theNote.replace(/<p([^>]*)>/g, '');
		theNote = theNote.replace(/<\/p([^>]*)>/g, '</br>');
				
		//var theField = document.getElementById(el);
		
		showWait();
		// clear the form field
		//theField.value = '';
		
		//if the extraVal is a multiselect, combine the values, otherwise just get the single value
		var extVal = null;
		var element = $(extraEl);
		if(element != null && typeof(element.multiple) != 'undefined')
		{
			if (element.multiple)
			{
				var box = element;
				var textToShow = '';
				for (var i = 0; i < box.options.length; i++)
				{
					if (box.options[i].selected)
					{
						if (textToShow == '')
							textToShow = box.options[i].value;
						else
							textToShow += ',' + box.options[i].value;
					}
				}
				extVal = textToShow;
			}
			else
				extVal = element.value;
		}
		else if (extVal != null)
			extVal = element.value;
			
		var stickyVal = 0;
		if (sticky != null && sticky)
			stickyVal = 1;
		//remind, task
		var remindVal = 0;
		if (remind != null && remind)
			remindVal = 1;
		var taskVal = 0;
		if (task != null && task)
			taskVal = 1;
			
		if (remindDate == undefined)
			remindDate = null;
		if (taskDate == undefined)
			taskDate = null;
			
		if (popUp == undefined)
			popUp = false;
			
		//create the display filter
		var uniqueName = listName + '_' + record +  '_' + system + '_';
		var noteFilterSelectID = uniqueName + "NoteFilter";
		var dispFilterVar = '1';

		if (popUp && window.opener && !(window.opener.$(noteFilterSelectID).value == null || window.opener.$(noteFilterSelectID).value == ''))
			dispFilterVar = window.opener.$(noteFilterSelectID).value.split('||')[1];
		else if ($(noteFilterSelectID) != null && $(noteFilterSelectID).value == '')
			dispFilterVar = $(noteFilterSelectID).value.split('||')[1];
		//create the display amount parameter
		var noteViewSelect = uniqueName + "NoteView";
		var dispAmtVar = '5';
		if (popUp && window.opener && !(window.opener.$(noteViewSelect).value == null || window.opener.$(noteViewSelect).value == ''))
			dispAmtVar = window.opener.$(noteViewSelect).value;
		else if ($(noteFilterSelectID) != null)
			dispAmtVar = $(noteViewSelect).value;
		//create the sorting parameter
		var noteSortColumn = uniqueName + 'noteSortCol';
		var noteSortDirection = uniqueName + 'noteSortDir';
		var sortVar = null
		if (popUp && window.opener && !(window.opener.$(noteSortColumn).value == null || window.opener.$(noteSortColumn).value == ''))
			sortVar = window.opener.$(noteSortColumn).value + ' ' + window.opener.$(noteSortDirection).value;
		else if ($(noteFilterSelectID) != null )
			sortVar = $(noteSortColumn).value + ' ' + $(noteSortDirection).value;
			
		DWREngine._execute(_cfscriptLocation, null, 'createNote', {'record':record, 'system':system, 'listName':listName, 'listNameView':listNameView, 'noteType':noteType, 'theNote':theNote, 'theField':el, 'createdIn':createdIn, 'extraContent':extVal, 'sticky':stickyVal, 'priority':priority, 'displayAmount':dispAmtVar, 'popUp':popUp, 'extraEmail':extraEmail,'remind':remindVal, 'remindDate':remindDate, 'task':taskVal, 'taskDate':taskDate, 'filterType':dispFilterVar}, showNoteAdded);
		
	}
	else
		alert(errMsg);
}

/* add's the note to the end of the note */
function appendNote(id, el, listName, listNameView, displayAmount, popUp, viewDelete, viewEdit)
{
	var oEditor = FCKeditorAPI.GetInstance(el);
	var theNote = oEditor.GetXHTML();
	
	errMsg = getErrorMsg(theNote);
	
	if(errMsg == '')
	{
		//var theField = document.getElementById(el);
		theNote = theNote.replace(/<p([^>]*)>/g, '');
		theNote = theNote.replace(/<\/p([^>]*)>/g, '<br />');
		
//alert('append: \n\n' + oEditor.GetXHTML() + '\n\n------------------\n\n' + theNote);
		
		showWait();
		
		if (viewDelete == undefined)
			viewDelete = false;
		if (viewEdit == undefined)
			viewEdit = false;
			
		DWREngine._execute(_cfscriptLocation, null, 'appendNote', {'id':id, 'note':theNote, 'displayAmount':displayAmount, 'listName':listName, 'listNameView':listNameView, 'popUp':popUp, 'deleteViewButton':viewDelete, 'editViewButton':viewEdit, 'complete':true, 'appendName':true, 'appendDate':true}, updateEdit);
		
	}
	else
		alert(errMsg);
}

/* UPDATENOTE() */
function updateNote(id, el, listName, listNameView, sticky, priority, displayAmount, popUp, viewDelete, viewEdit)
{//alert('updateNote');
	var oEditor = FCKeditorAPI.GetInstance(el);
	var theNote = oEditor.GetXHTML();
	
	errMsg = getErrorMsg(theNote);
	
	if(errMsg == '')
	{
		//var theField = document.getElementById(el);
		theNote = theNote.replace(/<p([^>]*)>/g, '');
		theNote = theNote.replace(/<\/p([^>]*)>/g, '<br />');
		
		showWait();
		
		var stickyVal = 0;
		if (sticky != null)
			if (sticky)
				stickyVal = 1;
				
		if (viewDelete == undefined)
			viewDelete = false;
		if (viewEdit == undefined)
			viewEdit = false;
			
		DWREngine._execute(_cfscriptLocation, null, 'updateNote', {'id':id, 'theNote':theNote, 'displayAmount':displayAmount, 'listName':listName, 'listNameView':listNameView, 'sticky':stickyVal, 'priority':priority, 'popUp':popUp, 'deleteViewButton':viewDelete, 'editViewButton':viewEdit}, updateEdit);
		
	}
	else
		alert(errMsg);
}

function updateEdit(r)
{
	if(r.status != 1)
	{
		alert("updateEdit: " + r.message);
		hideWait();
	}
	else
	{
		var viewDelete = false;
		var viewEdit = false;
		if (r.deleteviewbutton == 'true' || r.deleteviewbutton)
			viewDelete = true;
		if (r.editviewbutton == 'true' || r.editviewbutton)
			viewEdit = true;
		
		//create the display filter
		var uniqueName = r.listname + '_' + r.thequery.fk_id +  '_' + r.thequery.fk_sid + '_';
		var noteFilterSelectID = uniqueName + "NoteFilter";
		var dispFilterVar = '1';
		if (window.opener && !(window.opener.$(noteFilterSelectID).value == null || window.opener.$(noteFilterSelectID).value == ''))
		{
			dispFilterVar = window.opener.$(noteFilterSelectID).value.split('||')[1];
		}	
		//create the display amount parameter
		var noteViewSelect = uniqueName + "NoteView";
		var dispAmtVar = '5';
		if (window.opener && !(window.opener.$(noteViewSelect).value == null || window.opener.$(noteViewSelect).value == ''))
		{
			dispAmtVar = window.opener.$(noteViewSelect).value;
		}	
		//create the sorting parameter
		var noteSortColumn = uniqueName + 'noteSortCol';
		var noteSortDirection = uniqueName + 'noteSortDir';
		var sortVar = null
		if (window.opener && !(window.opener.$(noteSortColumn).value == null || window.opener.$(noteSortColumn).value == ''))
		{
			sortVar = window.opener.$(noteSortColumn).value + ' ' + window.opener.$(noteSortDirection).value;
		}	
		
		getNotes(r.thequery.fk_id, r.thequery.fk_sid, r.listname, r.listnameview, dispAmtVar, 1, sortVar,r.popup, viewDelete, viewEdit, dispFilterVar);
	}
}

/* SHOWNOTEADDED() */
function showNoteAdded(r)
{
//alert('cc: ' + r.cc);
	if(r.status != 1)
	{
		alert('showNoteAdded: ' + r.message);
	}
	else
	{
		// blank out the form field.
		setNoteText(r.fieldname, '');
		var uniqueName = r.listname + '_' + r.record +  '_' + r.system + '_';
		var formName = uniqueName + 'NoteForm';
		var allElements = formName  + '\n';

		if ($(formName) != undefined)  //check if the form exsists
		{
			for(i=0; i < $(formName).elements.length; i++)
			{
				var elemType = $(formName).elements[i].type;
				if (elemType == 'text')
				{
					allElements += $(formName).elements[i].name + ' - ' + $(formName).elements[i].value + ' - ' + $(formName).elements[i].type + ' - ' + $(formName).elements[i].alt + '\n';
					if ($(formName).elements[i].alt == 'date')
					{
						var d = new Date(); //'MM/dd/yyyy'
						var dMonth = d.getMonth() + 1;
						var dDate = d.getDate();
						var dYear = d.getFullYear();
						var theDate = ((dMonth < 10) ? '0' : '') + dMonth + '/' + ((dDate < 10) ? '0' : '') + dDate + '/' + dYear;
						//alert(theDate);
						$(formName).elements[i].value = theDate;
					}
					else
						$(formName).elements[i].value = '';
				}
				else if (elemType == 'select-one' || elemType == 'select-multiple')
				{
					allElements += $(formName).elements[i].name + ' - ' + $(formName).elements[i].value + ' - ' + $(formName).elements[i].alt + '\n';
					//this is for the default value of the drop down
					var n_default = -1;
					var sz_elementName = $(formName).elements[i].name;
					//test for priority
					var sz_elementSub = sz_elementName.substr(sz_elementName.length-8).toLowerCase();
					if (sz_elementSub == 'priority' )
						n_default = k_PRIORITY_DEFAULT;
						
					for (j = 0; j < $(formName).elements[i].options.length; j++)
					{
						if ($(formName).elements[i].options[j].value == n_default)
							$(formName).elements[i].options[j].selected = true;
						else
							$(formName).elements[i].options[j].selected = false;
					}
				}
				else if (elemType == 'checkbox')
				{
					allElements += $(formName).elements[i].name + ' - ' + $(formName).elements[i].checked + ' - ' + $(formName).elements[i].type + '\n';
					if ($(formName).elements[i].checked)
						$(formName).elements[i].click();
				}
				else
					allElements += '<' + $(formName).elements[i].name + ' - ' + $(formName).elements[i].value + ' - ' + $(formName).elements[i].type + '>\n';
			}
		}

//		alert(allElements);
		
		var viewDelete = false;
		var viewEdit = false;
		if (r.deleteviewbutton == 'true' || r.deleteviewbutton)
			viewDelete = true;
		if (r.editviewbutton == 'true' || r.editviewbutton)
			viewEdit = true;
		/*
		alert
		(
			'record -> ' +  r.record + '\n ' +
			'system -> ' + r.system + '\n ' +
			'listname -> ' + r.listname + '\n ' +
			'listnameview -> ' + r.listnameview + '\n ' +
			'numbernotes -> ' + r.displayamount + '\n ' +
			'notetype -> ' + r.notetype + '\n ' +
			'popup -> ' + r.popup + '\n ' +
			'filtertype -> ' + r.filtertype
		);
		*/
		getNotes(r.record, r.system, r.listname, r.listnameview, r.displayamount, r.notetype, null,r.popup, r.filtertype)
		
	}	
}

/* DELNOTE() */
function delNote(record)
{
	showWait();
	DWREngine._execute(_cfscriptLocation, null, 'deleteNote', record, showNoteDeleted);
}

/* SHOWNOTEDELETED - redraw the table with the new data*/
function showNoteDeleted(r)
{
	if(r.status != 1)
	{
		alert("showNoteDeleted: " + r.message);
	}
}

/* SHOWNOTES() */
function showNotes(r)
{
	if(r.status != 1)
	{
		alert("showNotes: " + r.status + ': ' + r.message);
		hideWait();
		return;
	}

	var dateFieldText = '';
	var displayPoint = r.arguments.listname + '_' + r.arguments.record +  '_' + r.arguments.system + '_DisplayPoint';
	/*
	if (r.popup)
		$(displayPoint);
	*/
	
	if(r.popup)
	{
		r.popup = false;
		window.opener.showNotes(r);
		hideWait();
		setTimeout('window.close()', 0);
		return;
	}
	
	if (window.opener && r.popup)
		theTable = window.opener.$(displayPoint);
	else
		theTable = $(displayPoint);
		
	if (theTable != null)
	{
		// Delete the table and redraw it 
		//delete row by row, all but the first one (the header of the row)
		for (i = theTable.rows.length-1; i > 0 ; i--)
			theTable.deleteRow(i);
	
		var ccCount = 0;
		var ccRemind = 0;
		// table deleted. redraw the table with new data.	
		for(i = 0; i < r.thesql.recordcount && i < r.displayamount; i++)
		{
			var j = i + 1;
			var uniqueDivID = r.thequery.id[i] + '_' + r.arguments.listname;
			var uniqueStickyDivID = r.thequery.id[i] + '_Sticky_' + r.arguments.listname;
			var uniqueMagDivID = r.thequery.id[i] + '_magnify_' + r.arguments.listname;
			
			theTable.insertRow(j);
			
			//draw the thumbtack/magnifying glass/reminder/alert colum
			theTable.rows[i+1].insertCell(0);
			
			//stuff for the thumbtack
			var stickyScript = '';
			var stickyImage = '<center><img src="_images/_icons/sticky.gif" height="14px" width="14px" onmouseover="return overlib(\'Sticky\');" onmouseout="return nd();" border="0"></center>';
			var nonstickyImage = '<center><img src="_images/_icons/nonsticky.gif" height="14px" width="14px" onmouseover="return overlib(\'Non-Sticky\');" onmouseout="return nd();" border="0"></center>';
			var stickyDiv = '';
			var nonstickyDiv = '';
			//only allow this if the user have the rights to edit
			if (r.thequery.editallow[i] == 1)
				stickyScript = '<a style="cursor:pointer" onclick="javascript:if($(\'' + uniqueStickyDivID + '\').style.display==\'block\'){ $(\'' + uniqueStickyDivID + '_non' + '\').style.display=\'block\';$(\'' + uniqueStickyDivID + '\').style.display=\'none\'; } else { $(\'' + uniqueStickyDivID + '_non' + '\').style.display=\'none\';$(\'' + uniqueStickyDivID + '\').style.display=\'block\';} toggleSticky(' + r.thequery.id[i] + ');" >';	
			if (r.thequery.sticky[i] == 0)
			{
				stickyDiv = '<div align="right" width="100%" id="' + uniqueStickyDivID + '" style="display:none">' + stickyImage + '</div>';
				nonstickyDiv = '<div align="right" width="100%" id="' + uniqueStickyDivID + '_non' + '" style="display:block">' + nonstickyImage + '</div>';
			}
			else
			{
				stickyDiv = '<div align="right" width="100%" id="' + uniqueStickyDivID + '" style="display:block">' + stickyImage + '</div>';
				nonstickyDiv = '<div align="right" width="100%" id="' + uniqueStickyDivID + '_non' + '" style="display:none">' + nonstickyImage + '</div>';
			}
			
			//stuff for the magnifying glass
			var magImageOnClick = "if($('" + uniqueDivID + "').className=='') $('" + uniqueDivID + "').className='NOTELFONT'; else $('" + uniqueDivID + "').className='';checkDivHeight('" + uniqueDivID + "', 150);";
			var magImage = '<center><img style="cursor:pointer;" src="_images/_icons/mag.gif" height="14px" width="14px" onclick="' + magImageOnClick + '" onmouseover="return overlib(\'Magnify\');" onmouseout="return nd();" border="0"></center>';
			
			//stuff for the reminder
			//if their is data in fk_uid_copy and in reminddate, then create this icon
			var sz_reminderImage = '';
			if (r.thequery.copy[i] != null && (r.thequery.copy[i] + '').length > 0 && r.thequery.reminddate[i] != null && (r.thequery.reminddate[i] + '').length > 0)
			{
				if (r.thequery.remindersent[i] == 0)	
					sz_reminderImage = '<img src="_images/_icons/reminder.png" height="14px" width="14px" onmouseover="return overlib(\'Reminder to be sent ' + (r.thequery.format_reminddate[i]) + '.\');" onmouseout="return nd();" border="0">';
				else
					sz_reminderImage = '<img src="_images/_icons/reminder_sent.png" height="14px" width="14px" onmouseover="return overlib(\'Reminder sent ' + (r.thequery.format_reminddate[i]) + '.\');" onmouseout="return nd();" border="0">';
			}
			
			//stuff for the task
			//if their is data in fk_uid_copy and in datedue, then create this icon
			var sz_taskImage = '';
			if (r.thequery.copy[i] != null && (r.thequery.copy[i] + '').length > 0 && r.thequery.datedue[i] != null && (r.thequery.datedue[i] + '').length > 0)
			{
				var taskImage = '_images/_icons/task_grey.gif';
				var taskImageSource = '';
				var taskImageClick = '';
				var taskMsg = '';
				var taskSource = '';
				//if the task is not completed yet
				if (r.thequery.datecompleted[i] == null || (r.thequery.datecompleted[i] + '').length == 0 )
				{
					var taskExt = '';
					if (new Date(r.thequery.datedue[i]) < (new Date()))
					{
						taskExt = 'past ';
						taskImage = '_images/_icons/task_red.gif';
					}
					else
						taskImage = '_images/_icons/task_green.gif';
					
					taskMsg = 'Task ' + taskExt + 'due ' + (r.thequery.format_datedue[i]);
					taskImageSource = '<img src="' + taskImage + '" height="14px" width="14px" onmouseover="return overlib(\'' + taskMsg + '.\');" onmouseout="return nd();" border="0">';
					taskImageClick = taskImageSource;
					
					if (r.thequery.taskaction[i] != null && (r.thequery.taskaction[i] + '').length > 0)
						taskImageClick = '<a style="cursor:pointer" onclick="' + r.thequery.taskaction[i] + '">' + taskImageSource + '</a>';
					//col2 += '<tr><td>' + taskImageClick + '</td></tr>';
					taskSource = taskImageClick;
				}
				else  //if the task has been completed
				{
					taskImage = '_images/_icons/task_grey.gif';
					taskMsg = 'Task completed ' + (r.thequery.format_datecompleted[i]);
					taskSource = '<img src="' + taskImage + '" height="14px" width="14x" onmouseover="return overlib(\'' + taskMsg + '.\');" onmouseout="return nd();" border="0">';
				}
				sz_taskImage = taskSource;
			}
			
			theTable.rows[i+1].cells[0].innerHTML = '<table><tr><td>' + stickyScript + stickyDiv + nonstickyDiv + '</a></td><td>' + magImage + '</td></tr><tr><td>' + sz_reminderImage + '</td><td>' + sz_taskImage + '</td></tr></table>';
			theTable.rows[i+1].cells[0].width = '32px';
			theTable.rows[i+1].cells[0].halignment = 'center';
			
			//draw the type/date column
			theTable.rows[i+1].insertCell(1);
			var createDateFieldText = '';
			var updateDateFieldText = '';
			if (r.thequery.createddate[i] != '' || r.thequery.createdtime[i] != '')
				createDateFieldText = r.thequery.createddate[i] + " " + r.thequery.createdtime[i];
			if (r.thequery.updateddate[i] != '' || r.thequery.updatedtime[i] != '')
				updateDateFieldText = r.thequery.updateddate[i] + " " + r.thequery.updatedtime[i];
			var col0 = '<table><tr><td class="NOTEL5A" valign="top">' + r.thequery.description[i] + '</td></tr><tr><td>' + createDateFieldText + '</td></tr>';
			col0 += '</table>';
			theTable.rows[i+1].cells[1].innerHTML = col0;
			theTable.rows[i+1].cells[1].width = '125px';
			theTable.rows[i+1].cells[1].halignment = 'left';
		
			//draw the note column
			theTable.rows[i+1].insertCell(2);
			if(r.thequery.note[i].length != 1)
			{
				//var thenote = r.thequery.note[i].replace(/<[pP\/][^>]*>/g, '');
				var thenote = ' ';
				if (r.thequery.note[i] != undefined)
					thenote = r.thequery.note[i];
				thenote.replace(/<p([^>]*)>/g, '');
				thenote = thenote.replace(/<\/p([^>]*)>/g, '<br />');

				//if the note is over 750 characters long, shorten it.  but leave a way to view the full note
				var notesource = '';
				//if (thenote.length > 750)
				//	notesource = '<div id="' + uniqueDivID + '_long' + '" >' + thenote + '</div>';
				//else
					notesource = thenote;
				var clickEvent = "javascript:noteExpandTimeout('" + uniqueDivID + "', 'NOTELFONT');";
				clickEvent = "javascript:if($('" + uniqueDivID + "').className=='NOTELFONT') $('" + uniqueDivID + "').className=''; else $('" + uniqueDivID + "').className='NOTELFONT';";
				theTable.rows[i+1].cells[2].innerHTML = '<div id="' + uniqueDivID + '" class="" >' + notesource + '</div>';
				
				checkDivHeight(uniqueDivID, 150, r.popup);
				
			}
			else
			{
				theTable.rows[i+1].cells[2].innerHTML = "&nbsp;";
			}
			theTable.rows[i+1].cells[2].halignment = 'left';
			
			//draw the author column
			var s_createdBy = 'Unknown';
			if (r.thequery.author[i] != null && r.thequery.author[i] != '')
				s_createdBy = r.thequery.author[i];
			var col2 = '<table><tr><td><tr><td><span class="NOTEL5A">By:</span> ' + s_createdBy.toUpperCase();
			//create the mouseover for the update info
			col2 += '</td></tr>';

			if ((r.thequery.copy[i] + '').length > 0 && r.thequery.copy[i] != null)
			{
				col2 += '<tr><td><span class="NOTEL5A">CC:</span> ' + r.thequery.copy[i] + '</td></tr>';
				ccCount++;	
			}
			col2 += '<tr><td>';
			
			col2 += '</table>';
	
			theTable.rows[i+1].insertCell(3);
			theTable.rows[i+1].cells[3].innerHTML = col2;
			theTable.rows[i+1].cells[3].valignment = 'top';
			theTable.rows[i+1].cells[3].width = '100px';
			
			//draw the info column
			//create the mouseover for the update info
			var sz_updateInfo = '';
			var sz_updateRollover = '';
			if (r.thequery.updatedby[i] != null)
				 sz_updateInfo = '<tr><td>' + r.thequery.updatedby[i].toUpperCase() + '</td></tr>';
			if (updateDateFieldText != '')
				sz_updateInfo += '<tr><td>' + updateDateFieldText + '</td></tr>';
			if (sz_updateInfo != '')
				sz_updateRollover = '<img style="cursor:pointer;" src="_images/_icons/icon_info.gif" height="12px" width="12px" onclick="return overlib(\'<table>' + sz_updateInfo + '</table>\',  MOUSEOFF,  CAPTION, \'Update Information\');" onmouseout="return nd();" border="0">';
			
			theTable.rows[i+1].insertCell(4);
			theTable.rows[i+1].cells[4].innerHTML = '&nbsp;' + sz_updateRollover + '&nbsp;';
			theTable.rows[i+1].cells[4].halignment = 'right';
			
			//draw the priority column
			theTable.rows[i+1].insertCell(5);
			theTable.rows[i+1].cells[5].innerHTML = '<center>' + r.thequery.priority_desc[i] + '</center>';
			theTable.rows[i+1].cells[5].halignment = 'right';
			theTable.rows[i+1].cells[5].width = '20px';
	
			var editButton = r.thequery.jseditbutton[i];
			var delButton = r.thequery.jsdelbutton[i];
	
			//draw the action column
			theTable.rows[i+1].insertCell(6);
			theTable.rows[i+1].cells[6].halignment = 'right';
			theTable.rows[i+1].cells[6].width = '5px';
			if (editButton.length > 0 || delButton.length > 0)
				theTable.rows[i+1].cells[6].innerHTML = '<center><table border="0" cellspacing="0"><tr>' + editButton + delButton + '</tr></table></center>';
			else
				theTable.rows[i+1].cells[6].innerHTML = ' ';
	
			if(i % 2 == 0)
				theTable.rows[i+1].className = "AR2";
			else
				theTable.rows[i+1].className = "AR1";
		}
	}
	
	hideWait();
	
	
	if (r.popup)
	{	
		setTimeout('window.close()', 0);
		//window.close(this);  why the crap does this not work until the mouse is moved.  WTC!
	}

}

function setDisplayPoint(tableID, popUp)
{
	var prevDispPoint = displayPoint.id;
	
	if (popUp)
		displayPoint = window.opener.document.getElementById(tableID);
	else
		displayPoint = $(tableID);
		
	displayPointArray[called] = displayPoint;
}

function getDisplayPoint()
{
	return displayPoint;
}

function showWait()
{
	//alert(getProcessingPoint());
	
	if(getProcessingPoint() != null && getProcessingPoint() != '')        
	{
		var waitBox = getProcessingPoint();
		waitBox.style.pixelTop = (document.body.scrollTop + 150);
		waitBox.style.visibility = 'visible';
	}

	if(getImgProcessingPoint() != null && getImgProcessingPoint() != '')        
	{
		var waitBox = getImgProcessingPoint();
		waitBox.style.visibility = 'visible';
	}
}

function hideWait()
{
	if(getProcessingPoint() != null && getProcessingPoint() != '')
	{
		var waitBox = getProcessingPoint();
		waitBox.style.visibility = 'hidden';
	}
	
	if(getImgProcessingPoint() != null && getImgProcessingPoint() != '')
	{
		var waitBox = getImgProcessingPoint();
		waitBox.style.visibility = 'hidden';
	}
}

function setProcessingPoint(el, popUp)
{
	processingPoint = $(el);
}

function getProcessingPoint()
{
	return processingPoint;
}

function setImgProcessingPoint(el)
{
	imgProcessingPoint = $(el);
}

function getImgProcessingPoint()
{
	return imgProcessingPoint;
}

function setNoteText(el, text)
{
	// blank out the form field.
	try
	{
		var oEditor = FCKeditorAPI.GetInstance(el);
		oEditor.SetHTML(text);
		//document.getElementById(r.fieldname).value = '';
	}
	catch(err){}	
}

//this function exsists because the fckEditor doesn't play well with motzilla
//if the div's display is set to blank, the editor's properties are set to not allow the text to be edited
//but, once the SetHTML function is called, the text field can be edited.... weird?
function prepareNoteText(el)
{
	// just take the value of the field, and re-set it to it's own value.... don't ask
	
	try
	{
		var oEditor = FCKeditorAPI.GetInstance(el);
		var theNote = oEditor.GetXHTML();
		//oEditor.SetHTML('');
		oEditor.SetHTML(theNote);
	}
	catch(err){}	

}

function getErrorMsg(theNote, noteTypeEl)
{
	//check if things are blank that can't be
	
	var errMsg = '';
	
	if (theNote == '')
		errMsg = 'Note cannot be blank.';
		
	if (noteTypeEl != undefined)
	{
		var noteType = $(noteTypeEl).value;
		
		if ((noteType + '').length == 0)
		{		
			if (errMsg != '')
				errMsg += '  ';
			errMsg += 'Select a Note Type.';
			CC(noteTypeEl);
		}
		else
			CB(noteTypeEl);
	}
	
	return errMsg;
}

function noteExpandTimeout(el, className)
{
	setTimeout('changeClassName("' + el + '","' + className + '");', 1);
}

function changeClassName(el, className)
{
	$(el).className=className;
}

/*  wish this worked
function formatDate(date)
{
	//format the date
	var d = new Date(date);
	var curr_date = d.getDate();
	if (curr_date < 10) curr_date = '0' + curr_date;
	var curr_month = d.getMonth() + 1;
	if (curr_month < 10) curr_month = '0' + curr_month;
	var curr_year = d.getFullYear();
	
	return curr_month + '/' + curr_date + '/' + curr_year;
}
*/

function toggleSticky(id)
{
		showWait();
		DWREngine._execute(_cfscriptLocation, null, 'toggleSticky', {'id':parseInt(id)}, retToggleSticky);	
}

function retToggleSticky(r)
{
	hideWait();		
}


function sortSetup(sortHeaderRow,sortColumnID,sortColumn,sortDirection,sortingColumn)
{
	var arrow = '';
	if (sortingColumn == $(sortColumn).value)
	{
		if ($(sortDirection).value == 'asc')
			$(sortDirection).value = 'desc';
		else
			$(sortDirection).value = 'asc';
	}
	else
	{
		$(sortColumn).value = sortingColumn;
		$(sortDirection).value = 'asc';	
	}
	if ($(sortDirection).value == 'asc')
		arrow = '&nbsp;&nbsp;&uarr;';
	else
		arrow = '&nbsp;&nbsp;&darr;';
	
	var row = $(sortHeaderRow);
	//alert(row.cells.length);
	for (i = 0; i < row.cells.length; i ++)
	{
		var cell = row.cells[i].innerHTML;
		cell.replace('&nbsp;&nbsp;&darr;','');
		cell.replace('&nbsp;&nbsp;&uarr;','');
		//alert(cell + '\n---------------------\n' + row.cells[i].childNodes.length);
		for (j = 0; j < row.cells[i].childNodes.length; j++)
		{
			if(row.cells[i].childNodes[j].id != undefined && row.cells[i].childNodes[j].id != '')
			{
				//alert(i + ':' + j + ') ' + row.cells[i].childNodes[j].id + '\n-------\n' + $(row.cells[i].childNodes[j].id).innerHTML);
				if ($(row.cells[i].childNodes[j].id).innerHTML.indexOf('&nbsp') >= 0)
				{
					var innerTxt = $(row.cells[i].childNodes[j].id).innerHTML;
					var indx = innerTxt.indexOf('&nbsp');
					//alert(innerTxt.substr(0,indx));
					$(row.cells[i].childNodes[j].id).innerHTML = innerTxt.substr(0,indx);
				}
			}
		}
	}
//	alert($('test3').innerHTML);
	//set the innerHTML for the sorted column
	$(sortColumnID.id).innerHTML += arrow;
	
}



//this is to keep track of the open popups
var sz_windows = new Array();
function openWin(url, sz_name)
{ 
	var thisWin = null;
	var n_index = 0;
	var b_exsist = false;
	
	//find the window in the array
	//alert(navigator.appName);
	for (i = 0; i < sz_windows.length && !b_exsist; i++)
	{
		try
		{
			if (sz_windows[i].name == sz_name)
			{
				n_index = i;
				b_exsist = true; //get out of the loop
			}
		}
		catch(e)
		{	
			var sz_browser = navigator.appName;
			if (sz_browser.toLowerCase() != 'netscape') //need to have this for IE.  it can not gain focus (re-open) a window that has been closed
				sz_windows.splice(i,1);
		}
	
	}

	if (!b_exsist)
	{
		n_index = sz_windows.length;
		sz_windows[n_index] = window.open(url,sz_name,'toolbar=no,directories=no,location=no,status=no,menubar=no,resizable=yes,scrollbars=yes');
		//for some reason the window is maximizing, so resize it to the correct size
		sz_windows[n_index].resizeTo(660,460);
	}
	
	sz_windows[n_index].focus();

	
	return sz_windows[n_index];
}

//this function is used for sizing the height of a div correctly
function checkDivHeight(sz_div, n_height, b_popup)
{
	if (b_popup == 'undefined')
		b_popup = false;
	
	o_div = null;
	if (b_popup && window.opener)
		o_div = window.opener.$(sz_div);
	else
		o_div = $(sz_div);
		
	//turn off the overflow-y and height attributes for the div
	o_div.style.overflowY = '';
	o_div.style.height = '';
		
	//check for the height of the div.  
	// if it's greater than n_height, set it equal to n_height, and set overflow-y to auto
	if(o_div.offsetHeight > n_height)
	{
		o_div.style.height = n_height;
		o_div.style.overflowY = 'auto';
	}
}