jQuery.noConflict();
jQuery(document).ready(function(){
jQuery('#filter_by_sale').live('change',function(){
		var item=this.value;
		jQuery.ajax({
			type: "POST",
				url:'popup',
				data: 'passed=imarket&filter=1&value='+this.value,
				success: function(msg){
				jQuery('#main_div').html(msg);
				jQuery('#filter_by_sale').attr('value',item);
				}
			
		});
	});
jQuery('#filter_by_price').live('change',function(){
		var item=this.value;
		jQuery.ajax({
			type: "POST",
				url:'popup',
				data: 'passed=imarket&filter=2&value='+this.value,
				success: function(msg){
				jQuery('#main_div').html(msg);
				jQuery('#filter_by_price').attr('value',item);
				}
			
		});
	});
});

/*
entered_value = amount entered in the text box
property_max = max amount of cost_item in property storage
player_max   = max amount of cost_item in player storage
property_space = available space in property storage
player_space = available 
price_amt - from the table
sale_amt - from the table
lot_size - min amount of items to sell
lot_price - min cost amount to buy a lot of items

*/
function validateValue(entered_value, 
property_max_value, player_max_value,
property_space,player_space,
price_amt, sale_amt, 
lot_size, lot_price){
    /*	var buy_capability0=Math.round(property_max_value/price_amt);
	var buy_capability1=Math.round(player_max_value/price_amt);
    */
	var buy_capability0=Math.round(property_max_value/lot_price);
	//alert("buy_capability0 " + buy_capability0);
	var buy_capability1=Math.round(player_max_value/lot_price);
	//alert("buy_capability1 " + buy_capability1);

	var params = "entered_value = " + entered_value + "\n"
	    + "property_max = " + property_max_value + "\n"
	    + "player_max = " + player_max_value + "\n"
	    + "sale_amt = " + sale_amt + "\n"
	    + "lot_size = " + lot_size + "\n"
	    + "lot_price = " + lot_price + "\n"
	    ;

	if(entered_value <= 0) {
	    alert("You must enter a positive amount.");
	    return false;
	}

	total_item_count = entered_value * lot_size;
	if(total_item_count > sale_amt) {
	    alert("There are not that many items for sale.");
	    return false;
	}
	total_cost_count = entered_value * lot_price;
	if((total_cost_count > property_max_value) && (total_cost_count > player_max_value)) {
	    alert("You do not have enough items for this purchase.");
	    return false;
	}

	return true;
	alert(params);
	return false;

	alert('lot_size: ' + lot_size);
	var total_purchase_amount = entered_value * lot_size;
        alert(total_purchase_amount + " " + sale_amt);
	if(total_purchase_amount > sale_amt) {
	    alert("There are not enough items to sell.");
	    return false;
	}
	return false;
	if (entered_value <= sale_amt) {
	    multiple = Math.round(entered_value/lot_size);
	    if (multiple > 0){
		amount = lot_size * multiple;
		price = lot_price * multiple;
		// if player has price
		if ((property_max > price) || (player_max > price)) {
		    alert("buy " + entered_value + " for " + price + "?");
		    return true;
		} else {
		    alert("You can't afford that much!");
		}
	    } else {
		alert("You can't buy that few!");
		return false;
	    }
	}
	return false;

	/*
	if(entered_value <= property_space)
		available_space=property_space;
	else if(entered_value <= player_space)
		available_space=player_space;
	else if(property_space > player_space)
		available_space=property_space;
	else
		available_space=player_space;
	*/

	/*
	if(buy_capability1 >= entered_value*price_amt)
		buy_capability=buy_capability1;
	else if(buy_capability0 >= entered_value*price_amt)
		buy_capability=buy_capability0;
	else if(buy_capability1 >= buy_capability0)
		buy_capability=buy_capability1;
	else
		buy_capability=buy_capability0;
	*/

	/*
	if(available_space < buy_capability)
		buy_capability=available_space;
	*/

	if(buy_capability < 1)
	{
		alert("You do not have price item to purchase  this  item");
		return false;
	}
	/*
	if(available_space < 1)
	{
		alert("You do not have space to purchase this  item");
		return false;
	}
	*/
	else if(entered_value > sale_amt)
	{
		if(sale_amt > buy_capability )
			alert("Please enter the value from 1 to "+buy_capability);
		else
			alert("Please enter the value from 1 to "+sale_amt);
		return false;
	}

	else if(buy_capability < entered_value)
	{
		alert("Please enter the value from 1 to "+buy_capability);
		return false;
	}
	else 
        {
		return true;
	}
}
