  	var NS4 = (document.layers) ? 1 : 0;
  	var IE4 = (document.all) ? 1 : 0;
	var FF1 = (document.getElementById) ? 1 : 0;

	function OnLoad() {
		self.focus();
		pageLoaded = true;
		RebuildSearchContent();
	}

 	function clearEl() {}
	// end of hiding
 
	/*===========================================================================
						Search-Box Related Functions
	  ===========================================================================*/
	function SearchOptionChange(obj) {
		RebuildSearchContent();
	}

	function SearchRuleChange(obj) {
		RebuildSearchContent();
	}

	function SearchChangeTarget(obj) {
		var selected = GetSelectedRadio(obj);
		document.forms['SearchSubmitForm'].action=selected.value;
	}

	// This method will rebuild the search content in a non-style dependant manner,
	// that is - it doesn't know what kind of content is available in the fields, and
	// uses the object type to decipher what values to get from it.
	function RebuildSearchContent() {
		//TODO: Change from term to something more generic
		var termBox = document.getElementById("term");
		if (!termBox)
			return;

		var isLastRule = true;
		var searchString = "";
		var condition = null;

		for (ruleCnt=numRules; ruleCnt>0; ruleCnt--) {
			// Grab rule
			var rule = document.getElementById("SearchRule"+ruleCnt);
			
			// Grab condition (which is actually processed as a radio button, for last condition)
			var contentObj = GetRuleContent(ruleCnt);

			// If rule is included...
			if (rule.checked) {
				// Check if it's a multi-select box (special case)
				var value = GetInputValue(contentObj);

				// Disable AND/OR if last (doesn't have AND/OR) or if the value is empty (skipped)
				var disableCondition = (isLastRule == true | value == "");
				SearchEnableRule(ruleCnt, disableCondition);
	
				if (value != "") {
					// This condition will be applied to next rule
					if (!isLastRule) {
						condition = GetRuleCondition(ruleCnt);
						searchString  = " "+ condition +" " + searchString;
					}

					// Get it's value
					searchString = "("+value+")" + searchString;
	
					// Mark as used
					
	
					if (isLastRule)
						isLastRule = false;
				}
			}
			else {
				SearchDisableRule(ruleCnt);
			}
		}


		termBox.value = searchString;
	} 

	///
	function GetSelectedRadio(buttonGroup) {
	   // returns the array number of the selected radio button or -1 if no button is selected
	   if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
	      for (var i=0; i<buttonGroup.length; i++) {
	         if (buttonGroup[i].checked) {
	            return buttonGroup[i];
	         }
	      }
	   } else {
	      if (buttonGroup.checked) { return buttonGroup; } // if the one button is checked, return zero
	   }
	   // if we get to this point, no radio button is selected
	   return null;
	} // Ends the "getSelectedRadio" function

	// =====================================================================================
	// Checks the value of a condition rule (AND / OR) and returns the string value
	// =====================================================================================
	function GetRuleCondition(ruleNum) {
		eval("var conditionButton = document.SearchForm.SearchCondition"+(ruleNum)+";");
		var selected = GetSelectedRadio(conditionButton);
		if (selected == null)
			return null;
		else
			return selected.value;
	}

	function GetRuleContent(ruleNum) {
		// Get TD above rule
		var tdObj = document.getElementById("SearchContent"+ruleNum);

		// Now grab the object
		return tdObj.childNodes.item(0);
	}

	function GetInputValue(contentObj) {
		var value = "";
		if (contentObj.type == "select-multiple") {
			// Let's get the values
			var options = contentObj.options;
			for (i=0; i<options.length; i++) {
				if (options[i].selected) {
					if (value != "")
						value += " OR ";
					value += '"'+options[i].value+'"';
				}
			}
		}	
		else {
			if (contentObj.value != "")
				value = '"'+contentObj.value+'"';
		}
		
		return value;
	}

	function SearchEnableRule(ruleNum, disable) {
		var contentObj = GetRuleContent(ruleNum);

		// Expand the box for multi-select boxes
		if (contentObj.type == "select-multiple") {
//			contentObj.size = 3;
		}
		
		// Enable content
		contentObj.disabled = false;
		
		// Enable condition after
		eval("var conditionButton = document.SearchForm.SearchCondition"+(ruleNum)+";");
		if (conditionButton != null) {
			for (condCnt=0; condCnt<conditionButton.length; condCnt++) {
				conditionButton[condCnt].disabled = disable;
			}
		}		
	}

	function SearchDisableRule(ruleNum) {
		var contentObj = GetRuleContent(ruleNum);
		// Minimize multi-select boxes when they aren't selected		
		if (contentObj.type == "select-multiple") {
//			contentObj.size = 1;
		}
		
		// Disable content 
		contentObj.disabled = true;

		// Disable condition after
		eval("var conditionButton = document.SearchForm.SearchCondition"+(ruleNum)+";");
		if (conditionButton != null) {
			for (condCnt=0; condCnt<conditionButton.length; condCnt++) {
				conditionButton[condCnt].disabled = true;
			}
		}		
	}

	function SearchCopyClipboard() {
		var termBox = document.getElementById("term");
		var copied = termBox.createTextRange();
		copied.execCommand("Copy");
		alert("Copied!");
	}

   	// hide script from old browsers
   	function popup (loc, winName, winDim) {
     		myWindow = window.open(loc,winName,winDim);
   	}
        function submitGeneDecks(formid) {
          var form = window.document.getElementById(formid); 
          var info = '';
		  var symbol= form.symbol.value;
		  var section = form.section.value;
          boxes = form.gd_box.length;
          for (i=0; i<boxes; i++) {
            if (form.gd_box[i]) {
             if (form.gd_box[i].checked) {
                if (info != '') {
                   info += '%';
                }
                info += form.gd_box[i].value;
             }
            }
          }
          if (info == '') {
               if (form.gd_box) {
                 if (form.gd_box.checked) {
                   info += form.gd_box.value;
                 }
               }
          }
          if (info == '') {
               alert ( "Please select at least one." );
               return false;
          }
          window.location = baseVersion2+"/cgi-bin/GeneDecks/GDdisplay.pl?symbol="+symbol+"&section="+section+"&info="+info.urlencode();
		  return false;
         // form.info.value = info;
         // form.submit();
        }

        function submitQuery() {
          var searchParams = '';
          var url = "$URL_PUBMED_SEARCH";
          if(document.pubmedSearch.gene) {  
            if(document.pubmedSearch.gene.checked) {
               searchParams = document.pubmedSearch.gene.value;
            }
            var aliases = document.getElementById(aliases);
            var i;
            var search_aliases = '';
            if (document.pubmedSearch.alias_mult) {
              for (i=1; i<document.pubmedSearch.alias_mult.options.length; i++) {
                 if (document.pubmedSearch.alias_mult.options[i].selected) {
                     if (search_aliases == '') {
                       search_aliases = document.pubmedSearch.alias_mult.options[i].value;
                     }else{
                       search_aliases += ' or ';
                       search_aliases +=  document.pubmedSearch.alias_mult.options[i].value;
                     }
                 }
              }
            }
            else {
              if (document.pubmedSearch.alias_one) {
                 //if (!document.pubmedSearch.alias_one.selectedIndex == 0)
                 if(document.pubmedSearch.alias_one.checked) {
                    if (search_aliases == '') {
                         search_aliases = document.pubmedSearch.alias_one.value;
                    }else{
                      search_aliases += ' or ';
                      search_aliases +=  document.pubmedSearch.alias_one.value;
                    }
                 }
              }
            }
            if (search_aliases) {
               if (searchParams == '') {
                   searchParams = search_aliases;
               }
               else{
                   var choice = -1;
                   var i;
                   var andor;
                   choice = document.pubmedSearch.boolean1.selectedIndex
                   andor = document.pubmedSearch.boolean1[choice].value
                   searchParams += " " + andor + " " + "(" + search_aliases + ")";
               }
             }
             if (document.pubmedSearch.query_check) {
               if (document.pubmedSearch.query_check.checked) {
                if (document.pubmedSearch.query.value != '') {
                 if (searchParams == '') {
                   searchParams = document.pubmedSearch.query.value;
                 }
                 else {
                   var choice = -1;
                   var i;
                   var andor;
                   if(search_aliases) {
                      choice = document.pubmedSearch.boolean2.selectedIndex
                      andor = document.pubmedSearch.boolean2[choice].value
                      searchParams += " " + andor + " " + "(" + document.pubmedSearch.query.value + ")";
                   }
                   else{
                      choice = document.pubmedSearch.boolean1.selectedIndex
                      andor = document.pubmedSearch.boolean1[choice].value
                      searchParams += " " + andor + " " + "(" + document.pubmedSearch.query.value + ")";
                   }
                 }
                }
              }
            }
            if (searchParams == '') {
               alert ( "Please select at least one search term." );
               return false;
            }
            document.pubmedSearch.action = url + "&term=" + searchParams
            doFocus('aaa');
          }
        }


   	var winInst=null;
   	var jumpSectionInChange = false;
   	
   	// Function for drop down menu navigation
   	function JumpSection(selId)	{
		// If we're in onChange (due to our own resetting of the jump location), ignore and exit.
		if (jumpSectionInChange) return;
	
		var mySel = document.getElementById(selId);
		var myVal = mySel.options[mySel.selectedIndex].value;
		window.location = myVal;
		
		// Notify ourselves not to change for the next event coming (see above)
		jumpSectionInChange = true;
		mySel.options[0].selected=true;
		jumpSectionInChange = false;
	}
	    function doFocus(target) {
//  	alert('in doFocus');
    windowHandle = window.open('', target);
    setTimeout('windowHandle.focus();', 3000);
}

function doFocusHref(target,href){
	windowHandle = window.open(href, target);
    setTimeout('windowHandle.focus();', 3000);
	return false;
}


   	

