
var numButtons = 0; //this variable holds the number of buttons currently in the toolbar

function sequenceHistory(){

   document.mainForm.act.value = "dsp_inputHistory";
   document.mainForm.action = "results.jsp";
   document.mainForm.target = "_results";

   document.mainForm.submit();

   document.mainForm.action = "toolbar.jsp";
   document.mainForm.target = "_toolbar";
   
}


function mailThis(num1){


   var act = document.mainForm.elements['act' + num1].value;
   var theGid = document.mainForm.elements['gid' + num1].value;
   var thefileName = document.mainForm.elements['fileName' + num1].value;

     //document.restoreForm.target="_mail";
     //document.restoreForm.action="act/act_mail.jsp";
     document.restoreForm.act.value = "act_mail";
     document.restoreForm.party.value = document.mainForm.elements['act' + num1].value;
     document.restoreForm.gid.value = document.mainForm.elements['gid' + num1].value;
     document.restoreForm.fileName.value = document.mainForm.elements['fileName' + num1].value;
     document.restoreForm.submit();
     document.restoreForm.action="results.jsp";
     //document.restoreForm.target="_results";

}

function saveItem(num1){

   var act = document.mainForm.elements['act' + num1].value;
   var theGid = document.mainForm.elements['gid' + num1].value;
   var thefileName = document.mainForm.elements['fileName' + num1].value;
   var theType = document.mainForm.elements['type' + num1].value;


     document.restoreForm.action="results.jsp?ps=save";
     document.restoreForm.party.value = document.mainForm.elements['act' + num1].value;

     document.restoreForm.act.value = "act_printAndSave";
     document.restoreForm.gid.value = document.mainForm.elements['gid' + num1].value;
     document.restoreForm.fileName.value = document.mainForm.elements['fileName' + num1].value;
     document.restoreForm.type.value = document.mainForm.elements['type' + num1].value;
     document.restoreForm.submit();
     document.restoreForm.action = "results.jsp";
}

function closeItem(num1){

    //to remove an item from the toolbar, we make the value for 'act' for that item equal to ""
    //then we resubmit the form to toolbar.jsp
    //when recreating the buttons, toolbar.jsp will skip this button.

    document.mainForm.elements['act' + num1].value = "";

    document.mainForm.submit();

}


function printItem(num1){

   var act = document.mainForm.elements['act' + num1].value;
   var theGid = document.mainForm.elements['gid' + num1].value;
   var thefileName = document.mainForm.elements['fileName' + num1].value;
   var theType = document.mainForm.elements['type' + num1].value;

     document.restoreForm.target="_print";
     document.restoreForm.action="results.jsp?ps=print";
     document.restoreForm.party.value = document.mainForm.elements['act' + num1].value;

     document.restoreForm.act.value = "act_printAndSave";
     document.restoreForm.gid.value = document.mainForm.elements['gid' + num1].value;
     document.restoreForm.fileName.value = document.mainForm.elements['fileName' + num1].value;
     document.restoreForm.type.value = document.mainForm.elements['type' + num1].value;
     document.restoreForm.submit();
     document.restoreForm.action = "results.jsp";
     document.restoreForm.target="_results";
}


function restoreItem(num1){

   var act = document.mainForm.elements['act' + num1].value;
    
   document.mainForm.action="results.jsp";
   document.mainForm.target="_results";

   document.restoreForm.act.value = getPage(act);
   document.restoreForm.gid.value = document.mainForm.elements['gid' + num1].value;
   document.restoreForm.fileName.value = document.mainForm.elements['fileName' + num1].value;
   document.restoreForm.type.value = document.mainForm.elements['type' + num1].value;
   document.restoreForm.query.value = document.mainForm.elements['fileName' + num1].value;


   if (act == "Blast")
      document.restoreForm.blastType.value = document.mainForm.elements['blastType' + num1].value;

   else
      document.restoreForm.party.value = document.mainForm.elements['party' + num1].value;

   document.restoreForm.num.value = num1;
   document.restoreForm.submit();

   document.mainForm.action="toolbar.jsp";
   document.mainForm.target="_toolbar";
	
   
}

function getPage(act){
     switch (act) {
      case "DNA_Stat":
	return "act_dnaStat";

      case "DNA_CpG":
	return "act_dnaCpg";

      case "DNA_Pattern":
	return "act_dnaPattern";

      case "Translate":
	return "act_translate";

      case "Prot_Stat":
	return "act_protStat";

      case "Prot_Pattern":
	return "act_protPattern";

      case "View_Seq":
	return "act_sequence";

      case "ORF":
	document.restoreForm.party.value = "orf";
  	return "act_thirdParty";

      case "2&deg; Structure Prediction":
  	return "act_thirdParty";

      case "Dipole":
  	return "act_thirdParty";

      case "NCBI":
  	return "act_thirdParty";

      case "ProtParam":
  	return "act_thirdParty";

      case "NLSPredict":
  	return "act_thirdParty";

      case "efsite":
  	return "act_thirdParty";

      case "Gel_Mobil":
	return "act_rebase1";

      case "Map":
	return "act_rebase2";

      case "RE_BLAST":
	return "act_rebase3";

      case "Prot_Stat":
	return "act_protStat";

      case "Blast":
	return "dsp_blast";

      case "Outside_URL":
	return "dsp_url";

      default:
  	return "act_thirdParty";
     }//switch

   return"";

}

function getLink(act, theGid, thefileName, theType){
   var link;

   switch (act) {
      case "View_Seq":
	link = "act_sequence.jsp?gid=" + theGid + "&fileName=" + thefileName + "&type=" +theType;
	break;

      case "DNA_Stat":
	link = "act_dnaStat.jsp?gid=" + theGid + "&fileName=" + thefileName + "&type=" +theType;
	break;

      case "DNA_CpG":
	link = "act_dnaCpg.jsp?gid=" + theGid + "&fileName=" + thefileName + "&type=" +theType;
	break;

      case "DNA_Pattern":
	link = "act_dnaPattern.jsp?gid=" + theGid + "&fileName=" + thefileName + "&type=" +theType;
	break;

      case "Gel_Mobil":
	link = "act_rebase1.jsp?gid="+ theGid + "&fileName=" + thefileName;

	break;

      case "Map":
	link = "act_rebase2.jsp?gid="+ theGid + "&fileName=" + thefileName;
	break;

      case "RE_BLAST":
	link = "act_rebase3.jsp?gid="+ theGid + "&fileName=" + thefileName;
	break;

      case "Translate":
	link = "act_translate.jsp?gid=" + theGid + "&fileName=" + thefileName + "&type=" +theType;
	break;

      case "Prot_Stat":
	link = "act_protStat.jsp?gid=" + theGid + "&fileName=" + thefileName + "&type=" +theType;
	break;

      case "Prot_Pattern":
	link = "act_protPattern.jsp?gid=" + theGid + "&fileName=" + thefileName + "&type=" +theType;
	break;

      case "View_Struct":
	link = "http://www.ncbi.nlm.nih.gov/Structure/mmdb/mmdbsrv.cgi?uid=" + theGid + "&form=6&db=t&Dopt=j";
	break;

      case "NCBI":
      case "ProtParam":
      case "Dipole":
      case "efsite":
      case "ORF":
      case "2&deg; Structure Prediction":
	link = "orf/" + theGid + ".html";
	break;

      case "Blast":
	link = "query/" + thefileName + "/" + "Sequerome Results.html"
	//link = "results.jsp?act=wait&&fileName=" + thefileName + "&type=" +theType;
	break;

      default:
	link = "nothing";
	break;
   
   }

   return link;

}

function orf(gid,idType,seq){

   //these fields hold the information for the input history button
   document.mainForm.perform.value = "orf";
   document.mainForm.seq.value = seq;
   document.mainForm.seqId.value = gid;
   document.mainForm.idType.value = idType;
   document.mainForm.htype.value = "DNA";

   //These fields hold informatoin for this actions button on the toolbar
   document.mainForm.elements[name1].value = "ORF";
   document.mainForm.elements[name2].value = gid;
   document.mainForm.elements[name3].value = seq;
   document.mainForm.elements[name4].value = "DNA";
   document.mainForm.elements[name5].value = "orf";
   document.mainForm.submit();


}//orf

function smart(gid, idType, seq){

   //these fields hold the information for the input history button
   document.mainForm.perform.value = "2&deg; Structure Prediction";
   document.mainForm.seq.value = seq;
   document.mainForm.seqId.value = gid;
   document.mainForm.idType.value = idType;
   document.mainForm.htype.value = "Protein";

   //These fields hold informatoin for this actions button on the toolbar
   document.mainForm.elements[name1].value = "2&deg; Structure Prediction";
   document.mainForm.elements[name2].value = gid;
   document.mainForm.elements[name3].value = seq;
   document.mainForm.elements[name4].value = "Protein";
   document.mainForm.elements[name5].value = "smart";
   document.mainForm.submit();


}//smart

function dnaPattern(gid, idType, seq, type){


   //these fields hold the information for the input history button
   document.mainForm.perform.value = "DNA Pattern";
   document.mainForm.seq.value = seq;
   document.mainForm.seqId.value = gid;
   document.mainForm.idType.value = idType;
   document.mainForm.htype.value = "DNA";

   //These fields hold informatoin for this actions button on the toolbar
  document.mainForm.elements[name1].value = "DNA_Pattern";
  document.mainForm.elements[name2].value = gid;
  document.mainForm.elements[name3].value = seq;
  document.mainForm.elements[name4].value = type;
  document.mainForm.submit();

}

function blast(fileName, type, blastType, seq, seqId, idType){

   //these fields hold the information for the input history button
   document.mainForm.perform.value = "BLAST";
   document.mainForm.seq.value = seq;
   document.mainForm.seqId.value = seqId;
   document.mainForm.idType.value = idType;
   document.mainForm.htype.value = type;

   //These fields hold informatoin for this actions button on the toolbar
  document.mainForm.perform.value = type + " BLAST";
  document.mainForm.elements[name1].value = "Blast";
  document.mainForm.elements[name2].value = fileName;
  document.mainForm.elements[name3].value = fileName;
  document.mainForm.elements[name4].value = type;
  document.mainForm.elements[name6].value = blastType;
  document.mainForm.submit();


}


function dnaStat(gid, idType, seq, type){


   //these fields hold the information for the input history button
   document.mainForm.perform.value = "DNA STAT";
   document.mainForm.seq.value = seq;
   document.mainForm.seqId.value = gid;
   document.mainForm.idType.value = idType;
   document.mainForm.htype.value = type;

   //These fields hold informatoin for this actions button on the toolbar
  document.mainForm.elements[name1].value = "DNA_Stat";
  document.mainForm.elements[name2].value = gid;
  document.mainForm.elements[name3].value = seq;
  document.mainForm.elements[name4].value = type;
  document.mainForm.submit();


}

function dnaCpG(gid,idType, seq, type){

   //these fields hold the information for the input history button
   document.mainForm.perform.value = "DNA CpG";
   document.mainForm.seq.value = seq;
   document.mainForm.seqId.value = gid;
   document.mainForm.idType.value = idType;
   document.mainForm.htype.value = type;

   //These fields hold informatoin for this actions button on the toolbar
  document.mainForm.elements[name1].value = "DNA_CpG";
  document.mainForm.elements[name2].value = gid;
  document.mainForm.elements[name3].value = seq;
  document.mainForm.elements[name4].value = type;
  document.mainForm.submit();


}

function seq(gid, fileName, type){


   //these fields hold the information for the input history button
   document.mainForm.perform.value = "View Seq";
   document.mainForm.seq.value = "";
   document.mainForm.seqId.value = gid;
   document.mainForm.idType.value = "gid";
   document.mainForm.htype.value = type;

   //These fields hold informatoin for this actions button on the toolbar
  document.mainForm.elements[name1].value = "View_Seq";
  document.mainForm.elements[name2].value = gid;
  document.mainForm.elements[name3].value = fileName;
  document.mainForm.elements[name4].value = type;
  document.mainForm.submit();


}

function translate(gid, idType, seq, type){

   //these fields hold the information for the input history button
   document.mainForm.perform.value = "Translate";
   document.mainForm.seq.value = seq;
   document.mainForm.seqId.value = gid;
   document.mainForm.idType.value = idType;
   document.mainForm.htype.value = type;

   //These fields hold informatoin for this actions button on the toolbar
  document.mainForm.elements[name1].value = "Translate";
  document.mainForm.elements[name2].value = gid;
  document.mainForm.elements[name3].value = seq;
  document.mainForm.elements[name4].value = type;
  document.mainForm.submit();



}

function ncbi(gid,idType,type){

   //these fields hold the information for the input history button
   document.mainForm.perform.value = "NCBI Page";
   document.mainForm.seq.value = "";
   document.mainForm.seqId.value = gid;
   document.mainForm.idType.value = idType;
   document.mainForm.htype.value = type;

   //These fields hold informatoin for this actions button on the toolbar
   document.mainForm.elements[name1].value = "NCBI";
   document.mainForm.elements[name2].value = gid;
   document.mainForm.elements[name4].value = type;
   document.mainForm.elements[name5].value = "ncbi";
   document.mainForm.submit();




}//ncbi

function rebase1(gid,idType, seq){

   /*

   All of the rebase functions currently are executed in a new window.
   This can probably be changed if all of the images from these pages are stored on the server
 	as well as all of the html code from the page.
   For now we will open it in a new window.
   We open the window here (instead of where the button was originally clicked)
	so that toolbar.jsp can easily keep track of this window

  */


   //Send a request to a new window to perform this action
   document.restoreForm.target='Gel_Mobil_'+ gid + x;
   document.restoreForm.act.value="act_rebase1";
   document.restoreForm.gid.value=gid;
   document.restoreForm.fileName.value=seq;
   document.restoreForm.submit();
   document.restoreForm.target='_results';


   //these fields hold the information for the input history button
   document.mainForm.perform.value = "Gel Mobility";
   document.mainForm.seq.value = seq;
   document.mainForm.seqId.value = gid;
   document.mainForm.idType.value = idType;
   document.mainForm.htype.value = "DNA";

   //These fields hold informatoin for this actions button on the toolbar
   document.mainForm.elements[name1].value = "Gel_Mobil";
   document.mainForm.elements[name2].value = gid;
  document.mainForm.elements[name3].value = seq;
   document.mainForm.elements[name4].value = "DNA";
   document.mainForm.submit();




}//rebase1

function rebase2(gid, idType, seq){

   /*

   All of the rebase functions currently are executed in a new window.
   This can probably be changed if all of the images from these pages are stored on the server
 	as well as all of the html code from the page.
   For now we will open it in a new window.
   We open the window here (instead of where the button was originally clicked)
	so that toolbar.jsp can easily keep track of this window

  */

   //Send a request to a new window to perform this action
   document.restoreForm.target='Map_'+gid + x;
   document.restoreForm.act.value="act_rebase2";
   document.restoreForm.gid.value=gid;
   document.restoreForm.fileName.value=seq;
   document.restoreForm.submit();
   document.restoreForm.target='_results';


   //these fields hold the information for the input history button
   document.mainForm.perform.value = "Map";
   document.mainForm.seq.value = seq;
   document.mainForm.seqId.value = gid;
   document.mainForm.idType.value = idType;
   document.mainForm.htype.value = "DNA";

   //These fields hold informatoin for this actions button on the toolbar
   document.mainForm.elements[name1].value = "Map";
   document.mainForm.elements[name2].value = gid;
   document.mainForm.elements[name3].value = seq;
   document.mainForm.elements[name4].value = "DNA";
   document.mainForm.submit();


}//rebase2

function rebase3(gid,idType,seq){

   /*

   All of the rebase functions currently are executed in a new window.
   This can probably be changed if all of the images from these pages are stored on the server
 	as well as all of the html code from the page.
   For now we will open it in a new window.
   We open the window here (instead of where the button was originally clicked)
	so that toolbar.jsp can easily keep track of this window

  */

   //Send a request to a new window to perform this action
   document.restoreForm.target='RE_BLAST_'+gid + x;
   document.restoreForm.act.value="act_rebase3";
   document.restoreForm.gid.value=gid;
   document.restoreForm.fileName.value=seq;
   document.restoreForm.submit();
   document.restoreForm.target='_results';


   //these fields hold the information for the input history button
   document.mainForm.perform.value = "RE-BLAST from REBASE";
   document.mainForm.seq.value = seq;
   document.mainForm.seqId.value = gid;
   document.mainForm.idType.value = idType;
   document.mainForm.htype.value = "DNA";

   //These fields hold informatoin for this actions button on the toolbar
   document.mainForm.elements[name1].value = "RE_BLAST";
   document.mainForm.elements[name2].value = gid;
   document.mainForm.elements[name3].value = seq;
   document.mainForm.elements[name4].value = "DNA";
   document.mainForm.submit();


}//rebase3

function protParam(gid,idType,seq){


   //these fields hold the information for the input history button
   document.mainForm.perform.value = "ProtParam";
   document.mainForm.seq.value = seq;
   document.mainForm.seqId.value = gid;
   document.mainForm.idType.value = idType;
   document.mainForm.htype.value = "Protein";
  
   //These fields hold informatoin for this actions button on the toolbar
   document.mainForm.elements[name1].value = "ProtParam";
   document.mainForm.elements[name2].value = gid;
   document.mainForm.elements[name3].value = seq;
   document.mainForm.elements[name4].value = "Protein";
   document.mainForm.elements[name5].value = "protParam";
   document.mainForm.submit();


}//protparam

function NLSPredict(gid,idType,seq){

   //these fields hold the information for the input history button
   document.mainForm.perform.value = "NLSPredict";
   document.mainForm.seq.value = seq;
   document.mainForm.seqId.value = gid;
   document.mainForm.idType.value = idType;
   document.mainForm.htype.value = "Protein";
  
   //These fields hold informatoin for this actions button on the toolbar
   document.mainForm.elements[name1].value = "NLSPredict";
   document.mainForm.elements[name2].value = gid;
   document.mainForm.elements[name3].value = seq;
   document.mainForm.elements[name4].value = "Protein";
   document.mainForm.elements[name5].value = "NLSPredict";
   document.mainForm.submit();


}//NLSPredict

function dipole(gid, seq){

   //these fields hold the information for the input history button
   document.mainForm.perform.value = "Dipole";
   document.mainForm.seq.value = "";
   document.mainForm.seqId.value = gid;
   document.mainForm.idType.value = "pdbid";
   document.mainForm.htype.value = "Protein";

   document.mainForm.elements[name1].value = "Dipole";
   document.mainForm.elements[name2].value = gid;
   document.mainForm.elements[name3].value = seq;
   document.mainForm.elements[name4].value = "DNA";
   document.mainForm.elements[name5].value = "dipole";
   document.mainForm.submit();


}//dipole

function efsite(gid, seq){

   //these fields hold the information for the input history button
   document.mainForm.perform.value = "efsite";
   document.mainForm.seq.value = "";
   document.mainForm.seqId.value = gid;
   document.mainForm.idType.value = "pdbid";
   document.mainForm.htype.value = "Protein";
   
   document.mainForm.elements[name1].value = "efsite";
   document.mainForm.elements[name2].value = gid;
   document.mainForm.elements[name3].value = seq;
   document.mainForm.elements[name4].value = "DNA";
   document.mainForm.elements[name5].value = "efsite";
   document.mainForm.submit();


}//efsite

function protStat(gid, idType, seq, type){

   //these fields hold the information for the input history button
   document.mainForm.perform.value = "Protein STAT";
   document.mainForm.seq.value = seq;
   document.mainForm.seqId.value = gid;
   document.mainForm.idType.value = idType;
   document.mainForm.htype.value = type;

   //These fields hold informatoin for this actions button on the toolbar
  document.mainForm.elements[name1].value = "Prot_Stat";
  document.mainForm.elements[name2].value = gid;
  document.mainForm.elements[name3].value = seq;
  document.mainForm.elements[name4].value = type;
  document.mainForm.submit();


}

function protPattern(gid, idType, seq, type){


   //these fields hold the information for the input history button
   document.mainForm.perform.value = "Protein Pattern";
   document.mainForm.seq.value = seq;
   document.mainForm.seqId.value = gid;
   document.mainForm.idType.value = idType;
   document.mainForm.htype.value = type;

   //These fields hold informatoin for this actions button on the toolbar
  document.mainForm.elements[name1].value = "Prot_Pattern";
  document.mainForm.elements[name2].value = gid;
  document.mainForm.elements[name3].value = seq;
  document.mainForm.elements[name4].value = type;
  document.mainForm.submit();


}

function structure(pdbid){
   var newWin = window.open("http://www.ncbi.nlm.nih.gov/Structure/mmdb/mmdbsrv.cgi?uid=" + pdbid + "&form=6&db=t&Dopt=j","View_Struct_" + pdbid,'width=500,height=500,directories=yes,location=yes,menubar=yes,scrollbars=yes,status=yes,toolbar=yes,resizable=yes');
   newWin.focus();


   //these fields hold the information for the input history button
   document.mainForm.perform.value = "View Structure";
   document.mainForm.seq.value = "";
   document.mainForm.seqId.value = pdbid;
   document.mainForm.idType.value = "pdbid";
   document.mainForm.htype.value = "Protein";
   
   //These fields hold informatoin for this actions button on the toolbar
   document.mainForm.elements[name1].value = "View_Struct";
   document.mainForm.elements[name2].value = pdbid;
   document.mainForm.elements[name3].value = "noFile";
   document.mainForm.elements[name4].value = "Protein";
   document.mainForm.submit();

}//structure

function url(theUrl){

  var shortUrl = theUrl;

  if (theUrl.substring(0,7) == "http://")
	shortUrl = theUrl.substring(7,theUrl.length);

  if (shortUrl.length > 20){
	shortUrl = shortUrl.substring(0,18) + "...";
  }

  document.mainForm.elements[name1].value = "Outside_URL";
  document.mainForm.elements[name2].value = shortUrl;
  document.mainForm.elements[name3].value = theUrl;
  document.mainForm.submit();

}

	
