
function textrating(x) {	
	document.getElementById('wertunginfo').innerHTML = "Meine Wertung:";
	eltext = document.getElementById('wertungpunkte').style;		
	
	if (x < 5) 
		{eltext.color = '#ff0000'; }
	if (x <= 7 && x >= 5) 
		{eltext.color = '#FF9900'; }
	if (x > 7) 
		{eltext.color = '#339900'; }	

	x = x - 0.1;	
	x = Math.round(x);
	
	switch (x) {
		case 0: 	var trv="Würg!";			break;
		case 1: 	var trv="Würg!";			break;
		case 2: 	var trv="Würg!";			break;
		case 3: 	var trv="Naja!";			break;		
		case 4: 	var trv="Naja!";			break;
		case 5: 	var trv="Geht so";		break;
		case 6: 	var trv="Geht so";		break;		
		case 7: 	var trv="Brauchbar";	break;
		case 8: 	var trv="Gut!";				break;
		case 9: 	var trv="Sehr Gut!";	break;
		case 10: 	var trv="Genial!";		break;								
	}	
return trv;
}	

function doplus(setwertung) {		
	if (!document.wertungsform.wertung.value) { 
		document.wertungsform.wertung.value=setwertung; 
	}
	if (document.wertungsform.wertung.value < 10) { 		
		var tempwertung = document.wertungsform.wertung.value;
		tempwertung = Math.round(tempwertung*100)/100;		
		tempwertung = tempwertung + 0.1; 
		tempwertung = Math.round(tempwertung*100)/100;		
		slider.setValue(tempwertung);		
		document.wertungsform.wertung.value = tempwertung;
	} 
}

function dominus(setwertung) {		
	if (!document.wertungsform.wertung.value) { 
		document.wertungsform.wertung.value=setwertung; 
	}
	if (document.wertungsform.wertung.value > 1) { 		
		var tempwertung = document.wertungsform.wertung.value;
		tempwertung = Math.round(tempwertung*100)/100;		
		tempwertung = tempwertung - 0.1; 
		tempwertung = Math.round(tempwertung*100)/100;		
		slider.setValue(tempwertung);		
		document.wertungsform.wertung.value = tempwertung;
	} 
}

function doWertung() { 				
	if (document.wertungsform.wertung.value) { 
		document.wertungsform.submit(); 
	}
	else { 
		alert("Erst deine eigene Wertung einstellen und dann auf 'Bewertung abgeben' klicken."); 
	}	
}

function Slider(t, s, h) {          
    this.track = document.getElementById(t);
    this.slider = document.getElementById(s);
    this.handle = document.getElementById(h);
    this.track.onmousedown = this.onmousedown;    
    this.track.slider = this;    
    this.track.onselectstart = this.slider.onselectstart =	
    this.handle.onselectstart = function() { return false };    
    this.style = this.slider.style;
}

Slider.prototype.startDrag = function(e) {
    Slider.currentInstance = this;
    if (!e) e = window.event;
    if (!this.handleWidth) {
	    this.handleWidth = this.handle.offsetWidth;
	    this.initialWidth = this.slider.offsetWidth;
	    this.width = this.initialWidth;
	    this.maxWidth = this.track.offsetWidth;
    }
    this.screenX = e.screenX;
    var el = e.target || e.srcElement;
    if (el != this.handle) {
        var x = e.offsetX? e.offsetX : e.layerX;
        x += Math.round(this.handleWidth / 2);
        this.moveTo(x);
    }
    this.initialWidth = this.width;
}

Slider.prototype.onmousedown = function(e) {
    var s = this.slider;
    s.startDrag(e);    
    if (document.addEventListener) {
        document.addEventListener("mousemove", s.onmousemove, true);
        document.addEventListener("mouseup", s.onmouseup, true);
    }
    else if (document.attachEvent) {
        document.attachEvent("onmousemove", s.onmousemove);
        document.attachEvent("onmouseup", s.onmouseup);
        document.attachEvent("onlosecapture", s.onmouseup);
    }    
}

Slider.prototype.onmouseup = function(e) {
    var s = Slider.currentInstance;
    s.initialWidth = s.width;    
    if (document.removeEventListener) {
        document.removeEventListener("mousemove", s.onmousemove, true);
        document.removeEventListener("mouseup", s.onmouseup, true);
    }
    else if (document.detachEvent) {
        document.detachEvent("onmousemove", s.onmousemove);
        document.detachEvent("onmouseup", s.onmouseup);
        document.detachEvent("onlosecapture", s.onmouseup);
    }
    
}

Slider.prototype.onmousemove = function(e) {
    if (!e) e = window.event;
    var s = Slider.currentInstance;
    var x = s.initialWidth + (e.screenX - s.screenX);
    s.moveTo(x);    
}

Slider.prototype.moveTo = function(x) {
    if (x < this.handleWidth) x = this.handleWidth;
    else if (x > this.maxWidth) x = this.maxWidth;
    this.width = x;
    this.style.width = '' + x + 'px';
    document.getElementById('wertungpunkte').innerHTML = slider.getValue();
    document.getElementById('wertungtext').innerHTML =  textrating(slider.getValue());
    document.wertungsform.wertung.value = slider.getValue();
}

Slider.prototype.moveBy = function(x) {
    this.moveTo(this.width + x);    
}

Slider.prototype.getValue = function() {  
    return Math.round(((Math.round((this.width-this.handleWidth) / (this.maxWidth-this.handleWidth)* 100) / 11.1)+1)*10)/10; 
}

Slider.prototype.setValue = function(x) {
  this.moveTo(Math.round(x * 18.4));
  document.getElementById('wertungpunkte').innerHTML = x; 
  document.getElementById('wertungtext').innerHTML =  textrating(x)
}

var slider = new Slider('track', 'slider', 'handle');