/* global variables */

var swiftClient = function()
{
	// private functions and properties
	var _private =
	{
		request : function(id, method, url, data)
		{
			$(id).html($('#appLoader').html());
			$.ajax({
					type: method,
					url: url,
					data: data,
					cache: false,
					success: function(html){
				    	$(id).html(html);
				  	},
					error: function(req, textStatus, errorThrown){
				  		alert('Unable to complete request.');
				  	}
				});
		}
	}
	
	var _public =
	{
		get : function(id,url)
			{
			_private.request(id,'GET', url, null);
			return false;
			},
		form : function(id,form)
			{
			var data = $(form).serialize();
			var method = $(form).attr('method');
			var url = $(form).attr('action');
			_private.request(id, method, url, data);
			return false;
			},
		deleteItem : function(id,itemName,url,itemId)
			{
			if (confirm('Are you sure you want to delete '+itemName+' '+itemId+'.'))
				_private.request(id,'GET', url, null);
				return false;
			},
		whereFilesChecked : function(formId)
			{
				var select = '#' + formId + ' [type=checkbox]:not([name=\'combine\'])';
				var checkBoxes = $(select);
			    var reportsChecked = false;
				for(var x = 0; x < checkBoxes.length; x++){
					  if(checkBoxes[x].checked){
					     reportsChecked = true;
					  }
				}
				if (!reportsChecked) {
					alert('No ads selected.');
				}
				return reportsChecked;
			}			
	};
	
	return _public;
}();
