
////////////////////////////////////////////////////
//
// TOGGLE_SEARCH_OPTIONS FUNCTION
//
// Show 'Advanced Search' or 'ISBN' search options
//   * If div is already visible and user clicks on tab again, it disappears.
//   * Also changes link style of clicked tab.
//
////////////////////////////////////////////////////

function toggle_search_options(which, link, focus_on) {
    if (jQuery("#" + link).hasClass('selected')) {
        jQuery("#" + link).removeClass('selected');
	   jQuery("#" + which).addClass('invisible');
    } else {
	   jQuery(".search").addClass('invisible');
	   jQuery(".selected").removeClass('selected');
	   jQuery("#" + link).addClass('selected');
	   jQuery("#" + which).removeClass('invisible');
    }
    jQuery("#" + focus_on).focus();
}

// Toggle
function toggle(el, class_name) {
   jQuery('#' + el).toggleClass(class_name);
}

////////////////////////////////////////////////////
//
// TOGGLE TEXT
//
////////////////////////////////////////////////////

function toggle_text(el, def, alt) {
   if (jQuery('#' + el).html() == def) {
      jQuery('#' + el).empty().html(alt);
   } else {
      jQuery('#' + el).empty().html(def);
   }
}

////////////////////////////////////////////////////
//
// EMPTY_FORM FUNCTION
//
// Hit "Clear" button -> put all fields back to default state.
// NOTE: Not the state they were in when you arrived at the page - that would be "Reset," which is...
//   * a native HTML behavior
//   * what the button does if user doesn't have javaScript.
//
////////////////////////////////////////////////////

function empty_form(which_form, focus_on) {
   if (which_form == 'adv_search_form') {

      // Blank Out Text Fields
       var Blanks = ['kw_adv','title_adv','author_adv','publisher_adv','section_adv'] ;
      for( var i in Blanks ) {
	  jQuery('#' + Blanks[i]).val('');
      }

      // Reset Drop-Downs
      var Selects = ['class_adv','binding_adv','sort_by_adv','location_adv','days_old_adv'];
      for( var i in Selects ) {
	  jQuery('#' + Selects[i]).find('option:first').attr('selected', 'selected').parent('select');
      }

      // Uncheck Exact Title
      jQuery('#exact_title_adv').attr('checked', false);

      // Set Items Per Page To 100
      jQuery("#per_page_adv option[value='100']").attr('selected', 'selected');
   } else {
	  jQuery('#isbn').val('');
   }
   jQuery('.filled-in').removeClass('filled-in');
   jQuery('#kw_adv').focus();
}

////////////////////////////////////////////////////
//
// UNFLAG FUNCTION
// 
// PROBLEM: User mistakenly leaves a restricting condition (from their old search) on their new search.
//   * SERVER-SIDE: Add style 'filled-in' to label of a form element that has a value that is not the default value.
//   * CLIENT-SIDE: onChange, remove that style.
//
////////////////////////////////////////////////////

function unflag(which) {
    var id = jQuery(which).attr("id");
    if (jQuery("label[for='" + id + "']").hasClass('filled-in')) {
	jQuery("label[for='" + id + "']").removeClass('filled-in');
    }
}
