// JavaScript Document
function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

function redirectPage() {
	var sURL = '';
	
	// get all the inputs into an array.
	var inputs = $('#formFilter input');

	// not sure if you wanted this, but I thought I'd add it.
	// get an associative array of just the values.
	var values = '';
	inputs.each(function(i, el) {
		if ($(el).is(':checked')) {
			values = values + ',' + $(el).val();
		}
	});
	
	if ( (values.substring(1) == '') || (values.substring(1) == '1,2,6,9,10') ) {
		sURL = 'salon.php';
	} else {
		sURL = 'salon.php?forums=' + values.substring(1);
	}

	if ($('#topicSorting').val() == 'post') {
		if (sURL == 'salon.php') {
			sURL = sURL + '?sort=post';
		} else {
			sURL = sURL + '&sort=post';
		}
	}
	
	location.replace(sURL);
	return false;
}

$(function () {
	$('.pageNo').editInPlace(
		{	url:'ajaxProxy.php?mode=salonPage',
			saving_image:'images/ajaxLoader_circleBall.gif',
			value_required:true
		}
	);

	$('#formFilter').submit(function() {
		return redirectPage();
	});
	
	$('#topicSorting').change(function() {
		return redirectPage();
	});
});	

