/**
 * JQuery for manipulation of min-max prices
 * Make sure min can't be less than max
 */
var prices = Array();
prices['minp'] = 0;
prices['maxp'] = 0;

$(document).ready(
	function()
	{
		// min and max may be non-zero (search already populated)
		prices['minp'] = $('#minp').attr('selectedIndex');
		prices['maxp'] = $('#maxp').attr('selectedIndex');
		$("select").change(
			function()
			{
				prices[this.id] = this.selectedIndex;
				// We don't want to change the one the user touched
				if(this.id=="minp")
				{
					// Check min is less
					if(prices['minp']>prices['maxp'] && prices['maxp']>0)
					{
						// Quick hack - if maximum value on select is chosen by min, bring max level
						$('#maxp').attr('selectedIndex',prices['minp']+1);
					}
				}
				else
				{
					if(this.id=="maxp")
					{
						// Changed maxp
						// Check min is less
						if(prices['minp']>prices['maxp'] && prices['minp']>0)
						{
							// Don't want to set to -1
							if(prices['maxp']==0) setr = 0; else setr = prices['maxp']-1;
							$('#minp').attr('selectedIndex',setr);
						}
					}
				}
				// Show loading icon - visibility set rather than "display: none" so the other 
				// elements don't jump around the page when this is toggled
				$('#refine_loading').css('visibility','visible');
				// submit form
				$('#refine_form').submit();
			}
		);
	}
)

