/*__________________________________________________________________________________________
 *
 *                      LIBRARY FUNCTIONS
 *__________________________________________________________________________________________
 */
 
//----[ Dirty Hacks ]-----------------------------------------

/*
 * This code works around some stupid Microsoft security patches
 * which break the JavaScript object-detection mechanism.
 */
 
// Standard detection handler:

function detectObjectStandard(base,name)
{
	if( base[name] ) return true;
	else return false;
}

// Microsoft's conditional comments don't work in JavaScript, so must write the code dynamically...
if( document.all && document.getElementById && ( navigator.appVersion.toLowerCase().indexOf("win") >= 0 ) )
{
	var s = '';
	s += '<'+'script>';
	s += 'function detectObjectTryCatch(base,name){try{if( base[name] ) return true;else return false;}catch (e){return false;}}';
	s += '<'+'/script>';
	document.write(s);
	window.detectObject = window.detectObjectTryCatch;
}
else
{
	window.detectObject = window.detectObjectStandard;
}


//----[ Popups ]-----------------------------------------
function basicPopup(URL,name,p){var WindowName;if((!name)||(name==''))name='_blank';w=window.open(URL,WindowName,p);if(w.window.focus)w.window.focus();return false;}
function centerOnScreen(w,h){this.l=((window.screen)&&(screen.availWidth))?(screen.availWidth-w)/2:((window.screen)&&(screen.width))?(screen.width-w)/2:0;this.t=((window.screen)&&(screen.availHeight))?(screen.availHeight-h)/2:((window.screen)&&(screen.height))?(screen.height-h)/2:0}
function popup(URL,name,w,h,s){var c=new centerOnScreen(w,h);return basicPopup(URL,name,'height='+h+',width='+w+',top='+c.t+',left='+c.l+',scrollbars='+((s)?'yes':'no')+',resizable=yes')}
function Popup(URL,name,w,h,s){var c=new centerOnScreen(w,h);return basicPopup(URL,name,'height='+h+',width='+w+',top='+c.t+',left='+c.l+',scrollbars='+((s)?'yes':'no')+',resizable=yes')}

function esroPopup(URL){return Popup(URL,'eifEsroPopup',800,550,true);}

// To make it full-width, replace 800 with (window.screen)&&(screen.availWidth)

//----[ General ]-----------------------------------------
function preload()
{
	var a=preload.arguments;
	if(!window.__PreloadArray)window.__PreloadArray=new Array();
	for(i=0;i<a.length;i++)
	{
		var n='file'+a[i];
		window.__PreloadArray[n]=new Image();
		window.__PreloadArray[n].src=a[i];
	}
}

/*__________________________________________________________________________________________
 *
 *                      HIGH-LEVEL FUNCTIONS
 *__________________________________________________________________________________________
 */

//----[ Toggle ]-----------------------------------------

function toggleDateOptions()
{
	var args = toggleDateOptions.arguments;
	if( args.length < 1 ) return;
	var ok = false;
	var i;
	var frm='dhtmlform';
	for(i=0; i<args.length; ++i )
	{
		var id = args[i];
		if( ! document.forms[frm].elements[id] ) continue;
		obj = document.forms[frm].elements[id];
		if( ! obj.checked ) ok = true;
		obj.checked=true;
	}
	if( ! ok )
	{
		for(i=0; i<args.length; ++i )
		{
			var id = args[i];
			if( ! document.forms[frm].elements[id] ) continue;
			obj = document.forms[frm].elements[id];
			obj.checked=false;
		}
	}
}

function updateDateField()
{
	var s = getDateOptions();
	if(document.forms.searchform.daterange) document.forms.searchform.daterange.value=s;
	return true;
}

function getDateOptions()
{
	var frm=document.forms[ 'dhtmlform' ];
	var s='';
	var sep='';
	for( var i in frm.elements )
	{
		if( detectObject( frm.elements, i ) && frm.elements[i].checked )
		{
			s+=sep+frm.elements[i].name;
			sep='.';
		}
	}
	return s;
}

function toggleLayer( layerName )
{
	if( ! document.getElementById ) return true;
	var lyr = document.getElementById( layerName );
	if( ! lyr ) return true;
	if( lyr.style.visibility == 'visible' && lyr.style.display != 'none' )
		lyr.style.visibility = 'hidden';
	else
	{
		lyr.style.visibility = 'visible';
		lyr.style.display = 'block';
	}
	return false;
}
 
//----[ Rollovers ]-----------------------------------------
function rollover(name,file)
{
	if( ! document.images ) return;
	if( ! document.images[name] ) return;
	window.__lastImageName=name;
	window.__lastImageSrc=document.images[name].src;
	document.images[name].src=file;
}

function rollout()
{
	if( ! window.__lastImageName ) return;
	if( ! window.__lastImageSrc ) return;
	document.images[window.__lastImageName].src=window.__lastImageSrc;
}

//----[ Remote Rollovers ]-----------------------------------------
function remoteRollout()
{
	window.__lastRemoteRolloverHover = false;
	setTimeout( "_remoteRollout()", 1000 );
}

function _remoteRollout()
{
	if( window.__lastRemoteRolloverLayer && !window.__lastRemoteRolloverHover )
	{
		window.__lastRemoteRolloverLayer.innerHTML = window.__lastRemoteRolloverString;
		window.__lastRemoteRolloverLayer = null;
	}
}

function remoteRollover( lyr, newtext )
{
	window.__lastRemoteRolloverHover = true;
	if( ! document.getElementById ) return;
	var el = document.getElementById( lyr );
	if( el )
	{
		if( ! window.__lastRemoteRolloverLayer )
		{
			window.__lastRemoteRolloverLayer = el;
			window.__lastRemoteRolloverString = el.innerHTML;
		}
		el.innerHTML = newtext;
	}
}

//----[ Ticker ]-----------------------------------------
function tickerSlide()
{
	if( ! window.tickerMoving ) return;
	
	window.tickerScrollPos -= 3;
	window.tickerScrollLayer.style.left = window.tickerScrollPos+'px';
	if( window.tickerScrollPos <= window.tickerScrollEnd ) window.tickerScrollPos = window.tickerStartPos;
	window.tickerScrollTimeout = setTimeout( 'tickerSlide();', 55 );
}

function startTicker( html )
{
	if( !document.getElementById ) return;
	var holder = document.getElementById( 'divTickerHolder' );
	if( !holder || !holder.innerHTML ) return;
	window.tickerStartPos = parseInt( holder.style.width );
	if( isNaN( window.tickerStartPos ) ) return;
	window.tickerScrollPos = window.tickerStartPos;

	holder.visible = false;
	oldWidth = holder.style.width;
	holder.style.width = '999999px';
	holder.innerHTML = '<div style="position: relative;"><div id="divTickerInner" class="normal" style="position:absolute; left: 0px; top: 0px; overflow: visible;"><nobr>'+html+'</nobr></div></div>';

	window.tickerScrollLayer = document.getElementById( 'divTickerInner' );
	window.tickerScrollEnd = 0;
	if( window.tickerScrollLayer && window.tickerScrollLayer.innerHTML )
		window.tickerScrollEnd = -parseInt( window.tickerScrollLayer.offsetWidth );

	holder.style.width = oldWidth;
	holder.visible = true;

	if( ! window.tickerScrollEnd ) return;

	window.tickerMoving = true;
	tickerSlide();
}

function pauseTicker()
{
	if( window.tickerScrollTimeout )
	{
		clearTimeout( window.tickerScrollTimeout );
		window.tickerScrollTimeout = null;
	}
	window.tickerMoving = false;
}

function resumeTicker()
{
	if( !document.getElementById ) return;
	window.tickerMoving = true;
	tickerSlide();
}

//----[ Slideshow ]-----------------------------------------
function slideshowUpdate()
{
	window.slideshowTimeout = setTimeout( 'slideshowUpdate();', 250 );

	var now = (new Date()).getTime();
	if( now > window.slideshowChangeTime )
	{
		window.slideshowChangeTime = now + window.slideshowPauseLength;
		var currDivId = window.slideshowList[ window.slideshowIndex ];
		var nextIndex = ( window.slideshowIndex + 1 ) % window.slideshowList.length;
		var nextDivId = window.slideshowList[ nextIndex ];
		window.slideshowIndex = nextIndex;
		var layer1 = document.getElementById( currDivId );
		var layer2 = document.getElementById( nextDivId );
		layer2.style.visibility = 'visible';
		layer1.style.visibility = 'hidden';
	}
}

function slideshowStart( divId )
{
	if( ! window.slideshowList || window.slideshowList.length < 2 ) return;
	if( ! document.getElementById ) return;
	
	window.slideshowIndex = 0;
	window.slideshowPauseLength = 3000;
	window.slideshowPaused = false;
	window.slideshowChangeTime = (new Date()).getTime() + window.slideshowPauseLength;
	slideshowUpdate();
}

function slideshowAdd( divId )
{
	if( ! window.slideshowList ) window.slideshowList = new Array();
	window.slideshowList[ window.slideshowList.length ] = divId;
}

function slideshowPause()
{
	if( window.slideshowTimeout )
	{
		clearTimeout( window.slideshowTimeout );
		window.tickerScrollTimeout = null;
	}
}

function slideshowContinue()
{
	var now = (new Date()).getTime();
	if( window.slideshowChangeTime < now )
	{
		window.slideshowChangeTime = now + 1000;
	}
	else
	{
		window.slideshowChangeTime = now + window.slideshowPauseLength;
	}
	slideshowUpdate();
}

	
/*__________________________________________________________________________________________
 *
 *                      DHTML MENU FUNCTIONS
 *__________________________________________________________________________________________
 */
 
function toggleMenuSelection( id )
{
	return true; // Don't bother with DHTML fly-open
	
	var el = document.getElementById( id );
	var state = 'block';
	if( el )
	{
		if( el.style.display == 'block' ) state = 'none';
		el.style.display = state;
	}

	var el4 = document.getElementById( 'sponsorlogos' );
	if( el4 )
	{
		if( id == 'menu1' ) el4.style.display = 'block';
		else if( window.__defaultMenuOption == 'menu1' && state == 'none' ) el4.style.display = 'block';
		else el4.style.display = 'none';
	}

	if( state == 'block' )
	{		
		if( id == window.__lastMenuOption );
		else if( window.__lastMenuOption != window.__defaultMenuOption )
		{
			var el2 = document.getElementById( window.__lastMenuOption );
			var el3 = document.getElementById( window.__lastMenuMarker );
			if( el3 ) el3.style.display = 'none';
			if( el2 ) el2.style.display = 'none';
			if( el3 ) el3.style.display = 'block';
		}
		if( id != window.__defaultMenuOption ) window.__lastMenuOption = id;
	}
	return false;
}

function overmenu( id, mode )
{
	if( !document.getElementById ) return;

	if( window.__lastMenuTimeout ) clearTimeout( window.__lastMenuTimeout );
	outmenu( 2 );

	if( window.__defaultMenuMarker && window.__defaultMenuMarker != id )
	{
		var el = document.getElementById( window.__defaultMenuMarker );
		if( el ) el.style.display = 'none';
	}

	var el = document.getElementById( id );
	if( el )
	{
		window.__lastMenuMarker = id;
		el.style.display = 'block';
		if( mode == 1 ) window.__useMenucolor = '#D988DD';
		el.style.backgroundColor = window.__useMenucolor;
	}
}

function outmenu(mode)
{
	if( !document.getElementById ) return;

	if( mode == 1 ) window.__useMenucolor = '#ffffff';
	if( window.__lastMenuMarker )
	{
		var el = document.getElementById( window.__lastMenuMarker );
		if( mode == 1 )
		{
			el.style.backgroundColor = '#ffffff';
			return;
		}
		else if( window.__lastMenuMarker == window.__defaultMenuMarker )
		{
			el.style.backgroundColor = '#ffffff';
			mode = 2;
		}
		else
		{
			if( el ) el.style.display = 'none';
		}
		window.__lastMenuMarker = null;
	}
	if( !mode && window.__defaultMenuMarker )
	{
		window.__lastMenuTimeout = setTimeout( '__outmenu();', 300 );
	}
}
function __outmenu()
{
	var el = document.getElementById( window.__defaultMenuMarker );
	if( el )
	{
		el.style.display = 'block';
		el.style.backgroundColor = '#ffffff';
	}
}

/*__________________________________________________________________________________________
 *
 *                      DEFAULT VARIABLES
 *__________________________________________________________________________________________
 */
 
window.__useMenucolor = '#ffffff';



