/* agenda.js */
$(document).ready(function() {
var agendaitempubliceditor;
var agendaitemadmineditor;
var agendaitemexeceditor;
// getMyItems
$.getMyItems = function() {	
	$.get("/vsba/fairfax/Board.nsf/LT-GetMyItems?open&" + Math.random(), { id: "" }, 
		function(data){ 
			$("#my-agenda-items").html(data);
			$("#my-items-accordion").accordion({ collapsible: false, autoHeight: false });  // my-items accordion
			$("a.myitem[unique=" + $("#current-agenda-item").val() + "]", "#my-agenda-items").trigger("click").parent().prev("h3").find("a").trigger("click");
			$.attachMyItemsRightClick();
		}
	);					
}
// my items right-click
$.attachMyItemsRightClick = function() {
	/* My Item right-click */
	$('#my-agenda-items a.draft').contextMenu('myMenu1', {
		onShowMenu: function(e, menu) {
			$('li', menu).not("#duplicate, #delete").remove();
			return menu;
		}, 
		bindings: {
			'duplicate': function(t) {
				$.post("/vsba/fairfax/Board.nsf/LT-DuplicateItem?open&" + Math.random(), 
					{ id : $(t).attr('unique') }, 
					function(data){ 
						// $(t).clone().attr('unique', $.trim(data)).html("Copy of " + $(t).html()).removeClass('active').insertAfter(t);
						$("#current-agenda-item").val( data );
						$.getMyItems();
					}
				);
			},
			'delete': function(t) {
				if ( confirm('Delete this item?') ) { 
					$.deleteByID( $(t).attr('unique') ); 
					$(t).remove();
					$.getMyItems();
				}
			}
		}
	});
}
// getAgenda
$.getAgenda = function( meetingid ) {	
	$.get("/vsba/fairfax/Board.nsf/LT-GetAgenda?open&" + Math.random(), { id: meetingid }, 
		function(data){ 
			$.clearAgendaSearchBox();
			$("#agenda").html(data);
			$.attachAgendaFunctions();
			$("#current-meeting").val( meetingid );
			// If no items are active, then click the first one
			if ( $(".item.active", "#agenda").length == 0 ) {
				$("#agenda .item").not(".placeholder").filter(":first").trigger("click");
			}
		}
	);					
}	
// attachAgendaFunctions
$.attachAgendaFunctions = function() {						
	$("#agenda .actiontype").each( function(){  $(this).children('.comma:last').remove();  });
	$("#agenda .actiontype").each( function(){  
		if ( $(this).html().toLowerCase().indexOf("action") > 0 ) { $(this).parent('.item').addClass("type-action") }
		if ( $(this).html().toLowerCase().indexOf("consent") > 0 ) { $(this).parent('.item').addClass("type-consent").addClass("type-action") }
	});
	/* Add "active" class to current item */
	var curitem = $.trim(  $("#current-agenda-item").val() );
	$(".item[id='" + curitem + "']").addClass('active').trigger("click");
	/* move agenda items into the wrap-items area */
	$("#tab-agenda .pane-navigation .item").each( function(){
		$(this).prev(".wrap-category").children(".wrap-items").append( $(this) );
	});
	// get any uncategorized items and put them in the first category
	$("#agenda > .item").each( function(){ 
		$("#agenda .wrap-items:first").append( $(this) );
	});
	/* Sort Categories */
	// $(".wrap-category").tsort({attr:"categoryorder"});
	/* Add agenda numbering */
	$.numberTheAgenda( $("#agenda") );
	// see if a search is requested
	var packetSearchBox = $("#tab-welcome .search-box");
	var meetingSearchBox = $("#tab-meetings .search-box").filter(":visible");
	var agendaSearchBox = $("#tab-agenda .search-box");
	var packetSearchText = $.getSearchBoxText( $(packetSearchBox) );
	var meetingSearchText = $.getSearchBoxText( $(meetingSearchBox) );
	if ( packetSearchText || meetingSearchText ) {
		$("#li-agenda > a").trigger("click");
	
		if ( packetSearchText ) {
			$.setSearchBoxText( $(agendaSearchBox), packetSearchText);
		} else {
			$.setSearchBoxText( $(agendaSearchBox), meetingSearchText);
		}
		$(agendaSearchBox).find("img.search").trigger("click");
	}
	if (isAnonymous) { return }
	/* Make the agenda sortable */
	$.agendaSorting();
	if (! isPublisher) { return }
	/* Agenda Category right-click */
	$('#agenda .category').contextMenu('myMenu1', {
		onShowMenu: function(e, menu) {
			$('li', menu).not("#rename, #delete").remove();
			return menu;
		}, 
		bindings: {
			'rename': function(t) {
				catname = $(t).children('.category-name');
				cattext = $(catname).text();
				$(catname).html('<input class="edit-category" style="width: 220px; border: 0; background: #ffc; padding: 1px; font-size: 11px;" type="text" value="' + cattext + '"><div style="margin-top: 8px;"><u>Enter</u> to Save / <u>Escape</u> to Cancel</div>');
				$("input", catname).trigger('focus');
				// Save/Cancel if publisher hits return/escape
				$("input", catname).keyup( function(e) {
					if (e.keyCode == 27) {
						$(catname).html( cattext );
					}
					if (e.keyCode == 13) {
						$.post("/vsba/fairfax/Board.nsf/LT-SaveCategoryName?open&" + Math.random(), 
							{ id : $(t).attr('id'), name : $.trim( $(this).val() ) }, 
							function(data){ 
								if ( $.trim(data) == "1") {
									$(catname).html( $("input", catname).val() );
									$.saveAgendaOrder();
								} else {
									$(catname).html( cattext );
								}
							}
						);
					}
				});
				// Save if publisher clicks away from edit field
				$("input", catname).blur( function(e) {
					$.post("/vsba/fairfax/Board.nsf/LT-SaveCategoryName?open&" + Math.random(), 
						{ id : $(t).attr('id'), name : $.trim( $(this).val() ) }, 
						function(data){ 
							if ( $.trim(data) == "1") {
								$(catname).html( $("input", catname).val() );
							} else {
								$(catname).html( cattext );
							}
						}
					);
				});
					
			},
			'delete': function(t) {
				if ( confirm('Delete this category and item(s)?') ) { 
					var parent = $(t).parent('.wrap-category');
					$(".item, .category", parent).each( function(){
						// mark category and item(s) deleted
						$.deleteByID( $(this).attr('id') ); 
						$(this).remove();
					});
							
					$(t).remove();
					$.saveAgendaOrder(true);
				}
			}
		}
	});
	/* Agenda Item right-click */
	$('#agenda .item').contextMenu('myMenu1', {
		onShowMenu: function(e, menu) {
			$('li', menu).not("#rename, #delete, #copyasnew, #addpacket").remove();
			return menu;
		}, 
		bindings: {
	
			'rename': function(t) {
				itemname = $(t).children('.title');
				itemtext = $.trim( $(itemname).text() );
				$(itemname).html('<textarea class="edit-item-name" style="display: block; width: 100%; border: 1px solid #ddd; background: #FAFAFA; padding: 1px; font-size: 11px;">' + itemtext + 	'</textarea><div style="margin-top: 8px;"><u>Enter</u> to Save / <u>Escape</u> to Cancel</div>');
	
				$("textarea", itemname).click( function(e) {
					return false;
				});
				$("textarea", itemname).keyup( function(e) {
					if (e.keyCode == 27) {
						$(itemname).html( itemtext );
					}
					if (e.keyCode == 13) {
						$.post("/vsba/fairfax/Board.nsf/LT-SaveItemName?open&" + Math.random(), 
							{ 
								id : $(t).attr('id'), 
								name : $.trim( replaceSubstring( $("textarea", itemname).val(), "\n", "" ) ) 
							}, 
							function(data){ 
								if ( $.trim(data) == "1") {
									$(itemname).html( $.trim( replaceSubstring( $("textarea", itemname).val(), "\n", "" ) ) );
									// $.updateToolTips( $("#tab-agenda .pane-navigation .item") );
								} else {
									$(itemname).html( itemtext );
								}
							}
						);
					}
				});
				// Save if publisher clicks away from edit field
				$("textarea", itemname).blur( function(e) {
					$.post("/vsba/fairfax/Board.nsf/LT-SaveItemName?open&" + Math.random(), 
						{ 
							id : $(t).attr('id'), 
							name : $.trim( replaceSubstring( $("textarea", itemname).val(), "\n", "" ) ) 
						}, 
						function(data){ 
							if ( $.trim(data) == "1") {
								$(itemname).html( $.trim( replaceSubstring( $("textarea", itemname).val(), "\n", "" ) ) );
								// $.updateToolTips( $("#tab-agenda .pane-navigation .item") );
							} else {
								$(itemname).html( itemtext );
							}
						}
					);
				});
	
				$("textarea", itemname).trigger('focus');
						
			},
			'open': function(t) {
				$(t).trigger('click');
			},
			'duplicate': function(t) {
				$.post("/vsba/fairfax/Board.nsf/LT-DuplicateItem?open&" + Math.random(), 
					{ id : $(t).attr('id') }, 
					function(data){ 
						$(t).clone().attr('id', $.trim(data)).attr('unid', '').removeClass('active').insertAfter(t);
						$.saveAgendaOrder(true);
					}
				);
			},
			'delete': function(t) {
				if ( confirm('Delete this item?') ) { 
					$.deleteByID( $(t).attr('id') ); 
					$(t).remove();
					$.saveAgendaOrder(true);
				}
			}
		}
	});
}	
// Agenda Item Live click
$("#tab-agenda .pane-navigation .item").live("click", function() { 
	// Check for Edit Mode
	if ( $("#edit-agenda-item:visible").length > 0 ) {
		if (! confirm("Close this item without saving?")) { return false };
	}
	var activeItemID = $(this).attr('id')
	$.get("/vsba/fairfax/Board.nsf/LT-GetAgendaItem?open&" + Math.random(), { id : $(this).attr('id') }, 
		function(data){ 
			$("#current-agenda-item").val( activeItemID );
			$('#agenda-content').html(data);
			$.refreshAgendaItem();
			$.attachAgendaItemFunctions();
		}
	);  
});	
// View All Motions button
$(".view-all-motions").live("click", function() { 
	$(this).closest(".motions").find(".motion:hidden").slideDown(500);
	$(this).hide();
	$(".collapse-motions").show();
	return false;
});
// Collapse Motions button
$(".collapse-motions").live("click", function() { 
	$(this).closest(".motions").find(".motion").not(".finalresolution").slideUp(500);
	$(this).hide();
	$(".view-all-motions").show();
	return false;
});
// attachAgendaItemFunctions
$.attachAgendaItemFunctions = function() {		
	$.refreshAgendaItem();
				
	var agendaitemid = $("[name=agenda-item-unique]", "#wrap-agenda-item").val();
	var isnewdoc = $("[name=isnewdoc]", "#agenda-item-form").val();
	// show & hide buttons
	$("img.edit", "#wrap-agenda-item").removeClass("display-none");
	$("img.save", "#wrap-agenda-item").addClass("display-none");
	// motions
	var finals = $("#view-agenda-item .motions .motion.finalresolution");
	var notfinals = $("#view-agenda-item .motions .motion").not(".finalresolution");
	$("#view-agenda-item .motions .motion").addClass("ui-corner-all");
	if ( $(finals).length > 0 && $(notfinals).length > 0 ) {
		$(notfinals).hide();
	}
	if ( $("#view-agenda-item .motions .motion:hidden").length > 0 ) {
		$("#view-agenda-item .motions").prepend('<a class="collapse-motions" href="#">Collapse Motions</a>');
		$("#view-agenda-item .motions").prepend('<a class="view-all-motions" href="#">View All Motions</a>');
		$("#view-agenda-item .motions .collapse-motions").hide();
	}
	// put new doc in edit mode
	if ( isnewdoc == "1") { $("img.edit", "#wrap-agenda-item").trigger("click"); }
	// Get Files
	$.getPublicFiles( agendaitemid, $("[key=publicfiles]", "#wrap-agenda-item") ); 
	if (isAdmin || isExecutive) { $.getAdminFiles( agendaitemid, $("[key=adminfiles]", "#wrap-agenda-item") ); }
	if (isAdmin || isExecutive) { $.getExecFiles( agendaitemid, $("[key=execfiles]", "#wrap-agenda-item") ); }
	// Meeting selector
	$("select[name=meetingid]", "#agenda-item-form").change( function() {
		$.getMeetingCategories( $(this).val(), $("[name=categoryid]", "#agenda-item-form") );
	});
	// Action Type selector
	$("select[name=actiontype]", "#agenda-item-form").change( function() {
		$.refreshAgendaItem();
	});
	// Remove meeting options
	$("select[name=meetingid] option[status!=draft]", "#meeting-content").not("[isselect=yes]").remove();
	/* Attach Button hover info */
	$.updateToolTips( $("#wrap-agenda-item .content-navigation img") );
	// Show the content area
	$("#wrap-agenda-item").closest(".pane-content").show();
	// Window resize
	$.windowResize();
	// annotations
	if ( isExecAnnotations ) { $.addBdAnnotationsPanel( $("#tab-agenda"), agendaitemid ); }
	return;
	/************************************************************************************************************/
	/* Button - Previous */
	$("#btn-prev-item").click( function() {
		$( $.getPrevItemDOM() ).trigger('click');
	});
	/* Button - Next */
	$("#btn-next-item").click( function() {
		$( $.getNextItemDOM() ).trigger('click');
	});
	/* Fade buttons - Remove abilities */
	if ( $.getPrevItemDOM() ) { 
		var val1 = $( $.getPrevItemDOM() ).text();
		$("#btn-prev-item").attr('title', 'Previous Item: - ' + val1);
	} else {
		$("#btn-prev-item").css('opacity',0.25).unbind('click').attr('title', '');
	}
	if ( $.getNextItemDOM() ) { 
		var val1 = $( $.getNextItemDOM() ).text();
		$("#btn-next-item").attr('title', 'Next Item: - ' + val1);
	} else { 
		$("#btn-next-item").css('opacity',0.25).unbind('click').attr('title', '');
	}
}
// Add Agenda Item Editors
$.addAgendaItemEditors = function() {
	// remove any instances
	$("#edit-agenda-item .ckeditor").each( function() {
		var id = $(this).attr("id");
		var instance = CKEDITOR.instances[ id ];
		if ( instance ) { CKEDITOR.remove( instance ); }
	})
	// create public and admin
	$("#edit-agenda-item").find(".ckeditor.public, .ckeditor.admin").ckeditor( 
		function( ) { 
			$(".content-navigation img.save", "#wrap-agenda-item").removeClass("display-none"); 
			// $("#edit-agenda-item").scrollTop(0);  // keeps window at top
		}, 
		{ customConfig : '/vsba/fairfax/Board.nsf/javascript/ckconfig.js?open' }
	);
	// create exec
	$("#edit-agenda-item").find(".ckeditor.exec").ckeditor( 
		function( ) {  }, { customConfig : '/vsba/fairfax/Board.nsf/javascript/ckconfig-exec.js?open' }
	);
};
// Edit Agenda Item
$(".content-navigation img.edit", "#wrap-agenda-item").live( "click", function() {
	var theform = $("#agenda-item-form");
	var agendaitemid = $("[name=unique]", "#agenda-item-form").val();
	$.addAgendaItemEditors();
	// show & hide buttons
	$(".content-navigation img.previous", "#wrap-agenda-item").addClass("display-none");
	$(".content-navigation img.next", "#wrap-agenda-item").addClass("display-none");
	$(".content-navigation img.edit", "#wrap-agenda-item").addClass("display-none");
	$(".content-navigation img.print", "#wrap-agenda-item").addClass("display-none");
	$(".content-navigation img.close", "#wrap-agenda-item").removeClass("display-none");
	// show & hide content
	$("#view-agenda-item").hide();
	$("#edit-agenda-item").show();
	// $("#edit-agenda-item").scrollTop(0);  // keeps window at top
	// Grab upload controls
	$.updateUploadAreas();
	return false;
		
});
// saveAgendaItem
$.saveAgendaItem = function() {	
	// var query = $("#agenda-item-form, [name=agendaitem_public_body], [name=agendaitem_admin_body], [name=agendaitem_exec_body]", "#agenda-item-form").serialize();
	var query = $("#agenda-item-form, .ckeditor", "#edit-agenda-item").serialize();
	// hide content area
	$("#wrap-agenda-item").closest(".pane-content").hide();
	$.ajax({
		type: "POST",
		url: "/vsba/fairfax/Board.nsf/LT-SaveAgendaItem?open&" + Math.random(),
		dataType: "html",
		data: query,
		success: function(response){
			var meetingstatus = $.trim($("#current-meeting-status").val());
			
			// Submitted without needing approval, is has reached final approval.
			if ($.trim(response) == "2") {
				$.quickAlert("Note", "The agenda item has been submitted to meeting.", 4000);
				$("#wrap-agenda-item").remove();
			}
			// Notification of Active Agenda Item change
			if ( response.indexOf("notifyAgendaItemChange") > 0 ) {
				$("body").append(response);  // append script tag to execute
			}
			if (meetingstatus == "my-items") { 
				// My Items
				$.getMyItems(); 
			} else {
				// Active, Draft or Templates
				$.getAgenda( $("#current-meeting").val() );
			}
		}
	});
}
// Close Agenda Item
$(".content-navigation img.close", "#wrap-agenda-item").live( "click", function() {
	if (! confirm("Close this item without saving?")) { return false };	
	// show & hide content
	$("#edit-agenda-item").hide();
	$("#view-agenda-item").show();
	// show & hide buttons
	$(".content-navigation img.previous", "#wrap-agenda-item").removeClass("display-none");
	$(".content-navigation img.next", "#wrap-agenda-item").removeClass("display-none");
	$(".content-navigation img.edit", "#wrap-agenda-item").removeClass("display-none");
	$(".content-navigation img.print", "#wrap-agenda-item").removeClass("display-none");
	$(".content-navigation img.close", "#wrap-agenda-item").addClass("display-none");
	$(".content-navigation img.save", "#wrap-agenda-item").addClass("display-none");
});
// Save Agenda Item
$(".content-navigation img.save", "#wrap-agenda-item").live( "click", function() {
	var lengthpublic; 	try { lengthpublic = $("[name=agendaitem_public_body]", "#edit-agenda-item").val().length; } catch(err) { lengthpublic = 0; }
	var lengthadmin; 	try { lengthadmin = $("[name=agendaitem_admin_body]", "#edit-agenda-item").val().length; } catch(err) { lengthadmin = 0; }
	var lengthexec; 	try { lengthexec = $("[name=agendaitem_exec_body]", "#edit-agenda-item").val().length; } catch(err) { lengthexec = 0; }
	if ( lengthpublic > 64000 || lengthadmin > 64000 || lengthexec > 64000 ) {
		$.quickAlert("Cannot Save", "You have too much information in one field.  Try to trim the amount of information you are saving.  Please contact Support if you need assitance.", 8000);
		return false;
	}
	var hasSubject = $("[name=subject]", "#agenda-item-form").length;
	var subject = $("[name=subject]", "#agenda-item-form").val();
	// Confirm workflow fields
	if ( hasSubject && ! subject ) {
		// alert("A Subject is required to save an item.");
		$.quickAlert("Fields Required", "A Subject is required to save an item.", 4000);
		return;
	}
	if (isAdmin) { $("[name=workflowaction]", "#agenda-item-form").val("save"); }
	// Save the Agenda Item
	$.saveAgendaItem();
	return false;			
});
// Notify Active Item Change
$.notifyAgendaItemChange = function(agendaitemid) {
	if (! isPublisher) { return }
	$("#dialog-yesno").html("Would you like to send notification that the Agenda Item has changed?").dialog({
		resizable: false,
		height:140,
		title: "Alert",
		modal: true,
		buttons: {
			'No': function() {
				$(this).dialog('close');
			},
			'Yes': function() {
				$.ajax({
					type: "POST",
					url: "/vsba/fairfax/Board.nsf/LT-NotifyAgendaItemChange?open&" + Math.random(),
					dataType: "html",
					data: { id : agendaitemid },
					success: function(data){
						if ( $.trim(data) == "1" ) {
							$.quickAlert("Notification Sent", "An email has been sent to notify people there has been a change.", 4000);
						} else {
							alert("ERROR: Could not send the notification.  Please contact support.");
						}
					}
				});
				$(this).dialog('close'); 
			}
		}
	});
}
// Submit Button
$(".content-navigation img.submit", "#wrap-agenda-item").live( "click", function() {
	var hasMeetingid = $("[name=meetingid]", "#agenda-item-form").length;
	var hasSubject = $("[name=subject]", "#agenda-item-form").length;
	var hasActiontype = $("[name=actiontype]", "#agenda-item-form").length;
	var hasApprovaltreeid = $("[name=approvaltreeid]", "#agenda-item-form").length;
	var meetingid = $("[name=meetingid]", "#agenda-item-form").val();
	var subject = $("[name=subject]", "#agenda-item-form").val();
	var actiontype = $("[name=actiontype]", "#agenda-item-form").val();
	var approvaltreeid = $("[name=approvaltreeid]", "#agenda-item-form").val();
	var requireapproval = $("[name=requireapproval]", "#agenda-item-form").val();
	// Confirm workflow fields
	if ( (hasMeetingid && ! meetingid) || (hasSubject && ! subject ) ) {
		$.quickAlert("Fields Required", "A meeting and subject are required to submit.", 4000);
		return;
	}
	// Require Approval for Actions
	if ( $.trim(requireapproval) == "1" ) {
		if ( $.actionTypeHasAction() ) {
			if ( hasApprovaltreeid && ! approvaltreeid ) {
				$.quickAlert("Fields Required", "Approval needed for Action items.  Please select an Approval Tree.", 4000);
				return;
			}	
		}
	}
	// Require Approval for All
	if ( $.trim(requireapproval) == "2" ) {
		if ( hasApprovaltreeid && ! approvaltreeid ) {
			$.quickAlert("Fields Required", "Approval needed.  Please select an Approval Tree.", 4000);
			return;
		}
	}
	$("[name=workflowaction]", "#agenda-item-form").val("submit");
	$.saveAgendaItem();
	return false;			
});
// Approve Button
$(".content-navigation img.approve", "#wrap-agenda-item").live( "click", function() {
	if (! confirm("Approve this item?")) { return false };
	$("[name=workflowaction]", "#agenda-item-form").val("approve");
	$.saveAgendaItem();
	return false;			
});
// Reject Button
$(".content-navigation img.reject", "#wrap-agenda-item").live( "click", function() {
	if (! confirm("Reject this item?")) { return false };
	$("[name=workflowaction]", "#agenda-item-form").val("reject");
	$.saveAgendaItem();
	return false;			
});
// Restart Tree Button
$(".content-navigation img.restart", "#wrap-agenda-item").live( "click", function() {
	if (! confirm("Restart approval tree?")) { return false };
	$("[name=workflowaction]", "#agenda-item-form").val("restart");	
	$.saveAgendaItem();
	return false;			
});
// Force Approve Button
$(".content-navigation img.force", "#wrap-agenda-item").live( "click", function() {
	if (! confirm("Force approval?")) { return false };
	$("[name=workflowaction]", "#agenda-item-form").val("force");
	$.saveAgendaItem();
	return false;			
});
// Add or Open My Items
$(".btn-navigation img.add, .myitem", "#wrap-my-items").live("click", function() {
	// Check for Edit Mode
	if ( $("#edit-agenda-item:visible").length > 0 ) {
		if (! confirm("Close this item without saving?")) { return false };
	}
	$("#my-agenda-items").find("a.myitem").removeClass("active");
	$.get("/vsba/fairfax/Board.nsf/LT-GetAgendaItem?open&" + Math.random(), { id : $(this).attr('unique') }, 
		function(data){ 
			$('#meeting-content').html(data);
			$("#current-agenda-item").val( $("[name=unique]", "#agenda-item-form").val() );  // set current agent item
			$.attachAgendaItemFunctions();
			// Show Meeting Content area
			$("#pane-content-meetings", "#tab-meetings").show();
		}
	);  
});
// refreshAgendaItem
$.refreshAgendaItem = function() {	
	$.refreshWorkflow();
	$.refreshDetailFields();
}
// actionTypeHasAction
$.actionTypeHasAction = function() {	
	// cycle action type checkboxes looking for action
	var hasaction = false;
	$("input[name=actiontype]:checked").each( function() {
		if ( $(this).val().toLowerCase().indexOf("action") > -1 ) {
			hasaction = true;
			return false;
		}
	});
	return hasaction;
}
// actionTypeHasConsent
$.actionTypeHasConsent = function() {	
	// cycle action type checkboxes looking for consent
	var hasconsent = false;
	$("input[name=actiontype]:checked").each( function() {
		if ( $(this).val().toLowerCase().indexOf("consent") > -1 ) {
			hasconsent = true;
			return false;
		}
	});
	return hasconsent;
}
// actionTypeHasMinutes
$.actionTypeHasMinutes = function() {	
	// cycle action type checkboxes looking for minutes
	var hasminutes = false;
	$("input[name=actiontype]:checked").each( function() {
		if ( $(this).val().toLowerCase().indexOf("minutes") > -1 ) {
			hasminutes = true;
			return false;
		}
	});
	return hasminutes;
}
// refreshDetailFields
$.refreshDetailFields = function() {	
	if ( $.actionTypeHasAction() || $.actionTypeHasConsent() ) {
		$("#wrap-agenda-item .wrap-detail-fields").show();
	} else {
		$("#wrap-agenda-item .wrap-detail-fields").hide();
	}
	if ( $.actionTypeHasAction() ) {
		$("#wrap-agenda-item .wrap-recommended-action").show();
	} else {
		$("#wrap-agenda-item .wrap-recommended-action").hide();
	}
	if ( $.actionTypeHasMinutes() ) {
		$("#wrap-agenda-item .wrap-minutes-fields").show();
	} else {
		$("#wrap-agenda-item .wrap-minutes-fields").hide();
		$("#wrap-agenda-item .wrap-minutes-fields [name=minutesid]").val("");
	}
}	
// refreshWorkflow
$.refreshWorkflow = function() {	
	var actiontype = $("[name=actiontype]", "#edit-agenda-item").val();
	var requireapproval = $("[name=requireapproval]", "#edit-agenda-item").val();
//	var hasaction = String(actiontype).toLowerCase().indexOf("action") > -1;
	//  Approval for Action Items
	if ( $.trim(requireapproval) == "1" && $.actionTypeHasAction() ) {
		$(".wrap-workflow", "#edit-agenda-item").show();
	} else {
		$(".wrap-workflow", "#edit-agenda-item").hide();
	}
	// Approval for all items
	if ( $.trim(requireapproval) == "2" ) {
		$(".wrap-workflow", "#edit-agenda-item").show();
	}
}	
// getMeetingCategories
$.getMeetingCategories = function( meetingid, el ) {
	$.get("/vsba/fairfax/Board.nsf/LT-GetMeetingCategories?open&" + Math.random(), { meetingid: meetingid }, 
		function(data){ 
			$(el).html(data);
		}
	);					
}	
});
