 var handleCancel2 = function() {	    
	    this.cancel();
	}
	var handleSubmit2 = function() 
	{		
		//var obj = $("demo_info");
		//alert("Start:" +Slider.getThumbStart());
		//alert("End: " + Slider.getThumbEnd());		
		this.cancel();
			
		setDates(Slider.getThumbStart(),Slider.getThumbEnd(),Slider.getType(),Slider.isFullRange());
	    //this.submit();	    
	}		
	
   var SliderDialog;
   var Slider;
   
   function initSlider(id)
   {
	   SliderDialog = new YAHOO.widget.Dialog("SliderDialog",{close: false, draggable: false});
	   
	   var myButtons2 = [ { text:"OK", handler:handleSubmit2, isDefault:true }/*,
                  { text:"Cancel", handler:handleCancel2 } */];
	   SliderDialog.cfg.queueProperty("buttons", myButtons2);	   
	   Slider = new handleSlider(id);	   
   }
   
   function showSlider(id,type,positionelement,title, minValue, maxValue, startValue, endValue)
   {		   	  	   	   
	   $('SliderType'+id).value = type;
	   $('SliderTitle'+id).firstChild.nodeValue = title;
	   $('SliderStartValue'+id).value = startValue;
	   $('SliderEndValue'+id).value = endValue;	   
	   Slider.setRangeValueMin(minValue);	   	   
	   Slider.setRangeValueMax(maxValue);	   
	   	   	   
	   SliderDialog.cfg.setProperty("x",$(positionelement).cumulativeOffset().left-12);
	   SliderDialog.cfg.setProperty("y",$(positionelement).cumulativeOffset().top+20);
	   
	   //SliderDialog.cfg.setProperty("modal",true);
	   SliderDialog.render();	   
	   SliderDialog.show();  
	   Slider.updateUI();
   }
      
   
   var handleSlider = function (id) 
   {	    
	   var that = this;
	   this.id = id;
	   
	   // Slider has a range of 200 pixels
	    this.range = 207;
	    
	    this.isFullRange = function(val)
	    {
	    	return that.slider.minVal == 0 && that.slider.maxVal == that.range;
	    }
	    
	    this.setRangeValueMin = function(val)
	    {
	    	var cf = (parseInt($('SliderEndValue'+that.id).value)-parseInt($('SliderStartValue'+that.id).value))/(that.range - 20);
	    	that.slider.setMinValue(Math.round((val-parseInt($('SliderStartValue'+that.id).value))/cf));	    	
	    }
	    
	    this.setRangeValueMax = function(val)
	    {
	    	var cf = (parseInt($('SliderEndValue'+that.id).value)-parseInt($('SliderStartValue'+that.id).value))/(that.range - 20);
	    	that.slider.setMaxValue(20+Math.round((val-parseInt($('SliderStartValue'+that.id).value))/cf));	    	
	    }
	    
	    this.getThumbStart = function()
	    {
	    	return that.convert(that.slider.minVal);
	    }
	    
	    this.getThumbEnd = function()
	    {
	    	return that.convert(that.slider.maxVal - 20);
	    }
	    
	    this.getType = function()
	    {
	    	return $('SliderType'+that.id).value;
	    }	   
	    	   
	 	 	  	 	  
	    // Set up a function to convert the min and max values into something useful
	    this.convert = function (val) 
	    {
	    	// Conversion factor from 0-200 pixels to 100-1000
		    // Note 20 pixels are subtracted from the range to account for the
		    // thumb values calculated from their center point (10 pixels from
		    // the center of the left thumb + 10 pixels from the center of the
		    // right thumb)
		    var cf = (parseInt($('SliderEndValue'+that.id).value)-parseInt($('SliderStartValue'+that.id).value))/(that.range - 20);		   
		 
	        return Math.round(val * cf + parseInt($('SliderStartValue'+that.id).value));
	    };	    	    
	    
	    // Custom function to update the text fields, the converted value
        // report and the slider's title attribute
        this.updateUI = function () 
        {
        	var Dom = YAHOO.util.Dom;		        	
        	var info    = Dom.get("demo_info"+that.id),
            from    = Dom.get("demo_from"+that.id),
            to      = Dom.get("demo_to"+that.id);
        	
            from.value = that.slider.minVal;
            to.value   = that.slider.maxVal;
 
            // Update the converted values and the slider's title.
            // Account for the thumb width offsetting the value range by
            // subtracting the thumb width from the max value.
            var min = that.getThumbStart(),
                max = that.getThumbEnd();
 
            info.innerHTML = min + " - " + max;
            //demo_bg.title  = "Current range " + min + " - " + max;
        };
	 
	    // Slider set up is done when the DOM is ready
	    YAHOO.util.Event.onDOMReady(function () 
	    {	    	    
		 
		    // No ticks for this example
		    var tickSize = 0;
		 
		    // We'll set a minimum distance the thumbs can be from one another
		    var minThumbDistance = 0;
		 
		    // Initial values for the thumbs
		    var initValues = [0,207];
	        // Create the DualSlider
	        	that.slider = YAHOO.widget.Slider.getHorizDualSlider("demo_bg"+that.id,
	            "demo_min_thumb"+that.id, "demo_max_thumb"+that.id,
	            that.range, tickSize, initValues);
	 
	        that.slider.minRange = minThumbDistance;
	        	       
	 
	        // Subscribe to the dual thumb slider's change and ready events to
	        // report the state.
	        that.slider.subscribe('ready', that.updateUI);
	        that.slider.subscribe('change', that.updateUI);
	 
	    });
	}
