var ratingDescr		= new Array('Nudny', 'Taki sobie', 'Dobry', '¦wietny', 'Rewelacja!');
var ratingDescrHTML	= null;
var ratingsOriginalHTML	= null;
var langThankYou		= 'Dziêki';
var langRatings			= 'ranking';

function getRatingsDiv() {
	if (ratingDescrHTML == null) {
		ratingDescrHTML	= document.getElementById('ratingDescr');
	}
	if (ratingsOriginalHTML == null) {
		//ratingsOriginalHTML	= document.getElementById('ratingDescr').innerHTML;
		temp = document.getElementById('ratingDescr');
		if(temp != null)ratingsOriginalHTML = temp.innerHTML;
	}
}

function getVar(id) {
	getRatingsDiv();
	
	if (window['allowRating_'+id] == undefined) {
		window['allowRating_'+id] = 1;
	}
	
	return window['allowRating_'+id];
}

function ratingShowStars(i, id) {
	if (getVar(id)) {
		for (j=1; j<=5; j++) {
			if (j<=i)
				document.getElementById('stars'+j+'_'+id).className = document.getElementById('sb2o').className;
			else
				document.getElementById('stars'+j+'_'+id).className = document.getElementById('sb0o').className;
		}
		if (typeof(ratingDescrHTML) != 'undefined' && ratingDescrHTML != null) {
			ratingDescrHTML.innerHTML = '<span style="color: #4A4A4A"><b>'+ratingDescr[i-1]+'</b></span>';
		}
	}
}

function ratingOriginalStars(i, id) {
	if (getVar(id)) {
		for (j=1; j<=5; j++) {
			document.getElementById('stars'+j+'_'+id).className = document.getElementById('sb'+window['currentStars_'+id][j-1]).className;
		}
		if (typeof(ratingDescrHTML) != 'undefined' && ratingDescrHTML != null) {
			ratingDescrHTML.innerHTML = ratingsOriginalHTML;
		}
	}
}

var ratingImage=new Image();

function saveRating(type, id, i) {
	if (getVar(id)) {
		window['allowRating_'+id]		= 0;
		
		if(type == '1'){
		$("#resp_duration").load("_info.php?a=tub_vote&id=" + id + "&rate=" +i+ "&typ=1").slideDown("slow");
		}
		
		if(type == '2'){
		$("#resp_duration").load("_info.php?a=tub_vote&id=" + id + "&rate=" +i+ "&typ=2").slideDown("slow");
		}
		
		if(type == '3'){
		$("#resp_duration").load("_info.php?a=tub_vote&id=" + id + "&rate=" +i+ "&typ=3").slideDown("slow");
		}
		
		
		if (typeof(ratingDescrHTML) != 'undefined' && ratingDescrHTML != null) {
			ratingDescrHTML.innerHTML	= langThankYou;
		}
		
		var ratingsNum = document.getElementById('ratingsNum');
		if (typeof(ratingsNum) != 'undefined' && ratingsNum != null) {
			ratingsNum.innerHTML		= window['ratings_'+id].formatMoney(0,'.',',') + ' ' + langRatings;
		}
	}
}

Number.prototype.formatMoney = function(c, d, t){
var n = this, c = isNaN(c = Math.abs(c)) ? 2 : c, d = d == undefined ? "," : d, t = t == undefined ? "." : t, s = n < 0 ? "-" : "", i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0;
   return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
 };
