if(!window.WSC){var WSC={};}
(function($){
	WSC.AjaxDelete = {
		message : '<b>This action cannot be undone.</b><br>Are you sure you want to delete this record?',
		
		init : function(selector) {
			var self = this;
			selector = selector || 'a.delete';
			/* Apply the click handler to any of the links with the className */
			$(function(){
				$(selector).click(function(){ self.Confirm(this); return false;});
			});
		},
		
		/* Confirm - present the user with an yes or no dialog */
		Confirm : function(a){
			var self = this;
			var myDialog = WSC.Dialog;
			var message = this.message;
			var action = function(){self.Delete(a);};
			if(myDialog) {			
				var confirmOptions = {
					type: 'confirm',
					okText: 'Yes',
					cancelText: 'No',
					onOk: action
				};
				myDialog(message, confirmOptions);
			}
			else {
				message = message.replace(/<br\s*[\/]?>/, '\n').replace(/<[a-zA-Z\/][^>]*>/g, '');
				if(confirm(message)){ action(); }
			}
		},
		
		/* Delete - called when the user clicks yes */
		Delete : function(a){
			var self = this;
			/* Set the ajax options */
			var ajxoptions = {
				url : a.href,
				success : function(data, textStatus){self.Remove(a); },
				error : function(XMLHttpRequest, textStatus, errorThrown){alert('Sorry there was an error!\n'+ textStatus);}
			};
			/* Make the ajax call */
			$.ajax(ajxoptions);
		},
		
		/* Remove the row */
		Remove : function(a){
			$(a).parents('tr:eq(0)').remove();
		}
	} /* end WSC.AjaxDelete */
	
	WSC.AjaxActivate = {
		path : 'elements/',
		
		init: function(selector) {
			selector = selector || 'a.activate';
			/* Preload the image */
			(new Image()).src = this.path + 'indicator_arrows.gif';
			/* Apply the click handler to any of the links with the className */
			$(function(){
				$(selector).click(function(){ self.Activate(this); return false;});
			});
		},
	
		Activate: function(a){
			var img = $('img', a)[0];
			var org = img.src;
			var path = this.path;
			img.src = path + 'indicator_arrows.gif';
	
			var ajxoptions = {
				url : a.href,
				success : function(data, textStatus){img.src = path +'orb_'+ data +'.gif';},
				error : function(XMLHttpRequest, textStatus, errorThrown){alert('Sorry there was an error!\n'+ textStatus);}
			};
			/* Make the ajax call */
			$.ajax(ajxoptions);
		}
	} /* end WSC.AjaxActivate */
	
})(jQuery);

