function sd_echoOption( fromName ) {
	var val = document.download[fromName].value;
	document.download.downloadMethod.value = val;
	document.download.downloadMethodAlt.value = val;
}

function sd_resort( field ) {
  document.download.resortBy.value = field;
  return sd_go( "sort" );
}

function sd_setPage( page ) {
  document.download.newPage.value = page;
  return sd_go( "page" );
}

function sd_doDownload(){
  var ret = sd_go( "download" );
  sd_unselectAll();
  return ret;
}

function sd_clearValuesMatch( leadingMatch ){
  for (var i = 0; i < document.download.length; i++) {
    var o = document.download.elements[i];
    if( o.name.indexOf( leadingMatch ) == 0 ){
      o.value = "";
    }
  }
}

function sd_clearValues(){
  sd_clearValuesMatch( "search" );
}

function sd_doClear(){
  sd_clearValues();
  return sd_go('search');
}

var sd_category_field="category";

function sd_setCategoryValue( cat ){
  var objs = document.getElementsByName("search["+sd_category_field+"=]");
  for( var i=0; i<objs.length; i++ ){
    var obj = objs[i];
    obj.value = cat;
  }
}

function sd_setCategory( cat ){
  sd_setCategoryValue( cat );
  return sd_go('search');
}

function sd_print( page ){
  document.download.target = "_blank";
  document.download.newPage.value = page;
  return sd_go("print");
}

function sd_enterGo( cmd ){
  if (window.event && window.event.keyCode == 13)
    return sd_go( cmd );
  else
    return true;
}

function sd_go( cmd ){
  document.download.command.value = cmd;
  sd_go_debug();
  document.download.submit();
  document.download.target = "";
  return false;
}

var sd_debug = false;

function sd_go_debug(){
  if( sd_debug ){
    var msg = "";

    for (var i = 0; i < document.download.length; i++) {
      var o = document.download.elements[i];
      msg += o.name + "=" + o.value +"\n";
    }

    window.alert( msg );
  }
}

function sd_checkEnter(event) {
  var keycode;
  if (window.event) {
    keycode = window.event.keyCode;
  } else if (event) {
    keycode = event.which;
  }
  return (keycode == 13); 
}

function sd_cart() {
  sd_clearValues();
  return sd_go('cart');
}

function sd_popup( url, features ){
  window.open( url, "popup", features );
  return false;  // Do not follow href 
}

var sd_audio_features = "";

function sd_audio( url ){
  if( sd_audio_features != "" ){
    return sd_popup( url, sd_audio_features );
  } else {
    return true;  // Take the default action, ie - follow the link
  }
}