/*
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;

// Rollover for image Stars //
function rating(num, realValue){
	sMax = 0;	// Isthe maximum number of stars
	for(n=0; n<num.parentNode.childNodes.length; n++){
		if(num.parentNode.childNodes[n].nodeName == "A"){
			sMax++;	
		}
	}
	sMax = 5 /* numero de estrellas */
	if(!(num==null)){
//	if(!rated){
		s = num.id.replace("_", ''); // Get the selected star
		a = 0;
		for(i=1; i<=sMax; i++){		
			if(i<=s){
				if ((!(realValue==null))&&(realValue==0)){
					document.getElementById("_"+i).className = "";
					holder = a+1;
					a++;
					}
				else {
				document.getElementById("_"+i).className = "starOn";
				holder = a+1;
				a++;
				};
			}else{
				document.getElementById("_"+i).className = "";
			}
		}
	}
}

function ratingOver(num){
	sMax = 0;	// Isthe maximum number of stars
	for(n=0; n<num.parentNode.childNodes.length; n++){
		if(num.parentNode.childNodes[n].nodeName == "A"){
			sMax++;	
		}
	}
	sMax = 5 /* numero de estrellas */
//	if(!(num==null)){
//	if(!rated){
// si no ha sido valorado
//if (document.formRating.ratingField.value == 0) {
	s = num.id.replace("_", ''); // Get the selected star
		a = 0;
		for(i=1; i<=sMax; i++){		
			if(i<=s){
				document.getElementById("_"+i).className = "starOver";
				holder = a+1;
				a++;
			}else{
				document.getElementById("_"+i).className = "";
			}
		}
//	}
}

// For when you roll out of the the whole thing //
function off(me,currentValue){
	var realValue = currentValue;
	if (currentValue==0) {currentValue=1}
	if(!(me==null)){
//	if(!rated){
		if(!preSet){	
			for(i=1; i<=sMax; i++){		
				rating(document.getElementById("_"+currentValue), realValue);
				//document.getElementById("_"+i).className = ""
			}
		}else{
			rating(document.getElementById("_"+currentValue), realValue);
			//rating(preSet);
		}
	}
}

// When you actually rate something //
function rateIt(me){
//	if(!rated){
//	if (document.formRating.ratingField.value == 0) {
		preSet = me;
		rated=1;
		sendRate(me);
		//rating(me);
//	}
}

// Send the rating information somewhere using Ajax or something like that.
function sendRate(sel){
	document.formRating.ratingField.value = parseInt(preSet.id.replace("_", ''));
	xajax_votar(document.formRating.ratingIdClip.value, document.formRating.ratingField.value);
//	alert ("Tu valoraci"+String.fromCharCode(243)+"n de "+parseInt(preSet.id.replace("_", ''))+" ha sido registrada" );
//	alert("Your rating was: "+parseInt(preSet.id.replace("_", '')));
}


