/*
Based on a Web-Tutorial by
Author: Addam M. Driver
Date: 10/31/2006
*/

var maxVal     = 5;	// Isthe maximum number of stars
var star_id_re = /^(\d+)_(\d+)$/;
var preset     = []; // Is the PreSet value onces a selection has been made
var rated      = [];

function getRef(star){
    match  = star_id_re.exec(star.id);
    return match[1];
}

function getVal(star){
    match  = star_id_re.exec(star.id);
    return match[2];
}

function getStar(ref, val){
    return document.getElementById(ref+"_"+val);
}

// Rollover for image Stars //
function over(star){
    ref = getRef(star);
	if(!rated[ref]){
        val    = getVal(star);
		for(i=1; i<=maxVal; i++){		
			if(i<=val)
				document.getElementById(ref+"_"+i).className = "on";
			else
				document.getElementById(ref+"_"+i).className = "";
		}
	}
}

// For when you roll out of the the whole thing //
function out(star){
    ref = getRef(star);
	if(!rated[ref]){
		if(!preset[ref]){	
			for(i=1; i<=maxVal; i++){		
				document.getElementById(ref+"_"+i).className = "";
			}
		}
        else{
			over(getStar(ref, preset[ref]));
		}
	}
}

// When you actually rate something //
function rateIt(star){
    ref = getRef(star);
	if(!rated[ref]){
        val = getVal(star);
		preset[ref] = val;
		rated[ref]=1;
		sendRate(ref, val);
		over(star);
	}
}

// Send the rating information somewhere using Ajax or something like that.
function sendRate(ref, val){
    //window.open ("blog-entry-rate.php?bewerbung="+ref+"&bewertung="+val,"ratingwindow", "status=0,toolbar=0,location=0,menubar=0,width=560,height=400,scrollbars=auto");
    document.location.href="blog-entry-rate.php?bewerbung="+ref+"&bewertung="+val,"ratingwindow";
}


