/* */

var metaPhOrs_link='/wsgi/metaPhOrs_query.py';

// 
function singleQuery(metaid){
  if ( metaid != "" ) {
    $("#breadcrumb").append( " <a target=_blank href='/wsgi/metaPhOrs_query.py/getAllSeqs?metaid="+metaid+"'>Get all sequences</a> ");
    $("#content_title").html("Orthology predictions for "+metaid);
    $("#pageContent").html('Searching...<br /><img src="/loader.gif">')
    $("#pageContent").load( metaPhOrs_link+'/orthologs', {"metaid": metaid } );
  }
  else{
    alert("Specify your query first.");
  }
}
/*
function multiQuery(){
  var textIds = document.getElementsByName("textIds")[0].value;
  var species = "";
  var handle = document.getElementsByName("species");
  if (textIds != "" ){
    for (i=0; i < handle.length; i++){
      species+=handle.item(i).value+" ";
    };
    $(".with-tabs").html("Predictions for multiple queries");
    $("#pageContent").html('Searching...<br /><img src="/loader.gif">')
    $("#pageContent").load( metaPhOrs_link+'/multi', {"textIds": textIds, "species": species } );
  }
}
//
function globalQuery(){
  var species = "";
  var handle = document.getElementsByName("species");
  if (handle.length == 2 ){
    var title="Predictions between ";
    for (i=0; i < handle.length; i++){
      species+=handle.item(i).value+" ";
      title+=handle.item(i).value;
      if (i==0){
        title+=" and ";
      }
    };
    $(".with-tabs").html(title);
    $("#pageContent").html('This query may take some time. Please, be patient.<br />Searching...<br /><img src="/loader.gif">')
    $("#pageContent").load( metaPhOrs_link+'/globalPred', {"species": species } );
  }
  else {
    alert("You have to specify two species!");
  }
}
*/
function getTrees( query,query2,extSignals ){
  var title = "Trees for "+query+" and "+query2;
  $("#content_title").html(title);
  $("#pageContent").html('Loading...<br /><img src="/loader.gif">')
  $("#pageContent").load( metaPhOrs_link+'/getTrees', {"query": query, "query2": query2, "extSignals": extSignals} );
}
function loadTree(ac){
  $("#tree").html('Loading...<br /><img src="/loader.gif">')
  $("#tree").load( metaPhOrs_link+'/loadTree', {"ac": ac } );
}
//
function getSeq(metaid){
  if ( metaid != "" ) {
    $("#content_title").html("Sequence information for "+metaid);
    $("#pageContent").html('<img src="/loader.gif">'+metaPhOrs_link+'/getSeq')
    $("#pageContent").load( metaPhOrs_link+'/getSeq', {"metaid": metaid } );
  }
}
//
function addSpecies(){
  var handle = document.getElementsByName("species");
  var inputBase='<input type="text" name="species" id="sp0" size="15" value="_value_" autocomplete="off" style="display: block"><div id="sp0suggestion" class="suggest"></div>';
  if (handle.length <= 7){
    var curHtml='',_html='';
    for (i=1; i <= handle.length; i++){
      _html=inputBase.replace( 'sp0', 'sp'+i );
      _html=_html.replace( 'sp0', 'sp'+i );
      _html=_html.replace( '_value_', handle.item(i-1).value );
      curHtml+=_html;
    };
    $("#speciesSelector").html( curHtml );
  }
  else{
    alert("There is limit of 7 species.\nSelect no species to get predictions from all species in text mode.");
  }
  document.getElementById("sp0").value="";
}
function clearElement(fieldId){
  $(fieldId).html("");
}
//
function setbg(color){
  document.getElementById("styled").style.background=color
}
//
function togglecomments (postid) { 
  var whichpost = document.getElementById(postid);
  if (whichpost.className=="commentshown") {
    whichpost.className="commenthidden"; 
  } 
  else {
    whichpost.className="commentshown"; 
  } 
}
  
// BLAT SEARCH
function similaritySearch() {
  var fasta = document.getElementById("fastaQuery").value, species=document.getElementById("sp0").value;
  if ( fasta != "" ) {
    $("#pageContent").html('<img src="/loader.gif">')
    $("#pageContent").load(metaPhOrs_link+'/similaritySearch', {"fasta": fasta,"species": species } );    
  } 
  else {
    alert("Provide fasta sequence first");
  }
}

function clearField(fieldId) {
  document.getElementById(fieldId).value="";
}




