/*
Author: Addam M. Driver
Date: 10/31/2006
*/

var sMax;	// 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
var rated=0;

// Rollover for image Stars //
function rating(num,flag){
	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){
		s = num.id.replace("_"+flag, ''); // Get the selected star
		a = 0;
		for(i=1; i<=sMax; i++){		
			if(i<=s){
				document.getElementById("_"+flag+i).className = "on";
				//document.getElementById("rateStatus").innerHTML = num.title;	
				holder = a+1;
				a++;
			}else{
				document.getElementById("_"+flag+i).className = "";
			}
		}
	}
}

// For when you roll out of the the whole thing //
function off(me,flag){
	if(!rated){
		if(!preSet){	
			for(i=1; i<=sMax; i++){		
				document.getElementById("_"+flag+i).className = "";
				//document.getElementById("rateStatus").innerHTML = me.parentNode.title;
			}
		}else{
			rating(preSet);
			//document.getElementById("rateStatus").innerHTML = document.getElementById("ratingSaved").innerHTML;
		}
	}
}

// When you actually rate something //
function rateIt(me){
	if(!rated){
		//document.getElementById("rateStatus").innerHTML = document.getElementById("ratingSaved").innerHTML + " :: "+me.title;
		preSet = me;
		rated++;
		//sendRate(me);
		rating(me);
	}
}

// Send the rating information somewhere using Ajax or something like that.
function sendRate(num){
	s = num.id.replace("_", '');
	document.getElementById("calificar_receta_calificacion").value = s;
	document.formreceta.submit();
	//alert("Your rating was: "+document.getElementById("calificar_receta_calificacion").value);
}

function ranking(num){
	a = 0;
	for(i=1; i<=5; i++){		
		if(i<=num){
			document.getElementById("r"+i).className = "on";	

		}else{
			document.getElementById("r"+i).className = "";
		}
	}
}

function rankingList(letra,num){
	a = 0;
	for(i=1; i<=5; i++){		
		if(i<=num){
			document.getElementById(letra+i).className = "on";	

		}else{
			document.getElementById(letra+i).className = "";
		}
	}
}

function rateLocal(num,nombre,flag){
	s = num.id.replace("_"+flag, '');
	if (!rated)
	{
		document.getElementById("comentario_"+nombre).value = s;	
	}
	preSet = num;
	rated=1;
	
}

function hacerSubmit(form){
	form.submit();
	//alert("Your rating was: "+sel.title);
}

