/* begin javascript functions for swapping molecule lists --->
 this is probably messy - it's old code written under duress, but it works 
and I'm not inclined to change it */

function arrayStart(arrayAlpha,theForm,molClass)
{
	var arrayName = "";
	
	//set the hidden form field if specified
	if(molClass){
		theForm.viewedMolClass.value = molClass;
	}
	
	switch (theForm.viewedMolClass.value.toLowerCase()){
	
		case "receptor":
			arrayName = "arrayReceptor"+arrayAlpha;
			break;
			
		case "coregulator":
			arrayName = "arrayCoregulator"+arrayAlpha;
			break;
			
		case "ligand":
			arrayName = "arrayLigand"+arrayAlpha;
			break;
			
	
			}

	swapOptions(arrayName,theForm);	
}

function swapOptions(the_array_name)
{
/* internet explorer has a bug wherein setting innerHTML of a select 
box doesn't work. Their preferred solution is to set the options, which makes
sense, except that we can't do that in a straightforward way because of the 
entity references. Their solution for lesser mortals is to wrap the select 
in a div and do it that way. Okay! */ 

  var the_select = document.getElementById("internetExplorerSelectBug");
  var the_array = eval(the_array_name);
  
  //tried doing this with options and it escaped the entity references
  //let's try innerHTML and hope it all works
  the_select.innerHTML="<select name='selMolecule' id='selMolecule' size='1'>"+setOptionText(the_select,the_array)+"</select>";

  
}

function setOptionText(the_select, the_array)
{
	var returnText = "";
  for (loop=0; loop < the_array.length; loop++)
  {
  	var dispText = the_array[loop].split("||")[0];
	var dispValue = the_array[loop].split("||")[1];
    //tried doing this with options and it escaped the entity references
	//let's try innerHTML and hope it all works
    //the_select.options[loop] = new Option(dispText,dispValue);
	returnText+="<option value = '"+dispValue+"'>"+dispText+"</option>";
  }
	return(returnText);
  
}
function goMolecule (submitForm) {

	var molType = "";
	var molId = "";
	
	/* using getElementById because this part of the form
	because it's overwritten using innerHTML whenever the options
	list is changed. It's using innerHTML to rewrite the options
	because of the way IE mishandles entity references when doing
	it the "correct" way through the DOM
	*/
	var select = document.getElementById("selMolecule");

	//get molType
	/* edited out 9/21/6 CMW when we started using a hidden form field for this
	for(i=0; i < submitForm.moleculeType.length; i++){
		if(submitForm.moleculeType[i].checked) molType = submitForm.moleculeType[i].value;
	}
	*/
	molType = submitForm.viewedMolClass.value.toLowerCase();

	//get molId
	molId = select[select.selectedIndex].value;
	
	if(!molType.length || !molId.length){
		alert("Please select a molecule in order to view its information.");
		return false;
	}

	this.location.href="molecule.cfm?molType="+molType+"&molId="+molId;
}