function matchPrice(o){
	i=o.attr('id');
	s=(i.indexOf('_sale')>-1 ? 'sale' :'rent')
	if(i.indexOf('_from')>-1){
		pf=o
		pt=$("#id_"+s+"_price_to");
		if(pt.val() != '' && parseInt(pf.val()) > parseInt(pt.val())){
			pt.val(pf.val());
		}
	}else{
		pf=$("#id_"+s+"_price_from");
		pt=o
		if(pf.val() != '' && parseInt(pt.val()) < parseInt(pf.val())){
			pf.val(pt.val());
		}
	}
	
}
$(document).ready(function(){
	$("#id_show").change(function(){
		v=$(this).val();
		if(v=='rental'){
			$("#rent_price").show();
		} else {
			$("#rent_price").hide();
		}
		if(v=='sale'){
			$("#sale_price").show();
		} else {
			$("#sale_price").hide();
		}
	});
	$("#id_sale_price_from").change(function(){
		matchPrice($(this))
	});
	$("#id_sale_price_to").change(function(){
		matchPrice($(this));
	});
	$("#id_rent_price_from").change(function(){
		matchPrice($(this));
	});
	$("#id_rent_price_to").change(function(){
		matchPrice($(this));
	});
	v=$("#id_show").val()
	if(v=='rental'){$("#rent_price").show();}
	if(v=='sale'){$("#sale_price").show();}
});


