var listeSet = new Array();
var nbSet = 0;
var set=false;
var v=0;
var a;
var listeInitialId = new Array();
var listeInitialStars = new Array();
var nbFaqs = 0;

function loadStars()
{
star1 = new Image();
star1.src = "/cs/Mut509/images/ml/star_empty.gif";
star2 = new Image();
star2.src = "/cs/Mut509/images/ml/star.gif";
}

function updateValueInFatwire(theid, x)
{
	var idfaq = theid.substring("star_".length, theid.length -1); 
	
	// REPLACE THIS CODE BY AJAX CALL
	//alert("ID OF FAQ --> " + idfaq + " : " + x + " star(s)");
	updateAsset('vote', 'Mut509_FAQ', idfaq, x);
}


function addFaq(theid, thestars)
{
	listeInitialId[nbFaqs] = theid;
	listeInitialStars[nbFaqs] = thestars;
	nbFaqs++;
}

function highlight(theid, x)
{
	if (isInListeSet(theid)==false)
	{
		y=x*1+1
	
		for (i=1;i<6;i++)
		{
			document.getElementById(theid + "" + i).src= star1.src;
		}
		
		if (x == 1) {
			document.getElementById(theid + "" + x).src= star2.src;
		} else if (x == 2) {
			for (i=1;i<3;i++)
			{
				document.getElementById(theid + "" + i).src= star2.src;
			}
		} else if (x == 3) {
			for (i=1;i<4;i++)
			{
				document.getElementById(theid + "" + i).src= star2.src;
			}
			
		} else if (x == 4) {
			for (i=1;i<5;i++)
			{
				document.getElementById(theid + "" + i).src= star2.src;
			}
		
		} else if (x == 5) {
			for (i=1;i<6;i++)
			{
				document.getElementById(theid + "" + i).src= star2.src;
			}
		}		
		
	}
}
function losehighlight(theid, x)
{
	if (isInListeSet(theid)==false)
	{
		var thenumber = 0;
		for (var j = 0; j < nbFaqs; j++) {
			if (listeInitialId[j] == theid) {
				thenumber = j;
				break;
			}
		}
		var theinitialstars = listeInitialStars[thenumber];
		if (theinitialstars == 0) {
			theinitialstars = -1;
		}
		
		for (i=5;i>theinitialstars;i--)
		{
			document.getElementById("" + theid + i).src=star1.src;
			//document.getElementById('vote').innerHTML=""
		}
		for (i=1;i<(theinitialstars+1);i++)
		{
			document.getElementById("" + theid + i).src=star2.src;
			//document.getElementById('vote').innerHTML=""
		}
	}
}

function isInListeSet(thevariable) 
{
	for (var i = 0; i < nbSet; i++) {
		if (listeSet[i] == thevariable) {
			return true;
		}
	}
	return false;
}

function setStar(theid, x)
{
y=x*1+1
if (isInListeSet(theid)==false)
	{
	switch(x)
		{
		case "1": a="1" 
		flash(theid, a);
		break;
		case "2": a="2" 
		flash(theid, a);
		break;
		case "3": a="3" 
		flash(theid, a);
		break;
		case "4":a="4" 
		flash(theid, a);
		break;
		case "5":a="5" 
		flash(theid, a);
		break;
		}
	listeSet[nbSet] = theid;
	nbSet++;
	updateValueInFatwire(theid, x);
	//document.getElementById('vote').innerHTML="Thank you for your vote!"
	}	
}


function flash(theid, a)
{
y=a*1+1
switch(v)
	{
	case 0:
	for (i=1;i<y;i++)	
		{
		document.getElementById("" + theid + i).src= star1.src;
		}
	v=1
	setTimeout(flash,200)
	break;
	case 1:	
	for (i=1;i<y;i++)	
		{
		document.getElementById("" + theid + i).src= star2.src;
		}
	v=2
	setTimeout(flash,200)
	break;
	case 2:
	for (i=1;i<y;i++)	
		{
		document.getElementById("" + theid + i).src= star1.src;
		}
	v=3
	setTimeout(flash,200)
	break;
	case 3:
	for (i=1;i<y;i++)	
		{
		document.getElementById("" + theid + i).src= star2.src;
		}
	v=4
	setTimeout(flash,200)
	break;
	case 4:
	for (i=1;i<y;i++)	
		{
		document.getElementById("" + theid + i).src= star1.src;
		}
	v=5
	setTimeout(flash,200)
	break;
	case 5:
	for (i=1;i<y;i++)	
		{
		document.getElementById("" + theid + i).src= star2.src;
		}
	v=6
	setTimeout(flash,200)
	break;
	}
}