function onbutton(linkname, pic)
{
    document.getElementById(linkname).src = (pic)
}
function hovercolor(color,linkname)
{
    document.getElementById(linkname).style.color = (color)
}
function pop_normal_page(url)
{
    window.open(url, 'user_page', "fullscreen=yes,scrollbars=yes,toolbar=yes,location=yes,menubar=yes,directories=yes,resizable=yes,status=yes")
}


function rotatad(iframe_id)
{
    var random_time = (Math.random())*random_timez;
    random_time = Math.floor(random_time);
    var fixed_time = fixed_timez;
    var waiting_time = random_time + fixed_time;
    var javascrexpr = "exec_rotatad('" + iframe_id + "')";
    var t = setTimeout(javascrexpr,waiting_time);
}
function exec_rotatad(iframe_id)
{
    var thiselement = document.getElementById(iframe_id);
    if(thiselement!=null)
    {
        var thecurrent_src = document.getElementById(iframe_id).src;
        //reassign source
        document.getElementById(iframe_id).src = thecurrent_src;
        //call another turn
        rotatad(iframe_id);
    }
}

function popuphelp(url)
{
    window.open(url, "popuphelp", "width=600,height=600,scrollbars=yes,resizable=yes,")
}

function report_not_working(userornabo, linkID, movieID)
{
    var url='report_not_working.php?userornabo=' + userornabo + '&linkID=' + linkID + '&movieID=' + movieID
    window.open(url, "report_not_working", "width=600,height=600,scrollbars=yes,resizable=yes,")
}

function open_url_decoder()
{
    url="url_decoder.php"
    window.open(url, "url_decoder", "width=600,height=200,scrollbars=yes,toolbar=no,location=no,menubar=0,directories=no,resizable=yes,status=0")
}

function wordwrap( str, int_width, str_break, cut ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +   improved by: Nick Callen
    // +    revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Sakimori
    // *     example 1: wordwrap('Kevin van Zonneveld', 6, '|', true);
    // *     returns 1: 'Kevin |van |Zonnev|eld'
    // *     example 2: wordwrap('The quick brown fox jumped over the lazy dog.', 20, '<br />\n');
    // *     returns 2: 'The quick brown fox <br />\njumped over the lazy<br />\n dog.'
    // *     example 3: wordwrap('Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.');
    // *     returns 3: 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod \ntempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim \nveniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea \ncommodo consequat.'

    // PHP Defaults
    var m = ((arguments.length >= 2) ? arguments[1] : 75   );
    var b = ((arguments.length >= 3) ? arguments[2] : "\n" );
    var c = ((arguments.length >= 4) ? arguments[3] : false);

    var i, j, l, s, r;

    str += '';

    if (m < 1) {
        return str;
    }

    for (i = -1, l = (r = str.split("\n")).length; ++i < l; r[i] += s) {
        for(s = r[i], r[i] = ""; s.length > m; r[i] += s.slice(0, j) + ((s = s.slice(j)).length ? b : "")){
            j = c == 2 || (j = s.slice(0, m + 1).match(/\S*(\s)?$/))[1] ? m : j.input.length - j[0].length || c == 1 && m || j.input.length + (j = s.slice(m).match(/^\S*/)).input.length;
        }
    }

    return r.join("\n");
}


function setCookie(c_name,value,expiredays)
{
    var exdate=new Date();
    exdate.setDate(exdate.getDate()+expiredays);
    document.cookie=c_name+ "=" +escape(value)+
    ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}
function getCookie(c_name)
{
    if (document.cookie.length>0)
    {
        c_start=document.cookie.indexOf(c_name + "=");
        if (c_start!=-1)
        {
            c_start=c_start + c_name.length+1;
            c_end=document.cookie.indexOf(";",c_start);
            if (c_end==-1) c_end=document.cookie.length;
            return unescape(document.cookie.substring(c_start,c_end));
        }
    }
    return "";
}


function close_chatroo()
{
    document.getElementById("my_chatroo").innerHTML = '';
    document.getElementById("chatroo_toggl").innerHTML = 'open chat';
    document.getElementById("chatroo_toggl").onclick = open_chatroo;
    setCookie('remember_chatroo_close','clozed',365)
}
function open_chatroo()
{
    document.getElementById("my_chatroo").innerHTML = '<iframe src="http://2meet4free.com/chat?lobbyID=1257436223914806&lobby_name=Video Lister Roomz&embed=1&nowtheme=nabolister" style="width:800px;height:540px;" frameBorder="0"></iframe>';
    document.getElementById("chatroo_toggl").innerHTML = 'close chat';
    document.getElementById("chatroo_toggl").onclick = close_chatroo;
    setCookie('remember_chatroo_close','open',-1)
}

var ajax_pipes=new Array();
ajax_pipes[1]='_heartbeat_ofjoy';
for (xol in ajax_pipes)
{
    var joystring = 'var req' + ajax_pipes[xol] + '; function loadXMLDoc' + ajax_pipes[xol] + '(url) {if (window.XMLHttpRequest) {req' + ajax_pipes[xol] + ' = new XMLHttpRequest(); req' + ajax_pipes[xol] + '.onreadystatechange = processReqChange' + ajax_pipes[xol] + '; req' + ajax_pipes[xol] + '.open("GET", url, true); req' + ajax_pipes[xol] + '.send(null);} else if (window.ActiveXObject){req' + ajax_pipes[xol] + ' = new ActiveXObject("Microsoft.XMLHTTP"); if (req' + ajax_pipes[xol] + ') {req' + ajax_pipes[xol] + '.onreadystatechange = processReqChange' + ajax_pipes[xol] + ';req' + ajax_pipes[xol] + '.open("GET", url, true);req' + ajax_pipes[xol] + '.send();}}}';
    eval(joystring);
}


var heartbeetfreq = 15000;
var restarted = 0;
function send_heartbeat_ofjoy()
{
    if(restarted == 0)
    {
        send_heartbeat_ofjoy_re();
        restarted = 1;
    }
}
function send_heartbeat_ofjoy_re()
{
    var url = "/xmlheartbeat_ofjoy";
    loadXMLDoc_heartbeat_ofjoy(url);
    var t=setTimeout("send_heartbeat_ofjoy_re()",heartbeetfreq);
}

var current_amount_of_pm_inqueuforyou = 0;
function processReqChange_heartbeat_ofjoy()
{
    if (req_heartbeat_ofjoy.readyState == 4)
    {
        if (req_heartbeat_ofjoy.status == 200)
        {
            response = req_heartbeat_ofjoy.responseXML.documentElement;
            var result = response.getElementsByTagName("result")[0].firstChild.data;
            if(result=='ok')
            {
                var messages_num = response.getElementsByTagName("messages_num")[0].firstChild.data;
                var newmessages_num = response.getElementsByTagName("newmessages_num")[0].firstChild.data;
                show_inbox_status(messages_num,newmessages_num);
                var message_pubid_array = new Array();
                var message_screen_name_array = new Array();
                var message_ip_array = new Array();
                var totalmessages = response.getElementsByTagName("totalmessages")[0].firstChild.data;
                if(current_amount_of_pm_inqueuforyou == 0 && totalmessages >= 1)
                {
                    makesound("yougotmessages_sound");
                }
                current_amount_of_pm_inqueuforyou =  totalmessages;
                var countzaz = 0;
                while(countzaz < totalmessages)
                {
                    countzaz++;
                    var message_pubid_name = "message_pubid_" + countzaz;
                    var message_screen_name_name = "message_screen_name_" + countzaz;
                    var message_ip_name = "message_ip_" + countzaz;
                    message_pubid_array[countzaz] = response.getElementsByTagName(message_pubid_name)[0].firstChild.data;
                    message_screen_name_array[countzaz] = response.getElementsByTagName(message_screen_name_name)[0].firstChild.data;
                    message_ip_array[countzaz] = response.getElementsByTagName(message_ip_name)[0].firstChild.data;
                }
                show_pm_messages(message_pubid_array,message_screen_name_array,message_ip_array,totalmessages);
            }
        }
    }
}

function show_inbox_status(messages_num,newmessages_num)
{
    var messagesS = 's';
    if(messages_num==1)
    {
        messagesS = '';
    }
    var newmessagesstring = '';
    if(newmessages_num >= 1)
    {
        newmessagesstring = ', <acronym title="' + newmessages_num + ' new"><span id="newmessages_num">' + newmessages_num + '</span></acronym>';
    }
    var showinboxstatusstring = '<acronym title="' + messages_num + ' message' + messagesS + '">' + messages_num + '</acronym>' + newmessagesstring;
    document.getElementById('inbox_status').innerHTML = showinboxstatusstring;
    blink('newmessages_num',500);
}
function show_pm_messages(message_pubid_array,message_screen_name_array,message_ip_array,totalmessages)
{
    var showmessagezstring = '<table style="font-size:12px;"><tr><td>';
    var countziaz = 0;
    var rememberdivids = new Array();
    while(countziaz < totalmessages)
    {
        countziaz++;
        var divid = 'pm_' + message_pubid_array[countziaz];
        showmessagezstring = showmessagezstring + '<div class="effect" style="font-size:18px;position:relative;padding-left:6px;padding-right:6px;padding-bottom:2px;vertical-align:middle;"><acronym title="' + message_screen_name_array[countziaz] + ' is talking to you"><a onclick="openpm(' + message_pubid_array[countziaz] + ',' + "'" + escape(message_screen_name_array[countziaz]) + "'" + ')" style="cursor:pointer;"><img src="http://' + myhappydomain + '/common_files/pics/bulle.gif" style="position:relative;top:4px" id="' + divid + '" /> ' + message_screen_name_array[countziaz] + ' is talking to you</a></acronym></div><br />';
        rememberdivids[divid]='remember';
    }
    showmessagezstring = showmessagezstring + '</td></tr></table>';
    document.getElementById('pm_status').innerHTML = showmessagezstring;
    for(x in rememberdivids)
    {
        blink(x,500);
    }
}
var pm_windows = new Array();
function openpm(u,namez)
{
    var url = 'http://backstage.' + myhappydomain + '/messages/pm?u=' + u;
    var name = 'pm_' + u;
    if (!pm_windows[u] || pm_windows[u].closed)
    {
        pm_windows[u] = window.open(url,name);
    }
    else
    {
        alert('PM window with ' + unescape(namez) + ' already opened.');
    }
}

var blinkers = new Array();
function blink(element_id,freq)
{
    if(blinkers[element_id]!='blinking')
    {
        do_blink(element_id,freq);
        blinkers[element_id]='blinking';
    }
}
function do_blink(element_id,freq)
{
    var theelement = document.getElementById(element_id);
    if(theelement!=null)
    {
        if(theelement.style.visibility == "visible")
        {
            theelement.style.visibility = "hidden";
        }
        else
        {
            theelement.style.visibility = "visible";
        }
    }
    var t=setTimeout("do_blink('" + element_id + "'," + freq + ");",freq);
}

var countrecalls = 0;
function makesound(elsound)
{
    var myFlashMovie = document.vidsounds;
    //if(myFlashMovie!=null)
    if(myFlashMovie.playsound_js)
    {
        myFlashMovie.playsound_js(elsound);
    }
    else if(countrecalls < 10)
    {
        var recall = "makesound('" + elsound + "');";
        var t=setTimeout(recall,100);
        countrecalls++;
    }
}


function shoratings(dailyrating,dailyvotes,weeklyrating,weeklyvotes,monthlyrating,monthlyvotes,yearlyrating,yearlyvotes,rating,votes)
{
    var dailyvotesS = 's';
    if(dailyvotes==1)
    {
        dailyvotesS = '';
    }
    var weeklyvotesS = 's';
    if(weeklyvotes==1)
    {
        weeklyvotesS = '';
    }
    var monthlyvotesS = 's';
    if(monthlyvotes==1)
    {
        monthlyvotesS = '';
    }
    var yearlyvotesS = 's';
    if(yearlyvotes==1)
    {
        yearlyvotesS = '';
    }
    var votesS = 's';
    if(votes==1)
    {
        votesS = '';
    }
    rezuuss = '<acronym title="today\'s rating: ' + dailyrating + ', ' + dailyvotes + ' vote' + dailyvotesS + '" style="cursor:help;">' + makerate(dailyrating,dailyvotes) + '</acronym>&#160;' +
    '<acronym title="this week\'s rating: ' + weeklyrating + ', ' + weeklyvotes + ' vote' + weeklyvotesS + '" style="cursor:help;">' + makerate(weeklyrating,weeklyvotes) + '</acronym>&#160;' +
    '<acronym title="this month\'s rating: ' + monthlyrating + ', ' + monthlyvotes + ' vote' + monthlyvotesS + '" style="cursor:help;">' + makerate(monthlyrating,monthlyvotes) + '</acronym>&#160;' +
    '<acronym title="this year\'s rating: ' + yearlyrating + ', ' + yearlyvotes + ' vote' + yearlyvotesS + '" style="cursor:help;">' + makerate(yearlyrating,yearlyvotes) + '</acronym>&#160;' +
    '<acronym title="aLL-time rating: ' + rating + ', ' + votes + ' vote' + votesS + '" style="cursor:help;">' + makerate(rating,votes) + '</acronym>';
    return rezuuss;
}
function makerate(rating,votes)
{

    var light = 30;


    var moveratingcolor = '#FFFFFF';
    var shorating = '?';
    if(votes != 0)
    {
        var percent_good = rating * 10;
        var quantity_of_green = (200 * (percent_good / 100)) - 1;
        var quantity_of_green = Math.floor(quantity_of_green);
        var percent_bad = (10 - rating) * 10;
        var quantity_of_red = (200 * (percent_bad / 100)) - 1;
        var quantity_of_red = Math.floor(quantity_of_red);


        quantity_of_red = quantity_of_red +light;
        if(quantity_of_red>255)
        {
            quantity_of_red=255;
        }
        quantity_of_green = quantity_of_green +light;
        if(quantity_of_green>255)
        {
            quantity_of_green=255;
        }


        moveratingcolor = ' rgb(' + quantity_of_red + ', ' + quantity_of_green + ', ' + light + ')';
        shorating = Math.round(rating*10)/10;
    }
    var movierating_incolor = '<span style="color:' + moveratingcolor + ';font-weight:bold;">' + shorating + '</span>';

    var ppls_good = votes;
    if(ppls_good > 10)
    {
        ppls_good = 10;
    }
    var percent_ppls_good = ppls_good * 10;
    var quantity_of_green = (256 * (percent_ppls_good / 100)) - 1;
    var quantity_of_green = Math.floor(quantity_of_green);
    var percent_ppls_bad = (10 - ppls_good) * 10;
    var quantity_of_red = (256 * (percent_ppls_bad / 100)) - 1;
    var quantity_of_red = Math.floor(quantity_of_red);

    quantity_of_red = quantity_of_red +light;
    if(quantity_of_red>255)
    {
        quantity_of_red=255;
    }
    quantity_of_green = quantity_of_green +light;
    if(quantity_of_green>255)
    {
        quantity_of_green=255;
    }

    var movievotescolor = ' rgb(' + quantity_of_red + ', ' + quantity_of_green + ', ' + light + ')';
    var movievotes_incolor = '<span style="color:' + movievotescolor + ';">' + votes + '</span>';

    var rezuu = movierating_incolor + '&#160;<span style="font-size:80%;color:inherit;">(' + movievotes_incolor + ')</span>';
    return rezuu;


}