/*
 *  jukebox.js - javascript routines for jukebox page
 *  $Revision: 1.15 $
 *  $Date: 2008/10/10 08:27:33 $
 *
 *  copyright 2006-2007 Jim E. Sontag
 *
 ****************************************************************/

var msExploder = navigator.appName.match( /Microsoft/ ) ? true : false;

// ==================================================================
 
function reqList()
{
  // user submits a request list
  var x = document.getElementById('cmd')
  x.value = 'vote'
  document.getElementById( 'criteria' ).submit()
}

function clrClient()
{
//  document.getElementById('field').value = 'client'
  document.getElementById('client').value = ''
  document.getElementById('criteria').submit()
}

function prevBlk()
{
  var elem = document.getElementById('firstrow')
  var x = parseInt(elem.value)
  elem.value = x - incr 
  document.getElementById('criteria').submit() 
}

function nextBlk()
{
  var elem = document.getElementById('firstrow')
  var x = parseInt(elem.value)
  elem.value = x + incr 
  document.getElementById('criteria').submit() 
}

function promote( idx )
{
  document.getElementById( 'cmd' ).value = 'promote'
  document.getElementById( 'song' ).value = idx
  document.getElementById('criteria').submit() 
}

function remove( idx )
{
  document.getElementById( 'cmd' ).value = 'remove'
  document.getElementById( 'song' ).value = idx
  document.getElementById('criteria').submit() 
}

function clearSearch()
{
  // when a new value has been entered in either
  // the title or artist input fields
  document.getElementById('firstrow').value = 0
  document.getElementById('total').value = 0
}

function clearCriteria()
{
  // when a new value has been entered in 
  // the search input field
  document.getElementById('firstrow').value = 0
  document.getElementById('total').value = 0
}

function newQuery()
{
  document.getElementById('firstrow').value = 0
  document.getElementById('total').value = ''
}

function chkKey( elem, evt )
{
/* This function was originally written for IE because the onChange
   event would not fire if the submit button was disabled.  According
   to the HTML 4.01 spec, onChange is not supposed to fire until the focus
   changes to another control, but FF fires the onChange event when the
   Enter key is hit.
   
   To overcome this behavior with IE, we check for keystrokes. If the
   Enter key is hit, we clear the criteria fields and initiate a new Query.
   The net effect is to 'rollover' from the last record to the first
   with the search criteria reamin the same. Only the Limit clause gets 
   adjusted.  
*/

//  if( msExploder) { } // if this is MSIE

  // only process the Enter key
  if( evt.keyCode != 13 )
    return

  // identify the field that has the focus
//  document.getElementById( 'field' ).value = elem.id
  
  var first = parseInt(document.getElementById( 'firstrow' ).value)
  var total = parseInt(document.getElementById( 'total' ).value)
  
  // check to see if more records exist
  var x = (total - first) > ( incr )
  if( !x ) {
    // no more
    document.getElementById( 'firstrow' ).value = 0
    return
  }
  var y = parseInt( document.getElementById( 'firstrow' ).value )
  document.getElementById( 'firstrow' ).value = y + incr
  
  return
}

function makeList( dir ) {
  document.getElementById('mode').value = dir
  document.getElementById('dummy').click()
}

function getGenre( genre )
{
  document.getElementById('search').value = genre
  document.getElementById('dummy').click()
}
