function setupDoubleClicks(chartNumber, actionURL, showChartsAction, showAllAction, arrayA, buttonsArray, playlistURL)
{
  $('#songchart' + chartNumber).dblclick( function (e) {
     target = $(e.target);
  
      while(target.get(0).tagName != "TR"){
        target = target.parent();
      }
  
      var id =  target.get(0).id.substr(3);
     window.location.href= actionURL + '/' + id + '?referringgrid=' + chartNumber;
  });

   $('#songchart' + chartNumber).text(' ');

     arrayA.push(
            { name: 'Show details', bclass: 'list', onpress: function() { showDetails(chartNumber, actionURL); } } );

         
     if (showChartsAction != '')
       arrayA.push({ name: 'Show full charts', bclass: 'chart', onpress:
          function () {
                 window.location.href=showChartsAction;
              }});       

     if (showAllAction != '')
       arrayA.push( { name: 'List all', bclass: 'allsongs', onpress: function () {
                 window.location.href=showAllAction;
              }
            });  

     if (playlistURL != '')
     arrayA.push({ name: 'Listen in playlist', bclass: 'playlist', onpress: function() {
           window.open(playlistURL, '_blank', 'width=570, height=190, scrollbars=no, resizable=no, menubar=no, toolbar=no, location=no, directories=no, status=no');
           }
         });
      
      if (buttonsArray.length > 0)
        arrayA.concat(buttonsArray);
}

function showDetails(chartNumber, actionURL)
{
  if ($('.trSelected', $('#songchart' + chartNumber)).length > 0)
  {
    var id = $('.trSelected', $('#songchart' + chartNumber))[0].id;
    window.location.href= actionURL + '/' + id.substring(3, id.length) + '?referringgrid=' + chartNumber;
  }
  else
  {
    showErrorDialog('Select the item for which you would like to view details, and then click the "Details" button again.');
  } 
}

function toplistOperation(chartNumber, operation, toplistOpsUrl)
{
   if ($('.trSelected', $('#songchart' + chartNumber)).length > 0)
  {
    var id = $('.trSelected', $('#songchart' + chartNumber))[0].id;
    id = id.substring(3, id.length);
    $.get(toplistOpsUrl + '?operation=' + operation + '&id=' + id + '&chartnumber=' + chartNumber, refreshGrid);
  }
  else
  {
    showErrorDialog('Select the item you would like to move up, and click the "' + operation + '" button again.');
  } 
}

function refreshGrid(data)
{
    //returned data is the chart number, or nothing in the case of an error.
    $('#songchart' + data).flexReload(); 
}
