function cargaSlider() {
	$(".mSlider").each(function() {
		var id = $(this).attr("id");
		var confm = $("#"+id+"Conf").val();	
		var conf = confm.split("-");
		var valormin = parseInt($("#"+conf[3]).val());
		var valormax = parseInt($("#"+conf[4]).val());
		if (!valormax) {
			valormax = parseInt(conf[1]);
		}
		if (!valormin) {
			valormin = parseInt(conf[0]);
		}
		$(this).slider({
			animate: false,
			range: true,
			step: parseInt(conf[2]),
			min: parseInt(conf[0]),
			max: parseInt(conf[1]),		
			values: [valormin, valormax],
			slide: function(event, ui) {				
				cambiaValor(conf, ui.values[0], ui.values[1]);				
			},
			change: function() {
				$("#filters input[name='i']").attr("value", 0);
				actualizaForm();
			}
		});
		cambiaValor(conf, valormin, valormax);
	});
}

function cambiaValor(conf, valmint, valmaxt) {
	var valmin = valmint;
	var valmax = valmaxt;
	var txtslider = $("#txtSlider").val().split("_");
	$("#"+conf[3]).val(valmint);
	$("#"+conf[4]).val(valmaxt);
	if (conf[6] == 1) {
		valmax = formatNumber(valmax, 0, ".", "", "€");
		valmin = formatNumber(valmin, 0, ".", "", "€");
	} else if (conf[6] == 2) {
		valmax += "m<sup>2</sup>";
		valmin += "m<sup>2</sup>";
	}
	var esmin = false;
	var esmax = false;
	if (valmint==parseInt(conf[0])) {
		esmin = true;
	}
	if (valmaxt==parseInt(conf[1])) {
		esmax = true;
	}
	var html;
	if (esmin && !esmax) {
		html = txtslider[1]+" "+valmax;
	} else if (esmax && !esmin) {
		html = txtslider[0]+" "+valmin;
	} else if (esmin && esmax) {
		html = conf[7];
	} else {
		html = txtslider[0]+" "+valmin+" "+txtslider[1]+" "+valmax;
	}
	$("#"+conf[5]).html(html);	
}

function formatNumber(num, dec, thou, pnt, curr) {
	var x = Math.round(num * Math.pow(10,dec));
	if (x >= 0) n1=n2=''; 
	var y = (''+Math.abs(x)).split('');
	var z = y.length - dec; 
	if (z<0) z--; 
	for(var i = z; i < 0; i++) 
		y.unshift('0'); 
		y.splice(z, 0, pnt);
	if(y[0] == pnt) y.unshift('0'); 
	while (z > 3) {
		z-=3;
		y.splice(z,0,thou);
	}  
	var r = y.join('')+curr;
	return r;
}
