/* Opens popup window  */
function opener(page)
{
  window.open(page, "popup", "location=no,menubar=no,resizable=no,width=550,height=580,scrollbars=yes");
}

/* Opens popup window */
function NewWindow(mypage, myname, w, h, scroll) 
{
  var winl = (screen.width - w) / 2;
  var wint = (screen.height - h) / 2;
  winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
  win = window.open(mypage, myname, winprops)
  if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

/* Even 'column' script
Derived from a script by Alejandro Gervasio. 
Modified to work in FireFox by Stefan Mischook for Killersites.com
Modified by Erica Melton to work in WST
How it works: just apply the CSS class of 'column' to your pages' main columns.
Add "matchColumns();" to body onload.
*/
function matchColumns()
{ 
  var divs,contDivs,maxHeight,divHeight,d; 
	
  // get all <div> elements in the document 
  divs=document.getElementsByTagName('div'); 
  contDivs=[]; 

  // initialize maximum height value 
  maxHeight=0; 

  // iterate over all <div> elements in the document 
  for(var i=0;i<divs.length;i++){ 
    // make collection with <div> elements with class attribute 'container' 
    if(/\bcolumn\b/.test(divs[i].className))
	  { 
      d=divs[i]; 
      contDivs[contDivs.length]=d; 
		
      // determine height for <div> element 
      if(d.offsetHeight)
	    { divHeight=d.offsetHeight;}
      else if(d.style.pixelHeight)
	    { divHeight=d.style.pixelHeight;} 

      // calculate maximum height 
      maxHeight=Math.max(maxHeight,divHeight); 
      } 
    } 

    // assign maximum height value to all of container <div> elements 

    for(var i=0;i<contDivs.length;i++)
	{ contDivs[i].style.height=maxHeight + "px"; } 	
} 

/* AJAX FUNCTION */
function ajaxFunction(url,divid)
  {
  var xmlHttp;
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      try
        {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
      catch (e)
        {
        alert("Your browser does not support AJAX!");
        return false;
        }
      }
    }
    xmlHttp.onreadystatechange=function()
      {
      if(xmlHttp.readyState==4)
        {
        document.getElementById(divid).innerHTML = xmlHttp.responseText;
        }
      }
    xmlHttp.open("GET",encodeURI(url),true);
    xmlHttp.send(null);
  }
  
function getKeywordList()
{
   document.getElementById("keywordlist").style.display = "block";
var vSearchTxt = document.getElementById("keywordSearch").value;
vSearchTxt = vSearchTxt.replace("'","");
if (vSearchTxt.length > 0)
  {
  ajaxFunction("ajax.asp?type=keywordsearch&searchtext="+ vSearchTxt +"", "keywordlist");
  }
}
function FillKeywordValues(keywordMatch)
{
    document.getElementById("keywordSearch").value = keywordMatch;
}
function getAuthorList()
{
   document.getElementById("authorlist").style.display = "block";
var vSearchTxt = document.getElementById("authorSearch").value;
vSearchTxt = vSearchTxt.replace("'","");
if (vSearchTxt.length > 0)
  {
  ajaxFunction("ajax.asp?type=authorsearch&searchtext="+ vSearchTxt +"", "authorlist");
  }
}
function FillAuthorValues(authorMatch)
{   
    document.getElementById("authorSearch").value = authorMatch;
}



/* 
 * Cross-browser event handling, by Scott Andrew
 */
function addEvent(element, eventType, lamdaFunction, useCapture) {
    if (element.addEventListener) {
        element.addEventListener(eventType, lamdaFunction, useCapture);
        return true;
    } else if (element.attachEvent) {
        var r = element.attachEvent('on' + eventType, lamdaFunction);
        return r;
    } else {
        return false;
    }
}

/*
 * Clear Default Text: functions for clearing and replacing default text in
 * <input> elements.
 *
 * by Ross Shannon, http://www.yourhtmlsource.com/
 */

addEvent(window, 'load', init, false);

function init() {
    var formInputs = document.getElementsByTagName('input');
    for (var i = 0; i < formInputs.length; i++) {
        var theInput = formInputs[i];
        
        if (theInput.type == 'text' && theInput.className.match(/\bcleardefault\b/)) {  
            /* Add event handlers */          
            addEvent(theInput, 'focus', clearDefaultText, false);
            addEvent(theInput, 'blur', replaceDefaultText, false);
            
            /* Save the current value */
            if (theInput.value != '') {
                theInput.defaultText = theInput.value;
            }
        }
    }
}

function clearDefaultText(e) {
    var target = window.event ? window.event.srcElement : e ? e.target : null;
    if (!target) return;
    
    if (target.value == target.defaultText) {
        target.value = '';
    }
}

function replaceDefaultText(e) {
    var target = window.event ? window.event.srcElement : e ? e.target : null;
    if (!target) return;
    
    if (target.value == '' && target.defaultText) {
        target.value = target.defaultText;
    }
}


//manipulate the tabs on the home page. 3-19-09:jrp
function mamiTabs (vWhich) {
//hide both and primary
	if (vWhich == 1) { 
		document.getElementById("celllineImage").style.display = "none";
		document.getElementById("culturesImage").style.display = "block";
		//make itself usable
		document.getElementById("mami_tab_Cell_Line").style.color = '#000';		
		document.getElementById("MAMI_overlayBG_cellline").style.opacity = 1;
	  document.getElementById("MAMI_overlayBG_cellline").style.filter = 'alpha(opacity=100)';
		document.getElementById("mami_tab_Cell_Line").style.opacity = 1;
	  document.getElementById("mami_tab_Cell_Line").style.filter = 'alpha(opacity=100)';
		//make others un-usable		
		document.getElementById("mami_tab_Both").style.color = '#000';
        document.getElementById("mami_tab_Primary").style.color = '#000';		
		document.getElementById("MAMI_overlayBG_primary").style.opacity = .35;
	  document.getElementById("MAMI_overlayBG_primary").style.filter = 'alpha(opacity=35)';		
		document.getElementById("mami_tab_Both").style.opacity = .35;
	  document.getElementById("mami_tab_Both").style.filter = 'alpha(opacity=35)';			

		document.getElementById("mami_tab_Primary").style.opacity = .35;
	  document.getElementById("mami_tab_Primary").style.filter = 'alpha(opacity=35)';			
		
		document.getElementById("filterPrimaryMOS").value = 0;
		}
	if (vWhich == 2) { 
		document.getElementById("celllineImage").style.display = "block";
		document.getElementById("culturesImage").style.display = "none";
		//make itself usable
		document.getElementById("mami_tab_Both").style.color = '#000';		
		document.getElementById("mami_tab_Both").style.opacity = 1;
	  document.getElementById("mami_tab_Both").style.filter = 'alpha(opacity=100)';	
		document.getElementById("MAMI_overlayBG_primary").style.opacity = 1;
	  document.getElementById("MAMI_overlayBG_primary").style.filter = 'alpha(opacity=100)';				
		//make others un-usable
		document.getElementById("mami_tab_Cell_Line").style.color = '#000';
		document.getElementById("mami_tab_Primary").style.color = '#000';
		document.getElementById("MAMI_overlayBG_cellline").style.opacity = .35;
	  document.getElementById("MAMI_overlayBG_cellline").style.filter = 'alpha(opacity=35)';		
		document.getElementById("mami_tab_Cell_Line").style.opacity = .35;
	  document.getElementById("mami_tab_Cell_Line").style.filter = 'alpha(opacity=35)';		
		document.getElementById("mami_tab_Primary").style.opacity = .35;
	  document.getElementById("mami_tab_Primary").style.filter = 'alpha(opacity=35)';	

		document.getElementById("filterPrimaryMOS").value = 0;
		
		}
	if (vWhich == 3) { 
		document.getElementById("celllineImage").style.display = "block";
		document.getElementById("culturesImage").style.display = "none";
		//make itself usable
		document.getElementById("mami_tab_Primary").style.color = '#000';		
		document.getElementById("mami_tab_Primary").style.opacity = 1;
	  document.getElementById("mami_tab_Primary").style.filter = 'alpha(opacity=100)';	
		document.getElementById("MAMI_overlayBG_primary").style.opacity = 1;
	  document.getElementById("MAMI_overlayBG_primary").style.filter = 'alpha(opacity=100)';			
		//make others un-usable
		document.getElementById("mami_tab_Cell_Line").style.color = '#000';
		document.getElementById("mami_tab_Both").style.color = '#000';		
		document.getElementById("MAMI_overlayBG_cellline").style.opacity = .35;
	  document.getElementById("MAMI_overlayBG_cellline").style.filter = 'alpha(opacity=35)';		
		document.getElementById("mami_tab_Cell_Line").style.opacity = .35;
	  document.getElementById("mami_tab_Cell_Line").style.filter = 'alpha(opacity=35)';		
		document.getElementById("mami_tab_Both").style.opacity = .35;
	  document.getElementById("mami_tab_Both").style.filter = 'alpha(opacity=35)';	
		
		document.getElementById("filterPrimaryMOS").value = 1;

		}
	
	
	
// turn on the tab just clicked...
//	   document.getElementById("keywordlist").style.display = "block";
// turn off the other two...		 
//	   document.getElementById("keywordlist").style.display = "block";
// 	   document.getElementById("keywordlist").style.display = "block"; 

}

//manipulate the tabs on the home page. 11-02-09:jrp
function mamiTabsAlert (vWhich) {
//hide both and primary
	if (vWhich == 1) { 
		document.getElementById("celllineImage").style.display = "none";
		document.getElementById("culturesImage").style.display = "block";
		document.getElementById("mami_tab_Cell_Line").style.cursor = "pointer";
		//make itself usable
		document.getElementById("mami_tab_Cell_Line").style.opacity = 1;
	  document.getElementById("mami_tab_Cell_Line").style.filter = 'alpha(opacity=100)';
		//make others un-usable		
		document.getElementById("mami_tab_Both").style.opacity = .35;
	  document.getElementById("mami_tab_Both").style.filter = 'alpha(opacity=35)';			
		document.getElementById("mami_tab_Primary").style.opacity = .35;
	  document.getElementById("mami_tab_Primary").style.filter = 'alpha(opacity=35)';			
		
		//document.getElementById("filterPrimaryMOS").value = 0;
		}
	if (vWhich == 2) { 
		document.getElementById("celllineImage").style.display = "block";
		document.getElementById("culturesImage").style.display = "none";
		document.getElementById("mami_tab_Both").style.cursor = "pointer";
		//make itself usable
		document.getElementById("mami_tab_Both").style.opacity = 1;
	  document.getElementById("mami_tab_Both").style.filter = 'alpha(opacity=100)';	
		//make others un-usable
		document.getElementById("mami_tab_Cell_Line").style.opacity = .35;
	  document.getElementById("mami_tab_Cell_Line").style.filter = 'alpha(opacity=35)';		
		document.getElementById("mami_tab_Primary").style.opacity = .35;
	  document.getElementById("mami_tab_Primary").style.filter = 'alpha(opacity=35)';	

		//document.getElementById("filterPrimaryMOS").value = 0;
		}
	if (vWhich == 3) { 
		document.getElementById("celllineImage").style.display = "block";
		document.getElementById("culturesImage").style.display = "none";
		document.getElementById("mami_tab_Primary").style.cursor = "pointer";		
		//make itself usable
		document.getElementById("mami_tab_Primary").style.opacity = 1;
	  document.getElementById("mami_tab_Primary").style.filter = 'alpha(opacity=100)';			
		//make others un-usable
		document.getElementById("mami_tab_Cell_Line").style.opacity = .35;
	  document.getElementById("mami_tab_Cell_Line").style.filter = 'alpha(opacity=35)';		
		document.getElementById("mami_tab_Both").style.opacity = .35;
	  document.getElementById("mami_tab_Both").style.filter = 'alpha(opacity=35)';	
			
		//document.getElementById("filterPrimaryMOS").value = 1;
		}
}

/*
 * This is the function that actually highlights a text string by
 * adding HTML tags before and after all occurrences of the search
 * term. You can pass your own tags if you'd like, or if the
 * highlightStartTag or highlightEndTag parameters are omitted or
 * are empty strings then the default <font> tags will be used.
 */
function doHighlight(bodyText, searchTerm, highlightStartTag, highlightEndTag) 
{
  // the highlightStartTag and highlightEndTag parameters are optional
  if ((!highlightStartTag) || (!highlightEndTag)) {
    highlightStartTag = "<font style='color:blue; background-color:yellow;'>";
    highlightEndTag = "</font>";
  }
  
  // find all occurences of the search term in the given text,
  // and add some "highlight" tags to them (we're not using a
  // regular expression search, because we want to filter out
  // matches that occur within HTML tags and script blocks, so
  // we have to do a little extra validation)
  var newText = "";
  var i = -1;
  var lcSearchTerm = searchTerm.toLowerCase();
  var lcBodyText = bodyText.toLowerCase();
    
  while (bodyText.length > 0) {
    i = lcBodyText.indexOf(lcSearchTerm, i+1);

    if (i < 0) {
      newText += bodyText;
      bodyText = "";
    } else {

      // skip anything inside an HTML tag
      if (bodyText.lastIndexOf(">", i) >= bodyText.lastIndexOf("<", i)) {
        // skip anything inside a <script> block
        if (lcBodyText.lastIndexOf("/script>", i) >= lcBodyText.lastIndexOf("<script", i)) {
          newText += bodyText.substring(0, i) + highlightStartTag + bodyText.substr(i, searchTerm.length) + highlightEndTag;
          bodyText = bodyText.substr(i + searchTerm.length);
          lcBodyText = bodyText.toLowerCase();
				
          i = -1;
        }
      }
    }

  }
  
  return newText;
}


/*
 * This is sort of a wrapper function to the doHighlight function.
 * It takes the searchText that you pass, optionally splits it into
 * separate words, and transforms the text on the current web page.
 * Only the "searchText" parameter is required; all other parameters
 * are optional and can be omitted.
 */
function highlightSearchTerms(searchText, treatAsPhrase, warnOnFailure, highlightStartTag, highlightEndTag)
{
  // if the treatAsPhrase parameter is true, then we should search for 
  // the entire phrase that was entered; otherwise, we will split the
  // search string so that each word is searched for and highlighted
  // individually
//  if (treatAsPhrase) {
//    searchArray = [searchText];
//  } else {
 	var searchText = document.getElementById("formObjects").innerHTML;

    searchArray = searchText.split(",");
		
//alert(searchArray);
//  }
  
//  if (!document.body || typeof(document.body.innerHTML) == "undefined") {
//    if (warnOnFailure) {
//      alert("Sorry, for some reason the text of this page is unavailable. Searching will not work.");
//    }
//    return false;
//  }
  
//  var bodyText = document.body.innerHTML;
var bodyText = document.getElementById("articleText").innerHTML;

  for (var i = 0; i < searchArray.length; i++) {

    bodyText = doHighlight(bodyText, searchArray[i], highlightStartTag, highlightEndTag);
	}

  
	document.getElementById("articleText").innerHTML = bodyText;
	document.getElementById("enhanceArticle").value = "done";

  return true;
}

