﻿$(function () {
	$(".jqButton").button();
	$("#tabs").tabs().show();
	$("#delete-confirm").dialog({
		resizable: false,
		height: 160,
		autoOpen: false,
		modal: true,
		buttons: {
			'Delete': function () {
				$(this).dialog('close');
			},
			Cancel: function () {
				$(this).dialog('close');
			}
		}
	});

	$(".DocResults").find(".DocDel").each(function () {
		$(this).click(function () {
			var me = $(this).parents().filter(".Doc");
			var dlg = [];
			var id = me.find(".DocID").html();

			dlg.push("<div class='delete-confirm' title='Delete Document'>");
			dlg.push("<span class='ui-icon ui-icon-alert' style='float:left; margin:0 7px 20px 0;'></span><b>Document Title:</b> " + me.find(".DocTitle").html() + "<br/><br/>Are you sure you want to delete this document? ");
			dlg.push("</div>");

			var jDlg = $(dlg.join(""));

			$("body").append(jDlg);
			jDlg.dialog({
				resizable: false,
				height: 160,
				modal: true,
				width: 500,
				buttons: {
					"Cancel": function () { $(this).dialog("close"); },
					"Delete": function () {
						//console.log(id);
						$.post(baseUrl + "handlers/ArchiveDoc.ashx", { UserID: 1, DocID: id }, function (data) {
							if (data === "Success") {
								jDlg.dialog("close");
								var sdlg = [];

								sdlg.push("<div class='delete-success' style='padding-top:10px;' title='Delete Successful'>");
								sdlg.push("<span class='ui-icon ui-icon-circle-check' style='float:left; margin:0 7px 50px 0;'></span>Document Deleted Successfully<br/>");
								sdlg.push("</div>");

								var jsDlg = $(sdlg.join(""));
								$("body").append(jsDlg);
								jsDlg.dialog({
									modal: true,
									buttons: {
										Ok: function () {
											$(this).dialog('close');
										}
									}
								});
								me.slideUp(1000, function() {
									$(this).remove();
								});
							}
						})
					}
				},
				close: function () { jDlg.remove(); }
			});
		})
	});

});
