var sMax;	
var holder; // Is the holding pattern for clicked state
var rated;
var ratedval;

var ratedGroup = new Array();
var groupSelectedID = new Array();
var ratingform;



// Rollover for image Stars //

function set_star_variables(val1,val2)
{
	// 1. max stars
	// 2. form name
	sMax = val1;
	ratingform = val2;
	
}

// starobj, divgroup, selected val
function rating(object,group,selval,groupID)
{
	
	starobj = group+"_star_";
	
	for(i=1; i<=sMax; i++)
	{		
		if(i<=selval)
		{
			document.getElementById(starobj+i).className = "on";
			
		}
		else
		{
			document.getElementById(starobj+i).className = "";
		}
	}
	
}




// For when you roll out of the the whole thing //
function off(me,group,selval,groupID){
	
	
	starobj = group+"_star_";
	

	
	
	if (ratedGroup.length>0)
	{
		// what the hell @ indexOf does not work in IE 
		// we now need to do manual searching
		
		var tmpvalfound = -1;
		
		
		for(var i=0; i<ratedGroup.length; i++)
		{
		    if(ratedGroup[i]==groupID)
		    {
		        tmpvalfound = i;
		        break;
		    }
		}
		
		// IE does not support indexOf
		
		
		
		if (tmpvalfound=='-1')
		{
		
				for(i=1; i<=sMax; i++)
				{		
					document.getElementById(starobj+i).className = "";
					
				}
			
		}
		else
		{
			rated_star = groupSelectedID[groupID];
		
			
			rating(me,group,rated_star,groupID); // restore rated value on mouse out
		}
	}
	else
	{
			for(i=1; i<=sMax; i++)
			{		
				document.getElementById(starobj+i).className = "";
					
			}
	}
	
	
	
	
	
	
}




// starID, groupLabel, starValue(1-10), groupID

function rateIt(me,group,selval,groupID)
{
	
	ratedGroup[groupID] = groupID;
	groupSelectedID[groupID] = selval;
	
	
	
	
	
		
	saveRate(groupID,selval); // function if you wish to manipulate some values
	
	rating(me,group,selval,groupID); // show the selected ratings
	
}






// Send the rating information somewhere using Ajax or something like that.
function saveRate(group,val)
{
	eval("document."+ratingform+".property_"+group+".value = val;");
}
