// JavaScript Document

var csMax;	// Isthe maximum number of stars
var cholder; // Is the holding pattern for clicked state
var cpreSet; // Is the cpreSet value onces a selection has been made
var crated=0;

// Rollover for image Stars //
function comidaRating(num,flag){
	csMax = 0;	// Isthe maximum number of stars
	for(n=0; n<num.parentNode.childNodes.length; n++){
		if(num.parentNode.childNodes[n].nodeName == "A"){
			csMax++;	
		}
	}

	if(!crated){
		s = num.id.replace("_"+flag, ''); // Get the selected star
		a = 0;
		for(i=1; i<=csMax; i++){		
			if(i<=s){
				document.getElementById("_"+flag+i).className = "on";
				//document.getElementById("rateStatus").innerHTML = num.title;	
				cholder = a+1;
				a++;
			}else{
				document.getElementById("_"+flag+i).className = "";
			}
		}
	}
}

// For when you roll out of the the whole thing //
function comidaOff(me,flag){
	if(!crated){
		if(!cpreSet){	
			for(i=1; i<=csMax; i++){		
				document.getElementById("_"+flag+i).className = "";
				//document.getElementById("rateStatus").innerHTML = me.parentNode.title;
			}
		}else{
			rating(cpreSet);
			//document.getElementById("rateStatus").innerHTML = document.getElementById("ratingSaved").innerHTML;
		}
	}
}

// When you actually rate something //
function comidaRateIt(me){
	if(!crated){
		//document.getElementById("rateStatus").innerHTML = document.getElementById("ratingSaved").innerHTML + " :: "+me.title;
		cpreSet = me;
		crated++;
		//sendRate(me);
		rating(me);
	}
}

function comidaRate(num,flag){
	s = num.id.replace("_"+flag, '');
	if (!crated)
	{
		document.getElementById("comentario_comida").value = s;	
	}
	cpreSet = num;
	crated=1;	
}
