/**
* Author: Addam M. Driver
* Date: 10/31/2006
* Changes by Vladi 2008
* Changes by Ivan 2008
* Changes by Ogi 2008
* Changes by Ogi 2009
*/


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 starstext = new Array() ;
starstext[0] = "oceń firmę" ;
starstext[1] = "zła jakość usług" ;
starstext[2] = "taka sobie jakość usług" ;
starstext[3] = "niezła jakość usług" ;
starstext[4] = "dobra jakość usług" ;
starstext[5] = "bardzo dobra jakość usług" ;
starstext[6] = "znakomita jakość usług" ;

// Rollover for image Stars //
function rating(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++;	
		}
	}
	
	if(!rated){
		s = num.id.replace("r_", ''); // Get the selected star
		a = 0;
		for(i=1; i<=sMax; i++){		
			if(i<=s){
				document.getElementById("r_"+i).className = "on";
				holder = a+1;
				a++;
			}else{
				document.getElementById("r_"+i).className = "";
			}
		}
		document.getElementById('rate_text').innerHTML = "("+starstext[holder]+")" ;
	}
}

function ratingS(num,id){
	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("r_"+id+"_", ''); // Get the selected star
		a = 0;
		for(i=1; i<=sMax; i++){		
			if(i<=s){
				document.getElementById("r_"+id+"_"+i).className = "on";
				holder = a+1;
				a++;
			}else{
				document.getElementById("r_"+id+"_"+i).className = "";
			}
		}
		document.getElementById('rate_text_'+id).innerHTML = "("+starstext[holder]+")" ;
	}
}

// For when you roll out of the the whole thing //
function off(me){
	if(!rated){
		if(!preSet){	
			for(i=1; i<=sMax; i++){		
				document.getElementById("r_"+i).className = "";
			}
		}else{
			rating(preSet);
		}
	}
	document.getElementById('rate_text').innerHTML = "("+starstext[0]+")" ;
}
function offS(me,id){
	if(!rated){
		if(!preSet){	
			for(i=1; i<=sMax; i++){		
				document.getElementById("r_"+id+"_"+i).className = "";
			}
		}else{
			rating(preSet);
		}
	}
	document.getElementById('rate_text_'+id).innerHTML = "("+starstext[0]+")" ;
}

// When you actually rate something //
function rateIt(me, be){
	if (confirm('Czy na pewno chcesz oddać '+be+' głosów na tę firmę?')) {
		if(!rated){
			preSet = me;
			rated=1;
			sendRate(me);
			rating(me);
		}
	}
}

function rateItS(me,id, be){
	if (confirm('Czy na pewno chcesz oddać '+be+' głosów na tę firmę?')) {
		if(!rated){
			preSet = me;
			rated=1;
			sendRateS(me,id);
			rating(me);
		}
	}
}

// Send the rating information somewhere using Ajax or something like that.
function sendRate(sel){
	var frm = document.getElementById('ranking_frm');
	frm.ranking.value = sel.id.split('r_')[1];
	frm.submit();
}

function sendRateS(sel,id){
	var frm = document.getElementById('ranking_frm_'+id);
	frm.ranking.value = sel.id.split('r_'+id+'_')[1];
	frm.submit();
}
