/* Search tabs. Uses jQuery. */

function selected(tab) {
  jQuery('#letters a').attr('class',(tab=='block-letters')?'current':'');
  jQuery('#people a').attr('class',(tab=='block-people')?'current':'');
  jQuery('#bibliography a').attr('class',(tab=='block-bibliography')?'current':'');
  jQuery('#articles a').attr('class',(tab=='block-articles')?'current':'');
  jQuery('#block-letters').css('display','none');
  jQuery('#block-people').css('display','none');
  jQuery('#block-bibliography').css('display','none');
  jQuery('#block-articles').css('display','none');
  jQuery('#'+tab).css('display','block');
}

function lucene_escape(instr) {
  outstr="";
  for(var i=0;i<instr.length;i++) {
    if(instr.charAt(i).match(/[+&|!(){}[\]^"~*?:\\\\-]/))
      outstr=outstr+"\\";
    outstr=outstr+instr.charAt(i);
  }
  return "\""+outstr+"\"";
}

jQuery(window).load(function(){
  jQuery('#block-people').css('display','none');
  jQuery('#block-bibliography').css('display','none');
  jQuery('#block-articles').css('display','none');
  jQuery('#letters a').click(function() { selected('block-letters'); });
  jQuery('#people a').click(function() { selected('block-people'); });
  jQuery('#bibliography a').click(function() { selected('block-bibliography'); });
  jQuery('#articles a').click(function() { selected('block-articles'); });
  selected('block-letters');
    
  jQuery('.cmxform').submit(function() {
    var str='';
    jQuery('input',this).each(function() {
      var name=jQuery(this).attr('name');
      var value=jQuery(this).attr('value');
      if(value && name!='Search')
        str=str+name+":"+lucene_escape(value)+" ";
    });
/*    jQuery.getJSON("http://camtools-labs.caret.cam.ac.uk/solr/select",{
      "wt": "json",
      "fl": "*",
      "q": str
    },function(data) {
      alert(data);
    }); */
    
 //   alert(str);
//    return false;
  });
  
});
