
function navBar(tableCellRef, hoverFlag, navStyle) {
	if (1 == hoverFlag) 
	{
        if (navStyle == 2)
        {
            tableCellRef.style.backgroundColor = '#D51032';
        }
	} 
	else 
	{
        if (navStyle == 1)
        {
            tableCellRef.style.backgroundColor = '#18987D';
        }
	}
}

function navBarClick(tableCellRef, navStyle, url, sendTo) {
	navBar(tableCellRef, 0, navStyle);
	if (sendTo == 1) {
		parent.location.href = url;
	} else if (sendTo == 0) {
	    var x = (screen.width - 570) / 2;
	    var y = (screen.height - 370) / 2;
		OpenWin = this.open(url, "Important", "toolbar=0,menubar=0,location=0,scrollbars=0,resizable=0,width=570,height=370,left='+x+',top='+y+'");
	} else if (sendTo == 2) { // For the About the Atlas
		parent.frames[1].location.href = url + "#TemplateAtlas";
	}
}

function submit_page(form) {

bl.style.cursor="wait";

var checking = form.searchstring.value
var a = checking.length
var theCharCode = checking.charCodeAt(a-1);
if (theCharCode == 32){
alert ("Can not have a space at the end of string.")
return false
}

if(form.searchacronym.value == "") {
	alert ("Can not search an empty string.")
	window.otherfind.searchacronym.focus();
	return false
	}
}

function retrace() { history.back() }

function CheckSearchKeyword()
{
    var keyword = document.getElementById("ctl00_MainContent_SearchBox1_txtSearchString"); 
    if (null != keyword && "" != keyword.value)
    {
        return true;
    }
    else
    {
        var theTable = document.getElementById("otherSiteID");
        if (null != theTable)
        {
            theTable.style.left = "180px";
            theTable.style.top = "20px";
            theTable.style.position = "absolute";
            theTable.style.width = screen.width - 180;
        }
        alert('Cannot search an empty string.');
        FocusKeywordBox();
    }
    return false;
}

function ResetSearchKeyword()
{
    var keyword = document.getElementById("ctl00_MainContent_SearchBox1_txtSearchString"); 
    if (null != keyword)
    {
        keyword.value = "";
        FocusKeywordBox();
    }
    return false;
}

function FocusKeywordBox()
{
    var keyword = document.getElementById("ctl00_MainContent_SearchBox1_txtSearchString"); 
    if (null != keyword)
    {
        keyword.focus();
    }
}

function KeywordBoxHandler()
{
    if (event.keyCode == 13)
    {
        var button = document.getElementById("ctl00_MainContent_SearchBox1_btnSubmit");
        if (null != button)
        {
            button.focus();
            button.click();
        }
    }
}

function KeywordBoxHandlerAtlas()
{
	if (event.keyCode == 13)
	{
		return OpenSubSiteFromAtlasOther();
	} 
}

function OpenSubSiteFromAtlasOther()
{
	var p_keyword = document.getElementById("ctl00_txtSearchString");
	
	if (null != p_keyword)
	{
		var keyValue = p_keyword.value;		
		if (keyValue == "")
		{
			alert("Please enter a structure name!");
			return false;		
		}
		else
		{
			var page = "search.aspx?searchstring="+keyValue+"&fromwhere=other";
			var width = 900;
			var height = 600;
			var left = (screen.width - width) / 2;
			var top = (screen.height - height) / 2;
			window.open(page, null, "toolbar=no,location=yes,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width="+width+",height="+height+",top="+top+",left="+left+"");
			return false;
		}
	}
}

function SetEverySiteNavHeight()
{
    var navBar = document.getElementById("navigation");
    var content = document.getElementById("content");
    if (null != navBar && null != content)
    {        
        if (content.offsetHeight > navBar.offsetHeight)
        {
            window.document.body.scroll = "yes";
            window.document.body.style.overflow = "auto";
            var bodyHeight = window.document.body.offsetHeight;
            navBar.style.height = bodyHeight + "px";
        }
        else
        {
            window.document.body.style.overflow = "hidden";
            window.document.body.style.overflowY = "hidden";
            //navBar.style.height = "l00%";
        }
    }

    // Search page bug!    
    var keyword = document.getElementById("ctl00_MainContent_SearchBox1_txtSearchString"); 
    if (null != keyword)
    {
        keyword.focus();
    }

}

function SetSubSiteNavHeight()
{
    var navBar = document.getElementById("navigation");
    var content = document.getElementById("content");
    if (null != navBar && null != content)
    {
        window.document.body.scroll = "no";
        window.document.body.style.overflow = "hidden";
        window.document.body.style.overflowY = "hidden";
        var bodyHeight = window.document.body.offsetHeight;
        var contentHeight = content.offsetHeight;
        var bodyHeight = window.document.body.offsetHeight;
        var contentHeight = content.offsetHeight;
        //if (contentHeight > bodyHeight)
        if (bodyHeight > contentHeight)
        {
            navBar.style.height = bodyHeight + "px";
        }
        else
        {
            //navBar.style.height = "100%";
        }
    }    
}

function OpenDialog(page)
{
    var top = (screen.height - 370) / 2;
    var left = (screen.width - 600) / 2;
    if (navigator.appVersion.indexOf("MSIE") != -1)
    {
        //var feature = "dialogTop:" + top + "px;dialogLeft:" + left + "px;dialogHeight:370px;dialogWidth:570px;resizable:no;scroll:no;status:no;";
        var feature = "center:yes;dialogHeight:370px;dialogWidth:600px;resizable:no;scroll:no;status:no;";    
        window.showModalDialog(page,"",feature);
    }
    else if (navigator.userAgent.indexOf("Opera") != -1)
    {
        window.navigate(page);        
    }
    else
    {
        top = top - 80;
        var feature = "top="+top+"px,left="+left+"px,height=370px,width=600px,status=no,toolbar=no,menubar=no,location=no";
        window.open(page,"", feature);
    }
}

// #######################################################################
// begin for NewInternalStructure
// #######################################################################
// Use the maxChecked variable to set the maximum number that can be checked
var maxChecked = 5
var totalChecked = 0
var totalChecked_other = 0
var total = 0

function retrace()
{
    history.back()
}

function getRelations(questID)
{
    var width = 820;
    var height = 265;
    var left = (screen.width - width) / 2;
    var top = (screen.height - (height-50)) / 2;
	 window.open("relations.aspx?questID=" + questID, "Relations", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width="+width+",height="+height+",top="+top+",left="+left+"");
}

function submit_page(form) {

	var anyClicked=false;

	if (form.is_chkbox != null) {

		var chkbox = form.is_chkbox.length;
		if (chkbox > 0) {
	        for (var i=0; i<chkbox; i++)
	        {
	        	if(form.is_chkbox[i].checked)
	            	anyClicked=true;
	        }
	    }
	    else {
	    	if (form.is_chkbox.checked)
	        	anyClicked=true;
		}
	}

   	if(!anyClicked)
   	{
   		alert("Please check boxes for the images you want to view full size");
        return false;
   	}

   	return true;
}

function CountChecked(field) {

		if (document.is_chkbox == null)
		totalChecked = 0
        else
        totalChecked = checkStatus(document.is_chkbox)

        total = totalChecked + totalChecked_other

        if (field.checked)
           total += 1
        else
           total -= 1

        if (total > maxChecked) {
           alert ("The maximum number of selections is 4.")
           field.checked = false
           total = maxChecked
        }
}

function ResetCount() {
		total = 0
        totalChecked = 0
        totalChecked_a = 0
        totalChecked_h = 0
}

function checkStatus(cbList) {
        var kewl = 0
        for (var i=0; i<cbList.length; i++) {
                        if (cbList[i].checked == true)
                        kewl += 1
        }
        return (kewl)
}
// #######################################################################
// end for NewInternalStructure
// #######################################################################

function DisplayMapViewData()
{
	var selectedVal = "";
	var iIndex=0;
	
	while(document.getElementById("ctl00_MainContent_rbList" + '_' + iIndex))
	{
		if (document.getElementById("ctl00_MainContent_rbList" + '_' + iIndex).checked)
		{
			selectedVal = document.getElementById("ctl00_MainContent_rbList" + '_' + iIndex).value;
		}
		
		iIndex = iIndex + 1;
	}
	
	var page = "http://neuromaps.braininfo.org/cgi-bin/NeuroMaps.py?species=" + selectedVal;
	//window.location = page;
	var width = 800;
	var height = 600;
	var left = (screen.width - width) / 2;
	var top = (screen.height - height) / 2;
	window.open(page, "", "toolbar=no,location=yes,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width="+width+",height="+height+",top="+top+",left="+left+"");
 }
 
 function DisplayMapViewData_Temp() //temporary function, to be deleted later
 {
	var selectedVal = "Macaque";
	
	var page = "http://neuromaps.braininfo.org/cgi-bin/NeuroMaps.py?species=" + selectedVal;
	//window.location = page;
	var width = 800;
	var height = 600;
	var left = (screen.width - width) / 2;
	var top = (screen.height - height) / 2;
	window.open(page, "", "toolbar=no,location=yes,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width="+width+",height="+height+",top="+top+",left="+left+"");
 }
 
 function menuOtherSite_redirect(questID) {
    window.location = "/ShowItHier.aspx?questID="+questID;
    
 }