﻿/*
Author: Addam M. Driver
Date: 10/31/2006
Modified: Sergio A Adame
Date: 09/30/2008
*/

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;
var alreadyRated = ","; //Contains the alreadyRated business

// Rollover for image Stars //
function rating(name){
    var num = document.getElementById(name);	
    sMax = 5;
	var sVal = name.substring(name.length-1,name.length);	
	if(sVal=="1")
	    s = 1;
    if(sVal=="2")
        s = 2;
    if(sVal=="3")
	    s = 3;
	if(sVal=="4")
	    s = 4;
	if(sVal=="5")
	    s = 5;
	
	for(i=1; i<=sMax; i++){		
			if(i<=s){
			    document.getElementById("opinaEstrella" + i).className = "on";
				document.getElementById("divOpinionCalificacion").innerHTML = num.title;
			}else{
				document.getElementById("opinaEstrella" + i).className = "";
			}
		}
}

// For when you roll out of the the whole thing //
function off(name){
    var starMe = document.getElementById(name);
	if(preSet!= name){	
		for(i=1; i<=sMax; i++){		
		    document.getElementById("opinaEstrella" + i).className = "";
		    document.getElementById("divOpinionCalificacion").innerHTML = "";
		}
	}else{
		rating(preSet);
	}
}

// When you actually rate something //
function rateIt(name){
    var me = document.getElementById(name);
	
	//if(!rated){
	preSet = name;
	document.getElementById("divOpinionCalificacion").innerHTML = me.title;
	document.getElementById("ctl00_contentMain_opinionCalificacion").value = name.substring(name.length-1,name.length)
	//rated=1;
	//sendRate(me);
	rating(name);
}

// Send the rating information somewhere using Ajax or something like that.
function sendRate(sel){
	alert(document.getElementById("ctl00_contentMain_opinionCalificacion").value);
}


