function getRatingBoxHtml(mid, uvote) {
  var r = '<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td height="10"></td></tr></table>';

  r += '<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td style="background-color:#ffffff;padding:5px 10px; border: 1px solid #B0B0B0;">'
  r += '<div id="ratingbar">';
  r += '<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr>';
  for (i=0; i<ratingStars.length;i++) {
    r += '<td width="10%" align="center"';
    if (!ratingDisableVote) {
      r += ' onclick="rating(\'click\',\''+i+'\',\''+ mid +'\')" onmouseover="rating(\'over\',\''+i+'\',\''+ mid +'\')" onmouseout="rating(\'out\',\''+i+'\',\''+ mid +'\')" style="cursor:pointer"';
    }
    r += '><div id="ratingstar_' + i + '" class="rating_' + ratingStars[i] + '"></div></td>';
  }
  r += '</tr></table>';
  r += '</div>';
  r += '</td></tr></table>';

  if (!ratingDisableVote) {
    r += '<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td height="10"></td></tr></table>';
    r += '<div id="ratingmsg">Click on the number of stars that you want to give this channel.</div>';
  }
  else if (uvote > 0) {
    r += '<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td height="10"></td></tr></table>';
    if (uvote == 1) {
      r += '<div id="ratingmsg">You have rated this media with 1 point.</div>';
    }
    else {
      r += '<div id="ratingmsg">You have rated this media with '+uvote+' points.</div>';
    }
  }
  return r;
}
function rating(act, val, mid) {
  if (act == "over") {
    for (i=0; i<ratingStars.length;i++) {
      if (i<=val) {
        $('ratingstar_'+i).className = 'rating_active';
      }
      else {
        $('ratingstar_'+i).className = 'rating_empty';
      }
    }
  }
  else if (act == "out") {
    for (i=0; i<ratingStars.length;i++) {
      $('ratingstar_'+i).className = 'rating_'+ratingStars[i];
    }
  }
  else if (act == "click") {
    nt = '<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr>';
    for (i=0; i<ratingStars.length;i++) {
      if (i <= val) {
        nt += '<td width="10%" align="center"><div id="ratingstar_' + i + '" class="rating_active"></div></td>';
      }
      else {
        nt += '<td width="10%" align="center"><div id="ratingstar_' + i + '" class="rating_empty"></div></td>';
      }
    }
    nt += '</tr></table>';
    $('ratingbar').innerHTML = nt;


    var rmsize = bytefx.$size($('ratingmsg'));
    time = new Date();
    bytefx.fade($('ratingmsg'), 100, 0, 15);
    bytefx.size( $('ratingmsg'), {width:rmsize['width'],height:75}, 15, function(){
      $('ratingmsg').innerHTML = "To prevent automatic votes, please copy the following four-numbers code in the box:"
        + "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td height=\"10\"></td></tr></table>"
        + "<table width=\"250\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td width=\"120\">"
        + "<img src=\"/captcha.php?t=" + time.getHours() + time.getMinutes() + time.getSeconds() + "\" width=\"120\" height=\"25\">"
        + "<td width=\"10\"></td><td width=\"120\">"
        + "<input onkeypress=\"return numbersOnly(event)\" onkeyup=\"rating2('" + val + "', '" + mid + "')\" id=\"votingcaptcha\" type=\"text\" maxlength=\"4\" value=\"\" style=\"width:120px;height:25px;font-size:16px;font-weight:bold;text-align:center;text-transform:uppercase;border:1px solid #B0B0B0; background-color:#ffffff;color:#4B4B4B\">"
        + "</td></tr></table>";

      bytefx.fade($('ratingmsg'), 0, 100, 50, function() { $('votingcaptcha').focus(); } );


    } );
  } 
} 
function rating2(val, mid) {
  if ($('votingcaptcha').value.length == 4) {
    $('votingcaptcha').disabled = true;
    $('ratingbar').innerHTML = '<center><img width="221" height="15" src="/img/ratinglb.gif"></center>';

    new Ajax.Request('/rate.php', {
      method: 'post',
      parameters: 'mid=' +escape(mid) + '&value=' + escape((val * 1) + 1) + '&captcha=' + escape($('votingcaptcha').value),
      onSuccess: function(transport) {        
        pr = parseProperties(transport.responseText)
        if (pr['status'] == "error") {
          if (pr['type'] == "captcha error") {
            $('votingcaptcha').disabled = false;
            rating("click", val, mid);
            alert("The image verification code you entered is incorrect.\nPlease try again.");
          }
          else if (pr['type'] == "already voted" || pr['type'] == "wrongid") {
            var rmsize = bytefx.$size($('ratingmsg'));
            bytefx.fade($('ratingmsg'), 100, 0, 15);
            bytefx.size( $('ratingmsg'), {width:rmsize['width'],height:33}, 15, function(){
              var r = '<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr>';
              for (i=0; i<ratingStars.length;i++) {
                r += '<td width="10%" align="center"';                
                r += '><div id="ratingstar_' + i + '" class="rating_' + ratingStars[i] + '"></div></td>';
              }
              r += '</tr></table>';
              $('ratingbar').innerHTML = r;
              
              if (pr['type'] == "wrongid") {
                $('ratingmsg').innerHTML = "<span style=\"color:red\">Sorry, an error has occurred. Please reload the page and rate this media again.</span>";
              }
              else {
                $('ratingmsg').innerHTML = "<span style=\"color:red\">Sorry, you have already rated this media so your current vote will be ignored.</span>";
              }
              bytefx.fade($('ratingmsg'), 0, 100, 50);
            });           
          }
        }  
        else if (pr['status'] == "ok") {
          ratingDisableVote = true;            
          rstars = pr['rstars'].split(",");
          for(i=0; i<rstars.length; i++) {
            ratingStars[i] = rstars[i];
          }
          
          
          var rmsize = bytefx.$size($('ratingmsg'));
          bytefx.fade($('ratingmsg'), 100, 0, 15);
          bytefx.size( $('ratingmsg'), {width:rmsize['width'],height:20}, 15, function(){
            var r = '<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr>';
            for (i=0; i<ratingStars.length;i++) {
              r += '<td width="10%" align="center"';                
              r += '><div id="ratingstar_' + i + '" class="rating_' + ratingStars[i] + '"></div></td>';
            }
            r += '</tr></table>';
            $('ratingbar').innerHTML = r;
            
            $('rateitxt').innerHTML = pr['newtext'];
            if (pr['val'] == 1) {
              $('ratingmsg').innerHTML = "You have rated this media with 1 point.";
            }
            else {
              $('ratingmsg').innerHTML = "You have rated this media with " + pr['val'] + " points.";
            }
            bytefx.fade($('ratingmsg'), 0, 100, 50);
          }); 
        }
        else {
          var rmsize = bytefx.$size($('ratingmsg'));
          bytefx.fade($('ratingmsg'), 100, 0, 15);
          bytefx.size( $('ratingmsg'), {width:rmsize['width'],height:33}, 15, function(){
            var r = '<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr>';
            for (i=0; i<ratingStars.length;i++) {
              r += '<td width="10%" align="center"';
              if (!ratingDisableVote) {
                r += ' onclick="rating(\'click\',\''+i+'\',\''+ mid +'\')" onmouseover="rating(\'over\',\''+i+'\',\''+ mid +'\')" onmouseout="rating(\'out\',\''+i+'\',\''+ mid +'\')" style="cursor:pointer"';
              }
              r += '><div id="ratingstar_' + i + '" class="rating_' + ratingStars[i] + '"></div></td>';
            }
            r += '</tr></table>';
            $('ratingbar').innerHTML = r;
          
            $('ratingmsg').innerHTML = "<span style=\"color:red\">Sorry, an error has occurred on the network and your vote has not been saved.</span>";
            bytefx.fade($('ratingmsg'), 0, 100, 50);
          });           
        }         
      },
      onFailure: function() {
        var rmsize = bytefx.$size($('ratingmsg'));
        bytefx.fade($('ratingmsg'), 100, 0, 15);
        bytefx.size( $('ratingmsg'), {width:rmsize['width'],height:33}, 15, function(){
          var r = '<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr>';
          for (i=0; i<ratingStars.length;i++) {
            r += '<td width="10%" align="center"';
            if (!ratingDisableVote) {
              r += ' onclick="rating(\'click\',\''+i+'\',\''+ mid +'\')" onmouseover="rating(\'over\',\''+i+'\',\''+ mid +'\')" onmouseout="rating(\'out\',\''+i+'\',\''+ mid +'\')" style="cursor:pointer"';
            }
            r += '><div id="ratingstar_' + i + '" class="rating_' + ratingStars[i] + '"></div></td>';
          }
          r += '</tr></table>';
          $('ratingbar').innerHTML = r;
        
          $('ratingmsg').innerHTML = "<span style=\"color:red\">Sorry, an error has occurred on the network and your vote has not been saved.</span>";
          bytefx.fade($('ratingmsg'), 0, 100, 50);
        }); 
      }
    });
    
  }
}



function parseProperties(str) {
  var pr = new Object();
  var prarr = str.split("\n");
  for (i=0; i<prarr.length; i++) {    
    if (prarr[i].indexOf("=") > 1) {
      prval = prarr[i].split("=", 2);
      pr[prval[0]] = prval[1];
    }
  }
  return pr; 
}

function numbersOnly(e) {
  var keynum;
  var keychar;

  if(window.event) {
    keynum = e.keyCode
  }
  else if(e.which) {
    keynum = e.which
  }
  if (keynum != 8) {
    keychar = String.fromCharCode(keynum);
    return ("123456789".indexOf(keychar,0) != -1);
  }
  return true;
}
function printBookmarkBox() {
  var sites = new Array();
  sites[sites.length] = new Array('Del.icio.us', 'http://del.icio.us/post?url={url}&title={title}','0',1);
  sites[sites.length] = new Array('Google Bookmarks', 'http://www.google.com/bookmarks/mark?op=edit&bkmk={url}&title={title}', '-16px',1);
  sites[sites.length] = new Array('Yahoo! Bookmarks', 'http://bookmarks.yahoo.com/toolbar/savebm?u={url}&t={title}&ei=UTF-8', '-32px', 1);
  sites[sites.length] = new Array('Netvouz', 'http://netvouz.com/action/submitBookmark?url={url}&title={title}&description=%20', '-48px', 1);
  sites[sites.length] = new Array('Ma.gnolia', 'http://ma.gnolia.com/bookmarklet/add?url={url}&title={title}', '-64px',1);
  sites[sites.length] = new Array('Mister Wong', 'http://www.mister-wong.com/addurl/?bm_url={url}&bm_description={title}&plugin=soc', '-80px', 1);
  sites[sites.length] = new Array('Spurl', 'http://www.spurl.net/spurl.php?url={url}&title={title}','-96px');
  sites[sites.length] = new Array('Furl', 'http://furl.net/storeIt.jsp?u={url}&t={title}','-112px',0);
  sites[sites.length] = new Array('BlinkList','http://www.blinklist.com/?Action=Blink/addblink.php&Description=&Url={url}&Title={title}','-128px',1);
  sites[sites.length] = new Array('StumbleUpon', 'http://www.stumbleupon.com/submit?url={url}&title={title}', '-144px', 1);
  sites[sites.length] = new Array('Simpy', 'http://simpy.com/simpy/LinkAdd.do?note={title}&href={url}&title={title}', '-160px', 1);
  sites[sites.length] = new Array('Diigo', 'http://www.diigo.com/post?url={url}&title={title}', '-176px',1);
  sites[sites.length] = new Array('Yahoo! My Web', 'http://myweb2.search.yahoo.com/myresults/bookmarklet?u={url}&t={title}','-192px', 1);
  sites[sites.length] = new Array('AskJeeves', 'http://myjeeves.ask.com/mysearch/BookmarkIt?v=1.2&t=webpages&title={title}&url={url}', '-208px', 1);
  sites[sites.length] = new Array('Blogmarks', 'http://www.blogmarks.net/my/new.php?mini=1&url={url}&title={title}', '-224px',1);
  sites[sites.length] = new Array('Facebook', 'http://www.facebook.com/sharer.php?u={url}&t={title}', '-240px', 0);
  sites[sites.length] = new Array('Faves', 'http://faves.com/Authoring.aspx?u={url}&t={title}','-256px',1);
  sites[sites.length] = new Array('Segnalo','http://segnalo.alice.it/post.html.php?url={url}&title={title}','-272px',1);


  document.write('Bookmark on<span id="bmboxlab">...</span>');
  document.write('<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td height="8"></td></tr></table>');
  document.write('<table width="250" border="0" cellspacing="0" cellpadding="0"><tr>');
  for (i=0;i<sites.length;i++) {
    myUrl = document.location.href;
    if (myUrl.indexOf("#") > -1) {
      myUrl = myUrl.substring(0, myUrl.indexOf("#"));
    }
  
    if (sites[i][3] == 1) {
      sites[i][1] = sites[i][1].replace(/{title}/, encodeURIComponent(document.title));
      sites[i][1] = sites[i][1].replace(/{url}/, encodeURIComponent(myUrl));
    }
    else {
      sites[i][1] = sites[i][1].replace(/{title}/, escape(document.title));
      sites[i][1] = sites[i][1].replace(/{url}/, escape(myUrl));
    }
  
    if (i<6 || (i>8 && i<15)) {
      document.write('<td width="24">');
    }
    else {
      document.write('<td width="25">');
    }
    document.write('<a rel="nofollow" class="bmlink" target="_blank" onmouseover="document.getElementById(\'bmboxlab\').innerHTML = \'&nbsp;<b>' + sites[i][0] + '</b>\'" ');
    document.write('onmouseout="document.getElementById(\'bmboxlab\').innerHTML = \'...\'" href="'+sites[i][1]+'">');
    document.write('<img style="height:16px;background:transparent url(/img/bookmarks.gif) '+sites[i][2]+' 0" src="/img/dot.gif" width="16" height="16" alt="" border="0">');
  
    document.write('</a></td>');
    if (i != 8 && i != 17) {
      document.write('<td width=\"3\"></td>');
    }
    else if (i == 8) {
      document.write('</tr><td><td colspan="19" height="4"></td></tr><tr>');
    }
  }
  document.write('</tr></table>');
}


function relatedChannels(s) {
  var e = s+3;
  if (e > rchannels.length) {
    e = rchannels.length;
  }

  var r = '<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><tr><td height="230" valign="top">';
  r += '<table width="100%" border="0" cellspacing="0" cellpadding="0">';
  for (i=s; i<e; i++) {
    r+='<tr><td width="82">';
    r+='<a href="/'+rchannels[i][1]+'" class="rellink"><img src="/img/'+rchannels[i][0]+'" width="70" height="53" border="0"></a>';
    r+='</td><td style="padding-left:10px; padding-top:4px" valign="top">';
    
    r += '<table width="100%" border="0" cellspacing="0" cellpadding="0">';
    r += '<tr><td style="line-height:12px;"><div style="overflow:hidden">';  
    r += '<nobr><b><a href="/'+rchannels[i][1]+'">'+rchannels[i][2]+'</a></b></nobr>';
    r += '</td>';
    
    if (rchannels[i][3] != "") {
      r += '<td style="line-height:12px" align="right" width="22">';
      r += '<img src="/img/flag/'+rchannels[i][3]+'.png" align="right" width="16" height="11">';
      r += '</td>';
    }
    r += '</tr></table>';
    
    r+='<span class="startxt"><span style="color:#FFCC00">';
    var star = 1;
    for (j=1; j<=rchannels[i][5]; j++) {
      r+='&#8226;';
      star++;
    }
    r+='</span>';
    for (j=star; j<=10; j++) {
      r+='&#8226;';
    }
    r+='</span>';
    
    r+='  </div>';
    r+='  <div style="padding-top:3px;line-height:15px">';
    r+='  '+rchannels[i][4]+'<br>';
    r+='  '+rchannels[i][6]+'';
    r+='  </div>';
    r+='</td></tr>';
    r+='<tr><td colspan="2" height="5"></td></tr>';
    r+='<tr><td colspan="2" height="1" bgcolor="#cfcfcf"></td></tr>';
    r+='<tr><td colspan="2" height="5"></td></tr>';
  }
  r+='</table>';
  r+='</td></tr></table>';
  return r;
}
function relatedChannelsGo(s) {
  bytefx.fade($('rchannels'), 100, 0, 30, function(){
    $('rchannels').innerHTML = relatedChannels(s);
    bytefx.fade($('rchannels'), 0, 100, 30);
  });
}

function emdedWMV(url) {
  document.writeln("<OBJECT width=\"540\" height=\"470\" CLASSID=\"CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6\" type=\"application/x-oleobject\">");
  document.writeln("<PARAM NAME=\"URL\" VALUE=\""+url+"\">");
  document.writeln("<PARAM name=\"transparantatstart\" value=\"0\">");
  document.writeln("<PARAM name=\"showtracker\" value=\"0\">");
  document.writeln("<PARAM name=\"showstatusbar\" value=\"0\">");
  document.writeln("<PARAM name=\"showpositioncontrols\" value=\"0\">");
  document.writeln("<PARAM name=\"showaudiocontrols\" value=\"1\">");
  document.writeln("<PARAM name=\"showcontrols\" value=\"1\">");
  document.writeln("<PARAM name=\"showcaptioning\" value=\"0\">");
  document.writeln("<PARAM name=\"previewmode\" value=\"0\">");
  document.writeln("<PARAM name=\"enabletracker\" value=\"0\">");
  document.writeln("<PARAM name=\"enablefullscreencontrols\" value=\"0\">");  
  document.writeln("<PARAM name=\"enablepositioncontrols\" value=\"0\">");
  document.writeln("<PARAM name=\"enablecontextmenu\" value=\"0\">");
  document.writeln("<PARAM name=\"displaysize\" value=\"0\">");
  document.writeln("<PARAM name=\"displaymode\" value=\"0\">");
  document.writeln("<PARAM name=\"clicktoplay\" value=\"0\">");
  document.writeln("<PARAM name=\"bufferingtime\" value=\"5\">");
  document.writeln("<PARAM name=\"autorewind\" value=\"0\">");
  document.writeln("<PARAM name=\"allowchangedisplaysize\" value=\"0\">");
  document.writeln("<PARAM name=\"allowscan\" value=\"0\">");
  document.writeln("<PARAM name=\"animationatstart\" value=\"1\">");
  document.writeln("<PARAM name=\"autostart\" value=\"1\">");
  document.writeln("<PARAM name=\"autosize\" value=\"1\">");
  document.writeln("<PARAM name=\"audiostream\" value=\"1\">");
  document.writeln("<PARAM name=\"stretchToFit\" value=\"true\">");
  document.writeln("<embed width=\"540\" height=\"470\" stretchToFit=\"1\" transparantatstart=\"0\" showtracker=\"0\" showstatusbar=\"0\" showpositioncontrols=\"0\" showgotobar=\"0\" showdisplay=\"0\" showaudiocontrols=\"1\" showcontrols=\"1\" showcaptioning=\"0\" previewmode=\"0\" enabletracker=\"0\" enablefullscreencontrols=\"0\" enablepositioncontrols=\"0\" enablecontextmenu=\"0\" displaysize=\"100\" displaymode=\"0\" clicktoplay=\"0\" bufferingtime=\"5\" autorewind=\"0\" allowchangedisplaysize=\"0\" allowscan=\"0\" animationatstart=\"1\" autostart=\"1\" autosize=\"0\" audiostream=\"1\" pluginspage=\"http://www.microsoft.com/windows/mediaplayer/download/default.asp\" type=\"application/x-mplayer2\" src=\""+url+"\"/></embed>");  
  document.writeln("</OBJECT>");  
}
function emdedRM(url) {
  document.writeln("<OBJECT width=\"540\" height=\"405\" CLASSID=\"clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA\" type=\"audio/x-pn-realaudio-plugin\">\n");
  document.writeln("<PARAM NAME=\"SRC\" VALUE=\""+url+"\">\n");
  document.writeln("<PARAM NAME=\"AUTOSTART\" VALUE=\"true\">\n");
  document.writeln("<PARAM NAME=\"CONTROLS\" VALUE=\"ImageWindow\">\n");
  document.writeln("<PARAM NAME=\"CONSOLE\" VALUE=\"one\">\n");
  document.writeln("<EMBED SRC=\""+url+"\" width=\"540\" height=\"405\" nojava=\"true\" autostart=\"true\" CONTROLS=\"ImageWindow\" CONSOLE=\"one\" type=\"audio/x-pn-realaudio-plugin\"></embed>\n");
  document.writeln("</OBJECT>\n");
}
function emdedMOV(url) {
  document.writeln("<OBJECT width=\"540\" height=\"405\" CLASSID=\"clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B\" type=\"video/quicktime\" codebase=\"http://www.apple.com/qtactivex/qtplugin.cab\">\n");
  document.writeln("<PARAM NAME=\"SRC\" VALUE=\""+url+"\">\n");
  document.writeln("<PARAM NAME=\"AUTOSTART\" VALUE=\"true\">\n");
  document.writeln("<PARAM NAME=\"scale\" VALUE=\"toFit\">\n");
  document.writeln("<param name=\"type\" value=\"video/quicktime\" width=\"540\" height=\"405\">\n");
  document.writeln("<EMBED SRC=\""+url+"\" width=\"540\" height=\"405\" autostart=\"true\" type=\"video/quicktime\" scale=\"toFit\" pluginspage=\"http://www.apple.com/quicktime/download/\"></embed>\n");
  document.writeln("</OBJECT>\n");
}
function emdedDIVX(url) {
  document.write('<object codebase="http://go.divx.com/plugin/DivXBrowserPlugin.cab" height="405" width="540" classid="clsid:67DABFBF-D0AB-41fa-9C46-CC0F21721616"><param name="autoplay" value="false">');
  document.write('<param name="src" value="' + url + '" /><param name="custommode" value="Stage6" /><param name="showpostplaybackad" value="false" />');
  document.write('<embed type="video/divx" src="' + url + '" pluginspage="http://go.divx.com/plugin/download/" showpostplaybackad="false" custommode="Stage6" autoplay="false" height="405" width="540" /></object>');
}



var scrollpg=0;
var scrollpgs=0;
var scrollpos=0;
var scrollspeed=20;
var crossobj;

function relatedMedia() {   
  document.write('<div id="container" style="position:relative;width:250px;height:232px;overflow:hidden;border:0">')
  document.write('<div id="content" style="position:absolute;width:250px;left:0px;top:0px">')
 
  document.write('<ilayer name="nscontainer" width="250" height="232" clip="0,0,250,232">');
  document.write('<layer name="nscontent" width="250" height="232" visibility="hidden">');
  document.write('<div id="scritem_0">' + relatedChannels(0) + '</div>');

  scrollpgs = Math.ceil(rchannels.length/3);
  for (i=1; i<scrollpgs +1; i++) {
    document.write('<div id="scritem_' + i + '"></div>');
  }

  document.write('</layer>');
  document.write('</ilayer>');

  document.write('</div></div>')
  crossobj=document.getElementById? document.getElementById("content") : document.all.content

  document.write('<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td height="3"></td></tr></table>');
  document.write('<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr>');
  document.write('<td width="50%"><div id="scrollprev"><a class="arrowprev" href="#" onclick="relatedMediaPrev();return false">Previous</a></div></td>');
  document.write('<td width="50%" align="right"><div id="scrollnext"><a class="arrownext" href="#" onclick="relatedMediaNext();return false">Next</a></div></td>');
  document.write('</tr></table>'); 
  
  relatedMediaArrows();
   
}
function relatedMediaNext(){
  scrollpg++;
  if ($('scritem_' + scrollpg).innerHTML == "") {
    $('scritem_' + scrollpg).innerHTML = relatedChannels(scrollpg*3);
  }
  var pos0 = bytefx.$position($('scritem_0'));
  var pos1 = bytefx.$position($('scritem_1'));
  relatedMediaArrows();
  scrollpos -= (pos1.y-pos0.y);
  relatedMediaNextMove()
}
function relatedMediaPrev(){
  scrollpg--;
  var pos0 = bytefx.$position($('scritem_0'));
  var pos1 = bytefx.$position($('scritem_1'));
  relatedMediaArrows();
  scrollpos += (pos1.y-pos0.y);;
  relatedMediaPrevMove()
}
function relatedMediaArrows() {
  if (scrollpg <= 0) { 
    $('scrollprev').style.display = 'none';
  }
  else {
    $('scrollprev').style.display = 'block';
  } 
  if (scrollpg >= (scrollpgs-1)) { 
    $('scrollnext').style.display = 'none';
  }
  else {
    $('scrollnext').style.display = 'block';
  }
}

function relatedMediaNextMove() {
  if (window.moveupvar) clearTimeout(moveupvar)
  crossobj.style.top=parseInt(crossobj.style.top)-scrollspeed+"px"
  
  if (parseInt(crossobj.style.top) - scrollspeed > scrollpos) {
    movedownvar=setTimeout("relatedMediaNextMove()",20)
  }
  else {
    crossobj.style.top = scrollpos
  }
}
function relatedMediaPrevMove(){
  if (window.movedownvar) clearTimeout(movedownvar)
  crossobj.style.top=parseInt(crossobj.style.top)+scrollspeed+"px"
  
  if (parseInt(crossobj.style.top) + scrollspeed < scrollpos) {
    moveupvar=setTimeout("relatedMediaPrevMove()",20)
  }
  else {
    crossobj.style.top = scrollpos;
  }  
}


 
function emdedRadioWMA(url) {
  document.writeln("<OBJECT width=\"540\" height=\"45\" CLASSID=\"CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6\" type=\"application/x-oleobject\">");
  document.writeln("<PARAM NAME=\"URL\" VALUE=\""+url+"\">");
  document.writeln("<PARAM name=\"transparantatstart\" value=\"0\">");
  document.writeln("<PARAM name=\"showtracker\" value=\"0\">");
  document.writeln("<PARAM name=\"showstatusbar\" value=\"0\">");
  document.writeln("<PARAM name=\"showpositioncontrols\" value=\"0\">");
  document.writeln("<PARAM name=\"showaudiocontrols\" value=\"1\">");
  document.writeln("<PARAM name=\"showcontrols\" value=\"1\">");
  document.writeln("<PARAM name=\"showcaptioning\" value=\"0\">");
  document.writeln("<PARAM name=\"previewmode\" value=\"0\">");
  document.writeln("<PARAM name=\"enabletracker\" value=\"0\">");
  document.writeln("<PARAM name=\"enablefullscreencontrols\" value=\"0\">");  
  document.writeln("<PARAM name=\"enablepositioncontrols\" value=\"0\">");
  document.writeln("<PARAM name=\"enablecontextmenu\" value=\"0\">");
  document.writeln("<PARAM name=\"displaysize\" value=\"0\">");
  document.writeln("<PARAM name=\"displaymode\" value=\"0\">");
  document.writeln("<PARAM name=\"clicktoplay\" value=\"0\">");
  document.writeln("<PARAM name=\"bufferingtime\" value=\"5\">");
  document.writeln("<PARAM name=\"autorewind\" value=\"0\">");
  document.writeln("<PARAM name=\"allowchangedisplaysize\" value=\"0\">");
  document.writeln("<PARAM name=\"allowscan\" value=\"0\">");
  document.writeln("<PARAM name=\"animationatstart\" value=\"1\">");
  document.writeln("<PARAM name=\"autostart\" value=\"1\">");
  document.writeln("<PARAM name=\"autosize\" value=\"1\">");
  document.writeln("<PARAM name=\"audiostream\" value=\"1\">");
  document.writeln("<embed width=\"540\" height=\"45\" transparantatstart=\"0\" showtracker=\"0\" showstatusbar=\"0\" showpositioncontrols=\"0\" showgotobar=\"0\" showdisplay=\"0\" showaudiocontrols=\"1\" showcontrols=\"1\" showcaptioning=\"0\" previewmode=\"0\" enabletracker=\"0\" enablefullscreencontrols=\"0\" enablepositioncontrols=\"0\" enablecontextmenu=\"0\" displaysize=\"100\" displaymode=\"0\" clicktoplay=\"0\" bufferingtime=\"5\" autorewind=\"0\" allowchangedisplaysize=\"0\" allowscan=\"0\" animationatstart=\"1\" autostart=\"1\" autosize=\"0\" audiostream=\"1\" pluginspage=\"http://www.microsoft.com/windows/mediaplayer/download/default.asp\" type=\"application/x-mplayer2\" src=\""+url+"\"/></embed>");  
  document.writeln("</OBJECT>");  
}
function emdedRadioRM(url) {
  document.writeln("<OBJECT width=\"540\" height=\"60\" CLASSID=\"clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA\" type=\"application/x-oleobject\">\n");
  document.writeln("<PARAM NAME=\"SRC\" VALUE=\""+url+"\">\n");
  document.writeln("<PARAM NAME=\"AUTOSTART\" VALUE=\"true\">\n");
  document.writeln("<PARAM NAME=\"CONTROLS\" VALUE=\"Default\">\n");
  document.writeln("<EMBED type=\"audio/x-pn-realaudio-plugin\" id=\"player\" name=\"player\" PLUGINSPAGE=\"http://www.real.com/products/player/\" SRC=\""+url+"\" WIDTH=\"540\" HEIGHT=\"60\" CONTROLS=\"Default\" AUTOSTART=\"true\"></embed>");
  document.writeln("</OBJECT>\n");
}
function emdedRadioMOV(url) {
  document.writeln("<OBJECT width=\"540\" height=\"16\" CLASSID=\"clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B\" type=\"video/quicktime\" codebase=\"http://www.apple.com/qtactivex/qtplugin.cab\">\n");
  document.writeln("<PARAM NAME=\"SRC\" VALUE=\""+url+"\">\n");
  document.writeln("<PARAM NAME=\"AUTOSTART\" VALUE=\"true\">\n");
  document.writeln("<EMBED SRC=\""+url+"\" width=\"540\" height=\"16\" autostart=\"true\" type=\"video/quicktime\" scale=\"toFit\" pluginspage=\"http://www.apple.com/quicktime/download/\"></embed>\n");
  document.writeln("</OBJECT>\n");
}




function badmediaReport() {
  time = new Date();
    
  var hout = ''; 
  hout += '<table width="100%" border="0" cellspacing="0" cellpadding="0">';
  hout += '<tr><td><b>Report broken media</b></td></tr>';
  hout += '<tr><td height="8"></td></tr>';
  hout += '<tr><td>Please copy the following code before to submit your report:</td></tr>';
  hout += '<tr><td height="8"></td></tr>';
  hout += '</table>';
     
  hout += "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td width=\"130\">";
  hout += "<img src=\"/captcha.php?cid=broken&t=" + time.getHours() + time.getMinutes() + time.getSeconds() + "\" width=\"120\" height=\"25\">";
  hout += "</td><td>";
  hout += " <input onkeypress=\"return numbersOnly(event)\" onkeyup=\"sendBrokenReport()\" id=\"badlinkcaptcha\" type=\"text\" maxlength=\"4\" value=\"\" style=\"width:120px;height:25px;font-size:16px;font-weight:bold;text-align:center;text-transform:uppercase;border:1px solid #B0B0B0; background-color:#ffffff;color:#4B4B4B\">";
  hout += "</td><td style=\"padding-left:10px\">";
  hout += "<div style=\"display:none\" id=\"indicatoryellow\"><img src=\"/img/indicatoryellow.gif\" width=\"16\" height=\"16\" alt=\"\"><div>";
  hout += "</td></tr></table>";

  hout += '<table width="100%" border="0" cellspacing="0" cellpadding="0">';
  hout += '<tr><td height="12"></td></tr>';
  hout += '<tr><td>Note: use <a href="/contacts.php">contact form</a> to report errors in data or categories (please, remember to put the media url address in the message and describe where is the error you found)</td></tr>';
  hout += '</table>';
    

  var bd = bytefx.$size($('brokendiv'));
  $('brokendiv_test').style.width = bd['width'];
  $('brokendiv_test').innerHTML = hout;
  
  var bdt = bytefx.$size($('brokendiv_test'));
  $('brokendiv_test').innerHTML = '';
  
  bytefx.size($('brokendiv'), {width:bdt['width'],height:bdt['height']}, 30, function(){  
    $('brokendiv').innerHTML = hout;      
  });

}
function sendBrokenReport() {
  if ($('badlinkcaptcha').value.length == 4) {
    $('badlinkcaptcha').disabled = true;
    $('indicatoryellow').style.display = "block";

    new Ajax.Request('/brokenlink.php', {
      method: 'post',
      parameters: 'id=' + escape(brokenMediaId) + '&captcha=' + escape($('badlinkcaptcha').value),
      onSuccess: function(transport) {        
        pr = parseProperties(transport.responseText);

        if (pr['status'] == "error") {
          $('badlinkcaptcha').disabled = false;
          $('badlinkcaptcha').value = "";
          $('indicatoryellow').style.display = "none"; 
          if (pr['type'] == "captcha error") {           
            alert("The image verification code you entered is incorrect.\nPlease try again.");
          }
          else {
            alert("An error has occurred.\nPlease try again later.");
          }
        }  
        else if (pr['status'] == "ok") {
          var bd = bytefx.$size($('brokendiv'));
          bytefx.size($('brokendiv'), {width:bd['width'],height:14}, 30, function(){
            $('brokendiv').innerHTML = "<b>Thanks for your report!</b>";      
          });           
        }
      },
      onFailure: function() {
        $('badlinkcaptcha').disabled = false;
        $('none').style.display = "block";            
        alert("An error has occurred.\nPlease try again later.");   
      }
    });  
  
  }  
  
  
  
  
  
  
  
  
  
  
}


function enableBrokenReport() {
  if (brokenReportSeconds > 0) {
    $('broken_report_seconds').innerHTML = brokenReportSeconds;
    brokenReportSeconds--;
    setTimeout("enableBrokenReport()", 1000);  
  } 
  else {
    $('brokendiv').innerHTML = '<a href="#" onclick="badmediaReport();return false;" style="color:#C24A2F;padding-left:20px;line-height:14px;background:url(/img/report.gif);background-repeat:no-repeat">Report broken media</a>'; 
  }    
}
