/*global $ alert */
"use strict";  
function acceptAction(action, memberid, siteid) {
var fields = '', thisid, thisval, thisint = 0;
if (!memberid) {
var memberid = '';
}
if (!siteid) {
var siteid = '';
}
$("input:checked.sites").each(function (i) {
	thisid = $(this).attr('id');
	thisval = $(this).val();
	if (thisval != '') {
		fields = fields + '&' + 'sites' + thisid + '=' + thisval;
		thisint++;
	}
});
if (thisint < 1) {
	alert('You must select one or more sites to process the action'); return false;
}
}
function decline(action) {
if (action < 5) {
	$('#actionCell').html('<table style="width: 20em;"><tr><td>Loading...</td></tr></table>');
	$.post('/cs/controller/action.php?ajax=true',
		{'action': action, 'response': 'declined'},
		function (data) {
			$('#actionCell').html(data);
		}
	);
}
}
function loadScript(action, response, target) {
if (!action) {
	var action = 'single';
}
if (!response) {
	var response = 'declined';
}
if (!target) {
	var target = 'actionCell';
	var url = 'action';
} else if (target == 'resultsCell') {
	var url = 'results';
}
	$('#' + target).html('<table style="width: 20em;"><tr><td>Loading...</td></tr></table>');
	$.post('controller/' + url + '.php?ajax=true',
		{'action': action, 'response': response},
		function (data) {
			$('#' + target).html(data);
			if (action == 'notfound' && $('#email').val() != '') {
				$('#reportEmail').val($('#email').val());
			}
		}
	);
}
function searchBy(field) {
	$.post('/cs/controller/search.php?ajax=true',
		{'field': field},
		function (data) {
			$('#resultsCell').html(data);
		}
	);
}
function getResults() {
var fields = '', thisid, thisval, thisint = 0;
$(".searchField").each(function (i) {
	thisid = $(this).attr('id');
	thisval = $(this).val();
	if (thisval != '') {
		fields = fields + '&' + thisid + '=' + thisval;
		thisint++;
	}
});
if (($('#field').val() == 'user' && thisint < 2 && $('#email').val() == '') || ($('#field').val() != 'user' && thisint < 4)) {
	alert('Please be more specific'); return false;
}
}
function reloadResults() {
//loading('resultsCell', 60, 17);
	$('#resultsCell').html('<hr/><table style="width: 17em;"><tr><td>Loading...</td></tr></table>');
	$.post('controller/results.php',
		{},
		function (data) {
			$('#resultsCell').html(data);
			loadScript('1', 'load');
		}
	);
}
function loading(target, limit, width) {
setTimeout("$('#" + target + "').html('<hr/><table style=\"width: " + width + "em;\"><tr><td>Loading...</td></tr></table>');", (limit * 1000));
	
}
