/**
 * simpleBans.js
 *
 * Series of extensions to the simple machines forum.
 * (EXSMF) SIMPLE BANNING INTERFACE MODIFICATION
 *
 * @author kent quey
 * @link http://exsmf.kentquey.com
 * @copyright 2007
 *
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

/************* START:(EXSMF) SIMPLE BANNING INTERFACE MODIFICATION *************/
function submitSimpleBans() {
	//default options
	var simpleban_user = window.document.getElementById('simpleban[user]');
	var simpleban_forever = window.document.getElementById('simpleban[expiration][forever]');
	var simpleban_temporarily = window.document.getElementById('simpleban[expiration][temporarily]');
	var simpleban_days = window.document.getElementById('simpleban[days]');
	
	var simpleban_expiration;
	if(simpleban_forever.checked == true) { simpleban_expiration = 'forever'; }
	else if(simpleban_temporarily.checked == true) { simpleban_expiration = 'temporarily'; }
	
	//advanced options
	var simpleban_fullban = window.document.getElementById('simpleban[restrictions][fullban]');
	var simpleban_partialban = window.document.getElementById('simpleban[restrictions][partialban]');
	
	var simpleban_reason = window.document.getElementById('simpleban[reason]');
	var simpleban_notes = window.document.getElementById('simpleban[notes]');
	
	var simpleban_partialban_type;
	jQuery('input[@id="simpleban[restrictions][partialban][type]"]').each(function() {
		if(this.checked == true) { simpleban_partialban_type = this.value; }
	});
	
	var simpleban_restriction;
	if(simpleban_fullban.checked == true) { simpleban_restriction = 'fullban'; }
	if(simpleban_partialban.checked == true) { simpleban_restriction = simpleban_partialban_type; }
	
	//mode options
	var simpleban_mode_add = window.document.getElementById('simpleban[mode][add]');
	var simpleban_mode_remove = window.document.getElementById('simpleban[mode][remove]');
	var simpleban_mode_modify = window.document.getElementById('simpleban[mode][modify]');
	var simpleban_mode;
	if(simpleban_mode_add.checked == true) {
		simpleban_mode = simpleban_mode_add.value;
	} else if(simpleban_mode_remove.checked == true) {
		simpleban_mode = simpleban_mode_remove.value;
	} else if(simpleban_mode_modify.checked == true) {
		simpleban_mode = simpleban_mode_modify.value;
	}
	
	jQuery.post('index.php?action=simpleban',{userToBan:simpleban_user.value, expiration:simpleban_expiration, days:simpleban_days.value, restriction:simpleban_restriction, reason:simpleban_reason.value, notes:simpleban_notes.value, mode:simpleban_mode}, function(status) {
		if(simpleban_mode_remove.checked == true) {
			jQuery('div#simpleBanErrorMessages').html(status);
			//clear specific fields
			jQuery('input[@type="text"]').each(function() { this.value = ""; });
			jQuery('input[@type="hidden"]').each(function() { this.value = ""; });
		} else {
			jQuery('div#simpleBanErrorMessages').html(status);
		}
	});
}
/************* END:(EXSMF) SIMPLE BANNING INTERFACE MODIFICATION *************/