function buglog ( msg ) {
    if ( window.console ) { window.console.log ( msg ) ; }
}

function ebyid ( id ) {
    return document.getElementById( id ) ;
}
eid = ebyid ;

// searches the text of a select input's options, and selects the next match beyond the current selection
function searchSelectbox(needle,haystack) {
  if ( ! needle.length ) { return ; }
  var re = new RegExp(needle, 'i') ;
  var first = -1 ;
  for ( var i = 0 ; i < haystack.options.length ; i++ ) {
    if ( re.test( haystack.options[i].text ) ) {
      // make a note of the first match for looping later if necessary
      if ( first < 0 ) { first = i ; }
      // if a this match is later than the selected one, select it
      //buglog( first, i, haystack.selectedIndex ) ;
      if ( i > haystack.selectedIndex ) {
        haystack.options[i].selected = true ;
        return ;
      }
    }
  }
  // loop back to the first match if there are no later  matches
  if ( first > -1 ) { haystack.options[first].selected = true ; }
  return ;
}


function ckmodten( ccnum ) {
  // http://www.beachnet.com/~hstiles/cardtype.html
  // Visa, MC, Amex and Discover use this mod10 checksumming method for card numbers
  ccnum = ccnum.replace( /[^0-9]/g  , '' ) ;
  buglog( ccnum ) ;
  if ( ! ccnum.length ) { return false ; }
  var sum = 0 ;
  ccnum = ccnum.split('').reverse() ;
  for ( var ccidx = 0 ; ccidx < ccnum.length ; ccidx++ ) {
    if ( ccidx %2 ) {
      mult = (ccnum[ccidx]*2+'') ;
      for ( var multidx = 0 ; multidx < mult.length ; multidx++ ) {
        sum += mult[multidx] *1 ; }
    } else {
      sum += ccnum[ccidx] *1 ;
    }
    //buglog( sum ) ;
  }
  buglog( 'final sum: '+ sum + ( ! ( sum %10 ) ) ) ;
  return ! ( sum %10 )  ;
}

