/* LT-DuplicateMeeting.js */
$(document).ready(function() {
// duplicateMeeting
$.duplicateMeeting = function(meetingid) {	
	$("#wrap-dialog").remove();
	$('<div id="wrap-dialog"></div>').appendTo('#for-screen').hide();
	$('#wrap-dialog').html('\
		<div id="dialog"><input type="hidden" name="dupemeetingid" id="dupemeetingid" value="' + meetingid + '">\
			<div class="menubar">\
				<div class="title">Duplicate the Meeting?</div>\
				<div class="description">Choose the Agenda Items and Files to duplicate.</div>\
				<div class="buttons"><a id="btn-dupe-meeting-dupe" href="#">Duplicate</a><a id="btn-dupe-meeting-cancel" href="#">Cancel</a></div>\
			</div>\
			<div class="wrap-content">\
				<div class="content-nav"><a id="btn-dupe-meeting-checkall" href="#">Check All</a><a id="btn-dupe-meeting-checknone" href="#">Check None</a> <input id="dupeattachments" name="dupeattachments" type="checkbox" value="1"> Duplicate Attachments</div>\
				<div class="content"></div>\
			</div>\
		</div>\
	'); 
	// Don't allow the Body, now in the background, to scroll
	$('body').css('overflow','hidden');
		
	// Duplicate Button
	$("#dialog .menubar #btn-dupe-meeting-dupe").click( function() {
		$.post("/co/acsd50/Board.nsf/LT-DuplicateMeeting?open&" + Math.random(), 
			$("input:hidden, input:checkbox", "#dialog" ).serialize(), 
			function(data){ 
				$("#dialog .menubar #btn-dupe-meeting-cancel").trigger('click');
				$("#new-current-meeting").val( $.trim(data) );
				$("#li-meetings .tab-menuitems [key=draft]").trigger("click");
			}
		);
	});
	// Cancel Button
	$("#dialog .menubar #btn-dupe-meeting-cancel").click( function() {
		$("#wrap-dialog").remove();
		$('body').css('overflow','auto');
	});
	// Check All Button
	$("#dialog #btn-dupe-meeting-checkall").click( function() {
		$("#dialog .content input:checkbox").attr('checked','checked');
	});
	// Check None Button
	$("#dialog #btn-dupe-meeting-checknone").click( function() {
		$("#dialog .content input:checkbox").attr('checked','');
	});
	// Call window resize
	$.windowResize();
	// Get Agenda Checkboxes
	$.getAgendaForDuplication(meetingid);
	$('body').css('overflow','hidden');
}
// getAgendaForDuplication
$.getAgendaForDuplication = function( meetingid ) {	
	$.post("/co/acsd50/Board.nsf/DUPLICATE-GetAgenda?open&test&" + Math.random(), 
		{ id : meetingid }, 
		function(data){ 
			$("#dialog .content").html(data);
			$("#dialog .item").each( function(){ $(this).prev(".wrap-category").children(".wrap-items").append( $(this) ); });
			// Category Checkbox Click
			$("#dialog .category input:checkbox").click( function() {
			var theparent = $(this).parent().parent();
				if ( $(this).filter(":checked").length == 1 ) {
					$(".wrap-items input:checkbox", theparent).attr('checked','checked');
				} else {
					$(".wrap-items input:checkbox", theparent).attr('checked','');
				}
			});
			// Now show the screen
			$('#wrap-dialog').show();
		}
	);
}
// getPublicFilesForDuplication
$.getPublicFilesForDuplication = function( id, el ) {
	$.post("/co/acsd50/Board.nsf/LT-GetPublicFiles?open&" + Math.random(), 
		{ id : id }, 
		function(data){ 
			$(el).html( data );	
		}
	);
}
});
