var matchRatings = new Array();
var matchRateIdMap = new Array();
/*	matchRateIdMap[comp].push(rateid)*/

function rateShow(comp,rateid)
{
	var img_src = ""
	var img = ""
	for(x = 1; x <= 5; x++)
	{
		if(matchRatings[comp] && x<=matchRatings[comp])
			img_src='i/bewertungsslider_true.png'
		else
			img_src='i/bewertungsslider_false.png'
		img +='<img src="'+img_src+'"' 
		img += 'id="rating_star'+x+'_'+comp+'_'+rateid+'"'
		img += ' onmouseover="javascript:rateMove('+comp+','+x+','+rateid+');"'
		img += ' onclick="javascript:rateSave('+comp+','+x+','+rateid+');" '
		img += ' onmouseout="javascript:rateReset('+comp+','+x+','+rateid+');" '
		img += '/>' 
	}
	document.write(img)
	if(!matchRateIdMap[comp])
		matchRateIdMap[comp] = new Array()
	matchRateIdMap[comp].push(rateid)
}

function rateMove(comp,rating,rateid)
{
	for(x=1;x<=5;x++)
	{
		if(x <= rating)
			document.getElementById('rating_star'+x+"_"+comp+'_'+rateid).src='i/bewertungsslider_true.png'
		else
			document.getElementById('rating_star'+x+"_"+comp+'_'+rateid).src='i/bewertungsslider_false.png'
	}
}

function rateSaveAlt(comp,rating,rateid)
{
	matchRatings[comp] = rating
}

function rateReset(comp,rating,rateid)
{
	for(x=1;x<=5;x++)
	{
		if(matchRatings[comp] && x<=matchRatings[comp])
			document.getElementById('rating_star'+x+"_"+comp+'_'+rateid).src='i/bewertungsslider_true.png'
		else
			document.getElementById('rating_star'+x+"_"+comp+'_'+rateid).src='i/bewertungsslider_false.png'
	}
}

function rateSave(comp,rateing)
{
	matchRatings[comp] = rateing
	
	for(var x = 0; x < matchRateIdMap[comp].length;x++)
	{
		rateReset(comp,rateing,matchRateIdMap[comp][x])
	}
	
	var url = 'ajax/profile_comp_rateing.php';
	http_request = false;
	if (window.XMLHttpRequest) 
	{ // Mozilla, Safari,...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) 
		{
			http_request.overrideMimeType('text/xml');
		}
	}
	else if (window.ActiveXObject) 
	{ // IE
		try 
		{
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) 
		{
			try 
			{
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch (e) {}
		}
	}

	if (!http_request) 
	{
            return false;
	}

	http_request.open('POST', url, false);
	http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	http_request.send('comp='+comp+'&'+'rateing='+rateing+'&');
	
	if (http_request.readyState == 4) 
	{
		if (http_request.status == 200) 
		{
        	if(http_request.responseText)
        	{
        		//document.getElementById(comp+'rateing').style.display = "block";
        		//document.getElementById(comp+'rateing').innerHTML = http_request.responseText;
        	}
        }
	}
	return false;
}
