
<!-- Begin
function setRadioOptions(formName, radioName, newValue) {
	radioObj = document.forms[formName].elements[radioName];
	if (!radioObj) {
		return;
	}
	var radioLength = radioObj.length;
	if (radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for (var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if (radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}
function performFormSubmittion(formName, fieldName, newValue) {
	var myForm = document.forms[formName];
	if (myForm) {
		fieldToSet = myForm.elements[fieldName];
		if (fieldToSet) {
			fieldToSet.value = newValue;
			document.forms[formName].submit();
		}
	}
}
function setFormFieldValue(formName, fieldName, newValue) {
	var myForm = document.forms[formName];
	if (myForm) {
		fieldToSet = myForm.elements[fieldName];
		if (fieldToSet) {
			fieldToSet.value = newValue;
		}
	}
}

function changeFormSubmitUrl(formName, newValue) {
	var myForm = document.forms[formName];
	if (myForm) {
		myForm.action = newValue;
	} else {
	    alert('form '+formName+' not found');
	}
}


function toggleLayer(whichLayer) {
	var elem, vis;
	if (document.getElementById) {// this is the way the standards work
		elem = document.getElementById(whichLayer);
	} else {
		if (document.all) {// this is the way old msie versions work
			elem = document.all[whichLayer];
		} else {
			if (document.layers) {// this is the way nn4 works
				elem = document.layers[whichLayer];
			}
		}
	}
	vis = elem.style;
      // if the style.display value is blank we try to figure it out here
	if (vis.display == "" && elem.offsetWidth != undefined && elem.offsetHeight != undefined) {
		vis.display = (elem.offsetWidth != 0 && elem.offsetHeight != 0) ? "block" : "none";
	}
	vis.display = (vis.display == "" || vis.display == "block") ? "none" : "block";
}
function hideLayer(elem) {
	var vis;
	vis = elem.style;
      // if the style.display value is blank we try to figure it out here
	if (vis.display == "" && elem.offsetWidth != undefined && elem.offsetHeight != undefined) {
		vis.display = (elem.offsetWidth != 0 && elem.offsetHeight != 0) ? "block" : "none";
	}
	vis.display = "none";
}
function isVisible(whichLayer) {
	var elem, vis;
	if (document.getElementById) {// this is the way the standards work
		elem = document.getElementById(whichLayer);
	} else {
		if (document.all) {// this is the way old msie versions work
			elem = document.all[whichLayer];
		} else {
			if (document.layers) {// this is the way nn4 works
				elem = document.layers[whichLayer];
			}
		}
	}
	vis = elem.style;
      // if the style.display value is blank we try to figure it out here
	if (vis.display == "" && elem.offsetWidth != undefined && elem.offsetHeight != undefined) {
		vis.display = (elem.offsetWidth != 0 && elem.offsetHeight != 0) ? "block" : "none";
	}
	return (vis.display == "" || vis.display == "block") ? true : false;
}
function showSpan(textSpanId, ellipsisSpanId) {
	var more = $(ellipsisSpanId);
	var moreText = $(textSpanId);
	Effect.toggle(moreText, 'appear');
	Effect.toggle(more, 'appear');
}
function floatMenu() {
	if (!document.getElementById) {
		return;
	}
	var menu = document.getElementById("organism_headerT");
	var topMenu = document.getElementById("organism_topMenuT");
	
	var distX = getScrollXY()[0];
	var windX = getWindowXY()[0];
	var width = windX - 16;
	//var width = windX;
	
	if(topMenu){
		topMenu.style.width = width + distX;
	}

	if(menu) {
		menu.style.left = distX;
		menu.style.width = width;
	}
}

// Resize the toolbar table based on the size of the current window and the scrolling
function floatToolbar() {
	
	// Make it so that no toolbar button is wider than 100 pixels
	$$('.toolbarItem').each(function(itemTableCell){
	if(itemTableCell.clientWidth > 100)
	   	itemTableCell.width = 100;
	});	   

    // For each toolbar table, change its width
    if($$('.toolbarTable').length > 0) {
        // Get window size, scroll position, and size of left menu
		var distX = getScrollXY()[0];
		var windX = getWindowXY()[0];
		var width = windX - 30;
		var leftMenuWidth = $('leftMenuContainer').clientWidth;
		
		// For each toolbar table, change its width
		$$('.toolbarTable').each(function(table){
		   	table.width = width + distX - leftMenuWidth;
		});	
	}
}

function floatLeftMenu() {
	if (!document.getElementById) {
		return;
	}
	var menu = document.getElementById("menu");
	var leftMenu = document.getElementById("sideMenu");
	
	var distY = getScrollXY()[1];
	var windY = getWindowXY()[1];
	var height = windY * 0.965;
	
	if (height < 850) {
		distY = distY - 850 + height;
		if(distY < 0){
			distY = 0;
		}
		height = 850;
	}
	if(menu) {
		menu.style.top = distY + "px";
		menu.style.left = height + "px";
	}
	
	if(leftMenu){
		leftMenu.style.top = distY + "px";
		leftMenu.style.left = height+ "px";
	}
}

function getWindowXY() {
	var myWidth = 0, myHeight = 0;
	if (typeof (window.innerWidth) == "number") {
    //Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else {
		if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
    //IE 6+ in 'standards compliant mode'
			myWidth = document.documentElement.clientWidth;
			myHeight = document.documentElement.clientHeight;
		} else {
			if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
    //IE 4 compatible
				myWidth = document.body.clientWidth;
				myHeight = document.body.clientHeight;
			}
		}
	}
	return [myWidth, myHeight];
}
function getScrollXY() {
	var scrOfX = 0, scrOfY = 0;
	if (typeof (window.pageYOffset) == "number") {
    	//Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	} else {
		if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
    		//DOM compliant
			scrOfY = document.body.scrollTop;
			scrOfX = document.body.scrollLeft;
		} else {
			if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
    			//IE6 standards compliant mode
				scrOfY = document.documentElement.scrollTop;
				scrOfX = document.documentElement.scrollLeft;
			}
		}
	}
	return [scrOfX, scrOfY];
}
function initHome() {

    // Following to setup the more text
	var more = $("more");
	var moreText = $("moreText");
	if (more && moreText) {
		moreText.hide();
	}
    
    // Following to fix the ie dropdown menu
	var dropdownMenuTop = $$(".menuTop");
	for (var i = 0; i < dropdownMenuTop.length; i++) {
		dropdownMenuTop[i].onmouseover = function () {
			this.className += " sfhover";
		};
		dropdownMenuTop[i].onmouseout = function () {
			this.className = this.className.replace(new RegExp(" sfhover\\b"), "");
		};
	}
	  // Setup the floating Header and Top Menu
	Event.observe(window,'resize',floatMenu);
	Event.observe(window,'scroll',floatMenu);
	Event.observe(window,'resize',floatToolbar);
	Event.observe(window,'scroll',floatToolbar);	
	
    
    // Call floatMenu to make the header and top menu use the correct width
	floatMenu();
	floatToolbar();
	
    // Following to be use with the new left drop down menu
    var zIndex = 10;
    var brcMenuItems = $$('.brcMenuItem');
    brcMenuItems.each(function(brcMenuItem){
      var brcSubMenu = brcMenuItem.down('.brcSubMenu');
      brcMenuItem.observe('mouseover', function(evt){        
        // prevent the zIndex overflow
        if(isNaN(zIndex)) {
        	zIndex = 10;
        }
        // Following to fix IE z-index problem, when the position is absolute,
        // IE will recalculate the z-index, so we will need to make the 
        // parent (brcMenuItem) has a higher z-index, so the children will
        // received higher display properly.
        brcMenuItem.style.zIndex = ++zIndex;
        brcMenuItem.addClassName('sfhover');
      });
      brcMenuItem.observe('mouseout', function(evt){
        // return the zIndex back to 10
        brcMenuItem.style.zIndex = 10;
        brcMenuItem.removeClassName('sfhover');
      });      
    });    

    // Set up the mouse over highlight
	$$('.tblHighlightOn', '.tblHighlightOff').each(function(row){
		row.observe('mouseover', function(evt){
			row.addClassName('mouseOver');
		});
		row.observe('mouseout', function(evt){
			row.removeClassName('mouseOver');
		});		
	});
}     


function validateForm(theForm) {
   var selectedItems = getCheckedItems(theForm.id, 'selectedItems');
   // Validate that either checkboxes have been selected on this page
   // or that checkboxes were selected on another page
   if (selectedItems == '') {
        // selectedCountDiv will only exist if there is more than one page
		if(!$('selectedCountDiv') || $('selectedCountDiv').innerHTML == '0') {
			alert("Please select at least one checkbox.");
			return false;
		}	
	} 
	return true;
}
    
// Add the init to the load chain for the page.
Event.observe(window, 'load', initHome);
Event.observe(window, 'unload', function(event) {
	hideOverlay();
});

function doOverlay(insideElementId, hideDuration, w, h){
	if(!w) {
		w = "auto";
	}
	if(!h) {
		h = "auto";
	}
	if(hideDuration){
		TransparentMenu.show('ajax_info_message', {showMode: null, hideMode: "none", hideEffectOptions: {duration: hideDuration}, insideElement: {id: insideElementId, width:w, height:h}});
	}else{
		TransparentMenu.show('ajax_info_message', {showMode: null, hideMode: "none", hideEffectOptions: {duration: 2}, insideElement: {id: insideElementId, width:w, height:h}});
	}
}
function hideOverlay(){
	if(TransparentMenu){
		TransparentMenu.hide("ajax_info_message");
	}
}

function toggleAnalysisParameters(id) 
{
	Effect.toggle('the'+id, 'appear', {duration:0});
	Effect.toggle('show'+id, 'appear', {duration:0});
	Effect.toggle('hide'+id, 'appear', {duration:0});
}
// End -->


function getCheckedItems(formId, selectionInputControlName) {
	return getCheckedItemsInArray(formId,selectionInputControlName).join();
}

function getCheckedItemsInArray(formId, selectionInputControlName) {
	var allSelectedItems = $$('#' + formId + ' input[name=' + selectionInputControlName + ']');
	var selectedIds = new Array();
	allSelectedItems.each(function(selectedItem) {
		if (selectedItem.checked) {
			selectedIds.push(selectedItem.value);
		}
	});
	return selectedIds;	
}

function createReportDialog(initialUrl, refreshIds, isStrongRemove) {
	lightBox = new LITBox("", "", initialUrl, "", {type:"window", overlay:true, resizable:false, opacity:1, callback:returnReplace.curry(refreshIds, '/brc/navigationOnly.do'), width:500, height:450, submitForm: false,strongRemove:isStrongRemove});
}

var validator;
function createSendReportValidator(form) {
	validator = new Validation(form, {onFormValidate:sendReport});
}

function sendReport(result, form) {
	if(!result) {
		return false;
	} else {
		// Add code to search and set the exception report
		setException();
		
		var jsonForm = form.serialize(true);		
		EmailService.sendReportEmail($H(jsonForm).toJSON(), showNotice.curry(form));
	}
}

function setException() {
	var hiddenException = $('exceptionReport');
	if(hiddenException) {
		// On the submit form, we have the field. So we will try to populate it.
		
		var exceptionTime = $('exceptionTime');
		var exceptionDesc = $('exceptionDesc');
		var exceptionDetail = $('stacktrace');
		var aHash = $H();
		aHash.set('exceptionTime', getTagText(exceptionTime));
		aHash.set('exceptionDesc', getTagText(exceptionDesc));
		aHash.set('exceptionDetail', getTagText(exceptionDetail));
		hiddenException.value = aHash.toJSON();
	}
}

function getTagText(el)
{
	if(!el) {
		return '';
	}
	if (el.textContent) return el.textContent;
	if (el.innerText) return el.innerText;
	var x = el.childNodes;
	var txt = '';
	for (var i=0, len=x.length; i<len; ++i){
		if (3 == x[i].nodeType) {
			txt += x[i].data;
		} else if (1 == x[i].nodeType){
			txt += getElText(x[i]);
		}
	}
	return txt.replace(/\s+/g,' ');
}

function showNotice (form, response) {
	var jsonForm = form.serialize(true);
	if (jsonForm.reportType == 'problemReport') {
		lightBox.remove();
		createReportDialog('/brc/problemReportNotice.do?')
	}else if (jsonForm.reportType == 'curatorComments' ){
		lightBox.remove(); 
		createReportDialog('/brc/messageDialog.do?messageDialog=' + response);  
	}else if(jsonForm.reportType == 'feedbacks') {
		lightBox.remove();
		createReportDialog('/brc/messageDialog.do?messageDialog=' + response, null, true);
	} else {
		lightBox.remove();
		createReportDialog('/brc/messageDialog.do?messageDialog=' + response, null, true);		
	}
}

function createReportNoticeDialog(initialUrl
) {
	lightBox = new LITBox("", "", initialUrl, "", {type:"window", overlay:true, resizable:false, opacity:1,  callback:function() {lightBox.remove}, width:500, height:250, submitForm: false});
}

function createRegisterEmailDialog(initialUrl
) {	
	lightBox = new LITBox("", "", initialUrl, "", {type:"window", overlay:true, resizable:false, opacity:1, callback:returnCall, width:400, height:250, submitForm: true});
}

// Function handles Other Display Options
function initOtherOptions(evt) {
	// Check to see if any otherDisplayOptions check box is checked  		
	$$('.displayOptionTable').each(function(t){
		var otherDisplayChecked = false;
		t.select('.otherCheckBox').each(function(cb){
			if(cb.checked)
			  otherDisplayChecked = true;
		});
		if(otherDisplayChecked) {
			var otherOptionsToggler = t.down('A.otherOptionsToggler');
			if(otherOptionsToggler) {
				showOtherOptions(otherOptionsToggler);
			}
		}
	});		
}

function showOtherOptions(toggler){
    var td = $(toggler).up('td');
	var container = td.down('div');
	if(container) {		
	  $(toggler).hide();
	  container.show();
	}
}

realVisible=function(elem) {
	var target = $(elem);
	if(target == $(document.body)) {
		return true;
	}
	if(Element.visible(target)) {
		if(realVisible(target.up())) {
			return true;
		}
	}
	return false;
}

formSubmit=function(formToSubmit) {
	doOverlay('mainBody');
	formToSubmit.submit();
}

checkDisplayOptions=function(theForm,callBackMethod,upperbound) {
//		alert('calling checkDisplayOptions with form:' + Element.inspect(theForm));
		var displayOptions = $A([]);
		// Check displayOptions	
		try {				
			displayOptions = Element.select(theForm,"input.displayOptions,input.otherCheckBox");
		}catch(e) {
			console.debug(e);
		}
		var checkedDisplayOptionsCount = 0;
		displayOptions.each(function(d){
			if(d.checked && d.value != 'All' && realVisible(d)) {
				checkedDisplayOptionsCount++;							
			}
		});
//		alert('checkedDisplayOptionsCount:' + checkedDisplayOptionsCount);
		
		if(!upperbound) {
			upperbound = 12;
		}
		var confirmMsg = 'You selected more than ' + upperbound + ' display fields. The result page may be hard to read, requiring horizontal scrolling to see all data. Please confirm you would like to proceed by clicking the "Yes" button, or click the "No" button to go back and change your display selections.'		
		var confirmed = true;
		if(checkedDisplayOptionsCount > upperbound) {
			confirmed = false;
			lightBox = new LITBox(confirmMsg, "", "", "", {type:"confirm", overlay:true, resizable:false, opacity:1, strongRemove:true,callback:callBackMethod, width:400, height:175});
		}
		return confirmed;
}	

// Used to update workbench icons on family home page
// after an action is taken to log in
function switchViprFamilyHomePageOnLogin() {
   if($('homePageWorkbenchNotLoggedIn')) {
      $('homePageWorkbenchNotLoggedIn').hide();
      $('homePageWorkbenchLoggedIn').show();
   }
}

// Used to update workbench icons on family home page
// after an action is taken to log out
function switchViprFamilyHomePageOnLogout() {
   if($('homePageWorkbenchNotLoggedIn')) {
      $('homePageWorkbenchNotLoggedIn').show();
      $('homePageWorkbenchLoggedIn').hide();
   }   
}

function submitProblemReport() {
	var problemReportForm = document.forms['problemReportForm'];
	if(problemReportForm) {
		var exceptionTime = $('exceptionTime');
		var exceptionDesc = $('exceptionDesc');
		var exceptionDetail = $('stacktrace');
		var aHash = $H();
		aHash.set('exceptionTime', getTagText(exceptionTime));
		aHash.set('exceptionDesc', getTagText(exceptionDesc));
		aHash.set('exceptionDetail', getTagText(exceptionDetail));
		  	
		$('exceptionReport').value = aHash.toJSON();
		problemReportForm.submit();
	}
}