function rhighlight(field, stars) {
	if(stars == 0) {
		stars = rating[field];
	}
	for(var i = 1; i < 6; i ++) {
		var star = document.getElementById('rating_'+field+'_'+i);
		if(i <= stars) {
			star.src = '1pic/rating_star_full.gif';
		}
		else {
			star.src = '1pic/rating_star_empty.gif';
		}
	}
}

function rate(field, stars) {
	rating[field] = stars;
	document.getElementById('field_'+field).value = stars;
	
	rhighlight(field, 0);
}

function showBestPreis(evt) {
	var field = $('bestpreis_text');
	
	if(!evt) var evt = window.event;
	var pos = new Object();
	pos.left = evt.clientX;
	pos.top = evt.clientY;
	var b = (window.document.compatMode && window.document.compatMode == "CSS1Compat") ? 
	window.document.documentElement : window.document.body || null;
	if (b)
	{
		pos.scrollLeft= pos.left + b.scrollLeft;
		pos.scrollTop = pos.top + b.scrollTop;
		pos.clientHeight = b.clientHeight;
	}


	field.style.left = pos.scrollLeft - 365 +'px';
	if((pos.clientHeight - 200) > pos.top) { 
		field.style.top = 5+pos.scrollTop+'px';
	}
	else {
		field.style.top = (pos.scrollTop - 190)+'px';
	}
	
	field.style.display = 'block';
}
function hideBestPreis() {
	$('bestpreis_text').style.display = 'none';
}


function wkAdd(id)
{
	var anzahl = $('anzahl_' + id).value;
	new Ajax.Request('wkAdd.php', {
		method : 'post',
		postBody : 'id=' + id + '&anzahl=' + anzahl,
		onSuccess : function (transport) {
			var result = transport.responseText.evalJSON();
			
			if (result.status == 'success') {
				$('message_' + id).className = 'notice';
				$('message_' + id).innerHTML = result.message;
			} else {
				$('message_' + id).className = 'error';
				$('message_' + id).innerHTML = result.message;
			}
			
			if (result.wkAnzahl) {
				$('wkAnzahl').innerHTML = result.wkAnzahl;
			}
			
			if (result.lagerstand) {
				$('message_' + id).innerHTML += '<br /><br />' + result.lagerstand;
			}
			
			Effect.Appear('message_' + id, { duration : 0.25 });
			$('message_' + id).onclick = function() {
				Effect.Fade('message_' + id, { duration : 0.25 });
			}
		}
	});
	return false;
}