
this.sequenceConservationStatus = "off";
this.scFile = new String();
this.activeMode = "wireframe 0.10; spacefill 20%; colour none";
this.hlColorMode="colour none;";
this.hlMode=null;

function saveImage() {
	var myImage = jmolGetPropertyAsString("image");
	$("image_form").image.value = myImage;
	$("image_form").submit();
}

function show(layerName) {
	$(layerName).style.display = "";
}
function hide(layerName) {
	$(layerName).style.display = "none";
}

function run(script) {
	document.jmol.script(script);
}

function viewAmino() {
	cleanView();
	this.activeMode = "trace on; colour trace amino;";
	this.hlColorMode="colour trace amino;";
	this.hlMode="halos";
	updateView();
	updateHighlights();
}
function viewRainbow() {
	cleanView();
	this.activeMode = "trace on; colour trace group";
	this.hlColorMode="colour trace group;";
	this.hlMode="halos";
	updateView();
	updateHighlights();
}
function viewCartoon() {
	cleanView();
	this.activeMode = "cartoon on; colour structure";
	this.hlColorMode="colour structure;";
	this.hlMode="halos";
	updateView();
	updateHighlights();
}
function viewRocket() {
	cleanView();
	this.activeMode = "rocket 1.5; colour structure";
	this.hlColorMode="colour structure;";
	this.hlMode="halos";
	updateView();
	updateHighlights();
}
function viewBallStick() {
	cleanView();
	this.activeMode = "wireframe 0.10; spacefill 20%; colour none";
	this.hlColorMode="colour none;";
	this.hlMode=null;
	updateView();
	updateHighlights();
}
function viewLine() {
	cleanView();
	this.activeMode = "wireframe 0.10; colour chain";
	this.hlColorMode="colour chain;";
	this.hlMode=null;
	updateView();
	updateHighlights();
}
function viewStick() {
	cleanView();
	this.activeMode = "wireframe 0.50; colour chain";
	this.hlColorMode="colour chain;";
	this.hlMode=null;
	updateView();
	updateHighlights();
}
function viewSpace() {
	cleanView();
	this.activeMode = "spacefill 150%; colour chain";
	this.hlColorMode="colour chain;";
	this.hlMode=null;
	updateView();
	updateHighlights();
}
function viewCompo() {
	cleanView();	
	this.activeMode = "select all; spacefill 100%; select protein; color [Xcbbe8a]; select dna; color [Xae00fe]; select rna; color [Xfd0162]; select solvent; color [X3a79bc]; select ligand; color [X6dfa36]";
	this.hlColorMode="color [Xcbbe8a];";
	this.hlMode=null;
	updateView();
	updateHighlights();
}
function viewChar() {
	cleanView();
	this.activeMode = "select all; spacefill 100%; select solvent; color [X3a79bc]; select ligand; color [X6dfa36];select dna; cartoon on; color [Xae00fe]; select rna; cartoon on; color [Xfd0162]; select phe, met, trp, ile, val, leu, ala, pro; color grey; select cys, asn, gln, thr, tyr, ser, gly, his, lys, arg, asp, glu; color magenta; select his, lys, arg; color [X3366ff]; select asp, glu; color [Xdd0000]";	
	this.hlColorMode="select phe, met, trp, ile, val, leu, ala, pro; color grey; select cys, asn, gln, thr, tyr, ser, gly, his, lys, arg, asp, glu; color magenta; select his, lys, arg; color [X3366ff]; select asp, glu; color [Xdd0000];";
	this.hlMode=null;
	updateView();
	updateHighlights();
}
function updateView(){	
	// if the sequence conservation is on
	if (this.sequenceConservationStatus == "on" && this.scFile != null) {
		jmolScript(this.activeMode);
		// draw the conservation again.
		showSequenceConservation(this.scFile, true);
	} else {
		jmolScript("select all; " + this.activeMode);
	}
	var select = $('colorStructures');
	if(select && select.selectedIndex > 0) { 	
		colorStructure(select);
	}	
}
function updateHighlights(){
	hlManager.setMode(this.hlMode);
	hlManager.drawAll(null);	
}

function cleanView() {
	jmolScript("restore state state0;  wireframe off; spacefill off; trace off;labels off; ribbon off;cartoon off; rocket off;hbonds off; ssbonds off;");
	uncheckSpinCheckBox();	
    restoreOriginalZoom();	
	selectNoConservation();	
}

function clearDefaultJmolCommand() {
	var jmolCommand = $("jmolCommand");
	if (jmolCommand.value == "Type JMol command here.") {
		jmolCommand.value = "";
	}
}
function executeJmolCommand() {
	var jmolCommand = $("jmolCommand");
	if (jmolCommand.value != "Type JMol command here.") {
		jmolScript(jmolCommand.value);
	}
}
			
function uncheckSpinCheckBox() {
	var spinChkBox = $("SpinCheckBox");
	spinChkBox.checked = false;
}			
			
function showSequenceConservation(filename, skipHl) {
	this.scFile = filename;
	this.sequenceConservationStatus = "on";
	jmolScript("select all; spacefill; set propertyAtomNumberField 1; set propertyDataField 2;");
	jmolScript('x=load("' + filename + '");');
	jmolScript('data "property_poly @x"; propertyColorScheme ="bwr"; color property_poly; color property_poly absolute -1 1;');
	if(!skipHl) {
		updateHighlights();
	}
}

function clearConservation() {
	this.sequenceConservationStatus = "off";
	this.scFile = null;
	updateView();
	updateHighlights();	
}

function selectNoConservation() {
	if($('sequenceConservations')) {
		$('sequenceConservations').checked = true;
	}
}

// Resets all user interface fields
function resetUiControls(fromDrug) {
   restoreOriginalZoom();
   $('SpinCheckBox').checked=false;
   $('displayTypeSelectBox').selectedIndex = 0;
   $('displayTypeFloatoverImg').src='./images/tstrBallStick.jpg';
   $('displayTypeImg').src='./images/tstrBallStick.jpg';
   $('displayTypeFloatoverText').innerHTML=$('displayTypeHelp5').innerHTML;   
   try {
   	 if (fromDrug ){
     	$('highlightLigand').checked=true;
     }else{
     	$('highlightLigand').checked=false;
     }
   } catch(e) {}
   $('swissprotPosition').value='';
   $('jmolCommand').value='Type JMol command here.';
   $('colorStructures').options[0].selected = true;
	resetHlInPink();
   $('labelDropdown').options[0].selected = true;
   $('saveState').options[0].selected = true;
   $('restoreState').options[0].selected = true;
   try {
     $$('.epitopeCheckbox').each(function(e) {
        e.checked=false;
     });
   } catch(e) {}
   try {
     $$('.activeSiteCheckbox').each(function(e) {
        e.checked=false;
     });
   } catch(e) {}       
   try {       
     $('seqConservSelectBox').selectedIndex=0;
   } catch(e) {}
   try {  
    	$('activeSitesDiv').hide();
    	$('showActiveSitesLinkDiv').show();
   }catch(e) {}
}

function checkLigands(){
	var ligands = jmolGetPropertyAsArray("atominfo", "ligand");	
	if(eval(ligands).length > 0) {
		$('showLigands').show();
		$('noLigands').hide();
	}
	else {
		$('showLigands').hide();
		$('noLigands').show();	
	}
    ligandHighlighter.highlight();
}
  
 function handleColorStructuresSelect(event) {
	var select = $('colorStructures');	
 	var command = select.options[select.selectedIndex].value.evalJSON();
	colorStructure(select);
	// show hide submenu
	var submenu = $(command.submenuId);
	// reset submenu
	resetHlInPink();
	pinkHighlighter.clearAllHighlight();
	if(submenu){		
		// Show the right one.
		$(submenu).disabled = false;
		$(submenu).show();
		$('pinkDropDownListRow').show();					
	}
 }
 
 function resetHlInPink() {
 	$('pinkDropDownListRow').hide();
	$$('.hlInPink').each(function(hlInPink){
		hlInPink.hide();
		hlInPink.options[0].selected = true;
		hlInPink.disabled = true;
	});
 }
 
 function colorStructure(select, skipHl) {
 	var command = select.options[select.selectedIndex].value .evalJSON();
 	jmolScript('select all;' + command.colorMode);
 	// if the color structure select box is not selected 	
	if(select.selectedIndex == 0) {
		updateView();		 	
	}
	// draw the highlights
	if(!skipHl) {
		hlManager.setMode(command.mode);		
		hlManager.drawAll(null);
	}	
 }
 function clearColorStructure() {
 	var select = $('colorStructures');
 	select.selectedIndex = 0;
 }
 
 
