/*
Author: Addam M. Driver
Date: 10/31/2006
*/

var sMax;	// Isthe maximum number of stars
var holder; // Is the holding pattern for clicked state
if (!preSet) var preSet; // Is the PreSet value onces a selection has been made
if (!rated && rated !== false) var rated;

// 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 == "DIV"){
			sMax++;	
		}
	}*/
	sMax = 5;
	
	if(!rated){	  
		s = num.id.replace("_", ''); // Get the selected star
		a = 0;
		for(i=1; i<=sMax; i++){		
			if(i<=s){
				document.getElementById("_"+i).className = "hat_active";
				//document.getElementById("rateStatus").innerHTML = num.title;	
				holder = a+1;
				a++;
			}else{
				document.getElementById("_"+i).className = "hat";
			}
		}
	}
}

// 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("_"+i).className = "hat";
				//document.getElementById("rateStatus").innerHTML = me.parentNode.title;
			}
		} else{
		  rating(preSet); 
			//document.getElementById("rateStatus").innerHTML = document.getElementById("ratingSaved").innerHTML;
		}
	}
}

// When you actually rate something //
function rateIt(me, kolik, typ, id){
	if(!rated){
		//document.getElementById("rateStatus").innerHTML = document.getElementById("ratingSaved").innerHTML + " :: "+me.title;
		sendRate(kolik, typ, id);
	}
}

// Send the rating information somewhere using Ajax or something like that.
function sendRate(kolik, typ, id){
	var url = '/resource/ajax.php?task=hodnoceni&kde='+typ+'&co='+id+'&hodnoceni=' + kolik;
  var rq = new SZN.HTTPRequest();
	rq.setMethod("get");
	rq.setFormat("txt");
	rq.setMode("async");
  rq.send(url,window,"hodnot_callback");
}

function hodnot_callback(txt, status) {
  if (txt != 'notok' && status == 200) {
    alert(hodnoceni_hlaska);    
    var data = txt.split(':');
    var pocet = data[1];
    var hodnoceni = data[0]; 
    preSet = document.getElementById('_' + hodnoceni);        
    document.getElementById('votecount').innerHTML = pocet;
  } else {
    alert(hodnoceni_hlaska_notok);
  } 
  rating(preSet);
  rated=1;
}


