function createSlider(goal_id,value) {
    var Event = YAHOO.util.Event,
        Dom   = YAHOO.util.Dom,
        lang  = YAHOO.lang,
        slider, 
        bg="slider-bg"+goal_id, thumb="slider-thumb"+goal_id, 
        textfield="slider-converted-value"+goal_id, gr_bg = "slider-gr-bg"+goal_id;

    // The slider can move 0 pixels up
    var topConstraint = 0;

    // Custom scale factor for converting the pixel offset into a real value
    var scaleFactor = 100/120;

    // The amount the slider moves when the value is changed with the arrow
    // keys
    var keyIncrement = 6;

    var tickSize = 6;

    Event.onDOMReady(function() {

        slider = YAHOO.widget.Slider.getHorizSlider(bg, 
                         thumb, topConstraint, bottomConstraint, tickSize);
		slider.animate = false;      //causes problems in calculating the percent and also in the thumb position. leave false.
		slider.keyIncrement = keyIncrement;
		slider.enableKeys = false;	// disable changing of slider by left and right arrows

		//In IE6, there was a problem in sliders that start at 0%: the thumb jumps up few pixels above the slider when it was moved and stays at that higher position.
		//It seems YUI sometimes can't set a value for a style that it didn't initialize and
		//thumbs for sliders that start at 0% are not moved onDomReady and therefore not initialized by YUI. 
		//Therefore, (though we have already styled it with css,) have YUI re-style the thumb to fix this problem in IE6
		//This is only needed if animation is true
		//YAHOO.util.Dom.setStyle(thumb, 'top', '-3px');	- doesn't work still


		slider.getRealValue = function() {
			return Math.round(this.getValue() * scaleFactor);
        
		}
		
				
		if (value == null) value = 0;
		slider.setValue(Math.round(value/scaleFactor));	//	
		
		

		slider.subscribe("change", function(offsetFromStart) {
			if (slider.valueChangeSource == 1){
				var c = YAHOO.util.Dom.get('check_goal_'+goal_id);
	
				if(!c.checked){
					showGoal(goal_id);
					c.checked=true;
				}
			}
            var fld = Dom.get(textfield);
			
			//adjust the green fill
			Dom.setStyle(gr_bg,"width",(offsetFromStart) + "px");
			
            // use the scale factor to convert the pixel offset into a real value
            var actualValue = slider.getRealValue();
			
            // update the text box and hidden element with the actual value
            fld.innerHTML = actualValue;
			Dom.get('progress_'+goal_id).value = actualValue;

            // Update the title attribute on the background.  This helps assistive
            // technology to communicate the state change
            Dom.get(bg).title = "slider value = " + actualValue;
        	
		});

    });
};

function completedSlider(goal_id) {
	var Event = YAHOO.util.Event,
        Dom   = YAHOO.util.Dom;
	
	Event.onDOMReady(function() {
		Dom.get('progress_'+goal_id).value = "100";					//set hidden value to 100
		Dom.get('slider-converted-value'+goal_id).innerHTML = "100";//set label to 100
		Dom.setStyle("slider-gr-bg"+goal_id,"width","127px"); 		//put green background to 100%
		Dom.get("slider-thumb"+goal_id).innerHTML = ""; 			//remove the slider thumb
	});
};

function showGoal(goal_id) {
	//var t = YAHOO.util.Dom.get("trackers"+goal_id);
	if(YAHOO.util.Dom.getStyle('trackers_'+goal_id, 'display') == 'none'){
		YAHOO.util.Dom.setStyle('trackers_'+goal_id, 'display', 'block' );	
	}else YAHOO.util.Dom.setStyle('trackers_'+goal_id, 'display', 'none' );	
	
	return;
};

function validNumber(f) {
/*	if (!/^\d*$/.test(f.value)) {
		//alert("Only integer numbers allowed!");
		f.value = f.value.replace(/[^\d]/g,"");
	}
*/
	var temp = f.value;
	var decimalPlaces = 2;

	var reg0Str = '[0-9]*';
	if (decimalPlaces > 0) {
		reg0Str += '\\.?[0-9]{0,' + decimalPlaces + '}';
	} else if (decimalPlaces < 0) {
		reg0Str += '\\.?[0-9]*';
	}
	reg0Str = '^' + reg0Str + '$';

	var reg0 = new RegExp(reg0Str);
	if (reg0.test(temp)) return true;

	// first replace all non numbers
	var reg1Str = '[^0-9' + (decimalPlaces != 0 ? '.' : '')  + ']';
	var reg1 = new RegExp(reg1Str, 'g');
	temp = temp.replace(reg1, '');

	if (decimalPlaces != 0) {
		var reg3 = /\./g;
		var reg3Array = reg3.exec(temp);
		if (reg3Array != null) {
			// keep only first occurrence of .
			//  and the number of places specified by decimalPlaces or the entire string if decimalPlaces < 0
			var reg3Right = temp.substring(reg3Array.index + reg3Array[0].length);
			reg3Right = reg3Right.replace(reg3, '');
			reg3Right = decimalPlaces > 0 ? reg3Right.substring(0, decimalPlaces) : reg3Right;
			temp = temp.substring(0,reg3Array.index) + '.' + reg3Right;
		}
	}

	f.value = temp;

	f.focus();
};

function preShowGoal(goal_id) {
	
	var c = YAHOO.util.Dom.get('check_goal_'+goal_id);
	if(c && !c.checked){
		showGoal(goal_id);
		c.checked=true;
	}
};


