// 
// $Id: immo_slider2010.js,v 1.2 2010/10/28 11:24:31 ics Exp $ 
// 
// $Log: immo_slider2010.js,v $
// Revision 1.2  2010/10/28 11:24:31  ics
// WNN-1524 ph
//
// Revision 1.1  2010/10/22 14:04:32  ics
// *** empty log message ***
//
// Revision 1.2  2009/03/02 16:04:19  ics
// ph:fix f. Lang
//
// Revision 1.1  2009/02/18 14:59:37  ics
// ph:v1
//
// 


function class_immo_slider() {

  this.pr_firstrun = 0; 
  this.cont_ajax_calls = 0;  

  this.pr_base_min = 0; 
  this.pr_base_step = 1; 
  this.pr_min10 = 0; 
  this.pr_max10 = 0; 

  this.fl_min = 0; 
  this.fl_max = 0; 
  this.fl_min_set = 0; 
  this.fl_max_set = 0; 


  this.write_fl_vals = function (min,max) {
	$j("#smin").val(this.aj_flache(min));
	$j("#smax").val(this.aj_flache(max));
	document.getElementById("D_FLMIN").innerHTML = this.aj_flache(min)+'&nbsp;<strong>mē</strong>&nbsp;'; 
	document.getElementById("D_FLMAX").innerHTML = this.aj_flache(max)+'&nbsp;<strong>mē</strong>';
  }; 

  this.aj_setpreis = function (index,wert) {
	var w = (Math.log(1*wert) -   pr_base_min ) / pr_base_step ;
	$j("#example_pr").slider("values", index,w ); 
  }

  this.aj_niceprice = function(preis) {
	if(Math.exp(this.pr_base_min) > 10000) {
		var m = 1000; 
	} else {
		var m = 10; 
	} 
	var tmp =  Math.round(Math.exp(preis * this.pr_base_step + this.pr_base_min) / m) * m; 
	return tmp; 
  }


  this.aj_flache = function (f) {
	return Math.round(f / 5) * 5;  
  }


  this.write_pr_vals = function(mi,ma) {
	var min = this.aj_niceprice(mi); 
	var max = this.aj_niceprice(ma);
	$j("#prmin").val(min);
	$j("#prmax").val(max);
	document.getElementById("D_PRMIN").innerHTML = this.dezimal(min)+'&nbsp;<strong>&euro;</strong>&nbsp;'; 
	document.getElementById("D_PRMAX").innerHTML = this.dezimal(max)+'&nbsp;<strong>&euro;</strong>';
	if(this.pr_firstrun == 0) {
		this.do_ajax("WIE=1");
		this.pr_firstrun++;
	}
  }



  	this.do_ajax = function(q) {
	var url = 'LANG='+page_lang+'&'; 
	var f = document.WIZARD; 

	for(var i = 0; i<f.elements.length; i++) {
		var e = f.elements[i]; 
		if(e.name.indexOf('J__') > 0) {
			url += e.name + "="+escape(e.value)+"&"; 
		}
	} 
	if(q != 'WIE=1') {
 	 document.getElementById('loader').style.display = 'block';
 	 document.getElementById('loader').style.left = ireds_getLeft(document.getElementById('biginhalt')) + 'px';
 	 document.getElementById('loader').style.top = ireds_getTop(document.getElementById('biginhalt')) + 'px';
 	 document.getElementById('loader').style.height = document.getElementById('biginhalt').offsetHeight + 'px';
 	 document.getElementById('loader').style.width = document.getElementById('biginhalt').offsetWidth+ 'px';
 	}
	// alert(url);
	if(this.cont_ajax_calls > 0 ) { 
		ajax_call("/wn05iframe/a_sucheinimmosuche.php?"+url+q); 
	}
	this.cont_ajax_calls++;
 //	window.location.hash="aj"+Math.floor(Math.random()*10000000);
 }

  this.checkbackb = function() {
  //	alert("checkbackb"); 
	if(window.location.hash.indexOf('aj') == 1) {
  // 		ajax_call("/wn05iframe/a_sucheinimmosuche.php?SETVAL=1"); 
	} 
  }

  this.draw = function() {
	/* http://docs.jquery.com/UI/Slider/slider#options */

	$j(function() {
			$j('#example3').slider({ 
			min: immoslider.aj_flache(immoslider.fl_min),
			max: immoslider.aj_flache(immoslider.fl_max),
			values: [immoslider.fl_min_set, immoslider.fl_max_set ], 

			range: true,stop: function () {	immoslider.do_ajax();	},
			slide: function(e, ui) {immoslider.write_fl_vals(Math.round(ui.values[0]),Math.round(ui.values[1]));}
		});
		$j("#smin").val($j("#example3").slider("values", 0));
		$j("#smax").val($j("#example3").slider("values", 1));
		if(immoslider.pr_firstrun == 0 && immoslider.pr_max10 == 0) {
			// hole ajax werte, fall kein Preis da ist 
			immoslider.do_ajax("WIE=1");
			immoslider.pr_firstrun++;
		}
	});

	if(this.pr_max10 > 0){
	  $j(function() {
			$j('#example_pr').slider({ 
			min: 0,
			max: 100,
			values: [immoslider.pr_min10,immoslider.pr_max10], 
			range: true,stop: function () {	immoslider.do_ajax();	},
			slide: function(e, ui) {immoslider.write_pr_vals(Math.round(ui.values[0]),Math.round(ui.values[1]));}
		});
 		immoslider.write_pr_vals(Math.round($j("#example_pr").slider("values", 0)),Math.round($j("#example_pr").slider("values", 1)) ); 
	  });
	}

  }

  this.dezimal = function (nStr) {
	nStr += '';
	x = nStr.split(',');
	x1 = x[0];
	x2 = x.length > 1 ? ',' + x[1] : '';  
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + '.' + '$2');
	}
	return x1; 
  }

}

