


     var currObj;              // stores the current object being manipulated (leftSlider or rightSlider object)
      var leftPos = 0;          // the current left position after mouse is released
      var rightPos = 150;       // the current right position after mouse is released
      var sliderWidth = 7;      // the width of the sliders (includes borders)
      var sliderBarWidth = 150; // the width of the slider bar (does not include borders)
      var mouseStart = -99999   // an arbitrary number used to show that it is the first time we are hitting the moveSlider1 function.
      var pos;                  // position with offset used during the move
      var min = 1;            // minimum value of the data
      var max = 15;            // maximum value of the data

      /* function moveSlider(obj)
           parameter obj - object reference to the calling object
         This function sets the resets the starting mouse position and sets the document
         methods used to watch for mouse events.
      */
      function moveSlider(obj) {
        mouseStart = -99999;   // set the beginning mouse position to an unlikely number.
        currObj = obj;         // set the currObj variable to the object that was clicked
        document.onmousemove = moveSlider1; // set the onmousemove method to the function that moves the slider
        document.onmouseup = moveDone;   // set the onmouseup method to the function that stops listening for the mousemove and reclaculates the data
      }

	  function moveSliderLeft(obj) {
        mouseStart = -99999;   // set the beginning mouse position to an unlikely number.
        currObj = obj;         // set the currObj variable to the object that was clicked
        document.onmousemove = moveSlider1Left; // set the onmousemove method to the function that moves the slider
        document.onmouseup = moveDone;   // set the onmouseup method to the function that stops listening for the mousemove and reclaculates the data
      }

      /* function moveslider1
         This function is called by the mousemove event
         checks the current mouse position and compares it
         to the mouse position when the move was started.
         uses the difference as an offset from the slider's
         staring position to move the slider with the mouse
      */
      function moveSlider1(e){
        if (!e) var e = window.event;  // if IE, then we need to assign e
        if (e.pageX) posX = e.pageX;   // FF, opera, netscape
        else if (e.clientX) {          // IE
          posX = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
        }
        if (mouseStart == -99999) mouseStart = posX;  // -99999 is an arbitrary number.  It is unlikely to be hit
        var offset = posX - mouseStart; // determine the difference from where the mouse started to where it is now

        if (currObj.id == "sliderLeft")
        {  // If we are moving the left slider
          pos = leftPos + offset;        // the new position should be the current left position + the offset
          if (pos < 0) pos = 0;          // if this makes the left position less than 0 then use 0
          if (pos > rightPos - sliderWidth) pos = rightPos - sliderWidth; // if the position would put us past the right slider then move up to the right slider

          var newValue;

          if (sector == "rent")
          {
          	newValue = Math.round(pos / sliderBarWidth * (max - min) + min) * 150;
          }
          else
          {
          	newValue = Math.pow(Math.round(pos / sliderBarWidth * (max - min) + min), 2) * 10;
          }

          document.getElementById('SliderMinPrice').value = OutputFormattedNumber( newValue );

		  //document.getElementById('fp').innerHTML = OutputFormattedNumber( newValue ) + ",000";
		  //getRetCount();

          CheckPriceMinMax();
        }
        else
        {
          pos = rightPos + offset   // the new position should be the current right position + the offset
          if (pos < leftPos + sliderWidth) pos = leftPos + sliderWidth;  // if the new position would take us past the left slider then move next to the left slider
          if (pos > sliderBarWidth) pos = sliderBarWidth;  // if the new position is past the end of the bar, position at the end of the bar.

          var newValue;

          if (sector == "rent")
          {
          	newValue = Math.round(pos / sliderBarWidth * (max - min) + min) * 150;
          }
          else
          {
          	newValue = Math.pow(Math.round(pos / sliderBarWidth * (max - min) + min), 2) * 10;
          }

          document.getElementById('SliderMaxPrice').value = OutputFormattedNumber( newValue );

		 // document.getElementById('tp').innerHTML = OutputFormattedNumber( newValue ) + ",000";
		  //getRetCount();

          CheckPriceMinMax();
         }

        currObj.style.left = pos + "px";  // move the slider to the new position
      }

  function moveSlider1Left(e){
        if (!e) var e = window.event;  // if IE, then we need to assign e
        if (e.pageX) posX = e.pageX;   // FF, opera, netscape
        else if (e.clientX) {          // IE
          posX = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
        }
        if (mouseStart == -99999) mouseStart = posX;  // -99999 is an arbitrary number.  It is unlikely to be hit
        var offset = posX - mouseStart; // determine the difference from where the mouse started to where it is now

        if (currObj.id == "sliderLeft")
        {  // If we are moving the left slider
          pos = leftPos + offset;        // the new position should be the current left position + the offset
          if (pos < 0) pos = 0;          // if this makes the left position less than 0 then use 0
          if (pos > rightPos - sliderWidth) pos = rightPos - sliderWidth; // if the position would put us past the right slider then move up to the right slider

          var newValue;

          if (sector == "rent")
          {
          	newValue = Math.round(pos / sliderBarWidth * (max - min) + min) * 150;
          }
          else
          {
          	newValue = Math.pow(Math.round(pos / sliderBarWidth * (max - min) + min), 2) * 10;
          }

          document.getElementById('SliderMinPrice').value = OutputFormattedNumber( newValue );

		  CheckPriceMinMax();
        }
        else
        {
          pos = rightPos + offset   // the new position should be the current right position + the offset
          if (pos < leftPos + sliderWidth) pos = leftPos + sliderWidth;  // if the new position would take us past the left slider then move next to the left slider
          if (pos > sliderBarWidth) pos = sliderBarWidth;  // if the new position is past the end of the bar, position at the end of the bar.

          var newValue;

          if (sector == "rent")
          {
          	newValue = Math.round(pos / sliderBarWidth * (max - min) + min) * 150;
          }
          else
          {
          	newValue = Math.pow(Math.round(pos / sliderBarWidth * (max - min) + min), 2) * 10;
          }

          document.getElementById('SliderMaxPrice').value = OutputFormattedNumber( newValue );

          CheckPriceMinMax();
         }

        currObj.style.left = pos + "px";  // move the slider to the new position
      }
      /* function moveDone()
         sets the current left/right position memory variable.
         clears the mouse monitoring methods.
         Calls the function to recaculate the data
      */
      function moveDone(e) {
        if (currObj.id == "sliderLeft") leftPos = pos;    // set the current left position to the value of pos
        else rightPos = pos;                              // set the current right position to the value of pos
        document.onmousemove = function() {};             // stop listening for a mousemove event
        document.onmouseup = function() {};               // stop listening for a mouseup event
      }
var sector = '';
      function updateSliderPos(currObj)
      {
      	val = currObj.value.replace(',', '');

      	if (sector == "sale")
      	{
      		val = Math.round(Math.sqrt(val / 10));
      	}
      	else
      	{
			val = val / 150;
      	}

      	if (currObj.id == "SliderMinPrice")
      	{
      		val -= 1;
      	}

      	if ( val != '0' && ( isNaN(val) || val == '' ) ) return;

      	pos = (val / ((max - min) + min)) * sliderBarWidth;

      	if ( currObj.id == "SliderMinPrice" )
      	{
      		slider = "sliderLeft";

      		if (pos < 0) pos = 0;          // if this makes the left position less than 0 then use 0

      		if (pos > rightPos - sliderWidth) pos = rightPos - sliderWidth;

			leftPos = pos;
      	}
      	else
      	{
      		slider = "sliderRight";

			if (pos < leftPos + sliderWidth) pos = leftPos + sliderWidth;  // if the new position would take us past the left slider then move next to the left slider

			if (pos > sliderBarWidth ) pos = sliderBarWidth ;

			rightPos = pos;
      	}
      	document.getElementById(slider).style.left = pos + "px";
      }

function OutputFormattedNumber(number)
{
  str = number.toString();
  i = str.indexOf(".");
  if ( i < 1 )
  {
    i = str.length;
  }
  while ( i > 3 )
  {
    i-=3;
    j = str.charAt( i-1 );
    if ( j>="0" && j<="9" )
    {
      str = str.substr( 0,i ) + "," + str.substr( i );
    }
  }

  return str;
}
