///////////////////////////////////////////////////////////////////////////////////////////////////////
// All code, unless otherwise specified was developed by Andrew Janssen, Copyright ©2002-2003.
// It may be used on any website (commercial, private, or non-profit) as long as this comment banner is not removed or edited.
///////////////////////////////////////////////////////////////////////////////////////////////////////

//This code checks to see if an incompatible or unsupported browswer is being used.
//If it is, an error message displaying info to the user will be displayed where the function is called.
// for details about the variables...check the code in browserdetect_lite.js or
// http://www.dithered.com/javascript/browser_detect/index.html for more information about variables available.
function detectBadBrowser(){
if(browser.isNS4x){
document.write("This page is not compatible with Netscape 4, please use a newer browser.<br>");
document.write("  Otherwise, you may visit the <a href='http://www-visualmedia.fnal.gov/VMS_SITE/active.html'>Old VMS Site</a>.<br>");
document.write("  The old site has not been updated since March 2003 and is no longer supported by VMS staff.");}
else if(!browser.isNS4x && !browser.isIE5up && !browser.isNS6up)
{
document.write("This page has not been tested with your browser and no attempt will be made to do so.<br>");
document.write("This messages will persist while using this page... but feel free to inform <a href='mailto:vismedsr@fnal.gov'>VMS</a><br>");
document.write(" about the compatibility so we can remove this message.");
}
}


//reset variables (this is important, otherwise may be treated "globally" using old values...
var section = 0;
var subsection = 0;
var linkTo = '';
var linkName = '';
var fileStructureLocation = '';
var ranNum = 0;
var runAlready=false;
var used=new Array(20);
//////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////
// User Defined variables, specific to graphic interface for site-wide menu
// XXX Color vs. Graphics... these are best used in pairs, i.e. use either all color or all graphics...XXX
// XXX IF graphic locations are defined, then they will OVER-RIDE colors (for IE)...define w/ caution
var specialColor = "#F56425";
//var specialGraphic =prePath +  'graphics/2a.gif';	//probably not used... ex. 'graphics/blank.gif'
var rOverColor = "#CCCCCC"; 
var rOutColor = "#F538FF"; 	//probably not used, //////must (un)comment in 'rOut()' to use
//var rOverBgGraphic =prePath +  'graphics/1a.gif'; 	//probably not used 
//var rOutBgGraphic =prePath +  'graphics/2d.gif'; 	//probably not used
//var sectionGraphic;


//sets bgcolor of table cell based on section #
// (un)comment sectionGraphic=''; to toggle graphical menu (this will degrade page performance..)
function getBg(sectionNumber){
	switch(sectionNumber){
	case 0: sectionColor='#AAC6FF';
			//sectionGraphic= 'graphics/blank.gif';
			break;
	case 1: sectionColor='#8AB0FF';
			//sectionGraphic= 'graphics/blank.gif';
			break;
	case 2: sectionColor='#558CFF';
			//sectionGraphic= 'graphics/blank.gif';
			break;
	case 3: sectionColor='#3577FF';
			//sectionGraphic= 'graphics/blank.gif';
			break;
	case 4: sectionColor='#1562FF';
			//sectionGraphic= 'graphics/blank.gif';
			break;
	case 5: sectionColor='#0050F4';
			//sectionGraphic= 'graphics/blank.gif';
			break;
	case 6: sectionColor='#0045D5';
			//sectionGraphic= 'graphics/blank.gif';
			break;
	case 7: sectionColor='#003AB5';
			//sectionGraphic= 'graphics/blank.gif';
			break;
	case 8: sectionColor='#003399';
			//sectionGraphic= 'graphics/blank.gif';
			break;
	case 9: sectionColor='FF0000';
			//sectionGraphic= prePath + '000graphics/whatsNewSmall.gif';
			break;
	default: sectionColor='#FFFF00';		//probably (hopefully!) not used
			//sectionGraphic= 'graphics/blank.gif';
			break;							
	}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////


/*//pre-load images for menu, if necessary!
//never tried it..though it's straight from old website...
function preloadImages(){
	if(document.images){
		var imgFiles = preloadImages.arguments;
		var preloadArray = new Array();
		for (var i=0; i< imgFiles.length; i++){
			preloadArray[i] = new image;
			preloadArray[i].src = imgFiles[i];
		}
	}
}*/

//Begin Menu Engine Functions...//
//initializes table cell bg(color)s (lines 11,17,28,37 must be (un)commented to toggle graphical menu)
function paintTable(tempSec, tempSub){
getInfo('idSec'+sec+'Sub'+sub+'Num'+0);
			//paint submenu
			for(i=numChildren; i>=1; i--) 
			{
				if(document.getElementById('idSec'+tempSec+'Sub'+tempSub+'Num'+i))
				{
					getInfo('idSec'+tempSec+'Sub'+tempSub+'Num'+i);
					getBg(tempSec);
					document.getElementById('idSec'+tempSec+'Sub'+tempSub+'Num'+i).style.backgroundColor=sectionColor;
					//document.getElementById('idSec'+tempSec+'Sub'+tempSub+'Num'+i).background=sectionGraphic;//
				}
				else
				{
					getBg(0);
					document.getElementById('idSec'+tempSec+'Sub'+tempSub+'Num'+i).style.backgroundColor=sectionColor;
					//document.getElementById('idSec'+tempSec+'Sub'+tempSub+'Num'+i).background=sectionGraphic;//
				}
			}
			//paint main menu
			tempSec=0;
			tempSub=0;
			while(document.getElementById('idSec'+tempSec+'Sub'+tempSub+'Num'+0))
				{
					getInfo('idSec'+tempSec+'Sub'+tempSub+'Num'+0);
					getBg(tempSec);
					document.getElementById('idSec'+tempSec+'Sub'+0+'Num'+0).style.backgroundColor=sectionColor;
					//document.getElementById('idSec'+tempSec+'Sub'+0+'Num'+0).background=sectionGraphic;//

					while(document.getElementById('idSec'+tempSec+'Sub'+tempSub+'Num'+0))
					{
						getInfo('idSec'+tempSec+'Sub'+tempSub+'Num'+0);
						getBg(tempSec);
						document.getElementById('idSec'+tempSec+'Sub'+tempSub+'Num'+0).style.backgroundColor=sectionColor;
						//document.getElementById('idSec'+tempSec+'Sub'+tempSub+'Num'+0).background=sectionGraphic;//
						tempSub++;
					}
					tempSec++;
					tempSub=0;
				}
			
}

//change table cell bg(color) on rollover
// (un)comment 7th line to toggle different color rollover
// (un)comment last line to toggle graphical menu
function rOver(td){
	if(document.getElementById)
	{
		getInfo(td.getAttribute('id'));		//determines what section rolling over...
		getBg(section);		//sets background image/color for that section...
		td.style.backgroundColor=sectionColor;
		//td.style.backgroundColor=rOverColor;		
		//td.background=rOverBgGraphic;
	}
}


//change table cell bg(color) back on rollout
// (un)comment lines 6/8 to toggle graphical menu, 7 for special color
function rOut(td){
if(document.getElementById){ 
	getInfo(td.getAttribute('id'));		//determines what section rolling over...
	getBg(section);		//sets background image/color for that section...
	td.style.backgroundColor=sectionColor;
	//td.background=sectionGraphic;//	// (un)comment) to toggle graphical menu, w/ regular section graphic
	//td.style.backgroundColor=rOutColor;		// (un)comment to toggle menu w/ special roll out color, probably won't use
	//td.background=rOutBgGraphic;//	// (un)comment to toggle menu w/ special roll out graphic, probably won't use
	}
}


//if this table cell is for the current page, then repaint it special/different bg(color)
// (un)comment lines 4, 8 to toggle graphical menu
function askWhere(tdID){
getInfo(tdID);
	document.getElementById('idSec'+sec+'Sub'+sub+'Num'+0).style.backgroundColor= specialColor;
	//document.getElementById('idSec'+sec+'Sub'+sub+'Num'+0).background=specialGraphic;//
	if(('idSec'+sec+'Sub'+sub+'Num'+0) != pageId)
	{
		document.getElementById(pageId).style.backgroundColor= specialColor;
		//document.getElementById(pageId).background=specialGraphic;//
	}
}


//creates dynamic links based off of getInfo data
// if want to add target, do so..ex: "new"..if not, use: "" 
function makeLink(id, target){
	getInfo(id);
	document.write("<a class='menu' href="+prePath+fileStructureLocation+linkTo+" target="+target+" >"+linkName+"</a>");
}


//This wasn't working..fix it if desired..make sure to include function call in body onLoad...
//uses page defined 'levelsDeep' variable to set paths for graphics, etc.
//var prePath= '';
//var prePath= '../../';
//function autoPath(level){
//	if(level>0){
//		prePath = '../' + prePath;
//		level--;
//	}
//	prePath = 'VMS_Site_2/' + prePath;
//}


//End menu engine functions....//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////
//Begin graphic functions.....//

//get graphic for any where!
// must pass in 4 paramters...
// id = title of graphic (not including tag), titles should not match any known pageId
// tempSec, tempSub, tempNum = identify what page you are on...these RARELY need to be changed (just leave sec,sub,num)
// numSlots = this is the number of random images to rotate through
// fileType = should be either "gif" or "jpg" or whatever the graphic tag is...
// twain = should be either "local" or "global"...otherwise will return error
// shania = should be either "random" or "static" ..this toggles random image engine
function getGraphic(id, tempSec, tempSub, tempNum, numSlots, fileType, twain, shania){
	if(shania == "static")
	{
		if(twain == "global")
		{
			makePageId(tempSec,tempSub,tempNum);
			getInfo(document.getElementById(pageId));
			document.write("<img src="+prePath+"000Graphics/"+fileStructureLocation+id+"."+fileType+" border='0'>");
		}
		else if(twain == "local")
		{
			makePageId(tempSec,tempSub,tempNum);
			document.write("<img src="+prePath+"000Graphics/"+fileStructureLocation+id+"."+fileType+" border='0'>");
		}
		else document.write("local/global parameter incorrect!!!");
	}
	else if(shania == "random")
	{
		//let's get a random number...not already used!
		if(runAlready==false)
		{
			//set array to false
			for(var i=0;i<numSlots;i++)<!--  -->
			{used[i] = false;}
			runAlready=true;
		}
		var success = false;
		while(!success)
		{
			getRandom(numSlots);
			if(used[ranNum-1] == false)
				{	
					used[ranNum-1] = true;
					success = true;
					//document.write(ranNum);
				}
		}
	
		if(twain == "global")
		{
			makePageId(tempSec,tempSub,tempNum);
			getInfo(document.getElementById(pageId));
			document.write("<img src="+prePath+"000Graphics/"+fileStructureLocation+id+ranNum+"."+fileType+" border='0'>");
		}
		else if(twain == "local")
		{
			makePageId(tempSec,tempSub,tempNum);
			document.write("<img src="+prePath+"000Graphics/"+fileStructureLocation+id+ranNum+"."+fileType+" border='0'>");
		}
		else document.write("local/global parameter incorrect!!!");
	}
	else document.write("random/static parameter incorrect!!!");	
}


//Gets random number for picture generation.
// slots = determines range of generated numbers 0 - #slots (integers)
function getRandom(slots)
{
    ranNum= Math.round(Math.random()*(slots-1))+1;
    //return ranNum;
}

//End graphic functions....//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////
//Begin "other" functions..//

//Take the passed in page ID's..and make a single page id. 
// tempSec,tempSub,tempNum are all passed in as expected defining a page location in structure
function makePageId(tempSec,tempSub,tempNum){
pageId= "idSec"+tempSec+"Sub"+tempSub+"Num"+tempNum;
//set key variables!
getInfo(pageId);
}

//These functions are to avoid errors...
// they will be overwritten if cookie.js is loaded (i think ;-)
function setupForm(){
return;}
function setCursorPosition(){
return;}	