var stars = new Array();
var star_images = new Array();
function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function () {
            oldonload();
            func();
        }
    }
}
function doc_id(id) {
    return document.getElementById(id);
}
function link(link_id) {
    window.open(siteurl + "link.php?link=" + link_id);
    return false;
}
function makeHttpRequest(url, callback_function, return_xml, post_data) {
    var xmlHttp, response;
    try {
        xmlHttp = new XMLHttpRequest();
    } catch (e) {
        try {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    if (!xmlHttp) return;
    xmlHttp.onreadystatechange = function () {
        if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
            if (return_xml) {
                response = eval('(' + xmlHttp.responseText + ')');
            } else {
                response = xmlHttp.responseText;
            }
            callback_function(response);
        }
    };
    if (post_data) {
        xmlHttp.open("POST", url, true);
        xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        xmlHttp.send(post_data);
    } else {
        xmlHttp.open("GET", url, true);
        xmlHttp.send(null);
    }
}
function init_rate_video() {
    for (var i = 1; i <= 5; i++) {
        stars[i] = doc_id("rate_" + i);
        star_images[i] = stars[i].src;
        stars[i].style.cursor = "pointer";
        stars[i].title = i;
        stars[i].onmouseover = function () {
            star_hover(this.title);
        };
        stars[i].onmouseout = clear_stars;
        stars[i].onclick = function () {
            rate_video(this.title);
        };
    }
}

function star_hover(star_id) {
    for (i = 1; i <= star_id; i++) stars[i].src = siteurl + "/images/star1.png";
}

function clear_stars() {
    for (i = 1; i <= 5; i++) stars[i].src = star_images[i];
}

function rate_video(rating) {
    function back_function(server_r) {
        doc_id("video_rating").innerHTML = server_r.rating;
    }
    makeHttpRequest(siteurl + "video.php?id=" + video_id + "&a=rate&r=" + rating + "&ajax=1", back_function, true);
}
addLoadEvent(init_rate_video);

