function gel(what) { return document.getElementById(what); }
function dn(what) { return document.createElement(what); }
function dac(what,c) { what.appendChild(c); }
function dat(what,s) { dac(what,document.createTextNode(s)); }
function hv(num)
{
if(num==-1) { hv(current_rating); gel.innerHTML = curviews + " views &#0183; " + current_rated + " ratings"; } else {
for( x=1;x<6;x++ ) {
if( x <= num ) document.getElementById("star"+x).style.backgroundImage="url(/images/tpl_icon_star_full.gif)";
if( x > num ) document.getElementById("star"+x).style.backgroundImage="url(/images/tpl_icon_star_empty.gif)";
}
}
}
function dhv(state)
{
if(state) {
/*
if(rating_uid == "") { 
	gel("infoDiv").innerHTML = "";
	//gel("infoDiv").innerHTML = '<a href="/login.php" id="llink">Login</a> to rate this video';
	gel("loginDiv").onmouseover = function() { dhv(1); };
	gel("infoDiv").style.display = "none";
	gel("loginDiv").style.display = "block";
	gel("rateDiv").onmouseout = null;
	gel("loginDiv").onmouseout = function() { dhv(0); };
} else*/
	gel("infoDiv").innerHTML = 'Click to rate';
} else {
gel("infoDiv").innerHTML = curviews + " views &#0183; " + current_rated + ' ratings';
/*
if( rating_uid == "" ) {
	gel("infoDiv").onmouseout = null;
	gel("rateDiv").onmouseover = function() { dhv(1); }; 
	gel("loginDiv").style.display = "none";
	gel("infoDiv").style.display = "block";
}
*/
}
}
function rr(r)
{
var cnt = r.getElementsByTagName("trate").item(0).firstChild.data;
if(cnt!='exist') {
hv(cnt);
current_rate = cnt; 
document.getElementById("infoDiv").style.display = "block";
document.getElementById("infoDiv").innerHTML = "Thank you for voting!";
} else {
document.getElementById("infoDiv").style.display = "block";
document.getElementById("infoDiv").innerHTML = "You have already voted.";
}
document.getElementById("starlist").onmouseout = null;
}
function ra(r)
{
for( x=1;x<6;x++ ) {
        document.getElementById("star"+x).onmouseover = null;
        document.getElementById("star"+x).onclick = null;
}
if( what == "video" )
	func = "process_data";
else if( what == "submission" )
	func = "rate_sub";
 
document.getElementById("infoDiv").innerHTML = "Recording Vote...";
cp.call( "/ajax/myajaxphp.php", func, rr, r * 2, video_id );
document.getElementById("starlist").className += " rated";
}
function rate_init()
{
/*
for( x=1;x<6;x++ ) {
        document.getElementById("star"+x).onmouseover = eval( "function() { hv("+x+"); }" );
        document.getElementById("star"+x).onclick = eval( "function() { ra("+x+"); }" );
}
*/
document.getElementById("star1").onmouseover = function() { hv(1); };
document.getElementById("star1").onclick = function() { ra(1); };
document.getElementById("star2").onmouseover = function() { hv(2); };
document.getElementById("star2").onclick = function() { ra(2); };
document.getElementById("star3").onmouseover = function() { hv(3); };
document.getElementById("star3").onclick = function() { ra(3); };
document.getElementById("star4").onmouseover = function() { hv(4); };
document.getElementById("star4").onclick = function() { ra(4); };
document.getElementById("star5").onmouseover = function() { hv(5); };
document.getElementById("star5").onclick = function() { ra(5); };

gel("rateDiv").onmouseover = function() { dhv(1); };
gel("rateDiv").onmouseout = function() { dhv(0); };
}
var current_rating = 0;
var current_rated = 0;
var vid = 0;
var curviews = 0;
var what = "video";
var rating_uid = "";

