﻿var sMax;	// Isthe maximum number of stars
var holder; // Is the holding pattern for clicked state
var preSet = new Array; // Is the PreSet value onces a selection has been made
var rated = new Array;

rated[0] = false;
rated[1] = false;
rated[2] = false;
rated[3] = false;

var areas = new Array();
areas[0] = "rateFood";
areas[1] = "rateValue";
areas[2] = "rateService";
areas[3] = "rateAtmosphere";

var theHiddenField = '';

// Rollover for image Stars //
function rating(num, index){
	sMax = 0;	// Isthe maximum number of stars
	for(n=0; n<num.parentNode.childNodes.length; n++){
		if(num.parentNode.childNodes[n].nodeName == "A"){
			sMax++;			
		}
	}
		
	if(!rated[index]){
		s = num.id.replace(areas[index] + "_", ''); // Get the selected star
		a = 0;
		
		for(i=1; i<=sMax; i++){		
			if(i<=s){			    
				document.getElementById(areas[index] + "_"+i).className = "on";				
				holder = a+1;
				a++;																			
			}else{				    
				document.getElementById(areas[index] + "_" + i).className = "";
			}
		}
		try
		{		
		    document.getElementById(theHiddenField).value = a;
		    theHiddenField = '';
		}
		catch(ex)
		{
		    // do nothing
		}
	}	
}

// For when you roll out of the the whole thing //
function off(me, index){
	if(!rated[index]){
		if(!preSet[index]){	
			for(i=1; i<=sMax; i++){		
				document.getElementById(areas[index] + "_" + i).className = "";				
			}
		}else{
			rating(preSet[index]);			
		}
	}
}

// When you actually rate something //
function rateIt(me, index, hf){
	
	if(!rated[index]){	    
		preSet[index] = me;		
		theHiddenField = hf;	
		rating(me, index);
		rated[index]=1;
	}
}
