$(document).ready(function() {

	/*
	 * Colapse the comments inout box and remove the border
	 */
	//$('#inputs').toggle();
	//$('#commentFieldset').addClass("noborder");
	
	/*
	 * Toggle the comment input fields and the dotted border.
	 */
	$('#commentLegend').toggle(
		function(){
			$('#inputs').show('slow');
			$('#commentFieldset').removeClass('noborder');
		},
		function () {
			$('#inputs').hide('slow');
			$('#commentFieldset').addClass('noborder');
		}
	);
	
	$('form.jform').submit(function(e) {
		e.preventDefault();
		var id = $(this).attr('id');
		var form = this;
		var queryString = '';
		$(':input', form).each(function(i) {
			var type = this.type;
			var value = this.value;
			var name = this.name;
			var object = $(this);
			if(type != 'submit' && type != 'radio') {
				if(type == 'checkbox') {
					value = $('#' + form.attr('id') + ' :checkbox[name=' + name + ']:checked').size();
				}
				queryString = queryString + name + '=' + value + '&';
			}
		});
		$.ajax({
			url: 'index.php',
			data: queryString,
			type: 'POST',
			dataType: 'json',
			success: function(html) {
				if (html.succes == false){
					alert(html.text);
				}
				if (html.succes == true){
					window.location.reload();
				}
			}
		});
		/*return formValid;
		this.blur();*/
	});
});


