var cartCount = 0;
var show = "visible";
var hide = "hidden";
var n_max_search_history_items = 6;
var arr_hxcursor = new Array();
var arr_curhx = new Array();
var arr_search_history = new Array();
var arr_cur_history_item = new Array();
var arr_selected_search_result_item = new Array();

var sBrowser = navigator.appName;
var nVersion = navigator.appVersion;
var sAgent = navigator.userAgent;
var bisIE = false;
var bisNav = false;
var isff = 0;
var issaf = 0;

if (sBrowser == "Microsoft Internet Explorer") {
	bisIE = true;
	if (nVersion.indexOf ("MSIE 7") != -1) { sBrowser = "ie"; nVersion = "7"; }
	else if (nVersion.indexOf ("MSIE 6") != -1) { sBrowser = "ie"; nVersion = "6"; }
	else { 
		sBrowser = "ie";
		nVersion = "0";
	}
} else if (nVersion.indexOf ("Safari/3") != -1) {
	issaf = 3;
} else if (nVersion.indexOf ("Safari/2") != -1) {
	issaf = 2;
} else if (nVersion.indexOf ("Safari") != -1) {
	issaf = 1;
} else if (sAgent.indexOf ("Firefox/1") != -1) {
	isff = 1;
} else if (sAgent.indexOf ("Firefox/2") != -1) {
	isff = 2;
} else if (sAgent.indexOf ("Firefox/3") != -1) {
	isff3 = 3;
} else if (sBrowser == "Netscape") {
	isNav = true;
	if (parseInt(nVersion) != 5) {
		show = "show";
		hide = "hide";
	}
}

function hideListPanel() {
	$("shoppingListDiv").style.display = "none";
	$("mainFrame").style.width = "948px";
}
function showListPanel(panelName) {
	$("shoppingListDiv").style.display = "inline";
	$("mainFrame").style.width = "727px";
	try{ listPanel.show_list(panelName); } catch(e) { }
}

function loadXMLText(xmlText) 
{
	var xmlDoc;
	try //Internet Explorer
	  {
		  xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		  xmlDoc.async="false";
		  xmlDoc.loadXML(xmlText);
	  }
	catch(e)
	  {
		  try //Firefox, Mozilla, Opera, etc.
		  {
			  parser = new DOMParser();
			  xmlDoc = parser.parseFromString(xmlText,"text/xml");
		  }
		  catch(e)
		  {
			return;
		  }
	}
	return xmlDoc;
}

function cartOrderNow(params) {
	var activeApp, activeWF;
	activeApp = Nav.activeApplication;
	activeWF = Nav.applications[activeApp].activeWorkflow;

	if(Nav.applications[activeApp].workflows[activeWF].order) {
		Nav.applications[activeApp].workflows[activeWF].order.enable();
		Nav.applications[activeApp].workflows[activeWF].order.click();
	}
}

function updatePartNumber(prodList, prod, elemID) {
	var partNumArr = $(elemID).value.split("|");
	var sizeTextArray = $(elemID).options[$(elemID).selectedIndex].text.split(':');
	var newPartNum = partNumArr[0];
	//var newTextSize = partNumArr[1];
	var newSize = partNumArr[1];
	var newSizeText = sizeTextArray[1];
	var prod_index = -1;
	var new_prod_index = -1;
	var list;
	var newProd;
	if(list = listPanel.list_by_name(prodList)) {
		prod_index = list.product_exists(prod);
		if(prod_index > -1) {
			//newProd = { cat: prod.get('cat'), subcat: prod.get('subcat'), text: prod.get('prodID') + ', ' + newTextSize, partNumber: newPartNum, size: newTextSize };
			newProd = { prodID: prod.get('prodID'), cat: prod.get('cat'), subcat: prod.get('subcat'), text: prod.get('prodID') + ', ' + newSizeText, partNumber: newPartNum, size: newSize };
			new_prod_index = list.partNumber_exists(newProd);
			if(new_prod_index > -1) {
				list.products[new_prod_index].set('qty', list.products[new_prod_index].get('qty') + prod.get('qty'));
				list.remove_product(prod_index);
			} else {
				list.products[prod_index].set('partNumber', newPartNum);
				list.products[prod_index].set('size', newSize);
				list.products[prod_index].set('sizeText', newSize);
				list.products[prod_index].set('text', newProd.get('text'));
				list._persist_contents();
				list._draw();
			}
			refreshOrderPage();
		}
	}
}

function updateProductQty(prodList, prod, elemID) {
	var newQty = Number($(elemID).value);
	var prod_index = -1;
	var list;
	if(list = listPanel.list_by_name(prodList)) {
		prod_index = list.product_exists(prod);
		if(prod_index > -1) {
			if(newQty > 0) {
				list.products[prod_index].set('qty', newQty);
				list._persist_contents();
				list._draw();
			} else {
				list.remove_product(prod_index);
			}
			refreshOrderPage();
		}
	}
}

function refreshOrderPage() {
	var activeApp, activeWF;
	activeApp = Nav.activeApplication;
	activeWF = Nav.applications[activeApp].activeWorkflow;
	if(Nav.applications[activeApp].workflows[activeWF].order) {
		Nav.applications[activeApp].workflows[activeWF].order.clickDisabled();
	}
}

function sendCartToBasket(msg) {
    // Check for submit error messages. Alert message if present
    var msg='';
    try { msg = $('submitErrorMessage').value; } catch (e) { }
    if (msg !='') {
        alert(msg);
        return;
    }

	if(cartCount > 0) {
		//clear shoppingList session data
		listPanel.shoppingList._force_clear_list();

		//submit form to url gateway
		$("allBasketForm").submit();
	} else {
		alert("You have no items in your list");
	}
}

function toggleList(h){
    //$('topMenu').style.visibility=h;
    $('listpanel_div_list_shoppingList').style.visibility=h;
}

function navigate_from_pipe_delim(str) {
	var returnVal = "";
	var navArray = str.split('|');
	if(navArray.length == 3) {
		try
		{
			eval("Nav." + navArray[0] + "." + navArray[1] + "." + navArray[2] + ".clickDisabled()");
		}
		catch (e)
		{

		}
	}
}

/*** added DL on 11/20/08 for dynamic drop down options***/
	function clearSelect(src)  {
		//clear options in dropdown for element
		while (src.length > 0)  {
			src.remove(0);
		}
	return;
	}

	function addOption(src, sOpt, sVal) {
		var oOption = document.createElement("OPTION");
		oOption.text = sOpt;
		oOption.value = sVal;
		if (bisIE)
		{
			src.add(oOption);
		} else {
			src.appendChild(oOption);
		}		
	}
/*** end DL added 11/20/08 ***/

/*** added DL on 11/24/08 for search history and util functions ***/

	if (document.layers) {
		show = "show";
		hide = "hide";
	}

	function inf(h){
		tag=document.getElementsByTagName('select');
		for(i=tag.length-1;i>=0;i--)
			tag[i].style.visibility=h;
		tag=document.getElementsByTagName('iframe');
		for(i=tag.length-1;i>=0;i--)
			tag[i].style.visibility=h;
		tag=document.getElementsByTagName('object');
		for(i=tag.length-1;i>=0;i--) {
			if (tag[i].id != 'progmovie') {
				tag[i].style.visibility=h;
			}
		}
		tag=document.getElementsByTagName('shoppingList');
		for(i=tag.length-1;i>=0;i--)
			tag[i].style.visibility=h;
	}

	function hideprogress() {
		inf(show);
		document.getElementById('progress').style.display = 'none';
		document.getElementById('progText').style.display = 'none';
		}

	function showprogress(p) {
		inf(hide);
		var dom_prog = document.getElementById('progmsg');
		if (!dom_prog) {
			return;
		}
		if (p==1) {
			document.getElementById('progmsg').innerHTML = "One moment please, Searching ...";
		} else if (p==2) {
			document.getElementById('progmsg').innerHTML = "One moment please, Updating ...";
		} else if (p==3) {
			document.getElementById('progmsg').innerHTML = "One moment please, Writing ...";
		} else if (p==4) {
			document.getElementById('progmsg').innerHTML = "One moment please, Reading ...";
		} else {
			document.getElementById('progmsg').innerHTML = "One moment please, Loading ...";
		}
		if (document.getElementById('progress').style.display != 'block') {
			document.getElementById('progress').style.display = 'block';
			document.getElementById('progText').style.display = 'block';
		}
		return;
	}

	function checkSearchTerm(txtTerm, buttonElem) {
		if (txtTerm.value != '') {
			$(buttonElem).className = "buttonOrangeMed floatLeft";
		} else {
			$(buttonElem).className = "buttonOrangeMedDisabled floatLeft";
		}
	}

	function checkChromFields(txtStart, txtStop, buttonElem) {
		if (txtStart.value != '' && txtStop.value != '') {
			$(buttonElem).className = "buttonOrangeMed floatLeft";
		} else {
			$(buttonElem).className = "buttonOrangeMedDisabled floatLeft";
		}
		return true;
	}

	function checkDateFields(txtDateStart, txtDateEnd, buttonElem) {
		if (txtDateStart && txtDateEnd && txtDateStart.value != '' && txtDateEnd.value != '') {
			$(buttonElem).className = "buttonOrangeMed floatLeft";
		} else if (txtDateStart && !txtDateEnd && txtDateStart.value != '') {
			$(buttonElem).className = "buttonOrangeMed floatLeft";
		} else if (txtDateEnd && !txtDateStart && txtDateEnd.value != '') {
			$(buttonElem).className = "buttonOrangeMed floatLeft";
		} else {
			$(buttonElem).className = "buttonOrangeMedDisabled floatLeft";
		}
	}

	function checkNumericOnlyField(event) {
		//Allow only numeric input into field.
		//Exceptions: Tab, Enter, Backspace.
		if (event.keyCode != 8 && event.keyCode != 9 && event.keyCode != 46 && ((event.shiftKey && event.keyCode > 47)  || event.keyCode <48 || event.keyCode >57))  return false;
		return true;
	}

	function checkAlphaOnlyField(event) {
		//Allow only Alpha input into field.
		//Exceptions: Tab, Enter, Backspace.
		if (event.keyCode != 8 && event.keyCode != 9 && event.keyCode != 46 && (((event.shiftKey && event.keyCode > 47) && (event.shiftKey && event.keycode < 58))  || (event.keyCode >= 48 && event.keyCode <= 57)))  return false;
		return true;
	}

	function buildFormPostData(oForm)  {
		//DL - helper function
		var aParams = new Array(0);
		var sParam = '';
		for (var i=0 ; i < oForm.elements.length; i++) {
			if (oForm.elements[i].type == 'radio' || oForm.elements[i].type == 'checkbox') {
				if (oForm.elements[i].checked) {
					sParam = encodeURIComponent(oForm.elements[i].name);
					sParam += "=";
					sParam += encodeURIComponent(oForm.elements[i].value);
					aParams.push(sParam);
				}
			} else {
				sParam = encodeURIComponent(oForm.elements[i].name);
				sParam += "=";
				sParam += encodeURIComponent(oForm.elements[i].value);
				aParams.push(sParam);
			}
		}
		return aParams.join("&");
	}

	function buildFormHashData(oForm) {
		//DL - helper function
		var formElems = $H();
		var sParam, sValue;

		formElems.set('form_id', oForm.id);
		for (var i=0 ; i < oForm.elements.length; i++)
		{
			if (oForm.elements[i].type == 'radio' || oForm.elements[i].type == 'checkbox') {
				if (oForm.elements[i].checked) {
					sParam = encodeURIComponent(oForm.elements[i].id);
					sValue = encodeURIComponent(oForm.elements[i].value);
					formElems.set(sParam, sValue);
				}
			} else {
				sParam = encodeURIComponent(oForm.elements[i].id);
				sValue = encodeURIComponent(oForm.elements[i].value);
				formElems.set(sParam, sValue);
			}
		}
		return formElems;
	}

	function isUniqueSearchHistory(srcContainerID, item) {
		//see if item already exists in the history list.
		if (item == '') {
			return false;
		}
		for (var i=0;i<arr_hxcursor[srcContainerID];i++) {
			if (arr_search_history[srcContainerID][i][2]==item) {
				return i;
			}
		}
		return -1;
	}

	function searchHistory_Pop(srcContainerID) {
		for (var i=0;i<arr_hxcursor[srcContainerID]-1;i++) {
			arr_search_history[srcContainerID][i][0] = arr_search_history[srcContainerID][i + 1][0];
			arr_search_history[srcContainerID][i][1] = arr_search_history[srcContainerID][i + 1][1];
			arr_search_history[srcContainerID][i][2] = arr_search_history[srcContainerID][i + 1][2];
			arr_search_history[srcContainerID][i][3] = arr_search_history[srcContainerID][i + 1][3];
			arr_search_history[srcContainerID][i][4] = arr_search_history[srcContainerID][i + 1][4];
		}
		arr_hxcursor[srcContainerID]--;
		return;
	}

	function getSearchTypeText(scText) {
		var s_cat = '';
		switch (scText) {
			case 'sirna_id':
				s_cat = 'siRNA ID';
				break;
			case 'gt_assay_id':
			case 'gex_assay_id':
			case 'assayID':
			case 'assay_id':
				s_cat = 'Assay ID';
				break;
			case 'legacy':
				s_cat = 'Legacy Assay ID';
				break;
			case 'gene_id':
				s_cat = 'Gene ID';
				break;
			case 'transcript_acc':
				s_cat = 'Accession Number';
				break;
			case 'omim_ids':
				s_cat = 'OMIM ID';
				break;
			case 'gene_name':
				s_cat = 'Gene Name';
				break;
			case 'gene_symbol':
				s_cat = 'Gene Symbol';
				break;
			case 'keyword':
				s_cat = 'Keyword';
				break;
			case 'rs_number':
				s_cat = 'rs Number';
				break;
			case 'cytoband':
				s_cat = 'Cytoband';
				break;
			case 'date':
				s_cat = 'Date Range';
				break;
			case 'salesorder':
				s_cat = 'Sales Order #';
				break;
			case 'assay_name':
				s_cat = 'Assay name';
				break;
		}
		return s_cat;
	}

	function getSearchCriteriaText(stText) {
		var criteria_text = '';
		switch(stText) {
			case 'contains':
				criteria_text = 'containing';
				break;
			case 'matches':
				criteria_text = 'matching';
				break;
			case 'begins':
				criteria_text = 'starting with';
				break;
			case 'ends':
				criteria_text = 'ending in';
				break;
			 case 'in':
				criteria_text = 'listed in';
				break;
			 case 'more':
				criteria_text = 'is greater than';
				break;
			case 'not':
				criteria_text = 'not matching';
				break;
			 case 'not contains':
				criteria_text = 'not containing';
				break;
			default:
				criteria_text = '';
		}
		return criteria_text;
	}

	function getSpeciesCommonName(species) {
		var str_species = species;
		if (species == 'Homo sapiens' || species == '9606') {
			str_species = 'Human';
		} else if (species == 'Mus musculus' || species == '10090') {
			str_species = 'Mouse';
		} else if (species == 'Rattus norvegicus' || species== '10116') {
			str_species = 'Rat';
		} else if (species == 'Macaca mulatta' || species== '9544') {
			str_species = 'Rhesus';
		} else if (species == 'Danio rerio' || species== '7955') {
			str_species = 'Zebrafish';
		} else if (species == 'Gallus gallus' || species== '9031') {
			str_species = 'Chicken';
		} else if (species == 'Sus scrofa' || species== '9823') {
			str_species = 'Pig';
		} else if (species == 'Arabidopsis thaliana' || species== '3702') {
			str_species = 'Thale cress';
		} else if (species == 'Drosophila melanogaster' || species== '7227') {
			str_species = 'Fruit fly';
		} else if (species == 'Caenorhabditis elegans' || species== '6239') {
			str_species = 'Nematode';
		} else if (species == 'Canis familiaris' || species== '9615') {
			str_species = 'Dog';
		} else if (species == 'Bos taurus' || species== '9913') {
			str_species = 'Cow';
		} else if (species == 'Oryctolagus cuniculus' || species== '9986') {
			str_species = 'Rabbit';
		} else if (species == 'all' || species == 'any') {
			str_species = 'all species';
		} else {
			str_species = 'unknown';
		}
		return str_species;
	}

	function getSpeciesScientificName(species) {
		var species_text = species;
		if (species == 'Human' || species == '9606') {
			species_text = 'Homo sapiens';
		} else if (species == 'Mouse' || species == '10090') {
			species_text = 'Mus musculus';
		} else if (species == 'Rat' || species== '10116') {
			species_text = 'Rattus norvegicus';
		} else if (species == 'Rhesus' || species== '9544') {
			species_text = 'Macaca mulatta';
		} else if (species == 'Zebrafish' || species== '7955') {
			species_text = 'Danio rerio';
		} else if (species == 'Chicken' || species== '9031') {
			species_text = 'Gallus gallus';
		} else if (species == 'Pig' || species== '9823') {
			species_text = 'Sus scrofa';
		} else if (species == 'Thale cress' || species== '3702') {
			species_text = 'Arabidopsis thaliana';
		} else if (species == 'Fruit fly' || species== '7227') {
			species_text = 'Drosophila melanogaster';
		} else if (species == 'Nematode' || species== '6239') {
			species_text = 'Caenorhabditis elegans';
		} else if (species == 'Dog' || species== '9615') {
			species_text = 'Canis familiaris';
		} else if (species == 'Cow' || species== '9913') {
			species_text = 'Bos taurus';
		} else if (species == 'Rabbit' || species== '9986') {
			species_text = 'Oryctolagus cuniculus';
		} else if (species == 'all' || species == 'any') {
			species_text = 'all species';
		} else {
			str_species = 'Unknown';
		}
		return species_text;
	}

	function saveSearchToHistory(searchFormID, srcContainerID, srcResultsID, srcSingleResultID, destCmd, type, numResults, srcMsgID) {
	   /**
	   * Desc: saves the current search parameters to a search history for recalling later.
	   * Created: dlu 11/24/08
	   * @INPUT Arguments:
	   * searchFormID = search form ID
	   * srcContainerID = ID of container which will display the list of history items on search page.
	   * srcResultsID = ID of div where initial search results are contained.
	   * srcSingleResultID = ID of div where single search results (assay details, gene details/product page) are contained.
	   * destCmd = javascript command or function call used to navigate from the current search page to the single results page (Select Assays).
	   * type = search type, i.e. chromosome, gene_id, gt_assay_id, etc. Probably can just indicate 'chromosome' or 'gene'.
	   * numResults = Number of search results returned by the search.
	   * srcMsgID = ID of span containing the search results descriptive text (e.g. 2 assays found for keyword matching 'bad'....).
	   *
	   * @RETURNS: Void.
	   */		
		var oForm = $(searchFormID);
		var newdiv = (srcResultsID != '') ? $(srcResultsID):'';
		var s_crit = '';
		var s_type = '';
		var searchType = '';
		var str_species='';
		var searchTerm = ''
		var s_hx = '';
		var chromo = '';
		var chromstart='';
		var chromend='';

		for (var i=0 ; i < oForm.elements.length; i++)	{
			if (oForm.elements[i].id.indexOf('search_type') != -1) {
				searchType = oForm.elements[i].value;
			} else if (oForm.elements[i].id.indexOf('search_node') != -1 || oForm.elements[i].id.indexOf('search_species') != -1) {
				str_species = oForm.elements[i].value;
			} else if (oForm.elements[i].id.indexOf('search_criteria') != -1) {
				s_crit = oForm.elements[i].value;
			} else if (oForm.elements[i].id.indexOf('search_term') != -1) {
				searchTerm = oForm.elements[i].value;
			} else if (oForm.elements[i].id.indexOf('search_chromosome') != -1) {
				chromo = oForm.elements[i].value;
			} else if (oForm.elements[i].id.indexOf('search_chromstart') != -1) {
				chromstart = oForm.elements[i].value;
			} else if (oForm.elements[i].id.indexOf('search_chromend') != -1) {
				chromend = oForm.elements[i].value;
			} else if (oForm.elements[i].id.indexOf('search_start_date') != -1) {
				str_start_date = oForm.elements[i].value;
			} else if (oForm.elements[i].id.indexOf('search_end_date') != -1) {
				str_end_date = oForm.elements[i].value;
			} else if (oForm.elements[i].id.indexOf('sales_order') != -1) {
				str_sales_order = oForm.elements[i].value;
			}
			
		}
		s_crit = getSearchCriteriaText(s_crit);
		s_type = getSearchTypeText(searchType);
		str_species = getSpeciesCommonName(str_species);

		if (searchTerm.length > 16) {
			searchTerm = searchTerm.slice(0,7) + '...';
		}

		if (type=='chromosome')	{
			searchTerm = 'Chr.' + chromo + ':' + chromstart + '-' + chromend;
			s_hx = 'Chromosome ' + chromo + ': from ' + chromstart + ' to ' + chromend + ' for ' + str_species;
		} else if (type.indexOf('assay_id') != -1 || type.indexOf('assayID') != -1 || type.indexOf('legacy') != -1 || type.indexOf('assay_name') != -1 || type.indexOf('salesorder') != -1) {
			s_hx = s_type + ' ' + s_crit + ' "' + searchTerm + '"';
		} else if (type.indexOf('date') != -1) {
			s_hx = s_type + ' from ' + str_start_date + ' to ' + str_end_date;
			searchTerm = str_start_date + ' to ' + str_end_date;
		} else if (type=='salesorder')	{
			searchTerm = 'Sales order # ' + str_sales_order;
			s_hx = s_type + ' ' + s_crit + ' "' + str_sales_order + '"';
		} else {
			s_hx = s_type + ' ' + s_crit + ' "' + searchTerm + '" for ' + str_species;
		}

		//Check to see if this one already exists first.
		var n_temp = isUniqueSearchHistory(srcContainerID, s_hx);
		if (n_temp != -1) {
			arr_cur_history_item[srcContainerID] = s_hx;
			arr_curhx[srcContainerID] = n_temp;
			displaySearchHistory(searchFormID, srcContainerID);
			return;
		}

		//initialize history array and cursor first if needed
		if (!arr_hxcursor[srcContainerID]) {
			//should only need to initialize once
			arr_hxcursor[srcContainerID] = 0;
			arr_curhx[srcContainerID] = 0;
			arr_search_history[srcContainerID] = new Array();
			arr_cur_history_item[srcContainerID] = '';
		}
		if (arr_hxcursor[srcContainerID] < n_max_search_history_items) {
			//should only need to initialize once
			arr_search_history[srcContainerID][arr_hxcursor[srcContainerID]] = new Array();
			arr_search_history[srcContainerID][arr_hxcursor[srcContainerID]][0] = '';		//history item text displayed on the search page, e.g. search term used for search.
			arr_search_history[srcContainerID][arr_hxcursor[srcContainerID]][1] = '';		//the innerHTML of search results container div
			arr_search_history[srcContainerID][arr_hxcursor[srcContainerID]][2] = '';		//text containing full search criteria, used as tooltip, and used to save as the current item for comparison purposes.
			arr_search_history[srcContainerID][arr_hxcursor[srcContainerID]][3] = $H({});	//hash object containing the search form element ids and their values.
			arr_search_history[srcContainerID][arr_hxcursor[srcContainerID]][4] = '';		//the ID of Search Results Div populated by a main search form.
			arr_search_history[srcContainerID][arr_hxcursor[srcContainerID]][5] = '';		//command to eval if needed, e.g. flip page to Select Assays.
			arr_search_history[srcContainerID][arr_hxcursor[srcContainerID]][6] = '';		//the ID of next page, such as the container Div in Select Assays page.
			arr_search_history[srcContainerID][arr_hxcursor[srcContainerID]][7] = '';		//the innerHTML of the single results container div, e.g. in Select Assays page.
			arr_search_history[srcContainerID][arr_hxcursor[srcContainerID]][8] = 0;		//number of search results.
			arr_search_history[srcContainerID][arr_hxcursor[srcContainerID]][9] = '';		//span id containing results display message.
		}

		if (arr_hxcursor[srcContainerID] == n_max_search_history_items) {
			searchHistory_Pop(srcContainerID);
		} else {
			//should only need to initialize once
			//arr_search_history[srcContainerID][arr_hxcursor[srcContainerID]] = new Array();
		}

		arr_search_history[srcContainerID][arr_hxcursor[srcContainerID]][0] = searchTerm;

		if (newdiv) {
			arr_search_history[srcContainerID][arr_hxcursor[srcContainerID]][1] = newdiv.innerHTML;
		} else {
			arr_search_history[srcContainerID][arr_hxcursor[srcContainerID]][1] = '';
		}

		//DL 6/29/09 - check to see if an error div exists and if it contains an error, and if so, get the contents of the error div  
		//and transfer over to the results div.  I used this method because it's rare and as a fix for existing custom assays search 
		//which has a separate error div. This way we don't have to store any error div IDs and its HTML in the search history object.
		var s_errDiv = "";
		if (srcResultsID.indexOf("_results_") != -1) {
			s_errDiv = srcResultsID.replace(/_results_/g, "_error_");
		} else if (srcResultsID.indexOf("_div") != -1) {
			s_errDiv = srcResultsID.replace(/_div/g, "_error_div");
		}
		if (s_errDiv != "" && $(s_errDiv) && $(s_errDiv).innerHTML != "") {
			arr_search_history[srcContainerID][arr_hxcursor[srcContainerID]][1] = $(s_errDiv).innerHTML + "<br><br>" + arr_search_history[srcContainerID][arr_hxcursor[srcContainerID]][1];
		}

		arr_search_history[srcContainerID][arr_hxcursor[srcContainerID]][2] = s_hx;
		arr_search_history[srcContainerID][arr_hxcursor[srcContainerID]][3] = buildFormHashData(oForm);
		arr_search_history[srcContainerID][arr_hxcursor[srcContainerID]][4] = srcResultsID;
		arr_search_history[srcContainerID][arr_hxcursor[srcContainerID]][5] = destCmd;
		arr_search_history[srcContainerID][arr_hxcursor[srcContainerID]][6] = srcSingleResultID;
		arr_search_history[srcContainerID][arr_hxcursor[srcContainerID]][7] = '';		//filled after it is created and displayed (Select Assays page).
		arr_search_history[srcContainerID][arr_hxcursor[srcContainerID]][8] = numResults;
		arr_search_history[srcContainerID][arr_hxcursor[srcContainerID]][9] = srcMsgID;

		arr_cur_history_item[srcContainerID] = s_hx;
		arr_curhx[srcContainerID] = arr_hxcursor[srcContainerID];
		arr_hxcursor[srcContainerID]++;
		if (arr_hxcursor[srcContainerID] > 0 && $(srcContainerID)) {
			displaySearchHistory(searchFormID, srcContainerID);
		}


	}

	function mouseOverSearchHistory(event) {
		var srcElem;
		if (window.event) {
			srcElem = window.event.srcElement;
		}
		else {
			srcElem = Event.element(event);
		}
		srcElem.className = "searchHistoryListHover";
	}

	function mouseOutSearchHistory(event, srcid) {
		var srcElem;
		if (window.event) {
			srcElem = window.event.srcElement;
		}
		else {
			srcElem = Event.element(event);
			id = element.id;
		}
		if (srcElem.title == arr_cur_history_item[srcid]) {
			srcElem.className = "searchHistoryListSelected";
		} else {
			srcElem.className = "searchHistoryList";
		}
		
	}

	function removeAllItemsFromHistory(srcHistoryID) {
		//remove recent search history items
		$(srcHistoryID).innerHTML = '';
		return;
	}

	function mouseClickSearchHistory(srcFormID, oSrcElem, srcContainerID) {
		//When history item is clicked and takes user to the saved results.
		//srcFormID - ID of the search form for retrieving and setting the values.
		//oSrcElem - the individual span object clicked.
		//srcContainerID - ID of history list container, used as Index for history array.

		var sdiv = '';
		var srcResultsID, destCmd, srcSingleResultID, srcSingleResultDiv, msgID;
		var i=0, recCount=0, rowCount = 0;
		var oSearchForm, oResultsElem;
		var savedFormElemsHash = $H({});
		var selected_val = oSrcElem.innerHTML;
		var selected_criteria = oSrcElem.title;

		for (i=0;i<arr_hxcursor[srcContainerID];i++) {
			if (arr_search_history[srcContainerID][i][0] == selected_val && arr_search_history[srcContainerID][i][2] == selected_criteria) {
				sdiv = arr_search_history[srcContainerID][i][1];										//search results div html
				arr_cur_history_item[srcContainerID] = arr_search_history[srcContainerID][i][2];		//search criteria string currently selected
				savedFormElemsHash = new Hash(arr_search_history[srcContainerID][i][3]);							//hash containing saved form values
				srcResultsID = arr_search_history[srcContainerID][i][4];								//ID of Search Results container div
				//retrieve command to eval if exists, and the container ID and content to fill with.
				destCmd = arr_search_history[srcContainerID][i][5];
				srcSingleResultID = arr_search_history[srcContainerID][i][6];
				srcSingleResultDiv = arr_search_history[srcContainerID][i][7];
				rowCount = parseInt(arr_search_history[srcContainerID][i][8]);
				msgID = arr_search_history[srcContainerID][i][9];
				arr_curhx[srcContainerID] = i;
				oSearchForm = $(savedFormElemsHash.get('form_id'));											//get the form we need to populate
			}
		}
		//populate the current form with the saved data
		if (oSearchForm) {
			var s_value;
			for (i=0 ; i < oSearchForm.elements.length; i++) {
				s_value = savedFormElemsHash.get(oSearchForm.elements[i].id);
				if (!s_value) {
					//must be radio or checkbox or text
					if (oSearchForm.elements[i].type == 'radio' || oSearchForm.elements[i].type == 'checkbox') {
						oSearchForm.elements[i].checked = false;
					} else if (oSearchForm.elements[i].type == 'text' || oSearchForm.elements[i].type == 'hidden' || oSearchForm.elements[i].type == 'textarea') {
						oSearchForm.elements[i].value = '';
					}
				} else {
					oSearchForm.elements[i].value = s_value;
					if (oSearchForm.elements[i].id.indexOf('search_type') != -1) {
						DOM_search_type = oSearchForm.elements[i];
					} else if (oSearchForm.elements[i].id.indexOf('search_criteria') != -1)	{
						s_search_criteria_id = oSearchForm.elements[i].id;
						//DL 6/29/09 - fix, because it must have all options present in order to set the value, and repopulate with the correct options, and then reset value back.
						clearSelect(oSearchForm.elements[i]);
						addOption(oSearchForm.elements[i], "Contains", "contains");
						addOption(oSearchForm.elements[i], "Matches", "matches");
						addOption(oSearchForm.elements[i], "Starts with", "begins");
						addOption(oSearchForm.elements[i], "Ends with", "ends");
						oSearchForm.elements[i].value = s_value;
					} else if (oSearchForm.elements[i].id.indexOf('_date') != -1) {
						//DL - fix problem with date display characters
						oSearchForm.elements[i].value = decodeURIComponent(s_value);
					}
				}
			} //end for

			//DL 6/29/09 - Check whether we are on Custom Search Form. If so, call different function for displaying/hiding appropriate fields.
			if (oSearchForm.id == 'frm_cadt_custom_reorder_search')	{
				cadt_custom_search_term_changed(false);
			} else {
				selcadtChangeSearchType(DOM_search_type, s_search_criteria_id, false);
			}
		}//end if 

		displaySearchHistory(srcFormID, srcContainerID);

		//DL 6/29/09 - check to see if an error div exists and if so, hide it because if this search had an error, the contents of the error div would 
		//have already been transferred over to the results div.  I used this method because it's rare and as a fix for existing custom assays search 
		//which has a separate error div. This way we don't have to store any error div IDs and its HTML in the search history object.
		var s_errDiv = "";
		if (srcResultsID.indexOf("_results_") != -1) {
			s_errDiv = srcResultsID.replace(/_results_/g, "_error_");
		} else if (srcResultsID.indexOf("_div") != -1) {
			s_errDiv = srcResultsID.replace(/_div/g, "_error_div");
		}
		if (s_errDiv != "" && $(s_errDiv)) {
			$(s_errDiv).hide();
		}

		if (srcResultsID != '' && sdiv != '') {
			//set the results page content
			oResultsElem = $(srcResultsID);
			oResultsElem.style.display = "block";
			if (oResultsElem) {
				oResultsElem.innerHTML = sdiv;
				if (msgID) {
					var s = "";
					if (rowCount > 1) {
						s = "s";
					}
					$(msgID).innerHTML = rowCount + " item" + s + " saved for " + selected_criteria;
				}
			}
		} else {
			//chromosome
			$(srcResultsID).style.display = "none";
			/*
			//unselect any and all select buttons in search results 
			var rowCount = Number($("cadt_gt_predesign_gene_search_result_count").value);
			for(var a = 0; a < rowCount; a++) {
				if($("cadt_gt_predesign_gene_search_select_button_" + a)) {
					$("cadt_gt_predesign_gene_search_select_button_" + a).className = "buttonSmallerOrange floatLeft";
				} else {
					break;
				}
			}
			*/
		}

		//********************************************************************************/
		// Set and display the single result (Select Assays page) if it exists.
		// For chromosome, this is the only way its results are shown. For the others,
		// this exists only if the search yielded only 1 single item.
		//*********************************************************************************/
		if (destCmd != '' && srcSingleResultID!= '' && srcSingleResultDiv != '') {
			//set the results page content
			eval(destCmd + '.click()');
			oResultsElem = $(srcSingleResultID);
			if (oResultsElem) {
				oResultsElem.innerHTML = srcSingleResultDiv;
			}
		}
	}

	function displaySearchHistory(srcSearchFormID, srcContainerID) {
		//writes the recent search history as links to the search page
		//srcSearchFormID - ID of the search form.
		//srcContainerID - ID of container span containing the history items.

		if (arr_hxcursor[srcContainerID] < 1) {
			return;
		}

		var i=0;
		var DOM_src = $(srcContainerID);
		var DOM_sp;
		var n_count = 0;
		var s_item_text='', s_item_criteria='';

		removeAllItemsFromHistory(DOM_src);
		for (i=0;i<arr_hxcursor[srcContainerID];i++) {
			s_item_text = arr_search_history[srcContainerID][i][0];
			if (s_item_text != '') {
				DOM_sp = new Element('span');				
				//DOM_sp.setAttribute("id",srcContainerID + '_sphxid' + i);
				DOM_sp.id = srcContainerID + '_sphxid' + i;
				DOM_sp.update(s_item_text);
				s_item_criteria = arr_search_history[srcContainerID][i][2];
				if (s_item_criteria != arr_cur_history_item[srcContainerID]) {
					DOM_sp.setAttribute("class",'searchHistoryList');
					DOM_sp.className = 'searchHistoryList';
					Element.observe(DOM_sp, 'mouseover', function(event){this.className = 'searchHistoryListHover';});
					Element.observe(DOM_sp, 'mouseout', function(event){
						if (this.title == arr_cur_history_item[srcContainerID]) {
							this.className = "searchHistoryListSelected";
						} else {
							this.className = 'searchHistoryList';
						}
					});
					Element.observe(DOM_sp, 'click', function(event){mouseClickSearchHistory(srcSearchFormID, this, srcContainerID);});
					//DOM_sp.onclick = new Function("mouseClickSearchHistory(this, '" + divResultsID + "')");
				} else {
					//we are at the current search history - changed back to make all links
					arr_curhx[srcContainerID] = i;
					DOM_sp.className = 'searchHistoryListSelected';				
				}
				DOM_sp.setAttribute("title",arr_search_history[srcContainerID][i][2]);
				DOM_src.appendChild(DOM_sp);
				DOM_sp = new Element('span');
				DOM_sp.update(' &nbsp;&nbsp;&nbsp;');
				DOM_src.appendChild(DOM_sp);
				
			}
		}

	return;
	}

	function getSearchHistoryContent(srcContainerID) {
	   /**
	   * Desc: return the given search history content.
	   * Created: dlu 11/24/08
	   * @INPUT Arguments:
	   * srcContainerID = ID of history array to retrieve
	   *
	   * @RETURNS: string.
	   */		

		if (!arr_hxcursor[srcContainerID]) {
			return 'Search results history does not exist.';
		}

		new Ajax.Request('../ga/apps/cadt/prepare_search_history.php', {
			method: 'post',
			parameters: { 
				'mode': 'set',
				'json': arr_search_history[srcContainerID].toJSON(),
				'container': srcContainerID,
				'hxcursor': arr_curhx[srcContainerID],
				'app': gaNavPtr.applications[gaNavPtr.activeApplication].name,
				'wf': gaNavAppPtr.activeWorkflow,
				'tab': gaNavAppPtr.workflows[gaNavAppPtr.activeWorkflow].activeTab
			},
			onSuccess: function(transport) {
				//alert(arr_search_history[srcContainerID].toJSON());
				//var popup = window.open("../ga/apps/cadt/save_search_to_file.php?container=" + srcContainerID);
			}
		});

		return '';
	}


	var curRow = -1;
	var selectRow = -1;

	function mouseOverStatusLine(sId) {
		return;
	}

	function mouseOutStatusLine(sId) {
		return;
	}

	function onMouseOverMozItem(srcElem) {
		//last modified 10/22/2007 DL to accomodate nested table
		//crawl up to find the row
		if (srcElem.style.backgroundColor == '#ffffcc')	{
			return;
		}

		while ((srcElem.tagName != "TR" && srcElem.tagName != "TABLE") || (srcElem.tagName == "TABLE" && srcElem.id == 'tbSub') || (srcElem.tagName == "TR" && srcElem.id == 'trSub') || (srcElem.tagName == "TR" && srcElem.className == 'trSub'))
			srcElem = srcElem.parentElement;

		if(srcElem.tagName != "TR") {
			return;
		}

		if (srcElem.rowIndex > 0) {
			hilite(srcElem);
		} else {
			hilite(-1);
		}
	}

	function onMouseOutMozItem(srcElem) {
		// Make sure we catch exit from the table

		if (srcElem.style.backgroundColor == '#ffffcc')	{
			return;
		}
		while (srcElem.tagName != "TR" && srcElem.tagName != "TABLE")
			srcElem = srcElem.parentElement;

		if(srcElem.tagName != "TR") {		
			return;
		}
		srcElem.style.backgroundColor = '';
		
		selectRow = -1;

		hilite(-1, -1);
	}

	function hilite(newRow)	{
		//last modified 10/22/2007 to sync hilite status panel item

		if (curRow != -1 && curRow!=selectRow)
		{
			curRow.style.backgroundColor = '';

			var sId = curRow.id			
			if ((sId.substr(0,1) == 'L' && sId != 'LSpacer') || (sId.substr(0,1) == 'T' && sId.substr(2,1) != '_')) {
				sId = curRow.name;
			}
			sId = sId.substr(3, sId.length);
			var newRow2 = document.getElementById('ts_' + sId);
			if (newRow2) {
				newRow2.style.backgroundColor = '';
			}

			mouseOutStatusLine(sId);
		}

		if (newRow != -1 && newRow!=selectRow)
		{
			newRow.style.backgroundColor = '#bec5de';

			var sId = newRow.id
			if ((sId.substr(0,1) == 'L' && sId != 'LSpacer') || (sId.substr(0,1) == 'T' && sId.substr(2,1) != '_')) {
				sId = newRow.name;
			}
			sId = sId.substr(3, sId.length);
			var newRow2 = document.getElementById('ts_' + sId);
			if (newRow2) {
				newRow2.style.backgroundColor = '#bec5de';
			}
			
			mouseOverStatusLine(sId);
		}		
		curRow = newRow;
	}

	function popUp8(URL) {
		day = new Date();
		id = day.getTime();
		eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1,width=800,height=400,left = 112,top = 184');");
	}
	function popUpWindow(URL, wd, ht) {
		day = new Date();
		id = day.getTime();
		eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=1,scrollbars=1,titlebar=1,location=1,statusbar=0,menubar=1,resizable=1,width=" + wd + ",height=" + ht + ",left = " + ((screen.availWidth - wd) / 2) + ",top = " + (((screen.availHeight - ht) / 2) - 60)+ "');");
	}
	function popUpDialog(URL, wd, ht) {
		day = new Date();
		id = day.getTime();
		eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=" + wd + ",height=" + ht + ",left = " + ((screen.availWidth - wd) / 2) + ",top = " + (((screen.availHeight - ht) / 2) - 60)+ "');");
	}
	function wopen(url, name, w, h) {
		 var win = window.open(url,
		  name,
		  'width=' + w + ', height=' + h + ', ' +
		  'location=no, menubar=no, ' +
		  'status=no, toolbar=no, scrollbars=yes, resizable=no');
		 win.resizeTo(w, h);
		 win.focus();
	}

	function getFormattedRequestString( A_values, char_delimiter )
	{
		//this will separate the array of values into delimited values.
		var str_values = "";
		var nCount = A_values.length;
		for( var i = 0; i < nCount; i++ ) {
			if(  A_values[i] != null ) {
				if (i < nCount - 1) {				
					str_values += ( A_values[i] + char_delimiter );
				} else {
					str_values += A_values[i];
				}
			}
		}
			
		return str_values;
	}

	function getArrayFromRequestString( str_values, char_delimiter )
	{
		//this will separate the delimited values into an array of values.
		var liststr = str_values.split(char_delimiter);			
		return liststr;
	}

   function hyphenizeStringValue(s_orig, maxchars, s_char) {
	   /**
	   * Desc:		insert a hyphen into a word if that word exceeds the character limit. However, note that this is
	   *			just a simple fxn not meant to be grammatically exact, so it doesn't follow the general rules of
	   *			correctly placing the hyphen.
	   * History:	4/15/09	- Fixed issues of possible existing hyphens in the original string and dealing with them.
	   *					  Checks distance between existing hyphen and start points to determine if another hyphen
	   *					  is needed there, otherwise reset start point to the existing hyphen.
	   *			3/15/08 - Fixed issue of only inserting one delimiter character even if the string[s] exceeded the
	   *					  maxchars by several fold. Now, it will iterate as many times necessary to make sure no
	   *					  section of string (e.g. incl. between hyphen and end of string) exceeds maxchars.
	   * Created: DLU 2/17/08
	   * Modified DLU 3/15/08, 4/15/09
	   * @INPUT Arguments:
	   *  s_orig	= source string containing either a sentence or word.
	   *  maxchars	= the maximum number of characters a word can have before a hyphen should be needed/inserted.
	   *  char		= character to insert. Default is a hyphen.
	   *
	   * @RETURNS: string - if a hyphen was inserted then return value is the new hyphenized-
	   *		   word or sentence which contains it. Otherwise, return value is the original unchanged source string.
	   */

		var k=0, pos=0, pos2=0;
		var bHyphen = false;
		var str_part_1 = '', str_part_2 = '', str_part_3 = '';		
		var str_word = '';
		var arr_words =  s_orig.split(/\s+/);
		var str_char = '-';
		if (s_char) {
			str_char = s_char;
		}
		for(k=0; k < arr_words.length; k++) {
			str_word = arr_words[k];
			str_word = str_word.replace(/\-/g, '*')		//convert any existing hyphens first, and note its position.
			pos2 = str_word.indexOf('*');
			pos = str_word.lastIndexOf(s_char);			//if not found as in the first time through, value of -1 is perfect.
			while (pos2 != -1 && pos2 - pos <= maxchars) {
				//DL - 4/15/09 - take into account any existing hyphens.
				//convert the * back to hyphen if it's within the max range, so first hyphen will be past the *.
				//So, make starting point where the * is.
				pos = pos2;
				pos2 = str_word.indexOf('*', pos2 + 1);
				bHyphen = true;
			}
			while (str_word.length - pos > maxchars) {
				str_part_1 = str_word.substr(0,pos+1);
				str_part_2 = str_word.substr(pos+1,maxchars);
				str_part_3 = str_word.substr(pos+1+maxchars, str_word.length - (pos+1+maxchars));
				//IE will work with just a hyphen to split the line, but FF requires a space also.
				if (bisIE) {
					str_word = str_part_1 + str_part_2 + str_char + str_part_3;
				} else {
					str_word = str_part_1 + str_part_2 + str_char + ' ' + str_part_3;
				}
				bHyphen = true;
				pos = str_word.lastIndexOf(s_char);
				while (pos2 != -1 && pos < pos2 && pos2 - pos <= maxchars) {
					//DL - 4/15/09 - take into account any existing hyphens.
					pos = pos2;									//make this the next start point
					pos2 = str_word.indexOf('*', pos2 + 1);		//get the next * position, if any
				}
			}
			str_word = str_word.replace(/\*/g, '-');
			arr_words[k] = str_word;
		}
		if(!bHyphen) {
			return s_orig;
		}
		s_new = getFormattedRequestString(arr_words, " ");
		if (!bisIE) {
			s_new = s_new.replace(/\-/g, '- ');
		}

		return s_new;
   }

	function getCookie(name) {
			 //Without this, it will return the first value 
			 //in document.cookie when name is the empty string.
			 if(name == '')
				return('');
			 
			 name_index = document.cookie.indexOf(name + '=');
			 
			 if(name_index == -1)
				return('');
			 
			 cookie_value =  document.cookie.substr(name_index + name.length + 1, 
													document.cookie.length);
			 
			 //All cookie name-value pairs end with a semi-colon, except the last one.
			 end_of_cookie = cookie_value.indexOf(';');
			 if(end_of_cookie != -1)
				cookie_value = cookie_value.substr(0, end_of_cookie);

			 //Restores all the blank spaces.
			 space = cookie_value.indexOf('+');
			 while(space != -1)
				  { 
				  cookie_value = cookie_value.substr(0, space) + ' ' + 
				  cookie_value.substr(space + 1, cookie_value.length);
								 
				  space = cookie_value.indexOf('+');
				  }

			 return(cookie_value);
	}
/*** end added DL on 11/24/08 ***/


    function checkCountry() {
        var country = readCookie('ab_countryName');
        switch(country) {
            case 'Japan': 
                $('other_ordering_options').style.visibility='hidden'; 
                break;
            default:
                $('other_ordering_options').style.visibility=''; 
        }
    }

    function emailOrderForm() {
        var msg = "<iframe id='emailOrderIframe' name='emailOrderIframe' frameborder='0' style='margin-left: 15px; margin-right: 15px; padding-left: 10px; width:700px; height:600px; border:1px solid silver;' src='../ga/email/emaildealerform.php'></iframe>"
            + '<br /><br />'
            + '<a id="sendmail" style="margin-left: 7px; margin-right: 4px; font-size: 10px; color: darkblue;cursor:pointer;" class="buttonSmallSilver floatLeft" onclick="window.frames[\'emailOrderIframe\'].emailForm();">E-Mail Order Form</a>'
            + '<a style="margin-right: 4px; font-size: 10px; color: darkblue;cursor:pointer;" class="buttonSmallSilver floatLeft" onclick="window.frames[\'emailOrderIframe\'].focus();window.frames[\'emailOrderIframe\'].print();">Print Order Form</a>'
            + '<a style="margin-right: 4px; font-size: 10px; color: darkblue;cursor:pointer;" class="buttonSmallSilver floatLeft" onclick="javascript:GA_UTIL.hide_lightbox(); parent.inf(parent.show); writeOmnitureEmailForm(-1);">Close Order Form</a>'
			+ '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <img src="../shared/images/reqInput_red.gif" hspace=4 align="absbottom" style="margin-bottom: 7px; vertical-align: bottom"> Required Field'
            + '<br>';
        //GA_UTIL.show_lightbox(msg,null);
		inf(hide);

		//Send to Omniture to indicate form was opened
		var pageName = getOmniturePageName();
		s.pageName = pageName + ' -> E-mail Order Form';
		s.channel="";
		s.prop1=""; 
		s.eVar30="";
		s.prop30="";
		var s_code=s.t();   
		if(s_code)document.write(s_code);

		GA_UTIL.show_lightbox_at('10%','25%',msg,null);
    }

    function printOrderForm() {
        var msg = "<iframe name='printOrderIframe' id='printOrderIframe' frameborder='0' style='margin-left: 10px; margin-right: 15px; padding-left: 10px; width:640px; height:300px; border:1px solid silver;' src='../ga/email/printform.php'></iframe>"
            + '<br /><br />'
            + '<a style="margin-right: 4px; font-size: 10px; color: darkblue;cursor:pointer;" class="buttonSmallSilver floatLeft" onclick="window.frames[\'printOrderIframe\'].focus();window.frames[\'printOrderIframe\'].print(); writeOmniturePrintForm(1);">Print Window</a>'
            + '<a style="margin-right: 4px; font-size: 10px; color: darkblue;cursor:pointer;" class="buttonSmallSilver floatLeft" onclick="javascript:GA_UTIL.hide_lightbox(); parent.inf(parent.show); writeOmniturePrintForm(-1);">Close Window</a>'
            + '<br>';
		inf(hide);

		//Send to Omniture to indicate form was opened
		var pageName = getOmniturePageName();
		s.pageName = pageName + ' -> Print Order Form';
		s.channel="";
		s.prop1="";
		s.eVar30="";
		s.prop30="";
		var s_code=s.t();   
		if(s_code)document.write(s_code);

        GA_UTIL.show_lightbox(msg,null);
    }

	function hideAllHelpBalloons() {
		//var app = gaNavPtr.activeApplication;			//Nav.activeApplication;
		//var wf = gaNavAppPtr.activeWorkflow;			//Nav.applications[activeApp].activeWorkflow;
		//var tab = gaNavAppPtr.workflows[wf].activeTab;	//Nav.applications[activeApp].workflows[activeWF].activeTab
		if (!Nav) {
			return;
		}
		var activeApp = Nav.activeApplication;
		var activeWF = Nav.applications[activeApp].activeWorkflow;
		var tab = Nav.applications[activeApp].workflows[activeWF].activeTab;
		var cur_divName = Nav.applications[activeApp].workflows[activeWF].tabs[tab].divName;
		var objs = $(cur_divName).getElementsByTagName("img");
		var i = 0;

		for (i=0 ; i < objs.length; i++)	{
			if (objs[i].id.indexOf('HelpBalloon_') != -1) {
				if(objs[i]._HelpBalloon._properties.visible) {
					objs[i]._HelpBalloon.hide();
				}
			}
		}
	}

	function createHelpIcons(s_title, div_target, help_url, icon_url, app_prefix, size_override) {
		var elems = $(div_target).getElementsByTagName("help");			//gaNavPtr.container.elements;
		if (!elems)	{
			return;
		}
		var i = 0, pos = 0;
		var o_hb;
		var arr_hb = new Array();
		var objs = new Array();
		var n_count = 0;
		var bFound = false;
		var hb_name = '', hb_id = '', hb_file = '', s_temp = '';
		var s_attrib_size = (size_override != '')?size_override:'default';	

		//Check for any help icons that are needed
		s_temp = 'hb_' + app_prefix + '_';
		n_count = s_temp.length;
		for (i=0 ; i < elems.length; i++)	{			
			if (elems[i].id.indexOf(s_temp) != -1) {
				//extract xxxx base name: hb_cadt_xxxxx_h01 - h01, hnn is so the same help for multiple help icon instances.
				var h_hb = new Hash();
				pos = elems[i].id.lastIndexOf('_h');
				if (pos != -1) {
					//length of base name section.
					h_hb.set('base', (elems[i].id).substr(n_count, pos - n_count));
					h_hb.set('id', (elems[i].id).substr(pos));
				} else {
					//grab from offset to the end.
					h_hb.set('base', (elems[i].id).substr(n_count));
					h_hb.set('id', '');					
				}
				arr_hb.push(h_hb);
			}
		}
		n_count = arr_hb.length;

		for (i=0; i < n_count; i++) {
			//e.g.hb_cadt_gexCustomSequence_name
			var hs_info = $H(arr_hb[i]);
			hb_name = hs_info.get('base');
			hb_id = hs_info.get('id');
			hb_file = help_url + '/' + app_prefix + '_help_' + hb_name + '.html';

			if (!size_override && bisIE && elems[i].bsize) {
				s_attrib_size = elems[i].bsize;
			} else if (!size_override && elems[i].readAttribute('bsize')) {
				s_attrib_size = elems[i].readAttribute('bsize');
			}

			o_hb = new HelpBalloon({ returnElement: true, type: s_attrib_size, title: s_title, icon: icon_url, dataURL: hb_file })._elements.icon;
			o_hb.hspace = '5';
			o_hb.vspace = '2';
			o_hb.align = 'absmiddle';
			s_temp = app_prefix + '_' + hb_name + hb_id;
			if ($(s_temp)) {
				//first make sure it doesn't exist already
				bFound = false;
				objs = $(s_temp).getElementsByTagName("img");
				if (objs.length > 0) {
					for (i=0 ; i < objs.length; i++)	{
						if (objs[i].id.indexOf('HelpBalloon_') != -1 && objs[i]._HelpBalloon.options.dataURL == hb_file) {
							bFound = true;
							break;
						}
					}
				}

				if (!bFound) {
					$(s_temp).appendChild(o_hb);
					//$('cadt_' + arr_hb[i]).appendChild((new HelpBalloon({ returnElement: true, title: 'Custom Assay Design Tool', icon: '../shared/images/icon_question.gif', dataURL: hb_file }))._elements.icon);
				}
			}
		}
	}

	function showHelp(id) {
		var objHelp = $(id).getElementsByTagName("img");
		if (objHelp[0].id.indexOf('HelpBalloon_') != -1) {
			objHelp[0]._HelpBalloon.show();
		}
	}

	function hideHelp(id) {
		if ($(id)) {
			document.body.removeChild($(id));
		}
	}

	function confirmDialog(properties) {
	   /**
	   * Desc:		Create a customizable dialog using the Lightbox object, with configurable
	   *			text, buttons, functions, return values.
	   * History:	4/12/09 - v1.0
	   * Created:	DLU 4/12/09
	   * Modified	DLU 4/12/09
	   * @INPUT Arguments:
	   * properties	= hash containing properties as keys and their values.
	   *			  "message" - main content of the dialog which to present to users.
	   *			  "all_buttons" - text for each button separated by | symbol.
	   *			  "hide_buttons" - text of the buttons (separated by | symbol) that will invoke the hide_lightbox function to close dialog.
	   *			  "button_[n]_function" - functions to call for button # n if any.
	   *			  "width" - width of dialog.
	   *			  "height" - height of dialog.
	   *			  "icom" - image to use in dialog.
	   *
	   * @RETURNS:	void
	   */	    


		var h_settings = $H(properties);
		var s_msg = h_settings.get("message");
		var arr_all_buttons = (h_settings.get("all_buttons")).split('|');
		var arr_hide_buttons = (h_settings.get("hide_buttons")).split('|');
		var s_width = h_settings.get("width");
		var s_height = h_settings.get("height");
		var s_image = "";			
		var closeFunction;
		var i = 0;

		var html = "";
		html += "<div style=\"width: " + s_width + "px; height: " + s_height + "px; margin: 10px; font-family: Arial; font-size: 12px;\">";
		if (h_settings.get("icon")) {
			s_image = "../shared/images/" + h_settings.get("icon");
			html += "<table cellpadding=\"0\" cellspacing=\"0\"><tr><td valign=\"top\" align=\"left\"><img src=\"" + s_image + "\" title=\"Alert\"></td>";
			html += "<td width=\"20\">&nbsp;</td><td valign=\"top\" align=\"left\">" + s_msg + "</td></tr></table>";
		} else {
			html += "<p>" + s_msg + "</p>";
		}
		html += "<div align=\"center\" style=\"margin-top: 15px; margin-left: auto; margin-right: auto;\"><table border=\"0\"><tbody><tr>";

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

			if (arr_hide_buttons[i] == arr_all_buttons[i]) {
				closeFunction = "parent.inf(show); GA_UTIL.hide_lightbox();";
			} else {
				closeFunction = "";
			}
			if (h_settings.get("button_" + i + "_function")) {
				btnFunction = h_settings.get("button_" + i + "_function") + ";";
			} else {
				btnFunction = "";
			}

			html += "<td><span class=\"nestedFontSize floatLeft\"><a id=\"dialog_btn_" + i + "\" class=\"buttonOrange\" href=\"javascript: void(0);\" onclick=\"" + btnFunction + closeFunction + "\">" + arr_all_buttons[i] + "</a></span></td>";

			if (i < arr_all_buttons.length - 1) {
				html += "<td><span class=\"nestedFontSize floatLeft\">&nbsp;&nbsp;&nbsp;&nbsp;</span></td>";
			}
		}

		html += "</tr></tbody></table></div>";
		html += "</div>";

		inf(hide);
		GA_UTIL.show_lightbox(html, null);
	}

	function getOmniturePageName() {
		var activeAppIndex = Nav.activeApplication;
		var activeWorkflowIndex = Nav.applications[activeAppIndex].activeWorkflow;
		var activeTabIndex = Nav.applications[activeAppIndex].workflows[activeWorkflowIndex].activeTab;
		var activeAppTitle = Nav.applications[activeAppIndex].title;
		var activeAppName = Nav.applications[activeAppIndex].ext_name;
		var activeWorkflowText = Nav.applications[activeAppIndex].workflows[activeWorkflowIndex].text;
		var activeTabText = Nav.applications[activeAppIndex].workflows[activeWorkflowIndex].tabs[activeTabIndex].text;
		var pageName = activeAppName + ' -> ' + activeWorkflowText + ' -> ' + activeTabText;
		//alert('inside getOmniturePageName: pageName = ' + pageName);
		return pageName;
	}

	function writeOmniture() {
		var pageName = getOmniturePageName();

		if (s.pageName == pageName) {
			return;
		}
		s.pageName = pageName;
		//alert('inside writeOmniture: s.pageName = ' + s.pageName);
		s.channel="";
		s.prop1="";
		s.eVar30 = "";
		s.prop30 = "";
		s.eVar31 = "";
		s.prop31 = "";
		s.eVar32 = "";
		s.prop32 = "";
		s.eVar34 = "";
		s.prop34 = "";
		s.eVar35 = "";
		s.prop35 = "";
		var s_code=s.t();   
		if(s_code)document.write(s_code);
	}

	function writeOmnitureNav(o_tab) {
		//Must get the names from the tab object. 
		//We have to use old Nav variables because the newest gaNavigation.js has not been deployed into production, yet. 
		//Therefore, when the new Nav is in production, replace with the commented code on the same line.
		//var activeAppTitle = o_tab.parentApp.title;
		var activeAppName =	gaNavPtr.applications[o_tab.appIndex].ext_name;	//o_tab.parentApp.ext_name;
		var activeWorkflowName = gaNavPtr.applications[o_tab.appIndex].workflows[o_tab.workflowIndex].name;  //o_tab.parentWF.name;
		var activeWorkflowText = gaNavPtr.applications[o_tab.appIndex].workflows[o_tab.workflowIndex].text;  //o_tab.parentWF.text;
		var activeTabName = o_tab.name;
		var activeTabText = o_tab.text;
		var s_pageName = activeAppName + ' -> ' + activeWorkflowText + ' -> ' + activeTabText;

		if (s.pageName == s_pageName) {
			return;
		}
		s.pageName = s_pageName;

		var s_id = activeWorkflowName + activeTabName;
		if (arr_selected_search_result_item[s_id]) {
			//record which search result record customer clicked to view its details in Select Assays or Product Details tabs, etc.
			//The workflow and tab name combination must match so it is only displayed for the right tab/page.
			s.pageName += ' [' + arr_selected_search_result_item[s_id] + ']';
		}
		//alert('inside writeOmnitureNav: s.pageName = ' + s.pageName);
		s.channel="";
		s.prop1="";
		s.eVar30 = "";
		s.prop30 = "";
		s.eVar31 = "";
		s.prop31 = "";
		s.eVar32 = "";
		s.prop32 = "";
		s.eVar34 = "";
		s.prop34 = "";
		s.eVar35 = "";
		s.prop35 = "";
		var s_code=s.t();   
		if(s_code)document.write(s_code);
	}

	function writeOmnitureEmailForm(code) {
		//Send to Omniture
		var pageName = getOmniturePageName();
		if (code > 0) {
			s.pageName = pageName + " -> E-mail Order Form Sent";
			s.eVar30 = "E-mail Order Form Sent SUCCESS";
			s.prop30 = "E-mail Order Form Sent SUCCESS";
		} else if (code == 0) {
			s.pageName = pageName + " -> E-mail Order Form Error";
			s.eVar30 = "E-mail Order Form Send FAILED";
			s.prop30 = "E-mail Order Form Send FAILED";
		} else {
			s.pageName = pageName;
			s.eVar30 = "E-mail Order Form CLOSED";
			s.prop30 = "E-mail Order Form CLOSED";
		}

		s.channel="";
		s.prop1="";
		s.eVar31 = "";
		s.prop31 = "";
		s.eVar32 = "";
		s.prop32 = "";
		s.eVar34 = "";
		s.prop34 = "";
		s.eVar35 = "";
		s.prop35 = "";
		var s_code=s.t();
		if(s_code)document.write(s_code);
	}

	function writeOmniturePrintForm(code) {
		//Send to Omniture
		var pageName = getOmniturePageName();
		if (code > 0) {
			s.pageName = pageName + " -> Print Order Form being printed";
			s.eVar30 = "Print Order Form being printed";
			s.prop30 = "Print Order Form being printed";
		} else {
			s.pageName = pageName;
			s.eVar30 = "Print Order Form CLOSED";
			s.prop30 = "Print Order Form CLOSED";
		}

		s.channel="";
		s.prop1="";
		s.eVar31 = "";
		s.prop31 = "";
		s.eVar32 = "";
		s.prop32 = "";
		s.eVar34 = "";
		s.prop34 = "";
		s.eVar35 = "";
		s.prop35 = "";
		var s_code=s.t();
		if(s_code)document.write(s_code);
	}

	function writeOmnitureSearch(h_search) {
		var activeAppIndex = Nav.activeApplication;
		var activeWorkflowIndex = Nav.applications[activeAppIndex].activeWorkflow;
		var activeTabIndex = Nav.applications[activeAppIndex].workflows[activeWorkflowIndex].activeTab;
		var activeAppName = Nav.applications[activeAppIndex].ext_name;
		var activeWorkflowName = Nav.applications[activeAppIndex].workflows[activeWorkflowIndex].name;
		var activeTabName = Nav.applications[activeAppIndex].workflows[activeWorkflowIndex].tabs[activeTabIndex].name;
		var s_id = activeWorkflowName + activeTabName;
		var pageName = getOmniturePageName();

		s.pageName = pageName;

		if (arr_selected_search_result_item[s_id]) {
			//record which search result record customer clicked to view its details in Select Assays or Product Details tabs, etc.
			//The workflow and tab name combination must match so it is only displayed for the right tab/page.
			//For this function, this is invoked at the same time as a search event when the search yields only 1 single result, so it goes directly to the "Details" page.
			s.pageName += ' [' + arr_selected_search_result_item[s_id] + ']';
		}

		var search_term = '';
		var search_criteria = '';
		var search_categories = '';
		var search_type = h_search.get('search_type');
		var search_status = h_search.get('status');

		if(activeWorkflowName == "customReorder" || activeWorkflowName == "configuratorSearch") {
			search_criteria = h_search.get('criteria');
			if(search_type == "date") {
				//Date Range Search, Search term = dates selected.
				search_term = h_search.get('startDate') + ':' + h_search.get('endDate');
			} else {
				//All other search types
				//Search terms (including sales order # if entered by user)
				search_term = h_search.get('searchTerm');
				if (h_search.get('salesOrder') != '') {
					search_term += ':' + h_search.get('salesOrder');
				}
			}
			//Search categories (the drop down values separated by a colon :)
			search_categories = search_type + ':' + search_criteria;

		} else {
			var species = '';
			if (h_search.get('search_species')) {
				species = h_search.get('search_species');
			} else if (h_search.get('node_id')) {
				var node_id = h_search.get('node_id');
				species = getSpeciesScientificName(node_id);
			}
			if (search_type == 'chromosome' || search_type == 'location') {
				//Search for Chromosome
				//Search term (term entered by user)
				var chromosome = '';
				if (h_search.get('chromo'))	{
					chromosome = h_search.get('chromo');
				} else if (h_search.get('chromosome')) {
					chromosome = h_search.get('chromosome');
				}
				search_term = 'Chr.' + chromosome + ':' + h_search.get('start') + '-' + h_search.get('stop');
				//Search categories = species only.
				search_criteria = '';
			} else {
				//Other search types - get criteria and search term
				search_criteria = (h_search.get('criteria'))?':'+h_search.get('criteria'):((h_search.get('search_criteria'))?':'+h_search.get('search_criteria'):'');
				search_term = (h_search.get('searchTerm'))?h_search.get('searchTerm'):((h_search.get('search_term'))?h_search.get('search_term'):'');
			}
			//Search categories (the drop down values separated by a colon :) = species:search_type:criteria
			search_categories = species + ':' + search_type + search_criteria;
		}

		//Search Tool used (populated for each tool): eVar35 & prop35.
		s.eVar35 = activeAppName;
		s.prop35 = activeAppName;
		//Search term (term entered by user) = eVar 31 & prop 31
		s.eVar31 = search_term;
		s.prop31 = search_term;
		//Search categories (the drop down values separated by a colon :) =  eVar32 & prop 32
		s.eVar32 = search_categories;
		s.prop32 = search_categories;
		//Search status (whether search was successful or failed)  = eVar 34 & prop 34
		s.eVar34 = search_status;
		s.prop34 = search_status;
		//alert('inside writeOmnitureSearch: ' + s.pageName);
		s.channel="";
		s.prop1="";
		s.eVar30 = "";
		s.prop30 = "";
		var s_code=s.t();   
		if(s_code)document.write(s_code);
	}

	function setSelectedProductPage(searchType, s_json, wfn, tabn) {
		var s_json_row = s_json.replace(/=/g, '"');
		var searchResult = s_json_row.evalJSON();
		var s_val = searchType + '=';
		var s_id = wfn + tabn;
		switch (searchType) {
			case "keyword":				
			case "gene_symbol":
			case "gene_name":
			case "gene_id":
				s_val = 'Gene=' + searchResult[0]['GENE_SYMBOL'] + ':' + searchResult[0]['PRIMARY_EXT_ID'];
				break;
			case "gt_assay_id":
			case "gex_assay_id":
				s_val = 'AssayID=' + searchResult[0]['ASSAY_PRODUCT_ID'];
				break;
			case "transcript_acc":
				s_val = 'Transcript=' + searchResult[0]['PRIMARY_EXT_ACC'] + '.' + searchResult[0]['PRIMARY_EXT_VERSION'];	
				break;
			case "rs_number":
				s_val = 'rs#' + searchResult[0]['DBSNP_ID'];
				break;
			case "cytoband":
				s_val += searchResult[0]['CYTOBAND'];
				break;
			case "chromosome":
				s_val = getSpeciesCommonName(searchResult.node_id) + ':Chr' + searchResult.chromo + ':' + searchResult.start + '-' + searchResult.stop;
				break;
			case "importassay":
				s_val = 'Import ' + searchResult.rowCount + ' Assays';
				break;
			case "importsearch":
				s_val = 'Import Search Results';
				break;
			default:
				s_val = '';
		}
		//store this value
		arr_selected_search_result_item[s_id] = s_val;
		return;
	}