circlefunction = {}


circlefunction.unArchiveCircle = function(listId, circlename) {
	
	var waitingDialog = document.createElement("div");
	waitingDialog.id = "waitingDialog";
	var confirmDialog = document.createElement("div");
	var resultDialog = document.createElement("div");
	
	$(waitingDialog).html("<div style='text-align: center;'><img src='/facebox/loading.gif' style='width:32px; height: 32px;'></div>");	
	$(confirmDialog).html("<div style='text-align: center; margin-bottom: 10px;'>Are you sure you want to unarchive this circle: <span style='font-weight: bold; color: red;'> "+unescape(circlename)+" </span>? <br><br><span style='font-size: 14px;'>This can be undone in the future.</span></div>");
	
	waitingDialog.className="flora";
	confirmDialog.className="flora";
	resultDialog.className="flora";
	
	$("#bodyRight").append(confirmDialog);
	
	$(confirmDialog).dialog(
		{ width: 500, buttons: {
				"No, leave this circle archived" : function() {
					$(confirmDialog).dialog("close");
					$(confirmDialog).remove();
				},
				"Yes, I want to unarchive this circle" : function() {
					var url = '/api/circlefunctions.php?c=unArchiveCircle&listId='+listId;
							
					$(confirmDialog).dialog("close");
					$(confirmDialog).remove();
					$("#bodyRight").append(waitingDialog);
					$(waitingDialog).dialog({});
											
					$.getJSON(url,function(data){
							$(waitingDialog).dialog("close");
							$(waitingDialog).remove();
							if (data.response == 1) {
								$(resultDialog).html("<div style='text-align: center; margin-bottom: 10px;'>Circle "+ unescape(circlename) + " Unarchived.</div>");
							} else {
								$(resultDialog).html("<div style='text-align: center; margin-bottom: 10px;'>Error: "+ data.errorMessage + ".</div>")
							}
							$("#bodyRight").append(resultDialog);
							$(resultDialog).dialog({buttons: { "Ok" : function(){
								$(resultDialog).dialog("close");
								$(resultDialog).remove();
								window.location.reload(false);
							}}});
						
					});
				}
			}
		}
	);
}


circlefunction.archiveCircle = function(listId, circlename) {
	
	var waitingDialog = document.createElement("div");
	waitingDialog.id = "waitingDialog";
	var confirmDialog = document.createElement("div");
	var resultDialog = document.createElement("div");
	
	$(waitingDialog).html("<div style='text-align: center;'><img src='/facebox/loading.gif' style='width:32px; height: 32px;'></div>");	
	$(confirmDialog).html("<div style='text-align: center; margin-bottom: 10px;'>Are you sure you want to archive this circle: <span style='font-weight: bold; color: red;'> "+unescape(circlename)+" </span>? <br><br><span style='font-size: 14px;'>This can be undone in the future.</span></div>");
	
	waitingDialog.className="flora";
	confirmDialog.className="flora";
	resultDialog.className="flora";
	
	$("#bodyRight").append(confirmDialog);
	
	$(confirmDialog).dialog(
		{ width: 500, buttons: {
				"No, I don't want to archive this circle" : function() {
					$(confirmDialog).dialog("close");
					$(confirmDialog).remove();
				},
				"Yes, I want to archive this circle" : function() {
					var url = '/api/circlefunctions.php?c=archiveCircle&listId='+listId;
							
					$(confirmDialog).dialog("close");
					$(confirmDialog).remove();
					$("#bodyRight").append(waitingDialog);
					$(waitingDialog).dialog({});
											
					$.getJSON(url,function(data){
							$(waitingDialog).dialog("close");
							$(waitingDialog).remove();
							if (data.response == 1) {
								$(resultDialog).html("<div style='text-align: center; margin-bottom: 10px;'>Circle "+ unescape(circlename) + " archived.</div>");
							} else {
								$(resultDialog).html("<div style='text-align: center; margin-bottom: 10px;'>Error: "+ data.errorMessage + ".</div>")
							}
							$("#bodyRight").append(resultDialog);
							$(resultDialog).dialog({buttons: { "Ok" : function(){
								$(resultDialog).dialog("close");
								$(resultDialog).remove();
								window.location.reload(false);
							}}});
						
					});
				}
			}
		}
	);
}


circlefunction.removeCircle = function(listId,circlename){

	var waitingDialog = document.createElement("div");
		waitingDialog.id = "waitingDialog";
	var confirmDialog1 = document.createElement("div");
	var confirmDialog2 = document.createElement("div");
	var resultDialog = document.createElement("div");
	
	$(waitingDialog).html("<div style='text-align: center;'><img src='/facebox/loading.gif' style='width:32px; height: 32px;'></div>");
	
	$(confirmDialog1).html("<div style='text-align: center; margin-bottom: 10px;'>WARNING Are you sure that you want to delete circle:<span style='font-weight: bold; color: red;'> "+unescape(circlename)+" </span>? <br><br><span style='font-size: 14px;'>This can not be reversed.</span></div>");
	
			$(confirmDialog2).html("<div style='text-align: center; margin-bottom: 10px;'>Are you absolutely sure you want to delete circle <span style='font-weight: bold; color: red;'> "+ unescape(circlename) +"</span> You will not be able to recover this information once it has been removed.<br><br><span style='font-weight: bold;'>This can not be undone</span></div>");

$(resultDialog).html("<div style='text-align: center; margin-bottom: 10px;'>Circle "+ unescape(circlename) + " Removed.</div>");
	
	confirmDialog1.className="flora";
	confirmDialog2.className="flora";
	waitingDialog.className="flora";
	resultDialog.className="flora";
	
/* 		/$(waitingDialog).remove(); */
		$("#bodyRight").append(confirmDialog1);
	
	
		$(confirmDialog1).dialog({width: 500, buttons: { 
			"No, I want to keep this circle" : function(){
				$(confirmDialog1).dialog("close");
				$(confirmDialog1).remove();
				
			},
			"Yes, I want to Delete this circle": function(){
				
				$(confirmDialog1).dialog("close");
				$(confirmDialog1).remove();
				$("#bodyRight").append(confirmDialog2);
				$(confirmDialog2).dialog({width: 400,
					buttons: {
						"No. Do not Delete!": function(){
							$(confirmDialog2).dialog("close");
							$(confirmDialog2).remove();
						},
						"Yes. I want to delete this circle" : function(){
						
							var url = '/api/circlefunctions.php?c=removeCircle&listId='+listId;
							
							$(confirmDialog2).dialog("close");
							$(confirmDialog2).remove();
							$("#bodyRight").append(waitingDialog);
							$(waitingDialog).dialog({});
													
							$.getJSON(url,function(data){
									$(waitingDialog).dialog("close");
									$(waitingDialog).remove();
									$("#bodyRight").append(resultDialog);
									$(resultDialog).dialog({buttons: { "Ok" : function(){
										$(resultDialog).dialog("close");
										$(resultDialog).remove();
									}}});
								
							});	
						
						}
					}
				});
				
				
			}
		}});
		
	


}