function shocast(movieID, actorID, order, page)
{
    var urlz = "/cast/xmlcast?movieID=" + movieID + "&actorID=" + actorID + "&order=" + order + "&page=" + page;
    loadXMLDoccast(urlz);
}
var reqcast;
function loadXMLDoccast(url)
{
    if (window.XMLHttpRequest)
    {
        // branch for native XMLHttpRequest object
        reqcast = new XMLHttpRequest();
        reqcast.onreadystatechange = processReqChangecast;
        reqcast.open("GET", url, true);
        reqcast.send(null);
    }
    else if (window.ActiveXObject)
    {
        // branch for IE/Windows ActiveX version
        reqcast = new ActiveXObject("Microsoft.XMLHTTP");
        if (reqcast)
        {
            reqcast.onreadystatechange = processReqChangecast;
            reqcast.open("GET", url, true);
            reqcast.send();
        }
    }
}

function processReqChangecast()
{
    if (reqcast.readyState == 4)
    {
        if (reqcast.status == 200)
        {
            response = reqcast.responseXML.documentElement;
            var totalcasts = response.getElementsByTagName("totalcasts")[0].firstChild.data;
            var thismovieID = response.getElementsByTagName("thismovieID")[0].firstChild.data;
            var thisactorID = response.getElementsByTagName("thisactorID")[0].firstChild.data;
            var thisorder = response.getElementsByTagName("thisorder")[0].firstChild.data;
            var thispage = response.getElementsByTagName("thispage")[0].firstChild.data;
            var totalpages = response.getElementsByTagName("totalpages")[0].firstChild.data;
            if(totalcasts>=1)
            {
                var result_string = '';
                thispage = Math.abs(thispage);
                totalpages = Math.abs(totalpages);
                var previouspage = Math.abs(thispage)-1;
                var nextpage = Math.abs(thispage)+1;
                if(totalpages>1)
                {
                    if(thispage>1)
                    {
                        var previousbuttonpage = '<a onclick="shocast(' + thismovieID + ', ' + thisactorID + ', ' + "'" + thisorder + "'" + ', ' + previouspage + ')" style="cursor:pointer;">previous page</a> | ';
                    }
                    else
                    {
                        var previousbuttonpage = '';
                    }
                    if(thispage<totalpages)
                    {
                        var nextbuttonpage = ' | <a onclick="shocast(' + thismovieID + ', ' + thisactorID + ', ' + "'" + thisorder + "'" + ', ' + nextpage + ')" style="cursor:pointer;">next page</a>';
                    }
                    else
                    {
                        var nextbuttonpage = '';
                    }
                    var paginationstring = '<div class="effect" style="font-size:80%;">' + previousbuttonpage + "page " + thispage + " of " + totalpages + nextbuttonpage + '</div>';
                }
                else
                {
                    paginationstring = '';
                }






                if(thismovieID==0)
                {
                    var thisleftcolumnname = "movie";
                }
                else
                {
                    var thisleftcolumnname = "actor";
                }
                result_string = result_string + paginationstring + '<table class="castliner">';
                var count = 0;
                var willhavetoload=new Array();
                while(count < totalcasts)
                {
                    count++;
                    var this_castID_name = 'castID-' + count;
                    var this_movieID_name = 'movieID-' + count;
                    var this_actorID_name = 'actorID-' + count;
                    var this_role_name = 'role-' + count;
                    var this_rating_name = 'rating-' + count;
                    var this_votes_name = 'votes-' + count;
                    var this_time_name = 'time-' + count;
                    var this_userID_name = 'userID-' + count;
                    var this_actor_name_name = 'actor_name-' + count;
                    var this_movie_name_name = 'movie_name-' + count;
                    var this_movie_year_name = 'movie_year-' + count;
                    var this_castID = response.getElementsByTagName(this_castID_name)[0].firstChild.data;
                    var this_movieID = response.getElementsByTagName(this_movieID_name)[0].firstChild.data;
                    var this_actorID = response.getElementsByTagName(this_actorID_name)[0].firstChild.data;
                    var this_role = response.getElementsByTagName(this_role_name)[0].firstChild.data;
                    var this_rating = response.getElementsByTagName(this_rating_name)[0].firstChild.data;
                    var this_votes = response.getElementsByTagName(this_votes_name)[0].firstChild.data;
                    var this_time = response.getElementsByTagName(this_time_name)[0].firstChild.data;
                    var this_userID = response.getElementsByTagName(this_userID_name)[0].firstChild.data;
                    var this_actor_name = response.getElementsByTagName(this_actor_name_name)[0].firstChild.data;
                    var this_movie_name = response.getElementsByTagName(this_movie_name_name)[0].firstChild.data;
                    var this_movie_year = response.getElementsByTagName(this_movie_year_name)[0].firstChild.data;
                    var this_poster_publicname_name = 'publicname-' + this_userID;
                    var this_poster_publicname = response.getElementsByTagName(this_poster_publicname_name)[0].firstChild.data;
                    if(this_movie_year == '0')
                    {
                        var show_movie_year = '';
                    }
                    else
                    {
                        var show_movie_year = ' ' + this_movie_year;
                    }

                    var oneortwo = (count % 2 ) + 1;
                    var cellclass = 'castcolor' + oneortwo;
                    var unavpic = '/noface.png';
                    if(thismovieID==0)
                    {
                        var this_movie_pic_name = 'movie_pic-' + this_movieID;
                        var this_movie_pic = response.getElementsByTagName(this_movie_pic_name)[0].firstChild.data;
                        var this_movie_pic_name_upp = 'movie_pic_upp-' + this_movieID;
                        var this_movie_pic_upp = response.getElementsByTagName(this_movie_pic_name_upp)[0].firstChild.data;
                        var moviepicid = 'moviepic' + this_castID;
                        if(this_movie_pic=='none')
                        {
                            this_movie_pic='/image_not_available_small.jpg';
                        }
                        var widier = "";
                        if(this_movie_pic_upp==1)
                        {
                            var widier = "width:20px;height:30px;";
                        }
                        else
                        {
                            this_movie_pic = this_movie_pic.replace('_w_40_h_40_','_w_20_h_30_');
                        }
                        var thisshitforleftside = '<td style="text-align:center;vertical-align:middle;" class="' + cellclass + '"><a href="/linkz?m=' + this_movieID + '"><img src="'+ this_movie_pic + '" style="' + widier + 'border:none;padding:1px;" id="' + moviepicid + '"  /></a></td><td style="text-align:left;vertical-align:middle;" class="' + cellclass + '"><a href="/linkz?m=' + this_movieID + '">' + this_movie_name + '</a> ' + show_movie_year + '</td>';
                        if(this_movie_pic_upp==1)
                        {
                            willhavetoload[moviepicid]=this_movie_pic;
                        }
                        unavpic = '/image_not_available_small.jpg';
                    }
                    else
                    {
                        var this_actor_pic_name = 'actor_pic-' + this_actorID;
                        var this_actor_pic = response.getElementsByTagName(this_actor_pic_name)[0].firstChild.data;
                        var actorpicid = 'actorpic' + this_castID;
                        if(this_actor_pic=='none')
                        {
                            this_actor_pic='/noface.png';
                        }
                        var thisshitforleftside = '<td style="text-align:center;vertical-align:middle;" class="' + cellclass + '"><a href="/cast_member?actor=' + this_actorID + '"><img src="'+ this_actor_pic + '" style="width:20px;height:30px;border:none;padding:1px;" id="' + actorpicid + '" /></a></td><td style="text-align:left;vertical-align:middle;" class="' + cellclass + '"><a href="/cast_member?actor=' + this_actorID + '">' + this_actor_name + '</a></td>';
                        willhavetoload[actorpicid]=this_actor_pic;
                    }
                    var votespanid = 'cast_votes_string_' + this_castID;
                    var votersblok = "<span id='" + votespanid + "'>" + makecastvotesstring(this_rating, this_votes, this_castID) + "</span>";

                    var votestd = ""
                    if(castvotes != 'off')
                        {votestd = "<td style='text-align:left;vertical-align:middle;' class='" + cellclass + "'>" + votersblok + "</td>";}
                    
                    var thisdatarow = "<tr>" + thisshitforleftside + "<td class='" + cellclass + "'>...</td><td style='text-align:left;vertical-align:middle;' class='" + cellclass + "'> " + this_role + "</td>" + votestd + "</tr>";
                    result_string = result_string + thisdatarow;
                }
                result_string = result_string + "</table>" + paginationstring;
                document.getElementById("cast_" + thismovieID).innerHTML = result_string;

                for(x in willhavetoload)
                {
                    put_pic(x,willhavetoload[x],unavpic,50,30);
                }
            }
            else
            {
                document.getElementById("cast_" + thismovieID).innerHTML = '<!-- -->';
            }
        }
        else
        {
            //alert("There was a problem retrieving the XML data:\n" + reqcast.statusText);
        }
    }
}

function makecastvotesstring(rating, votes, castID)
{
    var thinger = 'cast';
    if(votes==1)
    {
        var votesS = '';
    }
    else
    {
        var votesS = 's';
    }
    var votesstring = "<span style='font-size:85%;'>rating: <b>" + rating + "</b>, " + votes + " vote" + votesS + "</span>";
    votesstring = votesstring + "<br /><span style='font-size:75%;'>vote: <a onclick='vote" + thinger + "(" + castID + ", 0)' style='cursor:pointer;'>0</a>, <a onclick='vote" + thinger + "(" + castID + ", 1)' style='cursor:pointer;'>1</a>, <a onclick='vote" + thinger + "(" + castID + ", 2)' style='cursor:pointer;'>2</a>, <a onclick='vote" + thinger + "(" + castID + ", 3)' style='cursor:pointer;'>3</a>, <a onclick='vote" + thinger + "(" + castID + ", 4)' style='cursor:pointer;'>4</a>, <a onclick='vote" + thinger + "(" + castID + ", 5)' style='cursor:pointer;'>5</a>, <a onclick='vote" + thinger + "(" + castID + ", 6)' style='cursor:pointer;'>6</a>, <a onclick='vote" + thinger + "(" + castID + ", 7)' style='cursor:pointer;'>7</a>, <a onclick='vote" + thinger + "(" + castID + ", 8)' style='cursor:pointer;'>8</a>, <a onclick='vote" + thinger + "(" + castID + ", 9)' style='cursor:pointer;'>9</a>, <a onclick='vote" + thinger + "(" + castID + ", 10)' style='cursor:pointer;'>10</a></span>";
    return votesstring;
}





function votecast(castID, note)
{
    var votesbox = 'cast_votes_string_' + castID;
    document.getElementById(votesbox).innerHTML = '...Loading...';
    var urlz = "/cast/xmlvotecast?castID=" + castID + "&note=" + note;
    loadXMLDocvotecast(urlz);
}
var reqvotecast;
function loadXMLDocvotecast(url)
{
    if (window.XMLHttpRequest)
    {
        // branch for native XMLHttpRequest object
        reqvotecast = new XMLHttpRequest();
        reqvotecast.onreadystatechange = processReqChangevotecast;
        reqvotecast.open("GET", url, true);
        reqvotecast.send(null);
    }
    else if (window.ActiveXObject)
    {
        // branch for IE/Windows ActiveX version
        reqvotecast = new ActiveXObject("Microsoft.XMLHTTP");
        if (reqvotecast)
        {
            reqvotecast.onreadystatechange = processReqChangevotecast;
            reqvotecast.open("GET", url, true);
            reqvotecast.send();
        }
    }
}
function processReqChangevotecast()
{
    if (reqvotecast.readyState == 4)
    {
        if (reqvotecast.status == 200)
        {
            var response = reqvotecast.responseXML.documentElement;
            var result = response.getElementsByTagName("result")[0].firstChild.data;
            var rating = response.getElementsByTagName("rating")[0].firstChild.data;
            var votes = response.getElementsByTagName("votes")[0].firstChild.data;
            var castID = response.getElementsByTagName("castID")[0].firstChild.data;
            if(result=='ok')
            {
                var votesbox = 'cast_votes_string_' + castID;
                var redonevotesbox = makecastvotesstring(rating, votes, castID);
                document.getElementById(votesbox).innerHTML = redonevotesbox;
            }
        }
        else
        {
            //alert("There was a problem retrieving the XML data:\n" + reqvotecast.statusText);
        }
    }
}







