/**********************************************************************************************/
var CurrentSlider = null;
var ns6 = false;
try
{
    ns6 = document.getElementById&&!document.all?true:false;
}
catch(e){}
var ns4 = false;
try
{
    ns4 = document.layers?1:0;
}
catch(e){}
var ie4 = false;
try
{
    ie4 = document.all;
}
catch(e){}



function OnAllMouseWheel(event){
    try
    {
        if( CurrentSlider != null )
        {
            CurrentSlider.DoMouseScroll( CurrentSlider.CalculateMouseScrollDelta( event ) );
            if (event.preventDefault)
                  event.preventDefault();
            event.returnValue = false;
        }
    }
    catch(e){}
}
function OnAllKeyUp( obj )
{
    try
    {
        if( CurrentSlider != null )
        {
 	        var KeyCode = 0;
		    if( ns4 || ns6 )
		    {
		        KeyCode = parseInt(  obj.which );
		    }
		    else
		    {
      	        KeyCode = parseInt( event.keyCode );
		    }
    		CurrentSlider.DoChangeByKeyPress( KeyCode );
        }
    }
    catch(e){}
}
if( ns6 == true )
{
    try
    {
        if (window.addEventListener)
             /** DOMMouseScroll is for mozilla. */
             window.addEventListener('DOMMouseScroll', OnAllMouseWheel , false);    
        window.onmousewheel = document.onmousewheel = OnAllMouseWheel;
    }
    catch(e){}
}
if( ns4 || ns6 )
{
    try
    {
        document.onkeyup = OnAllKeyUp;
    }
    catch(e){}
}




if (!Control) var Control = { };
Control.Slider_v2 = Class.create({
  initialize: function(handle, track, options) {
    try
    {
//        debugger;
        var slider = this;
        
        if (Object.isArray(handle)) {
          this.handles = handle.collect( function(e) { return $(e) });
        } else {
          this.handles = [$(handle)];
        }
        
        this.FireChangeEvent = true;
        this.track   = $(track);
        this.options = options || { };

        this.EnableMouseWheelEvent = this.options.EnableMouseWheel == true || this.options.EnableMouseWheel == false ? this.options.EnableMouseWheel : true;
        this.EnableKeyboardEvent = this.options.EnableKeyboardEvent == true || this.options.EnableKeyboardEvent == false ? this.options.EnableKeyboardEvent : true;
        
        this.Steps = !( isNaN(this.options.Steps) ) && this.options.Steps != null ? this.options.Steps : 1;
        this.DefaultValue = true;

        this.axis      = this.options.axis || 'horizontal';
        this.increment = this.options.increment || 1;
        this.step      = parseInt(this.options.step || '1');
        this.range     = this.options.range || $R(0,1);
        
        this.value     = 0; 
        this.values    = this.handles.map( function() { return 0 });
        if( this.DefaultValue )
        {
            this.values[0] = this.range[0];
        }
        else
        {
            this.values[ this.values.length - 1 ] = this.range[1];
        }
        this.spans     = this.options.spans ? this.options.spans.map(function(s){ return $(s) }) : false;
        this.options.startSpan = $(this.options.startSpan || null);
        this.options.endSpan   = $(this.options.endSpan || null);

        this.restricted = this.options.restricted || false;

        this.maximum   = this.options.maximum || this.range.end;
        this.minimum   = this.options.minimum || this.range.start;

        // Will be used to align the handle onto the track, if necessary
        this.alignX = parseInt(this.options.alignX || '0');
        this.alignY = parseInt(this.options.alignY || '0');
        
        this.trackLength = this.maximumOffset() - this.minimumOffset();

        this.handleLength = this.isVertical() ? 
          (this.handles[0].offsetHeight != 0 ? 
            this.handles[0].offsetHeight : this.handles[0].style.height.replace(/px$/,"")) : 
          (this.handles[0].offsetWidth != 0 ? this.handles[0].offsetWidth : 
            this.handles[0].style.width.replace(/px$/,""));
            if( this.handleLength <= 0 )
            {
                this.handleLength = 10;
            }

        this.MouseScrollEnabled = false;
        this.active   = false;
        this.dragging = false;
        this.disabled = false;

        if (this.options.disabled) this.setDisabled();

        // Allowed values array
        this.allowedValues = this.options.values ? this.options.values.sortBy(Prototype.K) : false;
        if (this.allowedValues) {
          this.minimum = this.allowedValues.min();
          this.maximum = this.allowedValues.max();
        }

        this.eventMouseDown = this.startDrag.bindAsEventListener(this);
        this.eventMouseUp   = this.endDrag.bindAsEventListener(this);
        this.eventMouseMove = this.update.bindAsEventListener(this);

        // Initialize handles in reverse (make sure first handle is active)
        this.handles.each( function(h,i) {
          i = slider.handles.length-1-i;
          slider.setValue(parseFloat(
            (Object.isArray(slider.options.sliderValue) ? 
              slider.options.sliderValue[i] : slider.options.sliderValue) || 
             slider.range.start), i);
          h.makePositioned().observe("mousedown", slider.eventMouseDown);
        });
        
        this.track.observe("mousedown", this.eventMouseDown);
        document.observe("mouseup", this.eventMouseUp);
        document.observe("mousemove", this.eventMouseMove);
        
        /*mouseoverand out*/
        this.eventMouseOver = this.OnMouseOver.bindAsEventListener(this);
        this.eventMouseOut = this.OnMouseOut.bindAsEventListener(this);
        if( ns6 == false && ns4 == false)
        {
            this.eventMouseScroll = this.OnMouseScroll.bindAsEventListener(this);
            this.eventKeyUp = this.OnKeyUP.bindAsEventListener(this);
        }
        
        this.track.observe("mouseover" , this.eventMouseOver);
        this.track.observe("mouseout" , this.eventMouseOut);
        if( ns6 == false && ns4 == false)
        {
            this.track.observe("mousewheel" , this.eventMouseScroll);
            this.track.observe("keyup" , this.eventKeyUp);
        }    
        /*mouseoverand out*/
        this.initialized = true;
    }
    catch(e){}
  }
  ,
  OnMouseOver : function(event)
  {
    try
    {
        this.MouseScrollEnabled = true;
        CurrentSlider = this;
    }
    catch(e){}
  }
  ,
  OnMouseOut : function(event)
  {
    try
    {
        this.MouseScrollEnabled = false;
        CurrentSlider = null;
    }
    catch(e){}
  }
  ,
  dispose: function() {
    try
    {
        var slider = this;    
        Event.stopObserving(this.track, "mousedown", this.eventMouseDown);
        Event.stopObserving(this.track, "mouseover", this.eventMouseOver);
        Event.stopObserving(this.track, "mouseout", this.eventMouseOut);
        if( ns6 == false && ns4 == false)
        {
            Event.stopObserving(this.track, "mousewheel", this.eventMouseScroll);
            Event.stopObserving(this.track, "keyup", this.eventKeyUp);
        }    
        Event.stopObserving(document, "mouseup", this.eventMouseUp);
        Event.stopObserving(document, "mousemove", this.eventMouseMove);
        this.handles.each( function(h) {
          Event.stopObserving(h, "mousedown", slider.eventMouseDown);
        });
    }
    catch(e){}
  },
  setDisabled: function(){
    try
    {
        this.disabled = true;
    }
    catch(e){}
  },
  setEnabled: function(){
    try
    {
        this.disabled = false;
    }
    catch(e){}
  },  
  getNearestValue: function(value){
    try
    {
        if (this.allowedValues){
          if (value >= this.allowedValues.max()) return(this.allowedValues.max());
          if (value <= this.allowedValues.min()) return(this.allowedValues.min());
          
          var offset = Math.abs(this.allowedValues[0] - value);
          var newValue = this.allowedValues[0];
          this.allowedValues.each( function(v) {
            var currentOffset = Math.abs(v - value);
            if (currentOffset <= offset){
              newValue = v;
              offset = currentOffset;
            } 
          });
          return newValue;
        }
        if (value > this.range.end) return this.range.end;
        if (value < this.range.start) return this.range.start;
        return value;
    }
    catch(e){}
  },
  setValue: function(sliderValue, handleIdx){
    try
    {
        if( !this.isValidRange()  )
        {
            //////////////////if range end and start are same , nothing to do!!!!!!!!!!!!
            this.setDefaultValue( true );
            //set the first handle to start point
            this.handles[0].style[this.isVertical() ? 'top' : 'left'] = "0px";
//            var SummaryDiv = document.getElementById("SummaryDiv");
//            SummaryDiv.innerHTML = "";
//            SummaryDiv.innerHTML += this.handles[0].style[this.isVertical() ? 'top' : 'left'];
            if( this.handles.length > 1 )
            {
                //set the last handle to last point
                this.handles[ this.handles.length - 1 ].style[this.isVertical() ? 'top' : 'left'] =  "" + (this.trackLength - this.handleLength) + "px";
//                SummaryDiv.innerHTML += "," + this.handles[ this.handles.length - 1 ].style[this.isVertical() ? 'top' : 'left'];
            }
            var i = 0 ;
            for( i = 0 ; i < this.values.length ; i++ )
            {
                this.values[i] = this.range.start;
            }
        }
        else
        {
            if (!this.active) 
            {
              this.activeHandleIdx = handleIdx || 0;
              this.activeHandle    = this.handles[this.activeHandleIdx];
              this.updateStyles();
            }
            handleIdx = handleIdx || this.activeHandleIdx || 0;
            if (this.initialized && this.restricted) 
            {
              if ((handleIdx>0) && (sliderValue<this.values[handleIdx-1]))
                sliderValue = this.values[handleIdx-1];
              if ((handleIdx < (this.handles.length-1)) && (sliderValue>this.values[handleIdx+1]))
                sliderValue = this.values[handleIdx+1];
            }
            sliderValue = this.getNearestValue(sliderValue);
            var nPosition = this.translateToPx(sliderValue);
            try
            {
                if( this.handles.length > 1 )
                {
                    if( handleIdx < this.handles.length - 1 )
                    {
                        //Make sure that handle does not overlap with next handle
                        var nNextPos = this.translateToPx( this.values[ handleIdx + 1  ] );
                        nNextPos = parseFloat( nNextPos ) - this.handleLength;
                        if( parseFloat( nPosition ) >= nNextPos)
                        {
                           nPosition = nNextPos;
                        }
                    }
                    if( handleIdx > 0 )
                    {
                        //Make sure that handle does not overlap with previous handle
                        var nNextPos = this.translateToPx( this.values[ handleIdx - 1  ] );
                        nNextPos = parseFloat( nNextPos ) + this.handleLength;
                        if( parseFloat( nPosition ) <= nNextPos )
                        {
                           nPosition = nNextPos;
                        }
                    }
                    if( parseFloat( nPosition ) < 0 )
                    {
                        nPosition = 0;
                    }
                    if( parseFloat( nPosition ) > this.trackLength - this.handleLength )
                    {
                        nPosition = this.trackLength - this.handleLength;
                    }
                }
                nPosition = "" + parseFloat( nPosition ) + "px";
                //calculate right value
                sliderValue = this.translateToValue( parseFloat( nPosition ) );
            }
            catch(e){}
            this.values[handleIdx] = sliderValue;
            this.value = this.values[0]; // assure backwards compat
            this.handles[handleIdx].style[this.isVertical() ? 'top' : 'left'] = nPosition;
            this.drawSpans();
            if (!this.dragging || !this.event) this.updateFinished();
        }//end of if( (this.range.end - this.range.start) == 0 )
    }
    catch(e){}
  },
  setValueBy: function(delta, handleIdx) {
    try
    {
        this.setValue(this.values[handleIdx || this.activeHandleIdx || 0] + delta, 
          handleIdx || this.activeHandleIdx || 0);
    }
    catch(e){}
  },
  translateToPx: function(value) {
    try
    {
        if( !this.isValidRange() )
        {
            return "0px";
        }
        else
        {
            return Math.round(
              ((this.trackLength-this.handleLength)/(this.range.end-this.range.start)) * 
              (value - this.range.start)) + "px";
        }
    }
    catch(e){}
  },
  translateToValue: function(offset) {
    try
    {
        return ((offset/(this.trackLength-this.handleLength) * 
          (this.range.end-this.range.start)) + this.range.start);
    }
    catch(e){}
  },
  getRange: function(range) {
    try
    {
        var v = this.values.sortBy(Prototype.K); 
        range = range || 0;
        return $R(v[range],v[range+1]);
    }
    catch(e){}
  },
  setRange : function( dblMin , dblMax )
  {
     try
     {
//         debugger;
         this.FireChangeEvent = false;
//         if( dblMin < dblMax )
//         {
         this.range = $R(dblMin , dblMax );
         if( this.values != null )
         {
             if( this.values.length != null )
             {
                if( this.values.length > 0 )
                {
                    var dblValue = this.values[0];
                    if( this.values[0] < dblMin || this.values[0] > dblMax)
                    {
                        dblValue = dblMin; 
                    }
                    if( this.DefaultValue )
                    {
                        dblValue = dblMin; 
                    }
                    this.setValue(dblValue , 0);
                    dblValue = this.values[this.values.length - 1];
                    if( this.values[this.values.length - 1] < dblMin || this.values[this.values.length - 1] > dblMax )
                    {
                        dblValue = dblMax; 
                    }
                    if( this.DefaultValue )
                    {
                        dblValue = dblMax; 
                    }
                    this.setValue(dblValue , this.values.length - 1 );
                }  
             }
         }
//         }//end of if( dblMin < dblMax )
         this.FireChangeEvent = true;
     }
     catch(e){}
  }
  ,
  minimumOffset: function(){
    try
    {
        return(this.isVertical() ? this.alignY : this.alignX);
    }
    catch(e){}
  },
  maximumOffset: function(){
    try
    {
        return(this.isVertical() ? 
          (this.track.offsetHeight != 0 ? this.track.offsetHeight :
            this.track.style.height.replace(/px$/,"")) - this.alignY : 
          (this.track.offsetWidth != 0 ? this.track.offsetWidth : 
            this.track.style.width.replace(/px$/,"")) - this.alignX);
    }
    catch(e){}
  },  
  isVertical:  function(){
    try
    {
        return (this.axis == 'vertical');
    }
    catch(e){}
  },
  drawSpans: function() {
    try
    {
        var slider = this;
        if (this.spans)
          $R(0, this.spans.length-1).each(function(r) { slider.setSpan(slider.spans[r], slider.getRange(r)) });
        if (this.options.startSpan)
          this.setSpan(this.options.startSpan,
            $R(0, this.values.length>1 ? this.getRange(0).min() : this.value ));
        if (this.options.endSpan)
          this.setSpan(this.options.endSpan, 
            $R(this.values.length>1 ? this.getRange(this.spans.length-1).max() : this.value, this.maximum));
    }
    catch(e){}
  },
  setSpan: function(span, range) {
    try
    {
        if (this.isVertical()) {
          span.style.top = this.translateToPx(range.start);
          span.style.height = this.translateToPx(range.end - range.start + this.range.start);
        } else {
          span.style.left = this.translateToPx(range.start);
          span.style.width = this.translateToPx(range.end - range.start + this.range.start);
        }
    }
    catch(e){}
  },
  updateStyles: function() {
    try
    {
        this.handles.each( function(h){ Element.removeClassName(h, 'selected') });
        Element.addClassName(this.activeHandle, 'selected');
    }
    catch(e){}
  },
  isValidRange : function()
  {
    if( this.range.end -  this.range.start > 0 )
    {
        return true;
    }
    else
    {
        return false;
    }
  }
  ,
  setDefaultValue : function( isDefault )
  {
        if( !this.isValidRange() )
        {
            this.DefaultValue = true;
        }
        else
        {
            this.DefaultValue = isDefault;
        }
  }
  ,
  startDrag: function(event) {
    try
    {
        if (Event.isLeftClick(event)) {
          this.setDefaultValue( false );
          if (!this.disabled){
            this.active = true;
            
            var handle = Event.element(event);
            var pointer  = [Event.pointerX(event), Event.pointerY(event)];
            var track = handle;
            if (track==this.track) {
              var offsets  = Position.cumulativeOffset(this.track); 
              this.event = event;
              this.setValue(this.translateToValue( 
               (this.isVertical() ? pointer[1]-offsets[1] : pointer[0]-offsets[0])-(this.handleLength/2)
              ));
              var offsets  = Position.cumulativeOffset(this.activeHandle);
              this.offsetX = (pointer[0] - offsets[0]);
              this.offsetY = (pointer[1] - offsets[1]);
            } else {
              while((this.handles.indexOf(handle) == -1) && handle.parentNode) 
                handle = handle.parentNode;
                
              if (this.handles.indexOf(handle)!=-1) {
                this.activeHandle    = handle;
                this.activeHandleIdx = this.handles.indexOf(this.activeHandle);
                this.updateStyles();
                
                var offsets  = Position.cumulativeOffset(this.activeHandle);
                this.offsetX = (pointer[0] - offsets[0]);
                this.offsetY = (pointer[1] - offsets[1]);
              }
            }
          }
          Event.stop(event);
        }
    }
    catch(e){}
  },
  update: function(event) {
    try
    {
       if (this.active) {
          this.setDefaultValue( false );
          if (!this.dragging) this.dragging = true;
          this.draw(event);
          if (Prototype.Browser.WebKit) window.scrollBy(0,0);
          Event.stop(event);
       }
    }
    catch(e){}
  }
  ,
  DoChangeByKeyPress : function( KeyCode )
  {
    try
    {
         if( this.EnableKeyboardEvent )
         {
            this.setDefaultValue( false );
    	    var PAGE_UP_KEY = 33;
    	    var PAGE_DOWN_KEY = 34;	
	        var LEFT_ARROW_KEY = 39;
	        var RIGHT_ARROW_KEY = 37;
	        var DOWN_ARROOW_KEY = 40;
	        var UP_ARROW_KEY = 38;
  	        var delta = 0;
  	        switch( KeyCode )
  	        {
  	            case PAGE_DOWN_KEY:
  	                delta = this.Steps * 5;
  	                break;
  	            case PAGE_UP_KEY:
  	                delta = this.Steps * -5;
  	                break;
  	            case LEFT_ARROW_KEY:
  	                delta = this.Steps;
  	                break;
  	            case DOWN_ARROOW_KEY:
  	                delta = this.Steps;
  	                break;
  	            case UP_ARROW_KEY:
  	                delta = this.Steps * -1;
  	                break;
  	            case RIGHT_ARROW_KEY:
  	                delta = this.Steps * -1;
  	                break;
  	        }
            if( delta != 0 )
            {
               var nIndex = this.GetActiveHandleIndex();
               this.values[ nIndex ] += delta;
               this.setValue( this.values[ nIndex ] , nIndex );
            }
         }
    }
    catch(e){}
  } 
  ,
  OnKeyUP : function(event)
  {
    try
    {
		var KeyCode = 0;
		if( ns4 || ns6 )
		{
		    KeyCode = parseInt(  event.which );
		}
		else
		{
      	    KeyCode = parseInt( event.keyCode );
		}
		this.DoChangeByKeyPress( KeyCode );
        Event.stop(event);
    }
    catch(e){}
  }
  ,
  CalculateMouseScrollDelta : function( event )
  {
        var delta = 0;
        try
        {
            if (!event)
            { 
              event = window.event;
            }
            if (event.wheelDelta) 
            { 
                delta = event.wheelDelta / 120;
                if (window.opera)
                {
                    delta = -delta;
                }
            } 
            else 
            {
                if (event.detail) 
                {
                    delta = - event.detail / 3;
                }
            }
        }
        catch(e)
        {
        }
        return delta;    
  }
  ,
  GetActiveHandleIndex : function()
  {
    try
    {
        var i = 0 ; 
        for( i = 0 ; i < this.handles.length ; i++ )
        {
            if( this.activeHandle.id == this.handles[i].id )
            {
                return i;
            }
        }
        return this.handles.length - 1;
    }
    catch(e)
    {
        return this.handles.length - 1;
    }
  }
  ,
  DoMouseScroll : function( delta )
  {
    try
    {
        if( this.MouseScrollEnabled == true && this.EnableMouseWheelEvent == true)
        {
            this.setDefaultValue( false );
            if( delta != 0 )
            {
                var nIndex = this.GetActiveHandleIndex();
                this.values[ nIndex ] += (delta * this.Steps);
                this.setValue( this.values[ nIndex ] , nIndex );
            }               
        }        
 
    }
    catch(e){}
  }
  ,
  OnMouseScroll : function(event)
  {
     try
     {
        if( this.MouseScrollEnabled == true )
        {
            this.DoMouseScroll( this.CalculateMouseScrollDelta( event ) );
            Event.stop(event);
        }        
     }
     catch(e){}
  }
  ,
  draw: function(event) {
    try
    {
        var pointer = [Event.pointerX(event), Event.pointerY(event)];
        var offsets = Position.cumulativeOffset(this.track);
        pointer[0] -= this.offsetX + offsets[0];
        pointer[1] -= this.offsetY + offsets[1];
        this.event = event;
        this.setValue(this.translateToValue( this.isVertical() ? pointer[1] : pointer[0] ));
        if (this.initialized && this.options.onSlide)
          this.options.onSlide(this.values.length>1 ? this.values : this.value, this);
    }
    catch(e){}
  },
  endDrag: function(event) {
    try
    {
        if (this.active && this.dragging) {
          this.finishDrag(event, true);
          Event.stop(event);
        }
        this.active = false;
        this.dragging = false;
    }
    catch(e){}
  },  
  finishDrag: function(event, success) {
    try
    {
        this.setDefaultValue( false );
        this.active = false;
        this.dragging = false;
        this.updateFinished();
    }
    catch(e){}
  },
  updateFinished: function() {
    try
    {
        if (this.initialized && this.options.onChange && this.FireChangeEvent) 
          this.options.onChange(this.values.length>1 ? this.values : this.value, this);
        this.event = null;
    }
    catch(e){}
  }
});
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function SliderPlotter(objContainerDIV , isVeritcal , strImgURL , strHandlerCSS , strDivCSS , nLength , isTwoValues , strAlt)
{
    this.HandleDivsArray = new Array();
    this.TrackDiv = null;

    objContainerDIV.style.visibility = "visible";
    var objTrackDiv = objContainerDIV
    objTrackDiv.style.position = "relative";
    objTrackDiv.className = strDivCSS;
    if( nLength != null && !isNaN( nLength ) )
    {
        if( isVeritcal )
        {
            objTrackDiv.style.height = "" + nLength + "px";
//            objTrackDiv.style.width = "20px";
        }
        else
        {
//            objTrackDiv.style.height = "20px";
            objTrackDiv.style.width = "" + nLength + "px";
        }
    }
    if( isTwoValues )
    {
        var objMinHandlerDiv = document.createElement('DIV');
        objMinHandlerDiv.id = objContainerDIV.id + "_HandleDiv1";
        objMinHandlerDiv.className = strHandlerCSS;
        objMinHandlerDiv.style.display = "block";
        objMinHandlerDiv.style.position = "absolute";
        objMinHandlerDiv.style.left = "0px";
        objMinHandlerDiv.style.top = "0px";
        var objMinHandlerImg = document.createElement('IMG')
        objMinHandlerImg.id =  objContainerDIV.id + "_HandleImg1";
        objMinHandlerImg.src = strImgURL; 
        objMinHandlerImg.alt = strAlt;
        objMinHandlerDiv.appendChild( objMinHandlerImg );
        objTrackDiv.appendChild( objMinHandlerDiv );
        this.HandleDivsArray.push( objMinHandlerDiv );       
    }
    var objMaxHandlerDiv = document.createElement('DIV');
    objMaxHandlerDiv.id = objContainerDIV.id + "_HandleDiv2";
    objMaxHandlerDiv.className = strHandlerCSS;
    objMaxHandlerDiv.style.display = "block";
    objMaxHandlerDiv.style.position = "absolute";
    if( isVeritcal )
    {
       if( nLength != null && !isNaN( nLength ) )
       {
           objMaxHandlerDiv.style.top = "" + nLength + "px";
       }
       else
       {
           objMaxHandlerDiv.style.top = "100%";
       }
       objMaxHandlerDiv.style.left = "0px";
    }
    else
    {
        objMaxHandlerDiv.style.top = "0px";
        if( nLength != null && !isNaN( nLength ) )
        {
            objMaxHandlerDiv.style.left = "" + nLength + "px";
        }
        else
        {
           objMaxHandlerDiv.style.left = "100%";
        }
    }
    var objMaxHandlerImg = document.createElement('IMG')
    objMaxHandlerImg.id =  objContainerDIV.id + "_HandleImg2";
    objMaxHandlerImg.src = strImgURL;
    objMaxHandlerImg.alt = strAlt;
    objMaxHandlerDiv.appendChild( objMaxHandlerImg );
    objTrackDiv.appendChild( objMaxHandlerDiv );
    this.HandleDivsArray.push( objMaxHandlerDiv );       
    this.TrackDiv = objTrackDiv; 
}
/////////////////////////////////////////////////////////////////////////////////////////////////////
function MetaSearchSlider_v2( OnFinishSlideFunction , OnSlideFunction , nMin , nMax , isVertical , objContainerDIV  , strImgURL , strHandlerCSS , strDivCSS , nLength , isTwoValues , strAlt , nDecimals , nSteps)
{
    var objPlotter = new SliderPlotter( objContainerDIV , isVertical , strImgURL , strHandlerCSS , strDivCSS , nLength , isTwoValues , strAlt ); 
    this.Decimals = nDecimals;
    this.isVertical = isVertical;
    this.isTwoValues = isTwoValues;
    this.Container = objContainerDIV;
    //THIS FUNCTION SHOULD TAKE ONE ARGUMENT ( ArrValues ) contains array of values selected, CALLED WHEN USER FINISH SLIDING
    this.FinishSlideFunction = OnFinishSlideFunction;
    //THIS FUNCTION SHOULD TAKE ONE ARGUMENT ( ArrValues ) contains array of values selected, CALLED WHEN USER SLIDES
    this.SlideFunction = OnSlideFunction;
    var MinimumValue  = parseFloat( nMin );
    var MaximumValue = parseFloat( nMax );
    //this.SelectedMinimum = parseFloat( nMin );
    //this.SelectedMaximum = parseFloat( nMax ); 
    this.ArrTextBoxes = new Array();
    var Steps = nSteps; 
    var oldValue;
    var slider6;
    var SELF = this;
    Init();
    function Init()
    {
        SELF.Container.style.visibility = "visible";
        oldValue="["+ MinimumValue +","+ MaximumValue +"]"
        slider6 = null;
        var ArrIds = new Array();
        var i = 0 ; 
        for( i = 0 ; i < objPlotter.HandleDivsArray.length ; i++ )
        {
            ArrIds.push( objPlotter.HandleDivsArray[i].id ); 
        }
        var Direction = "horizontal";
        if( SELF.isVertical )
        {
            Direction = "vertical";
        }
        slider6 = new Control.Slider_v2( ArrIds , objPlotter.TrackDiv.id ,{
        sliderValue:[ MinimumValue , MaximumValue],
        range:$R( MinimumValue , MaximumValue ),
        axis : Direction,
        Steps : Steps,
        restricted:true,
        onSlide:function(v){
            var asplited=""+v;
            var arrsplit=asplited.split(",");

            var ArrValues = new Array();
            var i = 0 ;
            for( i = 0 ; i < arrsplit.length ; i++ )
            {
                var strValue = arrsplit[i];
                strValue = strValue.replace("[" , "" );
                strValue = strValue.replace("]" , "" );
                strValue = strValue.replace("'" , "" );
                if( strValue != "" )
                {
                    var dblValue = parseFloat( strValue );
                    //dblValue = dblValue.toFixed(  );
                    ArrValues.push(   parseFloat( parseFloat( strValue ).toFixed( SELF.Decimals ) ) ); 
                }
            }
            if( SELF.SlideFunction != null )
            {
                SELF.SlideFunction( ArrValues );
            }
        },
        onChange:function(v){
            var splited=""+v;
            oldValue = splited;

            var ArrValues = new Array();
            var i = 0 ;
            for( i = 0 ; i < oldValue.split(",").length ; i++ )
            {
                var strValue = oldValue.split(",")[i];
                strValue = strValue.replace("[" , "" );
                strValue = strValue.replace("]" , "" );
                strValue = strValue.replace("'" , "" );
                var dblValue = null;
                if( strValue != "" )
                {
                    dblValue = parseFloat( parseFloat( strValue ).toFixed( SELF.Decimals ) );
                    ArrValues.push(  dblValue  ); 
                }
                if( SELF.ArrTextBoxes.length > i && dblValue != null && !isNaN( dblValue ))
                {
                    SELF.ArrTextBoxes[i].value = dblValue;
                }
            }
//            SELF.SelectedMinimum = ArrValues[0];
//            SELF.SelectedMaximum = ArrValues[ ArrValues.length - 1 ];
            if( SELF.FinishSlideFunction != null )
            {
                SELF.FinishSlideFunction( ArrValues );
            }
        }});
    }
    this.GetSliderObject = function() 
    {
        return slider6;
    }
    this.ResetMinAndMax = function( nMin , nMax )
    {
//       if( nMin < SELF.MinimumValue )
//            SELF.MinimumValue  = parseFloat( nMin );
//       if( nMax > SELF.MaximumValue )
//            SELF.MaximumValue = parseFloat( nMax );
       //slider6.range = $R( SELF.MinimumValue , SELF.MaximumValue );
       slider6.setRange( nMin , nMax );
    }
    this.SetValue = function( strValue , nIndex )
    {
        slider6.FireChangeEvent = false;
        var dblValue = null;
        try
        {
            dblValue = parseFloat( strValue );
        }
        catch(e){}
        if( dblValue != null && !isNaN( dblValue ) )
        {
            slider6.setValue( dblValue , nIndex );
        }
        slider6.FireChangeEvent = true;
    }
    this.SetSteps = function( nSteps )
    {
        slider6.Steps = nSteps; 
    }
    this.GetValues = function()
    {
        var ArrValues = new Array();
        var i = 0;
        for( i = 0 ; i < slider6.values.length ; i++ )
        {
            var dblValue = parseFloat( parseFloat( slider6.values[i] ).toFixed( SELF.Decimals ) );
            ArrValues.push( dblValue );
        }
        return ArrValues;
    }
    this.GetMinAndMax = function()
    {
        var ArrValues = new Array();
        ArrValues.push( slider6.range.start )
        ArrValues.push( slider6.range.end )
        return ArrValues; 
    }
}
/**********************************************************************************************/
//Type.registerNamespace('AjaxControlToolkit');
/*AjaxControlToolkit._SliderDragDropManagerInternal = function() {
    AjaxControlToolkit._SliderDragDropManagerInternal.initializeBase(this);
    
    this._instance = null;
}
AjaxControlToolkit._SliderDragDropManagerInternal.prototype = {
    _getInstance : function() {
        this._instance = new AjaxControlToolkit.GenericDragDropManager();

        this._instance.initialize();
        this._instance.add_dragStart(Function.createDelegate(this, this._raiseDragStart));
        this._instance.add_dragStop(Function.createDelegate(this, this._raiseDragStop));
        
        return this._instance;
    }   
}*/
//AjaxControlToolkit._SliderDragDropManagerInternal.registerClass('AjaxControlToolkit._SliderDragDropManagerInternal', AjaxControlToolkit._DragDropManager);
//AjaxControlToolkit.SliderDragDropManagerInternal = new AjaxControlToolkit._SliderDragDropManagerInternal();


/*AjaxControlToolkit.DoubleSliderOrientation = function() {

}
AjaxControlToolkit.DoubleSliderOrientation.prototype = {
    Horizontal : 0,
    Vertical : 1
}*/
//AjaxControlToolkit.DoubleSliderOrientation.registerEnum('AjaxControlToolkit.DoubleSliderOrientation', false);

DoubleSliderBehavior = function(element) {
    //AjaxControlToolkit.DoubleSliderBehavior.initializeBase(this, [element]);
    this._element = element;
    this._steps = 1;
    this._minimum =  0;
    this._maximum =  100;
    this._MinValueTextBox = null;
    this._MaxValueTextBox = null;
    this._keyDownHandler = null;
    this._ClientOnSlideFunction = null;
    this._ClientOnFinishSlidingFunction = null;
    this._decimals =  2;
    this._orientation =  "Horizontal";
    this._railCssClass = null;
    this._isHorizontal =  true;
    this._handleImageUrl = null;
    this._handleCssClass = null;
    this._length = null;
    this._tooltipText = '';
    this.SliderObject = null;
    this._TwoHandles = true;
    this._EnableChangeByKeyboardKeys = true;
    this._EnableChangeByMouseWheelScroll = true;
}
DoubleSliderBehavior.prototype = {
    
    // initialize / dispose
    //
    initialize : function() {
        //AjaxControlToolkit.DoubleSliderBehavior.callBaseMethod(this, 'initialize');
                
        this._initializeLayout();
    },
    
    dispose : function() {
        //this._disposeHandlers();
        //.DoubleSliderBehavior.callBaseMethod(this, 'dispose');
    },
    get_element : function()
    {
		return this._element;
    }
    ,
    _initializeLayout : function() {
        //this._keyDownHandler = Function.createDelegate(this, this._TextBox_onKeyDown);
        /*if( this._MinValueTextBox != null )
        {
            
            this.initializeTextBox( this._MinValueTextBox );
        }
        if( this._MaxValueTextBox != null )
        {
            this.initializeTextBox( this._MaxValueTextBox );
        }*/

    
        this._railElement = this.get_element();
        // This is a flag for saving keystrokes. 
        this._isHorizontal = (this._orientation.toUpperCase() == "HORIZONTAL" ); 
        
        var defaultRailCssClass = (this._isHorizontal) ? 'ajax__slider_h_rail' : 'ajax__slider_v_rail'; 
        var defaultHandleCssClass = (this._isHorizontal) ? 'ajax__slider_h_handle' : 'ajax__slider_v_handle';
        var defaultHandleImageUrl = "";
            
        this._railElement.className = (this._railCssClass) ? this._railCssClass : defaultRailCssClass; 
        this._railElement.className = (this._handleCssClass) ? this._handleCssClass : defaultHandleCssClass;
        if(!this._handleImageUrl) this._handleImageUrl = defaultHandleImageUrl;
        
        if (this._isHorizontal) {
            if(this._length) this._railElement.style.width =  this._length;
        } 
        else {
            if(this._length) this._railElement.style.height =  this._length;
        }


//        try
//        {
//            if( this._id == "PriceSlider" )
//            {
//                alert("Initialize with to:"+ this._minimum +"," + this._maximum);
//            }
//        }
//        catch(e){}
        
        this.SliderObject = new MetaSearchSlider_v2( this._ClientOnFinishSlidingFunction , this._ClientOnSlideFunction , this._minimum , this._maximum , !this._isHorizontal , this._railElement  , this._handleImageUrl , this._railElement.className , this._railElement.className , this._length , this._TwoHandles , this._tooltipText , this._decimals , this._steps);
        this.SliderObject.GetSliderObject().EnableMouseWheelEvent = this._EnableChangeByMouseWheelScroll;
        this.SliderObject.GetSliderObject().EnableKeyboardEvent = this._EnableChangeByKeyboardKeys;
        
        /*if( this._MinValueTextBox != null )
        {
           this.SliderObject.ArrTextBoxes.push( this._MinValueTextBox ); 
        }
        if( this._MaxValueTextBox != null )
        {
           this.SliderObject.ArrTextBoxes.push( this._MaxValueTextBox ); 
        }
        this.SetValuesInTextBoxes( this.SliderObject.GetValues() );*/
    }
    /*,
    initializeTextBox: function(element) {
    
        /// <summary>
        /// Initializes the textbox
        /// </summary>
        /// <param name="element" type="Sys.UI.DomElement" DomElement="true" mayBeNull="false" />
        /// <returns />    
        if( element != null )
        {
            element.autocomplete = "off";
            //$addHandler(element, "keydown", this._keyDownHandler);
            element.onkeydown = this._TextBox_onKeyDown;
        }
    },
    SetValuesInTextBoxes : function ( ArrValues )
    {
        if( ArrValues != null )
        {
            if( ArrValues.length != null )
            {
                if( ArrValues.length > 0 && this._MinValueTextBox != null)
                {
                   this._MinValueTextBox.value = "" + ArrValues[0]; 
                }
                if( ArrValues.length > 1 && this._MaxValueTextBox != null)
                {
                    this._MaxValueTextBox.value = "" + ArrValues[1];
                }
            }
        }        
    }
//    ,
//    _Slider_OnChangeValue : function( ArrValues )
//    {
//        try
//        {
//            this.SetValuesInTextBoxes( ArrValues );
//            if( this._ClientOnFinishSlidingFunction != null )
//            {
//                this._ClientOnFinishSlidingFunction( ArrValues );
//            }
//        }
//        catch(e)
//        {
//        }
//    }
    ,
    _TextBox_onKeyDown : function( e )
    {
        var k = e.keyCode ? e.keyCode : e.rawEvent.keyCode;
        var target = e.target ? e.target : e.rawEvent.target;
        if(k === Sys.UI.Key.enter) 
        {
            var nIndex = -1;
            if( this._MinValueTextBox != null && target != null)
            {
                if( target.id == this._MinValueTextBox.id )
                {
                    nIndex = 0;
                }
            }
            if( nIndex <= -1 && this._MaxValueTextBox != null && target != null)
            {
                if( target.id == this._MaxValueTextBox.id )
                {
                    nIndex = 1;
                }
            }
            if( nIndex > -1 )
            {
                this.SliderObject.SetValue( e.target.value , nIndex );
            }
        }        
    }*/
    /*,
    _disposeHandlers : function() {
        $clearHandlers(this._railElement);
    },
    
    get_dragMode : function() {       
        return AjaxControlToolkit.DragMode.Move;
    }*/,

    get_RailCssClass : function() {
        return this._railCssClass;
    },
    
    set_RailCssClass : function(value) {
        this._railCssClass = value;
    },  
    
    get_HandleImageUrl : function() {
        return this._handleImageUrl;
    },
    
    set_HandleImageUrl : function(value) {
        this._handleImageUrl = value;
    },
    
    get_HandleCssClass : function() {
        return this._handleCssClass;
    },
    
    set_HandleCssClass : function(value) {
        this._handleCssClass = value;
    },

    get_TwoHandles : function() {
        return this._TwoHandles;
    },
    
    set_TwoHandles : function(value) {
        this._TwoHandles = value;
    }, 


    get_ClientOnFinishSlidingFunction : function() {
        return this._ClientOnFinishSlidingFunction;
    },
    
    set_ClientOnFinishSlidingFunction : function(value) {
        if( value != "" && value != null )
        {
            this._ClientOnFinishSlidingFunction = eval( value );
        }
    }, 
    
    get_ClientOnSlideFunction : function() {
        return this._ClientOnSlideFunction;
    },
     
    set_ClientOnSlideFunction : function(value) {
        if( value != "" && value != null )
        {
            this._ClientOnSlideFunction = eval( value );
        }
    }/*, 


    get_MinValueTextBox : function() {
        return this._MinValueTextBox;
    },
    
    set_MinValueTextBox : function(value) {
        this._MinValueTextBox = value;
    }, 

    get_MaxValueTextBox : function() {
        return this._MaxValueTextBox;
    },
    
    set_MaxValueTextBox : function(value) {
        this._MaxValueTextBox = value;
    }*/, 


    get_EnableChangeByMouseWheelScroll : function() {
        return this._EnableChangeByMouseWheelScroll;
    },
    
    set_EnableChangeByMouseWheelScroll : function(value) {
        try
        {
            this.SliderObject.GetSliderObject().EnableMouseWheelEvent = value;
        }
        catch(e){}
        this._EnableChangeByMouseWheelScroll = value;
        
    }, 

    get_EnableChangeByKeyboardKeys : function() {
        return this._EnableChangeByKeyboardKeys;
    },
    
    set_EnableChangeByKeyboardKeys : function(value) {
        try
        {
            this.SliderObject.GetSliderObject().EnableKeyboardEvent = value;
        }
        catch(e){}
        this._EnableChangeByKeyboardKeys = value;
    }, 


    
    get_Minimum : function() {
        return this._minimum;
    },
    
    set_Minimum : function(value) {
        this._minimum = value;
    }, 
    
    get_Maximum : function() {
        return this._maximum;
    },
    
    set_Maximum : function(value) {
        this._maximum = value;
    },
    
    get_Orientation : function() {
        return this._orientation;
    },
    
    set_Orientation : function(value) {
        this._orientation = value;
    },
    
    get_Steps : function() {
        return this._steps;
    },
    
    set_Steps : function(value) {
        this._steps = Math.abs(value);
        this._steps = (this._steps == 1) ? 2 : this._steps;
        try
        {
            this.SliderObject.SetSteps( this._steps );
        }
        catch(e){}
    },
    
    get_Decimals : function() {
        return this._decimals;
    },
    
    set_Decimals : function(value) {
        this._decimals = Math.abs(value);
        try
        {
        this.SliderObject.Decimals = this._decimals;
        }
        catch(e){}
    }/*, 
      
    get_BoundControlID : function() {
        return this._boundControlID;
    },
    
    set_BoundControlID : function(value) {
        this._boundControlID = value;
        if(this._boundControlID) {
            this._boundControl = $get(this._boundControlID);
        } else {
            this._boundControl = null;
        }
    }*/,
    
    get_Length : function() {
        return this._length;
    },
    
    set_Length : function(value) {
        this._length = value ;
    },
    
    get_TooltipText : function() {
        return this._tooltipText;
    },
    
    set_TooltipText : function(value) {
        this._tooltipText = value;
    },
    ResetMinAndMax : function(nMin , nMax)
    {
        this.set_Minimum( nMin );
        this.set_Maximum( nMax );
        this.SliderObject.ResetMinAndMax( nMin , nMax );
    }
    ,
    GetSelectedValues : function()
    {
        return this.SliderObject.GetValues();
    }
    ,
    GetMinAndMax : function()
    {
		return this.SliderObject.GetMinAndMax();
    }
    ,
	SetMinAndMaxValues : function( nMin , nMax )
	{
		this.SliderObject.SetValue( nMin , 0);
		this.SliderObject.SetValue( nMax , 1);
	}    
/*    ,    
    // These are helper functions for communicating state back to the extender on the
    // server side.  They take or return a custom string that is available in your initialize method
    // and later.
    //
    getClientState : function() {
        var value = AjaxControlToolkit.SliderBehavior.callBaseMethod(this, 'get_ClientState');                
        if (value == '') value = null;
        return value;
    },
     
    setClientState : function(value) {
        return AjaxControlToolkit.SliderBehavior.callBaseMethod(this, 'set_ClientState',[value]);                
    }*/
}

//AjaxControlToolkit.DoubleSliderBehavior.DropPending = null; 

//AjaxControlToolkit.DoubleSliderBehavior.registerClass('AjaxControlToolkit.DoubleSliderBehavior', AjaxControlToolkit.BehaviorBase, AjaxControlToolkit.IDragSource, AjaxControlToolkit.IDropTarget);
