var sMax = 5;	// Isthe maximum number of stars
var holder; // Is the holding pattern for clicked state
var preSet; // Is the PreSet value onces a selection has been made  .style.backgroundImage = "url(star_on.gif)";
var rated;

// Rollover for image Stars //
function rating(num)
{
	if(!rated)
	{
		s = num.id; // Get the selected star
		a = 0;
		for(i=1; i<=sMax; i++)
		{		
			if(i<=s)
			{
				document.getElementById(i).style.backgroundImage = "url(star_on.gif)";
				document.getElementById("rateStatus").innerHTML = num.name;	
				holder = a+1;
				a++;
			}
			else
			{
				document.getElementById(i).style.backgroundImage = "url(star_off.gif)";
			}
		}
	}
}

function rating_default(num)
{
	if(!rated)
	{
		s = num; // Get the selected star
		a = 0;
		for(i=1; i<=sMax; i++)
		{		
			if(i<=s)
			{
				document.getElementById(i).style.backgroundImage = "url(star_on.gif)";
				holder = a+1;
				a++;
			}
			else
			{
				document.getElementById(i).style.backgroundImage = "url(star_off.gif)";
			}
		}
	}
}

// For when you roll out of the the whole thing //
function off(me){
	if(!rated){
		if(!preSet){	
			for(i=1; i<=sMax; i++){		
				document.getElementById(i).style.backgroundImage = "url(star_off.gif)";
				document.getElementById("rateStatus").innerHTML = "";
			}
		}else{
			rating(preSet);
			document.getElementById("rateStatus").innerHTML = "<span style='color:red'>Rating Saved!</span>";
		}
	}
}

// When you actually rate something //
function rateIt(rate,me,p_id){
	if(!rated){
		document.getElementById("rateStatus").innerHTML = "<span style='color:red'>Rating Saved!</span>";
		preSet = me;
		rated=1;
		sendRate(rate,p_id);
		rating(me);
	}
}

// Send the rating information somewhere using Ajax or something like that.
function sendRate(rate,post_id)
{
	window.location="frame_rate.php?act=add&rate="+rate+"&post_id="+post_id;
	//alert(rate);
	//var data_str=rate+","+p_id;
	//x_save_rate(data_str, update_div);
	//alert("ma3 el salameh");
}

function update_div()
{
	//document.getElementById("rateStatus").innerHTML="ok";
}














