// JavaScript Document
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) == '9') ) {
		sURL = 'board_ask.php';
	} 
	if ( (values.substring(1) == '') || (values.substring(1) == '27,28,29') ) {
		sURL = 'board_salon.php';
	} 
	if ( (values.substring(1) == '') || (values.substring(1) == '1') ) {
		sURL = 'board_howto.php';
	}
	if ( (values.substring(1) == '') || (values.substring(1) == '2') ) {
		sURL = 'board_review.php';
	}
	if ( (values.substring(1) == '') || (values.substring(1) == '6') ) {
		sURL = 'board_her.php';
	}
	if ( (values.substring(1) == '') || (values.substring(1) == 10'') ) {
		sURL = 'board_nokrung.php';
	}
	else {
		sURL = 'webboard.php?forums=' + values.substring(1);
	}

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

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

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

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

$('#calendar').datepicker({
		defaultDate: qsDate,
		gotoCurrent: false,
		changeMonth: false,
		changeYear: false,
		dayNamesMin: ['<img src="images/2009_weekdaySun.gif" alt="S" />',
					  '<img src="images/2009_weekdayMon.gif" alt="M" />',
					  '<img src="images/2009_weekdayTue.gif" alt="T" />',
					  '<img src="images/2009_weekdayWed.gif" alt="W" />',
					  '<img src="images/2009_weekdayThu.gif" alt="T" />',
					  '<img src="images/2009_weekdayFri.gif" alt="F" />',
					  '<img src="images/2009_weekdaySat.gif" alt="S" />'],
		prevText:'&lt;&lt;',
		nextText:'&gt;&gt;',
		dateFormat: ' yy-mm-dd',
		onSelect: function(dateText){
			var newURL		= 'webboard.php?date='+jQuery.trim(dateText);
			location.replace(newURL);
		},
		minDate: new Date(2009, 3 - 1, 16),
		maxDate: new Date()
	});
